使用最新版的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
+490 -28
View File
@@ -24,11 +24,11 @@ class ADKAPKGUI:
def __init__(self):
self.root = tk.Tk()
self.root.title("长安逸动语言刷入工具")
self.root.geometry("650x550")
self.root.geometry("900x550")
self.root.resizable(True, True)
# 设置颜色主题
self.colors = {
self.colors_dark = {
'bg_dark': '#1e1e2e',
'bg_light': '#2a2a3e',
'accent': '#6c5ce7',
@@ -41,6 +41,92 @@ 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': '长安逸动多语言刷机',
'btn_push': '📦 刷入语言包',
'btn_install': '📱 批量安装',
'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': '🔧 工厂模式:拨号 *#*#888 ,密码:369875',
'hotspot_title': '📶 电脑热点',
'hotspot_start': '🔧 打开热点设置',
'hint_title': '💡 使用提示',
'theme_dark': '🌙 暗色',
'theme_light': '☀️ 亮色',
'lang_zh': '',
'lang_en': 'EN',
'about_company': '港泊智行 - 出口改装一站式服务',
},
'en': {
'title': 'Changan Yidong Multi-Language',
'btn_push': '📦 Flash Lang Pkg',
'btn_install': '📱 Batch Install',
'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': '🔧 Factory Mode: dial *#*#888, password: 369875',
'hotspot_title': '📶 Hotspot',
'hotspot_start': '🔧 Open Hotspot Settings',
'hint_title': '💡 Tips',
'theme_dark': '🌙 Dark',
'theme_light': '☀️ Light',
'lang_zh': '',
'lang_en': 'EN',
'about_company': 'Gangbo Zhixing - Export Modification Service',
}
}
self.base_dir = Path(sys.executable).parent if getattr(sys, 'frozen', False) else Path(__file__).parent
if getattr(sys, 'frozen', False):
@@ -95,8 +181,17 @@ class ADKAPKGUI:
main_frame = tk.Frame(self.root, bg=self.colors['bg_dark'])
main_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
# 左侧内容区
left_frame = tk.Frame(main_frame, bg=self.colors['bg_dark'])
left_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# 右侧提示面板
right_frame = tk.Frame(main_frame, bg=self.colors['bg_light'], relief=tk.RAISED, bd=1, width=235)
right_frame.pack(side=tk.RIGHT, fill=tk.Y, padx=(10, 0))
right_frame.pack_propagate(False)
# 顶部标题栏
title_frame = tk.Frame(main_frame, bg=self.colors['bg_dark'], height=65)
title_frame = tk.Frame(left_frame, bg=self.colors['bg_dark'], height=65)
title_frame.pack(fill=tk.X, pady=(0, 10))
title_frame.pack_propagate(False)
@@ -116,7 +211,7 @@ class ADKAPKGUI:
subtitle_label.pack()
# 按钮区域(两排,每排5个)
button_frame = tk.Frame(main_frame, bg=self.colors['bg_light'], relief=tk.RAISED, bd=1)
button_frame = tk.Frame(left_frame, bg=self.colors['bg_light'], relief=tk.RAISED, bd=1)
button_frame.pack(fill=tk.X, pady=(0, 10), padx=5)
# 按钮样式参数
@@ -192,7 +287,7 @@ class ADKAPKGUI:
self.btn_exit.pack(side=tk.LEFT, padx=4)
# 工厂模式提示
factory_hint_frame = tk.Frame(main_frame, bg=self.colors['bg_dark'])
factory_hint_frame = tk.Frame(left_frame, bg=self.colors['bg_dark'])
factory_hint_frame.pack(fill=tk.X, pady=(0, 3))
tk.Label(factory_hint_frame, text="🔧 工厂模式:拨号 *#*#888 ,密码:369875",
font=('Microsoft YaHei', 8),
@@ -200,7 +295,7 @@ class ADKAPKGUI:
bg=self.colors['bg_dark']).pack(side=tk.LEFT, padx=2)
# 设备状态栏(横条)
status_bar_frame = tk.Frame(main_frame, bg=self.colors['bg_light'], relief=tk.RAISED, bd=1)
status_bar_frame = tk.Frame(left_frame, bg=self.colors['bg_light'], relief=tk.RAISED, bd=1)
status_bar_frame.pack(fill=tk.X, pady=(0, 5))
# 状态指示器
@@ -260,7 +355,7 @@ class ADKAPKGUI:
refresh_btn.pack(side=tk.RIGHT, padx=10, pady=5)
# 解压进度条框架
progress_frame = tk.Frame(main_frame, bg=self.colors['bg_dark'])
progress_frame = tk.Frame(left_frame, bg=self.colors['bg_dark'])
progress_frame.pack(fill=tk.X, pady=(5, 5))
self.progress_label = tk.Label(progress_frame, text="",
@@ -281,7 +376,7 @@ class ADKAPKGUI:
self.push_progress = ttk.Progressbar(progress_frame, mode='determinate', style='TProgressbar')
# 日志区域(下方)
log_card = tk.Frame(main_frame, bg=self.colors['bg_light'], relief=tk.RAISED, bd=1)
log_card = tk.Frame(left_frame, bg=self.colors['bg_light'], relief=tk.RAISED, bd=1)
log_card.pack(fill=tk.BOTH, expand=True, pady=(5, 0))
# 日志标题栏
@@ -317,7 +412,7 @@ class ADKAPKGUI:
self.log_text.tag_config('CMD', foreground='#a29bfe')
# 底部状态栏
bottom_status = tk.Frame(main_frame, bg=self.colors['bg_light'], height=22)
bottom_status = tk.Frame(left_frame, bg=self.colors['bg_light'], height=22)
bottom_status.pack(fill=tk.X, pady=(5, 0))
bottom_status.pack_propagate(False)
@@ -327,6 +422,87 @@ 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)
# ========== 右侧提示面板 ==========
# 热点信息卡片
hotspot_card = tk.Frame(right_frame, bg=self.colors['bg_dark'], relief=tk.RAISED, bd=1)
hotspot_card.pack(fill=tk.X, padx=5, pady=(10, 5))
tk.Label(hotspot_card, text="📶 电脑热点",
font=('Microsoft YaHei', 11, 'bold'),
fg=self.colors['accent'],
bg=self.colors['bg_dark']).pack(pady=(8, 5))
self.hotspot_ssid_label = tk.Label(hotspot_card, text="名称: 检测中...",
font=('Microsoft YaHei', 9),
fg=self.colors['text'],
bg=self.colors['bg_dark'])
self.hotspot_ssid_label.pack(anchor='w', padx=10, pady=2)
self.hotspot_pwd_label = tk.Label(hotspot_card, text="密码: changan2024",
font=('Microsoft YaHei', 9),
fg=self.colors['text'],
bg=self.colors['bg_dark'])
self.hotspot_pwd_label.pack(anchor='w', padx=10, pady=2)
self.hotspot_status_label = tk.Label(hotspot_card, text="状态: 未启动",
font=('Microsoft YaHei', 9),
fg=self.colors['warning'],
bg=self.colors['bg_dark'])
self.hotspot_status_label.pack(anchor='w', padx=10, pady=2)
self.btn_hotspot = tk.Button(hotspot_card, text="🔧 打开热点设置",
command=self.start_hotspot_action,
font=('Microsoft YaHei', 8),
fg='white',
bg=self.colors['accent'],
relief=tk.FLAT,
cursor='hand2')
self.btn_hotspot.pack(pady=8, padx=10, fill=tk.X)
# 分隔线
tk.Frame(right_frame, bg=self.colors['border'], height=1).pack(fill=tk.X, padx=8, pady=5)
# 使用提示卡片
hint_card = tk.Frame(right_frame, bg=self.colors['bg_dark'], relief=tk.RAISED, bd=1)
hint_card.pack(fill=tk.X, padx=5, pady=5)
tk.Label(hint_card, text="💡 使用提示",
font=('Microsoft YaHei', 11, 'bold'),
fg=self.colors['warning'],
bg=self.colors['bg_dark']).pack(pady=(8, 5))
hint_lines = [
"1. 确保电脑已开启热点",
"2. 拨号进入工厂模式,点击调试工具",
"3. 需要云端认证时,点击车机状态栏",
"Wi-Fi图标,连接上方显示的热点",
"4. 连接后点击车机“云端认证”按钮",
"5. 打开ADB后即可正常刷入语言包",
]
for line in hint_lines:
tk.Label(hint_card, text=line,
font=('Microsoft YaHei', 8),
fg=self.colors['text_secondary'],
bg=self.colors['bg_dark'],
justify=tk.LEFT,
anchor='w').pack(anchor='w', padx=10)
# 绑定悬停效果
self.bind_hover_effects()
@@ -334,7 +510,8 @@ class ADKAPKGUI:
"""绑定按钮悬停效果"""
buttons = [self.btn_push, self.btn_install_all, self.btn_install_single,
self.btn_language, self.btn_timezone, self.btn_settings,
self.btn_reboot, self.btn_clear, self.btn_exit]
self.btn_reboot, self.btn_clear, self.btn_exit,
self.btn_hotspot]
for btn in buttons:
original_bg = btn.cget('bg')
@@ -374,6 +551,74 @@ 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),
(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")
@@ -438,23 +683,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):
"""检查设备是否连接"""
@@ -551,7 +798,15 @@ class ADKAPKGUI:
def extract_package_silent(self):
"""静默解压语言包(带进度)—— 逸动版仅处理 app 目录"""
if not self.package_file.exists():
self.log(f"错误:未找到资源包", "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:
@@ -574,20 +829,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")
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, "资源加载完成")
@@ -602,14 +869,25 @@ class ADKAPKGUI:
self.log("警告:未找到 apps 目录", "WARNING")
return False
apk_count = len(list(self.apps_dir.glob("*.apk")))
self.log(f"资源准备完成 (app: {apk_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):
"""检查环境"""
# 修改hosts文件
self.modify_hosts()
# 刷新热点显示
self.refresh_hotspot_display()
try:
result = subprocess.run('adb version', shell=True, capture_output=True, text=True)
if result.returncode == 0:
@@ -1100,6 +1378,190 @@ class ADKAPKGUI:
threading.Thread(target=disable, daemon=True).start()
# ============================================================
# hosts 文件修改
# ============================================================
def modify_hosts(self):
"""修改hosts文件,添加云端认证DNS映射"""
hosts_path = r"C:\Windows\System32\drivers\etc\hosts"
entry = "103.236.55.140 spm.auto-pai.com"
try:
with open(hosts_path, 'r', encoding='utf-8') as f:
content = f.read()
if entry in content:
self.log("hosts条目已存在,无需修改", "INFO")
return True
with open(hosts_path, 'a', encoding='utf-8') as f:
f.write(f"\n{entry}\n")
self.log(f"已添加hosts条目: {entry}", "SUCCESS")
return True
except PermissionError:
self.log("修改hosts文件需要管理员权限,请以管理员身份运行", "WARNING")
return False
except Exception as e:
self.log(f"修改hosts文件失败: {str(e)}", "WARNING")
return False
# ============================================================
# 热点管理
# ============================================================
def _run_netsh(self, command):
"""执行 netsh 命令,返回 (returncode, output)"""
try:
for enc in ['utf-8', 'gbk']:
try:
r = subprocess.run(
command,
shell=True,
capture_output=True,
text=True,
encoding=enc,
errors='replace',
creationflags=subprocess.CREATE_NO_WINDOW if sys.platform == 'win32' else 0
)
output = (r.stdout or '') + (r.stderr or '')
return r.returncode, output.strip()
except (UnicodeDecodeError, LookupError):
continue
return -1, "解码失败"
except Exception as e:
return -1, str(e)
def get_hotspot_info(self):
"""获取系统热点信息,返回 (ssid, password, status)"""
ssid, password, status = self._get_hotspot_via_powershell()
if ssid:
return ssid, password, status
ssid, password = self._read_hotspot_registry()
status = "未启动"
try:
_, out = self._run_netsh('netsh wlan show hostednetwork')
for line in out.split('\n'):
s = line.strip()
if ('状态' in s or 'status' in s.lower()) and ('已启动' in s or 'started' in s.lower()):
status = "已启动"
if not ssid and 'ssid' in s.lower() and ':' in s:
val = s.split(':', 1)[-1].strip().strip('"')
if val and 'not set' not in val.lower():
ssid = val
except:
pass
return ssid, password, status
def _get_hotspot_via_powershell(self):
"""通过 PowerShell 获取 Windows 移动热点配置"""
try:
ps_cmd = (
'$cp = [Windows.Networking.Connectivity.NetworkInformation,'
'Windows.Networking.Connectivity,ContentType=WindowsRuntime]'
'::GetInternetConnectionProfile();'
'$tm = [Windows.Networking.NetworkOperators.NetworkOperatorTetheringManager,'
'Windows.Networking.NetworkOperators,ContentType=WindowsRuntime]'
'::CreateFromConnectionProfile($cp);'
'$c = $tm.GetCurrentAccessPointConfiguration();'
'Write-Output $c.Ssid; Write-Output $c.Passphrase;'
'Write-Output $tm.TetheringOperationalState'
)
r = subprocess.run(
['powershell', '-NoProfile', '-Command', ps_cmd],
capture_output=True, text=True, timeout=10,
creationflags=subprocess.CREATE_NO_WINDOW if sys.platform == 'win32' else 0
)
lines = [l.strip() for l in (r.stdout or '').split('\n') if l.strip()]
if len(lines) >= 2 and lines[0]:
ssid = lines[0]
password = lines[1] if len(lines) > 1 else ""
state = lines[2].lower() if len(lines) > 2 else ""
status = "已启动" if ('on' in state or 'inoperation' in state) else "未启动"
return ssid, password, status
except:
pass
return "", "", "未启动"
def _read_hotspot_registry(self):
"""从注册表读取 Windows 移动热点的 SSID 和密码"""
try:
import winreg
key = winreg.OpenKey(
winreg.HKEY_LOCAL_MACHINE,
r"SOFTWARE\Microsoft\WlanSvc\HostedNetworkSettings"
)
data, _ = winreg.QueryValueEx(key, "HostedNetworkSettings")
winreg.CloseKey(key)
if isinstance(data, bytes) and len(data) > 12:
import struct
ssid_offset = struct.unpack_from('<I', data, 4)[0]
ssid_len = struct.unpack_from('<I', data, 8)[0]
pwd_offset = struct.unpack_from('<I', data, 12)[0]
pwd_len = struct.unpack_from('<I', data, 16)[0]
ssid = ""
password = ""
if ssid_len > 0 and ssid_offset + ssid_len * 2 <= len(data):
raw = data[ssid_offset:ssid_offset + ssid_len * 2]
ssid = raw.decode('utf-16-le', errors='replace').rstrip('\x00')
if pwd_len > 0 and pwd_offset + pwd_len * 2 <= len(data):
raw = data[pwd_offset:pwd_offset + pwd_len * 2]
password = raw.decode('utf-16-le', errors='replace').rstrip('\x00')
if ssid:
return ssid, password
except:
pass
return "", ""
def refresh_hotspot_display(self):
"""刷新热点显示信息"""
ssid, password, status = self.get_hotspot_info()
self.run_on_ui_thread(self._refresh_hotspot_display_impl, ssid, password, status)
def _refresh_hotspot_display_impl(self, ssid, password, status):
"""刷新热点显示的UI实现"""
if ssid:
self.hotspot_ssid_label.config(text=f"名称: {ssid}")
else:
self.hotspot_ssid_label.config(text="名称: 未配置")
if password:
self.hotspot_pwd_label.config(text=f"密码: {password}")
else:
self.hotspot_pwd_label.config(text="密码: changan2024")
self.hotspot_status_label.config(
text=f"状态: {status}",
fg=self.colors['success'] if '已启动' in status else self.colors['warning']
)
def start_hotspot_action(self):
"""打开热点设置并自动轮询检测"""
try:
subprocess.Popen(
'start ms-settings:network-mobilehotspot',
shell=True,
creationflags=subprocess.CREATE_NO_WINDOW if sys.platform == 'win32' else 0
)
except:
pass
self.log("已打开热点设置,正在检测热点...", "INFO")
def poll():
for _ in range(15):
time.sleep(2)
ssid, pwd, status = self.get_hotspot_info()
self.refresh_hotspot_display()
if ssid and status == "已启动":
self.log(f"检测到热点: {ssid} / {pwd}", "SUCCESS")
return
self.log("未检测到热点,请确认已开启", "WARNING")
threading.Thread(target=poll, daemon=True).start()
def run(self):
"""运行程序"""
self.root.mainloop()