diff options
author | Sven Strickroth <email@cs-ware.de> | 2012-09-24 18:50:37 +0200 |
---|---|---|
committer | Sven Strickroth <email@cs-ware.de> | 2012-09-24 18:50:37 +0200 |
commit | 6605f51d81a9ccfb1b5a1c1689a57cf3f5b2f5b3 (patch) | |
tree | 2e96001a13cdc68155f6042b288b84dcc880ec03 /src/fileops.c | |
parent | 68e75c3a57874d3f1a6a7d36495e9303b69c6a78 (diff) | |
download | libgit2-6605f51d81a9ccfb1b5a1c1689a57cf3f5b2f5b3.tar.gz |
Automatically detect msysgit installation path
Do not hardcode the installation path of msysgit, but read installation path from registry.
Also "%PROGRAMFILES%\Git\etc" won't work on x64 systems with 64-bit libgit2, because
msysgit is x86 only and located in "%ProgramFiles(x86)%\Git\etc".
Signed-off-by: Sven Strickroth <email@cs-ware.de>
Diffstat (limited to 'src/fileops.c')
-rw-r--r-- | src/fileops.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/fileops.c b/src/fileops.c index cd0c055ae..b9044f0a3 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -423,12 +423,36 @@ static int win32_find_file(git_buf *path, const struct win32_path *root, const c int git_futils_find_system_file(git_buf *path, const char *filename) { #ifdef GIT_WIN32 +#ifndef _WIN64 +#define REG_MSYSGIT_INSTALL L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1" +#else +#define REG_MSYSGIT_INSTALL L"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1" +#endif + struct win32_path root; - if (win32_expand_path(&root, L"%PROGRAMFILES%\\Git\\etc\\") < 0 || - root.path[0] == L'%') /* i.e. no expansion happened */ + HKEY hKey; + DWORD dwType = REG_SZ; + DWORD dwSize = MAX_PATH; + + root.len = 0; + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, REG_MSYSGIT_INSTALL, 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) { - giterr_set(GITERR_OS, "Cannot locate the system's Program Files directory"); + if (RegQueryValueExW(hKey, L"InstallLocation", NULL, &dwType,(LPBYTE)&root.path, &dwSize) == ERROR_SUCCESS) + { + // InstallLocation points to the root of the msysgit directory + if (wcscat_s(root.path, MAX_PATH, L"etc\\")) + { + giterr_set(GITERR_OS, "Cannot locate the system's msysgit directory - path too long"); + return -1; + } + root.len = (DWORD)wcslen(root.path) + 1; + } + } + RegCloseKey(hKey); + + if (!root.len) { + giterr_set(GITERR_OS, "Cannot locate the system's msysgit directory"); return -1; } |