Skip to content

Commit

Permalink
Merge pull request #35 from triwinds/dev
Browse files Browse the repository at this point in the history
PR for 0.3.6
  • Loading branch information
triwinds authored Mar 24, 2023
2 parents ae7ada0 + c5fcc0c commit 345770d
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 95 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 0.3.6
- 对于一些不经常发生变更的数据使用持久化缓存
- 更新 ffhome 的链接
- 一些样式与描述调整
- 在列表中显示金手指文件里面以 {} 包裹的内容

## 0.3.5
- 打开金手指管理界面时异步加载游戏信息
- DoH 查询时复用已建立的连接
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.3.5'
current_version = '0.3.6'
user_agent = f'ns-emu-tools/{current_version}'


Expand Down
28 changes: 19 additions & 9 deletions module/cheats.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@
import shutil
import string
from pathlib import Path
from typing import List, Dict, Optional
from utils.network import session
from typing import List, Dict
from utils.network import get_durable_cache_session
import logging
import time
from functools import lru_cache
from utils.string_util import auto_decode
from module.msg_notifier import send_notify


logger = logging.getLogger(__name__)
cheat_item_re = re.compile(r'\[(.*?)][\n\r]+([\n\ra-z0-9A-Z\s]+)', re.MULTILINE)
multi_new_line_re = re.compile('(\r\n|\n){2,}')
cheat_file_re = re.compile(r'^[\dA-Za-z]{16}.[tT][xX][tT]$')
cheat_file_re = re.compile(r'^[\dA-Za-z]{16}.txt$')
game_id_re = re.compile(r'^[\dA-Za-z]{16}$')
cheat_name_re = re.compile(r'\{.*?}')


# @lru_cache(1)
def get_game_data():
res = {}
try:
resp = session.get('https://cdn.jsdelivr.net/gh/triwinds/ns-emu-tools@main/game_data.json', timeout=5)
resp = get_durable_cache_session().get(
'https://cdn.jsdelivr.net/gh/triwinds/ns-emu-tools@main/game_data.json', timeout=5)
return resp.json()
except Exception as e:
logger.warning(f'fail to load game data, ex: {e}')
Expand Down Expand Up @@ -67,7 +68,6 @@ def _parse_ryujinx_cheat_file():

def _parse_yuzu_cheat_file(cheat_file: Path):
# yuzu: https://github.com/yuzu-emu/yuzu/blob/master/src/core/memory/cheat_engine.cpp#L100
from utils.string_util import auto_decode
with open(cheat_file, 'rb') as f:
data = auto_decode(f.read()).strip()
if not data:
Expand Down Expand Up @@ -127,15 +127,25 @@ def list_all_cheat_files_from_folder(folder_path: str):
if not folder.exists():
raise RuntimeError(f'目录 {folder} 不存在.')
res = []
for txt_file in folder.glob('*.[tT][xX][tT]'):
for txt_file in folder.glob('*.txt'):
if cheat_file_re.match(txt_file.name):
name = _read_cheat_name(txt_file)
res.append({
'path': str(txt_file.absolute()),
'name': txt_file.name
'name': name
})
return res


def _read_cheat_name(txt_file: Path):
with txt_file.open('rb') as f:
text = auto_decode(f.read())
res = cheat_name_re.findall(text)
if res:
return f'{txt_file.name} - {res[0]}'
return txt_file.name


def load_cheat_chunk_info(cheat_file_path: str):
cheat_file = Path(cheat_file_path)
if not cheat_file.exists():
Expand Down
4 changes: 2 additions & 2 deletions module/firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from functools import lru_cache
from config import config
from module.downloader import download
from utils.network import get_finial_url, session
from utils.network import get_finial_url, get_durable_cache_session

logger = logging.getLogger(__name__)
hactool_path = Path(os.path.realpath(os.path.dirname(__file__))).joinpath('hactool.exe')
Expand Down Expand Up @@ -108,7 +108,7 @@ def get_firmware_infos():
import urllib.parse
base_url = 'https://archive.org/download/nintendo-switch-global-firmwares/'
url = base_url + 'nintendo-switch-global-firmwares_files.xml'
resp = session.get(get_finial_url(url), timeout=5)
resp = get_durable_cache_session().get(get_finial_url(url), timeout=5)
data = xmltodict.parse(resp.text)
files = data['files']['file']
res = []
Expand Down
2 changes: 1 addition & 1 deletion ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def main(port=0, mode=None, dev=False):
mode = 'edge'
else:
mode = 'user default'
size = (1440, 900)
size = (1440, 850)
logger.info(f'browser mode: {mode}')
if port == 0:
from utils.network import get_available_port
Expand Down
2 changes: 1 addition & 1 deletion ui_webview.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def main():
port = get_available_port()
url = f'http://localhost:{port}/{default_page}'
logger.info(f'start webview with url: {url}')
webview.create_window('NS EMU TOOLS', url, width=1440, height=900, text_select=True)
webview.create_window('NS EMU TOOLS', url, width=1440, height=850, text_select=True)
webview.start(func=start_eel)


Expand Down
26 changes: 25 additions & 1 deletion utils/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import requests_cache
from requests.adapters import HTTPAdapter
from gevent.lock import RLock

logger = logging.getLogger(__name__)

Expand All @@ -30,7 +31,30 @@
session.mount('https://cfrp.e6ex.com', HTTPAdapter(max_retries=5))
session.mount('https://nsarchive.e6ex.com', HTTPAdapter(max_retries=5))
session.mount('https://api.github.com', HTTPAdapter(max_retries=5))
session.mount('https://cdn.jsdelivr.net', HTTPAdapter(max_retries=5))


_durable_cache_session = None
request_lock = RLock()


def get_durable_cache_session():
global _durable_cache_session
if not _durable_cache_session:
_durable_cache_session = requests_cache.CachedSession(cache_control=True)
_durable_cache_session.mount('https://cdn.jsdelivr.net', HTTPAdapter(max_retries=5))
_durable_cache_session.mount('https://nsarchive.e6ex.com', HTTPAdapter(max_retries=5))
origin_get = _durable_cache_session.get

def sync_get(url: str, params=None, **kwargs):
request_lock.acquire()
try:
return origin_get(url, params, **kwargs)
finally:
request_lock.release()

_durable_cache_session.get = sync_get
return _durable_cache_session


options_on_proxy = {
'split': '16',
Expand Down
151 changes: 90 additions & 61 deletions vue/src/components/ConsoleDialog.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<template>
<div class="text-center">
<v-dialog
v-model="$store.state.consoleDialogFlag"
max-width="900"
:persistent="$store.state.persistentConsoleDialog"
v-model="$store.state.consoleDialogFlag"
max-width="900"
:persistent="$store.state.persistentConsoleDialog"
>

<v-card>
Expand All @@ -12,41 +12,34 @@
</v-card-title>

<div style="padding-left: 10px; padding-right: 10px; padding-top: 10px;" class="flex-grow-0">
<v-virtual-scroll ref="consoleBox" :items="$store.state.consoleMessages" height="300" item-height="26"
style="background-color: #000; overflow-y: scroll; overflow-x: scroll;">
<template v-slot:default="{ item, index }">
<v-list-item :key="index">
<v-list-item-content class="white--text" style="white-space: nowrap; display: inline-block;">{{item}}</v-list-item-content>
</v-list-item>
</template>
</v-virtual-scroll>
<textarea id="consoleBox" :value="logText" readonly rows="15"></textarea>
</div>

<v-divider></v-divider>

<v-card-actions>
<v-spacer></v-spacer>
<v-btn
color="primary"
text
@click="pauseDownload"
v-if="$store.state.persistentConsoleDialog"
color="primary"
text
@click="pauseDownload"
v-if="$store.state.persistentConsoleDialog"
>
暂停下载任务
</v-btn>
<v-btn
color="primary"
text
@click="stopDownload"
v-if="$store.state.persistentConsoleDialog"
color="primary"
text
@click="stopDownload"
v-if="$store.state.persistentConsoleDialog"
>
中断并删除下载任务
</v-btn>
<v-btn
color="primary"
text
@click="closeDialog"
:disabled="$store.state.persistentConsoleDialog"
color="primary"
text
@click="closeDialog"
:disabled="$store.state.persistentConsoleDialog"
>
关闭
</v-btn>
Expand All @@ -57,46 +50,82 @@
</template>

<script>
export default {
name: 'ConsoleDialog',
data () {
return {
}
},
created() {
// this.showConsoleDialog()
// setInterval(() => {
// this.appendConsoleMessage("test" + new Date().getTime())
// }, 300)
},
methods: {
closeDialog() {
this.$store.commit('SET_CONSOLE_DIALOG_FLAG', false)
},
stopDownload() {
window.eel.stop_download()((resp) => {
console.log(resp)
})
},
pauseDownload() {
window.eel.pause_download()((resp) => {
console.log(resp)
})
},
export default {
name: 'ConsoleDialog',
data() {
return {}
},
created() {
// this.showConsoleDialog()
// setInterval(() => {
// this.appendConsoleMessage("test" + new Date().getTime())
// }, 300)
},
methods: {
closeDialog() {
this.$store.commit('SET_CONSOLE_DIALOG_FLAG', false)
},
computed: {
stopDownload() {
window.eel.stop_download()((resp) => {
console.log(resp)
})
},
updated() {
this.$nextTick(() => {
let consoleBox = this.$refs.consoleBox
if (consoleBox) {
if (consoleBox.$el.scrollHeight > consoleBox.$el.offsetHeight) {
consoleBox.$el.scrollTop = consoleBox.$el.scrollHeight
}
}
pauseDownload() {
window.eel.pause_download()((resp) => {
console.log(resp)
})
},
},
computed: {
logText() {
let text = ''
for (let line of this.$store.state.consoleMessages) {
text += line + '\n'
}
return text
}
},
updated() {
this.$nextTick(() => {
let consoleBox = document.getElementById("consoleBox")
if (consoleBox) {
consoleBox.scrollTop = consoleBox.scrollHeight
}
})
}
</script>
}
</script>

<style scoped>
#consoleBox {
background-color: #000;
width: 100%;
color: white;
overflow-x: scroll;
overflow-y: scroll;
resize: none;
}
#consoleBox::-webkit-resizer, #consoleBox::-webkit-scrollbar-thumb {
background: #aaa;
border-radius: 3px;
}
#consoleBox::-webkit-scrollbar {
width: 5px !important;
height: 5px !important;
}
#consoleBox::-webkit-scrollbar-corner, #consoleBox ::-webkit-scrollbar-track {
background: transparent !important;
}
#consoleBox::-webkit-resizer, #consoleBox ::-webkit-scrollbar-thumb {
background: #aaa;
border-radius: 3px;
}
#consoleBox::-webkit-scrollbar-corner, #consoleBox ::-webkit-scrollbar-track {
background: transparent !important;
}
</style>
8 changes: 7 additions & 1 deletion vue/src/pages/OtherLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,15 @@ export default {
title: '金手指合集',
description: '由 Switch 520 整理的金手指合集',
},{
link: 'https://xxxxx520.com/48675.html',
link: 'http://www.ffhome.com/works/1814.html',
title: 'FFHOME Nintendo Switch Game Manager',
description: '软件全称 FFHOME Nintendo Switch Game Manager,它是一款整理(处理)你拥有的NSP格式、XCI格式游戏文件的一款小工具,包括文件信息查看、批量更名和文件处理等功能。',
subLinks: [
{
name: '备用',
link: 'https://xxxxx520.com/48675.html'
}
]
},
],
}
Expand Down
11 changes: 4 additions & 7 deletions vue/src/pages/Ryujinx.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,16 @@
<span class="text-h6 secondary--text">当前固件版本:</span>
<v-tooltip top>
<template v-slot:activator="{ on, attrs }">
<v-btn color="warning" outlined style="margin-right: 15px" v-bind="attrs" v-on="on"
<v-btn color="warning" outlined v-bind="attrs" v-on="on"
@click="detectFirmwareVersion" :disabled='isRunningInstall'>
{{ ryujinxConfig.firmware ? ryujinxConfig.firmware : "未知" }}
</v-btn>
</template>
<span>点击重新检测固件版本, 需安装密钥后使用</span>
</v-tooltip>
<span class="text-h6 secondary--text">
最新固件版本:
</span>
<span class="text-h6">
{{ latestFirmwareVersion }}
</span>
<span class="text-h7 secondary--text">
(如果固件能用就没必要更新)
</span>
</v-col>
</v-row>
</v-container>
Expand Down
Loading

0 comments on commit 345770d

Please sign in to comment.