From d0afc5162116f874b32912cbd6e3d98f133122d2 Mon Sep 17 00:00:00 2001 From: Don HO Date: Thu, 22 Apr 2021 05:20:54 +0200 Subject: [PATCH] Add ARM64 support for auto-update feature --- .../MISC/PluginsManager/PluginsManager.cpp | 30 +++++++------------ PowerEditor/src/NppCommands.cpp | 8 +++-- PowerEditor/src/Parameters.h | 16 ++++++++-- .../src/WinControls/AboutDlg/AboutDlg.cpp | 4 +-- PowerEditor/src/winmain.cpp | 12 ++++++-- 5 files changed, 42 insertions(+), 28 deletions(-) diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp index d95f0b32f..0041b70cd 100644 --- a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp @@ -28,24 +28,6 @@ const TCHAR * USERMSG = TEXT(" is not compatible with the current version of Not Do you want to remove this plugin from the plugins directory to prevent this message from the next launch?"); -#ifdef _WIN64 - -#ifdef _M_ARM64 -#define ARCH_TYPE IMAGE_FILE_MACHINE_ARM64 -const TCHAR *ARCH_ERR_MSG = TEXT("Cannot load 32-bit or non-ARM64 plugin."); -#else -#define ARCH_TYPE IMAGE_FILE_MACHINE_AMD64 -const TCHAR *ARCH_ERR_MSG = TEXT("Cannot load 32-bit plugin."); -#endif - -#else -#define ARCH_TYPE IMAGE_FILE_MACHINE_I386 -const TCHAR *ARCH_ERR_MSG = TEXT("Cannot load 64-bit plugin."); -#endif - - - - bool PluginsManager::unloadPlugin(int index, HWND nppHandle) { SCNotification scnN; @@ -128,9 +110,17 @@ int PluginsManager::loadPlugin(const TCHAR *pluginFilePath) try { pi->_moduleName = pluginFileName; + int archType = nppParams.archType(); + if (getBinaryArchitectureType(pluginFilePath) != archType) + { + const TCHAR *archErrMsg = TEXT("Cannot load 64-bit plugin."); // IMAGE_FILE_MACHINE_I386 by default + if (archType == IMAGE_FILE_MACHINE_ARM64) + archErrMsg = TEXT("Cannot load 32-bit or non-ARM64 plugin."); + else if(archType == IMAGE_FILE_MACHINE_AMD64) + archErrMsg = TEXT("Cannot load 32-bit plugin."); - if (getBinaryArchitectureType(pluginFilePath) != ARCH_TYPE) - throw generic_string(ARCH_ERR_MSG); + throw generic_string(archErrMsg); + } const DWORD dwFlags = GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "AddDllDirectory") != NULL ? LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS : 0; pi->_hLib = ::LoadLibraryEx(pluginFilePath, NULL, dwFlags); diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 3a085241c..876f5cb2d 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -3153,11 +3153,15 @@ void Notepad_plus::command(int id) { param = TEXT("-verbose -v"); param += VERSION_VALUE; - - if (NppParameters::getInstance().isx64()) + int archType = NppParameters::getInstance().archType(); + if (archType == IMAGE_FILE_MACHINE_AMD64) { param += TEXT(" -px64"); } + else if (archType == IMAGE_FILE_MACHINE_ARM64) + { + param += TEXT(" -parm64"); + } } Process updater(updaterFullPath.c_str(), param.c_str(), updaterDir.c_str()); diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 84bab3d44..a283c5148 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -29,6 +29,19 @@ #include #include +#ifdef _WIN64 + +#ifdef _M_ARM64 +#define ARCH_TYPE IMAGE_FILE_MACHINE_ARM64 +#else +#define ARCH_TYPE IMAGE_FILE_MACHINE_AMD64 +#endif + +#else +#define ARCH_TYPE IMAGE_FILE_MACHINE_I386 + +#endif + class NativeLangSpeaker; const bool POS_VERTICAL = true; @@ -1670,8 +1683,7 @@ public: void setCloudChoice(const TCHAR *pathChoice); void removeCloudChoice(); bool isCloudPathChanged() const; - bool isx64() const { return _isx64; }; - + int archType() const { return ARCH_TYPE; }; COLORREF getCurrentDefaultBgColor() const { return _currentDefaultBgColor; } diff --git a/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp index d2d9a5c92..55b6c8a98 100644 --- a/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp +++ b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp @@ -40,7 +40,7 @@ INT_PTR CALLBACK AboutDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPara buildTime += wmc.char2wchar(__TIME__, CP_ACP); NppParameters& nppParam = NppParameters::getInstance(); - LPCTSTR bitness = nppParam.isx64() ? TEXT("(64-bit)") : TEXT("(32-bit)"); + LPCTSTR bitness = nppParam.archType() == IMAGE_FILE_MACHINE_I386 ? TEXT("(32-bit)") : (nppParam.archType() == IMAGE_FILE_MACHINE_AMD64 ? TEXT("(64-bit)") : TEXT("(ARM 64-bit)")); ::SetDlgItemText(_hSelf, IDC_VERSION_BIT, bitness); ::SendMessage(compileDateHandle, WM_SETTEXT, 0, reinterpret_cast(buildTime.c_str())); @@ -123,7 +123,7 @@ INT_PTR CALLBACK DebugInfoDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM / // Notepad++ version _debugInfoStr = NOTEPAD_PLUS_VERSION; - _debugInfoStr += nppParam.isx64() ? TEXT(" (64-bit)") : TEXT(" (32-bit)"); + _debugInfoStr += nppParam.archType() == IMAGE_FILE_MACHINE_I386 ? TEXT(" (32-bit)") : (nppParam.archType() == IMAGE_FILE_MACHINE_AMD64 ? TEXT(" (64-bit)") : TEXT(" (ARM 64-bit)")); _debugInfoStr += TEXT("\r\n"); // Build time diff --git a/PowerEditor/src/winmain.cpp b/PowerEditor/src/winmain.cpp index 4881058df..b054df073 100644 --- a/PowerEditor/src/winmain.cpp +++ b/PowerEditor/src/winmain.cpp @@ -625,10 +625,14 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int) if (TheFirstOne && isUpExist && isGtXP && isSignatureOK) { - if (nppParameters.isx64()) + if (nppParameters.archType() == IMAGE_FILE_MACHINE_AMD64) { updaterParams += TEXT(" -px64"); } + else if (nppParameters.archType() == IMAGE_FILE_MACHINE_ARM64) + { + updaterParams += TEXT(" -parm64"); + } if (doUpdateNpp) { @@ -650,10 +654,14 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int) generic_string upPlParams = TEXT("-v"); upPlParams += notepad_plus_plus.getPluginListVerStr(); - if (nppParameters.isx64()) + if (nppParameters.archType() == IMAGE_FILE_MACHINE_AMD64) { upPlParams += TEXT(" -px64"); } + else if (nppParameters.archType() == IMAGE_FILE_MACHINE_ARM64) + { + upPlParams += TEXT(" -parm64"); + } upPlParams += TEXT(" -upZip");