Files
2026-04-04 15:33:17 -05:00

65 lines
2.0 KiB
Python

import os
import zipfile
from tools.helper import bcolors, download_file, file_md5, is_offline_only, print_color
class General:
def _local_md5(self):
if not os.path.isfile(self.dl_file_name):
return ""
return file_md5(self.dl_file_name)
def _has_valid_local_file(self):
return os.path.isfile(self.dl_file_name) and self._local_md5() == self.act_md5
def download(self):
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("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(
"Downloaded file md5 mismatch: expected {}, got {}".format(
self.act_md5,
remote_md5,
)
)
os.replace(temp_path, self.dl_file_name)
except Exception:
if os.path.isfile(temp_path):
os.remove(temp_path)
raise
def extract(self):
print_color("Extracting archive...", bcolors.GREEN)
print(self.dl_file_name)
print(self.extract_to)
with zipfile.ZipFile(self.dl_file_name) as z:
z.extractall(self.extract_to)
def copy(self):
pass
def install(self):
# pass
self.download()
self.extract()
self.copy()