使用最新版的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
+333 -45
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,160 @@ 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': '适用于启源Q07多语言安装',
'btn_root': '🔓 获取权限',
'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': '🔄 检查',
'hint_factory': '🔧 关闭车辆WI-FI和4G网络,拨号获取的密码进入工程模式',
'warn_no_device': '设备未连接',
'warn_connect_first': '请先连接设备并点击「检查」按钮刷新状态!',
'warn_no_vin': '请先刷新设备状态并获取VIN码',
'err_auth_fail': '授权失败',
'err_device_not_auth': '设备未授权',
'err_resource_fail': '资源准备失败!',
'err_no_resource_dir': '资源目录未找到',
'info_flash_start': '开始刷入语言包...',
'info_flash_done': '语言包刷入完成,重启设备后生效',
'info_flash_fail': '语言包刷入失败',
'warn_no_apk': '未找到语言包文件',
'info_installing': '安装中...',
'info_install_done': '安装完成',
'info_log_cleared': '日志已清空',
'confirm_reboot': '确定要重启设备吗?',
'info_rebooting': '设备正在重启...',
'warn_device_disconnected': '设备已断开连接',
'info_device_connected': '设备已连接',
'info_checking_auth': '正在验证授权状态...',
'info_auth_pass': '✅ 授权验证通过!',
'info_auth_fail': '❌ 授权验证失败',
'info_preparing': '正在准备资源...',
'err_no_package': '错误:未找到资源包',
'err_no_password': '错误:解压密码未设置',
'err_no_7za': '错误:未找到 7za.exe',
'err_extract_fail': '解压失败',
'info_extracting': '正在解压资源包...',
'info_extract_done': '资源准备完成',
'err_extract_user': '资源准备失败,请检查网络连接后重试',
'warn_no_app_dir': '警告:未找到 app/priv-app 目录',
'theme_dark': '🌙 暗色',
'theme_light': '☀️ 亮色',
'lang_zh': '',
'lang_en': 'EN',
'switch_lang': '语言 / Language',
'switch_theme': '切换主题',
'about_company': '宜宾科宜科技有限公司 - 智能设备管理平台',
'warn_flash_warning': '⚠️ 重要提示',
'warn_flash_msg': '刷入过程中请勿:\n ● 重启车机\n ● 退出本程序\n ● 关闭电脑\n\n否则可能导致车机系统损坏!',
'err_wrong_password': '请检查密码是否正确',
'title_pop_lang': '快捷语言设置',
},
'en': {
'title': 'Qiyuan Q07 Multi-Language',
'btn_root': '🔓 Get Root',
'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',
'hint_factory': '🔧 Turn off WiFi & 4G, enter factory mode with dial code',
'warn_no_device': 'Device not connected',
'warn_connect_first': 'Please connect device and click Check button!',
'warn_no_vin': 'Please refresh device status and get VIN',
'err_auth_fail': 'Authorization failed',
'err_device_not_auth': 'Device not authorized',
'err_resource_fail': 'Resource preparation failed!',
'err_no_resource_dir': 'Resource directory not found',
'info_flash_start': 'Starting language pack flashing...',
'info_flash_done': 'Flashing complete, reboot device to take effect',
'info_flash_fail': 'Flashing failed',
'warn_no_apk': 'No APK files found',
'info_installing': 'Installing...',
'info_install_done': 'Install complete',
'info_log_cleared': 'Log cleared',
'confirm_reboot': 'Are you sure you want to reboot?',
'info_rebooting': 'Device rebooting...',
'warn_device_disconnected': 'Device disconnected',
'info_device_connected': 'Device connected',
'info_checking_auth': 'Verifying authorization...',
'info_auth_pass': '✅ Authorization passed!',
'info_auth_fail': '❌ Authorization failed',
'info_preparing': 'Preparing resources...',
'err_no_package': 'Error: package.bin not found',
'err_no_password': 'Error: password not set',
'err_no_7za': 'Error: 7za.exe not found',
'err_extract_fail': 'Extraction failed',
'info_extracting': 'Extracting package...',
'info_extract_done': 'Resource preparation complete',
'err_extract_user': 'Resource preparation failed, check network and retry',
'warn_no_app_dir': 'Warning: app/priv-app directory not found',
'theme_dark': '🌙 Dark',
'theme_light': '☀️ Light',
'lang_zh': '',
'lang_en': 'EN',
'switch_lang': 'Language',
'switch_theme': 'Theme',
'about_company': 'Yibin Keyi Technology - Smart Device Platform',
'warn_flash_warning': '⚠️ Warning',
'warn_flash_msg': 'During flashing, DO NOT:\n ● Reboot vehicle\n ● Close this app\n ● Power off PC\n\nSystem damage may occur!',
'err_wrong_password': 'Please check password',
'title_pop_lang': 'Quick Language Setting',
}
}
# 从 exe/py 所在目录查找资源文件
self.base_dir = Path(sys.executable).parent if getattr(sys, 'frozen', False) else Path(__file__).parent
@@ -104,19 +258,19 @@ class ADKAPKGUI:
title_frame.pack_propagate(False)
# 标题
title_label = tk.Label(title_frame,
text="🚀 适用于启源Q07多语言安装",
self.title_label = tk.Label(title_frame,
text="🚀 适用于启源Q07多语言安装",
font=('Microsoft YaHei', 18, 'bold'),
fg=self.colors['accent'],
bg=self.colors['bg_dark'])
title_label.pack()
subtitle_label = tk.Label(title_frame,
self.title_label.pack()
self.subtitle_label = tk.Label(title_frame,
text="宜宾科宜科技有限公司 - 智能设备管理平台",
font=('Microsoft YaHei', 9),
fg=self.colors['text_secondary'],
bg=self.colors['bg_dark'])
subtitle_label.pack()
self.subtitle_label.pack()
# 按钮区域(两排,每排5个)
button_frame = tk.Frame(main_frame, bg=self.colors['bg_light'], relief=tk.RAISED, bd=1)
@@ -201,10 +355,11 @@ class ADKAPKGUI:
self.status_indicator.pack(side=tk.LEFT)
self.status_dot = self.status_indicator.create_oval(2, 2, 8, 8, fill='#636e72')
tk.Label(status_indicator_frame, text="设备:",
self.device_label = tk.Label(status_indicator_frame, text="设备:",
font=('Microsoft YaHei', 9),
fg=self.colors['text'],
bg=self.colors['bg_light']).pack(side=tk.LEFT, padx=(5, 3))
bg=self.colors['bg_light'])
self.device_label.pack(side=tk.LEFT, padx=(5, 3))
self.device_status_label = tk.Label(status_indicator_frame, text="未检测",
font=('Microsoft YaHei', 9, 'bold'),
@@ -216,10 +371,11 @@ class ADKAPKGUI:
# VIN信息
vin_frame = tk.Frame(status_bar_frame, bg=self.colors['bg_light'])
vin_frame.pack(side=tk.LEFT, padx=20, pady=5)
tk.Label(vin_frame, text="VIN码:",
self.vin_label_title = tk.Label(vin_frame, text="VIN码:",
font=('Microsoft YaHei', 9),
fg=self.colors['text'],
bg=self.colors['bg_light']).pack(side=tk.LEFT)
bg=self.colors['bg_light'])
self.vin_label_title.pack(side=tk.LEFT)
self.vin_label = tk.Label(vin_frame, text="未获取",
font=('Microsoft YaHei', 9, 'bold'),
fg='#636e72',
@@ -230,10 +386,11 @@ class ADKAPKGUI:
# 授权状态
auth_frame = tk.Frame(status_bar_frame, bg=self.colors['bg_light'])
auth_frame.pack(side=tk.LEFT, padx=20, pady=5)
tk.Label(auth_frame, text="授权:",
self.auth_label_title = tk.Label(auth_frame, text="授权:",
font=('Microsoft YaHei', 9),
fg=self.colors['text'],
bg=self.colors['bg_light']).pack(side=tk.LEFT)
bg=self.colors['bg_light'])
self.auth_label_title.pack(side=tk.LEFT)
self.auth_label = tk.Label(auth_frame, text="未验证",
font=('Microsoft YaHei', 9, 'bold'),
fg='#636e72',
@@ -242,14 +399,14 @@ class ADKAPKGUI:
self.auth_label.pack(side=tk.LEFT, padx=(5, 0))
# 刷新按钮
refresh_btn = tk.Button(status_bar_frame, text="🔄 检查",
self.btn_refresh = tk.Button(status_bar_frame, text="🔄 检查",
command=self.refresh_device_status,
font=('Microsoft YaHei', 8),
fg=self.colors['accent'],
bg=self.colors['bg_light'],
relief=tk.FLAT,
cursor='hand2')
refresh_btn.pack(side=tk.RIGHT, padx=10, pady=5)
self.btn_refresh.pack(side=tk.RIGHT, padx=10, pady=5)
# 提示信息区域(设备状态下方)
tips_frame = tk.Frame(main_frame, bg=self.colors['bg_light'], relief=tk.RAISED, bd=1)
@@ -301,10 +458,11 @@ class ADKAPKGUI:
log_title_frame.pack(fill=tk.X)
log_title_frame.pack_propagate(False)
tk.Label(log_title_frame, text="📋 运行日志",
self.log_title_label = tk.Label(log_title_frame, text="📋 运行日志",
font=('Microsoft YaHei', 10, 'bold'),
fg=self.colors['accent'],
bg=self.colors['bg_dark']).pack(side=tk.LEFT, padx=10)
bg=self.colors['bg_dark'])
self.log_title_label.pack(side=tk.LEFT, padx=10)
self.btn_clear = tk.Button(log_title_frame, text="🗑 清空日志",
command=self.clear_log,
@@ -347,7 +505,26 @@ class ADKAPKGUI:
fg=self.colors['text_secondary'],
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)
@@ -398,6 +575,84 @@ 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'])
# 更新 ttk 样式
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):
"""刷新所有UI文本"""
t = self.t
widgets = [
(getattr(self, 'title_label', None), 'title', None),
(getattr(self, 'subtitle_label', None), 'about_company', None),
(getattr(self, 'btn_root', None), 'btn_root', 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),
(getattr(self, 'hint_label', None), 'hint_factory', 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")
@@ -462,23 +717,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):
"""检查设备是否连接"""
@@ -563,9 +820,18 @@ 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
# 检查 7za 是否存在
if not os.path.exists(self.sz):
self.log(f"错误:未找到 7za.exe ({self.sz})", "ERROR")
return False
try:
# 使用用户目录,无需管理员权限
local_appdata = os.environ.get('LOCALAPPDATA', os.path.expanduser('~\\AppData\\Local'))
@@ -573,35 +839,49 @@ class ADKAPKGUI:
hidden_path.mkdir(parents=True, exist_ok=True)
self.temp_dir = hidden_path / "apps_cache_Q07"
# 如果已存在,先清理
if self.temp_dir.exists():
shutil.rmtree(self.temp_dir, ignore_errors=True)
time.sleep(0.5)
self.temp_dir.mkdir(parents=True, exist_ok=True)
# 设置隐藏属性(Windows
if sys.platform == 'win32':
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)
# 使用 7za 高速解压
self.log(f"正在准备资源包", "INFO")
# 使用 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")
# 尝试解析错误信息(7za 输出可能是 GBK)
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, "资源加载完成")
# 查找app和priv-app目录
self.apps_dir = None
self.priv_apps_dir = None
@@ -615,13 +895,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):
@@ -1160,7 +1448,7 @@ class ADKAPKGUI:
if self.debug_mode:
self.debug_mode = False
self.log("调试模式已关闭", "WARNING")
self.status_text.config(text="就绪")
self.status_text.config(text=self.t('status_ready'))
self.refresh_device_status()
return