This commit is contained in:
恍兮惚兮 2024-08-07 14:14:04 +08:00
parent f474325d54
commit aaa0c82380
7 changed files with 57 additions and 10 deletions

1
.gitignore vendored
View File

@ -39,4 +39,5 @@ LunaTranslator/run37.bat
LunaTranslator/run3732.bat
LunaTranslator/run38.bat
LunaTranslator/run3832.bat
LunaTranslator/logs
LunaTranslator/LunaTranslator/.vscode/settings.json

View File

@ -1,4 +1,4 @@
import sys, os
import sys, os, io, time
def prepareqtenv():
@ -142,6 +142,7 @@ def checkpermission():
try:
os.makedirs("userconfig", exist_ok=True)
os.makedirs("logs", exist_ok=True)
except PermissionError:
msg = QMessageBox()
msg.setText(_TR("权限不足,请以管理员权限运行!"))
@ -167,6 +168,38 @@ def switchdir():
pass
class debugoutput(io.IOBase):
file = None
def __init__(self, file=sys.stdout) -> None:
super().__init__()
self.originfile = file
def write(self, data):
if self.originfile:
self.originfile.write(data)
try:
if self.file is None:
self.file = open(
f"logs/{time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime())}.txt",
"w",
errors="ignore",
)
self.file.write(data)
self.file.flush()
except:
pass
def flush(self):
if self.originfile:
self.originfile.flush()
def savelogs():
sys.stderr = debugoutput(sys.stderr)
sys.stdout = debugoutput(sys.stdout)
if __name__ == "__main__":
switchdir()
prepareqtenv()
@ -177,5 +210,6 @@ if __name__ == "__main__":
checklang()
checkintegrity()
checkpermission()
savelogs()
loadmainui()
app.exit(app.exec())

View File

@ -493,8 +493,7 @@ class autosql(sqlite3.Connection):
self.close()
@tryprint
def parsemayberegexreplace(lst: list, line: str):
def parsemayberegexreplace_(lst: list, line: str):
for fil in lst:
regex = fil.get("regex", False)
escape = fil.get("escape", regex)
@ -524,6 +523,13 @@ def parsemayberegexreplace(lst: list, line: str):
return line
def parsemayberegexreplace(lst: list, line: str):
try:
return parsemayberegexreplace_(lst, line)
except:
return line
def checkpostlangmatch(name):
for item in static_data["transoptimi"]:
if name == item["name"]:

View File

@ -50,10 +50,10 @@ class Process:
return globalconfig["gptpromptdict"]
elif which == 2:
gameuid = gobject.baseobject.textsource.gameuid
return savehook_new_data[gameuid]["gptpromptdict_use"]
return savehook_new_data[gameuid]["gptpromptdict"]
elif which == 3:
gameuid = gobject.baseobject.textsource.gameuid
return (
savehook_new_data[gameuid]["gptpromptdict_use"]
savehook_new_data[gameuid]["gptpromptdict"]
+ globalconfig["gptpromptdict"]
)

View File

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

View File

@ -15,11 +15,11 @@ generate_product_version(
set(sources PyStand.cpp luna.rc ${versioninfo})
add_executable(LunaTranslator_debug ${sources})
target_compile_definitions(LunaTranslator_debug PRIVATE PYSTAND_CONSOLE)
#add_executable(LunaTranslator_debug ${sources})
#target_compile_definitions(LunaTranslator_debug PRIVATE PYSTAND_CONSOLE)
add_executable(LunaTranslator WIN32 ${sources})
add_executable(LunaTranslator_admin WIN32 ${sources})
set_target_properties(LunaTranslator_admin PROPERTIES LINK_FLAGS " /MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\" ")
target_precompile_headers(LunaTranslator_debug REUSE_FROM pch)
#target_precompile_headers(LunaTranslator_debug REUSE_FROM pch)
target_precompile_headers(LunaTranslator_admin REUSE_FROM pch)
target_precompile_headers(LunaTranslator REUSE_FROM pch)

View File

@ -1,4 +1,4 @@

#include "PyStand.h"
//---------------------------------------------------------------------
@ -317,6 +317,12 @@ int WINAPI
WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int show)
#endif
{
{
// 当更新进行时,禁止启动
AutoHandle hMutex = CreateMutex(NULL, FALSE, L"LUNA_UPDATER_SINGLE");
if (GetLastError() == ERROR_ALREADY_EXISTS)
return 0;
}
auto __handle = AutoHandle(CreateMutexA(&allAccess, FALSE, "LUNA_UPDATER_BLOCK"));
PyStand ps(L"LunaTranslator\\runtime");
if (ps.DetectScript() != 0)