mirror of
https://github.com/ikunshare/Onekey.git
synced 2026-01-12 16:25:53 +08:00
chore: 代码优化 && 更换进度条模块
This commit is contained in:
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
10
.idea/Onekey.iml
generated
Normal file
10
.idea/Onekey.iml
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -11,10 +11,11 @@
|
||||
|
||||
|
||||
## Onekey
|
||||
Onekey Steam Depot Manifest Downloader
|
||||
Onekey Steam Depot Manifest Downloader
|
||||
|
||||
## 使用方法
|
||||
先去Release下最新发布,然后去steamtools官网下steamtools,日志会有点石介意别用
|
||||
去Releases处下载最新的发布,并且安装好SteamTools或者GreenLuma
|
||||
然后打开Onekey输入App ID即可使用
|
||||
|
||||
## 开发
|
||||
本程序使用Python编程语言开发
|
||||
@@ -66,5 +67,4 @@ pip install -r requirements.txt
|
||||
## 社区和支持
|
||||
加入我们的社区,参与讨论和支持:
|
||||
- [GitHub Discussions](https://github.com/ikunshare/Onekey/discussions)
|
||||
- [QQ](https://qm.qq.com/q/d7sWovfAGI)
|
||||
- [Telegram](https://t.me/ikunshare_qun)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import time
|
||||
import ujson as json
|
||||
from aiohttp import ClientError, ConnectionTimeoutError
|
||||
from .log import log
|
||||
from .stack_error import stack_error
|
||||
@@ -9,7 +10,7 @@ async def check_github_api_rate_limit(headers, session):
|
||||
|
||||
try:
|
||||
async with session.get(url, headers=headers, ssl=False) as r:
|
||||
r_json = await r.json()
|
||||
r_json = json.loads(await r.read())
|
||||
|
||||
if r.status == 200:
|
||||
rate_limit = r_json.get('rate', {})
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import os
|
||||
import requests
|
||||
import aiohttp
|
||||
import ujson as json
|
||||
from .log import log
|
||||
from .stack_error import stack_error
|
||||
|
||||
|
||||
def checkcn():
|
||||
async def checkcn(client) -> bool:
|
||||
try:
|
||||
req = requests.get('https://mips.kugou.com/check/iscn?&format=json')
|
||||
req.raise_for_status()
|
||||
body = req.json()
|
||||
req = await client.get('https://mips.kugou.com/check/iscn?&format=json')
|
||||
body = json.loads(await req.read())
|
||||
scn = bool(body['flag'])
|
||||
if not scn:
|
||||
log.info(
|
||||
@@ -21,7 +21,7 @@ def checkcn():
|
||||
|
||||
except KeyboardInterrupt:
|
||||
log.info("\n 程序已退出")
|
||||
except requests.RequestException as e:
|
||||
except aiohttp.ClientError as e:
|
||||
os.environ['IS_CN'] = 'yes'
|
||||
log.warning('检查服务器位置失败,已忽略,自动认为你在中国大陆')
|
||||
log.warning(stack_error(e))
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import os
|
||||
from aiohttp import ClientError, ConnectionTimeoutError
|
||||
from tqdm.asyncio import tqdm_asyncio
|
||||
|
||||
from rich.progress import Progress, BarColumn, TextColumn, TimeElapsedColumn
|
||||
from .log import log
|
||||
|
||||
|
||||
async def get(sha: str, path: str, repo: str, session, chunk_size: int = 1024) -> bytearray:
|
||||
if os.environ.get('IS_CN') == 'yes':
|
||||
url_list = [
|
||||
@@ -24,14 +22,20 @@ async def get(sha: str, path: str, repo: str, session, chunk_size: int = 1024) -
|
||||
try:
|
||||
async with session.get(url, ssl=False) as response:
|
||||
if response.status == 200:
|
||||
total_size = int(
|
||||
response.headers.get('Content-Length', 0))
|
||||
total_size = int(response.headers.get('Content-Length', 0))
|
||||
content = bytearray()
|
||||
|
||||
with tqdm_asyncio(total=total_size, unit='B', unit_scale=True, desc=f'下载 {path}', colour='#ffadad') as pbar:
|
||||
with Progress(
|
||||
TextColumn("[progress.description]{task.description}", style="#66CCFF"),
|
||||
BarColumn(style="#66CCFF", complete_style="#4CE49F", finished_style="#2FE9D9"),
|
||||
TextColumn("[progress.percentage]{task.percentage:>3.0f}%", style="#66CCFF"),
|
||||
TimeElapsedColumn(),
|
||||
) as progress:
|
||||
task = progress.add_task(f"下载{path}中...", total=total_size)
|
||||
|
||||
async for chunk in response.content.iter_chunked(chunk_size):
|
||||
content.extend(chunk)
|
||||
pbar.update(len(chunk))
|
||||
progress.update(task, advance=len(chunk))
|
||||
|
||||
return content
|
||||
else:
|
||||
@@ -3,7 +3,7 @@ import aiofiles
|
||||
import vdf
|
||||
|
||||
from .log import log
|
||||
from .manifest_down import get
|
||||
from .dl import get
|
||||
from .stack_error import stack_error
|
||||
|
||||
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
from .get_steam_path import steam_path
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
async def greenluma_add(depot_id_list: list) -> bool:
|
||||
app_list_path = steam_path / 'AppList'
|
||||
|
||||
try:
|
||||
app_list_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
for file in app_list_path.glob('*.txt'):
|
||||
file.unlink(missing_ok=True)
|
||||
|
||||
depot_dict = {
|
||||
int(i.stem): int(i.read_text(encoding='utf-8').strip())
|
||||
for i in app_list_path.iterdir() if i.is_file() and i.stem.isdecimal() and i.suffix == '.txt'
|
||||
}
|
||||
|
||||
for depot_id in map(int, depot_id_list):
|
||||
if depot_id not in depot_dict.values():
|
||||
index = max(depot_dict.keys(), default=-1) + 1
|
||||
while index in depot_dict:
|
||||
index += 1
|
||||
|
||||
(app_list_path /
|
||||
f'{index}.txt').write_text(str(depot_id), encoding='utf-8')
|
||||
|
||||
depot_dict[index] = depot_id
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f'处理时出错: {e}')
|
||||
return False
|
||||
@@ -1,8 +1,4 @@
|
||||
from .log import log
|
||||
from colorama import Fore, Back, Style, init
|
||||
|
||||
init()
|
||||
|
||||
|
||||
def init():
|
||||
banner_lines = [
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import os
|
||||
from aiohttp import ClientSession, ConnectionTimeoutError
|
||||
from typing import Any
|
||||
|
||||
from aiohttp import ClientSession, ConnectionTimeoutError
|
||||
from common.checkcn import checkcn
|
||||
from common.config import config
|
||||
from common.dkey_merge import depotkey_merge
|
||||
from common.migration import migrate
|
||||
from common.st_unlock import stool_add
|
||||
from common.gl_unlock import greenluma_add
|
||||
from common.unlock import stool_add, greenluma_add
|
||||
from common.get_manifest_info import get_manifest
|
||||
from common.check import check_github_api_rate_limit
|
||||
from common.log import log
|
||||
@@ -18,7 +18,7 @@ isGreenLuma = any((steam_path / dll).exists()
|
||||
isSteamTools = (steam_path / 'config' / 'stUI').is_dir()
|
||||
|
||||
|
||||
async def fetch_branch_info(session, url, headers):
|
||||
async def fetch_branch_info(session, url, headers) -> str | None:
|
||||
try:
|
||||
async with session.get(url, headers=headers, ssl=False) as response:
|
||||
return await response.json()
|
||||
@@ -32,7 +32,7 @@ async def fetch_branch_info(session, url, headers):
|
||||
return None
|
||||
|
||||
|
||||
async def get_latest_repo_info(session, repos, app_id, headers):
|
||||
async def get_latest_repo_info(session, repos, app_id, headers) -> Any | None:
|
||||
latest_date = None
|
||||
selected_repo = None
|
||||
|
||||
@@ -50,23 +50,25 @@ async def get_latest_repo_info(session, repos, app_id, headers):
|
||||
|
||||
async def main(app_id: str, repos: list) -> bool:
|
||||
app_id_list = list(filter(str.isdecimal, app_id.strip().split('-')))
|
||||
|
||||
if not app_id_list:
|
||||
log.error(f'App ID无效')
|
||||
return False
|
||||
app_id = app_id_list[0]
|
||||
|
||||
checkcn()
|
||||
app_id = app_id_list[0]
|
||||
|
||||
async with ClientSession() as session:
|
||||
github_token = config.get("Github_Personal_Token", "")
|
||||
headers = {'Authorization': f'Bearer {
|
||||
github_token}'} if github_token else None
|
||||
|
||||
await checkcn(session)
|
||||
await check_github_api_rate_limit(headers, session)
|
||||
|
||||
selected_repo, latest_date = await get_latest_repo_info(session, repos, app_id, headers)
|
||||
|
||||
if selected_repo:
|
||||
log.info(f'选择清单仓库:{selected_repo}')
|
||||
log.info(f'选择清单仓库: {selected_repo}')
|
||||
url = f'https://api.github.com/repos/{
|
||||
selected_repo}/branches/{app_id}'
|
||||
r_json = await fetch_branch_info(session, url, headers)
|
||||
|
||||
@@ -2,7 +2,7 @@ import subprocess
|
||||
import aiofiles
|
||||
from aiohttp import ConnectionTimeoutError
|
||||
from pathlib import Path
|
||||
from tqdm.asyncio import tqdm
|
||||
from rich.progress import Progress, BarColumn, TextColumn, TimeElapsedColumn
|
||||
from .log import log
|
||||
from .get_steam_path import steam_path
|
||||
|
||||
@@ -19,13 +19,19 @@ async def download_setup_file(session) -> None:
|
||||
if r.status == 200:
|
||||
total_size = int(r.headers.get('Content-Length', 0))
|
||||
chunk_size = 8192
|
||||
progress = tqdm(total=total_size, unit='B',
|
||||
unit_scale=True, desc='下载安装程序')
|
||||
with Progress(
|
||||
TextColumn("[progress.description]{task.description}", style="#66CCFF"),
|
||||
BarColumn(style="#66CCFF", complete_style="#4CE49F", finished_style="#2FE9D9"),
|
||||
TextColumn("[progress.percentage]{task.percentage:>3.0f}%", style="#66CCFF"),
|
||||
TimeElapsedColumn(),
|
||||
) as progress:
|
||||
|
||||
task = progress.add_task(f"下载安装程序中...", total=total_size)
|
||||
|
||||
async with aiofiles.open(setup_file, mode='wb') as f:
|
||||
async for chunk in r.content.iter_chunked(chunk_size):
|
||||
await f.write(chunk)
|
||||
progress.update(len(chunk))
|
||||
async with aiofiles.open(setup_file, mode='wb') as f:
|
||||
async for chunk in r.content.iter_chunked(chunk_size):
|
||||
await f.write(chunk)
|
||||
progress.update(task, advance=len(chunk))
|
||||
|
||||
progress.close()
|
||||
log.info('安装程序下载完成')
|
||||
|
||||
@@ -2,13 +2,11 @@ import os
|
||||
import asyncio
|
||||
import subprocess
|
||||
import aiofiles
|
||||
|
||||
from .log import log
|
||||
from .get_steam_path import steam_path
|
||||
from .log import log
|
||||
|
||||
lock = asyncio.Lock()
|
||||
|
||||
|
||||
async def stool_add(depot_data: list, app_id: str) -> bool:
|
||||
lua_filename = f"{app_id}.lua"
|
||||
lua_filepath = steam_path / "config" / "stplug-in" / lua_filename
|
||||
@@ -44,3 +42,35 @@ async def stool_add(depot_data: list, app_id: str) -> bool:
|
||||
log.info(f'🗑️ 删除临时文件: {lua_filepath}')
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def greenluma_add(depot_id_list: list) -> bool:
|
||||
app_list_path = steam_path / 'AppList'
|
||||
|
||||
try:
|
||||
app_list_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
for file in app_list_path.glob('*.txt'):
|
||||
file.unlink(missing_ok=True)
|
||||
|
||||
depot_dict = {
|
||||
int(i.stem): int(i.read_text(encoding='utf-8').strip())
|
||||
for i in app_list_path.iterdir() if i.is_file() and i.stem.isdecimal() and i.suffix == '.txt'
|
||||
}
|
||||
|
||||
for depot_id in map(int, depot_id_list):
|
||||
if depot_id not in depot_dict.values():
|
||||
index = max(depot_dict.keys(), default=-1) + 1
|
||||
while index in depot_dict:
|
||||
index += 1
|
||||
|
||||
(app_list_path /
|
||||
f'{index}.txt').write_text(str(depot_id), encoding='utf-8')
|
||||
|
||||
depot_dict[index] = depot_id
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f'处理时出错: {e}')
|
||||
return False
|
||||
@@ -2,7 +2,6 @@ aiofiles==24.1.0
|
||||
aiohttp==3.10.10
|
||||
colorama==0.4.6
|
||||
colorlog==6.8.2
|
||||
Requests==2.32.3
|
||||
tqdm==4.66.5
|
||||
rich==13.9.4
|
||||
ujson==5.10.0
|
||||
vdf==3.4
|
||||
|
||||
Reference in New Issue
Block a user