Skip to content

Commit

Permalink
msw: attempt to locate MSYS2 installation folder by checking the regi…
Browse files Browse the repository at this point in the history
…ster entries first
  • Loading branch information
eranif committed Jan 6, 2023
1 parent 62cddde commit a1673b7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
39 changes: 33 additions & 6 deletions CodeLite/MSYS2.cpp
Expand Up @@ -2,10 +2,15 @@

#include "cl_standard_paths.h"

#include <functional>
#include <wx/arrstr.h>
#include <wx/stdpaths.h>
#include <wx/tokenzr.h>

#ifdef __WXMSW__
#include <wx/msw/registry.h>
#endif

bool MSYS2::FindInstallDir(wxString* msyspath)
{
if(m_checked_for_install_dir) {
Expand All @@ -15,14 +20,36 @@ bool MSYS2::FindInstallDir(wxString* msyspath)

m_checked_for_install_dir = true;

// try common paths
std::vector<wxString> vpaths = { R"(C:\msys64)", R"(C:\msys2)", R"(C:\msys)" };
for(const wxString& path : vpaths) {
if(wxFileName::DirExists(path)) {
m_install_dir = path;
*msyspath = m_install_dir;
wxString reg_install_path;
#ifdef __WXMSW__
wxRegKey uninstall(wxRegKey::HKCU, R"(SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall)");
wxString appname;
long dummy;
bool cont = uninstall.GetFirstKey(appname, dummy);
while(cont) {
wxString display_name;
wxRegKey appkey(wxRegKey::HKCU, R"(SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\)" + appname);
if(appkey.QueryValue("DisplayName", display_name) && display_name == "MSYS2 64bit") {
appkey.QueryValue("InstallLocation", reg_install_path);
break;
}
cont = uninstall.GetNextKey(appname, dummy);
}
#endif

if(!reg_install_path.empty()) {
m_install_dir = reg_install_path;
*msyspath = m_install_dir;
} else {
// try common paths
std::vector<wxString> vpaths = { R"(C:\msys64)", R"(C:\msys2)", R"(C:\msys)" };
for(const wxString& path : vpaths) {
if(wxFileName::DirExists(path)) {
m_install_dir = path;
*msyspath = m_install_dir;
break;
}
}
}
return !m_install_dir.empty();
}
Expand Down
1 change: 0 additions & 1 deletion TODO.TXT
Expand Up @@ -7,4 +7,3 @@ Debug Adapter Client

others:
----
- Support code formatter for CMake (cmake-format) + update the docs on how to install it

0 comments on commit a1673b7

Please sign in to comment.