Skip to content

Commit

Permalink
Check for the path existence.
Browse files Browse the repository at this point in the history
  • Loading branch information
lygstate committed May 16, 2014
1 parent fc105e3 commit 8a55960
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NotepadReplacer.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
cd /d %~dps0
set WD=%CD%
echo %WD%
if not exist "%WD%\notepad++.exe" ( goto NoNotepadPlusPlus )

:: --> Check for permissions
net session >nul 2>&1
Expand Down Expand Up @@ -46,4 +47,5 @@ reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Executi
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe" /f /v "Notepad++" /t REG_SZ /d "%WD%"
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe" /f /v "readme" /t REG_SZ /d "call NotepadStarter.exe instead of original notepad.exe! To disable this option just remove notepad.exe entry"

:NoNotepadPlusPlus
::pause
6 changes: 5 additions & 1 deletion NotepadStarter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ wstring GetParentDir(std::wstring p) {

bool LaunchProcess(STARTUPINFO& si, PROCESS_INFORMATION& oProcessInfo, std::wstring cmd, bool wait);

bool ExistPath(wstring const& p) {
return PathFileExistsW(p.c_str()) == TRUE;
}

std::wstring QueryNotepadCommand() {
HKEY hKey;
LSTATUS errorCode = RegOpenKeyExW(
Expand All @@ -324,7 +328,7 @@ std::wstring QueryNotepadCommand() {
NotepadStarter = FullPath(NotepadStarter);
RegCloseKey(hKey);
}
if (!hasNpp) {
if (!hasNpp || !ExistPath(NotepadPlusPlusFolder + L"\\notepad++.exe")) {
std::wstring NotepadStarterCurrent = GetThisExecutable();
NotepadPlusPlusFolder = GetParentDir(NotepadStarterCurrent);
if (NotepadStarter != NotepadStarterCurrent) {
Expand Down
2 changes: 2 additions & 0 deletions NotepadStarterInstall.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
cd /d %~dps0
set WD=%CD%
echo %WD%
if not exist "%WD%\notepad++.exe" ( goto NoNotepadPlusPlus )

:: --> Check for permissions
net session >nul 2>&1
Expand All @@ -19,4 +20,5 @@ reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Executi
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe" /f /v "Debugger" /t REG_SZ /d "%WD%\NotepadStarter.exe"
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe" /f /v "readme" /t REG_SZ /d "call NotepadStarter.exe instead of original notepad.exe! To disable this option just remove notepad.exe entry"

:NoNotepadPlusPlus
::pause

0 comments on commit 8a55960

Please sign in to comment.