fix:尝试修复大部分人遇到的闪退问题

This commit is contained in:
ikun
2024-09-07 18:40:13 +08:00
parent 6ec83c4196
commit 7352f20eb4
4 changed files with 43 additions and 22 deletions

View File

@@ -1,11 +1,12 @@
import ujson as json
import aiofiles
from . import log
from . import log, stack_error
import os
import sys
import asyncio
log = log.log
stack_error = stack_error.stack_error
# 生成配置文件
async def gen_config_file():
@@ -29,8 +30,14 @@ async def load_config():
os.system('pause')
sys.exit()
else:
async with aiofiles.open("./config.json", mode="r", encoding="utf-8") as f:
config = json.loads(await f.read())
return config
try:
async with aiofiles.open("./config.json", mode="r", encoding="utf-8") as f:
config = json.loads(await f.read())
return config
except Exception as e:
log.error(f"配置文件加载失败,原因: {stack_error(e)}")
os.remove("./config.json")
os.system('pause')
config = asyncio.run(load_config())

View File

@@ -1,17 +1,24 @@
import winreg
import os
from common import log, config, stack_error
from pathlib import Path
from common import config
stack_error = stack_error.stack_error
config = config.config
log = log.log
# 通过注册表获取Steam安装路径
def get_steam_path():
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Software\Valve\Steam')
steam_path = Path(winreg.QueryValueEx(key, 'SteamPath')[0])
custom_steam_path = config["Custom_Steam_Path"]
if not custom_steam_path == '':
return Path(custom_steam_path)
else:
return steam_path
try:
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Software\Valve\Steam')
steam_path = Path(winreg.QueryValueEx(key, 'SteamPath')[0])
custom_steam_path = config["Custom_Steam_Path"]
if not custom_steam_path == '':
return Path(custom_steam_path)
else:
return steam_path
except Exception as e:
log.error(f'Steam路径获取失败, {stack_error(e)}')
os.system('pause')
steam_path = get_steam_path()

View File

@@ -15,8 +15,12 @@ def migrate():
old_file = os.path.join(directory, filename)
new_file = os.path.join(directory, new_filename)
os.rename(old_file, new_file)
log.info(f'Renamed: {filename} -> {new_filename}')
migrate = migrate
try:
# 使用 os.replace 进行强制替换
os.replace(old_file, new_file)
log.info(f'Renamed: {filename} -> {new_filename}')
except Exception as e:
log.error(f'Failed to rename {filename} -> {new_filename}: {e}')
migrate = migrate

15
main.py
View File

@@ -4,6 +4,7 @@ import aiofiles
import traceback
import time
import asyncio
import time
from common import log, config, getsteampath, stunlock, glunlock, stack_error, manifestdown, dkey_merge, migration
from aiohttp import ClientSession
from pathlib import Path
@@ -30,7 +31,7 @@ print('\033[1;32;40m | |_| | | | \\ | | |___ | | \\ \\ | |___ / /' + '\033
print('\033[1;32;40m \\_____/ |_| \\_| |_____| |_| \\_\\ |_____| /_/' + '\033[0m')
log.info('作者ikun0014')
log.info('本项目基于wxy1343/ManifestAutoUpdate进行修改采用ACSL许可证')
log.info('版本1.1.7')
log.info('版本1.1.8')
log.info('项目仓库https://github.com/ikunshare/Onekey')
log.info('官网ikunshare.com')
log.warning('本项目完全开源免费如果你在淘宝QQ群内通过购买方式获得赶紧回去骂商家死全家\n交流群组:\n点击链接加入群聊【𝗶𝗸𝘂𝗻分享】https://qm.qq.com/q/d7sWovfAGI\nhttps://t.me/ikunshare_group')
@@ -154,11 +155,13 @@ repos = [
if __name__ == '__main__':
try:
migration()
log.info('App ID可以在SteamDB或Steam商店链接页面查看')
app_id = input("请输入游戏AppID").strip()
asyncio.run(main(app_id))
while True:
log.info('App ID可以在SteamDB或Steam商店链接页面查看')
app_id = input("请输入游戏AppID").strip()
asyncio.run(main(app_id))
except KeyboardInterrupt:
exit()
except Exception as e:
log.error(f' ⚠ 发生错误: {stack_error(e)}')
traceback.print_exc()
log.error(f' ⚠ 发生错误: {stack_error(e)}将在5秒后退出')
time.sleep(5)
os.system('pause')