/** * @brief Determine the Windows path of our / directory * @internal * @return Error code from winerror.h, ERROR_SUCCESS on success */ long _plibc_DetermineRootDir() { char szModule[_MAX_PATH], szDrv[_MAX_DRIVE], szDir[_MAX_DIR]; char *pszBin; long lDirLen; /* Get the path of the calling module. It should be located in one of the "bin" directories */ GetModuleFileName(NULL, szModule, MAX_PATH); _splitpath(szModule, szDrv, szDir, NULL, NULL); lDirLen = strlen(szDir); pszBin = szDir + lDirLen - 5; if (lDirLen < 5 || strnicmp(pszBin, "\\bin\\", 5) != 0) { char szRegPath[251]; /* Get the installation path from the registry */ lDirLen = _MAX_PATH - 1; _win_snprintf(szRegPath, 250, "Software\\%s\\%s", _pszOrg, _pszApp); szRegPath[250] = 0; if(QueryRegistry (HKEY_CURRENT_USER, szRegPath, "InstallDir", szRootDir, &lDirLen) != ERROR_SUCCESS) { lDirLen = _MAX_PATH - 1; if(QueryRegistry (HKEY_LOCAL_MACHINE, szRegPath, "InstallDir", szRootDir, &lDirLen) != ERROR_SUCCESS) { if (GetCurrentDirectory(sizeof(szRootDir), szRootDir) == 0) return ERROR_BAD_ENVIRONMENT; lDirLen = strlen(szRootDir); } } strcat(szRootDir, "\\"); lRootDirLen = lDirLen + 1; szDrv[0] = 0; } else { pszBin[1] = 0; lDirLen -= 4; } if(szDrv[0]) { strcpy(szRootDir, szDrv); lRootDirLen = 3 + lDirLen - 1; /* 3 = strlen(szDir) */ if(lRootDirLen > _MAX_PATH) return ERROR_BUFFER_OVERFLOW; strcat(szRootDir, szDir); } return ERROR_SUCCESS; }
bool Registrar::IsVersion5Installed() { CStdString sResult = QueryRegistry(_T("SOFTWARE\\Hummingbird\\PowerDOCS"), _T("CurrentVersion")); if (sResult.Left(1) != _T("5")) return false; sResult = QueryRegistry(_T("SOFTWARE\\Hummingbird\\PowerDOCS"), _T("InstallPath")); return !sResult.IsEmpty(); }
long _plibc_DetermineProgramDataDir() { long lRet; lDataDirLen = _MAX_PATH; lRet = QueryRegistry(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\" "Explorer\\Shell Folders", "Common AppData", szDataDir, &lDataDirLen); lDataDirLen += strlen(_pszApp) + 1 + strlen(_pszOrg) + 1; if (lRet == ERROR_BUFFER_OVERFLOW || lDataDirLen > _MAX_PATH) { return ERROR_BUFFER_OVERFLOW; } else if (lRet == ERROR_SUCCESS) { strcat(szDataDir, "\\"); strcat(szDataDir, _pszOrg); strcat(szDataDir, "\\"); strcat(szDataDir, _pszApp); strcat(szDataDir, "\\"); } else strcpy(szDataDir, szRootDir); return ERROR_SUCCESS; }
/** * @brief Determine the user's home directory * @internal * @return Error code from winerror.h, ERROR_SUCCESS on success */ long _plibc_DetermineHomeDir() { char *lpszProfile = getenv("USERPROFILE"); if(lpszProfile != NULL && lpszProfile[0] != 0) /* Windows NT */ { lHomeDirLen = strlen(lpszProfile); if(lHomeDirLen + 1 > _MAX_PATH) return ERROR_BUFFER_OVERFLOW; strcpy(szHomeDir, lpszProfile); if(szHomeDir[lHomeDirLen - 1] != '\\') { szHomeDir[lHomeDirLen] = '\\'; szHomeDir[++lHomeDirLen] = 0; } } else { /* C:\My Documents */ long lRet; lHomeDirLen = _MAX_PATH; lRet = QueryRegistry(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\" "Explorer\\Shell Folders", "Personal", szHomeDir, &lHomeDirLen); if(lRet == ERROR_BUFFER_OVERFLOW) return ERROR_BUFFER_OVERFLOW; else if(lRet == ERROR_SUCCESS) { /* lHomeDirLen includes \0 */ if (lHomeDirLen <= _MAX_PATH) strcat(szHomeDir, "\\"); else return ERROR_BUFFER_OVERFLOW; } else { /* C:\Program Files\GNUnet\home\... */ /* 5 = strlen("home\\") */ lHomeDirLen = strlen(szRootDir) + strlen(szUser) + 5 + 1; if(_MAX_PATH < lHomeDirLen) return ERROR_BUFFER_OVERFLOW; strcpy(szHomeDir, szRootDir); strcat(szHomeDir, "home\\"); strcat(szHomeDir, szUser); strcat(szHomeDir, "\\"); } } return ERROR_SUCCESS; }
bool Registrar::IsVersion39Installed() { CStdString sResult = QueryRegistry(_T("SOFTWARE\\Hummingbird\\PowerDOCS 3.9"), _T("Path")); return !sResult.IsEmpty(); }