Skip to content

Commit

Permalink
Merge pull request #28 from triwinds/dev
Browse files Browse the repository at this point in the history
PR for 0.2.9
  • Loading branch information
triwinds authored Feb 18, 2023
2 parents 2711c1c + c31f5c2 commit 4a9acf2
Show file tree
Hide file tree
Showing 19 changed files with 197 additions and 70 deletions.
5 changes: 5 additions & 0 deletions api/common_response.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from module.msg_notifier import send_notify
from exception.common_exception import VersionNotFoundException


logger = logging.getLogger(__name__)
Expand All @@ -11,6 +12,10 @@ def success_response(data=None, msg=None):

def exception_response(ex):
import traceback
if isinstance(ex, VersionNotFoundException):
logger.error(f'{str(ex)}')
send_notify(f'无法获取 {ex.branch} 分支的 [{ex.target_version}] 版本信息')
return error_response(404, str(ex))
logger.error(ex, exc_info=True)
traceback_str = "\n".join(traceback.format_exception(ex))
send_notify(f'出现异常, {traceback_str}')
Expand Down
9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change Log

## 0.2.9
- 添加新 GitHub 下载源 nuaa.cf, 并更新在其它 GitHub 下载源中使用的 UA
- 更正尝试下载一个不存在的 Ryujinx 版本时所展示的文本
- 集成 sentry sdk 收集异常信息 (可通过 `--no-sentry` 启动参数将其禁用)
- 使 DNS 缓存遵循返回的 ttl 设定
- 当 yuzu/ryujinx/固件 版本检测失败时, 将记录中的版本号重置为 `未知`

ps. 目前 Ryujinx LDN 只能下载 3.0.1 及之后的版本。如果需要更久之前的版本,请前往 Ryujinx 官网下载。

## 0.2.8
- 调整 ui 启动逻辑
- 启动后自动创建 `切换 UI 启动模式.bat` 用于切换启动模式
Expand Down
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sys


current_version = '0.2.8'
current_version = '0.2.9'
user_agent = f'ns-emu-tools/{current_version}'


Expand Down
14 changes: 14 additions & 0 deletions exception/common_exception.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@


class VersionNotFoundException(Exception):
msg: str = ''
target_version: str = ''
branch: str = ''
emu_type: str = ''

def __init__(self, target_version, branch, emu_type):
self.target_version = target_version
self.branch = branch
self.emu_type = emu_type
self.msg = f'Fail to get release info of version [{target_version}] on branch [{branch}]'
super().__init__(self.msg)
30 changes: 25 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import sys

from config import config, dump_config
import argparse
from utils.webview2 import ensure_runtime_components, can_use_webview, show_msgbox
import logging
import gevent.monkey

gevent.monkey.patch_ssl()
gevent.monkey.patch_socket()

import sys
from config import config, dump_config
from utils.webview2 import can_use_webview

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -35,7 +38,7 @@ def fallback_to_browser():
return start_ui(None)


def main():
def create_parser():
parser = argparse.ArgumentParser()
parser.add_argument(
"-m",
Expand All @@ -48,15 +51,32 @@ def main():
choices=['auto', 'webview', 'browser', 'chrome', 'edge', 'user default'],
help="切换 ui 启动方式",
)
parser.add_argument(
"--no-sentry",
action='store_true',
help="禁用 sentry",
)
return parser


def main():
parser = create_parser()
args = parser.parse_args()
logger.info(f'args: {args}')

if args.switch_mode is not None:
logger.info(f'switch mode: {args.switch_mode}')
config.setting.ui.mode = args.switch_mode
dump_config()
return 0

from module.external.bat_scripts import create_scripts
create_scripts()

if not args.no_sentry:
from module.sentry import init_sentry
init_sentry()

ui_mode = args.mode or config.setting.ui.mode
logger.info(f'ui mode: {ui_mode}')
if ui_mode is None or ui_mode == 'auto':
Expand Down
2 changes: 1 addition & 1 deletion module/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def init_aria2():

def download(url, save_dir=None, options=None, download_in_background=False):
init_aria2()
tmp = init_download_options_with_proxy()
tmp = init_download_options_with_proxy(url)
tmp['auto-file-renaming'] = 'false'
tmp['allow-overwrite'] = 'false'
if options is not None:
Expand Down
14 changes: 11 additions & 3 deletions module/firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
hactool_path = Path(os.path.realpath(os.path.dirname(__file__))).joinpath('hactool.exe')


def detect_firmware_version(emu_type: str):
def _detect_firmware_version(emu_type: str):
firmware_files = []
version = None
if emu_type == 'yuzu':
Expand Down Expand Up @@ -38,13 +38,21 @@ def detect_firmware_version(emu_type: str):
target_file = find_target_firmware_file(firmware_files, key_path)
if target_file:
version = extract_version(target_file, key_path)
if version:
return version


def detect_firmware_version(emu_type: str):
version = None
try:
version = _detect_firmware_version(emu_type)
except Exception as e:
raise e
finally:
if emu_type == 'yuzu':
config.yuzu.yuzu_firmware = version
else:
config.ryujinx.firmware = version
dump_config()
return version


def find_target_firmware_file(firmware_files, key_path):
Expand Down
13 changes: 10 additions & 3 deletions module/ryujinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import time
from pathlib import Path

from exception.common_exception import VersionNotFoundException
from module.downloader import download
from repository.ryujinx import get_ryujinx_release_info_by_version, get_ldn_ryujinx_release_info_by_version
from utils.network import get_github_download_url
Expand All @@ -19,6 +20,8 @@
def get_ryujinx_download_url(target_version: str, branch: str):
if branch in {'mainline', 'ava'}:
release_info = get_ryujinx_release_info_by_version(target_version)
if 'tag_name' not in release_info:
raise VersionNotFoundException(target_version, branch, 'ryujinx')
assets = release_info['assets']
for asset in assets:
name: str = asset['name']
Expand All @@ -28,6 +31,8 @@ def get_ryujinx_download_url(target_version: str, branch: str):
return asset['browser_download_url']
elif branch == 'ldn':
release_info = get_ldn_ryujinx_release_info_by_version(target_version)
if 'tag_name' not in release_info:
raise VersionNotFoundException(target_version, branch, 'ryujinx')
assets = release_info['assets']
ava_ldn_url, mainline_ldn_url = None, None
for asset in assets:
Expand Down Expand Up @@ -178,6 +183,8 @@ def detect_ryujinx_version():
rj_path = get_ryujinx_exe_path()
if not rj_path:
send_notify('未能找到 Ryujinx 程序')
config.ryujinx.version = None
dump_config()
return None
config.ryujinx.branch = detect_current_branch()
st_inf = subprocess.STARTUPINFO()
Expand All @@ -201,9 +208,9 @@ def detect_ryujinx_version():
idx = version.index('ldn')
version = version[idx+3:]
config.ryujinx.branch = 'ldn'
config.ryujinx.version = version
dump_config()
return version
config.ryujinx.version = version
dump_config()
return version


def update_ryujinx_path(new_ryujinx_path: str):
Expand Down
18 changes: 18 additions & 0 deletions module/sentry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sentry_sdk
from config import current_version


def sampler(sample_data):
if 'wsgi_environ' in sample_data and sample_data['wsgi_environ']['PATH_INFO'] == '/index.html':
return 1
return 0


def init_sentry():
sentry_sdk.init(
dsn="https://[email protected]/4504689953472512",
auto_session_tracking=False,
traces_sampler=sampler,
release=f'ns-emu-tools@{current_version}'
)
sentry_sdk.set_user({'ip_address': '{{auto}}'})
13 changes: 7 additions & 6 deletions module/yuzu.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from repository.yuzu import get_yuzu_release_info_by_version
from utils.network import get_github_download_url
from utils.common import decode_yuzu_path
from exception.common_exception import VersionNotFoundException


logger = logging.getLogger(__name__)
Expand All @@ -24,9 +25,7 @@ def download_yuzu(target_version, branch):
send_notify('正在获取 yuzu 版本信息...')
release_info = get_yuzu_release_info_by_version(target_version, branch)
if not release_info.get('tag_name'):
logger.error(f'fail to get release info of version {target_version} on branch {branch}')
send_notify(f'无法获取 {branch} 分支的 [{target_version}] 版本信息')
raise RuntimeError(f'fail to get release info of version {target_version} on branch {branch}')
raise VersionNotFoundException(target_version, branch, 'yuzu')
logger.info(f'target yuzu version: {target_version}')
yuzu_path = Path(config.yuzu.yuzu_path)
logger.info(f'target yuzu path: {yuzu_path}')
Expand Down Expand Up @@ -131,6 +130,8 @@ def detect_yuzu_version():
yz_path = Path(config.yuzu.yuzu_path).joinpath('yuzu.exe')
if not yz_path.exists():
send_notify('未能找到 yuzu 程序')
config.yuzu.yuzu_version = None
dump_config()
return None
kill_all_yuzu_instance()
st_inf = subprocess.STARTUPINFO()
Expand Down Expand Up @@ -159,10 +160,10 @@ def detect_yuzu_version():
logger.exception('error occur in get_all_window_name')
kill_all_yuzu_instance()
if version:
config.yuzu.yuzu_version = version
config.yuzu.branch = branch
dump_config()
return version
config.yuzu.yuzu_version = version
dump_config()
return version


def kill_all_yuzu_instance():
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ httplib2
requests-cache
dnspython[doh]
pywebview
sentry-sdk
9 changes: 5 additions & 4 deletions ui.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import logging
import gevent.monkey

gevent.monkey.patch_all(httplib=True, subprocess=False)
import eel
from config import config
from utils.network import get_available_port

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -64,6 +60,7 @@ def main(port=0, mode=None, dev=False):
size = (1440, 900)
logger.info(f'browser mode: {mode}')
if port == 0:
from utils.network import get_available_port
port = get_available_port()
logger.info(f'starting eel at port: {port}')
if mode == 'edge':
Expand All @@ -73,5 +70,9 @@ def main(port=0, mode=None, dev=False):


if __name__ == '__main__':
import gevent.monkey

gevent.monkey.patch_ssl()
gevent.monkey.patch_socket()
main(8888, False, True)
# main(0, 'edge')
9 changes: 4 additions & 5 deletions ui_webview.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import logging

import gevent.monkey

gevent.monkey.patch_ssl()
gevent.monkey.patch_socket()
import eel
import webview
from config import config
Expand Down Expand Up @@ -49,4 +44,8 @@ def main():


if __name__ == '__main__':
import gevent.monkey

gevent.monkey.patch_ssl()
gevent.monkey.patch_socket()
main()
Loading

0 comments on commit 4a9acf2

Please sign in to comment.