Skip to content

Commit

Permalink
Getting NotepadStarter works with installed notepad++
Browse files Browse the repository at this point in the history
  • Loading branch information
lygstate committed Mar 15, 2015
1 parent 8714b34 commit 57be3af
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
19 changes: 19 additions & 0 deletions plugin/NotepadStarterPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions starter/NotepadStarterInstall.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
10 changes: 10 additions & 0 deletions utils/NotepadUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
3 changes: 2 additions & 1 deletion utils/NotepadUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
bool LaunchProcess(STARTUPINFO& si, PROCESS_INFORMATION& oProcessInfo, std::wstring cmd, bool wait, bool noWindow = false);
std::wstring GetEnvironmentVariableValue(const std::wstring& name);

0 comments on commit 57be3af

Please sign in to comment.