diff --git a/.gitignore b/.gitignore index 8ceaf369..11200999 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,5 @@ src/files/themes src/run37.bat src/run3732.bat src/plugins/builds -src/plugins/libs/webview2 \ No newline at end of file +src/plugins/libs/webview2 +src/plugins/.vscode/settings.json diff --git a/src/LunaTranslator/gui/specialwidget.py b/src/LunaTranslator/gui/specialwidget.py index 68df1981..805aa114 100644 --- a/src/LunaTranslator/gui/specialwidget.py +++ b/src/LunaTranslator/gui/specialwidget.py @@ -363,7 +363,6 @@ class lazyscrollflow(ScrollArea): QApplication.processEvents() # 会在最大化时死锁 except: - print_exc() break @trypass @@ -534,7 +533,6 @@ class delayloadvbox(QWidget): if procevent: QApplication.processEvents() except: - print_exc() break self.nowvisregion = region @@ -729,6 +727,7 @@ class stackedlist(ScrollArea): self.scrolled.connect(lambda _: self.doshowlazywidget(True, _)) self.saveregion = QRect() + @trypass def doshowlazywidget(self, procevent, region: QRect = None): if region: self.saveregion = QRect(region) diff --git a/src/LunaTranslator/gui/translatorUI.py b/src/LunaTranslator/gui/translatorUI.py index 649d2ca9..b77a103f 100644 --- a/src/LunaTranslator/gui/translatorUI.py +++ b/src/LunaTranslator/gui/translatorUI.py @@ -430,6 +430,7 @@ class TranslatorWindow(resizableframeless): @threader def autohidedelaythread(self): while True: + time.sleep(0.5) # 当鼠标悬停,或前景窗口为当前进程的其他窗口时,禁止自动隐藏 if self.geometry().contains(QCursor.pos()) or ( windows.GetForegroundWindow() != self.winid @@ -446,7 +447,6 @@ class TranslatorWindow(resizableframeless): self.hidesignal.emit() self.autohidestart = False - time.sleep(0.5) def showhideui(self): if self._move_drag: diff --git a/src/LunaTranslator/myutils/config.py b/src/LunaTranslator/myutils/config.py index cbd3d3b9..32ee96c3 100644 --- a/src/LunaTranslator/myutils/config.py +++ b/src/LunaTranslator/myutils/config.py @@ -345,6 +345,14 @@ class __uid2gamepath: uid2gamepath = __uid2gamepath() +# 建立索引,当游戏特别多的时候,节省时间 +gamepath2uid_index = {} +for uid in savehook_new_data: + _p = os.path.abspath(savehook_new_data[uid]["gamepath"]) + if _p not in gamepath2uid_index: + gamepath2uid_index[_p] = [] + gamepath2uid_index[_p].append(uid) + def get_launchpath(uid): launch = savehook_new_data[uid].get("launchpath", "") @@ -361,19 +369,18 @@ def findgameuidofpath(gamepath, findall=False): else: return None, None gamepath = os.path.normpath(gamepath) + uids = gamepath2uid_index.get(gamepath, []) + if findall: + return uids collect = [] for sub in savegametaged: if sub is None: use = savehook_new_list else: use = sub["games"] - for uid in use: - if os.path.abspath(savehook_new_data[uid]["gamepath"]) == gamepath: - if findall: - if uid not in collect: - collect.append(uid) - else: - return uid, use + for uid in uids: + if uid in use: + return uid, use if findall: return collect else: diff --git a/src/LunaTranslator/myutils/utils.py b/src/LunaTranslator/myutils/utils.py index c4237a88..6d04897b 100644 --- a/src/LunaTranslator/myutils/utils.py +++ b/src/LunaTranslator/myutils/utils.py @@ -17,6 +17,7 @@ from myutils.config import ( savehook_new_data, findgameuidofpath, getdefaultsavehook, + gamepath2uid_index, ) import threading, winreg import re, heapq, winsharedutils @@ -271,9 +272,30 @@ def titlechangedtask(gameuid, title): trysearchforid(gameuid, [title]) +class gamepath2uid_index_helper(dict): + def __init__(self, d, uid): + super.__init__(d) + self.uid = uid + + def __setitem__(self, key, value): + + if key == "gamepath": + origin = os.path.abspath(self.get(key)) + if origin in gamepath2uid_index and self.uid in gamepath2uid_index[origin]: + try: + gamepath2uid_index[origin].remove(self.uid) + except: + pass + absv = os.path.abspath(value) + if absv not in gamepath2uid_index: + gamepath2uid_index[absv] = [] + gamepath2uid_index[absv].append(self.uid) + super.__setitem__(key, value) + + def initanewitem(title): uid = f"{time.time()}_{uuid.uuid4()}" - savehook_new_data[uid] = getdefaultsavehook(title) + savehook_new_data[uid] = gamepath2uid_index_helper(getdefaultsavehook(title), uid) return uid diff --git a/src/plugins/.vscode/settings.json b/src/plugins/.vscode/settings.json deleted file mode 100644 index b5be4e5e..00000000 --- a/src/plugins/.vscode/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "files.associations": { - "valarray": "cpp" - } -} \ No newline at end of file diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 83952465..81ca1147 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -29,7 +29,7 @@ include(generate_product_version) set(VERSION_MAJOR 5) set(VERSION_MINOR 55) -set(VERSION_PATCH 0) +set(VERSION_PATCH 1) add_library(pch pch.cpp) target_precompile_headers(pch PUBLIC pch.h) diff --git a/src/plugins/exec/PyStand.cpp b/src/plugins/exec/PyStand.cpp index c9ffa19b..79f7d979 100644 --- a/src/plugins/exec/PyStand.cpp +++ b/src/plugins/exec/PyStand.cpp @@ -53,10 +53,7 @@ bool PyStand::CheckEnviron(const wchar_t *rtp) } LocalFree(argvw); - // init: _cwd (current working directory) wchar_t path[MAX_PATH + 10]; - GetCurrentDirectoryW(MAX_PATH + 1, path); - _cwd = path; // init: _pystand (full path of PyStand.exe) GetModuleFileNameW(NULL, path, MAX_PATH + 1); @@ -64,57 +61,24 @@ bool PyStand::CheckEnviron(const wchar_t *rtp) wsprintf(path, L"e:\\github\\tools\\pystand\\pystand.exe"); #endif _pystand = path; + _home = std::filesystem::path(path).parent_path().wstring(); - // init: _home - int size = (int)wcslen(path); - for (; size > 0; size--) - { - if (path[size - 1] == L'/') - break; - if (path[size - 1] == L'\\') - break; - } - path[size] = 0; - SetCurrentDirectoryW(path); - GetCurrentDirectoryW(MAX_PATH + 1, path); - _home = path; - SetCurrentDirectoryW(_cwd.c_str()); + SetCurrentDirectoryW(_home.c_str()); - // init: _runtime (embedded python directory) - bool abspath = false; - if (wcslen(rtp) >= 3) - { - if (rtp[1] == L':') - { - if (rtp[2] == L'/' || rtp[2] == L'\\') - abspath = true; - } - } - if (abspath == false) - { - _runtime = _home + L"\\" + rtp; - } - else - { - _runtime = rtp; - } - GetFullPathNameW(_runtime.c_str(), MAX_PATH + 1, path, NULL); - _runtime = path; + _runtime = (std::filesystem::path(_home) / rtp).wstring(); // check home - std::wstring check = _runtime; - if (!PathFileExistsW(check.c_str())) + if (!PathFileExistsW(_runtime.c_str())) { - std::wstring msg = L"Missing embedded Python3 in:\n" + check; + std::wstring msg = L"Missing embedded Python3 in:\n" + _runtime; MessageBoxW(NULL, msg.c_str(), L"ERROR", MB_OK); return false; } // check python3.dll - std::wstring check2 = _runtime + L"\\python3.dll"; - if (!PathFileExistsW(check2.c_str())) + if (!PathFileExistsW((_runtime + L"\\python3.dll").c_str())) { - std::wstring msg = L"Missing python3.dll in:\r\n" + check; + std::wstring msg = L"Missing python3.dll in:\r\n" + _runtime; MessageBoxW(NULL, msg.c_str(), L"ERROR", MB_OK); return false; } diff --git a/src/plugins/exec/PyStand.h b/src/plugins/exec/PyStand.h index 738a1c52..2108d079 100644 --- a/src/plugins/exec/PyStand.h +++ b/src/plugins/exec/PyStand.h @@ -33,7 +33,6 @@ protected: protected: HINSTANCE _hDLL; - std::wstring _cwd; // current working directory std::wstring _args; // arguments std::wstring _pystand; // absolute path of pystand std::wstring _runtime; // absolute path of embedded python runtime