mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-27 15:44:12 +08:00
update
This commit is contained in:
parent
b89065f9c4
commit
e77487af08
@ -2,6 +2,7 @@ import sys, windows
|
||||
import platform, os
|
||||
|
||||
if __name__ == "__main__":
|
||||
_lock = windows.AutoHandle(windows.CreateMutex(False, "LUNA_UPDATER_BLOCK"))
|
||||
dirname = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
os.chdir(dirname)
|
||||
windows.addenvpath("./LunaTranslator/runtime/") # win7 no vcredist2015
|
||||
|
@ -5,12 +5,10 @@ from myutils.proxy import getproxy
|
||||
from traceback import print_exc
|
||||
import zipfile, os
|
||||
from myutils.config import globalconfig
|
||||
import windows
|
||||
import subprocess
|
||||
|
||||
|
||||
def getvesionmethod():
|
||||
url = "https://github.com/HIllya51/LunaTranslator/releases/"
|
||||
|
||||
try:
|
||||
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",
|
||||
@ -36,34 +34,13 @@ def getvesionmethod():
|
||||
def update():
|
||||
if platform.architecture()[0] == "64bit":
|
||||
bit = ""
|
||||
_6432 = "64"
|
||||
elif platform.architecture()[0] == "32bit":
|
||||
bit = "_x86"
|
||||
with open("./cache/update/update.bat", "w", encoding="utf8") as ff:
|
||||
|
||||
ff.write(
|
||||
r"""
|
||||
@echo off
|
||||
:waitloop
|
||||
tasklist | find "LunaTranslator_main.exe" > nul
|
||||
if %errorlevel%==0 (
|
||||
timeout /t 1 > nul
|
||||
goto waitloop
|
||||
)
|
||||
timeout 1
|
||||
xcopy .\cache\update\LunaTranslator"""
|
||||
+ bit
|
||||
+ r""" .\ /s /e /c /y /h /r
|
||||
exit
|
||||
"""
|
||||
)
|
||||
windows.ShellExecute(
|
||||
None,
|
||||
"open",
|
||||
"cache\\update\\update.bat",
|
||||
"",
|
||||
os.path.dirname("."),
|
||||
windows.SW_HIDE,
|
||||
)
|
||||
_6432 = "32"
|
||||
os.makedirs("./cache", exist_ok=True)
|
||||
shutil.copy(rf".\files\plugins\shareddllproxy{_6432}.exe", rf".\cache\Updater.exe")
|
||||
subprocess.Popen(rf".\cache\Updater.exe update .\cache\update\LunaTranslator{bit}")
|
||||
|
||||
|
||||
def updatemethod(_version, progresscallback):
|
||||
|
@ -12,7 +12,7 @@ generate_product_version(
|
||||
)
|
||||
|
||||
|
||||
add_executable(shareddllproxy shareddllproxy.cpp dllinject.cpp ntleas.cpp aspatch.cpp ${versioninfo})
|
||||
add_executable(shareddllproxy shareddllproxy.cpp dllinject.cpp ntleas.cpp aspatch.cpp update.cpp ${versioninfo})
|
||||
target_precompile_headers(shareddllproxy REUSE_FROM pch)
|
||||
if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
int dllinjectwmain(int argc, wchar_t *argv[]);
|
||||
int ntleaswmain(int argc, wchar_t *wargv[]);
|
||||
int updatewmain(int argc, wchar_t *wargv[]);
|
||||
bool checkisapatch();
|
||||
#ifndef _WIN64
|
||||
int LRwmain(int argc, wchar_t *argv[]);
|
||||
@ -61,6 +62,8 @@ int wmain(int argc, wchar_t *argv[])
|
||||
return ntleaswmain(argc - 1, argv + 1);
|
||||
if (argv0 == L"listpm")
|
||||
return listprocessmodule(argc - 1, argv + 1);
|
||||
if (argv0 == L"update")
|
||||
return updatewmain(argc - 1, argv + 1);
|
||||
|
||||
#ifndef _WIN64
|
||||
else if (argv0 == L"LR")
|
||||
|
36
plugins/shareddllproxy/update.cpp
Normal file
36
plugins/shareddllproxy/update.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#pragma comment(linker, "/subsystem:windows /entry:wmainCRTStartup")
|
||||
|
||||
int updatewmain(int argc, wchar_t *argv[])
|
||||
{
|
||||
if (argc <= 1)
|
||||
return 0;
|
||||
AutoHandle hMutex = CreateMutex(NULL, FALSE, L"LUNA_UPDATER_SINGLE");
|
||||
|
||||
if (GetLastError() == ERROR_ALREADY_EXISTS)
|
||||
return 0;
|
||||
while (true)
|
||||
{
|
||||
AutoHandle semaphore = CreateMutex(NULL, FALSE, L"LUNA_UPDATER_BLOCK");
|
||||
if (GetLastError() != ERROR_ALREADY_EXISTS)
|
||||
break;
|
||||
Sleep(1000);
|
||||
}
|
||||
WCHAR path[MAX_PATH];
|
||||
GetModuleFileNameW(GetModuleHandle(0), path, MAX_PATH);
|
||||
|
||||
*(wcsrchr(path, '\\')) = 0;
|
||||
*(wcsrchr(path, '\\')) = 0;
|
||||
|
||||
SetCurrentDirectory(path);
|
||||
try
|
||||
{
|
||||
std::filesystem::copy(argv[1], L".\\", std::filesystem::copy_options::recursive | std::filesystem::copy_options::overwrite_existing);
|
||||
MessageBoxW(0, L"Update success", L"Success", 0);
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
MessageBoxW(0, (StringToWideString(e.what()) + L"\r\nUpdate failed, maybe you should download again to fix errors").c_str(), L"Error", 0);
|
||||
ShellExecute(0, L"open", L"https://github.com/HIllya51/LunaTranslator/releases", NULL, NULL, SW_SHOWNORMAL);
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user