]> granicus.if.org Git - icinga2/commitdiff
Use the right path prefix for Windows.
authorGunnar Beutner <gunnar@beutner.name>
Fri, 18 Apr 2014 14:15:34 +0000 (16:15 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Fri, 18 Apr 2014 14:15:34 +0000 (16:15 +0200)
Refs #4865

icinga-app/icinga.cpp

index 2a08b32d1466be47a58a921144672715b12cacbf..3a8caa19df2dadf590b3e566940f6f1e8ce3f697 100644 (file)
@@ -202,10 +202,42 @@ int Main(void)
        /* Install exception handlers to make debugging easier. */
        Application::InstallExceptionHandlers();
 
-       Application::DeclarePrefixDir(ICINGA_PREFIX);
-       Application::DeclareSysconfDir(ICINGA_SYSCONFDIR);
-       Application::DeclareLocalStateDir(ICINGA_LOCALSTATEDIR);
-       Application::DeclarePkgDataDir(ICINGA_PKGDATADIR);
+#ifdef _WIN32
+       bool builtinPaths = true;
+
+       HKEY hKey;
+       if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Icinga Development Team\\ICINGA2", 0,
+           KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) {
+               BYTE pvData[MAX_PATH];
+               DWORD cbData = sizeof(pvData)-1;
+               DWORD lType;
+               if (RegQueryValueEx(hKey, NULL, NULL, &lType, pvData, &cbData) == ERROR_SUCCESS && lType == REG_SZ) {
+                       pvData[cbData] = '\0';
+
+                       String prefix = (char *)pvData;
+                       Application::DeclarePrefixDir(prefix);
+                       Application::DeclareSysconfDir(prefix + "\\etc");
+                       Application::DeclareLocalStateDir(prefix + "\\var");
+                       Application::DeclarePkgDataDir(prefix + "\\share");
+
+                       builtinPaths = false;
+               }
+
+               RegCloseKey(hKey);
+       }
+
+       if (builtinPaths) {
+               Log(LogWarning, "icinga-app", "Registry key could not be read. Falling back to built-in paths.");
+
+#else /* _WIN32 */
+               Application::DeclarePrefixDir(ICINGA_PREFIX);
+               Application::DeclareSysconfDir(ICINGA_SYSCONFDIR);
+               Application::DeclareLocalStateDir(ICINGA_LOCALSTATEDIR);
+               Application::DeclarePkgDataDir(ICINGA_PKGDATADIR);
+#endif /* _WIN32 */
+#ifdef _WIN32
+       }
+#endif /* _WIN32 */
 
        Application::DeclareApplicationType("icinga/IcingaApplication");