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

View File

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

View File

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

View File

@ -121,7 +121,9 @@ class dialog_savedgame_legacy(QWidget):
def clicked(self): def clicked(self):
startgamecheck( 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): def delayloadicon(self, k):

View File

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

View File

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

View File

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

View File

@ -338,32 +338,21 @@ class __uid2gamepath:
uid2gamepath = __uid2gamepath() uid2gamepath = __uid2gamepath()
def findgameuidofpath(gamepath, targetlist=None, findall=False): def findgameuidofpath(gamepath, 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()
collect = [] collect = []
for uid in checkin: for sub in savegametaged:
if savehook_new_data[uid]["gamepath"] == gamepath: if sub is None:
if findall: use = savehook_new_list
collect.append(uid) else:
else: use = sub["games"]
return uid for uid in use:
if findall: if savehook_new_data[uid]["gamepath"] == gamepath:
return collect if findall:
else: if uid not in collect:
return None collect.append(uid)
else:
return uid, use
return collect
def syncconfig(config1, default, drop=False, deep=0, skipdict=False): 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 ( from myutils.config import (
uid2gamepath, uid2gamepath,
findgameuidofpath, findgameuidofpath,
savehook_new_list,
savehook_new_data, savehook_new_data,
) )
from myutils.hwnd import getpidexe from myutils.hwnd import getpidexe
@ -22,47 +23,57 @@ class playtimemanager:
isolation_level=None, isolation_level=None,
) )
try: try:
self.sqlsavegameinfo.execute(
"CREATE TABLE gameinternalid(gameinternalid INTEGER PRIMARY KEY AUTOINCREMENT,gamepath TEXT);"
)
self.sqlsavegameinfo.execute( self.sqlsavegameinfo.execute(
"CREATE TABLE traceplaytime_v4(id INTEGER PRIMARY KEY AUTOINCREMENT,gameinternalid INT,timestart BIGINT,timestop BIGINT);" "CREATE TABLE traceplaytime_v4(id INTEGER PRIMARY KEY AUTOINCREMENT,gameinternalid INT,timestart BIGINT,timestop BIGINT);"
) )
except: except:
pass 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() 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): def querytraceplaytime_v4(self, gameuid):
gameinternalid = self.get_gameinternalid(uid2gamepath[gameuid]) gameinternalid = self.get_gameinternalid(gameuid)
return self.sqlsavegameinfo.execute( return self.sqlsavegameinfo.execute(
"SELECT timestart,timestop FROM traceplaytime_v4 WHERE gameinternalid = ?", "SELECT timestart,timestop FROM traceplaytime_v4 WHERE gameinternalid = ?",
(gameinternalid,), (gameinternalid,),
).fetchall() ).fetchall()
def get_gameinternalid(self, gamepath): def get_gameinternalid(self, gameuid):
while True: while True:
ret = self.sqlsavegameinfo.execute( ret = self.sqlsavegameinfo.execute(
"SELECT gameinternalid FROM gameinternalid WHERE gamepath = ?", "SELECT * FROM gameinternalid_v2 WHERE gameuid = ?",
(gamepath,), (gameuid,),
).fetchone() ).fetchone()
if ret is None: if ret is None:
self.sqlsavegameinfo.execute( self.sqlsavegameinfo.execute(
"INSERT INTO gameinternalid VALUES(NULL,?)", (gamepath,) "INSERT INTO gameinternalid_v2 VALUES(NULL,?)", (gameuid,)
) )
else: else:
return ret[0] return ret[0]
def resetgameinternal(self, fr, to): def traceplaytime(self, gameuid, start, end, new):
_id = self.get_gameinternalid(fr)
self.sqlsavegameinfo.execute(
"UPDATE gameinternalid SET gamepath = ? WHERE (gameinternalid = ?)",
(to, _id),
)
def traceplaytime(self, gamepath, start, end, new): gameinternalid = self.get_gameinternalid(gameuid)
print(gameuid, gameinternalid)
gameinternalid = self.get_gameinternalid(gamepath)
if new: if new:
self.sqlsavegameinfo.execute( self.sqlsavegameinfo.execute(
"INSERT INTO traceplaytime_v4 VALUES(NULL,?,?,?)", "INSERT INTO traceplaytime_v4 VALUES(NULL,?,?,?)",
@ -88,15 +99,13 @@ class playtimemanager:
if not maybevmpaused: if not maybevmpaused:
savehook_new_data[gameuid]["statistic_playtime"] += _t - __t savehook_new_data[gameuid]["statistic_playtime"] += _t - __t
if (not maybevmpaused) and (self.__currentexe == name_): if (not maybevmpaused) and (self.__currentexe == name_):
self.traceplaytime( self.traceplaytime(gameuid, self.__statistictime - 1, _t, False)
uid2gamepath[gameuid], self.__statistictime - 1, _t, False
)
else: else:
self.__statistictime = time.time() self.__statistictime = time.time()
self.__currentexe = name_ self.__currentexe = name_
self.traceplaytime( self.traceplaytime(
uid2gamepath[gameuid], gameuid,
self.__statistictime - 1, self.__statistictime - 1,
self.__statistictime, self.__statistictime,
True, True,
@ -115,11 +124,10 @@ class playtimemanager:
name_ = getpidexe(_pid) name_ = getpidexe(_pid)
if not name_: if not name_:
return return
uids = findgameuidofpath(name_, findall=True) uid = findgameuidofpath(name_)
try: try:
if len(uids): if uid:
for uid in uids: isok(uid[0])
isok(uid)
else: else:
self.__currentexe = None self.__currentexe = None
except: except:

View File

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