mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 16:44:13 +08:00
checksha
This commit is contained in:
parent
b73c62f1aa
commit
8430e769fb
@ -941,7 +941,7 @@ class MAINUI:
|
|||||||
self.translation_ui.showhideui()
|
self.translation_ui.showhideui()
|
||||||
|
|
||||||
def showtraymessage(self, title, message):
|
def showtraymessage(self, title, message):
|
||||||
self.tray.showMessage(_TR(title), _TR(message), getExeIcon(getcurrexe()))
|
self.tray.showMessage(title, message, getExeIcon(getcurrexe()))
|
||||||
|
|
||||||
def destroytray(self):
|
def destroytray(self):
|
||||||
self.tray.hide()
|
self.tray.hide()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from qtsymbols import *
|
from qtsymbols import *
|
||||||
import platform, functools
|
import platform, functools
|
||||||
import winsharedutils, queue
|
import winsharedutils, queue, hashlib
|
||||||
from myutils.config import globalconfig, static_data, _TR
|
from myutils.config import globalconfig, static_data, _TR
|
||||||
from myutils.wrapper import threader, tryprint
|
from myutils.wrapper import threader, tryprint
|
||||||
from myutils.hwnd import getcurrexe
|
from myutils.hwnd import getcurrexe
|
||||||
@ -60,7 +60,7 @@ def trygetupdate():
|
|||||||
version, links = tryqueryfromgithub()
|
version, links = tryqueryfromgithub()
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
return version, links[bit]
|
return version, links[bit], links.get("sha256", {}).get(bit, None)
|
||||||
|
|
||||||
|
|
||||||
def doupdate():
|
def doupdate():
|
||||||
@ -82,18 +82,23 @@ def doupdate():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def updatemethod_checkalready(size, savep):
|
def updatemethod_checkalready(size, savep, sha256):
|
||||||
if not os.path.exists(savep):
|
if not os.path.exists(savep):
|
||||||
return False
|
return False
|
||||||
stats = os.stat(savep)
|
stats = os.stat(savep)
|
||||||
if stats.st_size != size:
|
if stats.st_size != size:
|
||||||
return False
|
return False
|
||||||
return True
|
if not sha256:
|
||||||
|
return True
|
||||||
|
with open(savep, "rb") as ff:
|
||||||
|
newsha256 = hashlib.sha256(ff.read()).hexdigest()
|
||||||
|
# print(newsha256, sha256)
|
||||||
|
return newsha256 == sha256
|
||||||
|
|
||||||
|
|
||||||
@tryprint
|
@tryprint
|
||||||
def updatemethod(url, self):
|
def updatemethod(urls, self):
|
||||||
|
url, sha256 = urls
|
||||||
check_interrupt = lambda: not (
|
check_interrupt = lambda: not (
|
||||||
globalconfig["autoupdate"] and versionchecktask.empty()
|
globalconfig["autoupdate"] and versionchecktask.empty()
|
||||||
)
|
)
|
||||||
@ -104,7 +109,7 @@ def updatemethod(url, self):
|
|||||||
size = int(r2.headers["Content-Length"])
|
size = int(r2.headers["Content-Length"])
|
||||||
if check_interrupt():
|
if check_interrupt():
|
||||||
return
|
return
|
||||||
if updatemethod_checkalready(size, savep):
|
if updatemethod_checkalready(size, savep, sha256):
|
||||||
return savep
|
return savep
|
||||||
with open(savep, "wb") as file:
|
with open(savep, "wb") as file:
|
||||||
sess = requests.session()
|
sess = requests.session()
|
||||||
@ -130,7 +135,7 @@ def updatemethod(url, self):
|
|||||||
|
|
||||||
if check_interrupt():
|
if check_interrupt():
|
||||||
return
|
return
|
||||||
if updatemethod_checkalready(size, savep):
|
if updatemethod_checkalready(size, savep, sha256):
|
||||||
return savep
|
return savep
|
||||||
|
|
||||||
|
|
||||||
@ -167,7 +172,7 @@ def versioncheckthread(self):
|
|||||||
if not (need and globalconfig["autoupdate"]):
|
if not (need and globalconfig["autoupdate"]):
|
||||||
continue
|
continue
|
||||||
self.progresssignal.emit("……", 0)
|
self.progresssignal.emit("……", 0)
|
||||||
savep = updatemethod(_version[1], self)
|
savep = updatemethod(_version[1:], self)
|
||||||
if not savep:
|
if not savep:
|
||||||
self.progresssignal.emit(_TR("自动更新失败,请手动更新"), 0)
|
self.progresssignal.emit(_TR("自动更新失败,请手动更新"), 0)
|
||||||
continue
|
continue
|
||||||
|
Loading…
x
Reference in New Issue
Block a user