This commit is contained in:
eric
2026-04-04 15:33:17 -05:00
parent f0bfb952e8
commit 898238b3e0
5 changed files with 94 additions and 63 deletions

View File

@@ -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):