This commit is contained in:
恍兮惚兮 2024-11-04 00:53:21 +08:00
parent fbb30251c4
commit 0d56af06d8
9 changed files with 49 additions and 62 deletions

1
.gitignore vendored
View File

@ -33,3 +33,4 @@ src/run37.bat
src/run3732.bat src/run3732.bat
src/plugins/builds src/plugins/builds
src/plugins/libs/webview2 src/plugins/libs/webview2
src/plugins/.vscode/settings.json

View File

@ -363,7 +363,6 @@ class lazyscrollflow(ScrollArea):
QApplication.processEvents() # 会在最大化时死锁 QApplication.processEvents() # 会在最大化时死锁
except: except:
print_exc()
break break
@trypass @trypass
@ -534,7 +533,6 @@ class delayloadvbox(QWidget):
if procevent: if procevent:
QApplication.processEvents() QApplication.processEvents()
except: except:
print_exc()
break break
self.nowvisregion = region self.nowvisregion = region
@ -729,6 +727,7 @@ class stackedlist(ScrollArea):
self.scrolled.connect(lambda _: self.doshowlazywidget(True, _)) self.scrolled.connect(lambda _: self.doshowlazywidget(True, _))
self.saveregion = QRect() self.saveregion = QRect()
@trypass
def doshowlazywidget(self, procevent, region: QRect = None): def doshowlazywidget(self, procevent, region: QRect = None):
if region: if region:
self.saveregion = QRect(region) self.saveregion = QRect(region)

View File

@ -430,6 +430,7 @@ class TranslatorWindow(resizableframeless):
@threader @threader
def autohidedelaythread(self): def autohidedelaythread(self):
while True: while True:
time.sleep(0.5)
# 当鼠标悬停,或前景窗口为当前进程的其他窗口时,禁止自动隐藏 # 当鼠标悬停,或前景窗口为当前进程的其他窗口时,禁止自动隐藏
if self.geometry().contains(QCursor.pos()) or ( if self.geometry().contains(QCursor.pos()) or (
windows.GetForegroundWindow() != self.winid windows.GetForegroundWindow() != self.winid
@ -446,7 +447,6 @@ class TranslatorWindow(resizableframeless):
self.hidesignal.emit() self.hidesignal.emit()
self.autohidestart = False self.autohidestart = False
time.sleep(0.5)
def showhideui(self): def showhideui(self):
if self._move_drag: if self._move_drag:

View File

@ -345,6 +345,14 @@ class __uid2gamepath:
uid2gamepath = __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): def get_launchpath(uid):
launch = savehook_new_data[uid].get("launchpath", "") launch = savehook_new_data[uid].get("launchpath", "")
@ -361,18 +369,17 @@ def findgameuidofpath(gamepath, findall=False):
else: else:
return None, None return None, None
gamepath = os.path.normpath(gamepath) gamepath = os.path.normpath(gamepath)
uids = gamepath2uid_index.get(gamepath, [])
if findall:
return uids
collect = [] collect = []
for sub in savegametaged: for sub in savegametaged:
if sub is None: if sub is None:
use = savehook_new_list use = savehook_new_list
else: else:
use = sub["games"] use = sub["games"]
for uid in use: for uid in uids:
if os.path.abspath(savehook_new_data[uid]["gamepath"]) == gamepath: if uid in use:
if findall:
if uid not in collect:
collect.append(uid)
else:
return uid, use return uid, use
if findall: if findall:
return collect return collect

View File

@ -17,6 +17,7 @@ from myutils.config import (
savehook_new_data, savehook_new_data,
findgameuidofpath, findgameuidofpath,
getdefaultsavehook, getdefaultsavehook,
gamepath2uid_index,
) )
import threading, winreg import threading, winreg
import re, heapq, winsharedutils import re, heapq, winsharedutils
@ -271,9 +272,30 @@ def titlechangedtask(gameuid, title):
trysearchforid(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): def initanewitem(title):
uid = f"{time.time()}_{uuid.uuid4()}" uid = f"{time.time()}_{uuid.uuid4()}"
savehook_new_data[uid] = getdefaultsavehook(title) savehook_new_data[uid] = gamepath2uid_index_helper(getdefaultsavehook(title), uid)
return uid return uid

View File

@ -1,5 +0,0 @@
{
"files.associations": {
"valarray": "cpp"
}
}

View File

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

View File

@ -53,10 +53,7 @@ bool PyStand::CheckEnviron(const wchar_t *rtp)
} }
LocalFree(argvw); LocalFree(argvw);
// init: _cwd (current working directory)
wchar_t path[MAX_PATH + 10]; wchar_t path[MAX_PATH + 10];
GetCurrentDirectoryW(MAX_PATH + 1, path);
_cwd = path;
// init: _pystand (full path of PyStand.exe) // init: _pystand (full path of PyStand.exe)
GetModuleFileNameW(NULL, path, MAX_PATH + 1); 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"); wsprintf(path, L"e:\\github\\tools\\pystand\\pystand.exe");
#endif #endif
_pystand = path; _pystand = path;
_home = std::filesystem::path(path).parent_path().wstring();
// init: _home SetCurrentDirectoryW(_home.c_str());
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());
// init: _runtime (embedded python directory) _runtime = (std::filesystem::path(_home) / rtp).wstring();
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;
// check home // check home
std::wstring check = _runtime; if (!PathFileExistsW(_runtime.c_str()))
if (!PathFileExistsW(check.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); MessageBoxW(NULL, msg.c_str(), L"ERROR", MB_OK);
return false; return false;
} }
// check python3.dll // check python3.dll
std::wstring check2 = _runtime + L"\\python3.dll"; if (!PathFileExistsW((_runtime + L"\\python3.dll").c_str()))
if (!PathFileExistsW(check2.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); MessageBoxW(NULL, msg.c_str(), L"ERROR", MB_OK);
return false; return false;
} }

View File

@ -33,7 +33,6 @@ protected:
protected: protected:
HINSTANCE _hDLL; HINSTANCE _hDLL;
std::wstring _cwd; // current working directory
std::wstring _args; // arguments std::wstring _args; // arguments
std::wstring _pystand; // absolute path of pystand std::wstring _pystand; // absolute path of pystand
std::wstring _runtime; // absolute path of embedded python runtime std::wstring _runtime; // absolute path of embedded python runtime