From b7bf392e7bc4009d55e7c78384ac71c4d67a4ada 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: Thu, 4 Apr 2024 00:41:44 +0800 Subject: [PATCH] magpie config Update fullscreen.py --- .../LunaTranslator/myutils/fullscreen.py | 24 +++++++++-- .../LunaTranslator/winsharedutils.py | 23 ++++++++++ plugins/winsharedutils/CMakeLists.txt | 2 +- plugins/winsharedutils/define.h | 1 + plugins/winsharedutils/version.cpp | 42 +++++++++++++++++++ 5 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 plugins/winsharedutils/version.cpp diff --git a/LunaTranslator/LunaTranslator/myutils/fullscreen.py b/LunaTranslator/LunaTranslator/myutils/fullscreen.py index e053ea3e..041f836c 100644 --- a/LunaTranslator/LunaTranslator/myutils/fullscreen.py +++ b/LunaTranslator/LunaTranslator/myutils/fullscreen.py @@ -1,5 +1,5 @@ import os, json -import windows +import windows, winsharedutils from myutils.config import globalconfig, magpie10_config from myutils.hwnd import letfullscreen, recoverwindow, ListProcess, injectdll from traceback import print_exc @@ -123,12 +123,30 @@ class fullscreen: def _external_magpie10(self, hwnd, full): configpath = os.path.join(globalconfig["magpie10path"], "config/config.json") + if os.path.exists(configpath) == False: - configpath = os.path.join( - os.environ["LOCALAPPDATA"], "Magpie/config/config.json" + version = winsharedutils.queryversion( + os.path.join(globalconfig["magpie10path"], "Magpie.exe") ) + checks = [ + os.path.join( + os.environ["LOCALAPPDATA"], "Magpie/config/v2/config.json" + ), + os.path.join(os.environ["LOCALAPPDATA"], "Magpie/config/config.json"), + ] + if version: + if version[:3] >= (0, 10, 100): # v0.11.0-preview1 + checks = [checks[0]] + else: + checks = [checks[1]] + for ck in checks: + if os.path.exists(ck): + configpath = ck + break + if os.path.exists(configpath) == False: return + with open(configpath, "r", encoding="utf8") as ff: config = json.load(ff) autoRestore = config["autoRestore"] diff --git a/LunaTranslator/LunaTranslator/winsharedutils.py b/LunaTranslator/LunaTranslator/winsharedutils.py index 7515b6c6..63c206f7 100644 --- a/LunaTranslator/LunaTranslator/winsharedutils.py +++ b/LunaTranslator/LunaTranslator/winsharedutils.py @@ -18,6 +18,7 @@ from ctypes import ( windll, c_char, ) +from ctypes.wintypes import WORD import gobject utilsdll = CDLL(gobject.GetDllpath(("winsharedutils32.dll", "winsharedutils64.dll"))) @@ -286,3 +287,25 @@ class lockedqueue: def empty(self): return lockedqueueempty(self.ptr) + + +_queryversion = utilsdll.queryversion +_queryversion.restype = c_bool +_queryversion.argtypes = ( + c_wchar_p, + POINTER(WORD), + POINTER(WORD), + POINTER(WORD), + POINTER(WORD), +) + + +def queryversion(exe): + _1 = WORD() + _2 = WORD() + _3 = WORD() + _4 = WORD() + succ = _queryversion(exe, pointer(_1), pointer(_2), pointer(_3), pointer(_4)) + if succ: + return _1.value, _2.value, _3.value, _4.value + return None diff --git a/plugins/winsharedutils/CMakeLists.txt b/plugins/winsharedutils/CMakeLists.txt index a132fb2d..13ac89b9 100644 --- a/plugins/winsharedutils/CMakeLists.txt +++ b/plugins/winsharedutils/CMakeLists.txt @@ -2,7 +2,7 @@ project(winsharedutils) -add_library(winsharedutils MODULE otsu.cpp cinterface.cpp clipboard.cpp lnk.cpp dllmain.cpp levenshtein.cpp muteprocess.cpp sapi_dll.cpp simplemecab.cpp SimpleBrowser.cpp MWebBrowser.cpp icon.cpp) +add_library(winsharedutils MODULE version.cpp otsu.cpp cinterface.cpp clipboard.cpp lnk.cpp dllmain.cpp levenshtein.cpp muteprocess.cpp sapi_dll.cpp simplemecab.cpp SimpleBrowser.cpp MWebBrowser.cpp icon.cpp) if(${CMAKE_SIZEOF_VOID_P} EQUAL 8) set_target_properties(winsharedutils PROPERTIES OUTPUT_NAME "winsharedutils64") diff --git a/plugins/winsharedutils/define.h b/plugins/winsharedutils/define.h index 1471dd32..4d1f967a 100644 --- a/plugins/winsharedutils/define.h +++ b/plugins/winsharedutils/define.h @@ -2,6 +2,7 @@ #include extern "C" { + __declspec(dllexport) bool queryversion(const wchar_t *exe, WORD *_1, WORD *_2, WORD *_3, WORD *_4); __declspec(dllexport) bool SAPI_Speak(const wchar_t *Content, int version, int voiceid, int rate, int volume, const wchar_t *Filename); __declspec(dllexport) wchar_t **SAPI_List(int version, size_t *); diff --git a/plugins/winsharedutils/version.cpp b/plugins/winsharedutils/version.cpp new file mode 100644 index 00000000..7519892c --- /dev/null +++ b/plugins/winsharedutils/version.cpp @@ -0,0 +1,42 @@ +#include +#include +#include "define.h" + +#pragma comment(lib, "Version.lib") + +bool queryversion(const wchar_t *exe, WORD *_1, WORD *_2, WORD *_3, WORD *_4) +{ + + DWORD dwHandle; + DWORD dwSize = GetFileVersionInfoSizeW(exe, &dwHandle); + if (dwSize == 0) + { + return false; + } + + std::vector versionInfoBuffer(dwSize); + if (!GetFileVersionInfoW(exe, dwHandle, dwSize, versionInfoBuffer.data())) + { + return false; + } + + VS_FIXEDFILEINFO *pFileInfo; + UINT fileInfoSize; + if (!VerQueryValueW(versionInfoBuffer.data(), L"\\", reinterpret_cast(&pFileInfo), &fileInfoSize)) + { + return false; + } + + DWORD ms = pFileInfo->dwFileVersionMS; + DWORD ls = pFileInfo->dwFileVersionLS; + + WORD majorVersion = HIWORD(ms); + WORD minorVersion = LOWORD(ms); + WORD buildNumber = HIWORD(ls); + WORD revisionNumber = LOWORD(ls); + *_1 = majorVersion; + *_2 = minorVersion; + *_3 = buildNumber; + *_4 = revisionNumber; + return true; +} \ No newline at end of file