mirror of
https://github.com/ikunshare/Onekey.git
synced 2026-01-15 09:33:06 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ced52a87f | ||
|
|
7352f20eb4 | ||
|
|
6ec83c4196 | ||
|
|
a7ce46aa52 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -169,3 +169,4 @@ cython_debug/
|
||||
*.xml
|
||||
*.exe
|
||||
*.dll
|
||||
/main.dist
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import ujson as json
|
||||
import aiofiles
|
||||
from . import log
|
||||
from .stack_error import stack_error
|
||||
from .log import log
|
||||
import os
|
||||
import sys
|
||||
import asyncio
|
||||
|
||||
log = log.log
|
||||
|
||||
# 生成配置文件
|
||||
async def gen_config_file():
|
||||
default_config ={
|
||||
@@ -29,8 +28,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())
|
||||
25
common/dkey_merge.py
Normal file
25
common/dkey_merge.py
Normal file
@@ -0,0 +1,25 @@
|
||||
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:
|
||||
content = await f.read()
|
||||
config = vdf.loads(content)
|
||||
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:
|
||||
new_content = vdf.dumps(config, pretty=True)
|
||||
await f.write(new_content)
|
||||
return True
|
||||
@@ -1,17 +1,22 @@
|
||||
import winreg
|
||||
import os
|
||||
from .log import log
|
||||
from .config import config
|
||||
from .stack_error import stack_error
|
||||
from pathlib import Path
|
||||
from common import config
|
||||
|
||||
config = config.config
|
||||
|
||||
# 通过注册表获取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()
|
||||
@@ -1,6 +1,4 @@
|
||||
from common import getsteampath
|
||||
|
||||
steam_path = getsteampath.steam_path
|
||||
from .getsteampath import steam_path
|
||||
|
||||
# 增加GreenLuma解锁相关文件
|
||||
async def greenluma_add(depot_id_list):
|
||||
|
||||
26
common/manifestdown.py
Normal file
26
common/manifestdown.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from aiohttp import ClientError
|
||||
from .log import log
|
||||
|
||||
# 下载清单
|
||||
async def get(sha, path, repo, session):
|
||||
url_list = [
|
||||
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}',
|
||||
]
|
||||
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}')
|
||||
47
common/migration.py
Normal file
47
common/migration.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import os
|
||||
import requests
|
||||
import subprocess
|
||||
from .log import log
|
||||
from .getsteampath import steam_path
|
||||
from pathlib import Path
|
||||
|
||||
directory = Path(steam_path / "config" / "stplug-in")
|
||||
|
||||
def migrate(st_use):
|
||||
if st_use == True:
|
||||
log.info('检测到你正在使用SteamTools,尝试迁移旧文件')
|
||||
if os.path.exists(directory):
|
||||
for filename in os.listdir(directory):
|
||||
if filename.startswith("Onekey_unlock_"):
|
||||
new_filename = filename[len("Onekey_unlock_"):]
|
||||
|
||||
old_file = os.path.join(directory, filename)
|
||||
new_file = os.path.join(directory, new_filename)
|
||||
|
||||
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}')
|
||||
else:
|
||||
log.error('故障,正在重新安装SteamTools')
|
||||
temp_path = './temp'
|
||||
if not os.path.exists(temp_path):
|
||||
os.mkdir(temp_path)
|
||||
down_url = 'https://steamtools.net/res/SteamtoolsSetup.exe'
|
||||
out_path = './temp/SteamtoolsSetup.exe'
|
||||
with requests.get(down_url, stream=True) as r:
|
||||
if r.status_code == 200:
|
||||
with open(out_path, 'wb') as f:
|
||||
for chunk in r.iter_content(chunk_size=8192):
|
||||
f.write(chunk)
|
||||
else:
|
||||
log.error('网络错误')
|
||||
subprocess.run(str(out_path))
|
||||
os.rmdir(temp_path)
|
||||
else:
|
||||
log.info('未使用SteamTools,停止迁移')
|
||||
|
||||
|
||||
migrate = migrate
|
||||
@@ -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"{app_id}.lua"
|
||||
lua_filepath = steam_path / "config" / "stplug-in" / lua_filename
|
||||
|
||||
async with lock:
|
||||
|
||||
72
main.py
72
main.py
@@ -4,8 +4,9 @@ import aiofiles
|
||||
import traceback
|
||||
import time
|
||||
import asyncio
|
||||
from common import log, config, getsteampath, stunlock, glunlock, stack_error
|
||||
from aiohttp import ClientSession, ClientError
|
||||
import time
|
||||
from common import log, config, getsteampath, stunlock, glunlock, stack_error, manifestdown, dkey_merge, migration
|
||||
from aiohttp import ClientSession
|
||||
from pathlib import Path
|
||||
|
||||
log = log.log
|
||||
@@ -13,10 +14,14 @@ config = config.config
|
||||
lock = asyncio.Lock()
|
||||
steam_path = getsteampath.steam_path
|
||||
isGreenLuma = any((steam_path / dll).exists() for dll in ['GreenLuma_2024_x86.dll', 'GreenLuma_2024_x64.dll', 'User32.dll'])
|
||||
isSteamTools = (steam_path / 'config' / 'stplug-in').is_dir()
|
||||
isSteamTools = (steam_path / 'config' / 'stUI').is_dir()
|
||||
stunlock = stunlock.stunlock
|
||||
glunlock = glunlock.glunlock
|
||||
stack_error = stack_error.stack_error
|
||||
get = manifestdown.get
|
||||
depotkey_merge = dkey_merge.depotkey_merge
|
||||
migration = migration.migrate
|
||||
|
||||
|
||||
print('\033[1;32;40m _____ __ _ _____ _ _ _____ __ __ ' + '\033[0m')
|
||||
print('\033[1;32;40m / _ \\ | \\ | | | ____| | | / / | ____| \\ \\ / /' + '\033[0m')
|
||||
@@ -26,37 +31,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.9')
|
||||
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 +64,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'
|
||||
|
||||
@@ -169,9 +130,11 @@ async def main(app_id):
|
||||
collected_depots.extend(result)
|
||||
if collected_depots:
|
||||
if isSteamTools:
|
||||
migration(st_use=True)
|
||||
await stunlock(collected_depots, app_id)
|
||||
log.info(' ✅ 找到SteamTools,已添加解锁文件')
|
||||
if isGreenLuma:
|
||||
migration(st_use=False)
|
||||
await glunlock([app_id])
|
||||
depot_config = {'depots': {depot_id: {'DecryptionKey': depot_key} for depot_id, depot_key in collected_depots}}
|
||||
await depotkey_merge(steam_path / 'config' / 'config.vdf', depot_config)
|
||||
@@ -186,18 +149,19 @@ async def main(app_id):
|
||||
return False
|
||||
|
||||
repos = [
|
||||
'ManifestHub/ManifestHub',
|
||||
'ikun0014/ManifestHub',
|
||||
'Auiowu/ManifestAutoUpdate',
|
||||
'tymolu233/ManifestAutoUpdate'
|
||||
]
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
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')
|
||||
Reference in New Issue
Block a user