From f10c785d97503347614d44771287fe2dc186a54d 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, 3 May 2024 20:24:17 +0800 Subject: [PATCH] fix --- .../LunaTranslator/LunaTranslator_main.py | 14 +++++++---- LunaTranslator/LunaTranslator/windows.py | 23 ++++++++++++++++++- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/LunaTranslator/LunaTranslator/LunaTranslator_main.py b/LunaTranslator/LunaTranslator/LunaTranslator_main.py index 0ce28aaa..d7823e41 100644 --- a/LunaTranslator/LunaTranslator/LunaTranslator_main.py +++ b/LunaTranslator/LunaTranslator/LunaTranslator_main.py @@ -1,12 +1,13 @@ -import sys -from PyQt5.QtCore import Qt -from PyQt5.QtWidgets import QApplication -from PyQt5.QtGui import QFont +import sys, windows import platform, os if __name__ == "__main__": dirname = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) os.chdir(dirname) + windows.addenvpath("./LunaTranslator/runtime/") # win7 no vcredist2015 + windows.loadlibrary( + "./LunaTranslator/runtime/PyQt5/Qt5/bin/Qt5Core.dll" + ) # win7 no vcredist2015 for p in ( "./userconfig/memory", "./userconfig/memory", @@ -36,6 +37,11 @@ if __name__ == "__main__": import gobject gobject.overridepathexists() + + from PyQt5.QtCore import Qt + from PyQt5.QtWidgets import QApplication + from PyQt5.QtGui import QFont + QApplication.addLibraryPath( "./LunaTranslator/runtime/PyQt5/Qt5/plugins" ) # 中文字符下不能自动加载 diff --git a/LunaTranslator/LunaTranslator/windows.py b/LunaTranslator/LunaTranslator/windows.py index 77fee1e7..1dfc673a 100644 --- a/LunaTranslator/LunaTranslator/windows.py +++ b/LunaTranslator/LunaTranslator/windows.py @@ -25,7 +25,7 @@ from ctypes import ( sizeof, byref, ) -import ctypes +import ctypes, os from traceback import print_exc from ctypes.wintypes import ( RECT, @@ -949,3 +949,24 @@ _SetPropW.restype = BOOL def SetProp(hwnd, string, hdata): return _SetPropW(hwnd, string, hdata) + + +_GetEnvironmentVariableW = _kernel32.GetEnvironmentVariableW +_GetEnvironmentVariableW.argtypes = c_wchar_p, c_wchar_p, DWORD +_SetEnvironmentVariableW = _kernel32.SetEnvironmentVariableW +_SetEnvironmentVariableW.argtypes = LPCWSTR, LPCWSTR + + +def addenvpath(path): + path = os.path.abspath(path) + env = create_unicode_buffer(65535) + _GetEnvironmentVariableW("PATH", env, 65535) + _SetEnvironmentVariableW("PATH", env.value + ";" + path) + + +_LoadLibraryW = _kernel32.LoadLibraryW +_LoadLibraryW.argtypes = (LPCWSTR,) + + +def loadlibrary(path): + _LoadLibraryW(path)