Skip to content

Commit

Permalink
Merge pull request #68 from triwinds/dev
Browse files Browse the repository at this point in the history
PR for 0.4.1
  • Loading branch information
triwinds authored May 27, 2023
2 parents 4be358a + f287247 commit 1b5220f
Show file tree
Hide file tree
Showing 26 changed files with 906 additions and 141 deletions.
22 changes: 18 additions & 4 deletions api/common_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
from typing import Dict

import eel
from api.common_response import success_response, exception_response, error_response
from api.common_response import *
from config import current_version, shared
import logging
import time
Expand Down Expand Up @@ -121,9 +122,10 @@ def get_github_mirrors():

@eel.expose
def update_window_size(width: int, height: int):
from config import dump_config, config
width = width if width > 500 else 500
height = height if height > 400 else 400
from config import dump_config, config, shared
if shared['mode'] == 'webview':
from ui_webview import get_window_size
width, height = get_window_size()
if width == config.setting.ui.width and height == config.setting.ui.height:
return success_response()
config.setting.ui.width = width
Expand All @@ -133,6 +135,18 @@ def update_window_size(width: int, height: int):
return success_response()


@generic_api
def get_storage():
from storage import storage
return storage.to_dict()


@generic_api
def delete_path(path: str):
from module.common import delete_path
return delete_path(path)


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


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -85,8 +86,18 @@ def connection_error_handler(ex):
}


def generic_api(func):
def wrapper(*args, **kw):
try:
return success_response(func(*args, **kw))
except Exception as e:
return exception_response(e)
eel._expose(func.__name__, wrapper)
return wrapper


def error_response(code, msg):
return {'code': code, 'msg': msg}


__all__ = ['success_response', 'exception_response', 'error_response']
__all__ = ['success_response', 'exception_response', 'error_response', 'generic_api']
44 changes: 44 additions & 0 deletions api/save_manager_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from config import config
from api.common_response import *


@generic_api
def get_users_in_save():
from module.save_manager import get_users_in_save
return get_users_in_save()


@generic_api
def list_all_games_by_user_folder(folder: str):
from module.save_manager import list_all_games_by_user_folder
return list_all_games_by_user_folder(folder)


@generic_api
def ask_and_update_yuzu_save_backup_folder():
from module.save_manager import ask_and_update_yuzu_save_backup_folder
return ask_and_update_yuzu_save_backup_folder()


@generic_api
def backup_yuzu_save_folder(folder: str):
from module.save_manager import backup_folder
return backup_folder(folder)


@generic_api
def open_yuzu_save_backup_folder():
from module.save_manager import open_yuzu_save_backup_folder
return open_yuzu_save_backup_folder()


@generic_api
def list_all_yuzu_backups():
from module.save_manager import list_all_yuzu_backups
return list_all_yuzu_backups()


@generic_api
def restore_yuzu_save_from_backup(user_folder_name: str, backup_path: str):
from module.save_manager import restore_yuzu_save_from_backup
return restore_yuzu_save_from_backup(user_folder_name, backup_path)
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

## 0.4.1

- 添加固件安装前的提示
- 安装模拟器时不再自动关闭启动中的模拟器 (目录被其它程序占用时中止安装)
- 新增 yuzu 存档备份功能 (#57)
- 修复当系统缩放不为 100% 时,保存的窗口大小不正确的问题 (#58)
- 修复当系统设置为 IPv6 优先时无法打开页面的问题 & 文档更新. by @RivenNero

## 0.4.0

- 当 webview 模式长时间未能启动后自动切换至浏览器模式 (#47)(#48)
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.4.0'
current_version = '0.4.1'
user_agent = f'ns-emu-tools/{current_version}'


Expand Down
22 changes: 20 additions & 2 deletions module/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import subprocess
from pathlib import Path

from module.msg_notifier import send_notify
from module.network import get_finial_url

logger = logging.getLogger(__name__)
Expand All @@ -14,7 +14,6 @@ def check_and_install_msvc():
logger.info(f'msvc already installed.')
return
from module.downloader import download
from module.msg_notifier import send_notify
send_notify('开始下载 msvc 安装包...')
logger.info('downloading msvc installer...')
download_info = download(get_finial_url('https://aka.ms/vs/17/release/VC_redist.x64.exe'))
Expand All @@ -25,6 +24,25 @@ def check_and_install_msvc():
# process.wait()


def delete_path(path: str):
import shutil
path = Path(path)
logger.info(f'delete_path: {str(path)}')
if not path.exists():
send_notify(f'{str(path)} 不存在')
return
if path.is_dir():
logging.info(f'delete folder: {str(path)}')
send_notify(f'正在删除 {str(path)} 目录...')
shutil.rmtree(path, ignore_errors=True)
elif path.is_file():
logging.info(f'delete file: {str(path)}')
send_notify(f'正在删除 {str(path)} 文件...')
os.remove(path)
logger.info(f'delete_path done: {str(path)}')
send_notify(f'{str(path)} 删除完成')


if __name__ == '__main__':
# infos = get_firmware_infos()
# for info in infos:
Expand Down
36 changes: 14 additions & 22 deletions module/ryujinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from storage import storage, add_ryujinx_history
import logging
import os
from utils.common import find_all_instances, kill_all_instances, is_path_in_use


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -54,14 +55,18 @@ def install_ryujinx_by_version(target_version: str, branch: str):
if not download_url:
send_notify(f'获取 ryujinx 下载链接失败')
raise IgnoredException(f'No download url found with branch: {branch}, version: {target_version}')
ryujinx_path = Path(config.ryujinx.path)
ryujinx_path.mkdir(parents=True, exist_ok=True)
if is_path_in_use(ryujinx_path):
logger.info(f'Ryujinx path is in use, skip install.')
send_notify(f'Ryujinx 目录正在被其它程序占用, 请先关闭这些程序(如 Ryujinx, 资源管理器等)再进行安装.')
send_notify(f'如果找不到是什么程序在占用,可以试试重启系统.')
return
download_url = get_github_download_url(download_url)
logger.info(f'download ryujinx from url: {download_url}')
send_notify(f'开始下载 ryujinx ...')
info = download(download_url)
file = info.files[0]
ryujinx_path = Path(config.ryujinx.path)
ryujinx_path.mkdir(parents=True, exist_ok=True)
kill_all_ryujinx_instance(ryujinx_path)
from utils.package import uncompress
import tempfile
tmp_dir = Path(tempfile.gettempdir()).joinpath('ryujinx-install')
Expand Down Expand Up @@ -122,23 +127,6 @@ def clear_ryujinx_folder(ryujinx_path: Path):
os.remove(path)


def kill_all_ryujinx_instance(ryujinx_path: Path = None):
import psutil
kill_flag = False
for p in psutil.process_iter():
if p.name().startswith('Ryujinx.'):
if ryujinx_path is not None:
process_path = Path(p.exe()).parent.absolute()
if ryujinx_path.absolute() != process_path:
continue
send_notify(f'关闭 Ryujinx 进程 [{p.pid}]')
logger.info(f'kill Ryujinx process [{p.pid}]')
p.kill()
kill_flag = True
if kill_flag:
time.sleep(1)


def get_ryujinx_user_folder():
ryujinx_path = Path(config.ryujinx.path)
if ryujinx_path.joinpath('portable/').exists():
Expand Down Expand Up @@ -192,7 +180,11 @@ def detect_ryujinx_version():
config.ryujinx.version = None
dump_config()
return None
kill_all_ryujinx_instance()
instances = find_all_instances('Ryujinx.')
if instances:
logger.info(f'Ryujinx pid={[p.pid for p in instances]} is running, skip install.')
send_notify(f'Ryujinx 正在运行中, 请先关闭 Ryujinx.')
return
config.ryujinx.branch = detect_current_branch()
st_inf = subprocess.STARTUPINFO()
st_inf.dwFlags = st_inf.dwFlags | subprocess.STARTF_USESHOWWINDOW
Expand All @@ -211,7 +203,7 @@ def detect_ryujinx_version():
break
except:
logger.exception('error occur in get_all_window_name')
kill_all_ryujinx_instance()
kill_all_instances('Ryujinx.')
if version:
if 'ldn' in version:
idx = version.index('ldn')
Expand Down
Loading

0 comments on commit 1b5220f

Please sign in to comment.