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")