's'
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import os
|
||||
import zipfile
|
||||
|
||||
from tools.helper import bcolors, download_file, file_md5, print_color
|
||||
from tools.helper import bcolors, download_file, file_md5, is_offline_only, print_color
|
||||
|
||||
class General:
|
||||
def _local_md5(self):
|
||||
@@ -17,10 +17,24 @@ class General:
|
||||
temp_path = self.dl_file_name + ".tmp"
|
||||
local_valid = self._has_valid_local_file()
|
||||
|
||||
if local_valid:
|
||||
print_color(
|
||||
"Using validated offline bundle {} ...".format(self.dl_file_name),
|
||||
bcolors.GREEN,
|
||||
)
|
||||
return
|
||||
|
||||
if is_offline_only():
|
||||
raise FileNotFoundError(
|
||||
"REDROID_OFFLINE is set but offline file is missing or MD5 mismatch: {}".format(
|
||||
self.dl_file_name
|
||||
)
|
||||
)
|
||||
|
||||
try:
|
||||
if os.path.isfile(temp_path):
|
||||
os.remove(temp_path)
|
||||
print_color("Trying online download first ...", bcolors.GREEN)
|
||||
print_color("Local bundle not found or MD5 mismatch; downloading ...", bcolors.YELLOW)
|
||||
remote_md5 = download_file(self.dl_link, temp_path)
|
||||
if remote_md5 != self.act_md5:
|
||||
raise ValueError(
|
||||
@@ -30,18 +44,9 @@ class General:
|
||||
)
|
||||
)
|
||||
os.replace(temp_path, self.dl_file_name)
|
||||
except Exception as exc:
|
||||
except Exception:
|
||||
if os.path.isfile(temp_path):
|
||||
os.remove(temp_path)
|
||||
if local_valid:
|
||||
print_color(
|
||||
"Online download failed, falling back to local {} ({})".format(
|
||||
self.dl_file_name,
|
||||
exc,
|
||||
),
|
||||
bcolors.YELLOW,
|
||||
)
|
||||
return
|
||||
raise
|
||||
|
||||
def extract(self):
|
||||
|
||||
@@ -4,7 +4,15 @@ import re
|
||||
import zipfile
|
||||
import requests
|
||||
from stuff.general import General
|
||||
from tools.helper import bcolors, download_file, host, print_color, run, get_download_dir
|
||||
from tools.helper import (
|
||||
bcolors,
|
||||
download_file,
|
||||
get_download_dir,
|
||||
host,
|
||||
is_offline_only,
|
||||
print_color,
|
||||
run,
|
||||
)
|
||||
|
||||
class Magisk(General):
|
||||
_default_stable_json = (
|
||||
@@ -225,39 +233,32 @@ on property:init.svc.zygote=stopped
|
||||
local_valid = self._has_valid_local_archive()
|
||||
local_version = self._cached_version() or "bundled"
|
||||
|
||||
try:
|
||||
if self.custom_url:
|
||||
self.dl_link = self.custom_url
|
||||
self.release_version = "url:" + os.path.basename(self.custom_url)
|
||||
else:
|
||||
self.resolve_release()
|
||||
except Exception as exc:
|
||||
if local_valid:
|
||||
self.release_version = local_version
|
||||
print_color(
|
||||
"Resolving Kitsune Mask online failed, falling back to local {} ({})".format(
|
||||
self.release_version,
|
||||
exc,
|
||||
),
|
||||
bcolors.YELLOW,
|
||||
)
|
||||
return
|
||||
raise
|
||||
if local_valid:
|
||||
self.release_version = local_version
|
||||
print_color(
|
||||
"Using offline Magisk/Kitsune APK {} ({}) ...".format(
|
||||
self.dl_file_name,
|
||||
self.release_version,
|
||||
),
|
||||
bcolors.GREEN,
|
||||
)
|
||||
self._validate_archive()
|
||||
return
|
||||
|
||||
try:
|
||||
self._download_remote_archive()
|
||||
except Exception as exc:
|
||||
if local_valid:
|
||||
self.release_version = local_version
|
||||
print_color(
|
||||
"Downloading Kitsune Mask online failed, falling back to local {} ({})".format(
|
||||
self.release_version,
|
||||
exc,
|
||||
),
|
||||
bcolors.YELLOW,
|
||||
if is_offline_only():
|
||||
raise FileNotFoundError(
|
||||
"REDROID_OFFLINE is set but no valid offline magisk.apk at {}".format(
|
||||
self.dl_file_name
|
||||
)
|
||||
return
|
||||
raise
|
||||
)
|
||||
|
||||
if self.custom_url:
|
||||
self.dl_link = self.custom_url
|
||||
self.release_version = "url:" + os.path.basename(self.custom_url)
|
||||
else:
|
||||
self.resolve_release()
|
||||
|
||||
self._download_remote_archive()
|
||||
|
||||
def extract(self):
|
||||
print_color("Extracting archive...", bcolors.GREEN)
|
||||
|
||||
Reference in New Issue
Block a user