feat: 增加使用限制
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
45
license_manager.py
Normal file
45
license_manager.py
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user