diff --git a/plugin/NotepadStarterPlugin.cpp b/plugin/NotepadStarterPlugin.cpp index b9e2864..962c87d 100644 --- a/plugin/NotepadStarterPlugin.cpp +++ b/plugin/NotepadStarterPlugin.cpp @@ -116,6 +116,22 @@ void TryInstallNotepadStarter() { NotepadPlusPlusExecutable = FullPath(NotepadPlusPlusExecutable); RegCloseKey(hKey); } + + std::wstring NotepadPlusPlusDir = L""; + bool hasNppDir = false; + errorCode = RegOpenKeyExW( + HKEY_LOCAL_MACHINE, + L"SOFTWARE\\Notepad++", + 0, + KEY_READ, + &hKey); + if (errorCode == ERROR_SUCCESS) + { + hasNppDir = QueryRegistryString(hKey, L"", NotepadPlusPlusDir); + NotepadPlusPlusDir = FullPath(NotepadPlusPlusDir); + RegCloseKey(hKey); + } + if (!hasNpp || !ExistPath(NotepadPlusPlusExecutable) || NotepadPlusPlusSelf != NotepadPlusPlusExecutable) { #if 0 int ret = MessageBoxW( @@ -130,6 +146,9 @@ void TryInstallNotepadStarter() { int ret = IDYES; #endif std::wstring installScript = GetParentDir(NotepadPlusPlusSelf) + L"\\plugins\\NotepadStarter\\NotepadStarter.exe"; + if (!ExistPath(installScript) && hasNppDir && ExistPath(NotepadPlusPlusDir)) { + installScript = GetEnvironmentVariableValue(L"AppData") + L"\\notepad++\\plugins\\NotepadStarter\\NotepadStarter.exe"; + } switch (ret) { default: case IDCANCEL: diff --git a/starter/NotepadStarterInstall.bat b/starter/NotepadStarterInstall.bat index 0680397..ac146f4 100644 --- a/starter/NotepadStarterInstall.bat +++ b/starter/NotepadStarterInstall.bat @@ -7,6 +7,22 @@ set UseImageFileExecution="UseImageFileExecution" cd /d %~dps0..\.. set "NotepadPlusPlus=%CD%\notepad++.exe" + +set "NotepadPlusPlusDir=" +for /f "tokens=2,*" %%a in ('reg query HKEY_LOCAL_MACHINE\SOFTWARE\Notepad++ /ve 2^>NUL') do set "NotepadPlusPlusDir=%%b" + +if exist "%NotepadPlusPlusDir%" goto find_notepad_dir + +for /f "tokens=2,*" %%a in ('reg query HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Notepad++ /ve 2^>NUL') do set "NotepadPlusPlusDir=%%b" + +:find_notepad_dir + +if not exist "%NotepadPlusPlus%" ( + if exist "%NotepadPlusPlusDir%" ( + set "NotepadPlusPlus=%NotepadPlusPlusDir%\notepad++.exe" + ) +) + cd /d %~dps0 set "NotepadStarter=%CD%\NotepadStarter.exe" if not exist "%NotepadStarter%" ( goto NoNotepadPlusPlusOrNotepadStarter ) diff --git a/utils/NotepadUtils.cpp b/utils/NotepadUtils.cpp index 3fa31b6..e93c908 100644 --- a/utils/NotepadUtils.cpp +++ b/utils/NotepadUtils.cpp @@ -163,3 +163,13 @@ bool LaunchProcess(STARTUPINFO& si, PROCESS_INFORMATION& oProcessInfo, std::wstr } return true; } + +std::wstring GetEnvironmentVariableValue(const std::wstring& name) +{ + DWORD bufferSize = 65535; //Limit according to http://msdn.microsoft.com/en-us/library/ms683188.aspx + std::wstring buff; + buff.resize(bufferSize); + bufferSize = GetEnvironmentVariableW(name.c_str(), &buff[0], bufferSize); + buff.resize(bufferSize); + return std::move(buff); +} \ No newline at end of file diff --git a/utils/NotepadUtils.h b/utils/NotepadUtils.h index 5f41e85..9d6cc2f 100644 --- a/utils/NotepadUtils.h +++ b/utils/NotepadUtils.h @@ -27,4 +27,5 @@ wstring GetParentDir(std::wstring p); bool ExistPath(wstring const& p); std::wstring QueryErrorString(DWORD dw); HANDLE FoundProcessHandle(std::wstring const & processExecutable); -bool LaunchProcess(STARTUPINFO& si, PROCESS_INFORMATION& oProcessInfo, std::wstring cmd, bool wait, bool noWindow = false); \ No newline at end of file +bool LaunchProcess(STARTUPINFO& si, PROCESS_INFORMATION& oProcessInfo, std::wstring cmd, bool wait, bool noWindow = false); +std::wstring GetEnvironmentVariableValue(const std::wstring& name);