update 2024/9/26

This commit is contained in:
Dengrb 2024-09-27 22:26:31 +08:00
parent c807b47bd3
commit 8cfe7ac063
2 changed files with 26 additions and 23 deletions

View File

@ -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("完成!")

View File

@ -1,8 +0,0 @@
import shelve
#初始化数据库文件
with shelve.open('main') as db:
db['bin_name'] = 1
db.close()
exit()