Use the right path prefix for Windows.

Refs #4865
This commit is contained in:
Gunnar Beutner 2014-04-18 16:15:34 +02:00
parent bf39244f48
commit df518e4d0f
1 changed files with 36 additions and 4 deletions

View File

@ -202,10 +202,42 @@ int Main(void)
/* Install exception handlers to make debugging easier. */
Application::InstallExceptionHandlers();
#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");