From 65e85385901cdfb22fa910c9260b38767d999bd7 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 18 Nov 2015 17:34:29 +0100 Subject: [PATCH] GUI: Attempt to fix editor detection for x64 Windows --- gui/applicationlist.cpp | 61 +++++++++++++++++++++-------------------- gui/applicationlist.h | 2 ++ 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/gui/applicationlist.cpp b/gui/applicationlist.cpp index 0cc2c6af0..3dd89e34d 100644 --- a/gui/applicationlist.cpp +++ b/gui/applicationlist.cpp @@ -182,39 +182,42 @@ void ApplicationList::Clear() mDefaultApplicationIndex = -1; } +bool ApplicationList::CheckAndAddApplication(QString appPath, QString name, QString parameters) +{ + if (QFileInfo(appPath).exists() && QFileInfo(appPath).isExecutable()) { + Application app; + app.setName(name); + app.setPath("\"" + appPath + "\""); + app.setParameters(parameters); + AddApplication(app); + return true; + } + return false; +} + bool ApplicationList::FindDefaultWindowsEditor() { bool foundOne = false; - const QString appPath(getenv("ProgramFiles")); - const QString notepadppPath = appPath + "\\Notepad++\\notepad++.exe"; - if (QFileInfo(notepadppPath).exists() && QFileInfo(notepadppPath).isExecutable()) { - Application app; - app.setName("Notepad++"); - app.setPath("\"" + notepadppPath + "\""); - app.setParameters("-n(line) (file)"); - AddApplication(app); - foundOne = true; - } - - const QString notepadTwoPath = appPath + "\\Notepad2\\Notepad2.exe"; - if (QFileInfo(notepadTwoPath).exists() && QFileInfo(notepadTwoPath).isExecutable()) { - Application app; - app.setName("Notepad2"); - app.setPath("\"" + notepadTwoPath + "\""); - app.setParameters("/g (line) (file)"); - AddApplication(app); - foundOne = true; - } - +#ifdef WIN64 // As long as we do support 32-bit XP, we cannot be sure that the environment variable "ProgramFiles(x86)" exists + const QString appPathx86(getenv("ProgramFiles(x86)")); +#else + const QString appPathx86(getenv("ProgramFiles")); +#endif + const QString appPathx64(getenv("ProgramW6432")); const QString windowsPath(getenv("windir")); - const QString notepadPath = windowsPath + "\\system32\\notepad.exe"; - if (QFileInfo(notepadPath).exists() && QFileInfo(notepadPath).isExecutable()) { - Application app; - app.setName("Notepad"); - app.setPath(notepadPath); - app.setParameters("(file)"); - AddApplication(app); + + if (CheckAndAddApplication(appPathx86 + "\\Notepad++\\notepad++.exe", "Notepad++", "-n(line) (file)")) foundOne = true; - } + else if (CheckAndAddApplication(appPathx64 + "\\Notepad++\\notepad++.exe", "Notepad++", "-n(line) (file)")) + foundOne = true; + + if (CheckAndAddApplication(appPathx86 + "\\Notepad2\\Notepad2.exe", "Notepad2", "/g (line) (file)")) + foundOne = true; + else if (CheckAndAddApplication(appPathx64 + "\\Notepad2\\Notepad2.exe", "Notepad2", "/g (line) (file)")) + foundOne = true; + + if (CheckAndAddApplication(windowsPath + "\\system32\\notepad.exe", "Notepad", "(file)")) + foundOne = true; + return foundOne; } diff --git a/gui/applicationlist.h b/gui/applicationlist.h index 7e0f50b2a..7aba6aacc 100644 --- a/gui/applicationlist.h +++ b/gui/applicationlist.h @@ -116,6 +116,8 @@ protected: private: + bool CheckAndAddApplication(QString appPath, QString name, QString parameters); + /** * @brief List of applications *