mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 16:44:13 +08:00
updater
This commit is contained in:
parent
3d588bdb4c
commit
c5a94b4674
@ -82,6 +82,7 @@ class MAINUI:
|
||||
self.showocrimage = None
|
||||
self.showocrimage_cached = None
|
||||
self.autoswitchgameuid = True
|
||||
self.istriggertoupdate = False
|
||||
|
||||
def maybesetimage(self, pair):
|
||||
if self.showocrimage:
|
||||
@ -974,9 +975,13 @@ class MAINUI:
|
||||
trayMenu.addAction(quitAction)
|
||||
self.tray.setContextMenu(trayMenu)
|
||||
self.tray.activated.connect(self.leftclicktray)
|
||||
self.tray.messageClicked.connect(winsharedutils.dispatchcloseevent)
|
||||
self.tray.messageClicked.connect(self.triggertoupdate)
|
||||
self.tray.show()
|
||||
|
||||
def triggertoupdate(self):
|
||||
self.istriggertoupdate = True
|
||||
winsharedutils.dispatchcloseevent()
|
||||
|
||||
def leftclicktray(self, reason):
|
||||
if reason == QSystemTrayIcon.ActivationReason.Trigger:
|
||||
self.translation_ui.showhideui()
|
||||
|
@ -16,7 +16,6 @@ from gui.setting_about import (
|
||||
setTab_aboutlazy,
|
||||
setTab_update,
|
||||
versionlabelmaybesettext,
|
||||
updateprogress,
|
||||
versioncheckthread,
|
||||
)
|
||||
from gui.dynalang import LListWidgetItem, LListWidget
|
||||
@ -67,7 +66,6 @@ class TabWidget(QWidget):
|
||||
class Setting(closeashidewindow):
|
||||
voicelistsignal = pyqtSignal(object)
|
||||
versiontextsignal = pyqtSignal(str)
|
||||
progresssignal = pyqtSignal(str, int)
|
||||
progresssignal2 = pyqtSignal(str, int)
|
||||
progresssignal3 = pyqtSignal(int)
|
||||
showandsolvesig = pyqtSignal(str, str)
|
||||
@ -81,7 +79,6 @@ class Setting(closeashidewindow):
|
||||
self.versiontextsignal.connect(
|
||||
functools.partial(versionlabelmaybesettext, self)
|
||||
)
|
||||
self.progresssignal.connect(functools.partial(updateprogress, self))
|
||||
self.isfirst = True
|
||||
versioncheckthread(self)
|
||||
registrhotkeys(self)
|
||||
|
@ -76,7 +76,7 @@ def doupdate():
|
||||
gobject.getcachedir("Updater.exe"),
|
||||
)
|
||||
subprocess.Popen(
|
||||
rf".\cache\Updater.exe update .\cache\update\LunaTranslator{bit} "
|
||||
rf".\cache\Updater.exe update {int(gobject.baseobject.istriggertoupdate)} .\cache\update\LunaTranslator{bit} "
|
||||
+ dynamiclink("{main_server}")
|
||||
)
|
||||
|
||||
@ -129,8 +129,9 @@ def updatemethod(urls, self):
|
||||
prg = int(10000 * file_size / size)
|
||||
prg100 = prg / 100
|
||||
sz = int(1000 * (int(size / 1024) / 1024)) / 1000
|
||||
self.progresssignal.emit(
|
||||
"总大小{} MB 进度 {:0.2f}% ".format(sz, prg100), prg
|
||||
self.downloadprogress_cache = (
|
||||
"总大小{} MB 进度 {:0.2f}% ".format(sz, prg100),
|
||||
prg,
|
||||
)
|
||||
|
||||
if check_interrupt():
|
||||
@ -140,7 +141,7 @@ def updatemethod(urls, self):
|
||||
|
||||
|
||||
def uncompress(self, savep):
|
||||
self.progresssignal.emit(_TR("正在解压"), 10000)
|
||||
self.downloadprogress_cache = (_TR("正在解压"), 10000)
|
||||
shutil.rmtree(gobject.getcachedir("update/LunaTranslator/"))
|
||||
with zipfile.ZipFile(savep) as zipf:
|
||||
zipf.extractall(gobject.getcachedir("update"))
|
||||
@ -152,7 +153,7 @@ def versioncheckthread(self):
|
||||
while True:
|
||||
x = versionchecktask.get()
|
||||
gobject.baseobject.update_avalable = False
|
||||
self.progresssignal.emit("", 0)
|
||||
self.downloadprogress_cache = ("", 0)
|
||||
if not x:
|
||||
continue
|
||||
self.versiontextsignal.emit("获取中") # ,'',url,url))
|
||||
@ -171,28 +172,20 @@ def versioncheckthread(self):
|
||||
)
|
||||
if not (need and globalconfig["autoupdate"]):
|
||||
continue
|
||||
self.progresssignal.emit("……", 0)
|
||||
self.downloadprogress_cache = ("……", 0)
|
||||
savep = updatemethod(_version[1:], self)
|
||||
if not savep:
|
||||
self.progresssignal.emit(_TR("自动更新失败,请手动更新"), 0)
|
||||
self.downloadprogress_cache = (_TR("自动更新失败,请手动更新"), 0)
|
||||
continue
|
||||
|
||||
uncompress(self, savep)
|
||||
gobject.baseobject.update_avalable = True
|
||||
self.progresssignal.emit(_TR("准备完毕,等待更新"), 10000)
|
||||
self.downloadprogress_cache = (_TR("准备完毕,等待更新"), 10000)
|
||||
gobject.baseobject.showtraymessage(
|
||||
sversion, _TR("准备完毕,等待更新") + "\n" + _TR("点击消息后退出并开始更新")
|
||||
)
|
||||
|
||||
|
||||
def updateprogress(self, text, val):
|
||||
try:
|
||||
self.downloadprogress.setValue(val)
|
||||
self.downloadprogress.setFormat(text)
|
||||
except:
|
||||
self.downloadprogress_cache = val, text
|
||||
|
||||
|
||||
def createdownloadprogress(self):
|
||||
|
||||
self.downloadprogress = QProgressBar()
|
||||
@ -202,12 +195,18 @@ def createdownloadprogress(self):
|
||||
self.downloadprogress.setAlignment(
|
||||
Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter
|
||||
)
|
||||
try:
|
||||
val, text = self.downloadprogress_cache
|
||||
|
||||
def __cb(self):
|
||||
try:
|
||||
text, val = self.downloadprogress_cache
|
||||
except:
|
||||
return
|
||||
self.downloadprogress.setValue(val)
|
||||
self.downloadprogress.setFormat(text)
|
||||
except:
|
||||
pass
|
||||
|
||||
self.downloadprogresstimer = QTimer(self.downloadprogress)
|
||||
self.downloadprogresstimer.timeout.connect(functools.partial(__cb, self))
|
||||
self.downloadprogresstimer.start(100)
|
||||
return self.downloadprogress
|
||||
|
||||
|
||||
|
@ -29,7 +29,7 @@ include(generate_product_version)
|
||||
|
||||
set(VERSION_MAJOR 5)
|
||||
set(VERSION_MINOR 33)
|
||||
set(VERSION_PATCH 7)
|
||||
set(VERSION_PATCH 8)
|
||||
|
||||
add_library(pch pch.cpp)
|
||||
target_precompile_headers(pch PUBLIC pch.h)
|
||||
|
@ -23,15 +23,15 @@ int updatewmain(int argc, wchar_t *argv[])
|
||||
*(wcsrchr(path, '\\')) = 0;
|
||||
|
||||
SetCurrentDirectory(path);
|
||||
int needreload = std::stoi(argv[1]);
|
||||
try
|
||||
{
|
||||
std::filesystem::copy(argv[1], L".\\", std::filesystem::copy_options::recursive | std::filesystem::copy_options::overwrite_existing);
|
||||
MessageBoxW(GetForegroundWindow(), L"Update success", L"Success", 0);
|
||||
std::filesystem::copy(argv[2], L".\\", std::filesystem::copy_options::recursive | std::filesystem::copy_options::overwrite_existing);
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
MessageBoxA(GetForegroundWindow(), (std::string("Update failed!\r\n") + e.what()).c_str(), "Error", 0);
|
||||
ShellExecute(0, L"open", (std::wstring(argv[2]) + L"/Github/LunaTranslator/releases").c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||||
ShellExecute(0, L"open", (std::wstring(argv[3]) + L"/Github/LunaTranslator/releases").c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||||
return 0;
|
||||
}
|
||||
try
|
||||
@ -42,5 +42,10 @@ int updatewmain(int argc, wchar_t *argv[])
|
||||
catch (std::exception &e)
|
||||
{
|
||||
}
|
||||
MessageBoxW(GetForegroundWindow(), L"Update success", L"Success", 0);
|
||||
if (needreload)
|
||||
{
|
||||
ShellExecute(0, L"open", L".\\LunaTranslator.exe", NULL, NULL, SW_SHOWNORMAL);
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user