Debian Codegraph @

git/GitLocator.cpp

raw
1 #include "GitLocator.h"
2 #include <wx/tokenzr.h>
3 #include "globals.h"
4
5 #ifdef __WXMSW__
6 #include <wx/msw/registry.h>
7 #endif
8
9 GitLocator::GitLocator() {}
10
11 GitLocator::~GitLocator() {}
12
13 bool GitLocator::GetExecutable(wxFileName& gitpath) const
14 {
15 // Common to all platforms:
16 // use the PATH environment variable to locate git executable
17 wxString path;
18 if(::wxGetEnv("PATH", &path)) {
19 wxArrayString paths = ::wxStringTokenize(path, ";", wxTOKEN_STRTOK);
20 for(size_t i = 0; i < paths.GetCount(); ++i) {
21 wxString gitExeFullPath;
22 if(DoCheckGitInFolder(paths.Item(i), gitExeFullPath)) {
23 gitpath = gitExeFullPath;
24 return true;
25 }
26 }
27 }
28
29 #ifdef __WXMSW__
30 // Under Windows search the registry for git executable as well
31 wxRegKey regGit(wxRegKey::HKLM, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1");
32 wxRegKey regGit2(wxRegKey::HKLM, "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1");
33 wxString installLocation;
34 if(((regGit.Exists() && regGit.QueryValue("InstallLocation", installLocation)) ||
35 (regGit2.Exists() && regGit2.QueryValue("InstallLocation", installLocation))) &&
36 ::wxDirExists(installLocation)) {
37 wxString gitExeFullPath;
38 if(DoCheckGitInFolder(installLocation, gitExeFullPath)) {
39 gitpath = gitExeFullPath;
40 return true;
41 }
42 }
43 #endif
44 return false;
45 }
46
47 bool GitLocator::DoCheckGitInFolder(const wxString& folder, wxString& git) const
48 {
49 wxFileName gitExe(folder, "git.exe");
50 if(gitExe.Exists()) {
51 git = gitExe.GetFullPath();
52 return true;
53 }
54
55 // try to see if we have git.exe under an internal folder
56 gitExe.AppendDir("bin");
57 if(gitExe.Exists()) {
58 git = gitExe.GetFullPath();
59 return true;
60 }
61 return false;
62 }
63
64 bool GitLocator::MSWGetGitShellCommand(wxString& bashCommand) const
65 {
66 #ifdef __WXMSW__
67 wxRegKey regGit(wxRegKey::HKLM, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1");
68 wxRegKey regGit2(wxRegKey::HKLM, "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1");
69 wxString installLocation;
70 if(((regGit.Exists() && regGit.QueryValue("InstallLocation", installLocation)) ||
71 (regGit2.Exists() && regGit2.QueryValue("InstallLocation", installLocation))) &&
72 ::wxDirExists(installLocation)) {
73 wxString gitExeFullPath;
74 if(DoCheckGitInFolder(installLocation, gitExeFullPath)) {
75 wxFileName gitpath = gitExeFullPath;
76 gitpath.SetName("bash");
77 if(gitpath.Exists()) {
78 bashCommand = gitpath.GetFullPath();
79 ::WrapWithQuotes(bashCommand);
80 bashCommand << " --login -i";
81 return true;
82 }
83 }
84 }
85 #endif
86 return false;
87 }