update 2024/9/26
This commit is contained in:
parent
c807b47bd3
commit
8cfe7ac063
@ -5,13 +5,22 @@ from time import sleep
|
|||||||
import shelve
|
import shelve
|
||||||
|
|
||||||
|
|
||||||
def get_path(relative_path):
|
# 检查并创建cmd文件的函数
|
||||||
try:
|
def check_and_create_cmd_files(path):
|
||||||
path = sys._MEIPASS # pyinstaller 打包后的路径
|
csso_cmd_path = os.path.join(path, 'csso.cmd')
|
||||||
except AttributeError:
|
css_cmd_path = os.path.join(path, 'css.cmd')
|
||||||
path = os.path.abspath(".") # 当前工作目录的路径
|
|
||||||
|
|
||||||
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:
|
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')
|
bin_name = db.get('bin_name', '1')
|
||||||
|
|
||||||
if bin_name is None:
|
if bin_name is None:
|
||||||
os.startfile(get_path('load.exe'))
|
bin_name = '1' # 这里设为字符串以保持一致
|
||||||
|
db['bin_name'] = bin_name
|
||||||
|
|
||||||
|
|
||||||
def is_admin():
|
def is_admin():
|
||||||
@ -39,16 +49,18 @@ if is_admin():
|
|||||||
|
|
||||||
choice = input('>>> ')
|
choice = input('>>> ')
|
||||||
|
|
||||||
path = get_path('') # 获取当前工作目录的实际路径
|
path = os.getcwd() # 获取当前工作目录的实际路径
|
||||||
|
|
||||||
|
# 检查并创建cmd文件
|
||||||
|
check_and_create_cmd_files(path)
|
||||||
|
|
||||||
if choice == '1':
|
if choice == '1':
|
||||||
if bin_name == '2':
|
if bin_name == '2':
|
||||||
print('错误,你已是CS:SO!')
|
print('错误,你已是CS:SO!')
|
||||||
sleep(1.5)
|
sleep(1.5)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
# 切换到 CS:SO
|
# 启动 csso.cmd
|
||||||
os.system(f"ren {path}/bin {path}/bin1")
|
os.startfile(os.path.join(path, 'csso.cmd'))
|
||||||
os.system(f"ren {path}/bin2 {path}/bin")
|
|
||||||
with shelve.open('main.db') as db:
|
with shelve.open('main.db') as db:
|
||||||
db['bin_name'] = '2' # 切换至 CS:SO
|
db['bin_name'] = '2' # 切换至 CS:SO
|
||||||
print("完成!")
|
print("完成!")
|
||||||
@ -60,9 +72,8 @@ if is_admin():
|
|||||||
print("错误,你已是原版!")
|
print("错误,你已是原版!")
|
||||||
sleep(1.5)
|
sleep(1.5)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
# 切换到原版 CS
|
# 启动 css.cmd
|
||||||
os.system(f"ren {path}/bin {path}/bin2")
|
os.startfile(os.path.join(path, 'css.cmd'))
|
||||||
os.system(f"ren {path}/bin1 {path}/bin")
|
|
||||||
with shelve.open('main.db') as db:
|
with shelve.open('main.db') as db:
|
||||||
db['bin_name'] = '1' # 切换至 CS 原版
|
db['bin_name'] = '1' # 切换至 CS 原版
|
||||||
print("完成!")
|
print("完成!")
|
||||||
@ -79,4 +90,4 @@ else:
|
|||||||
# 如果没有管理员权限,重新以管理员权限运行脚本
|
# 如果没有管理员权限,重新以管理员权限运行脚本
|
||||||
print("请求管理员权限...")
|
print("请求管理员权限...")
|
||||||
# 使用 `ctypes` 模块提升权限,重新运行脚本
|
# 使用 `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)
|
@ -1,8 +0,0 @@
|
|||||||
import shelve
|
|
||||||
|
|
||||||
#初始化数据库文件
|
|
||||||
with shelve.open('main') as db:
|
|
||||||
db['bin_name'] = 1
|
|
||||||
db.close()
|
|
||||||
|
|
||||||
exit()
|
|
Loading…
x
Reference in New Issue
Block a user