From 8875656b82bbf525057de3dea03f899c79ae529c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Mon, 19 Aug 2024 22:21:43 +0800 Subject: [PATCH] fix --- .../LunaTranslator/LunaTranslator.py | 56 ++++++------- .../LunaTranslator/gui/dialog_memory.py | 4 +- .../LunaTranslator/gui/pretransfile.py | 30 ++++--- .../LunaTranslator/gui/selecthook.py | 80 +++++-------------- .../LunaTranslator/gui/setting_textinput.py | 1 + .../LunaTranslator/gui/translatorUI.py | 17 ++-- LunaTranslator/LunaTranslator/myutils/hwnd.py | 5 +- LunaTranslator/LunaTranslator/myutils/post.py | 34 ++++---- .../LunaTranslator/myutils/traceplaytime.py | 12 ++- .../LunaTranslator/myutils/utils.py | 20 ++--- .../LunaTranslator/textsource/filetrans.py | 1 - .../LunaTranslator/textsource/texthook.py | 45 ++++++++++- .../textsource/textsourcebase.py | 8 +- .../LunaTranslator/translator/premt.py | 2 +- .../LunaTranslator/translator/rengong.py | 2 +- .../transoptimi/gptpromptdict.py | 4 +- .../LunaTranslator/transoptimi/noundict.py | 4 +- .../transoptimi/transerrorfix.py | 4 +- .../LunaTranslator/transoptimi/vndbnamemap.py | 4 +- plugins/CMakeLists.txt | 4 +- 20 files changed, 159 insertions(+), 178 deletions(-) diff --git a/LunaTranslator/LunaTranslator/LunaTranslator.py b/LunaTranslator/LunaTranslator/LunaTranslator.py index 1a09a992..14b73702 100644 --- a/LunaTranslator/LunaTranslator/LunaTranslator.py +++ b/LunaTranslator/LunaTranslator/LunaTranslator.py @@ -79,6 +79,8 @@ class MAINUI: self._internal_reader = None self.reader_uid = None self.__hwnd = None + self.gameuid = 0 + self.autoswitchgameuid = True @property def reader(self): @@ -112,36 +114,38 @@ class MAINUI: self.translation_ui.isbindedwindow = False self.translation_ui.refreshtooliconsignal.emit() self.translation_ui.thistimenotsetop = False + if self.autoswitchgameuid: + self.gameuid = 0 else: - _mute = winsharedutils.GetProcessMute( - windows.GetWindowThreadProcessId(__hwnd) - ) - self.translation_ui.processismuteed = _mute - self.translation_ui.isbindedwindow = True - self.translation_ui.refreshtooliconsignal.emit() - try: - if not self.textsource: - return - if not self.textsource.autofindpids: - return - self.textsource.pids = [windows.GetWindowThreadProcessId(__hwnd)] - gameuid = findgameuidofpath(getpidexe(self.textsource.pids[0])) - if gameuid: - self.textsource.gameuid = gameuid[0] - except: - print_exc() - + _pid = windows.GetWindowThreadProcessId(__hwnd) + if _pid: + _mute = winsharedutils.GetProcessMute(_pid) + self.translation_ui.processismuteed = _mute + self.translation_ui.isbindedwindow = True + self.translation_ui.refreshtooliconsignal.emit() + try: + if self.autoswitchgameuid: + gameuid = findgameuidofpath(getpidexe(_pid)) + if gameuid: + self.gameuid = gameuid[0] + except: + print_exc() + else: + if self.autoswitchgameuid: + self.gameuid = 0 if globalconfig["keepontop"]: self.translation_ui.settop() @textsource.setter def textsource(self, _): - if _ is None and self.textsource_p: - try: - self.textsource_p.endX() - except: - print_exc() + if _ is None: + if self.textsource_p: + try: + self.textsource_p.endX() + except: + print_exc() self.hwnd = None + self.autoswitchgameuid = True self.textsource_p = _ @threader @@ -517,11 +521,7 @@ class MAINUI: try: for _ in (0,): - - if not self.textsource: - break - - gameuid = self.textsource.gameuid + gameuid = self.gameuid if not gameuid: break if savehook_new_data[gameuid]["tts_follow_default"]: diff --git a/LunaTranslator/LunaTranslator/gui/dialog_memory.py b/LunaTranslator/LunaTranslator/gui/dialog_memory.py index af332655..7b5e2d99 100644 --- a/LunaTranslator/LunaTranslator/gui/dialog_memory.py +++ b/LunaTranslator/LunaTranslator/gui/dialog_memory.py @@ -32,11 +32,11 @@ class dialog_memory(saveposwindow): formLayout = QVBoxLayout() # self.showtext = QTextEdit() self.rwpath = gobject.getuserconfigdir( - "memory/{}.html".format(gobject.baseobject.textsource.gameuid) + "memory/{}.html".format(gobject.baseobject.gameuid) ) try: if os.path.exists(self.rwpath) == False: - md5 = getfilemd5(uid2gamepath[gobject.baseobject.textsource.gameuid]) + md5 = getfilemd5(uid2gamepath[gobject.baseobject.gameuid]) f2 = gobject.getuserconfigdir("memory/{}.html".format(md5)) try: os.rename(f2, self.rwpath) diff --git a/LunaTranslator/LunaTranslator/gui/pretransfile.py b/LunaTranslator/LunaTranslator/gui/pretransfile.py index ff125e10..e1bd564c 100644 --- a/LunaTranslator/LunaTranslator/gui/pretransfile.py +++ b/LunaTranslator/LunaTranslator/gui/pretransfile.py @@ -3,24 +3,27 @@ import sqlite3, os, json, functools from traceback import print_exc from myutils.config import globalconfig, _TR from myutils.utils import autosql -from gui.usefulwidget import getQMessageBox, LFocusCombo +from gui.usefulwidget import getQMessageBox, LFocusCombo, getsimplepatheditor from gui.dynalang import LFormLayout, LPushButton, LDialog from textsource.texthook import splitembedlines +from collections import Counter +from myutils.wrapper import tryprint -def sqlite2json2(self, sqlitefile, targetjson=None, existsmerge=False): +@tryprint +def sqlite2json2( + self, sqlitefile, targetjson=None, existsmerge=False, isforembed=False +): try: sql = autosql(sqlite3.connect(sqlitefile, check_same_thread=False)) ret = sql.execute("SELECT * FROM artificialtrans ").fetchall() js_format2 = {} - collect = set() + collect = [] for _aret in ret: if len(_aret) == 4: - _id, source, mt, source_origin = _aret if targetjson: source = source_origin - js_format2[source] = mt elif len(_aret) == 3: _id, source, mt = _aret @@ -31,14 +34,13 @@ def sqlite2json2(self, sqlitefile, targetjson=None, existsmerge=False): mtjs = mt js_format2[source] = mtjs - collect = collect.union(set(mtjs.keys())) - collect = list(collect) + collect.extend(list(mtjs.keys())) except: print_exc() getQMessageBox(self, "错误", "所选文件格式错误!") return _collect = [] - for _ in collect: + for _, __ in Counter(collect).most_common(): if _ in globalconfig["fanyi"]: _collect.append(_) collect = _collect @@ -52,7 +54,6 @@ def sqlite2json2(self, sqlitefile, targetjson=None, existsmerge=False): combo.addItems([globalconfig["fanyi"][_]["name"] for _ in collect]) formLayout.addRow("首选翻译", combo) - e = QLineEdit(sqlitefile[: -(len(".sqlite"))]) bu = LPushButton("选择路径") @@ -79,7 +80,7 @@ def sqlite2json2(self, sqlitefile, targetjson=None, existsmerge=False): formLayout.addRow(button) button.rejected.connect(dialog.close) - def __savefunction(target, existsmerge): + def __savefunction(target, existsmerge, isforembed): if len(collect) > 0: transkirokuuse = collect[combo.currentIndex()] for k in js_format2: @@ -96,8 +97,9 @@ def sqlite2json2(self, sqlitefile, targetjson=None, existsmerge=False): for k in existsjs: if k not in js_format2 or js_format2[k] == "": js_format2[k] = existsjs[k] - for _ in js_format2: - js_format2[_] = splitembedlines(js_format2[_]) + if isforembed: + for _ in js_format2: + js_format2[_] = splitembedlines(js_format2[_]) os.makedirs(os.path.dirname(target), exist_ok=True) with open(target, "w", encoding="utf8") as ff: ff.write( @@ -105,7 +107,9 @@ def sqlite2json2(self, sqlitefile, targetjson=None, existsmerge=False): ) dialog.close() - button.accepted.connect(functools.partial(__savefunction, targetjson, existsmerge)) + button.accepted.connect( + functools.partial(__savefunction, targetjson, existsmerge, isforembed) + ) button.button(QDialogButtonBox.StandardButton.Ok).setText(_TR("确定")) button.button(QDialogButtonBox.StandardButton.Cancel).setText(_TR("取消")) dialog.show() diff --git a/LunaTranslator/LunaTranslator/gui/selecthook.py b/LunaTranslator/LunaTranslator/gui/selecthook.py index 28ef0204..73c85428 100644 --- a/LunaTranslator/LunaTranslator/gui/selecthook.py +++ b/LunaTranslator/LunaTranslator/gui/selecthook.py @@ -82,42 +82,6 @@ class QButtonGroup_switch_widegt(QWidget): self.wlist.append(widget) -def listprocessm(): - cachefname = gobject.gettempdir("{}.txt".format(time.time())) - arch = "64" if gobject.baseobject.textsource.is64bit else "32" - exe = os.path.abspath("./files/plugins/shareddllproxy{}.exe".format(arch)) - pid = " ".join([str(_) for _ in gobject.baseobject.textsource.pids]) - subprocess.run('"{}" listpm "{}" {}'.format(exe, cachefname, pid)) - - with open(cachefname, "r", encoding="utf-16-le") as ff: - readf = ff.read() - - os.remove(cachefname) - _list = readf.split("\n")[:-1] - if len(_list) == 0: - return [] - - ret = [] - hasprogram = "c:\\program files" in _list[0].lower() - for name_ in _list: - name = name_.lower() - if ( - ":\\windows\\" in name - or "\\microsoft\\" in name - or "\\windowsapps\\" in name - ): - continue - if hasprogram == False and "c:\\program files" in name: - continue - fn = name_.split("\\")[-1] - if fn in ret: - continue - if fn.lower() in ["lunahook32.dll", "lunahook64.dll"]: - continue - ret.append(fn) - return ret - - hookcodehelp = r""" 1、内存读取 R{S|Q|V|U}[codepage#]@addr @@ -261,12 +225,10 @@ class searchhookparam(LDialog): layout1 = QHBoxLayout() layout1.addWidget(LLabel("代码页")) - if savehook_new_data[gobject.baseobject.textsource.gameuid][ - "hooksetting_follow_default" - ]: + if savehook_new_data[gobject.baseobject.gameuid]["hooksetting_follow_default"]: cp = globalconfig["codepage_index"] else: - cp = savehook_new_data[gobject.baseobject.textsource.gameuid][ + cp = savehook_new_data[gobject.baseobject.gameuid][ "hooksetting_private" ].get("codepage_index", globalconfig["codepage_index"]) self.codepagesave = {"spcp": cp} @@ -357,7 +319,7 @@ class searchhookparam(LDialog): usestruct.boundaryModule, 2, uselayout=offaddrl, - getlistcall=listprocessm, + getlistcall=gobject.baseobject.textsource.listprocessm, ) autoaddline( "offstartaddr", @@ -565,11 +527,11 @@ class hookselect(closeashidewindow): if _isusing: if hn[:8] == "UserHook": - needinserthookcode = savehook_new_data[ - gobject.baseobject.textsource.gameuid - ]["needinserthookcode"] + needinserthookcode = savehook_new_data[gobject.baseobject.gameuid][ + "needinserthookcode" + ] needinserthookcode = list(set(needinserthookcode + [hc])) - savehook_new_data[gobject.baseobject.textsource.gameuid].update( + savehook_new_data[gobject.baseobject.gameuid].update( {"needinserthookcode": needinserthookcode} ) else: @@ -581,21 +543,17 @@ class hookselect(closeashidewindow): gobject.baseobject.textsource.useembed(tp.addr, tp.ctx, tp.ctx2, _) _use = self._check_tp_using(key) if _use: - savehook_new_data[gobject.baseobject.textsource.gameuid][ - "embedablehook" - ].append([hc, tp.addr, tp.ctx, tp.ctx2]) + savehook_new_data[gobject.baseobject.gameuid]["embedablehook"].append( + [hc, tp.addr, tp.ctx, tp.ctx2] + ) else: save = [] - for _ in savehook_new_data[gobject.baseobject.textsource.gameuid][ - "embedablehook" - ]: + for _ in savehook_new_data[gobject.baseobject.gameuid]["embedablehook"]: hc, ad, c1, c2 = _ if (hc, 0, c1, c2) == (hc, 0, tp.ctx, tp.ctx2): save.append(_) for _ in save: - savehook_new_data[gobject.baseobject.textsource.gameuid][ - "embedablehook" - ].remove(_) + savehook_new_data[gobject.baseobject.gameuid]["embedablehook"].remove(_) def setupUi(self): self.widget = QWidget() @@ -740,13 +698,13 @@ class hookselect(closeashidewindow): def opensolvetext(self): try: - dialog_setting_game(self, gobject.baseobject.textsource.gameuid, 3) + dialog_setting_game(self, gobject.baseobject.gameuid, 3) except: print_exc() def opengamesetting(self): try: - dialog_setting_game(self, gobject.baseobject.textsource.gameuid, 1) + dialog_setting_game(self, gobject.baseobject.gameuid, 1) except: print_exc() @@ -900,17 +858,17 @@ class hookselect(closeashidewindow): gobject.baseobject.textsource.selectedhook.append(key) if hn[:8] == "UserHook": - needinserthookcode = savehook_new_data[ - gobject.baseobject.textsource.gameuid - ]["needinserthookcode"] + needinserthookcode = savehook_new_data[gobject.baseobject.gameuid][ + "needinserthookcode" + ] needinserthookcode = list(set(needinserthookcode + [hc])) - savehook_new_data[gobject.baseobject.textsource.gameuid].update( + savehook_new_data[gobject.baseobject.gameuid].update( {"needinserthookcode": needinserthookcode} ) else: pass - savehook_new_data[gobject.baseobject.textsource.gameuid].update( + savehook_new_data[gobject.baseobject.gameuid].update( {"hook": gobject.baseobject.textsource.serialselectedhook()} ) except: diff --git a/LunaTranslator/LunaTranslator/gui/setting_textinput.py b/LunaTranslator/LunaTranslator/gui/setting_textinput.py index 9f016bdd..f69569f2 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_textinput.py +++ b/LunaTranslator/LunaTranslator/gui/setting_textinput.py @@ -249,6 +249,7 @@ def exportchspatch(self): sqlfname_all, os.path.join(os.path.dirname(exe), "translation.json"), existsmerge=True, + isforembed=True, ) diff --git a/LunaTranslator/LunaTranslator/gui/translatorUI.py b/LunaTranslator/LunaTranslator/gui/translatorUI.py index bd5e2e0b..9e4301a0 100644 --- a/LunaTranslator/LunaTranslator/gui/translatorUI.py +++ b/LunaTranslator/LunaTranslator/gui/translatorUI.py @@ -643,15 +643,13 @@ class TranslatorWindow(resizableframeless): "open_relative_link", lambda: browserdialog( gobject.baseobject.commonstylebase, - trypass(lambda: gobject.baseobject.textsource.gameuid)(), + trypass(lambda: gobject.baseobject.gameuid)(), ), ), ( "open_game_setting", lambda: dialog_setting_game( - gobject.baseobject.commonstylebase, - gobject.baseobject.textsource.gameuid, - 1, + gobject.baseobject.commonstylebase, gobject.baseobject.gameuid, 1 ), ), ("ocr_once", self.ocr_once_signal.emit), @@ -1079,11 +1077,12 @@ class TranslatorWindow(resizableframeless): self.titlebar.setstyle(bottomr, bottomr3) def muteprocessfuntion(self): - if gobject.baseobject.textsource and gobject.baseobject.textsource.pids: - self.processismuteed = not self.processismuteed - self.refreshtoolicon() - for pid in gobject.baseobject.textsource.pids: - winsharedutils.SetProcessMute(pid, self.processismuteed) + pid = windows.GetWindowThreadProcessId(gobject.baseobject.hwnd) + if not pid: + return + self.processismuteed = not self.processismuteed + self.refreshtoolicon() + winsharedutils.SetProcessMute(pid, self.processismuteed) def _externalfsend(self, current): self.isletgamefullscreened = current diff --git a/LunaTranslator/LunaTranslator/myutils/hwnd.py b/LunaTranslator/LunaTranslator/myutils/hwnd.py index cb94a8fe..106c586d 100644 --- a/LunaTranslator/LunaTranslator/myutils/hwnd.py +++ b/LunaTranslator/LunaTranslator/myutils/hwnd.py @@ -22,10 +22,7 @@ def grabwindow(app="PNG", callback_origin=None): dirname = os.path.basename(gamepath).replace( "." + os.path.basename(gamepath).split(".")[-1], "" ) - try: - uid = gobject.baseobject.textsource.gameuid - except: - uid = None + uid = gobject.baseobject.gameuid fname = gobject.getcachedir( f"screenshot/{dirname}/" + time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()), diff --git a/LunaTranslator/LunaTranslator/myutils/post.py b/LunaTranslator/LunaTranslator/myutils/post.py index 71afa412..329a03d0 100644 --- a/LunaTranslator/LunaTranslator/myutils/post.py +++ b/LunaTranslator/LunaTranslator/myutils/post.py @@ -393,25 +393,21 @@ def POSTSOLVE(line): usemypostpath = "./userconfig/mypost.py" usemodule = "mypost" try: - if gobject.baseobject.textsource: - gameuid = gobject.baseobject.textsource.gameuid - if gameuid and not savehook_new_data[gameuid]["textproc_follow_default"]: - useranklist = savehook_new_data[gameuid]["save_text_process_info"][ - "rank" - ] - usedpostprocessconfig = savehook_new_data[gameuid][ - "save_text_process_info" - ]["postprocessconfig"] - if savehook_new_data[gameuid]["save_text_process_info"].get( - "mypost", None - ): - usemodule = ( - "posts." - + savehook_new_data[gameuid]["save_text_process_info"]["mypost"] - ) - usemypostpath = "./userconfig/posts/{}.py".format( - savehook_new_data[gameuid]["save_text_process_info"]["mypost"] - ) + + gameuid = gobject.baseobject.gameuid + if gameuid and not savehook_new_data[gameuid]["textproc_follow_default"]: + useranklist = savehook_new_data[gameuid]["save_text_process_info"]["rank"] + usedpostprocessconfig = savehook_new_data[gameuid][ + "save_text_process_info" + ]["postprocessconfig"] + if savehook_new_data[gameuid]["save_text_process_info"].get("mypost", None): + usemodule = ( + "posts." + + savehook_new_data[gameuid]["save_text_process_info"]["mypost"] + ) + usemypostpath = "./userconfig/posts/{}.py".format( + savehook_new_data[gameuid]["save_text_process_info"]["mypost"] + ) except: print_exc() for postitem in useranklist: diff --git a/LunaTranslator/LunaTranslator/myutils/traceplaytime.py b/LunaTranslator/LunaTranslator/myutils/traceplaytime.py index 886f9e93..42909505 100644 --- a/LunaTranslator/LunaTranslator/myutils/traceplaytime.py +++ b/LunaTranslator/LunaTranslator/myutils/traceplaytime.py @@ -113,10 +113,14 @@ class playtimemanager: _hwnd = windows.GetForegroundWindow() _pid = windows.GetWindowThreadProcessId(_hwnd) try: - if len(gobject.baseobject.textsource.pids) == 0: - raise Exception() - if _pid in gobject.baseobject.textsource.pids or _pid == os.getpid(): - isok(gobject.baseobject.textsource.gameuid) + gamehwnd = gobject.baseobject.hwnd + if not gamehwnd: + raise + gamepid = windows.GetWindowThreadProcessId(gamehwnd) + if not gamepid: + raise + if _pid == gamepid or _pid == os.getpid(): + isok(gobject.baseobject.gameuid) else: self.__currentexe = None except: diff --git a/LunaTranslator/LunaTranslator/myutils/utils.py b/LunaTranslator/LunaTranslator/myutils/utils.py index 458a3f0d..69f29f4f 100644 --- a/LunaTranslator/LunaTranslator/myutils/utils.py +++ b/LunaTranslator/LunaTranslator/myutils/utils.py @@ -40,11 +40,7 @@ def checkisusingwine(): def __internal__getlang(k1, k2): try: for _ in (0,): - - if not gobject.baseobject.textsource: - break - - gameuid = gobject.baseobject.textsource.gameuid + gameuid = gobject.baseobject.gameuid if not gameuid: break if savehook_new_data[gameuid]["lang_follow_default"]: @@ -442,9 +438,7 @@ def minmaxmoveobservefunc(self): if hwnd == gobject.baseobject.hwnd: gobject.baseobject.hwnd = None return - p_pids = gobject.baseobject.textsource.pids - if not p_pids: - return + p_pids = windows.GetWindowThreadProcessId(gobject.baseobject.hwnd) _focusp = windows.GetWindowThreadProcessId(hwnd) if event != windows.EVENT_SYSTEM_FOREGROUND: return @@ -456,7 +450,7 @@ def minmaxmoveobservefunc(self): "Window_Magpie_967EB565-6F73-4E94-AE53-00CC42592A22", None ): return - if _focusp in p_pids: + if _focusp == p_pids: gobject.baseobject.translation_ui.thistimenotsetop = False gobject.baseobject.translation_ui.settop() else: @@ -590,9 +584,7 @@ def postusewhich(name1): merge = name1 + "_merge" for _ in (0,): try: - if not gobject.baseobject.textsource: - break - gameuid = gobject.baseobject.textsource.gameuid + gameuid = gobject.baseobject.gameuid if not gameuid: break if savehook_new_data[gameuid]["transoptimi_followdefault"]: @@ -638,9 +630,7 @@ loadpostsettingwindowmethod_private = functools.partial( def loadpostsettingwindowmethod_maybe(name, parent): for _ in (0,): try: - if not gobject.baseobject.textsource: - break - gameuid = gobject.baseobject.textsource.gameuid + gameuid = gobject.baseobject.gameuid if not gameuid: break return loadpostsettingwindowmethod_private(name)(parent, gameuid) diff --git a/LunaTranslator/LunaTranslator/textsource/filetrans.py b/LunaTranslator/LunaTranslator/textsource/filetrans.py index b3c930a4..2ccc44d2 100644 --- a/LunaTranslator/LunaTranslator/textsource/filetrans.py +++ b/LunaTranslator/LunaTranslator/textsource/filetrans.py @@ -118,7 +118,6 @@ class parselrc: class filetrans(basetext): - autofindpids = False def end(self): diff --git a/LunaTranslator/LunaTranslator/textsource/texthook.py b/LunaTranslator/LunaTranslator/textsource/texthook.py index dbf60fea..19226bd8 100644 --- a/LunaTranslator/LunaTranslator/textsource/texthook.py +++ b/LunaTranslator/LunaTranslator/textsource/texthook.py @@ -15,6 +15,7 @@ from myutils.utils import checkchaos, getfilemd5, getlangtgt, getlanguagespace from myutils.hwnd import injectdll, test_injectable, ListProcess, getpidexe from myutils.wrapper import threader from traceback import print_exc +import subprocess from ctypes import ( CDLL, @@ -88,7 +89,7 @@ HookInsertHandler = CFUNCTYPE(None, c_uint64, c_wchar_p) EmbedCallback = CFUNCTYPE(None, c_wchar_p, ThreadParam) -def splitembedlines(trans): +def splitembedlines(trans: str): if len(trans) and globalconfig["embedded"]["limittextlength_use"]: length = globalconfig["embedded"]["limittextlength_length"] lines = trans.split("\n") @@ -104,7 +105,6 @@ def splitembedlines(trans): class texthook(basetext): - autofindpids = False @property def config(self): @@ -188,7 +188,7 @@ class texthook(basetext): self.Luna_QueryThreadHistory = LunaHost.Luna_QueryThreadHistory self.Luna_QueryThreadHistory.argtypes = (ThreadParam,) self.Luna_QueryThreadHistory.restype = c_void_p - + self.pids = [] self.keepref = [] self.hookdatacollecter = OrderedDict() self.reverse = {} @@ -201,10 +201,46 @@ class texthook(basetext): self.multiselectedcollectorlock = threading.Lock() self.lastflushtime = 0 self.runonce_line = "" + gobject.baseobject.autoswitchgameuid = False self.delaycollectallselectedoutput() self.prepares() self.autohookmonitorthread() + def listprocessm(self): + cachefname = gobject.gettempdir("{}.txt".format(time.time())) + arch = "64" if self.is64bit else "32" + exe = os.path.abspath("./files/plugins/shareddllproxy{}.exe".format(arch)) + pid = " ".join([str(_) for _ in self.pids]) + subprocess.run('"{}" listpm "{}" {}'.format(exe, cachefname, pid)) + + with open(cachefname, "r", encoding="utf-16-le") as ff: + readf = ff.read() + + os.remove(cachefname) + _list = readf.split("\n")[:-1] + if len(_list) == 0: + return [] + + ret = [] + hasprogram = "c:\\program files" in _list[0].lower() + for name_ in _list: + name = name_.lower() + if ( + ":\\windows\\" in name + or "\\microsoft\\" in name + or "\\windowsapps\\" in name + ): + continue + if hasprogram == False and "c:\\program files" in name: + continue + fn = name_.split("\\")[-1] + if fn in ret: + continue + if fn.lower() in ["lunahook32.dll", "lunahook64.dll"]: + continue + ret.append(fn) + return ret + def connecthwnd(self, hwnd): if ( gobject.baseobject.AttachProcessDialog @@ -245,6 +281,8 @@ class texthook(basetext): def start(self, hwnd, pids, gamepath, gameuid, autostart=False): gobject.baseobject.hwnd = hwnd + gobject.baseobject.gameuid = gameuid + self.gameuid = gameuid self.detachall() _filename, _ = os.path.splitext(os.path.basename(gamepath)) sqlitef = gobject.gettranslationrecorddir(f"{_filename}_{gameuid}.sqlite") @@ -272,7 +310,6 @@ class texthook(basetext): self.removedaddress = [] self.gamepath = gamepath - self.gameuid = gameuid self.is64bit = Is64bit(pids[0]) if ( len(autostarthookcode) == 0 diff --git a/LunaTranslator/LunaTranslator/textsource/textsourcebase.py b/LunaTranslator/LunaTranslator/textsource/textsourcebase.py index ddcbefe7..013acdb0 100644 --- a/LunaTranslator/LunaTranslator/textsource/textsourcebase.py +++ b/LunaTranslator/LunaTranslator/textsource/textsourcebase.py @@ -6,17 +6,13 @@ from myutils.utils import autosql class basetext: - autofindpids = True def gettextonce(self): return None def init(self): ... def end(self): ... - def __init__(self): - self.pids = [] - self.gameuid = None # self.textgetmethod = gobject.baseobject.textgetmethod @@ -96,7 +92,7 @@ class basetext: "SELECT * FROM artificialtrans WHERE source = ?", (src,) ).fetchone() try: - savehook_new_data[self.gameuid]["statistic_wordcount"] += lensrc + savehook_new_data[gobject.baseobject.gameuid]["statistic_wordcount"] += lensrc except: pass if ret is None: @@ -111,7 +107,7 @@ class basetext: (src, json.dumps({})), ) try: - savehook_new_data[self.gameuid][ + savehook_new_data[gobject.baseobject.gameuid][ "statistic_wordcount_nodump" ] += lensrc except: diff --git a/LunaTranslator/LunaTranslator/translator/premt.py b/LunaTranslator/LunaTranslator/translator/premt.py index 418a5d04..418b6573 100644 --- a/LunaTranslator/LunaTranslator/translator/premt.py +++ b/LunaTranslator/LunaTranslator/translator/premt.py @@ -11,7 +11,7 @@ import winsharedutils class TS(basetrans): def unsafegetcurrentgameconfig(self): try: - gameuid = gobject.baseobject.textsource.gameuid + gameuid = gobject.baseobject.gameuid _path = savehook_new_data[gameuid]["gamesqlitefile"] return _path except: diff --git a/LunaTranslator/LunaTranslator/translator/rengong.py b/LunaTranslator/LunaTranslator/translator/rengong.py index 990ce45f..bee05969 100644 --- a/LunaTranslator/LunaTranslator/translator/rengong.py +++ b/LunaTranslator/LunaTranslator/translator/rengong.py @@ -24,7 +24,7 @@ class TS(basetrans): def unsafegetcurrentgameconfig(self): try: - gameuid = gobject.baseobject.textsource.gameuid + gameuid = gobject.baseobject.gameuid _path = savehook_new_data[gameuid]["gamejsonfile"] if isinstance(_path, str): _path = [_path] diff --git a/LunaTranslator/LunaTranslator/transoptimi/gptpromptdict.py b/LunaTranslator/LunaTranslator/transoptimi/gptpromptdict.py index f5328a35..8c2afd93 100644 --- a/LunaTranslator/LunaTranslator/transoptimi/gptpromptdict.py +++ b/LunaTranslator/LunaTranslator/transoptimi/gptpromptdict.py @@ -49,10 +49,10 @@ class Process: if which == 1: return globalconfig["gptpromptdict"] elif which == 2: - gameuid = gobject.baseobject.textsource.gameuid + gameuid = gobject.baseobject.gameuid return savehook_new_data[gameuid]["gptpromptdict"] elif which == 3: - gameuid = gobject.baseobject.textsource.gameuid + gameuid = gobject.baseobject.gameuid return ( savehook_new_data[gameuid]["gptpromptdict"] + globalconfig["gptpromptdict"] diff --git a/LunaTranslator/LunaTranslator/transoptimi/noundict.py b/LunaTranslator/LunaTranslator/transoptimi/noundict.py index 9cfe64cb..093e630e 100644 --- a/LunaTranslator/LunaTranslator/transoptimi/noundict.py +++ b/LunaTranslator/LunaTranslator/transoptimi/noundict.py @@ -135,10 +135,10 @@ class Process: if which == 1: return globalconfig["noundictconfig"] elif which == 2: - gameuid = gobject.baseobject.textsource.gameuid + gameuid = gobject.baseobject.gameuid return savehook_new_data[gameuid]["noundictconfig"] elif which == 3: - gameuid = gobject.baseobject.textsource.gameuid + gameuid = gobject.baseobject.gameuid return ( savehook_new_data[gameuid]["noundictconfig"] + globalconfig["noundictconfig"] diff --git a/LunaTranslator/LunaTranslator/transoptimi/transerrorfix.py b/LunaTranslator/LunaTranslator/transoptimi/transerrorfix.py index b5b704c9..9bd5888d 100644 --- a/LunaTranslator/LunaTranslator/transoptimi/transerrorfix.py +++ b/LunaTranslator/LunaTranslator/transoptimi/transerrorfix.py @@ -39,10 +39,10 @@ class Process: if which == 1: return transerrorfixdictconfig["dict_v2"] elif which == 2: - gameuid = gobject.baseobject.textsource.gameuid + gameuid = gobject.baseobject.gameuid return savehook_new_data[gameuid]["transerrorfix"] elif which == 3: - gameuid = gobject.baseobject.textsource.gameuid + gameuid = gobject.baseobject.gameuid return ( savehook_new_data[gameuid]["transerrorfix"] + transerrorfixdictconfig["dict_v2"] diff --git a/LunaTranslator/LunaTranslator/transoptimi/vndbnamemap.py b/LunaTranslator/LunaTranslator/transoptimi/vndbnamemap.py index f9e88829..8a90cc54 100644 --- a/LunaTranslator/LunaTranslator/transoptimi/vndbnamemap.py +++ b/LunaTranslator/LunaTranslator/transoptimi/vndbnamemap.py @@ -37,10 +37,10 @@ class Process: if which == 1: return globalconfig["global_namemap2"] elif which == 2: - gameuid = gobject.baseobject.textsource.gameuid + gameuid = gobject.baseobject.gameuid return savehook_new_data[gameuid]["namemap2"] elif which == 3: - gameuid = gobject.baseobject.textsource.gameuid + gameuid = gobject.baseobject.gameuid return ( savehook_new_data[gameuid]["namemap2"] + globalconfig["global_namemap2"] ) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index add6cc2b..a8a39cc8 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -28,8 +28,8 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/version) include(generate_product_version) set(VERSION_MAJOR 5) -set(VERSION_MINOR 28) -set(VERSION_PATCH 6) +set(VERSION_MINOR 29) +set(VERSION_PATCH 0) add_library(pch pch.cpp) target_precompile_headers(pch PUBLIC pch.h)