This commit is contained in:
恍兮惚兮 2024-07-06 23:08:19 +08:00
parent 8747d3a8ab
commit e63731b7a0
3 changed files with 75 additions and 8 deletions

View File

@ -19,7 +19,7 @@ from gui.usefulwidget import (
versionchecktask = queue.Queue() versionchecktask = queue.Queue()
def getvesionmethod(): def getvesionmethod_github():
try: try:
headers = { headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
@ -42,6 +42,22 @@ def getvesionmethod():
print_exc() print_exc()
return None return None
def getvesionmethod():
try:
res = requests.get(
"https://lunatranslator.xyz/version",
verify=False,
#proxies=getproxy(("github", "versioncheck")),
)
print(res.text)
res=res.json()
# print(res)
_version = res["version"]
return _version, res
except:
print_exc()
return None
def doupdate(): def doupdate():
if not gobject.baseobject.update_avalable: if not gobject.baseobject.update_avalable:
@ -69,7 +85,59 @@ def updatemethod_checkalready(size, savep):
@tryprint @tryprint
def updatemethod(_version, self): def updatemethod(info, self):
check_interrupt = lambda: not (
globalconfig["autoupdate"] and versionchecktask.empty()
)
if platform.architecture()[0] == "64bit":
bit = "64"
elif platform.architecture()[0] == "32bit":
bit = "32"
else:
raise Exception
url = info[bit]
savep = gobject.getcachedir("update/LunaTranslator{}.zip".format(bit))
r2 = requests.get(
url, stream=True, verify=False, proxies=getproxy(("github", "download"))
)
size = int(r2.headers["Content-Length"])
if check_interrupt():
return
if updatemethod_checkalready(size, savep):
return savep
with open(savep, "wb") as file:
sess = requests.session()
r = sess.get(
url, stream=True, verify=False, proxies=getproxy(("github", "download"))
)
file_size = 0
for i in r.iter_content(chunk_size=1024):
if check_interrupt():
return
if not i:
continue
file.write(i)
thislen = len(i)
file_size += thislen
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
)
if check_interrupt():
return
if updatemethod_checkalready(size, savep):
return savep
@tryprint
def updatemethod_github(_version, self):
check_interrupt = lambda: not ( check_interrupt = lambda: not (
globalconfig["autoupdate"] and versionchecktask.empty() globalconfig["autoupdate"] and versionchecktask.empty()
@ -121,7 +189,6 @@ def updatemethod(_version, self):
if updatemethod_checkalready(size, savep): if updatemethod_checkalready(size, savep):
return savep return savep
def uncompress(self, savep): def uncompress(self, savep):
self.progresssignal.emit("正在解压……", 10000) self.progresssignal.emit("正在解压……", 10000)
shutil.rmtree(gobject.getcachedir("update/LunaTranslator/")) shutil.rmtree(gobject.getcachedir("update/LunaTranslator/"))
@ -144,7 +211,7 @@ def versioncheckthread(self):
if _version is None: if _version is None:
sversion = _TR("获取失败") sversion = _TR("获取失败")
else: else:
sversion = _version sversion,info = _version
self.versiontextsignal.emit(sversion) self.versiontextsignal.emit(sversion)
version = winsharedutils.queryversion(sys.argv[0]) version = winsharedutils.queryversion(sys.argv[0])
need = ( need = (
@ -154,7 +221,7 @@ def versioncheckthread(self):
) )
if not (need and globalconfig["autoupdate"]): if not (need and globalconfig["autoupdate"]):
continue continue
savep = updatemethod(_version, self) savep = updatemethod(info, self)
if not savep: if not savep:
self.progresssignal.emit("自动更新失败,请手动更新", 0) self.progresssignal.emit("自动更新失败,请手动更新", 0)
continue continue
@ -317,7 +384,7 @@ def setTab_update(self, basel):
] ]
shuominggrid = [ shuominggrid = [
["Github", makehtml("https://github.com/HIllya51/LunaTranslator")], #["Github", makehtml("https://github.com/HIllya51/LunaTranslator")],
["项目网站", makehtml("https://lunatranslator.xyz/")], ["项目网站", makehtml("https://lunatranslator.xyz/")],
[ [
"使用说明", "使用说明",

View File

@ -56,7 +56,7 @@ def gethookgrid(self):
[ [
( (
makehtml( makehtml(
"https://github.com/HIllya51/LunaHook/issues/new?assignees=&labels=enhancement&projects=&template=01_game_request.yaml", "https://lunatranslator.xyz/",
show=_TR("不支持的游戏?"), show=_TR("不支持的游戏?"),
), ),
0, 0,

View File

@ -29,7 +29,7 @@ include(generate_product_version)
set(VERSION_MAJOR 5) set(VERSION_MAJOR 5)
set(VERSION_MINOR 7) set(VERSION_MINOR 7)
set(VERSION_PATCH 0) set(VERSION_PATCH 1)
add_library(pch pch.cpp) add_library(pch pch.cpp)
target_precompile_headers(pch PUBLIC pch.h) target_precompile_headers(pch PUBLIC pch.h)