update 2024/9/28

This commit is contained in:
Dengrb 2024-09-28 18:24:08 +08:00
parent 6753a1dc3d
commit 82f009baed
8 changed files with 42 additions and 53 deletions

3
.idea/.gitignore generated vendored
View File

@ -1,3 +0,0 @@
# 默认忽略的文件
/shelf/
/workspace.xml

View File

@ -1,6 +0,0 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml generated
View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.11" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated
View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/python.iml" filepath="$PROJECT_DIR$/.idea/python.iml" />
</modules>
</component>
</project>

8
.idea/python.iml generated
View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml generated
View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -1,4 +1,6 @@
import ctypes import ctypes
import winreg
import shutil
import sys import sys
import os import os
from time import sleep from time import sleep
@ -9,12 +11,6 @@ import shelve
def check_and_create_cmd_files(path): def check_and_create_cmd_files(path):
csso_cmd_path = os.path.join(path, 'csso.cmd') csso_cmd_path = os.path.join(path, 'csso.cmd')
css_cmd_path = os.path.join(path, 'css.cmd') css_cmd_path = os.path.join(path, 'css.cmd')
hl2_exe_path = os.path.join(path, "hl2.exe")
if not os.path.isfile(hl2_exe_path):
print('请把文件放置在游戏根目录下!')
sleep(1)
sys.exit()
if not os.path.isfile(csso_cmd_path): if not os.path.isfile(csso_cmd_path):
with open(csso_cmd_path, 'w') as csso_file: with open(csso_cmd_path, 'w') as csso_file:
@ -28,8 +24,27 @@ def check_and_create_cmd_files(path):
css_file.write('ren bin bin2\n') css_file.write('ren bin bin2\n')
css_file.write('ren bin1 bin\n') css_file.write('ren bin1 bin\n')
def get_steam_path():
try:
# 从注册表读取 Steam 安装路径
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Valve\Steam") as key:
steam_path, _ = winreg.QueryValueEx(key, "SteamPath")
return steam_path
except FileNotFoundError:
print("未能找到 Steam 安装路径。")
return None
with shelve.open('main.db') as db: def delete_csso_folder(steam_path):
target_folder = os.path.join(steam_path, "steamapps", "sourcemods", "csso")
if os.path.exists(target_folder):
print(f"正在删除文件夹: {target_folder}")
shutil.rmtree(target_folder) # 递归删除文件夹及其内容
print("文件夹已删除。")
else:
print(f"文件夹不存在: {target_folder}")
with shelve.open('main') as db:
# 如果数据库中没有 'bin_name',返回 '1'(默认值) # 如果数据库中没有 'bin_name',返回 '1'(默认值)
bin_name = db.get('bin_name', '1') bin_name = db.get('bin_name', '1')
@ -37,7 +52,6 @@ with shelve.open('main.db') as db:
bin_name = '1' # 这里设为字符串以保持一致 bin_name = '1' # 这里设为字符串以保持一致
db['bin_name'] = bin_name db['bin_name'] = bin_name
def is_admin(): def is_admin():
"""检查当前是否有管理员权限""" """检查当前是否有管理员权限"""
try: try:
@ -45,7 +59,6 @@ def is_admin():
except: except:
return False return False
if is_admin(): if is_admin():
# 如果已经是管理员,执行主要的逻辑 # 如果已经是管理员,执行主要的逻辑
print("已获得管理员权限") print("已获得管理员权限")
@ -56,7 +69,7 @@ if is_admin():
print(f"当前模式(1为CS原版, 2为CS:SO): {bin_name}") print(f"当前模式(1为CS原版, 2为CS:SO): {bin_name}")
print("请选择模式") print("请选择模式")
print("1. 改为CS:SO\n2. 改回原版\n3. 退出") print("1. 改为CS:SO\n2. 改回原版\n3. 删除CSSO并删除程序\n4. 退出")
choice = input('>>> ') choice = input('>>> ')
@ -67,12 +80,11 @@ if is_admin():
sys.exit() sys.exit()
# 启动 csso.cmd # 启动 csso.cmd
os.startfile(os.path.join(path, 'csso.cmd')) os.startfile(os.path.join(path, 'csso.cmd'))
with shelve.open('main.db') as db: with shelve.open('main') as db:
db['bin_name'] = '2' # 切换至 CS:SO db['bin_name'] = '2' # 切换至 CS:SO
print("完成!") print("完成!")
sleep(1.85) sleep(1.85)
sys.exit() sys.exit()
elif choice == '2': elif choice == '2':
if bin_name == '1': if bin_name == '1':
print("错误,你已是原版!") print("错误,你已是原版!")
@ -80,15 +92,30 @@ if is_admin():
sys.exit() sys.exit()
# 启动 css.cmd # 启动 css.cmd
os.startfile(os.path.join(path, 'css.cmd')) os.startfile(os.path.join(path, 'css.cmd'))
with shelve.open('main.db') as db: with shelve.open('main') as db:
db['bin_name'] = '1' # 切换至 CS 原版 db['bin_name'] = '1' # 切换至 CS 原版
print("完成!") print("完成!")
sleep(1.55) sleep(1.55)
sys.exit() sys.exit()
elif choice == '3': elif choice == '3':
sys.exit() if input('确定吗?\n 1.确定 2.不确定\n>>>') == '1':
with open('del.cmd','w') as d:
d.write('@echo off\n')
d.write('timeout /t 2 /nobreak > nul\n')
d.write('del /Q csso.cmd css.cmd change.exe main.bak main.dat main.dir\n')
d.write('del "%~f0"')
if bin_name != '1':
os.startfile(path,'css.cmd')
steam_path = get_steam_path()
if steam_path:
delete_csso_folder(steam_path)
os.rmdir(f'{path}\\bin2')
os.startfile(os.path.join(path , 'del.cmd'))
else:
sys.exit()
elif choice == '4':
sys.exit()
else: else:
print("输入错误!") print("输入错误!")

0
dist/.keep vendored
View File