mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2025-01-14 08:23:55 +08:00
dynamic
This commit is contained in:
parent
23127952f5
commit
f474325d54
@ -67,3 +67,6 @@ def testuseqwebengine():
|
||||
return os.path.exists(
|
||||
"./LunaTranslator/runtime/PyQt5/Qt5/bin/Qt5WebEngineCore.dll"
|
||||
) or (len(sys.argv) and sys.argv[-1] == "test")
|
||||
|
||||
|
||||
serverindex = 0
|
||||
|
@ -431,7 +431,13 @@ class browserdialog(saveposwindow):
|
||||
for link in savehook_new_data[self.gameuid]["relationlinks"]:
|
||||
items.append((link[0], tagitem.TYPE_GAME_LIKE, link[1]))
|
||||
if len(items) == 0:
|
||||
items.append(("Luna", tagitem.TYPE_GLOABL_LIKE, static_data["main_server"]))
|
||||
items.append(
|
||||
(
|
||||
"Luna",
|
||||
tagitem.TYPE_GLOABL_LIKE,
|
||||
static_data["main_server"][gobject.serverindex],
|
||||
)
|
||||
)
|
||||
self.tagswidget.clearTag(False)
|
||||
self.tagswidget.addTags(items)
|
||||
|
||||
|
@ -3,7 +3,7 @@ import platform, functools, sys
|
||||
import winsharedutils, queue
|
||||
from myutils.config import globalconfig, static_data, _TR
|
||||
from myutils.wrapper import threader, tryprint
|
||||
from myutils.utils import makehtml, dynamiclink, getlanguse
|
||||
from myutils.utils import makehtml, getlanguse, dynamiclink
|
||||
import requests
|
||||
import shutil, gobject
|
||||
from myutils.proxy import getproxy
|
||||
@ -16,21 +16,51 @@ from gui.dynalang import LLabel
|
||||
versionchecktask = queue.Queue()
|
||||
|
||||
|
||||
def getvesionmethod():
|
||||
def tryqueryfromhost():
|
||||
|
||||
for i, main_server in enumerate(static_data["main_server"]):
|
||||
try:
|
||||
res = requests.get(
|
||||
"{main_server}/version".format(main_server=main_server),
|
||||
verify=False,
|
||||
proxies=getproxy(("github", "versioncheck")),
|
||||
)
|
||||
res = res.json()
|
||||
gobject.serverindex = i
|
||||
_version = res["version"]
|
||||
|
||||
return _version, res
|
||||
except:
|
||||
print_exc()
|
||||
|
||||
|
||||
def tryqueryfromgithub():
|
||||
|
||||
res = requests.get(
|
||||
"https://api.github.com/repos/HIllya51/LunaTranslator/releases/latest",
|
||||
verify=False,
|
||||
proxies=getproxy(("github", "versioncheck")),
|
||||
)
|
||||
link = {
|
||||
"64": "https://github.com/HIllya51/LunaTranslator/releases/latest/download/LunaTranslator.zip",
|
||||
"32": "https://github.com/HIllya51/LunaTranslator/releases/latest/download/LunaTranslator_x86.zip",
|
||||
}
|
||||
return res.json()["tag_name"], link
|
||||
|
||||
|
||||
def trygetupdate():
|
||||
if platform.architecture()[0] == "64bit":
|
||||
bit = "64"
|
||||
elif platform.architecture()[0] == "32bit":
|
||||
bit = "32"
|
||||
try:
|
||||
res = requests.get(
|
||||
dynamiclink("{main_server}/version"),
|
||||
verify=False,
|
||||
proxies=getproxy(("github", "versioncheck")),
|
||||
)
|
||||
print(res.text)
|
||||
res = res.json()
|
||||
# print(res)
|
||||
_version = res["version"]
|
||||
return _version, res
|
||||
version, links = tryqueryfromhost()
|
||||
except:
|
||||
print_exc()
|
||||
return None
|
||||
try:
|
||||
version, links = tryqueryfromgithub()
|
||||
except:
|
||||
return None
|
||||
return version, links[bit]
|
||||
|
||||
|
||||
def doupdate():
|
||||
@ -46,7 +76,10 @@ def doupdate():
|
||||
rf".\files\plugins\shareddllproxy{_6432}.exe",
|
||||
gobject.getcachedir("Updater.exe"),
|
||||
)
|
||||
subprocess.Popen(rf".\cache\Updater.exe update .\cache\update\LunaTranslator{bit}")
|
||||
subprocess.Popen(
|
||||
rf".\cache\Updater.exe update .\cache\update\LunaTranslator{bit} "
|
||||
+ dynamiclink("{main_server}")
|
||||
)
|
||||
|
||||
|
||||
def updatemethod_checkalready(size, savep):
|
||||
@ -59,20 +92,13 @@ def updatemethod_checkalready(size, savep):
|
||||
|
||||
|
||||
@tryprint
|
||||
def updatemethod(info, self):
|
||||
def updatemethod(url, 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))
|
||||
savep = gobject.getcachedir("update/" + url.split("/")[-1])
|
||||
|
||||
r2 = requests.head(url, verify=False, proxies=getproxy(("github", "download")))
|
||||
size = int(r2.headers["Content-Length"])
|
||||
@ -125,7 +151,7 @@ def versioncheckthread(self):
|
||||
if not x:
|
||||
continue
|
||||
self.versiontextsignal.emit("获取中") # ,'',url,url))
|
||||
_version = getvesionmethod()
|
||||
_version = trygetupdate()
|
||||
|
||||
if _version is None:
|
||||
sversion = "获取失败"
|
||||
|
@ -466,7 +466,8 @@ def minmaxmoveobservefunc(self):
|
||||
|
||||
def dynamiclink(text):
|
||||
return text.format(
|
||||
main_server=static_data["main_server"], docs_server=static_data["docs_server"]
|
||||
main_server=static_data["main_server"][gobject.serverindex],
|
||||
docs_server=static_data["docs_server"][gobject.serverindex],
|
||||
)
|
||||
|
||||
|
||||
|
@ -1911,6 +1911,12 @@
|
||||
"Windows MCI",
|
||||
"miniaudio"
|
||||
],
|
||||
"main_server": "https://lunatranslator.xyz",
|
||||
"docs_server": "https://docs.lunatranslator.xyz"
|
||||
"main_server": [
|
||||
"https://lunatranslator.xyz",
|
||||
"http://38.46.30.10:5000"
|
||||
],
|
||||
"docs_server": [
|
||||
"https://docs.lunatranslator.xyz",
|
||||
"http://38.46.30.10:8000"
|
||||
]
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
|
||||
> **一款galgame翻译器**
|
||||
|
||||
### [使用说明](https://docs.lunatranslator.xyz/#/zh/) [视频教程](https://space.bilibili.com/592120404/video) [QQ群](https://lunatranslator.xyz/Resource/QQGroup) [Discord](https://discord.com/invite/ErtDwVeAbB)
|
||||
### [使用说明](https://docs.lunatranslator.xyz/#/zh/) [视频教程](https://space.bilibili.com/592120404/video) [QQ群](https://qm.qq.com/q/I5rr3uEpi2) [Discord](https://discord.com/invite/ErtDwVeAbB)
|
||||
|
||||
## 功能支持
|
||||
|
||||
|
81
build.py
81
build.py
@ -3,6 +3,47 @@ import shutil, json
|
||||
import subprocess, time
|
||||
import urllib.request
|
||||
|
||||
# 继github被封后,域名又被封了。真是走了狗屎运了。这个世界上到底还有什么是能信任的。
|
||||
# 暂时先这样吧。在软件内使用重定向链接,因为链接失效没办法及时更新;在github网站或文档内,用直链。
|
||||
hostserver = "https://lunatranslator.xyz/"
|
||||
try:
|
||||
urllib.request.urlopen(hostserver)
|
||||
usehost = True
|
||||
except:
|
||||
usehost = False
|
||||
links302 = {
|
||||
"Github": {
|
||||
"LunaTranslator": "HIllya51/LunaTranslator",
|
||||
"LunaHook": "HIllya51/LunaHook",
|
||||
},
|
||||
"Resource": {
|
||||
"ocr_models": {
|
||||
"ja.zip": "https://github.com/test123456654321/RESOURCES/releases/download/ocr_models/ja.zip",
|
||||
},
|
||||
"build_req": {
|
||||
"mecab.zip": "https://github.com/HIllya51/RESOURCES/releases/download/common/mecab.zip",
|
||||
"ocr.zip": "https://github.com/HIllya51/RESOURCES/releases/download/common/ocr.zip",
|
||||
"magpie.zip": "https://github.com/HIllya51/RESOURCES/releases/download/common/magpie.zip",
|
||||
"stylesheets-main.zip": "https://github.com/HIllya51/RESOURCES/releases/download/common/stylesheets-main.zip",
|
||||
"zstd.zip": "https://github.com/HIllya51/RESOURCES/releases/download/common/zstd.zip",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def dynalink(path: str):
|
||||
if usehost:
|
||||
return hostserver + path
|
||||
pathx = path.split("/")
|
||||
if pathx[0] == "Github":
|
||||
return (
|
||||
"https://github.com/"
|
||||
+ links302.get(pathx[0]).get(pathx[1])
|
||||
+ "/"
|
||||
+ "/".join(pathx[2:])
|
||||
)
|
||||
return links302.get(pathx[0]).get(pathx[1]).get(pathx[2])
|
||||
|
||||
|
||||
pluginDirs = ["DLL32", "DLL64", "Locale_Remulator", "LunaHook", "Magpie", "NTLEAS"]
|
||||
|
||||
@ -22,12 +63,12 @@ curlFile64 = "https://curl.se/windows/dl-8.8.0_3/curl-8.8.0_3-win64-mingw.zip"
|
||||
curlFileName64 = "curl-8.8.0_3-win64-mingw.zip"
|
||||
|
||||
|
||||
ocrModelUrl = (
|
||||
"https://lunatranslator.xyz/Resource/ocr_models"
|
||||
)
|
||||
ocrModelUrl = dynalink("Resource/ocr_models/ja.zip")
|
||||
availableLocales = ["cht", "en", "ja", "ko", "ru", "zh"]
|
||||
|
||||
LunaHook_latest = "https://lunatranslator.xyz/Github/LunaHook/releases/latest/download/Release_English.zip"
|
||||
LunaHook_latest = dynalink(
|
||||
"Github/LunaHook/releases/latest/download/Release_English.zip"
|
||||
)
|
||||
|
||||
LocaleRe = "https://github.com/InWILL/Locale_Remulator/releases/download/v1.5.3-beta.1/Locale_Remulator.1.5.3-beta.1.zip"
|
||||
|
||||
@ -112,17 +153,11 @@ def move_directory_contents(source_dir, destination_dir):
|
||||
def downloadcommon():
|
||||
os.chdir(rootDir + "\\temp")
|
||||
downloadlr()
|
||||
subprocess.run(
|
||||
f"curl -LO https://lunatranslator.xyz/Resource/build_req/mecab.zip"
|
||||
)
|
||||
subprocess.run(f"curl -LO {dynalink('Resource/build_req/mecab.zip')}")
|
||||
subprocess.run(f"7z x mecab.zip -oALL")
|
||||
subprocess.run(
|
||||
f"curl -LO https://lunatranslator.xyz/Resource/build_req/ocr.zip"
|
||||
)
|
||||
subprocess.run(f"curl -LO {dynalink('Resource/build_req/ocr.zip')}")
|
||||
subprocess.run(f"7z x ocr.zip -oALL")
|
||||
subprocess.run(
|
||||
f"curl -LO https://lunatranslator.xyz/Resource/build_req/magpie.zip"
|
||||
)
|
||||
subprocess.run(f"curl -LO {dynalink('Resource/build_req/magpie.zip')}")
|
||||
subprocess.run(f"7z x magpie.zip -oALL")
|
||||
|
||||
move_directory_contents("ALL/ALL", f"{rootDir}/LunaTranslator/files/plugins")
|
||||
@ -174,16 +209,14 @@ def downloadCurl():
|
||||
)
|
||||
|
||||
|
||||
def downloadOCRModel(locale):
|
||||
if locale not in availableLocales:
|
||||
return
|
||||
def downloadOCRModel():
|
||||
os.chdir(rootDir + "\\LunaTranslator\\files")
|
||||
if not os.path.exists("ocr"):
|
||||
os.mkdir("ocr")
|
||||
os.chdir("ocr")
|
||||
subprocess.run(f"curl -LO {ocrModelUrl}/{locale}.zip")
|
||||
subprocess.run(f"7z x {locale}.zip")
|
||||
os.remove(f"{locale}.zip")
|
||||
subprocess.run(f"curl -LO {ocrModelUrl}")
|
||||
subprocess.run(f"7z x ja.zip")
|
||||
os.remove(f"ja.zip")
|
||||
|
||||
|
||||
def get_url_as_json(url):
|
||||
@ -241,11 +274,11 @@ def buildPlugins():
|
||||
|
||||
def downloadsomething():
|
||||
os.chdir(rootDir + "\\temp")
|
||||
subprocess.run(
|
||||
f"curl -LO https://lunatranslator.xyz/Resource/build_req/stylesheets-main.zip"
|
||||
)
|
||||
subprocess.run(f"curl -LO {dynalink('Resource/build_req/stylesheets-main.zip')}")
|
||||
subprocess.run(f"7z x stylesheets-main.zip -oALL")
|
||||
move_directory_contents("ALL/stylesheets-main", rootDir + "\\LunaTranslator\\files\\themes")
|
||||
move_directory_contents(
|
||||
"ALL/stylesheets-main", rootDir + "\\LunaTranslator\\files\\themes"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@ -270,7 +303,7 @@ if __name__ == "__main__":
|
||||
downloadLocaleEmulator()
|
||||
downloadNtlea()
|
||||
downloadCurl()
|
||||
downloadOCRModel("ja")
|
||||
downloadOCRModel()
|
||||
downloadcommon()
|
||||
buildLunaHook()
|
||||
|
||||
|
@ -31,7 +31,7 @@ int updatewmain(int argc, wchar_t *argv[])
|
||||
catch (std::exception &e)
|
||||
{
|
||||
MessageBoxA(GetForegroundWindow(), (std::string("Update failed!\r\n") + e.what()).c_str(), "Error", 0);
|
||||
ShellExecute(0, L"open", L"https://lunatranslator.xyz/Github/LunaTranslator/releases", NULL, NULL, SW_SHOWNORMAL);
|
||||
ShellExecute(0, L"open", (std::wstring(argv[2]) + L"/Github/LunaTranslator/releases").c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||||
return 0;
|
||||
}
|
||||
try
|
||||
|
Loading…
x
Reference in New Issue
Block a user