From 3386d8e08e4428aeb3bdf5e55866c2f25b66ca16 Mon Sep 17 00:00:00 2001 From: AmzGrainRain Date: Thu, 1 May 2025 14:37:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20windows=20=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E4=B8=8B=E7=94=A8=E6=88=B7=E7=9B=AE=E5=BD=95=E7=9A=84?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bypass_token_limit.py | 9 ++++++++- new_signup.py | 9 ++++++++- reset_machine_manual.py | 9 ++++++++- totally_reset_cursor.py | 8 +++++++- utils.py | 11 ++++++++++- 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/bypass_token_limit.py b/bypass_token_limit.py index dd04517..7d8125c 100644 --- a/bypass_token_limit.py +++ b/bypass_token_limit.py @@ -26,7 +26,14 @@ EMOJI = { def get_user_documents_path(): """Get user Documents folder path""" if sys.platform == "win32": - return os.path.join(os.path.expanduser("~"), "Documents") + try: + import winreg + with winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders") as key: + documents_path, _ = winreg.QueryValueEx(key, "Personal") + return documents_path + except Exception as e: + # fallback + return os.path.join(os.path.expanduser("~"), "Documents") elif sys.platform == "darwin": return os.path.join(os.path.expanduser("~"), "Documents") else: # Linux diff --git a/new_signup.py b/new_signup.py index e24f487..5f0b686 100644 --- a/new_signup.py +++ b/new_signup.py @@ -116,7 +116,14 @@ def fill_signup_form(page, first_name, last_name, email, config, translator=None def get_user_documents_path(): """Get user Documents folder path""" if sys.platform == "win32": - return os.path.join(os.path.expanduser("~"), "Documents") + try: + import winreg + with winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders") as key: + documents_path, _ = winreg.QueryValueEx(key, "Personal") + return documents_path + except Exception as e: + # fallback + return os.path.join(os.path.expanduser("~"), "Documents") elif sys.platform == "darwin": return os.path.join(os.path.expanduser("~"), "Documents") else: # Linux diff --git a/reset_machine_manual.py b/reset_machine_manual.py index e581c75..8d7c2c8 100644 --- a/reset_machine_manual.py +++ b/reset_machine_manual.py @@ -33,7 +33,14 @@ EMOJI = { def get_user_documents_path(): """Get user Documents folder path""" if sys.platform == "win32": - return os.path.join(os.path.expanduser("~"), "Documents") + try: + import winreg + with winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders") as key: + documents_path, _ = winreg.QueryValueEx(key, "Personal") + return documents_path + except Exception as e: + # fallback + return os.path.join(os.path.expanduser("~"), "Documents") elif sys.platform == "darwin": return os.path.join(os.path.expanduser("~"), "Documents") else: # Linux diff --git a/totally_reset_cursor.py b/totally_reset_cursor.py index 00c1f0b..2fb260f 100644 --- a/totally_reset_cursor.py +++ b/totally_reset_cursor.py @@ -32,7 +32,13 @@ EMOJI = { def get_user_documents_path(): """Get user Documents folder path""" if sys.platform == "win32": - return os.path.join(os.path.expanduser("~"), "Documents") + try: + import winreg + with winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders") as key: + documents_path, _ = winreg.QueryValueEx(key, "Personal") + return documents_path + except Exception as e: + return os.path.join(os.path.expanduser("~"), "Documents") elif sys.platform == "darwin": return os.path.join(os.path.expanduser("~"), "Documents") else: # Linux diff --git a/utils.py b/utils.py index 8922f86..1d22979 100644 --- a/utils.py +++ b/utils.py @@ -6,7 +6,16 @@ import random def get_user_documents_path(): """Get user documents path""" if platform.system() == "Windows": - return os.path.expanduser("~\\Documents") + try: + import winreg + # 打开注册表 + with winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders") as key: + # 获取 "Personal" 键的值,这指向用户的文档目录 + documents_path, _ = winreg.QueryValueEx(key, "Personal") + return documents_path + except Exception as e: + # fallback + return os.path.expanduser("~\\Documents") else: return os.path.expanduser("~/Documents")