license_manager.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import json
  2. import os
  3. class LicenseManager:
  4. def __init__(self):
  5. self.license_file = os.path.join(
  6. os.getenv("APPDATA"), "CursorPro", "license.json"
  7. )
  8. self.max_uses = 10 # 最大使用次数
  9. def check_license(self):
  10. try:
  11. # 确保目录存在
  12. os.makedirs(os.path.dirname(self.license_file), exist_ok=True)
  13. if not os.path.exists(self.license_file):
  14. # 首次运行,创建许可文件
  15. license_data = {"use_count": 0, "is_activated": False}
  16. with open(self.license_file, "w") as f:
  17. json.dump(license_data, f)
  18. return True
  19. # 读取许可信息
  20. with open(self.license_file, "r") as f:
  21. license_data = json.load(f)
  22. if license_data.get("is_activated"):
  23. return True
  24. # 检查使用次数
  25. use_count = license_data.get("use_count", 0)
  26. if use_count >= self.max_uses:
  27. return False
  28. # 增加使用次数并保存
  29. license_data["use_count"] = use_count + 1
  30. with open(self.license_file, "w") as f:
  31. json.dump(license_data, f)
  32. return True
  33. except Exception as e:
  34. print(f"License check error: {e}")
  35. return False