@@ -182,39 +182,42 @@ void ApplicationList::Clear()
182182 mDefaultApplicationIndex = -1 ;
183183}
184184
185- bool ApplicationList::FindDefaultWindowsEditor ( )
185+ bool ApplicationList::CheckAndAddApplication (QString appPath, QString name, QString parameters )
186186{
187- bool foundOne = false ;
188- const QString appPath (getenv (" ProgramFiles" ));
189- const QString notepadppPath = appPath + " \\ Notepad++\\ notepad++.exe" ;
190- if (QFileInfo (notepadppPath).exists () && QFileInfo (notepadppPath).isExecutable ()) {
187+ if (QFileInfo (appPath).exists () && QFileInfo (appPath).isExecutable ()) {
191188 Application app;
192- app.setName (" Notepad++ " );
193- app.setPath (" \" " + notepadppPath + " \" " );
194- app.setParameters (" -n(line) (file) " );
189+ app.setName (name );
190+ app.setPath (" \" " + appPath + " \" " );
191+ app.setParameters (parameters );
195192 AddApplication (app);
196- foundOne = true ;
193+ return true ;
197194 }
195+ return false ;
196+ }
198197
199- const QString notepadTwoPath = appPath + " \\ Notepad2\\ Notepad2.exe" ;
200- if (QFileInfo (notepadTwoPath).exists () && QFileInfo (notepadTwoPath).isExecutable ()) {
201- Application app;
202- app.setName (" Notepad2" );
203- app.setPath (" \" " + notepadTwoPath + " \" " );
204- app.setParameters (" /g (line) (file)" );
205- AddApplication (app);
198+ bool ApplicationList::FindDefaultWindowsEditor ()
199+ {
200+ bool foundOne = false ;
201+ #ifdef WIN64 // As long as we do support 32-bit XP, we cannot be sure that the environment variable "ProgramFiles(x86)" exists
202+ const QString appPathx86 (getenv (" ProgramFiles(x86)" ));
203+ #else
204+ const QString appPathx86 (getenv (" ProgramFiles" ));
205+ #endif
206+ const QString appPathx64 (getenv (" ProgramW6432" ));
207+ const QString windowsPath (getenv (" windir" ));
208+
209+ if (CheckAndAddApplication (appPathx86 + " \\ Notepad++\\ notepad++.exe" , " Notepad++" , " -n(line) (file)" ))
210+ foundOne = true ;
211+ else if (CheckAndAddApplication (appPathx64 + " \\ Notepad++\\ notepad++.exe" , " Notepad++" , " -n(line) (file)" ))
206212 foundOne = true ;
207- }
208213
209- const QString windowsPath (getenv (" windir" ));
210- const QString notepadPath = windowsPath + " \\ system32\\ notepad.exe" ;
211- if (QFileInfo (notepadPath).exists () && QFileInfo (notepadPath).isExecutable ()) {
212- Application app;
213- app.setName (" Notepad" );
214- app.setPath (notepadPath);
215- app.setParameters (" (file)" );
216- AddApplication (app);
214+ if (CheckAndAddApplication (appPathx86 + " \\ Notepad2\\ Notepad2.exe" , " Notepad2" , " /g (line) (file)" ))
217215 foundOne = true ;
218- }
216+ else if (CheckAndAddApplication (appPathx64 + " \\ Notepad2\\ Notepad2.exe" , " Notepad2" , " /g (line) (file)" ))
217+ foundOne = true ;
218+
219+ if (CheckAndAddApplication (windowsPath + " \\ system32\\ notepad.exe" , " Notepad" , " (file)" ))
220+ foundOne = true ;
221+
219222 return foundOne;
220223}
0 commit comments