From 8728e0bff3ce190010e4bcacf19215cfed2b15e0 Mon Sep 17 00:00:00 2001 From: chengchongzhen <15939054361@163.com> Date: Mon, 30 Dec 2024 12:55:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cursor_pro_keep_alive.py | 9 ++++++++ license_manager.py | 45 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 license_manager.py diff --git a/cursor_pro_keep_alive.py b/cursor_pro_keep_alive.py index 665cd0f..9631de2 100644 --- a/cursor_pro_keep_alive.py +++ b/cursor_pro_keep_alive.py @@ -1,5 +1,7 @@ import os +from license_manager import LicenseManager + os.environ["PYTHONVERBOSE"] = "0" os.environ["PYINSTALLER_VERBOSE"] = "0" @@ -346,7 +348,14 @@ def cleanup_temp_files(): if __name__ == "__main__": browser_manager = None + license_manager = None try: + # 检查许可证 + license_manager = LicenseManager() + if not license_manager.check_license(): + print("免费使用次数已用完") + sys.exit(1) + # 加载配置 config = load_config() diff --git a/license_manager.py b/license_manager.py new file mode 100644 index 0000000..02a5e5d --- /dev/null +++ b/license_manager.py @@ -0,0 +1,45 @@ +import json +import os + + +class LicenseManager: + def __init__(self): + self.license_file = os.path.join( + os.getenv("APPDATA"), "CursorPro", "license.json" + ) + self.max_uses = 10 # 最大使用次数 + + def check_license(self): + try: + # 确保目录存在 + os.makedirs(os.path.dirname(self.license_file), exist_ok=True) + + if not os.path.exists(self.license_file): + # 首次运行,创建许可文件 + license_data = {"use_count": 0, "is_activated": False} + with open(self.license_file, "w") as f: + json.dump(license_data, f) + return True + + # 读取许可信息 + with open(self.license_file, "r") as f: + license_data = json.load(f) + + if license_data.get("is_activated"): + return True + + # 检查使用次数 + use_count = license_data.get("use_count", 0) + if use_count >= self.max_uses: + return False + + # 增加使用次数并保存 + license_data["use_count"] = use_count + 1 + with open(self.license_file, "w") as f: + json.dump(license_data, f) + + return True + + except Exception as e: + print(f"License check error: {e}") + return False