Files
Onekey/common/config.py
2024-10-12 20:06:27 +08:00

43 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
import sys
import asyncio
import ujson as json
import aiofiles
from .stack_error import stack_error
from .log import log
DEFAULT_CONFIG = {
"Github_Personal_Token": "",
"Custom_Steam_Path": "",
"QA1": "温馨提示Github_Personal_Token可在Github设置的最底下开发者选项找到详情看教程",
"教程": "https://ikunshare.com/Onekey_tutorial"
}
async def gen_config_file():
try:
async with aiofiles.open("./config.json", mode="w", encoding="utf-8") as f:
await f.write(json.dumps(DEFAULT_CONFIG, indent=2, ensure_ascii=False, escape_forward_slashes=False))
log.info('🖱️ 程序可能为第一次启动或配置重置,请填写配置文件后重新启动程序')
except Exception as e:
log.error(f'❌ 配置文件生成失败,{stack_error(e)}')
async def load_config():
if not os.path.exists('./config.json'):
await gen_config_file()
os.system('pause')
sys.exit()
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")
await gen_config_file()
os.system('pause')
sys.exit()
config = asyncio.run(load_config())