mirror of
https://git.axenov.dev/mirrors/cursor-free-vip.git
synced 2026-01-04 01:31:36 +03:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a873291481 | ||
|
|
7710ea4bb3 | ||
|
|
13483eed77 | ||
|
|
eb69f933af | ||
|
|
54cd8cf323 | ||
|
|
4e0289c86c | ||
|
|
af4a1c4065 |
11
README.md
11
README.md
@@ -17,7 +17,7 @@ This is a tool to automatically register (except for Google verification code),
|
|||||||
這是一個自動化工具,自動註冊(除了Google驗證碼),支持 Windows 和 macOS 系統,完成Auth驗證,重置Cursor的配置。
|
這是一個自動化工具,自動註冊(除了Google驗證碼),支持 Windows 和 macOS 系統,完成Auth驗證,重置Cursor的配置。
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="./images/pro_2025-01-14_14-40-37.png" alt="new" width="400"/><br>
|
<img src="./images/new107_2025-01-15_13-53-56.png" alt="new" width="400"/><br>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
@@ -37,6 +37,14 @@ This is a tool to automatically register (except for Google verification code),
|
|||||||
|
|
||||||
## 🔄 更新日志
|
## 🔄 更新日志
|
||||||
<details open>
|
<details open>
|
||||||
|
<summary>v1.0.7 - HotFix</summary>
|
||||||
|
|
||||||
|
1. Fix Reset Machine | 修復重置機器
|
||||||
|
2. Fix Locale Language | 修復多語言
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>Other Version Change Log</summary>
|
||||||
|
<details>
|
||||||
<summary>v1.0.7</summary>
|
<summary>v1.0.7</summary>
|
||||||
|
|
||||||
1. Add Locale Language Support | 增加多語言支持
|
1. Add Locale Language Support | 增加多語言支持
|
||||||
@@ -130,6 +138,7 @@ This is a tool to automatically register (except for Google verification code),
|
|||||||
<img src="./images/pro_2025-01-11_16-24-03.png" alt="Cursor Pro Logo" width="400"/><br>
|
<img src="./images/pro_2025-01-11_16-24-03.png" alt="Cursor Pro Logo" width="400"/><br>
|
||||||
</p>
|
</p>
|
||||||
</details>
|
</details>
|
||||||
|
</details>
|
||||||
|
|
||||||
## ✨ Features | 功能特點
|
## ✨ Features | 功能特點
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ a = Analysis(
|
|||||||
('reset_machine_manual.py', '.'),
|
('reset_machine_manual.py', '.'),
|
||||||
('cursor_register.py', '.'),
|
('cursor_register.py', '.'),
|
||||||
('browser.py', '.'),
|
('browser.py', '.'),
|
||||||
('control.py', '.')
|
('control.py', '.'),
|
||||||
|
('.env', '.')
|
||||||
],
|
],
|
||||||
hiddenimports=[
|
hiddenimports=[
|
||||||
'cursor_auth',
|
'cursor_auth',
|
||||||
|
|||||||
43
control.py
43
control.py
@@ -77,7 +77,7 @@ class BrowserControl:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def select_email_domain(self, domain_index=None):
|
def select_email_domain(self, domain_index=None):
|
||||||
"""选择邮箱域名,如果不指定index则随机选择"""
|
"""选择邮箱域名,如果不指定index则随机选择。避免选择fr.nf域名"""
|
||||||
try:
|
try:
|
||||||
print(f"{Fore.CYAN}{EMOJI['MAIL']} {self.translator.get('control.select_email_domain')}...{Style.RESET_ALL}")
|
print(f"{Fore.CYAN}{EMOJI['MAIL']} {self.translator.get('control.select_email_domain')}...{Style.RESET_ALL}")
|
||||||
# 找到下拉框
|
# 找到下拉框
|
||||||
@@ -95,21 +95,38 @@ class BrowserControl:
|
|||||||
all_options.extend(other_options)
|
all_options.extend(other_options)
|
||||||
|
|
||||||
if all_options:
|
if all_options:
|
||||||
# 如果没有指定索引,随机选择一个
|
max_attempts = 5 # 最大尝试次数
|
||||||
if domain_index is None:
|
attempt = 0
|
||||||
domain_index = random.randint(0, len(all_options) - 1)
|
|
||||||
|
|
||||||
if domain_index < len(all_options):
|
while attempt < max_attempts:
|
||||||
# 获取选中选项的文本
|
# 如果没有指定索引,随机选择一个
|
||||||
selected_domain = all_options[domain_index].text
|
if domain_index is None:
|
||||||
print(f"{Fore.CYAN}{EMOJI['MAIL']} {self.translator.get('control.select_email_domain')}: {selected_domain}{Style.RESET_ALL}")
|
domain_index = random.randint(0, len(all_options) - 1)
|
||||||
|
|
||||||
# 点击选择
|
if domain_index < len(all_options):
|
||||||
all_options[domain_index].click()
|
# 获取选中选项的文本
|
||||||
time.sleep(1)
|
selected_domain = all_options[domain_index].text
|
||||||
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} {self.translator.get('control.select_email_domain_success')}{Style.RESET_ALL}")
|
|
||||||
return True
|
# 检查是否为fr.nf域名
|
||||||
|
if "fr.nf" in selected_domain.lower():
|
||||||
|
print(f"{Fore.YELLOW}{EMOJI['INFO']} 检测到fr.nf域名,重新选择...{Style.RESET_ALL}")
|
||||||
|
domain_index = None # 重置索引以便重新随机选择
|
||||||
|
attempt += 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
print(f"{Fore.CYAN}{EMOJI['MAIL']} {self.translator.get('control.select_email_domain')}: {selected_domain}{Style.RESET_ALL}")
|
||||||
|
|
||||||
|
# 点击选择
|
||||||
|
all_options[domain_index].click()
|
||||||
|
time.sleep(1)
|
||||||
|
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} {self.translator.get('control.select_email_domain_success')}{Style.RESET_ALL}")
|
||||||
|
return True
|
||||||
|
|
||||||
|
attempt += 1
|
||||||
|
|
||||||
|
print(f"{Fore.RED}{EMOJI['ERROR']} 无法找到合适的非fr.nf域名{Style.RESET_ALL}")
|
||||||
|
return False
|
||||||
|
|
||||||
print(f"{Fore.RED}{EMOJI['ERROR']} {self.translator.get('control.no_available_domain_options', count=len(all_options))}{Style.RESET_ALL}")
|
print(f"{Fore.RED}{EMOJI['ERROR']} {self.translator.get('control.no_available_domain_options', count=len(all_options))}{Style.RESET_ALL}")
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class CursorAuth:
|
|||||||
|
|
||||||
# 重新连接数据库
|
# 重新连接数据库
|
||||||
conn = sqlite3.connect(self.db_path)
|
conn = sqlite3.connect(self.db_path)
|
||||||
print(f"{EMOJI['INFO']} {Fore.GREEN}{self.translator.get('auth.connected_to_database')}{Style.RESET_ALL}")
|
print(f"{EMOJI['INFO']} {Fore.GREEN} {self.translator.get('auth.connected_to_database')}{Style.RESET_ALL}")
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
# 增加超时和其他优化设置
|
# 增加超时和其他优化设置
|
||||||
@@ -90,7 +90,7 @@ class CursorAuth:
|
|||||||
UPDATE ItemTable SET value = ?
|
UPDATE ItemTable SET value = ?
|
||||||
WHERE key = ?
|
WHERE key = ?
|
||||||
""", (value, key))
|
""", (value, key))
|
||||||
print(f"{EMOJI['INFO']} {Fore.CYAN}Updating {key.split('/')[-1]}...{Style.RESET_ALL}")
|
print(f"{EMOJI['INFO']} {Fore.CYAN} {self.translator.get('auth.updating_pair')} {key.split('/')[-1]}...{Style.RESET_ALL}")
|
||||||
|
|
||||||
cursor.execute("COMMIT")
|
cursor.execute("COMMIT")
|
||||||
print(f"{EMOJI['SUCCESS']} {Fore.GREEN}{self.translator.get('auth.database_updated_successfully')}{Style.RESET_ALL}")
|
print(f"{EMOJI['SUCCESS']} {Fore.GREEN}{self.translator.get('auth.database_updated_successfully')}{Style.RESET_ALL}")
|
||||||
@@ -101,14 +101,14 @@ class CursorAuth:
|
|||||||
raise e
|
raise e
|
||||||
|
|
||||||
except sqlite3.Error as e:
|
except sqlite3.Error as e:
|
||||||
print(f"\n{EMOJI['ERROR']} {Fore.RED}{self.translator.get('auth.database_error', error=str(e))}{Style.RESET_ALL}")
|
print(f"\n{EMOJI['ERROR']} {Fore.RED} {self.translator.get('auth.database_error', error=str(e))}{Style.RESET_ALL}")
|
||||||
return False
|
return False
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"\n{EMOJI['ERROR']} {Fore.RED}{self.translator.get('auth.an_error_occurred', error=str(e))}{Style.RESET_ALL}")
|
print(f"\n{EMOJI['ERROR']} {Fore.RED} {self.translator.get('auth.an_error_occurred', error=str(e))}{Style.RESET_ALL}")
|
||||||
return False
|
return False
|
||||||
finally:
|
finally:
|
||||||
if conn:
|
if conn:
|
||||||
conn.close()
|
conn.close()
|
||||||
print(f"{EMOJI['DB']} {Fore.CYAN}{self.translator.get('auth.database_connection_closed')}{Style.RESET_ALL}")
|
print(f"{EMOJI['DB']} {Fore.CYAN} {self.translator.get('auth.database_connection_closed')}{Style.RESET_ALL}")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ class CursorRegistration:
|
|||||||
|
|
||||||
# 创建新的浏览器实例用于注册
|
# 创建新的浏览器实例用于注册
|
||||||
from browser import BrowserManager
|
from browser import BrowserManager
|
||||||
signup_browser_manager = BrowserManager(noheader=True)
|
signup_browser_manager = BrowserManager(noheader=False)
|
||||||
self.signup_tab = signup_browser_manager.init_browser()
|
self.signup_tab = signup_browser_manager.init_browser()
|
||||||
|
|
||||||
# 访问注册页面
|
# 访问注册页面
|
||||||
@@ -144,10 +144,10 @@ class CursorRegistration:
|
|||||||
|
|
||||||
# 获取验证码,设置60秒超时
|
# 获取验证码,设置60秒超时
|
||||||
verification_code = None
|
verification_code = None
|
||||||
max_attempts = 10 # 增加到10次尝试
|
max_attempts = 20 # 增加到10次尝试
|
||||||
retry_interval = 5 # 每5秒重试一次
|
retry_interval = 10 # 每5秒重试一次
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
timeout = 60 # 60秒超时
|
timeout = 160 # 60秒超时
|
||||||
|
|
||||||
print(f"{Fore.CYAN}{EMOJI['WAIT']} {self.translator.get('register.start_getting_verification_code')}...{Style.RESET_ALL}")
|
print(f"{Fore.CYAN}{EMOJI['WAIT']} {self.translator.get('register.start_getting_verification_code')}...{Style.RESET_ALL}")
|
||||||
|
|
||||||
|
|||||||
BIN
images/new107_2025-01-15_13-53-56.png
Normal file
BIN
images/new107_2025-01-15_13-53-56.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 55 KiB |
@@ -45,7 +45,10 @@
|
|||||||
"updating_pair": "Updating Key-Value Pair",
|
"updating_pair": "Updating Key-Value Pair",
|
||||||
"sqlite_success": "SQLite Database Updated Successfully",
|
"sqlite_success": "SQLite Database Updated Successfully",
|
||||||
"sqlite_error": "SQLite Database Update Failed: {error}",
|
"sqlite_error": "SQLite Database Update Failed: {error}",
|
||||||
"press_enter": "Press Enter to Exit"
|
"press_enter": "Press Enter to Exit",
|
||||||
|
"updating_system_ids": "Updating System IDs",
|
||||||
|
"system_ids_updated": "System IDs Updated Successfully",
|
||||||
|
"system_ids_update_failed": "System IDs Update Failed: {error}"
|
||||||
},
|
},
|
||||||
"register": {
|
"register": {
|
||||||
"title": "Cursor Registration Tool",
|
"title": "Cursor Registration Tool",
|
||||||
@@ -107,7 +110,8 @@
|
|||||||
"reset_machine_id": "Reset Machine ID",
|
"reset_machine_id": "Reset Machine ID",
|
||||||
"database_connection_closed": "Database Connection Closed",
|
"database_connection_closed": "Database Connection Closed",
|
||||||
"database_updated_successfully": "Database Updated Successfully",
|
"database_updated_successfully": "Database Updated Successfully",
|
||||||
"connected_to_database": "Connected to Database"
|
"connected_to_database": "Connected to Database",
|
||||||
|
"updating_pair": "Updating Key-Value Pair"
|
||||||
},
|
},
|
||||||
"control": {
|
"control": {
|
||||||
"generate_email": "Generating New Email",
|
"generate_email": "Generating New Email",
|
||||||
@@ -136,6 +140,8 @@
|
|||||||
"get_cursor_session_token": "Get Cursor Session Token",
|
"get_cursor_session_token": "Get Cursor Session Token",
|
||||||
"get_cursor_session_token_success": "Get Cursor Session Token Success",
|
"get_cursor_session_token_success": "Get Cursor Session Token Success",
|
||||||
"get_cursor_session_token_failed": "Get Cursor Session Token Failed",
|
"get_cursor_session_token_failed": "Get Cursor Session Token Failed",
|
||||||
"save_token_failed": "Save Token Failed"
|
"save_token_failed": "Save Token Failed",
|
||||||
|
"database_updated_successfully": "Database Updated Successfully",
|
||||||
|
"database_connection_closed": "Database Connection Closed"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,6 +26,30 @@
|
|||||||
"timeout": "以下进程未能在规定时间内关闭: {pids}",
|
"timeout": "以下进程未能在规定时间内关闭: {pids}",
|
||||||
"error": "关闭 Cursor 进程时发生错误: {error}"
|
"error": "关闭 Cursor 进程时发生错误: {error}"
|
||||||
},
|
},
|
||||||
|
"reset": {
|
||||||
|
"title": "Cursor 机器标识重置工具",
|
||||||
|
"checking": "检查配置文件",
|
||||||
|
"not_found": "配置文件未找到",
|
||||||
|
"no_permission": "无法读取或写入配置文件,请检查文件权限",
|
||||||
|
"reading": "读取当前配置",
|
||||||
|
"creating_backup": "创建配置备份",
|
||||||
|
"backup_exists": "备份文件已存在,跳过备份步骤",
|
||||||
|
"generating": "生成新机器标识",
|
||||||
|
"saving_json": "保存新配置到JSON",
|
||||||
|
"success": "机器标识重置成功",
|
||||||
|
"new_id": "新机器标识",
|
||||||
|
"permission_error": "权限错误: {error}",
|
||||||
|
"run_as_admin": "请尝试以管理员身份运行此程序",
|
||||||
|
"process_error": "重置进程错误: {error}",
|
||||||
|
"updating_sqlite": "更新SQLite数据库",
|
||||||
|
"updating_pair": "更新键值对",
|
||||||
|
"sqlite_success": "SQLite数据库更新成功",
|
||||||
|
"sqlite_error": "SQLite数据库更新失败: {error}",
|
||||||
|
"press_enter": "按回车键退出",
|
||||||
|
"updating_system_ids": "更新系统ID",
|
||||||
|
"system_ids_updated": "系统ID更新成功",
|
||||||
|
"system_ids_update_failed": "系统ID更新失败: {error}"
|
||||||
|
},
|
||||||
"register": {
|
"register": {
|
||||||
"title": "Cursor 注册工具",
|
"title": "Cursor 注册工具",
|
||||||
"start": "开始注册流程",
|
"start": "开始注册流程",
|
||||||
@@ -68,7 +92,8 @@
|
|||||||
"account_info_saved": "账户信息已保存",
|
"account_info_saved": "账户信息已保存",
|
||||||
"save_account_info_failed": "保存账户信息失败",
|
"save_account_info_failed": "保存账户信息失败",
|
||||||
"get_email_address": "获取邮箱地址",
|
"get_email_address": "获取邮箱地址",
|
||||||
"register_process_error": "注册流程错误: {error}"
|
"register_process_error": "注册流程错误: {error}",
|
||||||
|
"update_cursor_auth_info": "更新Cursor认证信息"
|
||||||
},
|
},
|
||||||
"auth": {
|
"auth": {
|
||||||
"title": "Cursor 认证管理器",
|
"title": "Cursor 认证管理器",
|
||||||
@@ -81,7 +106,11 @@
|
|||||||
"auth_update_failed": "认证信息更新失败: {error}",
|
"auth_update_failed": "认证信息更新失败: {error}",
|
||||||
"auth_file_created": "认证文件已创建",
|
"auth_file_created": "认证文件已创建",
|
||||||
"auth_file_create_failed": "认证文件创建失败: {error}",
|
"auth_file_create_failed": "认证文件创建失败: {error}",
|
||||||
"press_enter": "按回车键退出"
|
"press_enter": "按回车键退出",
|
||||||
|
"connected_to_database": "已连接到数据库",
|
||||||
|
"database_updated_successfully": "数据库更新成功",
|
||||||
|
"database_connection_closed": "数据库连接已关闭",
|
||||||
|
"updating_pair": "更新键值对"
|
||||||
},
|
},
|
||||||
"control": {
|
"control": {
|
||||||
"generate_email": "生成新邮箱",
|
"generate_email": "生成新邮箱",
|
||||||
|
|||||||
@@ -26,6 +26,30 @@
|
|||||||
"timeout": "以下進程未能在規定時間內關閉: {pids}",
|
"timeout": "以下進程未能在規定時間內關閉: {pids}",
|
||||||
"error": "關閉 Cursor 進程時發生錯誤: {error}"
|
"error": "關閉 Cursor 進程時發生錯誤: {error}"
|
||||||
},
|
},
|
||||||
|
"reset": {
|
||||||
|
"title": "Cursor 機器標識重置工具",
|
||||||
|
"checking": "檢查配置文件",
|
||||||
|
"not_found": "配置文件未找到",
|
||||||
|
"no_permission": "無法讀取或寫入配置文件,請檢查文件權限",
|
||||||
|
"reading": "讀取當前配置",
|
||||||
|
"creating_backup": "創建配置備份",
|
||||||
|
"backup_exists": "備份文件已存在,跳過備份步驟",
|
||||||
|
"generating": "生成新機器標識",
|
||||||
|
"saving_json": "保存新配置到JSON",
|
||||||
|
"success": "機器標識重置成功",
|
||||||
|
"new_id": "新機器標識",
|
||||||
|
"permission_error": "權限錯誤: {error}",
|
||||||
|
"run_as_admin": "請嘗試以管理員身份運行此程序",
|
||||||
|
"process_error": "重置進程錯誤: {error}",
|
||||||
|
"updating_sqlite": "更新SQLite數據庫",
|
||||||
|
"updating_pair": "更新鍵值對",
|
||||||
|
"sqlite_success": "SQLite數據庫更新成功",
|
||||||
|
"sqlite_error": "SQLite數據庫更新失敗: {error}",
|
||||||
|
"press_enter": "按回車鍵退出",
|
||||||
|
"updating_system_ids": "更新系統ID",
|
||||||
|
"system_ids_updated": "系統ID更新成功",
|
||||||
|
"system_ids_update_failed": "系統ID更新失敗: {error}"
|
||||||
|
},
|
||||||
"register": {
|
"register": {
|
||||||
"title": "Cursor 註冊工具",
|
"title": "Cursor 註冊工具",
|
||||||
"start": "開始註冊流程",
|
"start": "開始註冊流程",
|
||||||
@@ -68,7 +92,8 @@
|
|||||||
"account_info_saved": "賬戶信息已保存",
|
"account_info_saved": "賬戶信息已保存",
|
||||||
"save_account_info_failed": "保存賬戶信息失敗",
|
"save_account_info_failed": "保存賬戶信息失敗",
|
||||||
"get_email_address": "獲取郵箱地址",
|
"get_email_address": "獲取郵箱地址",
|
||||||
"register_process_error": "註冊流程錯誤: {error}"
|
"register_process_error": "註冊流程錯誤: {error}",
|
||||||
|
"update_cursor_auth_info": "更新Cursor認證信息"
|
||||||
},
|
},
|
||||||
"auth": {
|
"auth": {
|
||||||
"title": "Cursor 認證管理器",
|
"title": "Cursor 認證管理器",
|
||||||
@@ -81,7 +106,11 @@
|
|||||||
"auth_update_failed": "認證信息更新失敗: {error}",
|
"auth_update_failed": "認證信息更新失敗: {error}",
|
||||||
"auth_file_created": "認證文件已創建",
|
"auth_file_created": "認證文件已創建",
|
||||||
"auth_file_create_failed": "認證文件創建失敗: {error}",
|
"auth_file_create_failed": "認證文件創建失敗: {error}",
|
||||||
"press_enter": "按回車鍵退出"
|
"press_enter": "按回車鍵退出",
|
||||||
|
"connected_to_database": "已連接到數據庫",
|
||||||
|
"database_updated_successfully": "數據庫更新成功",
|
||||||
|
"database_connection_closed": "數據庫連接已關閉",
|
||||||
|
"updating_pair": "更新鍵值對"
|
||||||
},
|
},
|
||||||
"control": {
|
"control": {
|
||||||
"generate_email": "生成新郵箱",
|
"generate_email": "生成新郵箱",
|
||||||
|
|||||||
11
logo.py
11
logo.py
@@ -2,8 +2,14 @@ from colorama import Fore, Style, init
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# 加載環境變量獲取版本號
|
# 獲取當前腳本所在目錄
|
||||||
load_dotenv()
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
# 構建.env文件的完整路徑
|
||||||
|
env_path = os.path.join(current_dir, '.env')
|
||||||
|
|
||||||
|
# 加載環境變量,指定.env文件路徑
|
||||||
|
load_dotenv(env_path)
|
||||||
|
# 獲取版本號,如果未找到則使用默認值
|
||||||
version = os.getenv('VERSION', '1.0.0')
|
version = os.getenv('VERSION', '1.0.0')
|
||||||
|
|
||||||
# 初始化 colorama
|
# 初始化 colorama
|
||||||
@@ -29,6 +35,5 @@ CURSOR_LOGO = f"""
|
|||||||
def print_logo():
|
def print_logo():
|
||||||
print(CURSOR_LOGO)
|
print(CURSOR_LOGO)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print_logo()
|
print_logo()
|
||||||
16
main.py
16
main.py
@@ -42,11 +42,17 @@ class Translator:
|
|||||||
|
|
||||||
def get(self, key, **kwargs):
|
def get(self, key, **kwargs):
|
||||||
"""获取翻译文本"""
|
"""获取翻译文本"""
|
||||||
keys = key.split('.')
|
try:
|
||||||
value = self.translations.get(self.current_language, {})
|
keys = key.split('.')
|
||||||
for k in keys:
|
value = self.translations.get(self.current_language, {})
|
||||||
value = value.get(k, key)
|
for k in keys:
|
||||||
return value.format(**kwargs) if kwargs else value
|
if isinstance(value, dict):
|
||||||
|
value = value.get(k, key)
|
||||||
|
else:
|
||||||
|
return key # 如果中間值不是字典,返回原始key
|
||||||
|
return value.format(**kwargs) if kwargs else value
|
||||||
|
except Exception:
|
||||||
|
return key # 出現任何錯誤時返回原始key
|
||||||
|
|
||||||
def set_language(self, lang_code):
|
def set_language(self, lang_code):
|
||||||
"""设置当前语言"""
|
"""设置当前语言"""
|
||||||
|
|||||||
@@ -5,8 +5,20 @@ import uuid
|
|||||||
import hashlib
|
import hashlib
|
||||||
import shutil
|
import shutil
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
import logging
|
||||||
from colorama import Fore, Style, init
|
from colorama import Fore, Style, init
|
||||||
|
|
||||||
|
# 设置日志记录
|
||||||
|
logging.basicConfig(
|
||||||
|
level=logging.INFO,
|
||||||
|
format='%(asctime)s - %(levelname)s - %(message)s',
|
||||||
|
handlers=[
|
||||||
|
logging.StreamHandler(),
|
||||||
|
logging.FileHandler('reset_machine.log', encoding='utf-8')
|
||||||
|
]
|
||||||
|
)
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# 初始化colorama
|
# 初始化colorama
|
||||||
init()
|
init()
|
||||||
|
|
||||||
@@ -98,7 +110,7 @@ class MachineIDResetter:
|
|||||||
INSERT OR REPLACE INTO ItemTable (key, value)
|
INSERT OR REPLACE INTO ItemTable (key, value)
|
||||||
VALUES (?, ?)
|
VALUES (?, ?)
|
||||||
""", (key, value))
|
""", (key, value))
|
||||||
print(f"{EMOJI['INFO']} {Fore.CYAN}{self.translator.get('reset.updating_pair')}: {key}{Style.RESET_ALL}")
|
print(f"{EMOJI['INFO']} {Fore.CYAN} {self.translator.get('reset.updating_pair')}: {key}{Style.RESET_ALL}")
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
@@ -109,6 +121,60 @@ class MachineIDResetter:
|
|||||||
print(f"{Fore.RED}{EMOJI['ERROR']} {self.translator.get('reset.sqlite_error', error=str(e))}{Style.RESET_ALL}")
|
print(f"{Fore.RED}{EMOJI['ERROR']} {self.translator.get('reset.sqlite_error', error=str(e))}{Style.RESET_ALL}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def update_system_ids(self, new_ids):
|
||||||
|
"""更新系统级别的ID"""
|
||||||
|
try:
|
||||||
|
print(f"{Fore.CYAN}{EMOJI['INFO']} {self.translator.get('reset.updating_system_ids')}...{Style.RESET_ALL}")
|
||||||
|
|
||||||
|
if sys.platform.startswith("win"):
|
||||||
|
self._update_windows_machine_guid()
|
||||||
|
elif sys.platform == "darwin":
|
||||||
|
self._update_macos_platform_uuid(new_ids)
|
||||||
|
|
||||||
|
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} {self.translator.get('reset.system_ids_updated')}{Style.RESET_ALL}")
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
print(f"{Fore.RED}{EMOJI['ERROR']} {self.translator.get('reset.system_ids_update_failed', error=str(e))}{Style.RESET_ALL}")
|
||||||
|
logger.error(f"System IDs update failed: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _update_windows_machine_guid(self):
|
||||||
|
"""更新Windows MachineGuid"""
|
||||||
|
try:
|
||||||
|
import winreg
|
||||||
|
key = winreg.OpenKey(
|
||||||
|
winreg.HKEY_LOCAL_MACHINE,
|
||||||
|
"SOFTWARE\\Microsoft\\Cryptography",
|
||||||
|
0,
|
||||||
|
winreg.KEY_WRITE | winreg.KEY_WOW64_64KEY
|
||||||
|
)
|
||||||
|
new_guid = str(uuid.uuid4())
|
||||||
|
winreg.SetValueEx(key, "MachineGuid", 0, winreg.REG_SZ, new_guid)
|
||||||
|
winreg.CloseKey(key)
|
||||||
|
logger.info("Windows MachineGuid updated successfully")
|
||||||
|
except PermissionError:
|
||||||
|
logger.error("Permission denied: Run as administrator to update Windows MachineGuid")
|
||||||
|
raise
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to update Windows MachineGuid: {e}")
|
||||||
|
raise
|
||||||
|
|
||||||
|
def _update_macos_platform_uuid(self, new_ids):
|
||||||
|
"""更新macOS Platform UUID"""
|
||||||
|
try:
|
||||||
|
uuid_file = "/var/root/Library/Preferences/SystemConfiguration/com.apple.platform.uuid.plist"
|
||||||
|
if os.path.exists(uuid_file):
|
||||||
|
# 使用sudo来执行plutil命令
|
||||||
|
cmd = f'sudo plutil -replace "UUID" -string "{new_ids["telemetry.macMachineId"]}" "{uuid_file}"'
|
||||||
|
result = os.system(cmd)
|
||||||
|
if result == 0:
|
||||||
|
logger.info("macOS Platform UUID updated successfully")
|
||||||
|
else:
|
||||||
|
raise Exception("Failed to execute plutil command")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to update macOS Platform UUID: {e}")
|
||||||
|
raise
|
||||||
|
|
||||||
def reset_machine_ids(self):
|
def reset_machine_ids(self):
|
||||||
"""重置机器ID并备份原文件"""
|
"""重置机器ID并备份原文件"""
|
||||||
try:
|
try:
|
||||||
@@ -136,14 +202,19 @@ class MachineIDResetter:
|
|||||||
print(f"{Fore.CYAN}{EMOJI['RESET']} {self.translator.get('reset.generating')}...{Style.RESET_ALL}")
|
print(f"{Fore.CYAN}{EMOJI['RESET']} {self.translator.get('reset.generating')}...{Style.RESET_ALL}")
|
||||||
new_ids = self.generate_new_ids()
|
new_ids = self.generate_new_ids()
|
||||||
|
|
||||||
|
# 更新配置文件
|
||||||
config.update(new_ids)
|
config.update(new_ids)
|
||||||
|
|
||||||
print(f"{Fore.CYAN}{EMOJI['FILE']} {self.translator.get('reset.saving_json')}...{Style.RESET_ALL}")
|
print(f"{Fore.CYAN}{EMOJI['FILE']} {self.translator.get('reset.saving_json')}...{Style.RESET_ALL}")
|
||||||
with open(self.db_path, "w", encoding="utf-8") as f:
|
with open(self.db_path, "w", encoding="utf-8") as f:
|
||||||
json.dump(config, f, indent=4)
|
json.dump(config, f, indent=4)
|
||||||
|
|
||||||
|
# 更新SQLite数据库
|
||||||
self.update_sqlite_db(new_ids)
|
self.update_sqlite_db(new_ids)
|
||||||
|
|
||||||
|
# 更新系统ID
|
||||||
|
self.update_system_ids(new_ids)
|
||||||
|
|
||||||
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} {self.translator.get('reset.success')}{Style.RESET_ALL}")
|
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} {self.translator.get('reset.success')}{Style.RESET_ALL}")
|
||||||
print(f"\n{Fore.CYAN}{self.translator.get('reset.new_id')}:{Style.RESET_ALL}")
|
print(f"\n{Fore.CYAN}{self.translator.get('reset.new_id')}:{Style.RESET_ALL}")
|
||||||
for key, value in new_ids.items():
|
for key, value in new_ids.items():
|
||||||
@@ -160,18 +231,17 @@ class MachineIDResetter:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def run(translator=None):
|
def run(translator=None):
|
||||||
"""Main function to be called from main.py"""
|
"""便捷函数,用于直接调用重置功能"""
|
||||||
print(f"\n{Fore.CYAN}{'='*50}{Style.RESET_ALL}")
|
print(f"\n{Fore.CYAN}{'='*50}{Style.RESET_ALL}")
|
||||||
print(f"{Fore.CYAN}{EMOJI['RESET']} {translator.get('reset.title')}{Style.RESET_ALL}")
|
print(f"{Fore.CYAN}{EMOJI['RESET']} {translator.get('reset.title')}{Style.RESET_ALL}")
|
||||||
print(f"{Fore.CYAN}{'='*50}{Style.RESET_ALL}")
|
print(f"{Fore.CYAN}{'='*50}{Style.RESET_ALL}")
|
||||||
|
|
||||||
resetter = MachineIDResetter(translator)
|
resetter = MachineIDResetter(translator) # 正確傳遞 translator
|
||||||
resetter.reset_machine_ids()
|
resetter.reset_machine_ids()
|
||||||
|
|
||||||
print(f"\n{Fore.CYAN}{'='*50}{Style.RESET_ALL}")
|
print(f"\n{Fore.CYAN}{'='*50}{Style.RESET_ALL}")
|
||||||
input(f"{EMOJI['INFO']} {translator.get('reset.press_enter')}...")
|
input(f"{EMOJI['INFO']} {translator.get('reset.press_enter')}...")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# 如果直接运行,使用默认翻译器
|
|
||||||
from main import translator as main_translator
|
from main import translator as main_translator
|
||||||
run(main_translator)
|
run(main_translator)
|
||||||
Reference in New Issue
Block a user