diff --git a/.gitignore b/.gitignore index 7b1d5fb5..6014e851 100644 --- a/.gitignore +++ b/.gitignore @@ -39,4 +39,5 @@ LunaTranslator/run37.bat LunaTranslator/run3732.bat LunaTranslator/run38.bat LunaTranslator/run3832.bat +LunaTranslator/logs LunaTranslator/LunaTranslator/.vscode/settings.json diff --git a/LunaTranslator/LunaTranslator/LunaTranslator_main.py b/LunaTranslator/LunaTranslator/LunaTranslator_main.py index cb01d851..c6ab208a 100644 --- a/LunaTranslator/LunaTranslator/LunaTranslator_main.py +++ b/LunaTranslator/LunaTranslator/LunaTranslator_main.py @@ -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()) diff --git a/LunaTranslator/LunaTranslator/myutils/utils.py b/LunaTranslator/LunaTranslator/myutils/utils.py index 9dae2cf2..6e7ccdd3 100644 --- a/LunaTranslator/LunaTranslator/myutils/utils.py +++ b/LunaTranslator/LunaTranslator/myutils/utils.py @@ -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"]: diff --git a/LunaTranslator/LunaTranslator/transoptimi/gptpromptdict.py b/LunaTranslator/LunaTranslator/transoptimi/gptpromptdict.py index 14d24285..99f8b573 100644 --- a/LunaTranslator/LunaTranslator/transoptimi/gptpromptdict.py +++ b/LunaTranslator/LunaTranslator/transoptimi/gptpromptdict.py @@ -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"] ) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 8c5b8e03..16d4336d 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -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) diff --git a/plugins/exec/CMakeLists.txt b/plugins/exec/CMakeLists.txt index 368967d8..3d40598f 100644 --- a/plugins/exec/CMakeLists.txt +++ b/plugins/exec/CMakeLists.txt @@ -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) \ No newline at end of file diff --git a/plugins/exec/PyStand.cpp b/plugins/exec/PyStand.cpp index 8c01bc53..12e6ed15 100644 --- a/plugins/exec/PyStand.cpp +++ b/plugins/exec/PyStand.cpp @@ -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)