This commit is contained in:
恍兮惚兮 2024-08-14 11:44:43 +08:00
parent d76e6f4f00
commit e6fd54e233
10 changed files with 100 additions and 85 deletions

View File

@ -657,13 +657,15 @@ class MAINUI:
if not globalconfig["sourcestatus2"]["texthook"]["use"]:
return
gameuid = find_or_create_uid(savehook_new_list, pexe, title)
if gameuid not in savehook_new_list:
savehook_new_list.insert(0, gameuid)
found = findgameuidofpath(pexe)
if found:
gameuid, reflist = found
else:
if globalconfig["startgamenototop"] == False:
idx = savehook_new_list.index(gameuid)
savehook_new_list.insert(0, savehook_new_list.pop(idx))
gameuid = find_or_create_uid(savehook_new_list, pexe, title)
reflist = savehook_new_list
if globalconfig["startgamenototop"] == False:
idx = reflist.index(gameuid)
reflist.insert(0, reflist.pop(idx))
self.textsource = texthook(pids, hwnd, pexe, gameuid, autostart=False)
self.textsource.start()
@ -881,17 +883,18 @@ class MAINUI:
name_ = getpidexe(pid)
if not name_:
return
uid = findgameuidofpath(name_, savehook_new_list)
if not uid:
found = findgameuidofpath(name_)
if not found:
return
uid, reflist = found
pids = ListProcess(name_)
if self.textsource is not None:
return
if not globalconfig["sourcestatus2"]["texthook"]["use"]:
return
if globalconfig["startgamenototop"] == False:
idx = savehook_new_list.index(uid)
savehook_new_list.insert(0, savehook_new_list.pop(idx))
idx = reflist.index(uid)
reflist.insert(0, reflist.pop(idx))
self.textsource = texthook(pids, hwnd, name_, uid, autostart=True)
self.textsource.start()

View File

@ -251,7 +251,7 @@ class dialog_savedgame_new(QWidget):
menu.addAction(othersetting)
action = menu.exec(self.mapToGlobal(p))
if action == startgame:
startgamecheck(self, self.currentfocusuid)
startgamecheck(self, getreflist(self.reftagid), self.currentfocusuid)
elif action == gamesetting:
self.showsettingdialog()
elif action == addtolist:
@ -396,16 +396,21 @@ class dialog_savedgame_new(QWidget):
self.buttonlayout = buttonlayout
self.savebutton = []
self.simplebutton(
"开始游戏", True, lambda: startgamecheck(self, self.currentfocusuid), True
"开始游戏",
True,
lambda: startgamecheck(
self, getreflist(self.reftagid), self.currentfocusuid
),
True,
)
self.simplebutton("游戏设置", True, self.showsettingdialog, False)
self.simplebutton("删除游戏", True, self.clicked2, False)
self.simplebutton("打开目录", True, self.clicked4, True)
self.simplebutton("添加到列表", True, self.addtolist, False)
if globalconfig["startgamenototop"]:
self.simplebutton("左移", True, functools.partial(self.moverank, -1), False)
self.simplebutton("右移", True, functools.partial(self.moverank, 1), False)
# if globalconfig["startgamenototop"]:
self.simplebutton("左移", True, functools.partial(self.moverank, -1), False)
self.simplebutton("右移", True, functools.partial(self.moverank, 1), False)
self.simplebutton("添加游戏", False, self.clicked3, 1)
self.simplebutton("批量添加", False, self.clicked3_batch, 1)
self.simplebutton("其他设置", False, lambda: dialog_syssetting(self), False)
@ -494,7 +499,9 @@ class dialog_savedgame_new(QWidget):
gameitem = ItemWidget(
k, functools.partial(getpixfunction, k), savehook_new_data[k]["title"]
)
gameitem.doubleclicked.connect(functools.partial(startgamecheck, self))
gameitem.doubleclicked.connect(
functools.partial(startgamecheck, self, getreflist(self.reftagid))
)
gameitem.focuschanged.connect(self.itemfocuschanged)
if focus:
gameitem.click()

View File

@ -434,14 +434,14 @@ def getpixfunction(kk, small=False):
return _pix
def startgamecheck(self, gameuid):
def startgamecheck(self, reflist, gameuid):
if not gameuid:
return
if not os.path.exists(uid2gamepath[gameuid]):
return
if globalconfig["startgamenototop"] == False:
idx = savehook_new_list.index(gameuid)
savehook_new_list.insert(0, savehook_new_list.pop(idx))
idx = reflist.index(gameuid)
reflist.insert(0, reflist.pop(idx))
self.parent().parent().close()
startgame(gameuid)

View File

@ -121,7 +121,9 @@ class dialog_savedgame_legacy(QWidget):
def clicked(self):
startgamecheck(
self, self.model.item(self.table.currentIndex().row(), 2).savetext
self,
savehook_new_list,
self.model.item(self.table.currentIndex().row(), 2).savetext,
)
def delayloadicon(self, k):

View File

@ -284,7 +284,6 @@ class dialog_setting_game_internal(QWidget):
# 添加路径实际上也允许重复,只不过会去重。
res = os.path.normpath(res)
uid2gamepath[self.gameuid] = res
gobject.baseobject.playtimemanager.resetgameinternal(originpath, res)
_icon = getExeIcon(res, cache=True)
self.setWindowIcon(_icon)

View File

@ -733,10 +733,10 @@ class dialog_savedgame_v3(QWidget):
if self.currentfocusuid:
self.viewitem(k)
def delayitemcreater(self, k, select, reftagid):
def delayitemcreater(self, k, select, reftagid, reflist):
item = clickitem(k)
item.doubleclicked.connect(functools.partial(startgamecheck, self))
item.doubleclicked.connect(functools.partial(startgamecheck, self, reflist))
item.focuschanged.connect(functools.partial(self.itemfocuschanged, reftagid))
if select:
item.click()
@ -751,6 +751,7 @@ class dialog_savedgame_v3(QWidget):
res,
True,
self.reftagid,
getreflist(self.reftagid),
),
1 + globalconfig["dialog_savegame_layout"]["listitemheight"],
)
@ -785,7 +786,7 @@ class dialog_savedgame_v3(QWidget):
action = menu.exec(QCursor.pos())
if action == startgame:
startgamecheck(self, self.currentfocusuid)
startgamecheck(self, getreflist(self.reftagid), self.currentfocusuid)
elif addlist == action:
_dia = Prompt_dialog(
self,
@ -863,7 +864,9 @@ class dialog_savedgame_v3(QWidget):
self.righttop = makesubtab_lazy()
self.pixview = pixwrapper()
self.pixview.startgame.connect(
lambda: startgamecheck(self, self.currentfocusuid)
lambda: startgamecheck(
self, getreflist(self.reftagid), self.currentfocusuid
)
)
_w = QWidget()
rightlay = QVBoxLayout()
@ -877,14 +880,19 @@ class dialog_savedgame_v3(QWidget):
rightlay.addLayout(self.buttonlayout)
self.simplebutton(
"开始游戏", True, lambda: startgamecheck(self, self.currentfocusuid), True
"开始游戏",
True,
lambda: startgamecheck(
self, getreflist(self.reftagid), self.currentfocusuid
),
True,
)
self.simplebutton("删除游戏", True, self.shanchuyouxi, False)
self.simplebutton("打开目录", True, self.clicked4, True)
self.simplebutton("添加到列表", True, self.addtolist, False)
if globalconfig["startgamenototop"]:
self.simplebutton("上移", True, functools.partial(self.moverank, -1), False)
self.simplebutton("下移", True, functools.partial(self.moverank, 1), False)
# if globalconfig["startgamenototop"]:
self.simplebutton("上移", True, functools.partial(self.moverank, -1), False)
self.simplebutton("下移", True, functools.partial(self.moverank, 1), False)
self.simplebutton("添加游戏", False, self.clicked3, 1)
self.simplebutton("批量添加", False, self.clicked3_batch, 1)
self.simplebutton(
@ -923,7 +931,7 @@ class dialog_savedgame_v3(QWidget):
vis = False
group0.insertw(
rowreal,
functools.partial(self.delayitemcreater, k, vis, tagid),
functools.partial(self.delayitemcreater, k, vis, tagid, lst),
1 + globalconfig["dialog_savegame_layout"]["listitemheight"],
)
@ -1084,7 +1092,7 @@ class dialog_savedgame_v3(QWidget):
addgamesingle(self, self.addgame, getreflist(self.reftagid))
def clicked(self):
startgamecheck(self, self.currentfocusuid)
startgamecheck(self, getreflist(self.reftagid), self.currentfocusuid)
def simplebutton(self, text, save, callback, exists):
button5 = LPushButton(text)

View File

@ -9,7 +9,6 @@ from myutils.config import (
_TR,
static_data,
findgameuidofpath,
savehook_new_list,
)
from myutils.utils import getlanguse, dynamiclink
from myutils.subproc import endsubprocs
@ -1181,9 +1180,9 @@ class TranslatorWindow(resizableframeless):
gobject.baseobject.textsource.hwnd = hwnd if pid != _pid else None
if not globalconfig["sourcestatus2"]["texthook"]["use"]:
gobject.baseobject.textsource.pids = [pid] if pid != _pid else None
gameuid = findgameuidofpath(getpidexe(pid), savehook_new_list)
gameuid = findgameuidofpath(getpidexe(pid))
if gameuid:
gobject.baseobject.textsource.gameuid = gameuid
gobject.baseobject.textsource.gameuid = gameuid[0]
self.isbindedwindow = pid != _pid
self.refreshtoolicon()

View File

@ -338,32 +338,21 @@ class __uid2gamepath:
uid2gamepath = __uid2gamepath()
def findgameuidofpath(gamepath, targetlist=None, findall=False):
# 一般只在save_game_list里查找用于从getpidexe获取uid
# 因为有可能有过去的不再使用的uid发生碰撞。
# 只在添加游戏时,全面查找。
if not gamepath:
if findall:
return []
else:
return None
# 遍历的速度非常快1w条的速度也就0.001x秒
# 但1w条数据时load/dump的速度就有点慢了能2秒多
checkin = targetlist
if checkin is None:
checkin = savehook_new_data.keys()
def findgameuidofpath(gamepath, findall=False):
collect = []
for uid in checkin:
if savehook_new_data[uid]["gamepath"] == gamepath:
if findall:
collect.append(uid)
else:
return uid
if findall:
return collect
else:
return None
for sub in savegametaged:
if sub is None:
use = savehook_new_list
else:
use = sub["games"]
for uid in use:
if savehook_new_data[uid]["gamepath"] == gamepath:
if findall:
if uid not in collect:
collect.append(uid)
else:
return uid, use
return collect
def syncconfig(config1, default, drop=False, deep=0, skipdict=False):

View File

@ -6,6 +6,7 @@ from traceback import print_exc
from myutils.config import (
uid2gamepath,
findgameuidofpath,
savehook_new_list,
savehook_new_data,
)
from myutils.hwnd import getpidexe
@ -22,47 +23,57 @@ class playtimemanager:
isolation_level=None,
)
try:
self.sqlsavegameinfo.execute(
"CREATE TABLE gameinternalid(gameinternalid INTEGER PRIMARY KEY AUTOINCREMENT,gamepath TEXT);"
)
self.sqlsavegameinfo.execute(
"CREATE TABLE traceplaytime_v4(id INTEGER PRIMARY KEY AUTOINCREMENT,gameinternalid INT,timestart BIGINT,timestop BIGINT);"
)
except:
pass
try:
self.sqlsavegameinfo.execute(
"CREATE TABLE gameinternalid_v2(gameinternalid INTEGER PRIMARY KEY AUTOINCREMENT,gameuid TEXT);"
)
self.trycastoldversion()
except:
pass
threading.Thread(target=self.checkgameplayingthread).start()
def trycastoldversion(self):
for _id, gamepath in self.sqlsavegameinfo.execute(
"SELECT * from gameinternalid"
).fetchall():
gameuid = findgameuidofpath(gamepath)
if not gameuid:
continue
self.sqlsavegameinfo.execute(
"INSERT INTO gameinternalid_v2 VALUES(?,?)", (_id, gameuid[0])
)
self.sqlsavegameinfo.commit()
def querytraceplaytime_v4(self, gameuid):
gameinternalid = self.get_gameinternalid(uid2gamepath[gameuid])
gameinternalid = self.get_gameinternalid(gameuid)
return self.sqlsavegameinfo.execute(
"SELECT timestart,timestop FROM traceplaytime_v4 WHERE gameinternalid = ?",
(gameinternalid,),
).fetchall()
def get_gameinternalid(self, gamepath):
def get_gameinternalid(self, gameuid):
while True:
ret = self.sqlsavegameinfo.execute(
"SELECT gameinternalid FROM gameinternalid WHERE gamepath = ?",
(gamepath,),
"SELECT * FROM gameinternalid_v2 WHERE gameuid = ?",
(gameuid,),
).fetchone()
if ret is None:
self.sqlsavegameinfo.execute(
"INSERT INTO gameinternalid VALUES(NULL,?)", (gamepath,)
"INSERT INTO gameinternalid_v2 VALUES(NULL,?)", (gameuid,)
)
else:
return ret[0]
def resetgameinternal(self, fr, to):
_id = self.get_gameinternalid(fr)
self.sqlsavegameinfo.execute(
"UPDATE gameinternalid SET gamepath = ? WHERE (gameinternalid = ?)",
(to, _id),
)
def traceplaytime(self, gameuid, start, end, new):
def traceplaytime(self, gamepath, start, end, new):
gameinternalid = self.get_gameinternalid(gamepath)
gameinternalid = self.get_gameinternalid(gameuid)
print(gameuid, gameinternalid)
if new:
self.sqlsavegameinfo.execute(
"INSERT INTO traceplaytime_v4 VALUES(NULL,?,?,?)",
@ -88,15 +99,13 @@ class playtimemanager:
if not maybevmpaused:
savehook_new_data[gameuid]["statistic_playtime"] += _t - __t
if (not maybevmpaused) and (self.__currentexe == name_):
self.traceplaytime(
uid2gamepath[gameuid], self.__statistictime - 1, _t, False
)
self.traceplaytime(gameuid, self.__statistictime - 1, _t, False)
else:
self.__statistictime = time.time()
self.__currentexe = name_
self.traceplaytime(
uid2gamepath[gameuid],
gameuid,
self.__statistictime - 1,
self.__statistictime,
True,
@ -115,11 +124,10 @@ class playtimemanager:
name_ = getpidexe(_pid)
if not name_:
return
uids = findgameuidofpath(name_, findall=True)
uid = findgameuidofpath(name_)
try:
if len(uids):
for uid in uids:
isok(uid)
if uid:
isok(uid[0])
else:
self.__currentexe = None
except:

View File

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