Merge pull request #1299 from csware/support_local_msysgit_install

Support local msysgit installations
This commit is contained in:
Vicent Martí 2013-02-01 15:37:45 -08:00
commit db37d3de79
3 changed files with 33 additions and 24 deletions

View File

@ -64,6 +64,7 @@ Sergey Nikishin
Shawn O. Pearce Shawn O. Pearce
Shuhei Tanuma Shuhei Tanuma
Steve Frécinaux Steve Frécinaux
Sven Strickroth
Tim Branyen Tim Branyen
Tim Clem Tim Clem
Tim Harder Tim Harder

View File

@ -9,8 +9,9 @@
#include "path.h" #include "path.h"
#include "findfile.h" #include "findfile.h"
#define REG_MSYSGIT_INSTALL_LOCAL L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1"
#ifndef _WIN64 #ifndef _WIN64
#define REG_MSYSGIT_INSTALL L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1" #define REG_MSYSGIT_INSTALL REG_MSYSGIT_INSTALL_LOCAL
#else #else
#define REG_MSYSGIT_INSTALL L"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1" #define REG_MSYSGIT_INSTALL L"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1"
#endif #endif
@ -113,31 +114,12 @@ int win32_find_system_file_using_registry(git_buf *path, const char *filename)
{ {
struct win32_path root; struct win32_path root;
HKEY hKey; if (win32_find_msysgit_in_registry(&root, HKEY_CURRENT_USER, REG_MSYSGIT_INSTALL_LOCAL)) {
DWORD dwType = REG_SZ; if (win32_find_msysgit_in_registry(&root, HKEY_LOCAL_MACHINE, REG_MSYSGIT_INSTALL)) {
DWORD dwSize = MAX_PATH; giterr_set(GITERR_OS, "Cannot locate the system's msysgit directory");
return -1;
root.len = 0;
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, REG_MSYSGIT_INSTALL, 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
{
if (RegQueryValueExW(hKey, L"InstallLocation", NULL, &dwType,(LPBYTE)&root.path, &dwSize) == ERROR_SUCCESS)
{
// InstallLocation points to the root of the msysgit directory
if (dwSize + 4 > MAX_PATH) // 4 = wcslen(L"etc\\")
{
giterr_set(GITERR_OS, "Cannot locate the system's msysgit directory - path too long");
return -1;
}
wcscat(root.path, L"etc\\");
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;
}
if (win32_find_file(path, &root, filename) < 0) { if (win32_find_file(path, &root, filename) < 0) {
giterr_set(GITERR_OS, "The system file '%s' doesn't exist", filename); giterr_set(GITERR_OS, "The system file '%s' doesn't exist", filename);
@ -147,3 +129,28 @@ int win32_find_system_file_using_registry(git_buf *path, const char *filename)
return 0; return 0;
} }
int win32_find_msysgit_in_registry(struct win32_path *root, const HKEY hieve, const wchar_t *key)
{
HKEY hKey;
DWORD dwType = REG_SZ;
DWORD dwSize = MAX_PATH;
assert(root);
root->len = 0;
if (RegOpenKeyExW(hieve, key, 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) {
if (RegQueryValueExW(hKey, L"InstallLocation", NULL, &dwType, (LPBYTE)&root->path, &dwSize) == ERROR_SUCCESS) {
// InstallLocation points to the root of the msysgit directory
if (dwSize + 4 > MAX_PATH) {// 4 = wcslen(L"etc\\")
giterr_set(GITERR_OS, "Cannot locate the system's msysgit directory - path too long");
return -1;
}
wcscat(root->path, L"etc\\");
root->len = (DWORD)wcslen(root->path) + 1;
}
}
RegCloseKey(hKey);
return root->len ? 0 : GIT_ENOTFOUND;
}

View File

@ -18,6 +18,7 @@ int win32_expand_path(struct win32_path *s_root, const wchar_t *templ);
int win32_find_file(git_buf *path, const struct win32_path *root, const char *filename); int win32_find_file(git_buf *path, const struct win32_path *root, const char *filename);
int win32_find_system_file_using_path(git_buf *path, const char *filename); int win32_find_system_file_using_path(git_buf *path, const char *filename);
int win32_find_system_file_using_registry(git_buf *path, const char *filename); int win32_find_system_file_using_registry(git_buf *path, const char *filename);
int win32_find_msysgit_in_registry(struct win32_path *root, const HKEY hieve, const wchar_t *key);
#endif #endif