diff --git a/common/dkey_merge.py b/common/dkey_merge.py new file mode 100644 index 0000000..3de3d3d --- /dev/null +++ b/common/dkey_merge.py @@ -0,0 +1,23 @@ +import asyncio +import aiofiles +import vdf +from .log import log + +lock = asyncio.Lock() + +async def depotkey_merge(config_path, depots_config): + if not config_path.exists(): + async with lock: + log.error(' 👋 Steam默认配置不存在,可能是没有登录账号') + return + async with aiofiles.open(config_path, encoding='utf-8') as f: + config = vdf.load(f) + software = config['InstallConfigStore']['Software'] + valve = software.get('Valve') or software.get('valve') + steam = valve.get('Steam') or valve.get('steam') + if 'depots' not in steam: + steam['depots'] = {} + steam['depots'].update(depots_config['depots']) + async with aiofiles.open(config_path, mode='w', encoding='utf-8') as f: + vdf.dump(config, f, pretty=True) + return True \ No newline at end of file diff --git a/common/manifestdown.py b/common/manifestdown.py new file mode 100644 index 0000000..8599e7e --- /dev/null +++ b/common/manifestdown.py @@ -0,0 +1,28 @@ +from aiohttp import ClientError +from .log import log + +# 下载清单 +async def get(sha, path, repo, session): + url_list = [ + # f'https://gh.api.99988866.xyz/https://raw.githubusercontent.com/{repo}/{sha}/{path}', + f'https://cdn.jsdmirror.com/gh/{repo}@{sha}/{path}', + f'https://jsd.onmicrosoft.cn/gh/{repo}@{sha}/{path}', + f'https://mirror.ghproxy.com/https://raw.githubusercontent.com/{repo}/{sha}/{path}', + f'https://raw.githubusercontent.com/{repo}/{sha}/{path}', + f'https://gh.jiasu.in/https://raw.githubusercontent.com/{repo}/{sha}/{path}' + ] + retry = 3 + while retry: + for url in url_list: + try: + async with session.get(url, ssl=False) as r: + if r.status == 200: + return await r.read() + else: + log.error(f' 🔄 获取失败: {path} - 状态码: {r.status}') + except ClientError: + log.error(f' 🔄 获取失败: {path} - 连接错误') + retry -= 1 + log.warning(f' 🔄 重试剩余次数: {retry} - {path}') + log.error(f' 🔄 超过最大重试次数: {path}') + raise Exception(f' 🔄 无法下载: {path}') \ No newline at end of file diff --git a/common/stunlock.py b/common/stunlock.py index a63f4ae..713f778 100644 --- a/common/stunlock.py +++ b/common/stunlock.py @@ -11,7 +11,7 @@ steam_path = getsteampath.steam_path # 增加SteamTools解锁相关文件 async def stool_add(depot_data, app_id): - lua_filename = f"Onekey_unlock_{app_id}.lua" + lua_filename = f"Onekey{app_id}.lua" lua_filepath = steam_path / "config" / "stplug-in" / lua_filename async with lock: diff --git a/main.py b/main.py index 5b9029b..152eb18 100644 --- a/main.py +++ b/main.py @@ -4,8 +4,8 @@ import aiofiles import traceback import time import asyncio -from common import log, config, getsteampath, stunlock, glunlock, stack_error -from aiohttp import ClientSession, ClientError +from common import log, config, getsteampath, stunlock, glunlock, stack_error, manifestdown, dkey_merge +from aiohttp import ClientSession from pathlib import Path log = log.log @@ -17,6 +17,9 @@ isSteamTools = (steam_path / 'config' / 'stplug-in').is_dir() stunlock = stunlock.stunlock glunlock = glunlock.glunlock stack_error = stack_error.stack_error +get = manifestdown.get +depotkey_merge = dkey_merge.depotkey_merge + print('\033[1;32;40m _____ __ _ _____ _ _ _____ __ __ ' + '\033[0m') print('\033[1;32;40m / _ \\ | \\ | | | ____| | | / / | ____| \\ \\ / /' + '\033[0m') @@ -26,37 +29,11 @@ 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.6') +log.info('版本:1.1.7') 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') -# 下载清单 -async def get(sha, path, repo, session): - url_list = [ - # f'https://gh.api.99988866.xyz/https://raw.githubusercontent.com/{repo}/{sha}/{path}', - f'https://cdn.jsdmirror.com/gh/{repo}@{sha}/{path}', - f'https://jsd.onmicrosoft.cn/gh/{repo}@{sha}/{path}', - f'https://mirror.ghproxy.com/https://raw.githubusercontent.com/{repo}/{sha}/{path}', - f'https://raw.githubusercontent.com/{repo}/{sha}/{path}', - f'https://gh.jiasu.in/https://raw.githubusercontent.com/{repo}/{sha}/{path}' - ] - retry = 3 - while retry: - for url in url_list: - try: - async with session.get(url, ssl=False) as r: - if r.status == 200: - return await r.read() - else: - log.error(f' 🔄 获取失败: {path} - 状态码: {r.status}') - except ClientError: - log.error(f' 🔄 获取失败: {path} - 连接错误') - retry -= 1 - log.warning(f' 🔄 重试剩余次数: {retry} - {path}') - log.error(f' 🔄 超过最大重试次数: {path}') - raise Exception(f' 🔄 无法下载: {path}') - # 获取清单信息 async def get_manifest(sha, path, steam_path: Path, repo, session): collected_depots = [] @@ -85,24 +62,6 @@ async def get_manifest(sha, path, steam_path: Path, repo, session): raise return collected_depots -# 合并DecryptionKey -async def depotkey_merge(config_path, depots_config): - if not config_path.exists(): - async with lock: - log.error(' 👋 Steam默认配置不存在,可能是没有登录账号') - return - async with aiofiles.open(config_path, encoding='utf-8') as f: - config = vdf.load(f) - software = config['InstallConfigStore']['Software'] - valve = software.get('Valve') or software.get('valve') - steam = valve.get('Steam') or valve.get('steam') - if 'depots' not in steam: - steam['depots'] = {} - steam['depots'].update(depots_config['depots']) - async with aiofiles.open(config_path, mode='w', encoding='utf-8') as f: - vdf.dump(config, f, pretty=True) - return True - async def check_github_api_rate_limit(headers, session): url = 'https://api.github.com/rate_limit'