refactor to platform independent message_box function
[git-cheetah/kirill.git] / explorer / systeminfo.c
blobe71b55b48b455ec4f4246c5b5fbb0d639f0281fc
1 #include "../common/git-compat-util.h"
2 #include <windows.h>
3 #include "../common/systeminfo.h"
4 #include "dll.h"
6 static char gitPath[MAX_PATH] = "";
7 static TCHAR msysPath[MAX_PATH];
9 static int get_msys_path_from_registry(HKEY root)
11 HKEY key;
12 DWORD path_len = sizeof(msysPath);
14 LONG result = RegOpenKeyEx(root, GIT_CHEETAH_REG_PATH,
15 0, KEY_QUERY_VALUE, &key);
16 if (ERROR_SUCCESS != result)
17 return 0;
19 result = RegQueryValueEx(key,
20 GIT_CHEETAH_REG_PATHTOMSYS,
21 NULL, NULL, (LPBYTE)msysPath, &path_len);
23 RegCloseKey(key);
25 return ERROR_SUCCESS == result;
28 static TCHAR *msys_path(void)
30 static int found_path = 0;
32 /* try to find user-specific settings first */
33 if (!found_path)
34 found_path = get_msys_path_from_registry(HKEY_CURRENT_USER);
36 /* if not found in user settings, try machine-wide */
37 if (!found_path)
38 found_path = get_msys_path_from_registry(HKEY_LOCAL_MACHINE);
40 if (found_path)
41 return msysPath;
43 return NULL;
46 static inline int test_msys_path(const char *postfix, char *path)
48 int n;
49 char stat_path[MAX_PATH];
50 struct stat stat_info;
52 n = snprintf(stat_path, MAX_PATH, "%s\\%s\\git",
53 msys_path(), postfix);
54 if (n >= MAX_PATH)
55 goto test_git_path_failed;
57 n = snprintf(path, MAX_PATH, "%s\\%s", msys_path(), postfix);
58 if (n >= MAX_PATH)
59 goto test_git_path_failed;
61 if (lstat(path, &stat_info) == 0) {
62 return 1;
65 test_git_path_failed:
66 *path = '\0';
67 return 0;
70 const char *git_path()
72 char path[MAX_PATH];
74 if (!msys_path())
75 return NULL;
77 if (*gitPath)
78 return gitPath;
80 if (test_msys_path("bin", path)) {
81 memcpy(gitPath, path, MAX_PATH);
82 return gitPath;
85 if (test_msys_path("mingw\\bin", path)) {
86 memcpy(gitPath, path, MAX_PATH);
87 return gitPath;
90 return NULL;
93 void message_box(const char *string)
95 MessageBox(0, string, "Hello", MB_OK|MB_ICONEXCLAMATION);