Skip to content

Commit

Permalink
Merge pull request #39 from triwinds/dev
Browse files Browse the repository at this point in the history
PR for 0.3.8
  • Loading branch information
triwinds authored Apr 15, 2023
2 parents d8cbaca + 016dcaf commit 45a5e74
Show file tree
Hide file tree
Showing 25 changed files with 273 additions and 90 deletions.
9 changes: 9 additions & 0 deletions api/common_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ def load_history_path(emu_type: str):
return success_response(list(_merge_to_set(storage.ryujinx_history.keys(), config.ryujinx.path)))


@eel.expose
def get_github_mirrors():
from module.network import get_github_mirrors
try:
return success_response(get_github_mirrors())
except Exception as e:
return exception_response(e)


def _merge_to_set(*cols):
from collections.abc import Iterable
s = set()
Expand Down
22 changes: 19 additions & 3 deletions api/common_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from exception.common_exception import *
from exception.download_exception import *
from exception.install_exception import *
from requests.exceptions import ConnectionError


logger = logging.getLogger(__name__)
Expand All @@ -17,19 +18,19 @@ def exception_response(ex):
if type(ex) in exception_handler_map:
return exception_handler_map[type(ex)](ex)
logger.error(ex, exc_info=True)
traceback_str = "\n".join(traceback.format_exception(ex))
traceback_str = "".join(traceback.format_exception(ex))
send_notify(f'出现异常, {traceback_str}')
return error_response(999, str(ex))


def version_not_found_handler(ex: VersionNotFoundException):
logger.error(f'{str(ex)}')
logger.info(f'{str(ex)}')
send_notify(f'无法获取 {ex.branch} 分支的 [{ex.target_version}] 版本信息')
return error_response(404, str(ex))


def md5_not_found_handler(ex: Md5NotMatchException):
logger.error(f'{str(ex)}')
logger.info(f'{str(ex)}')
send_notify(f'固件文件 md5 不匹配, 请重新下载')
return error_response(501, str(ex))

Expand Down Expand Up @@ -59,13 +60,28 @@ def fail_to_copy_files_handler(ex: FailToCopyFiles):
return error_response(701, str(ex))


def ignored_exception_handler(ex):
logger.info(f'{str(ex)}')
return error_response(801, str(ex))


def connection_error_handler(ex):
import traceback
traceback_str = "".join([s for s in traceback.format_exception(ex) if s.strip() != ''])
logger.info(f'{str(ex)}\n{traceback_str}')
send_notify(f'出现异常, {traceback_str}')
return error_response(999, str(ex))


exception_handler_map = {
VersionNotFoundException: version_not_found_handler,
Md5NotMatchException: md5_not_found_handler,
DownloadInterrupted: download_interrupted_handler,
DownloadPaused: download_paused_handler,
DownloadNotCompleted: download_not_completed_handler,
FailToCopyFiles: fail_to_copy_files_handler,
IgnoredException: ignored_exception_handler,
ConnectionError: connection_error_handler,
}


Expand Down
9 changes: 9 additions & 0 deletions api/yuzu_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,12 @@ def get_all_yuzu_release_versions():
return success_response(get_all_yuzu_release_versions(config.yuzu.branch))
except Exception as e:
return exception_response(e)


@eel.expose
def get_yuzu_commit_logs():
from module.yuzu import get_yuzu_commit_logs
try:
return success_response(get_yuzu_commit_logs())
except Exception as e:
return exception_response(e)
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## 0.3.8
- 添加展示 yuzu 最近提交记录的按钮
- Edge 浏览器模式启动失败时自动回退至默认浏览器
- 重构 GitHub 下载源相关代码 & 移除失效的下载源

## 0.3.7
- 修复 Ryujinx 固件安装失败时会删除原有固件的问题 (#36)
- 一些样式调整
Expand Down
4 changes: 2 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sys


current_version = '0.3.7'
current_version = '0.3.8'
user_agent = f'ns-emu-tools/{current_version}'


Expand Down Expand Up @@ -62,7 +62,7 @@ class RyujinxConfig:
class NetworkSetting:
firmwareSource: Optional[str] = 'auto-detect'
githubApiMode: Optional[str] = 'direct'
githubDownloadSource: Optional[str] = 'self'
githubDownloadMirror: Optional[str] = 'cloudflare_load_balance'
useDoh: Optional[bool] = True


Expand Down
5 changes: 5 additions & 0 deletions exception/common_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ def __init__(self, target_version, branch, emu_type):
class Md5NotMatchException(Exception):
def __init__(self):
super().__init__('MD5 not match')


class IgnoredException(RuntimeError):
def __init__(self, msg=''):
super().__init__(msg)
16 changes: 8 additions & 8 deletions module/cfst.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import os
import subprocess
import sys
import time
from pathlib import Path
from typing import List
Expand All @@ -11,8 +10,9 @@
from config import config
from module.downloader import download
from module.msg_notifier import send_notify
from utils.network import get_github_download_url
from module.network import get_github_download_url
from module.hosts import Hosts
from exception.common_exception import IgnoredException

logger = logging.getLogger(__name__)
script_template = """@echo off
Expand Down Expand Up @@ -47,7 +47,7 @@ def run_cfst():
if not exe_path.exists():
logger.info('CloudflareSpeedTest not exist.')
send_notify('CloudflareSpeedTest not exist.')
raise RuntimeError('CloudflareSpeedTest not exist.')
raise IgnoredException('CloudflareSpeedTest not exist.')
logger.info('starting CloudflareSpeedTest...')
send_notify('正在运行 CloudflareSpeedTest...')
script_path = Path('CloudflareSpeedTest/cfst.bat')
Expand All @@ -65,13 +65,13 @@ def get_fastest_ip_from_result():
if not result_path.exists():
logger.info('CloudflareSpeedTest result not exist.')
send_notify('未能检测到 CloudflareSpeedTest 结果, 请先运行一次测试.')
raise RuntimeError('未能检测到 CloudflareSpeedTest 结果, 请先运行一次测试.')
raise IgnoredException('未能检测到 CloudflareSpeedTest 结果, 请先运行一次测试.')
with open(result_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
if len(lines) < 2:
logger.info('Fail to parse CloudflareSpeedTest result.')
send_notify('无法解析 CloudflareSpeedTest 结果, 请先运行一次测试.')
raise RuntimeError('无法解析 CloudflareSpeedTest 结果, 请先运行一次测试.')
raise IgnoredException('无法解析 CloudflareSpeedTest 结果, 请先运行一次测试.')
ip = lines[1].split(',', 1)[0]
logger.info(f'fastest ip from result: {ip}')
return ip
Expand All @@ -82,7 +82,7 @@ def show_result():
if not result_path.exists():
logger.info('CloudflareSpeedTest result not exist.')
send_notify('未能检测到 CloudflareSpeedTest 结果, 请先运行一次测试.')
raise RuntimeError('未能检测到 CloudflareSpeedTest 结果, 请先运行一次测试.')
raise IgnoredException('未能检测到 CloudflareSpeedTest 结果, 请先运行一次测试.')
with open(result_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
send_notify('===============测速结果===============')
Expand Down Expand Up @@ -120,7 +120,7 @@ def get_current_cfst_version():


def get_cf_hostnames():
default_list = ['nsarchive.e6ex.com', 'proxy.zyun.vip', 'download.nuaa.cf']
default_list = ['nsarchive.e6ex.com']
hostnames = get_override_host_names()
for hn in default_list:
if hn not in hostnames:
Expand Down Expand Up @@ -178,7 +178,7 @@ def write_hosts(hosts: Hosts):
if ret == 42:
logger.info(f'updated hosts: {hosts}')
return
raise RuntimeError(f'Unable to write hosts file.')
raise IgnoredException(f'Unable to write hosts file.')


if __name__ == '__main__':
Expand Down
15 changes: 8 additions & 7 deletions module/cheats.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import string
from pathlib import Path
from typing import List, Dict
from utils.network import get_durable_cache_session
from module.network import get_durable_cache_session
import logging
import time
from utils.string_util import auto_decode
from module.msg_notifier import send_notify
from exception.common_exception import IgnoredException


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -125,7 +126,7 @@ def _find_next(s, tc, i):
def list_all_cheat_files_from_folder(folder_path: str):
folder = Path(folder_path)
if not folder.exists():
raise RuntimeError(f'目录 {folder} 不存在.')
raise IgnoredException(f'目录 {folder} 不存在.')
res = []
for txt_file in folder.glob('*.txt'):
if cheat_file_re.match(txt_file.name):
Expand All @@ -149,7 +150,7 @@ def _read_cheat_name(txt_file: Path):
def load_cheat_chunk_info(cheat_file_path: str):
cheat_file = Path(cheat_file_path)
if not cheat_file.exists():
raise RuntimeError(f'文件 {cheat_file} 不存在.')
raise IgnoredException(f'文件 {cheat_file} 不存在.')
chunk_folder = cheat_file.parent.parent.joinpath('cheats_chunk')
if not chunk_folder.exists():
chunk_folder.mkdir(parents=True, exist_ok=True)
Expand Down Expand Up @@ -183,13 +184,13 @@ def load_cheat_chunk_info(cheat_file_path: str):
def update_current_cheats(enable_titles: List[str], cheat_file_path: str):
cheat_file = Path(cheat_file_path)
if not cheat_file.exists():
raise RuntimeError(f'文件 {cheat_file} 不存在.')
raise IgnoredException(f'文件 {cheat_file} 不存在.')
chunk_folder = cheat_file.parent.parent.joinpath('cheats_chunk')
if not chunk_folder.exists():
raise RuntimeError(f'仓库目录 {chunk_folder} 不存在.')
raise IgnoredException(f'仓库目录 {chunk_folder} 不存在.')
chunk_file = chunk_folder.joinpath(cheat_file.name[:16] + '_chunk.txt')
if not chunk_file.exists():
raise RuntimeError(f'仓库文件 {chunk_file} 不存在.')
raise IgnoredException(f'仓库文件 {chunk_file} 不存在.')
backup_file = chunk_folder.joinpath(f'{cheat_file.name[:16]}_{int(time.time()*1000)}.txt')
shutil.copy2(cheat_file, backup_file)
logger.info(f'backup {cheat_file} to {backup_file}')
Expand All @@ -212,7 +213,7 @@ def update_current_cheats(enable_titles: List[str], cheat_file_path: str):
def open_cheat_mod_folder(folder_path: str):
folder = Path(folder_path)
if not folder.exists():
raise RuntimeError(f'目录 {folder} 不存在.')
raise IgnoredException(f'目录 {folder} 不存在.')
import subprocess
parent_folder = folder.parent
logger.info(f'open folder [{parent_folder}] in explorer')
Expand Down
2 changes: 1 addition & 1 deletion module/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import subprocess
from pathlib import Path

from utils.network import get_finial_url
from module.network import get_finial_url

logger = logging.getLogger(__name__)

Expand Down
9 changes: 5 additions & 4 deletions module/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os
from module.msg_notifier import send_notify
from config import config
from utils.network import get_available_port, get_global_options, init_download_options_with_proxy
from module.network import get_available_port, get_global_options, init_download_options_with_proxy
from exception.download_exception import *

aria2: Optional[aria2p.API] = None
Expand Down Expand Up @@ -39,8 +39,9 @@ def init_aria2():
'--rpc-secret', '123456', '--log', 'aria2.log', '--log-level=info', f'--stop-with-process={os.getpid()}']
if config.setting.download.disableAria2Ipv6:
cli.append('--disable-ipv6=true')
cli.append('--async-dns-server=223.5.5.5,119.29.29.29')
else:
if config.setting.network.useDoh:
cli.append('--async-dns-server=223.5.5.5,119.29.29.29')
elif config.setting.network.useDoh:
cli.append('--async-dns-server=2400:3200::1,2402:4e00::,223.5.5.5,119.29.29.29')
logger.info(f'aria2 cli: {cli}')
aria2_process = subprocess.Popen(cli, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, startupinfo=st_inf)
Expand Down Expand Up @@ -131,7 +132,7 @@ def _download(url, save_dir=None, options=None, download_in_background=False):
os.remove(file.path)
raise DownloadInterrupted()
else:
logger.error(f'info.error_code: {info.error_code}, error message: {info.error_message}')
logger.info(f'info.error_code: {info.error_code}, error message: {info.error_message}')
raise RuntimeError(f'下载出错, error_code: {info.error_code}, error message: {info.error_message}')
else:
logger.info(f'progress: {info.progress_string()}, total size: {info.total_length_string()}')
Expand Down
9 changes: 5 additions & 4 deletions module/firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import os
from pathlib import Path
import logging
from config import config, dump_config
from config import dump_config
import shutil
from module.msg_notifier import send_notify
import xmltodict
from functools import lru_cache
from config import config
from module.downloader import download
from utils.network import get_finial_url, get_durable_cache_session
from module.network import get_finial_url, get_durable_cache_session
from exception.common_exception import IgnoredException

logger = logging.getLogger(__name__)
hactool_path = Path(os.path.realpath(os.path.dirname(__file__))).joinpath('hactool.exe')
Expand All @@ -35,11 +36,11 @@ def _detect_firmware_version(emu_type: str):
if not key_path.exists():
logger.error(f'prod keys not found in path: {key_path}')
send_notify('未能找到相应的 prod.keys 文件')
raise RuntimeError(f'prod keys not found in path: {key_path}')
raise IgnoredException(f'prod keys not found in path: {key_path}')
if not firmware_files:
logger.error(f'no firmware files found in path: {firmware_path}')
send_notify('未能找到相应的固件文件')
raise RuntimeError(f'no firmware files found in path: {firmware_path}')
raise IgnoredException(f'no firmware files found in path: {firmware_path}')
target_file = find_target_firmware_file(firmware_files, key_path)
if target_file:
version = extract_version(target_file, key_path)
Expand Down
Loading

0 comments on commit 45a5e74

Please sign in to comment.