From 8e37d6dc64c87150bd2a96e036c8388ff4909377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <1173718158@qq.com> Date: Fri, 8 Nov 2024 17:07:24 +0800 Subject: [PATCH] scripts --- .../scripts/build_lunahook.py | 1 + .../scripts/build_lunatranslator.py | 24 +++++++++--- {py => .github/scripts}/collectall.py | 7 ++++ {py => .github/scripts}/collectpyruntime.py | 7 ++++ {py => .github/scripts}/importanalysis.py | 0 .../scripts/packlunahook.py | 6 ++- .github/workflows/buildluna.yml | 6 +-- .github/workflows/buildlunahook.yml | 12 +++--- README.md | 2 +- cpp/LunaHook/scripts/buildcore.bat | 10 ++--- cpp/LunaHook/scripts/copytarget.py | 2 - cpp/LunaHook/scripts/pack.bat | 1 - cpp/scripts/build32.bat | 7 ++-- cpp/scripts/build64.bat | 9 +++-- cpp/scripts/copytarget.py | 17 -------- docs/other/README_en.md | 2 +- docs/other/README_ru.md | 2 +- py/LunaTranslator/ocrengines/youdaodictocr.py | 39 ------------------- 18 files changed, 66 insertions(+), 88 deletions(-) rename cpp/LunaHook/build.py => .github/scripts/build_lunahook.py (98%) rename py/build.py => .github/scripts/build_lunatranslator.py (87%) rename {py => .github/scripts}/collectall.py (94%) rename {py => .github/scripts}/collectpyruntime.py (96%) rename {py => .github/scripts}/importanalysis.py (100%) rename cpp/LunaHook/scripts/pack.py => .github/scripts/packlunahook.py (84%) delete mode 100644 cpp/LunaHook/scripts/copytarget.py delete mode 100644 cpp/LunaHook/scripts/pack.bat delete mode 100644 cpp/scripts/copytarget.py delete mode 100644 py/LunaTranslator/ocrengines/youdaodictocr.py diff --git a/cpp/LunaHook/build.py b/.github/scripts/build_lunahook.py similarity index 98% rename from cpp/LunaHook/build.py rename to .github/scripts/build_lunahook.py index 304deff7..8e2c3fc1 100644 --- a/cpp/LunaHook/build.py +++ b/.github/scripts/build_lunahook.py @@ -4,6 +4,7 @@ import subprocess rootDir = os.path.dirname(__file__) if not rootDir: rootDir = os.path.abspath(".") +rootDir=os.path.abspath(os.path.join(rootDir,'../../cpp/LunaHook')) if len(sys.argv) and sys.argv[1] == "loadversion": os.chdir(rootDir) with open("CMakeLists.txt", "r", encoding="utf8") as ff: diff --git a/py/build.py b/.github/scripts/build_lunatranslator.py similarity index 87% rename from py/build.py rename to .github/scripts/build_lunatranslator.py index ac6fd1b9..116a5a5b 100644 --- a/py/build.py +++ b/.github/scripts/build_lunatranslator.py @@ -9,6 +9,8 @@ if not rootDir: rootDir = os.path.abspath(".") else: rootDir = os.path.abspath(rootDir) +rootthisfiledir=rootDir +rootDir=os.path.abspath(os.path.join(rootDir,'../../py')) if sys.argv[1] == "loadversion": os.chdir(rootDir) with open("../cpp/version.cmake", "r", encoding="utf8") as ff: @@ -258,7 +260,7 @@ if __name__ == "__main__": shutil.rmtree(os.path.join(os.path.dirname(py37Path), "Lib\\test")) shutil.rmtree(os.path.join(os.path.dirname(py37Path), "Lib\\unittest")) # 放弃,3.8需要安装KB2533623才能运行,3.7用不着。 - subprocess.run(f"{py37Path} collectpyruntime.py") + subprocess.run(f"{py37Path} {os.path.join(rootthisfiledir,'collectpyruntime.py')}") elif sys.argv[1] == "merge": createPluginDirs() downloadsomething() @@ -291,12 +293,24 @@ if __name__ == "__main__": dirs_exist_ok=True, ) os.chdir(rootDir + "/../cpp/scripts") - subprocess.run(f"python copytarget.py 1") - subprocess.run(f"python copytarget.py 0") + os.makedirs('../../py/files/plugins/DLL32',exist_ok=True) + shutil.copy('../builds/_x86/shareddllproxy32.exe','../../py/files/plugins') + shutil.copy('../builds/_x86/winrtutils32.dll','../../py/files/plugins/DLL32') + shutil.copy('../builds/_x86/winsharedutils32.dll','../../py/files/plugins/DLL32') + shutil.copy('../builds/_x86/wcocr.dll','../../py/files/plugins/DLL32') + shutil.copy('../builds/_x86/LunaOCR32.dll','../../py/files/plugins/DLL32') + os.makedirs('../../py/files/plugins/DLL64',exist_ok=True) + shutil.copy('../builds/_x64/shareddllproxy64.exe','../../py/files/plugins') + shutil.copy('../builds/_x64/hookmagpie.dll','../../py/files/plugins') + shutil.copy('../builds/_x64/winrtutils64.dll','../../py/files/plugins/DLL64') + shutil.copy('../builds/_x64/winsharedutils64.dll','../../py/files/plugins/DLL64') + shutil.copy('../builds/_x64/wcocr.dll','../../py/files/plugins/DLL64') + shutil.copy('../builds/_x64/LunaOCR64.dll','../../py/files/plugins/DLL64') + if arch == "x86": os.chdir(rootDir) - os.system("python collectall.py 32") + os.system(f"python {os.path.join(rootthisfiledir,'collectall.py')} 32") else: os.chdir(rootDir) - os.system("python collectall.py 64") + os.system(f"python {os.path.join(rootthisfiledir,'collectall.py')} 64") diff --git a/py/collectall.py b/.github/scripts/collectall.py similarity index 94% rename from py/collectall.py rename to .github/scripts/collectall.py index 0a3d2b24..48632f7d 100644 --- a/py/collectall.py +++ b/.github/scripts/collectall.py @@ -3,6 +3,13 @@ import platform import sys from importanalysis import importanalysis +rootDir = os.path.dirname(__file__) +if not rootDir: + rootDir = os.path.abspath(".") +else: + rootDir = os.path.abspath(rootDir) +rootthisfiledir=rootDir +rootDir=os.path.abspath(os.path.join(rootDir,'../../py')) x86 = platform.architecture()[0] == "32bit" if sys.argv[1] == "32": targetdir = r"build\LunaTranslator_x86" diff --git a/py/collectpyruntime.py b/.github/scripts/collectpyruntime.py similarity index 96% rename from py/collectpyruntime.py rename to .github/scripts/collectpyruntime.py index 7a4b51b1..70ea8c5b 100644 --- a/py/collectpyruntime.py +++ b/.github/scripts/collectpyruntime.py @@ -3,6 +3,13 @@ import modulefinder, shutil, os, sys import builtins, platform import sys +rootDir = os.path.dirname(__file__) +if not rootDir: + rootDir = os.path.abspath(".") +else: + rootDir = os.path.abspath(rootDir) +rootthisfiledir=rootDir +rootDir=os.path.abspath(os.path.join(rootDir,'../../py')) pyversion = platform.python_version() pyversion2 = "".join(pyversion.split(".")[:2]) x86 = platform.architecture()[0] == "32bit" diff --git a/py/importanalysis.py b/.github/scripts/importanalysis.py similarity index 100% rename from py/importanalysis.py rename to .github/scripts/importanalysis.py diff --git a/cpp/LunaHook/scripts/pack.py b/.github/scripts/packlunahook.py similarity index 84% rename from cpp/LunaHook/scripts/pack.py rename to .github/scripts/packlunahook.py index e1703af5..e821d99a 100644 --- a/cpp/LunaHook/scripts/pack.py +++ b/.github/scripts/packlunahook.py @@ -1,8 +1,12 @@ import os, shutil, sys -os.chdir(os.path.dirname(__file__)) +rootDir = os.path.dirname(__file__) +if not rootDir: + rootDir = os.path.abspath(".") +rootDir=os.path.abspath(os.path.join(rootDir,'../../cpp/LunaHook')) +os.chdir(rootDir) for f in os.listdir("../builds"): if os.path.isdir("../builds/" + f) == False: continue diff --git a/.github/workflows/buildluna.yml b/.github/workflows/buildluna.yml index 93984882..0907152f 100644 --- a/.github/workflows/buildluna.yml +++ b/.github/workflows/buildluna.yml @@ -36,7 +36,7 @@ jobs: python-version: '3.7.9' architecture: ${{ matrix.architecture }} - - run: python py/build.py pyrt ${{ matrix.architecture }} 3.7.9 + - run: python .github/scripts/build_lunatranslator.py pyrt ${{ matrix.architecture }} 3.7.9 - uses: actions/upload-artifact@v4 with: name: pyrt_${{ matrix.architecture }} @@ -54,7 +54,7 @@ jobs: with: sdk-version: 22621 - - run: python py/build.py cpp ${{ matrix.architecture }} + - run: python .github/scripts/build_lunatranslator.py cpp ${{ matrix.architecture }} - uses: actions/upload-artifact@v4 with: name: cpp_${{ matrix.architecture }} @@ -76,7 +76,7 @@ jobs: - uses: actions/download-artifact@v4 with: path: build - - run: python py/build.py merge ${{ matrix.architecture }} + - run: python .github/scripts/build_lunatranslator.py merge ${{ matrix.architecture }} - uses: actions/upload-artifact@v4 with: name: ${{ matrix.fname }} diff --git a/.github/workflows/buildlunahook.yml b/.github/workflows/buildlunahook.yml index f69f9d57..8b66b77d 100644 --- a/.github/workflows/buildlunahook.yml +++ b/.github/workflows/buildlunahook.yml @@ -22,8 +22,8 @@ jobs: - uses: GuillaumeFalourd/setup-windows10-sdk-action@v2 with: sdk-version: 22621 - - run: python cpp/LunaHook/build.py build ${{ matrix.language }} winxp - - run: python cpp/LunaHook/scripts/pack.py + - run: python .github/scripts/build_lunahook.py build ${{ matrix.language }} winxp + - run: python .github/scripts/packlunahook.py - uses: actions/upload-artifact@v4 with: @@ -65,8 +65,8 @@ jobs: arch: ${{ matrix.qtarch }} dir: ${{ runner.temp }} setup-python: true - - run: python cpp/LunaHook/build.py ${{ matrix.cmd }} - - run: python cpp/LunaHook/scripts/pack.py + - run: python .github/scripts/build_lunahook.py ${{ matrix.cmd }} + - run: python .github/scripts/packlunahook.py # - name: Generate attestation for artifact # uses: actions/attest-build-provenance@v1 @@ -99,7 +99,7 @@ jobs: - uses: GuillaumeFalourd/setup-windows10-sdk-action@v2 with: sdk-version: 22621 - - run: python cpp/LunaHook/build.py build ${{ matrix.language }} ${{matrix.bits}} + - run: python .github/scripts/build_lunahook.py build ${{ matrix.language }} ${{matrix.bits}} - uses: actions/upload-artifact@v4 with: @@ -114,7 +114,7 @@ jobs: - uses: actions/download-artifact@v4 with: path: cpp/LunaHook/build - - run: python cpp/LunaHook/build.py merge + - run: python .github/scripts/build_lunahook.py merge - uses: softprops/action-gh-release@v2 with: tag_name: LunaHook diff --git a/README.md b/README.md index 4abfb750..d0e905d6 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ - **日语分词及假名显示** 支持使用 Mecab 等分词和显示假名 -- **查词** 支持使用 **离线辞书** ( MDICT、小学馆、灵格斯词典、EDICT/EDICT2 ) 和 **在线辞书** ( 有道、weblio、Goo、Moji、jisho ) 进行单词查询 +- **查词** 支持使用 **离线辞书** ( MDICT、小学馆、灵格斯词典、EDICT/EDICT2 ) 和 **在线辞书** ( 有道、weblio、Goo、Moji、jisho、JapanDict ) 进行单词查询 - **Anki** 支持使用一键添加单词到anki中 diff --git a/cpp/LunaHook/scripts/buildcore.bat b/cpp/LunaHook/scripts/buildcore.bat index 3b7876da..51cb15b2 100644 --- a/cpp/LunaHook/scripts/buildcore.bat +++ b/cpp/LunaHook/scripts/buildcore.bat @@ -1,6 +1,6 @@ -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 +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 -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 \ No newline at end of file +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 +robocopy ..\builds\Release_English ..\..\..\py\files\plugins\LunaHook \ No newline at end of file diff --git a/cpp/LunaHook/scripts/copytarget.py b/cpp/LunaHook/scripts/copytarget.py deleted file mode 100644 index 9462877d..00000000 --- a/cpp/LunaHook/scripts/copytarget.py +++ /dev/null @@ -1,2 +0,0 @@ -import shutil,sys -shutil.copytree('../builds/Release_English','../../../py/files/plugins/LunaHook',dirs_exist_ok=True) \ No newline at end of file diff --git a/cpp/LunaHook/scripts/pack.bat b/cpp/LunaHook/scripts/pack.bat deleted file mode 100644 index ec27cab8..00000000 --- a/cpp/LunaHook/scripts/pack.bat +++ /dev/null @@ -1 +0,0 @@ -python pack.py \ No newline at end of file diff --git a/cpp/scripts/build32.bat b/cpp/scripts/build32.bat index ac36340f..cf75912e 100644 --- a/cpp/scripts/build32.bat +++ b/cpp/scripts/build32.bat @@ -1,4 +1,5 @@ python fetchwebview2.py -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 +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 +copy .\builds\_x86\shareddllproxy32.exe ..\..\py\files\plugins +robocopy ..\builds\_x86 ..\..\py\files\plugins\DLL32 \ No newline at end of file diff --git a/cpp/scripts/build64.bat b/cpp/scripts/build64.bat index fff3305c..56fbcf73 100644 --- a/cpp/scripts/build64.bat +++ b/cpp/scripts/build64.bat @@ -1,4 +1,7 @@ python fetchwebview2.py -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 +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 + +copy ..\builds\_x64\shareddllproxy64.exe ..\..\py\files\plugins +copy ..\builds\_x64\hookmagpie.dll ..\..\py\files\plugins +robocopy ..\builds\_x64 ..\..\py\files\plugins\DLL64 \ No newline at end of file diff --git a/cpp/scripts/copytarget.py b/cpp/scripts/copytarget.py deleted file mode 100644 index 0d78e477..00000000 --- a/cpp/scripts/copytarget.py +++ /dev/null @@ -1,17 +0,0 @@ -import shutil,sys,os -x86=int(sys.argv[1]) -if x86: - os.makedirs('../../py/files/plugins/DLL32',exist_ok=True) - shutil.copy('../builds/_x86/shareddllproxy32.exe','../../py/files/plugins') - shutil.copy('../builds/_x86/winrtutils32.dll','../../py/files/plugins/DLL32') - shutil.copy('../builds/_x86/winsharedutils32.dll','../../py/files/plugins/DLL32') - shutil.copy('../builds/_x86/wcocr.dll','../../py/files/plugins/DLL32') - shutil.copy('../builds/_x86/LunaOCR32.dll','../../py/files/plugins/DLL32') -else: - os.makedirs('../../py/files/plugins/DLL64',exist_ok=True) - shutil.copy('../builds/_x64/shareddllproxy64.exe','../../py/files/plugins') - shutil.copy('../builds/_x64/hookmagpie.dll','../../py/files/plugins') - shutil.copy('../builds/_x64/winrtutils64.dll','../../py/files/plugins/DLL64') - shutil.copy('../builds/_x64/winsharedutils64.dll','../../py/files/plugins/DLL64') - shutil.copy('../builds/_x64/wcocr.dll','../../py/files/plugins/DLL64') - shutil.copy('../builds/_x64/LunaOCR64.dll','../../py/files/plugins/DLL64') diff --git a/docs/other/README_en.md b/docs/other/README_en.md index 4f619ece..4add386f 100644 --- a/docs/other/README_en.md +++ b/docs/other/README_en.md @@ -52,7 +52,7 @@ Supports almost all conceivable translation engines, including: - **Japanese Word Segmentation and Kana Display** Supports word segmentation and kana display using Mecab, etc. -- **Vocabulary Lookup** Supports **offline dictionaries** (MDICT, Shougakukan, Lingoes Dictionary, EDICT/EDICT2) and **online dictionaries** (Youdao, weblio, Goo, Moji, jisho) for word lookup +- **Vocabulary Lookup** Supports **offline dictionaries** (MDICT, Shougakukan, Lingoes Dictionary, EDICT/EDICT2) and **online dictionaries** (Youdao, weblio, Goo, Moji, jisho, JapanDict) for word lookup - **Anki** Supports one-click addition of words to Anki diff --git a/docs/other/README_ru.md b/docs/other/README_ru.md index b1f1715b..624e78b4 100644 --- a/docs/other/README_ru.md +++ b/docs/other/README_ru.md @@ -54,7 +54,7 @@ - **Сегментация японских слов и отображение глифов** Поддерживает использование Mecab и других для сегментации и отображения глифов -- **Поиск слов** Поддерживает использование **оффлайн словарей** ( MDICT, Shougakukan, Lingoes Dictionary, EDICT/EDICT2 ) и **онлайн словарей** ( Youdao, weblio, Goo, Moji, jisho ) для поиска слов +- **Поиск слов** Поддерживает использование **оффлайн словарей** ( MDICT, Shougakukan, Lingoes Dictionary, EDICT/EDICT2 ) и **онлайн словарей** ( Youdao, weblio, Goo, Moji, jisho, JapanDict ) для поиска слов - **Anki** Поддерживает добавление слов в Anki одним нажатием кнопки diff --git a/py/LunaTranslator/ocrengines/youdaodictocr.py b/py/LunaTranslator/ocrengines/youdaodictocr.py deleted file mode 100644 index 1715b1cb..00000000 --- a/py/LunaTranslator/ocrengines/youdaodictocr.py +++ /dev/null @@ -1,39 +0,0 @@ -from ocrengines.baseocrclass import baseocr -from ctypes import CDLL, c_char_p, c_size_t, c_void_p, CFUNCTYPE, sizeof, c_wchar_p -import json, os - -youdaosig = CDLL( - os.path.join(os.path.dirname(__file__), f"ydocr{sizeof(c_void_p)*8}.dll") -) -ydocr = youdaosig.ydocr -ydocr.argtypes = c_void_p, c_size_t, c_wchar_p, c_wchar_p, c_void_p - - -def doocr(image, src, tgt): - ret = [] - fp = CFUNCTYPE(None, c_char_p)(ret.append) - ydocr(image, len(image), src, tgt, fp) - boxs = [] - texts = [] - transs = [] - for line in ret: - line = json.loads(line.decode("utf8")) - boxs.append(line[:4]) - texts.append(line[4]) - transs.append(line[5]) - return boxs, transs, texts - - -class OCR(baseocr): - - def langmap(self): - return {"zh": "zh-CHS", "cht": "zh-CHT"} - - def ocr(self, imagebinary): - - boxs, transs, texts = doocr(imagebinary, self.srclang, self.tgtlang) - - if self.config["Translate"]: - return {"box": boxs, "text": transs, "isocrtranslate": True} - else: - return {"box": boxs, "text": texts}