From c54325d7ba06fe55a296f3bd822c771aafeb32de 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: Fri, 1 Mar 2024 22:06:50 +0800 Subject: [PATCH] srclang auto switch && custom command --- .../LunaTranslator/LunaTranslator.py | 5 +++ .../LunaTranslator/gui/dialog_savedgame.py | 41 ++++++++++++------- LunaTranslator/LunaTranslator/gui/settin.py | 4 +- .../LunaTranslator/gui/setting_lang.py | 5 ++- .../LunaTranslator/myutils/config.py | 3 ++ LunaTranslator/files/lang/ar.json | 4 +- LunaTranslator/files/lang/cht.json | 4 +- LunaTranslator/files/lang/en.json | 4 +- LunaTranslator/files/lang/es.json | 4 +- LunaTranslator/files/lang/fr.json | 4 +- LunaTranslator/files/lang/it.json | 4 +- LunaTranslator/files/lang/ja.json | 4 +- LunaTranslator/files/lang/ko.json | 4 +- LunaTranslator/files/lang/pl.json | 4 +- LunaTranslator/files/lang/ru.json | 4 +- LunaTranslator/files/lang/th.json | 4 +- LunaTranslator/files/lang/tr.json | 4 +- LunaTranslator/files/lang/uk.json | 4 +- LunaTranslator/files/lang/vi.json | 4 +- LunaTranslator/files/lang/zh.json | 4 +- LunaTranslator/trans_lang.py | 2 +- plugins/scripts/build32.bat | 1 + plugins/scripts/build64.bat | 1 + plugins/scripts/copytarget.py | 11 +++++ 24 files changed, 100 insertions(+), 33 deletions(-) create mode 100644 plugins/scripts/copytarget.py diff --git a/LunaTranslator/LunaTranslator/LunaTranslator.py b/LunaTranslator/LunaTranslator/LunaTranslator.py index df6b5a67..59709328 100644 --- a/LunaTranslator/LunaTranslator/LunaTranslator.py +++ b/LunaTranslator/LunaTranslator/LunaTranslator.py @@ -528,6 +528,11 @@ class MAINUI() : self.textsource=texthook(pids,hwnd,name_ ,autostarthookcode=savehook_new_data[name_]['hook'],needinserthookcode=needinserthookcode) elif len(pids)==1 and globalconfig['sourcestatus2']['fridahook']['use'] and savehook_new_data[name_]['fridahook']['loadmethod']==0: self.textsource=fridahook(0,savehook_new_data[name_]['fridahook']['js'],name_,pids[0],hwnd) + + + onloadautoswitchsrclang=savehook_new_data[name_]['onloadautoswitchsrclang'] + if onloadautoswitchsrclang>0: + self.settin_ui.srclangswitcher.setCurrentIndex(onloadautoswitchsrclang-1) break else: diff --git a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py index 417f15cb..0e9db6d3 100644 --- a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py +++ b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py @@ -478,13 +478,6 @@ class dialog_setting_game(QDialog): b=windows.GetBinaryType(exepath) - if type==2: - formLayout.addLayout(getboxlayout([ - QLabel(_TR("转区启动")), - getsimpleswitch(savehook_new_data[exepath],'leuse') - ])) - - if b==6: _methods=['','Locale_Remulator','Ntleas' ] else: @@ -492,15 +485,31 @@ class dialog_setting_game(QDialog): if b==6 and savehook_new_data[exepath]['localeswitcher']==0: savehook_new_data[exepath]['localeswitcher']=2 formLayout.addLayout(getboxlayout([ - QLabel(_TR("转区方法")),getsimplecombobox(_TRL(_methods),savehook_new_data[exepath],'localeswitcher') + QLabel(_TR("转区启动")), + getsimpleswitch(savehook_new_data[exepath],'leuse'), + QLabel(_TR("转区方法")), + getsimplecombobox(_TRL(_methods),savehook_new_data[exepath],'localeswitcher') + ][(type!=2)*2:])) + + editcmd=QLineEdit(savehook_new_data[exepath]['startcmd']) + editcmd.textEdited.connect(lambda _:savehook_new_data[exepath].__setitem__('startcmd',_)) + + formLayout.addLayout(getboxlayout([ + QLabel(_TR("命令行启动")), + getsimpleswitch(savehook_new_data[exepath],'startcmduse'), + editcmd ])) - formLayout.addLayout(getboxlayout([ QLabel(_TR("自动切换到模式")), getsimplecombobox(_TRL(['不切换','HOOK','剪贴板','OCR','FridaHook']),savehook_new_data[exepath],'onloadautochangemode2') ])) + formLayout.addLayout(getboxlayout([ + QLabel(_TR("自动切换源语言")), + getsimplecombobox(_TRL(['不切换'])+_TRL(static_data['language_list_translator']),savehook_new_data[exepath],'onloadautoswitchsrclang') + ])) + methodtab=QTabWidget() methodtab.addTab(self.gethooktab(exepath),"HOOK") @@ -655,9 +664,7 @@ def startgame(game): try: if os.path.exists(game): mode=savehook_new_data[game]['onloadautochangemode2'] - if mode==0: - pass - else: + if mode>0: _={ 1:'texthook', 2:'copy', @@ -672,14 +679,20 @@ def startgame(game): if globalconfig['sourcestatus2']['fridahook']['use'] and savehook_new_data[game]['fridahook'].get('loadmethod')==1: gobject.baseobject.textsource=fridahook(1,savehook_new_data[game]['fridahook'].get('js'),game) return + + dirpath=os.path.dirname(game) + + if savehook_new_data[game]['startcmduse']: + usearg=savehook_new_data[game]['startcmd'].format(exepath=game) + windows.CreateProcess(None,usearg, None,None,False,0,None, dirpath, windows.STARTUPINFO() ) + return if savehook_new_data[game]['leuse']==False or (game.lower()[-4:] not in ['.lnk','.exe']): #对于其他文件,需要AssocQueryStringW获取命令行才能正确le,太麻烦,放弃。 - windows.ShellExecute(None, "open", game, "", os.path.dirname(game), windows.SW_SHOW) + windows.ShellExecute(None, "open", game, "", dirpath, windows.SW_SHOW) return execheck3264=game usearg='"{}"'.format(game) - dirpath=os.path.dirname(game) if game.lower()[-4:]=='.lnk': exepath,args,iconpath,dirp=(winsharedutils.GetLnkTargetPath(game)) diff --git a/LunaTranslator/LunaTranslator/gui/settin.py b/LunaTranslator/LunaTranslator/gui/settin.py index f057c30c..fdc44ba7 100644 --- a/LunaTranslator/LunaTranslator/gui/settin.py +++ b/LunaTranslator/LunaTranslator/gui/settin.py @@ -15,7 +15,7 @@ from gui.settingpage_xianshishezhi import setTabThree ,setTabThree_direct from gui.settingpage_tts import setTab5 ,setTab5_direct from gui.settingpage_cishu import setTabcishu from gui.settingpage_quick import setTab_quick,setTab_quick_direct -from gui.setting_lang import setTablang +from gui.setting_lang import setTablang,setTablangd from gui.setting_proxy import setTab_proxy from gui.settingpage7 import setTab7 ,settab7direct from gui.settingpage_about import setTab_about,setTab_about_dicrect @@ -111,7 +111,7 @@ class Settin(closeashidewindow) : setTabThree_direct(self) setTab5_direct(self) setTab_quick_direct(self) - + setTablangd(self) setTab_about_dicrect(self) self.setstylesheet() diff --git a/LunaTranslator/LunaTranslator/gui/setting_lang.py b/LunaTranslator/LunaTranslator/gui/setting_lang.py index af196301..692306c8 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_lang.py +++ b/LunaTranslator/LunaTranslator/gui/setting_lang.py @@ -4,11 +4,14 @@ from myutils.config import globalconfig ,_TR,_TRL ,static_data from gui.usefulwidget import getsimplecombobox,getcolorbutton def setTablang(self) : self.tabadd_lazy(self.tab_widget, ('语言设置'), lambda :setTablanglz(self)) +def setTablangd(self): + self.srclangswitcher=getsimplecombobox(_TRL(static_data['language_list_translator']),globalconfig,'srclang3') + def setTablanglz(self) : grids=[ [('翻译及OCR语言',15)], [ - ("源语言",5),(getsimplecombobox(_TRL(static_data['language_list_translator'] ),globalconfig,'srclang3'),5),], + ("源语言",5),(self.srclangswitcher,5),], [ ("目标语言",5),(getsimplecombobox(_TRL(static_data['language_list_translator'] ),globalconfig,'tgtlang3'),5) , ], diff --git a/LunaTranslator/LunaTranslator/myutils/config.py b/LunaTranslator/LunaTranslator/myutils/config.py index 8f7d1968..2b421350 100644 --- a/LunaTranslator/LunaTranslator/myutils/config.py +++ b/LunaTranslator/LunaTranslator/myutils/config.py @@ -50,6 +50,7 @@ def getdefaultsavehook(gamepath,title=None): default={ 'localeswitcher':0, 'onloadautochangemode2':0, + 'onloadautoswitchsrclang':0, 'needinserthookcode':[], 'embedablehook':[], 'imagepath':None, @@ -59,6 +60,8 @@ def getdefaultsavehook(gamepath,title=None): 'statistic_wordcount':0, 'statistic_wordcount_nodump':0, 'leuse':True, + 'startcmd':'"{exepath}"', + 'startcmduse':False, 'hook':[], 'inserthooktimeout':0, 'needinserthookcode':[], diff --git a/LunaTranslator/files/lang/ar.json b/LunaTranslator/files/lang/ar.json index 6840024f..8cc31c1f 100644 --- a/LunaTranslator/files/lang/ar.json +++ b/LunaTranslator/files/lang/ar.json @@ -711,5 +711,7 @@ "多重区域模式": "وضع منطقة متعددة", "记忆选定区域": "اختيار الذاكرة", "关闭": "غلق", - "TGW语言模型": "TGW نموذج اللغة" + "TGW语言模型": "TGW نموذج اللغة", + "自动切换源语言": "التبديل التلقائي لغة المصدر", + "命令行启动": "بدء تشغيل سطر الأوامر" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/cht.json b/LunaTranslator/files/lang/cht.json index 919202cb..80f64b17 100644 --- a/LunaTranslator/files/lang/cht.json +++ b/LunaTranslator/files/lang/cht.json @@ -711,5 +711,7 @@ "多重区域模式": "多重區域模式", "记忆选定区域": "記憶選定區域", "关闭": "關閉", - "TGW语言模型": "TGW語言模型" + "TGW语言模型": "TGW語言模型", + "自动切换源语言": "自動切換源語言", + "命令行启动": "命令列啟動" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/en.json b/LunaTranslator/files/lang/en.json index 2d4d4dc4..5895eead 100644 --- a/LunaTranslator/files/lang/en.json +++ b/LunaTranslator/files/lang/en.json @@ -711,5 +711,7 @@ "多重区域模式": "Multi region mode", "记忆选定区域": "Memory selection area", "关闭": "close", - "TGW语言模型": "TGW language model" + "TGW语言模型": "TGW language model", + "自动切换源语言": "Automatically switch source language", + "命令行启动": "Command line startup" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/es.json b/LunaTranslator/files/lang/es.json index bf32a342..67f6dd7f 100644 --- a/LunaTranslator/files/lang/es.json +++ b/LunaTranslator/files/lang/es.json @@ -711,5 +711,7 @@ "多重区域模式": "Modelo multiregional", "记忆选定区域": "Área seleccionada de memoria", "关闭": "Cierre", - "TGW语言模型": "Modelo lingüístico tgw" + "TGW语言模型": "Modelo lingüístico tgw", + "自动切换源语言": "Cambiar automáticamente el lenguaje fuente", + "命令行启动": "Se inicia la línea de órdenes" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/fr.json b/LunaTranslator/files/lang/fr.json index 383ee200..eb74d940 100644 --- a/LunaTranslator/files/lang/fr.json +++ b/LunaTranslator/files/lang/fr.json @@ -711,5 +711,7 @@ "多重区域模式": "Mode Multi - zones", "记忆选定区域": "Mémoriser la zone sélectionnée", "关闭": "Fermé", - "TGW语言模型": "Modèle de langage tgw" + "TGW语言模型": "Modèle de langage tgw", + "自动切换源语言": "Changement automatique de langue source", + "命令行启动": "Démarrage de la ligne de commande" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/it.json b/LunaTranslator/files/lang/it.json index 8ab032ff..4fc71aed 100644 --- a/LunaTranslator/files/lang/it.json +++ b/LunaTranslator/files/lang/it.json @@ -711,5 +711,7 @@ "多重区域模式": "Modalità multi regione", "记忆选定区域": "Area di selezione della memoria", "关闭": "chiudi", - "TGW语言模型": "Modello linguistico TGW" + "TGW语言模型": "Modello linguistico TGW", + "自动切换源语言": "Cambia automaticamente la lingua sorgente", + "命令行启动": "Avvio della riga di comando" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ja.json b/LunaTranslator/files/lang/ja.json index 2f9f0f88..7a65721a 100644 --- a/LunaTranslator/files/lang/ja.json +++ b/LunaTranslator/files/lang/ja.json @@ -711,5 +711,7 @@ "多重区域模式": "複数領域モード", "记忆选定区域": "メモリ選択領域", "关闭": "閉じる", - "TGW语言模型": "TGW言語モデル" + "TGW语言模型": "TGW言語モデル", + "自动切换源语言": "ソース言語の自動切り替え", + "命令行启动": "コマンドライン起動" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ko.json b/LunaTranslator/files/lang/ko.json index f399f4f3..4036f0b5 100644 --- a/LunaTranslator/files/lang/ko.json +++ b/LunaTranslator/files/lang/ko.json @@ -711,5 +711,7 @@ "多重区域模式": "다중 영역 모드", "记忆选定区域": "선택한 영역 기억하기", "关闭": "닫기", - "TGW语言模型": "TGW 언어 모델" + "TGW语言模型": "TGW 언어 모델", + "自动切换源语言": "소스 언어 자동 전환", + "命令行启动": "명령줄 시작" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/pl.json b/LunaTranslator/files/lang/pl.json index f50b4081..6c6d2b3f 100644 --- a/LunaTranslator/files/lang/pl.json +++ b/LunaTranslator/files/lang/pl.json @@ -711,5 +711,7 @@ "多重区域模式": "Tryb wielu regionów", "记忆选定区域": "Obszar wyboru pamięci", "关闭": "zamknij", - "TGW语言模型": "Model językowy TGW" + "TGW语言模型": "Model językowy TGW", + "自动切换源语言": "Automatycznie przełączaj język źródłowy", + "命令行启动": "Uruchamianie wiersza poleceń" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ru.json b/LunaTranslator/files/lang/ru.json index d113db73..919ab6a1 100644 --- a/LunaTranslator/files/lang/ru.json +++ b/LunaTranslator/files/lang/ru.json @@ -711,5 +711,7 @@ "多重区域模式": "Многорегиональная модель", "记忆选定区域": "Запоминание выбранной области", "关闭": "Закрыть", - "TGW语言模型": "Языковая модель TGW" + "TGW语言模型": "Языковая модель TGW", + "自动切换源语言": "Автоматическое переключение исходного языка", + "命令行启动": "Запуск командной строки" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/th.json b/LunaTranslator/files/lang/th.json index 515212f6..7c21f389 100644 --- a/LunaTranslator/files/lang/th.json +++ b/LunaTranslator/files/lang/th.json @@ -711,5 +711,7 @@ "多重区域模式": "โหมดหลายโซน", "记忆选定区域": "หน่วยความจำพื้นที่ที่เลือก", "关闭": "ปิด", - "TGW语言模型": "รูปแบบภาษา TGW" + "TGW语言模型": "รูปแบบภาษา TGW", + "自动切换源语言": "สลับภาษาต้นทางโดยอัตโนมัติ", + "命令行启动": "เริ่มบรรทัดคำสั่ง" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/tr.json b/LunaTranslator/files/lang/tr.json index ca95c11f..9d72d3df 100644 --- a/LunaTranslator/files/lang/tr.json +++ b/LunaTranslator/files/lang/tr.json @@ -711,5 +711,7 @@ "多重区域模式": "Çok bölge modu", "记忆选定区域": "Hafıza seçim alanı", "关闭": "kapat", - "TGW语言模型": "TGW dil modeli" + "TGW语言模型": "TGW dil modeli", + "自动切换源语言": "Avtomatik kaynak dilini değiştir", + "命令行启动": "Komut satırı başlatma" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/uk.json b/LunaTranslator/files/lang/uk.json index 7ee36404..ff8793a1 100644 --- a/LunaTranslator/files/lang/uk.json +++ b/LunaTranslator/files/lang/uk.json @@ -711,5 +711,7 @@ "多重区域模式": "Режим декількох регіонів", "记忆选定区域": "Область вибору пам' яті", "关闭": "закрити", - "TGW语言模型": "Модель мови TGW" + "TGW语言模型": "Модель мови TGW", + "自动切换源语言": "Автоматично перемикати мову джерела", + "命令行启动": "Запуск командного рядка" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/vi.json b/LunaTranslator/files/lang/vi.json index 859eb5a2..2f082c97 100644 --- a/LunaTranslator/files/lang/vi.json +++ b/LunaTranslator/files/lang/vi.json @@ -711,5 +711,7 @@ "多重区域模式": "Chế độ đa vùng", "记忆选定区域": "Ghi nhớ vùng chọn", "关闭": "Đóng cửa", - "TGW语言模型": "Mô hình ngôn ngữ TGW" + "TGW语言模型": "Mô hình ngôn ngữ TGW", + "自动切换源语言": "Tự động chuyển đổi ngôn ngữ nguồn", + "命令行启动": "Chạy dòng lệnh" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/zh.json b/LunaTranslator/files/lang/zh.json index 91e37325..e9a0adac 100644 --- a/LunaTranslator/files/lang/zh.json +++ b/LunaTranslator/files/lang/zh.json @@ -711,5 +711,7 @@ "多重区域模式": "", "记忆选定区域": "", "关闭": "", - "TGW语言模型": "" + "TGW语言模型": "", + "自动切换源语言": "", + "命令行启动": "" } \ No newline at end of file diff --git a/LunaTranslator/trans_lang.py b/LunaTranslator/trans_lang.py index 9637bfc1..8287692f 100644 --- a/LunaTranslator/trans_lang.py +++ b/LunaTranslator/trans_lang.py @@ -1,6 +1,6 @@ import sys,time sys.path.append('./LunaTranslator') -from translator.baiduapi import TS +from translator.baidu import TS class TS1(TS): @property diff --git a/plugins/scripts/build32.bat b/plugins/scripts/build32.bat index 15fc523e..17accb67 100644 --- a/plugins/scripts/build32.bat +++ b/plugins/scripts/build32.bat @@ -1,2 +1,3 @@ cmake ../CMakeLists.txt -G "Visual Studio 17 2022" -A win32 -T host=x86 -B ../build/x86 cmake --build ../build/x86 --config Release --target ALL_BUILD -j 14 +python copytarget.py 1 \ No newline at end of file diff --git a/plugins/scripts/build64.bat b/plugins/scripts/build64.bat index bf83eeeb..b0698abe 100644 --- a/plugins/scripts/build64.bat +++ b/plugins/scripts/build64.bat @@ -1,2 +1,3 @@ cmake ../CMakeLists.txt -G "Visual Studio 17 2022" -A x64 -T host=x64 -B ../build/x64 cmake --build ../build/x64 --config Release --target ALL_BUILD -j 14 +python copytarget.py 0 \ No newline at end of file diff --git a/plugins/scripts/copytarget.py b/plugins/scripts/copytarget.py new file mode 100644 index 00000000..52f86c91 --- /dev/null +++ b/plugins/scripts/copytarget.py @@ -0,0 +1,11 @@ +import shutil,sys +x86=int(sys.argv[1]) +if x86: + shutil.copy('../builds/_x86/shareddllproxy32.exe','../../LunaTranslator/files/plugins') + shutil.copy('../builds/_x86/winrtutils32.dll','../../LunaTranslator/files/plugins/DLL32') + shutil.copy('../builds/_x86/winsharedutils32.dll','../../LunaTranslator/files/plugins/DLL32') +else: + shutil.copy('../builds/_x64/shareddllproxy64.exe','../../LunaTranslator/files/plugins') + shutil.copy('../builds/_x64/hookmagpie.dll','../../LunaTranslator/files/plugins') + shutil.copy('../builds/_x64/winrtutils64.dll','../../LunaTranslator/files/plugins/DLL64') + shutil.copy('../builds/_x64/winsharedutils64.dll','../../LunaTranslator/files/plugins/DLL64')