Skip to content

Commit

Permalink
Merge pull request #30 from triwinds/dev
Browse files Browse the repository at this point in the history
PR for 0.3.1
  • Loading branch information
triwinds authored Mar 1, 2023
2 parents bd102bc + 24e7583 commit 8cacfef
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 34 deletions.
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.3.1
- 调整浏览器的兼容范围, 修复某些老版本浏览器白屏的问题
- 最低需要支持 es6 的浏览器, 一般在 2016 年之后发布的浏览器都支持
- 修复固件 md5 校验失败时没有自动删除相应 zip 包的问题
- 修复非简体中文的系统环境中自动更新失败的问题
- 调整 Ryujinx 的安装逻辑: 安装时只移除 Ryujinx*.exe 文件, 其余文件使用覆盖模式
- 更新 CloudflareSpeedTest 版本至 v2.2.2 , 并修复了一些问题

## 0.3.0
- 在 api 请求发生超时错误时进行重试
- 当 IPv6 启用时 DoH 尝试查询 AAAA 记录
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.0'
current_version = '0.3.1'
user_agent = f'ns-emu-tools/{current_version}'


Expand Down
44 changes: 35 additions & 9 deletions module/cfst.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
cd /d <cfst_path>
CloudflareST.exe -p 0 -url "https://cloudflaremirrors.com/archlinux/images/latest/Arch-Linux-x86_64-basic.qcow2"
"""
target_cfst_version = 'v2.2.2'
version_file = Path('CloudflareSpeedTest/cfst_version')


def download_cfst():
Expand All @@ -27,14 +29,17 @@ def download_cfst():
logger.info('downloading CloudflareSpeedTest...')
send_notify('开始下载 CloudflareSpeedTest...')
url = get_github_download_url('https://github.com/XIU2/CloudflareSpeedTest/releases/download'
'/v2.1.0/CloudflareST_windows_amd64.zip')
f'/{target_cfst_version}/CloudflareST_windows_amd64.zip')
info = download(url)
filepath = info.files[0].path
import zipfile
logger.info('unzip CloudflareSpeedTest...')
send_notify('正在解压 CloudflareSpeedTest...')
with zipfile.ZipFile(filepath, 'r') as zf:
zf.extractall('CloudflareSpeedTest')
os.remove(filepath)
with version_file.open('w') as f:
f.write(target_cfst_version)


def run_cfst():
Expand Down Expand Up @@ -107,17 +112,37 @@ def install_ip_to_hosts(ip: str, host_names: List[str]):
send_notify('hosts 文件更新失败, 请使用管理员权限重新启动程序.')


def get_current_cfst_version():
if not version_file.exists():
return
with version_file.open() as f:
return f.read()


def get_cf_hostnames():
default_list = ['nsarchive.e6ex.com', 'proxy.zyun.vip', 'download.nuaa.cf']
hostnames = get_override_host_names()
for hn in default_list:
if hn not in hostnames:
hostnames.append(hn)
return hostnames


def optimize_cloudflare_hosts():
if target_cfst_version != get_current_cfst_version():
logger.info(f'cfst version changed, target version: {target_cfst_version}, '
f'current version: {get_current_cfst_version()}')
logger.info(f'removing old cfst...')
send_notify('CloudflareSpeedTest 版本已更新, 正在切换至新版本')
import shutil
shutil.rmtree('CloudflareSpeedTest', ignore_errors=True)
exe_path = Path('CloudflareSpeedTest/CloudflareST.exe')
if not exe_path.exists():
download_cfst()
run_cfst()
show_result()
fastest_ip = get_fastest_ip_from_result()
host_names = get_override_host_names()
if not host_names:
host_names = ['nsarchive.e6ex.com']
install_ip_to_hosts(fastest_ip, host_names)
install_ip_to_hosts(fastest_ip, get_cf_hostnames())


def remove_cloudflare_hosts():
Expand All @@ -126,8 +151,8 @@ def remove_cloudflare_hosts():
send_notify('正在删除 hosts 文件中的相关配置...')
from module.hosts import Hosts, HostsEntry
hosts = Hosts()
host_names = get_override_host_names()
for hn in host_names:
hostnames = get_cf_hostnames()
for hn in hostnames:
hosts.remove_all_matching(name=hn)
write_hosts(hosts)
subprocess.Popen(['ipconfig', '/flushdns'], stdout=subprocess.DEVNULL).wait()
Expand All @@ -143,6 +168,7 @@ def write_hosts(hosts: Hosts):
if check_is_admin():
hosts.write()
logger.info(f'updated hosts: {hosts}')
return
elif os.name == 'nt':
from utils.admin import run_with_admin_privilege
tmp_hosts = str(Path('tmp_hosts').absolute())
Expand All @@ -156,8 +182,8 @@ def write_hosts(hosts: Hosts):


if __name__ == '__main__':
run_cfst()
# optimize_cloudflare_hosts()
# run_cfst()
optimize_cloudflare_hosts()
# print(check_is_admin())
# remove_cloudflare_hosts()
# install_ip_to_hosts(get_fastest_ip_from_result(), get_override_host_names())
2 changes: 1 addition & 1 deletion module/firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def install_firmware(firmware_version, target_firmware_path):
file = info.files[0]
if config.setting.download.verifyFirmwareMd5 and not check_file_md5(file.path, target_info['md5']):
logger.info(f'firmware md5 not match, removing file [{file}]...')
os.remove(file)
os.remove(file.path)
from exception.common_exception import Md5NotMatchException
raise Md5NotMatchException()
import zipfile
Expand Down
9 changes: 2 additions & 7 deletions module/ryujinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,9 @@ def install_firmware_to_ryujinx(firmware_version=None):

def clear_ryujinx_folder(ryujinx_path: Path):
send_notify('清除旧版 ryujinx 文件...')
for path in ryujinx_path.glob('*'):
if path.name.lower().strip() == 'portable':
continue
for path in ryujinx_path.glob('Ryujinx*.exe'):
logger.debug(f'removing path: {path}')
if path.is_dir():
shutil.rmtree(path)
else:
os.remove(path)
os.remove(path)


def kill_all_ryujinx_instance():
Expand Down
3 changes: 2 additions & 1 deletion module/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

logger = logging.getLogger(__name__)
script_template = """@echo off
chcp>nul 2>nul 65001
echo 开始准备更新
timeout /t 5 /nobreak
if exist "<old_exe>" (
Expand Down Expand Up @@ -78,7 +79,7 @@ def update_self_by_tag(tag: str):
.replace('<old_exe>', str(Path(sys.argv[0]).absolute()))\
.replace('<new_exe>', str(new_exe_path)).replace('<target_place>', str(target_path))
logger.info(f'creating update script')
with open('update.bat', 'w') as f:
with open('update.bat', 'w', encoding='utf-8') as f:
f.write(script)
script_path = Path(sys.argv[0]).parent.joinpath('update.bat').absolute()
logger.info(f'execute script')
Expand Down
13 changes: 10 additions & 3 deletions vue/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
presets: [
'@vue/cli-plugin-babel/preset',
[
'@babel/preset-env',
{
useBuiltIns: 'entry', // or "usage"
corejs: 3,
},
]
]
}
4 changes: 3 additions & 1 deletion vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
"not dead",
"Chrome >= 51",
"Firefox >= 54"
]
}
1 change: 1 addition & 0 deletions vue/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<script type=text/javascript src="<%= process.env.VUE_APP_EEL_BASE_URI %>/eel.js"></script>
<script>
Expand Down
4 changes: 3 additions & 1 deletion vue/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
size="100"
rounded
>
<img src="./assets/icon.webp" alt="">
<img src="./assets/icon.png" alt="">
</v-avatar>

<div>版本:v{{ $store.state.currentVersion }}
Expand Down Expand Up @@ -154,6 +154,8 @@
</template>

<script>
import 'core-js/stable';
import 'regenerator-runtime/runtime';
import router from "@/router";
import SpeedDial from "@/components/SpeedDial";
import ConsoleDialog from "@/components/ConsoleDialog";
Expand Down
Binary file added vue/src/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed vue/src/assets/icon.webp
Binary file not shown.
11 changes: 6 additions & 5 deletions vue/src/pages/CloudflareST.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import * as showdown from 'showdown';
var mdRaw = `
**Tip 1**: 这个功能仍在实验中,使用前请确保你已经了解足够的网络知识 (至少应该知道如何恢复 hosts 文件,以备不测)。
**Tips 1**: 这个功能仍在实验中,使用前请确保你已经了解足够的网络知识 (至少应该知道如何恢复 hosts 文件,以备不测)。
**Tip 2**: 如果你的默认的连接速度已经足够快,或者你正在使用梯子,那么这个功能对你来说应该没什么用。如果你仍然希望使用这个功能的话,请先关掉梯子,以免干扰测速结果。
**Tips 2**: 如果你的默认的连接速度已经足够快,或者你正在使用梯子,那么这个功能对你来说应该没什么用。如果你仍然希望使用这个功能的话,请先关掉梯子,以免干扰测速结果。
**Tip 3**: 这个功能仅对设置中带 Cloudflare 标识的下载源生效,因此使用时请切换至 Cloudflare 下载源。
**Tips 3**: 这个功能仅对设置中带 Cloudflare 标识的下载源生效,因此使用时请切换至 Cloudflare 下载源。
总所周知 Cloudflare 拥有众多边缘节点,而节点的连接速度不一,所以这里提供一个方法来自动选择较好的节点。
Expand All @@ -43,9 +43,10 @@ var mdRaw = `
具体就是使用 \`XIU2/CloudflareSpeedTest\` 工具找出连接速度最快的 Cloudflare 节点,并将之应用到 hosts 文件中,以提升下载速度 (~~大概~~。
由于需要修改 hosts 文件,所以需要使用 \`管理员权限\` 启动程序才能使这个功能正常运作
由于需要修改 hosts 文件,所以需要使用 \`管理员权限\` 才能使这个功能正常运作
ps. 有时候 Cloudflare 的 ip 可能会被 GFW 阻断(见 [这个 issue](https://github.com/XIU2/CloudflareSpeedTest/issues/217)),这时候请移除添加的配置,并使用梯子。
ps. 有时候 Cloudflare 的 ip 可能会被 GFW 阻断(见 [这个 issue](https://github.com/XIU2/CloudflareSpeedTest/issues/217)),
这时候请移除添加的配置再试试,如果还是不行就需要使用梯子了。
pps. 如果无法自动下载 CloudflareST,可以从 [这里](https://pan.baidu.com/s/1Z_wQ_eqx5rd48xgi7DtEsg?pwd=s0x2) 下载然后放到 download 目录。
`
Expand Down
3 changes: 1 addition & 2 deletions vue/src/pages/Ryujinx.vue
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ export default {
async askAndUpdateRyujinxPath() {
this.cleanAndShowConsoleDialog()
this.appendConsoleMessage('=============================================')
this.appendConsoleMessage('安装/更新模拟器时会删除目录下除模拟器用户数据外的其他文件')
this.appendConsoleMessage('请确保您选择的目录下没有除模拟器外的其他文件')
this.appendConsoleMessage('选择的目录将作为存放模拟器的根目录')
this.appendConsoleMessage('建议新建目录单独存放')
this.appendConsoleMessage('=============================================')
let data = await window.eel.ask_and_update_ryujinx_path()();
Expand Down
2 changes: 1 addition & 1 deletion vue/src/pages/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<v-col><p class="success--text text-h5">下载设置</p></v-col>
</v-row>
<v-switch v-model="setting.download.autoDeleteAfterInstall" label="安装完成后自动删除下载的安装包"></v-switch>
<v-switch v-model="setting.download.disableAria2Ipv6" label="aria2 禁用 IPV6 (重启程序后生效)"></v-switch>
<v-switch v-model="setting.download.disableAria2Ipv6" label="aria2 禁用 IPv6 (重启程序后生效)"></v-switch>
<v-switch v-model="setting.download.removeOldAria2LogFile" label="启动 aria2 前删除旧的日志"></v-switch>
<v-switch v-model="setting.download.verifyFirmwareMd5" label="固件下载完成后校验 md5"></v-switch>
</v-container>
Expand Down
3 changes: 1 addition & 2 deletions vue/src/pages/Yuzu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ export default {
async modifyYuzuPath() {
this.cleanAndShowConsoleDialog()
this.appendConsoleMessage('=============================================')
this.appendConsoleMessage('安装/更新模拟器时会删除目录下除模拟器用户数据外的其他文件')
this.appendConsoleMessage('请确保您选择的目录下没有除模拟器外的其他文件')
this.appendConsoleMessage('选择的目录将作为存放模拟器的根目录')
this.appendConsoleMessage('建议新建目录单独存放')
this.appendConsoleMessage('=============================================')
let data = await window.eel.ask_and_update_yuzu_path()()
Expand Down

0 comments on commit 8cacfef

Please sign in to comment.