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