1
+ import os
2
+ import sys
3
+ import shutil
4
+ from cx_Freeze import setup , Executable
5
+ import ttkthemes
6
+ import site
7
+ import pkgutil
8
+ import tkinter
9
+ import _tkinter
10
+
11
+ # 获取tkinter库路径
12
+ tcl_path = os .path .dirname (_tkinter .__file__ )
13
+ tcl_lib = os .path .join (tcl_path , 'tcl8.6' )
14
+ tk_lib = os .path .join (tcl_path , 'tk8.6' )
15
+
16
+ # 获取ttkthemes的主题文件路径
17
+ themes_path = os .path .join (os .path .dirname (ttkthemes .__file__ ), "themes" )
18
+
19
+ # 获取所有主题文件
20
+ theme_files = []
21
+ for root , dirs , files in os .walk (themes_path ):
22
+ for file in files :
23
+ full_path = os .path .join (root , file )
24
+ rel_path = os .path .relpath (full_path , os .path .dirname (ttkthemes .__file__ ))
25
+ theme_files .append ((full_path , os .path .join ("lib" , "ttkthemes" , rel_path )))
26
+
27
+ # 获取所有PIL插件
28
+ pil_plugins = []
29
+ plugin_dir = os .path .join (os .path .dirname (pkgutil .get_loader ("PIL" ).get_filename ()), "plugins" )
30
+ if os .path .exists (plugin_dir ):
31
+ for file in os .listdir (plugin_dir ):
32
+ if file .endswith ('.py' ):
33
+ pil_plugins .append (f"PIL.{ os .path .splitext (file )[0 ]} " )
34
+
35
+ # 添加TCL/TK库文件
36
+ tcl_tk_files = []
37
+ if os .path .exists (tcl_lib ):
38
+ for root , dirs , files in os .walk (tcl_lib ):
39
+ for file in files :
40
+ full_path = os .path .join (root , file )
41
+ rel_path = os .path .relpath (full_path , tcl_lib )
42
+ tcl_tk_files .append ((full_path , os .path .join ("lib" , "tcl8.6" , rel_path )))
43
+
44
+ if os .path .exists (tk_lib ):
45
+ for root , dirs , files in os .walk (tk_lib ):
46
+ for file in files :
47
+ full_path = os .path .join (root , file )
48
+ rel_path = os .path .relpath (full_path , tk_lib )
49
+ tcl_tk_files .append ((full_path , os .path .join ("lib" , "tk8.6" , rel_path )))
50
+
51
+ # 依赖项
52
+ build_exe_options = {
53
+ "packages" : [
54
+ "tkinter" ,
55
+ "ttkthemes" ,
56
+ "psutil" ,
57
+ "requests" ,
58
+ "PIL" ,
59
+ "json" ,
60
+ "uuid" ,
61
+ "logging" ,
62
+ "webbrowser" ,
63
+ "threading" ,
64
+ "datetime" ,
65
+ "platform" ,
66
+ "shutil" ,
67
+ "ctypes" ,
68
+ "urllib3" ,
69
+ "idna" ,
70
+ "certifi" ,
71
+ "chardet" ,
72
+ "win32api" ,
73
+ "win32con" ,
74
+ "win32gui" ,
75
+ ] + pil_plugins ,
76
+ "includes" : [
77
+ "tkinter.ttk" ,
78
+ "PIL._tkinter_finder" ,
79
+ "ttkthemes.themed_tk" ,
80
+ "pkg_resources" ,
81
+ "appdirs" ,
82
+ ],
83
+ "include_files" : [
84
+ ("cursor_reset_plus.manifest" , "cursor_reset_plus.manifest" ),
85
+ ("LICENSE" , "LICENSE" ),
86
+ ("README.md" , "README.md" ),
87
+ ("requirements.txt" , "requirements.txt" ),
88
+ ("icon.ico" , "icon.ico" ),
89
+ ] + theme_files + tcl_tk_files ,
90
+ "include_msvcr" : True ,
91
+ "zip_include_packages" : "*" ,
92
+ "zip_exclude_packages" : [],
93
+ "excludes" : ["test" , "unittest" , "pdb" , "pydev" , "pydevd" ],
94
+ "optimize" : 2 ,
95
+ "build_exe" : "dist/CursorResetPlus"
96
+ }
97
+
98
+ # 目标文件
99
+ base = None
100
+ if sys .platform == "win32" :
101
+ base = "Win32GUI" # 使用Windows GUI
102
+
103
+ # 创建可执行文件
104
+ setup (
105
+ name = "Cursor Reset Plus" ,
106
+ version = "2.0.0" ,
107
+ description = "Cursor Reset Plus - 重置 Cursor IDE 设备标识的跨平台工具" ,
108
+ options = {"build_exe" : build_exe_options },
109
+ executables = [
110
+ Executable (
111
+ "cursor_reset_plus.py" ,
112
+ base = base ,
113
+ target_name = "CursorResetPlus.exe" ,
114
+ icon = "icon.ico" if os .path .exists ("icon.ico" ) else None ,
115
+ manifest = "cursor_reset_plus.manifest" ,
116
+ shortcut_name = "Cursor Reset Plus" ,
117
+ shortcut_dir = "DesktopFolder" ,
118
+ copyright = "Copyright © 2024" ,
119
+ uac_admin = True # 请求管理员权限
120
+ )
121
+ ]
122
+ )
0 commit comments