使用最新版的7z解压

This commit is contained in:
2026-05-20 13:57:41 +08:00
parent a99dad2116
commit cb840992ef
33 changed files with 3252 additions and 189 deletions
+225 -21
View File
@@ -28,7 +28,7 @@ class ADKAPKGUI:
self.root.resizable(True, True)
# 设置颜色主题
self.colors = {
self.colors_dark = {
'bg_dark': '#1e1e2e',
'bg_light': '#2a2a3e',
'accent': '#6c5ce7',
@@ -41,6 +41,84 @@ class ADKAPKGUI:
'text_secondary': '#b2bec3',
'border': '#3d3d5e'
}
self.colors_light = {
'bg_dark': '#f5f5f5',
'bg_light': '#ffffff',
'accent': '#6c5ce7',
'accent_hover': '#5b4bc4',
'success': '#00b894',
'error': '#d63031',
'warning': '#e17055',
'info': '#0984e3',
'text': '#2d3436',
'text_secondary': '#636e72',
'border': '#dfe6e9'
}
self.colors = dict(self.colors_dark)
self.theme = 'dark'
# 多语言
self.lang = 'zh'
self.T = {
'zh': {
'title': '适用于X5plus多语言安装',
'btn_push': '📦 刷入语言包',
'btn_install': '📱 安装App',
'btn_language': '🌐 语言设置',
'btn_timezone': '⏰ 时区设置',
'btn_settings': '⚙️ 安卓设置',
'btn_reboot': '🔄 重启设备',
'btn_disable_upgrade': '❌ 禁用升级',
'btn_clear_log': '🗑 清空日志',
'device_label': '设备:',
'vin_label': 'VIN码:',
'auth_label': '授权:',
'log_title': '📋 运行日志',
'status_ready': '就绪',
'status_connected': '已连接',
'status_disconnected': '未连接',
'status_detecting': '未检测',
'vin_none': '未获取',
'auth_none': '未验证',
'auth_yes': '已授权',
'auth_no': '未授权',
'btn_refresh': '🔄 检查',
'theme_dark': '🌙 暗色',
'theme_light': '☀️ 亮色',
'lang_zh': '',
'lang_en': 'EN',
'about_company': '宜宾科宜科技有限公司 - 智能设备管理平台',
},
'en': {
'title': 'X5plus Multi-Language',
'btn_push': '📦 Flash Lang Pkg',
'btn_install': '📱 Install App',
'btn_language': '🌐 Language',
'btn_timezone': '⏰ Timezone',
'btn_settings': '⚙️ Settings',
'btn_reboot': '🔄 Reboot',
'btn_disable_upgrade': '❌ Disable OTA',
'btn_clear_log': '🗑 Clear Log',
'device_label': 'Device:',
'vin_label': 'VIN:',
'auth_label': 'Auth:',
'log_title': '📋 Log',
'status_ready': 'Ready',
'status_connected': 'Connected',
'status_disconnected': 'Disconnected',
'status_detecting': 'Detecting',
'vin_none': 'None',
'auth_none': 'Unknown',
'auth_yes': 'Authorized',
'auth_no': 'Unauthorized',
'btn_refresh': '🔄 Check',
'theme_dark': '🌙 Dark',
'theme_light': '☀️ Light',
'lang_zh': '',
'lang_en': 'EN',
'about_company': 'Yibin Keyi Technology - Smart Device Platform',
}
}
# 从 exe/py 所在目录查找资源文件
self.base_dir = Path(sys.executable).parent if getattr(sys, 'frozen', False) else Path(__file__).parent
@@ -355,6 +433,22 @@ class ADKAPKGUI:
bg=self.colors['bg_light'])
self.status_text.pack(side=tk.LEFT, padx=10)
# 主题和语言切换按钮
self.btn_theme_switch = tk.Button(bottom_status, text="🌙 暗色",
command=self.toggle_theme,
font=('Microsoft YaHei', 8),
fg=self.colors['accent'],
bg=self.colors['bg_light'],
relief=tk.FLAT, cursor='hand2')
self.btn_theme_switch.pack(side=tk.RIGHT, padx=5)
self.btn_lang_switch = tk.Button(bottom_status, text="EN",
command=self.toggle_lang,
font=('Microsoft YaHei', 8, 'bold'),
fg=self.colors['accent'],
bg=self.colors['bg_light'],
relief=tk.FLAT, cursor='hand2')
self.btn_lang_switch.pack(side=tk.RIGHT, padx=5)
# 调试模式快捷键
self.root.bind('<Control-Shift-D>', self._toggle_debug)
@@ -406,7 +500,7 @@ class ADKAPKGUI:
now = datetime.now()
hour = now.hour # 如 14
minute_tens = now.minute // 10 # 如 58 → 5
return f"{minute_tens}0{hour}"
return f"{minute_tens}0{hour:02d}"
def _update_fac_pwd_display(self):
"""更新工程密码显示,每30秒刷新一次"""
@@ -424,6 +518,73 @@ class ADKAPKGUI:
"""将函数调度到主线程执行,确保线程安全"""
self.root.after(0, func, *args, **kwargs)
def t(self, key):
return self.T.get(self.lang, self.T['zh']).get(key, key)
def toggle_lang(self):
self.lang = 'en' if self.lang == 'zh' else 'zh'
self.btn_lang_switch.config(text=self.t('lang_en') if self.lang == 'zh' else self.t('lang_zh'))
self._refresh_ui_texts()
self.log(f"语言已切换为 {'English' if self.lang == 'en' else '中文'}", "INFO")
def toggle_theme(self):
if self.theme == 'dark':
self.colors = dict(self.colors_light)
self.theme = 'light'
self.btn_theme_switch.config(text=self.t('theme_dark'))
else:
self.colors = dict(self.colors_dark)
self.theme = 'dark'
self.btn_theme_switch.config(text=self.t('theme_light'))
self._apply_theme()
def _apply_theme(self):
c = self.colors
self.root.configure(bg=c['bg_dark'])
style = ttk.Style()
style.configure('TFrame', background=c['bg_dark'])
style.configure('TLabel', background=c['bg_dark'], foreground=c['text'])
style.configure('TLabelframe', background=c['bg_dark'], foreground=c['text'])
style.configure('TLabelframe.Label', background=c['bg_dark'], foreground=c['accent'])
style.configure('TProgressbar', background=c['accent'], troughcolor=c['bg_light'], borderwidth=0)
self.log_text.tag_config('INFO', foreground='#74b9ff')
self.log_text.tag_config('SUCCESS', foreground='#55efc4')
self.log_text.tag_config('ERROR', foreground='#ff7675')
self.log_text.tag_config('WARNING', foreground='#ffeaa7')
self.log_text.tag_config('CMD', foreground='#a29bfe')
if self.theme == 'light':
self.log_text.configure(bg='#ffffff', fg='#2d3436')
else:
self.log_text.configure(bg='#2d2d3d', fg='#e0e0e0')
def _refresh_ui_texts(self):
t = self.t
widgets = [
(getattr(self, 'title_label', None), 'title', None),
(getattr(self, 'subtitle_label', None), 'about_company', None),
(getattr(self, 'btn_push', None), 'btn_push', None),
(getattr(self, 'btn_install_all', None), 'btn_install', None),
(getattr(self, 'btn_language', None), 'btn_language', None),
(getattr(self, 'btn_timezone', None), 'btn_timezone', None),
(getattr(self, 'btn_settings', None), 'btn_settings', None),
(getattr(self, 'btn_reboot', None), 'btn_reboot', None),
(getattr(self, 'btn_exit', None), 'btn_disable_upgrade', None),
(getattr(self, 'btn_clear', None), 'btn_clear_log', None),
(getattr(self, 'log_title_label', None), 'log_title', None),
(getattr(self, 'status_text', None), 'status_ready', None),
(getattr(self, 'device_label', None), 'device_label', None),
(getattr(self, 'vin_label_title', None), 'vin_label', None),
(getattr(self, 'auth_label_title', None), 'auth_label', None),
(getattr(self, 'btn_refresh', None), 'btn_refresh', None),
]
for w, key, _ in widgets:
if w: w.config(text=t(key))
self.btn_theme_switch.config(text=t('theme_light') if self.theme == 'dark' else t('theme_dark'))
self.btn_lang_switch.config(text=t('lang_en') if self.lang == 'zh' else t('lang_zh'))
if self.vin:
self._update_device_status_impl(self.device_connected, self.vin,
getattr(self, '_last_authorized', False))
def _log_impl(self, message, level="INFO"):
"""日志写入的实际实现(必须在主线程调用)"""
timestamp = datetime.now().strftime("%H:%M:%S")
@@ -488,23 +649,25 @@ class ADKAPKGUI:
def _update_device_status_impl(self, connected, vin, authorized):
"""设备状态UI更新的实际实现(必须在主线程调用)"""
self._last_authorized = authorized
t = self.t
if connected:
self.status_indicator.itemconfig(self.status_dot, fill=self.colors['success'])
self.device_status_label.config(text="已连接", fg=self.colors['success'])
self.device_status_label.config(text=t('status_connected'), fg=self.colors['success'])
if vin:
self.vin_label.config(text=vin, fg=self.colors['success'])
if authorized:
self.auth_label.config(text="已授权", fg=self.colors['success'])
self.auth_label.config(text=t('auth_yes'), fg=self.colors['success'])
else:
self.auth_label.config(text="未授权", fg=self.colors['error'])
self.auth_label.config(text=t('auth_no'), fg=self.colors['error'])
else:
self.vin_label.config(text="未获取", fg=self.colors['error'])
self.auth_label.config(text="未验证", fg=self.colors['error'])
self.vin_label.config(text=t('vin_none'), fg=self.colors['error'])
self.auth_label.config(text=t('auth_none'), fg=self.colors['error'])
else:
self.status_indicator.itemconfig(self.status_dot, fill=self.colors['error'])
self.device_status_label.config(text="未连接", fg=self.colors['error'])
self.vin_label.config(text="未获取", fg=self.colors['error'])
self.auth_label.config(text="未验证", fg=self.colors['error'])
self.device_status_label.config(text=t('status_disconnected'), fg=self.colors['error'])
self.vin_label.config(text=t('vin_none'), fg=self.colors['error'])
self.auth_label.config(text=t('auth_none'), fg=self.colors['error'])
def check_device_connection(self):
"""检查设备是否连接"""
@@ -547,7 +710,15 @@ class ADKAPKGUI:
def extract_package_silent(self):
"""静默解压语言包(带进度)"""
if not self.package_file.exists():
self.log(f"未找到资源包 ({self.package_file.name})", "ERROR")
self.log(f"错误:未找到资源包 ({self.package_file})", "ERROR")
return False
if not self.extract_password:
self.log("错误:解压密码未设置", "ERROR")
return False
if not os.path.exists(self.sz):
self.log(f"错误:未找到 7za.exe ({self.sz})", "ERROR")
return False
try:
@@ -570,19 +741,32 @@ class ADKAPKGUI:
subprocess.run(f'attrib +h "{self.temp_dir.parent}"', shell=True, capture_output=True)
subprocess.run(f'attrib +h "{self.temp_dir}"', shell=True, capture_output=True)
self.log(f"正在解压资源包...", "INFO")
# 使用 7za 高速解压
# 使用 7za 解压(不用 text=True 避免编码问题)
self.update_progress(0, 1, "资源加载中...")
result = subprocess.run(
[self.sz, 'x', str(self.package_file), f'-p{self.extract_password}', f'-o{self.temp_dir}', '-y'],
capture_output=True, text=True, creationflags=subprocess.CREATE_NO_WINDOW if sys.platform == 'win32' else 0
[self.sz, 'x', str(self.package_file),
f'-p{self.extract_password}',
f'-o{self.temp_dir}', '-y'],
capture_output=True,
creationflags=subprocess.CREATE_NO_WINDOW if sys.platform == 'win32' else 0
)
if result.returncode != 0:
stderr = result.stderr.strip()
if stderr:
self.log(f"解压失败: {stderr[:200]}", "ERROR")
err_msg = ""
for output in [result.stderr, result.stdout]:
if output:
for enc in ['gbk', 'utf-8']:
try:
err_msg += output.decode(enc, errors='replace')
break
except:
continue
if err_msg.strip():
self.log(f"解压失败: {err_msg.strip()[:300]}", "ERROR")
else:
self.log("解压失败,请检查密码是否正确", "ERROR")
self.log(f"解压失败 (返回码: {result.returncode}),请检查密码是否正确", "ERROR")
return False
self.update_progress(1, 1, "资源加载完成")
@@ -599,13 +783,21 @@ class ADKAPKGUI:
self.priv_apps_dir = priv_app_candidates[0]
if not self.apps_dir and not self.priv_apps_dir:
self.log("未找到 app/priv-app 目录", "WARNING")
self.log("警告:未找到 app/priv-app 目录", "WARNING")
return False
apk_count = len(list(self.apps_dir.glob("*.apk"))) if self.apps_dir else 0
priv_count = len(list(self.priv_apps_dir.glob("*.apk"))) if self.priv_apps_dir else 0
self.log(f"资源准备完成 (app: {apk_count}, priv-app: {priv_count})", "SUCCESS")
return True
except Exception as e:
self.log(f"资源准备失败", "ERROR")
if getattr(self, 'debug_mode', False):
self.log(f"资源准备失败: {str(e)}", "ERROR")
import traceback
self.log(traceback.format_exc(), "ERROR")
else:
self.log("资源准备失败,请检查网络连接后重试", "ERROR")
return False
def check_environment(self):
@@ -825,6 +1017,18 @@ class ADKAPKGUI:
return
self.show_progress(True, is_push=True)
# 推送系统分区前先获取 root 权限并重新挂载
ok, err = self.run_adb_command('adb -d root')
if not ok:
self.log(f"adb root 失败: {err}", "WARNING")
else:
# adbd 重启后需要短暂等待
time.sleep(2)
ok, err = self.run_adb_command('adb -d remount')
if not ok:
self.log(f"adb remount 失败: {err}", "WARNING")
self.run_adb_command('adb -d shell mkdir -p /data/local/tmp')
all_apks = []
@@ -1021,7 +1225,7 @@ class ADKAPKGUI:
# 语言列表:(显示名, locale_code)
languages = [
("🇨🇳 中文", "zh-CN"),
("英 English", "en-US"),
("英 English", "en-EN"),
("俄 Русский", "ru-RU"),
("法 Français", "fr-FR"),
("西 Español", "es-ES"),