From 8cfe7ac0630ef446965315ff05b4aa4ff68152de Mon Sep 17 00:00:00 2001 From: dengrb1 Date: Fri, 27 Sep 2024 22:26:31 +0800 Subject: [PATCH] update 2024/9/26 --- change/change.py | 41 ++++++++++++++++++++++++++--------------- change/load.py | 8 -------- 2 files changed, 26 insertions(+), 23 deletions(-) delete mode 100644 change/load.py diff --git a/change/change.py b/change/change.py index 41b3fd8..3e98a1e 100644 --- a/change/change.py +++ b/change/change.py @@ -5,13 +5,22 @@ from time import sleep import shelve -def get_path(relative_path): - try: - path = sys._MEIPASS # pyinstaller 打包后的路径 - except AttributeError: - path = os.path.abspath(".") # 当前工作目录的路径 +# 检查并创建cmd文件的函数 +def check_and_create_cmd_files(path): + csso_cmd_path = os.path.join(path, 'csso.cmd') + css_cmd_path = os.path.join(path, 'css.cmd') - return os.path.normpath(os.path.join(path, relative_path)) # 返回实际路径 + if not os.path.isfile(csso_cmd_path): + with open(csso_cmd_path, 'w') as csso_file: + csso_file.write('@echo off\n') + csso_file.write('ren bin bin1\n') + csso_file.write('ren bin2 bin\n') + + if not os.path.isfile(css_cmd_path): + with open(css_cmd_path, 'w') as css_file: + css_file.write('@echo off\n') + css_file.write('ren bin bin2\n') + css_file.write('ren bin1 bin\n') with shelve.open('main.db') as db: @@ -19,7 +28,8 @@ with shelve.open('main.db') as db: bin_name = db.get('bin_name', '1') if bin_name is None: - os.startfile(get_path('load.exe')) + bin_name = '1' # 这里设为字符串以保持一致 + db['bin_name'] = bin_name def is_admin(): @@ -39,16 +49,18 @@ if is_admin(): choice = input('>>> ') - path = get_path('') # 获取当前工作目录的实际路径 + path = os.getcwd() # 获取当前工作目录的实际路径 + + # 检查并创建cmd文件 + check_and_create_cmd_files(path) if choice == '1': if bin_name == '2': print('错误,你已是CS:SO!') sleep(1.5) sys.exit() - # 切换到 CS:SO - os.system(f"ren {path}/bin {path}/bin1") - os.system(f"ren {path}/bin2 {path}/bin") + # 启动 csso.cmd + os.startfile(os.path.join(path, 'csso.cmd')) with shelve.open('main.db') as db: db['bin_name'] = '2' # 切换至 CS:SO print("完成!") @@ -60,9 +72,8 @@ if is_admin(): print("错误,你已是原版!") sleep(1.5) sys.exit() - # 切换到原版 CS - os.system(f"ren {path}/bin {path}/bin2") - os.system(f"ren {path}/bin1 {path}/bin") + # 启动 css.cmd + os.startfile(os.path.join(path, 'css.cmd')) with shelve.open('main.db') as db: db['bin_name'] = '1' # 切换至 CS 原版 print("完成!") @@ -79,4 +90,4 @@ else: # 如果没有管理员权限,重新以管理员权限运行脚本 print("请求管理员权限...") # 使用 `ctypes` 模块提升权限,重新运行脚本 - ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1) + ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1) \ No newline at end of file diff --git a/change/load.py b/change/load.py deleted file mode 100644 index 580cf3f..0000000 --- a/change/load.py +++ /dev/null @@ -1,8 +0,0 @@ -import shelve - -#初始化数据库文件 -with shelve.open('main') as db: - db['bin_name'] = 1 - db.close() - -exit() \ No newline at end of file