diff --git a/.github/scripts/build_lunatranslator.py b/.github/scripts/build_lunatranslator.py index 51e6877e..e61fb98a 100644 --- a/.github/scripts/build_lunatranslator.py +++ b/.github/scripts/build_lunatranslator.py @@ -205,7 +205,7 @@ def buildPlugins(arch): f"cmake --build ../build/x86 --config Release --target ALL_BUILD -j 14" ) # subprocess.run(f"python copytarget.py 1") - elif arch=='x64': + elif arch == "x64": subprocess.run( f'cmake ../CMakeLists.txt -G "Visual Studio 17 2022" -A x64 -T host=x64 -B ../build/x64 -DCMAKE_SYSTEM_VERSION=10.0.26621.0' ) @@ -213,19 +213,21 @@ def buildPlugins(arch): f"cmake --build ../build/x64 --config Release --target ALL_BUILD -j 14" ) # subprocess.run(f"python copytarget.py 0") - elif arch=='xp': + elif arch == "xp": url = "https://github.com/Chuyu-Team/YY-Thunks/releases/download/v1.0.7/YY-Thunks-1.0.7-Binary.zip" os.system(rf"curl -SLo YY-Thunks-1.0.7-Binary.zip " + url) os.system(rf"7z x -y YY-Thunks-1.0.7-Binary.zip -o../libs/YY-Thunks") with open("do.bat", "w") as ff: ff.write( - rf""" + rf""" cmake -DWINXP=ON ../CMakeLists.txt -G "Visual Studio 16 2019" -A win32 -T v141_xp -B ../build/x86_xp cmake --build ../build/x86_xp --config Release --target ALL_BUILD -j 14 """ - ) + ) os.system(f"cmd /c do.bat") + + def downloadsomething(): pass # shutil.rmtree(rootDir + "\\files\\LunaTranslator_qss\\.git") @@ -280,10 +282,31 @@ if __name__ == "__main__": downloadLocaleEmulator() downloadNtlea() downloadCurl() - downloadOCRModel() + if arch != "xp": + downloadOCRModel() downloadcommon() downloadbass() os.chdir(rootDir) + if arch == "xp": + shutil.copytree( + f"{rootDir}/../build/cpp_xp", + f"{rootDir}/../cpp/builds", + dirs_exist_ok=True, + ) + shutil.copytree( + f"{rootDir}/../build/hook_xp", + f"{rootDir}/files/plugins/LunaHook", + dirs_exist_ok=True, + ) + os.chdir(rootDir + "/../cpp/scripts") + os.makedirs("../../py/files/plugins/DLL32", exist_ok=True) + shutil.copy("../builds/_x86/shareddllproxy32.exe", "../../py/files/plugins") + shutil.copy( + "../builds/_x86/winsharedutils32.dll", "../../py/files/plugins/DLL32" + ) + os.chdir(rootDir) + os.system(f"python {os.path.join(rootthisfiledir,'collectall_xp.py')}") + exit() shutil.copytree( f"{rootDir}/../build/hook_64", f"{rootDir}/files/plugins/LunaHook", diff --git a/.github/scripts/collectall.py b/.github/scripts/collectall.py index 48632f7d..0a3d2b24 100644 --- a/.github/scripts/collectall.py +++ b/.github/scripts/collectall.py @@ -3,13 +3,6 @@ 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/.github/scripts/collectall_xp.py b/.github/scripts/collectall_xp.py new file mode 100644 index 00000000..ddeafcd2 --- /dev/null +++ b/.github/scripts/collectall_xp.py @@ -0,0 +1,44 @@ +import shutil, os +import platform +import sys + +os.system("git clone https://github.com/HIllya51/py3.4_pyqt5.5.1") +os.rename("py3.4_pyqt5.5.1", "runtime") +targetdir = r"build\LunaTranslator_x86_winxp" +launch = r"..\cpp\builds\_x86" +baddll = "DLL64" + + +def copycheck(src, tgt): + print(src, tgt, os.path.exists(src)) + if not os.path.exists(src): + return + if src.lower().endswith("_ssl.pyd"): + return + if not os.path.exists(tgt): + os.makedirs(tgt, exist_ok=True) + if os.path.isdir(src): + tgt = os.path.join(tgt, os.path.basename(src)) + if os.path.exists(tgt): + shutil.rmtree(tgt) + shutil.copytree(src, tgt) + return + shutil.copy(src, tgt) + + +copycheck(os.path.join(launch, "LunaTranslator.exe"), targetdir) +copycheck(os.path.join(launch, "LunaTranslator_debug.exe"), targetdir) +copycheck("./LunaTranslator", targetdir) +copycheck(r".\files", targetdir) +copycheck("runtime", targetdir + "/files") +try: + shutil.rmtree(rf"{targetdir}\files\plugins\{baddll}") +except: + pass +shutil.copy(r"..\LICENSE", targetdir) + +target = os.path.basename(targetdir) +os.chdir(os.path.dirname(targetdir)) +if os.path.exists(rf"{target}.zip"): + os.remove(rf"{target}.zip") +os.system(rf'"C:\Program Files\7-Zip\7z.exe" a -m0=Deflate -mx9 {target}.zip {target}') diff --git a/.github/workflows/buildluna.yml b/.github/workflows/buildluna.yml index d5887cf4..a4679640 100644 --- a/.github/workflows/buildluna.yml +++ b/.github/workflows/buildluna.yml @@ -117,4 +117,19 @@ jobs: - uses: actions/upload-artifact@v4 with: name: ${{ matrix.fname }} - path: py/build/${{matrix.fname}}.zip \ No newline at end of file + path: py/build/${{matrix.fname}}.zip + merge_xp: + runs-on: windows-latest + needs: [build_cpp_xp,hook_xp] + steps: + - uses: actions/checkout@v4 + - run: git submodule init py/files/LunaTranslator_qss + - run: git submodule update py/files/LunaTranslator_qss + - uses: actions/download-artifact@v4 + with: + path: build + - run: python .github/scripts/build_lunatranslator.py merge xp + - uses: actions/upload-artifact@v4 + with: + name: LunaTranslator_x86_winxp + path: py/build/LunaTranslator_x86_winxp.zip \ No newline at end of file diff --git a/.gitignore b/.gitignore index f90246b6..d0acfa9a 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,4 @@ cpp/libs/opencv-static/opencv-static.7z cpp/LunaHook/.vscode/settings.json cpp/LunaHook/scripts/YY-Thunks-1.0.7-Binary.zip cpp/libs/YY-Thunks +py/LunaTranslator/.vscode/settings.json diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index ae6bfe04..5cf62d8e 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -34,10 +34,10 @@ target_precompile_headers(pch PUBLIC pch.h) add_subdirectory(exec) add_subdirectory(winsharedutils) -add_subdirectory(hookmagpie) add_subdirectory(shareddllproxy) +if(NOT WINXP) +add_subdirectory(hookmagpie) add_subdirectory(LunaOCR) add_subdirectory(winrtutils) -if(NOT WINXP) add_subdirectory(wcocr) endif() \ No newline at end of file diff --git a/cpp/LunaOCR/OCR.cpp b/cpp/LunaOCR/OCR.cpp index 4bcc5d62..04aa7aed 100644 --- a/cpp/LunaOCR/OCR.cpp +++ b/cpp/LunaOCR/OCR.cpp @@ -1,12 +1,3 @@ - -enum class Directional -{ - H, - V, - Auto -}; - -#ifndef WINXP #include #include #include @@ -15,6 +6,13 @@ enum class Directional typedef std::vector TextBox; typedef std::string TextLine; typedef std::pair TextBlock; +enum class Directional +{ + H, + V, + Auto +}; + struct ScaleParam { int srcWidth; @@ -705,16 +703,13 @@ std::vector OcrLite::detect_internal(cv::Mat &src, cv::Rect &originRe return textBlocks; } -#else -struct OcrLite; -#endif + struct ocrpoints { int x1, y1, x2, y2, x3, y3, x4, y4; }; DECLARE_API OcrLite *OcrInit(const wchar_t *szDetModel, const wchar_t *szRecModel, const wchar_t *szKeyPath, int nThreads) { -#ifndef WINXP OcrLite *pOcrObj = nullptr; try { @@ -731,14 +726,10 @@ DECLARE_API OcrLite *OcrInit(const wchar_t *szDetModel, const wchar_t *szRecMode { return nullptr; } -#else - return nullptr; -#endif } DECLARE_API void OcrDetect(OcrLite *pOcrObj, const void *binptr, size_t size, Directional mode, void (*cb)(ocrpoints, const char *)) { -#ifndef WINXP if (!pOcrObj) return; @@ -758,13 +749,10 @@ DECLARE_API void OcrDetect(OcrLite *pOcrObj, const void *binptr, size_t size, Di catch (...) { } -#endif } DECLARE_API void OcrDestroy(OcrLite *pOcrObj) { -#ifndef WINXP if (pOcrObj) delete pOcrObj; -#endif } \ No newline at end of file diff --git a/cpp/exec/PyStand.cpp b/cpp/exec/PyStand.cpp index 79f7d979..eccd869f 100644 --- a/cpp/exec/PyStand.cpp +++ b/cpp/exec/PyStand.cpp @@ -74,7 +74,7 @@ bool PyStand::CheckEnviron(const wchar_t *rtp) MessageBoxW(NULL, msg.c_str(), L"ERROR", MB_OK); return false; } - +#ifndef WINXP // check python3.dll if (!PathFileExistsW((_runtime + L"\\python3.dll").c_str())) { @@ -82,7 +82,14 @@ bool PyStand::CheckEnviron(const wchar_t *rtp) MessageBoxW(NULL, msg.c_str(), L"ERROR", MB_OK); return false; } - +#else + if (!PathFileExistsW((_runtime + L"\\python34.dll").c_str())) + { + std::wstring msg = L"Missing python34.dll in:\r\n" + _runtime; + MessageBoxW(NULL, msg.c_str(), L"ERROR", MB_OK); + return false; + } +#endif // setup environment SetEnvironmentVariableW(L"PYSTAND", _pystand.c_str()); SetEnvironmentVariableW(L"PYSTAND_HOME", _home.c_str()); @@ -117,7 +124,11 @@ bool PyStand::LoadPython() // python dll must be load under "runtime" SetCurrentDirectoryW(runtime.c_str()); // LoadLibrary +#ifndef WINXP _hDLL = (HINSTANCE)LoadLibraryA("python3.dll"); +#else + _hDLL = (HINSTANCE)LoadLibraryA("python34.dll"); +#endif if (_hDLL) { _Py_Main = (t_Py_Main)GetProcAddress(_hDLL, "Py_Main"); diff --git a/cpp/winrtutils/CMakeLists.txt b/cpp/winrtutils/CMakeLists.txt index 081fd371..123ff2cf 100644 --- a/cpp/winrtutils/CMakeLists.txt +++ b/cpp/winrtutils/CMakeLists.txt @@ -12,9 +12,7 @@ generate_product_version( add_library(winrtutils MODULE winrtsnapshot.cpp winrtocr.cpp livecaptions.cpp ${versioninfo}) target_precompile_headers(winrtutils REUSE_FROM pch) -if(NOT WINXP) target_link_libraries(winrtutils wil) -endif() if(${CMAKE_SIZEOF_VOID_P} EQUAL 8) set_target_properties(winrtutils PROPERTIES OUTPUT_NAME "winrtutils64") else() diff --git a/cpp/winrtutils/livecaptions.cpp b/cpp/winrtutils/livecaptions.cpp index 6b412771..16972646 100644 --- a/cpp/winrtutils/livecaptions.cpp +++ b/cpp/winrtutils/livecaptions.cpp @@ -1,4 +1,3 @@ -#ifndef WINXP // https://github.com/corbamico/get-livecaptions-cpp/ #include #include @@ -61,10 +60,8 @@ public: return FindWindowW(L"LiveCaptionsDesktopWindow", nullptr) != NULL; } }; -#endif DECLARE_API HANDLE livecaption_start(void (*cb)(const wchar_t *)) { -#ifndef WINXP auto mutex = CreateSemaphoreW(NULL, 0, 1, NULL); auto flag = new int{1}; std::thread([=]() @@ -93,21 +90,13 @@ DECLARE_API HANDLE livecaption_start(void (*cb)(const wchar_t *)) delete flag; }) .detach(); return mutex; -#else - return NULL; -#endif } + DECLARE_API void livecaption_stop(HANDLE m) { -#ifndef WINXP ReleaseSemaphore(m, 1, NULL); -#endif } DECLARE_API bool livecaption_isrunning() { -#ifndef WINXP return Engine::is_livecaption_running(); -#else - return false; -#endif } \ No newline at end of file diff --git a/cpp/winrtutils/winrtocr.cpp b/cpp/winrtutils/winrtocr.cpp index 55eacf5a..956507dd 100644 --- a/cpp/winrtutils/winrtocr.cpp +++ b/cpp/winrtutils/winrtocr.cpp @@ -1,5 +1,3 @@ - -#ifndef WINXP #include #include #include @@ -27,10 +25,8 @@ using namespace Windows::Media::Devices; using namespace Windows::Security::Cryptography; using namespace Windows::Globalization; using namespace Windows::Foundation::Collections; -#endif DECLARE_API bool check_language_valid(wchar_t *language) { -#ifndef WINXP OcrEngine ocrEngine = OcrEngine::TryCreateFromUserProfileLanguages(); std::wstring l = language; try @@ -42,13 +38,9 @@ DECLARE_API bool check_language_valid(wchar_t *language) { return false; } -#else - return false; -#endif } DECLARE_API void getlanguagelist(void (*cb)(LPCWSTR)) { -#ifndef WINXP OcrEngine ocrEngine = OcrEngine::TryCreateFromUserProfileLanguages(); auto languages = ocrEngine.AvailableRecognizerLanguages(); @@ -57,11 +49,9 @@ DECLARE_API void getlanguagelist(void (*cb)(LPCWSTR)) auto lang = language.LanguageTag(); cb(lang.c_str()); } -#endif } DECLARE_API void OCR(void *ptr, size_t size, wchar_t *lang, wchar_t *space, void (*cb)(int, int, int, int, LPCWSTR)) { -#ifndef WINXP IBuffer buffer = CryptographicBuffer::CreateFromByteArray( winrt::array_view(static_cast(ptr), size)); InMemoryRandomAccessStream memoryStream; @@ -94,5 +84,4 @@ DECLARE_API void OCR(void *ptr, size_t size, wchar_t *lang, wchar_t *space, void } cb(x1, y1, x2, y2, xx.c_str()); } -#endif } diff --git a/cpp/winrtutils/winrtsnapshot.cpp b/cpp/winrtutils/winrtsnapshot.cpp index 00d18fec..98aa9759 100644 --- a/cpp/winrtutils/winrtsnapshot.cpp +++ b/cpp/winrtutils/winrtsnapshot.cpp @@ -1,6 +1,4 @@ - -#ifndef WINXP -#include +#include #include #include #include @@ -205,10 +203,8 @@ void capture_window(HWND window_handle, void (*cb)(byte *, size_t)) memcpy(ptr, p_buf.get(), l_bmp_info.bmiHeader.biSizeImage); cb(p_buf2.get(), bmfh.bfSize); } -#endif DECLARE_API void winrt_capture_window(HWND hwnd, void (*cb)(byte *, size_t)) { -#ifndef WINXP // auto hwnd = GetForegroundWindow();// FindWindow(L"Window_Magpie_967EB565-6F73-4E94-AE53-00CC42592A22", 0); auto style_ex = GetWindowLong(hwnd, GWL_EXSTYLE); auto style_ex_save = style_ex; @@ -224,5 +220,4 @@ DECLARE_API void winrt_capture_window(HWND hwnd, void (*cb)(byte *, size_t)) capture_window(hwnd, cb); if (needset) SetWindowLong(hwnd, GWL_EXSTYLE, style_ex_save); -#endif }