Add ARM64 support for auto-update feature

This commit is contained in:
Don HO 2021-04-22 05:20:54 +02:00
parent f6856626e0
commit d0afc51621
5 changed files with 42 additions and 28 deletions

View File

@ -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?"); 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) bool PluginsManager::unloadPlugin(int index, HWND nppHandle)
{ {
SCNotification scnN; SCNotification scnN;
@ -128,9 +110,17 @@ int PluginsManager::loadPlugin(const TCHAR *pluginFilePath)
try try
{ {
pi->_moduleName = pluginFileName; 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(archErrMsg);
throw generic_string(ARCH_ERR_MSG); }
const DWORD dwFlags = GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "AddDllDirectory") != NULL ? LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS : 0; 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); pi->_hLib = ::LoadLibraryEx(pluginFilePath, NULL, dwFlags);

View File

@ -3153,11 +3153,15 @@ void Notepad_plus::command(int id)
{ {
param = TEXT("-verbose -v"); param = TEXT("-verbose -v");
param += VERSION_VALUE; param += VERSION_VALUE;
int archType = NppParameters::getInstance().archType();
if (NppParameters::getInstance().isx64()) if (archType == IMAGE_FILE_MACHINE_AMD64)
{ {
param += TEXT(" -px64"); param += TEXT(" -px64");
} }
else if (archType == IMAGE_FILE_MACHINE_ARM64)
{
param += TEXT(" -parm64");
}
} }
Process updater(updaterFullPath.c_str(), param.c_str(), updaterDir.c_str()); Process updater(updaterFullPath.c_str(), param.c_str(), updaterDir.c_str());

View File

@ -29,6 +29,19 @@
#include <assert.h> #include <assert.h>
#include <tchar.h> #include <tchar.h>
#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; class NativeLangSpeaker;
const bool POS_VERTICAL = true; const bool POS_VERTICAL = true;
@ -1670,8 +1683,7 @@ public:
void setCloudChoice(const TCHAR *pathChoice); void setCloudChoice(const TCHAR *pathChoice);
void removeCloudChoice(); void removeCloudChoice();
bool isCloudPathChanged() const; bool isCloudPathChanged() const;
bool isx64() const { return _isx64; }; int archType() const { return ARCH_TYPE; };
COLORREF getCurrentDefaultBgColor() const { COLORREF getCurrentDefaultBgColor() const {
return _currentDefaultBgColor; return _currentDefaultBgColor;
} }

View File

@ -40,7 +40,7 @@ INT_PTR CALLBACK AboutDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPara
buildTime += wmc.char2wchar(__TIME__, CP_ACP); buildTime += wmc.char2wchar(__TIME__, CP_ACP);
NppParameters& nppParam = NppParameters::getInstance(); 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); ::SetDlgItemText(_hSelf, IDC_VERSION_BIT, bitness);
::SendMessage(compileDateHandle, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(buildTime.c_str())); ::SendMessage(compileDateHandle, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(buildTime.c_str()));
@ -123,7 +123,7 @@ INT_PTR CALLBACK DebugInfoDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM /
// Notepad++ version // Notepad++ version
_debugInfoStr = NOTEPAD_PLUS_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"); _debugInfoStr += TEXT("\r\n");
// Build time // Build time

View File

@ -625,10 +625,14 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int)
if (TheFirstOne && isUpExist && isGtXP && isSignatureOK) if (TheFirstOne && isUpExist && isGtXP && isSignatureOK)
{ {
if (nppParameters.isx64()) if (nppParameters.archType() == IMAGE_FILE_MACHINE_AMD64)
{ {
updaterParams += TEXT(" -px64"); updaterParams += TEXT(" -px64");
} }
else if (nppParameters.archType() == IMAGE_FILE_MACHINE_ARM64)
{
updaterParams += TEXT(" -parm64");
}
if (doUpdateNpp) if (doUpdateNpp)
{ {
@ -650,10 +654,14 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int)
generic_string upPlParams = TEXT("-v"); generic_string upPlParams = TEXT("-v");
upPlParams += notepad_plus_plus.getPluginListVerStr(); upPlParams += notepad_plus_plus.getPluginListVerStr();
if (nppParameters.isx64()) if (nppParameters.archType() == IMAGE_FILE_MACHINE_AMD64)
{ {
upPlParams += TEXT(" -px64"); upPlParams += TEXT(" -px64");
} }
else if (nppParameters.archType() == IMAGE_FILE_MACHINE_ARM64)
{
upPlParams += TEXT(" -parm64");
}
upPlParams += TEXT(" -upZip"); upPlParams += TEXT(" -upZip");