diff --git a/common/config.py b/common/config.py index daf82d5..84f4add 100644 --- a/common/config.py +++ b/common/config.py @@ -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()) \ No newline at end of file diff --git a/common/getsteampath.py b/common/getsteampath.py index af7404b..6e39895 100644 --- a/common/getsteampath.py +++ b/common/getsteampath.py @@ -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() \ No newline at end of file diff --git a/common/migration.py b/common/migration.py index f35c37e..43a02cf 100644 --- a/common/migration.py +++ b/common/migration.py @@ -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 \ No newline at end of file diff --git a/main.py b/main.py index 08f6ac6..32b6b29 100644 --- a/main.py +++ b/main.py @@ -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() \ No newline at end of file + log.error(f' ⚠ 发生错误: {stack_error(e)},将在5秒后退出') + time.sleep(5) + os.system('pause') \ No newline at end of file