Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

一键更新相关功能, 生涯页刷新保留筛选, 优化异常时保存的log #354

Merged
merged 7 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 44 additions & 44 deletions app/common/update.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
import subprocess

bat = '''@echo off
bat = '''
# 等待 Seraphine.exe 退出
while ((Get-Process Seraphine -ErrorAction SilentlyContinue) -ne $null) {
Write-Host "Seraphine is running, waiting..."
Start-Sleep -Seconds 1
}

$fileList = Get-Content -Path "filelist.txt"

# 遍历文件列表
foreach ($file in $fileList) {
# 检查文件或目录是否存在
if (Test-Path -Path $file) {
# 删除文件或目录
Remove-Item -Path $file -Recurse -Force
Write-Output "Removed: $file"
} else {
Write-Output "NotFound: $file"
}
}

# 设置源路径
$src = "$env:AppData\\Seraphine\\temp"

# 移动目录
Get-ChildItem -Path $src -Directory | ForEach-Object {
Move-Item -Path $_.FullName -Destination '.' -Force
}

# 移动文件
Get-ChildItem -Path $src -File | ForEach-Object {
Move-Item -Path $_.FullName -Destination '.' -Force
}

# 删除更新解压的临时文件夹
Remove-Item -Path $src -Recurse -Force

# 启动新版本的 Seraphine.exe
Start-Process -FilePath ".\Seraphine.exe" -NoNewWindow

# 删除自身脚本文件
Remove-Item -Path $MyInvocation.MyCommand.Definition -Force

:start

@REM 等待 Seraphine.exe 退出
tasklist | find /i "Seraphine.exe" > nul
if NOT errorlevel 1 (
echo Seraphine is running, waiting...
timeout /t 1 > nul
goto start
)

@REM 删除当前目录下所有文件夹
for /d %%i in (*) do (
rmdir "%%~fi" /s /q
)

@REM 删除当前目录下除了自己的所有文件
for %%i in (*) do (
if NOT "%%i" equ "updater.bat" (
del "%%i" /s /q
)
)

@REM 将解压好的文件和文件夹拷贝到当前文件夹内
set src=%AppData%\\Seraphine\\temp

for /D %%a in (%src%\\*) do (
move %%a .
)

for %%a in (%src%\\*) do (
move %%a .
)

@REM 删除原来的那堆东西
rmdir %src% /s /q

@REM 启动一下新版本
start /b .\Seraphine.exe

@REM 删除自己
del %0
'''


def runUpdater():
with open("updater.bat", 'w', encoding='utf-8') as f:
with open("updater.ps1", 'w', encoding='utf-8') as f:
f.write(bat)

subprocess.Popen("updater.bat")
subprocess.Popen("PowerShell.exe -ExecutionPolicy Bypass -File updater.ps1")
19 changes: 19 additions & 0 deletions app/common/util.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

import requests
import base64
import subprocess
Expand Down Expand Up @@ -34,10 +36,27 @@ def checkUpdate(self):
"""
info = self.getReleasesInfo()

ver_info = self.__get_ver_info()
info["forbidden"] = ver_info.get("forbidden", False)

if info.get("tag_name")[1:] != VERSION:
return info
return None

def __get_ver_info(self):
url = f'{self.githubApi}/repos/{self.user}/{self.repositories}/contents/document/ver.json'
if cfg.get(cfg.enableProxy):
proxy = {'https': cfg.get(cfg.proxyAddr)}
else:
proxy = None

res = self.sess.get(url, proxies=proxy).json()

json_data = json.loads(str(base64.b64decode(res['content']), encoding='utf-8'))

return json_data.get(VERSION, {})


def getNotice(self):
url = f'{self.githubApi}/repos/{self.user}/{self.repositories}/contents/document/notice.md'

Expand Down
3 changes: 3 additions & 0 deletions app/components/message_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def __initWidget(self):

self.myYesButton.setEnabled(False)

# 当前版本被禁用时, 不允许忽略版本
self.myCancelButton.setEnabled(not self.info["forbidden"])

def __initLayout(self):
self.viewLayout.addWidget(self.titleLabel)
self.viewLayout.addWidget(self.content)
Expand Down
2 changes: 1 addition & 1 deletion app/components/seraphine_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ def __str__(self):
methods = [attr for attr in dir(self) if callable(getattr(self, attr))]
attrs = [f"{k}({type(v).__name__})={v!r}" for k, v in self.__dict__.items() if
not isinstance(v, wrapper) and k not in methods]
return f"{self.__class__.__name__}(\n {', '.join(attrs)}\n)"
return f"{self.__class__.__name__}({', '.join(attrs)})"
2 changes: 1 addition & 1 deletion app/lol/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __str__(self):
# 如果是None的成员, 不会被打印; 没打印response就是没有响应;
attrs = [f"{k}={v!r}" for k, v in self.__dict__.items()
if v is not None]
return f"PastRequest(\n {', '.join(attrs)}\n)"
return f"PastRequest({', '.join(attrs)})"


def needLcu():
Expand Down
3 changes: 3 additions & 0 deletions app/view/career_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,10 @@ async def __changeToCurrentSummoner(self):
@asyncSlot()
async def refresh(self):
if self.puuid:
tmp_filter_idx = self.filterComboBox.currentIndex()
await self.updateInterface(puuid=self.puuid)
self.filterComboBox.setCurrentIndex(tmp_filter_idx)
self.__onfilterComboBoxChanged(tmp_filter_idx)

async def updateInterface(self, puuid=None, summoner=None):
'''
Expand Down
5 changes: 3 additions & 2 deletions app/view/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,10 +921,10 @@ def exceptHook(self, ty, value, tb):
if ty in [ConnectionRefusedError, ClientConnectorError]:
return

logger.error("connector call_stack -------------- ↓", "Crash")
logger.error(f"Exception occurred:\n{content}", "Crash")

for call in connector.callStack:
logger.error(call, "Crash")
logger.error("connector call_stack -------------- ↑", "Crash")

logger.error(str(self.searchInterface), "Crash")
logger.error(str(self.gameInfoInterface), "Crash")
Expand All @@ -939,6 +939,7 @@ def exceptHook(self, ty, value, tb):

self.oldHook(ty, value, tb)
signalBus.terminateListeners.emit()
logger.error("Abnormal exit", "Crash")
sys.exit()

def __onCurrentStackedChanged(self, index):
Expand Down
5 changes: 5 additions & 0 deletions document/ver.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"0.12.3": {
"forbidden": false
}
}
6 changes: 6 additions & 0 deletions make.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ rm -Path .\dist\Seraphine\app\resource\game* -r
rm -r .\dist\Seraphine\app\resource\i18n\Seraphine.zh_CN.ts
rm -r .\dist\Seraphine\app\view

$files = Get-ChildItem -Path ".\dist\Seraphine\*" -Recurse |
Select-Object -ExpandProperty FullName |
ForEach-Object { $_.Replace((Resolve-Path ".\dist\Seraphine").Path + "\", "") }

$files | Out-File -FilePath ".\dist\Seraphine\filelist.txt" -Encoding UTF8

if (! $dbg) {
7z a $dest\Seraphine.zip .\dist\Seraphine\* -r
rm -r .\dist
Expand Down
Loading