//--------------------------------------------------------------------------- __fastcall TConfiguration::TConfiguration() { FCriticalSection = new TCriticalSection(); FUpdating = 0; FStorage = stDetect; FDontSave = false; FApplicationInfo = NULL; FUsage = new TUsage(this); FDefaultCollectUsage = false; wchar_t Buf[10]; UnicodeString RandomSeedPath; if (GetEnvironmentVariable(L"APPDATA", Buf, LENOF(Buf)) > 0) { RandomSeedPath = L"%APPDATA%"; } else { RandomSeedPath = GetShellFolderPath(CSIDL_LOCAL_APPDATA); if (RandomSeedPath.IsEmpty()) { RandomSeedPath = GetShellFolderPath(CSIDL_APPDATA); } } FDefaultRandomSeedFile = IncludeTrailingBackslash(RandomSeedPath) + L"winscp.rnd"; }
//--------------------------------------------------------------------------- TConfiguration::TConfiguration() : FCriticalSection(nullptr), FDontSave(false), FChanged(false), FUpdating(0), FApplicationInfo(nullptr), FLogging(false), FPermanentLogging(false), FLogWindowLines(0), FLogFileAppend(false), FLogProtocol(0), FActualLogProtocol(0), FLogActions(false), FPermanentLogActions(false), FConfirmOverwriting(false), FConfirmResume(false), FAutoReadDirectoryAfterOp(false), FSessionReopenAuto(0), FSessionReopenBackground(0), FSessionReopenTimeout(0), FSessionReopenAutoStall(0), FProgramIniPathWrittable(0), FTunnelLocalPortNumberLow(0), FTunnelLocalPortNumberHigh(0), FCacheDirectoryChangesMaxSize(0), FShowFtpWelcomeMessage(false), FTryFtpWhenSshFails(false), FDisablePasswordStoring(false), FForceBanners(false), FDisableAcceptingHostKeys(false), FDefaultCollectUsage(false), FSessionReopenAutoMaximumNumberOfRetries(0) { FCriticalSection = new TCriticalSection(); FUpdating = 0; FStorage = stRegistry; FDontSave = false; FApplicationInfo = nullptr; // FUsage = new TUsage(this); // FDefaultCollectUsage = false; wchar_t Buf[10]; UnicodeString RandomSeedPath; if (GetEnvironmentVariable(L"APPDATA", Buf, LENOF(Buf)) > 0) { RandomSeedPath = L"%APPDATA%"; } else { RandomSeedPath = GetShellFolderPath(CSIDL_LOCAL_APPDATA); if (RandomSeedPath.IsEmpty()) { RandomSeedPath = GetShellFolderPath(CSIDL_APPDATA); } } FDefaultRandomSeedFile = IncludeTrailingBackslash(RandomSeedPath) + L"winscp.rnd"; }
nsresult nsXREDirProvider::GetUpdateRootDir(nsIFile* *aResult) { nsCOMPtr<nsIFile> appDir = GetAppDir(); nsAutoString appPath; nsresult rv = appDir->GetPath(appPath); NS_ENSURE_SUCCESS(rv, rv); // AppDir may be a short path. Convert to long path to make sure // the consistency of the update folder location nsString longPath; PRUnichar* buf; uint32_t bufLength = longPath.GetMutableData(&buf, MAXPATHLEN); NS_ENSURE_TRUE(bufLength >= MAXPATHLEN, NS_ERROR_OUT_OF_MEMORY); DWORD len = GetLongPathNameW(appPath.get(), buf, bufLength); // Failing GetLongPathName() is not fatal. if (len <= 0 || len >= bufLength) longPath.Assign(appPath); else longPath.SetLength(len); // Use <UserLocalDataDir>\updates\<relative path to app dir from // Program Files> if app dir is under Program Files to avoid the // folder virtualization mess on Windows Vista nsAutoString programFiles; rv = GetShellFolderPath(CSIDL_PROGRAM_FILES, programFiles); NS_ENSURE_SUCCESS(rv, rv); programFiles.AppendLiteral("\\"); uint32_t programFilesLen = programFiles.Length(); if (longPath.Length() < programFilesLen) return NS_ERROR_FAILURE; nsAutoString programName; if (_wcsnicmp(programFiles.get(), longPath.get(), programFilesLen) == 0) { programName = Substring(longPath, programFilesLen); } else { // We need the update root directory to live outside of the installation // directory, because otherwise the updater writing the log file can cause // the directory to be locked, which prevents it from being replaced after // background updates. programName.AssignASCII(MOZ_APP_NAME); } nsCOMPtr<nsIFile> updRoot; rv = GetUserLocalDataDirectory(getter_AddRefs(updRoot)); NS_ENSURE_SUCCESS(rv, rv); rv = updRoot->AppendRelativePath(programName); NS_ENSURE_SUCCESS(rv, rv); NS_ADDREF(*aResult = updRoot); return NS_OK; }
nsresult nsXREDirProvider::GetUpdateRootDir(nsIFile* *aResult) { nsCOMPtr<nsIFile> appDir = GetAppDir(); nsAutoString appPath; nsresult rv = appDir->GetPath(appPath); NS_ENSURE_SUCCESS(rv, rv); // AppDir may be a short path. Convert to long path to make sure // the consistency of the update folder location nsString longPath; PRUnichar* buf; PRUint32 bufLength = longPath.GetMutableData(&buf, MAXPATHLEN); NS_ENSURE_TRUE(bufLength >= MAXPATHLEN, NS_ERROR_OUT_OF_MEMORY); #ifdef WINCE longPath.Assign(appPath); #else DWORD len = GetLongPathNameW(appPath.get(), buf, bufLength); // Failing GetLongPathName() is not fatal. if (len <= 0 || len >= bufLength) longPath.Assign(appPath); else longPath.SetLength(len); #endif // Use <UserLocalDataDir>\updates\<relative path to app dir from // Program Files> if app dir is under Program Files to avoid the // folder virtualization mess on Windows Vista nsAutoString programFiles; rv = GetShellFolderPath(CSIDL_PROGRAM_FILES, programFiles); NS_ENSURE_SUCCESS(rv, rv); programFiles.AppendLiteral("\\"); PRUint32 programFilesLen = programFiles.Length(); if (longPath.Length() < programFilesLen) return NS_ERROR_FAILURE; if (_wcsnicmp(programFiles.get(), longPath.get(), programFilesLen) != 0) return NS_ERROR_FAILURE; nsCOMPtr<nsILocalFile> updRoot; rv = GetUserLocalDataDirectory(getter_AddRefs(updRoot)); NS_ENSURE_SUCCESS(rv, rv); rv = updRoot->AppendRelativePath(Substring(longPath, programFilesLen)); NS_ENSURE_SUCCESS(rv, rv); NS_ADDREF(*aResult = updRoot); return NS_OK; }
void StartupRunner::_RunShellFolderContents(int nFolder) { TCHAR tzPath[MAX_PATH] = { 0 }; if (GetShellFolderPath(nFolder, tzPath, COUNTOF(tzPath))) { if (tzPath[0]) { TCHAR tzSearchPath[MAX_PATH] = { 0 }; PathCombine(tzSearchPath, tzPath, _T("*.*")); WIN32_FIND_DATA findData = { 0 }; HANDLE hSearch = FindFirstFile(tzSearchPath, &findData); while (hSearch != INVALID_HANDLE_VALUE) { if (!PathIsDirectory(findData.cFileName) && !(findData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) && !(findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)) { SHELLEXECUTEINFO seiCommand = { 0 }; seiCommand.cbSize = sizeof(SHELLEXECUTEINFO); seiCommand.lpFile = findData.cFileName; seiCommand.lpDirectory = tzPath; seiCommand.nShow = SW_SHOWNORMAL; seiCommand.fMask = SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI; if (!LSShellExecuteEx(&seiCommand)) { TRACE("StartupRunner failed to launch '%s'", findData.cFileName); } } if (!FindNextFile(hSearch, &findData)) { FindClose(hSearch); hSearch = INVALID_HANDLE_VALUE; } } } } else { TRACE("Failed to get full path to Startup folder %d", nFolder); } }
csString csGetPlatformConfigPath (const char* key, bool local) { char appDataPath [MAX_PATH + 1]; csString path; // Try to retrieve "Application Data" directory if (!GetShellFolderPath (local ? CSIDL_LOCAL_APPDATA : CSIDL_APPDATA, appDataPath)) { // Fall back to My Documents if (!GetShellFolderPath (CSIDL_PERSONAL, appDataPath)) { // Guess... strcpy (appDataPath, "."); } } path << appDataPath << "\\" << key; const size_t adpl = strlen (appDataPath) + 1; ReplaceReserved (path, adpl); ReplaceSeparators (path, adpl); return path; }
bool LSAPIInit::setShellFolderVariable(LPCWSTR pwzVariable, int nFolder) { bool bSuccess = false; wchar_t wzPath[MAX_PATH] = { 0 }; if (GetShellFolderPath(nFolder, wzPath, MAX_PATH)) { PathAddBackslashEx(wzPath, MAX_PATH); PathQuoteSpacesW(wzPath); m_smSettingsManager->SetVariable(pwzVariable, wzPath); bSuccess = true; } return bSuccess; }
//--------------------------------------------------------------------- TStoredSessionList * __fastcall TGUIConfiguration::SelectFilezillaSessionsForImport( TStoredSessionList * Sessions) { std::auto_ptr<TStoredSessionList> ImportSessionList(new TStoredSessionList(true)); ImportSessionList->DefaultSettings = Sessions->DefaultSettings; UnicodeString AppDataPath = GetShellFolderPath(CSIDL_APPDATA); UnicodeString FilezillaSiteManagerFile = IncludeTrailingBackslash(AppDataPath) + L"FileZilla\\sitemanager.xml"; if (FileExists(FilezillaSiteManagerFile)) { ImportSessionList->ImportFromFilezilla(FilezillaSiteManagerFile); ImportSessionList->SelectSessionsToImport(Sessions, true); } return ImportSessionList.release(); }
nsresult nsXREDirProvider::GetUserDataDirectoryHome(nsIFile** aFile, bool aLocal) { // Copied from nsAppFileLocationProvider (more or less) nsresult rv; nsCOMPtr<nsIFile> localDir; #if defined(XP_MACOSX) FSRef fsRef; OSType folderType; if (aLocal) { folderType = kCachedDataFolderType; } else { #ifdef MOZ_THUNDERBIRD folderType = kDomainLibraryFolderType; #else folderType = kApplicationSupportFolderType; #endif } OSErr err = ::FSFindFolder(kUserDomain, folderType, kCreateFolder, &fsRef); NS_ENSURE_FALSE(err, NS_ERROR_FAILURE); rv = NS_NewNativeLocalFile(EmptyCString(), true, getter_AddRefs(localDir)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsILocalFileMac> dirFileMac = do_QueryInterface(localDir); NS_ENSURE_TRUE(dirFileMac, NS_ERROR_UNEXPECTED); rv = dirFileMac->InitWithFSRef(&fsRef); NS_ENSURE_SUCCESS(rv, rv); localDir = do_QueryInterface(dirFileMac, &rv); #elif defined(XP_IOS) nsAutoCString userDir; if (GetUIKitDirectory(aLocal, userDir)) { rv = NS_NewNativeLocalFile(userDir, true, getter_AddRefs(localDir)); } else { rv = NS_ERROR_FAILURE; } NS_ENSURE_SUCCESS(rv, rv); #elif defined(XP_WIN) nsString path; if (aLocal) { rv = GetShellFolderPath(CSIDL_LOCAL_APPDATA, path); if (NS_FAILED(rv)) rv = GetRegWindowsAppDataFolder(aLocal, path); } if (!aLocal || NS_FAILED(rv)) { rv = GetShellFolderPath(CSIDL_APPDATA, path); if (NS_FAILED(rv)) { if (!aLocal) rv = GetRegWindowsAppDataFolder(aLocal, path); } } NS_ENSURE_SUCCESS(rv, rv); rv = NS_NewLocalFile(path, true, getter_AddRefs(localDir)); #elif defined(MOZ_WIDGET_GONK) rv = NS_NewNativeLocalFile(NS_LITERAL_CSTRING("/data/b2g"), true, getter_AddRefs(localDir)); #elif defined(XP_UNIX) const char* homeDir = getenv("HOME"); if (!homeDir || !*homeDir) return NS_ERROR_FAILURE; #ifdef ANDROID /* We want (ProfD == ProfLD) on Android. */ aLocal = false; #endif if (aLocal) { // If $XDG_CACHE_HOME is defined use it, otherwise use $HOME/.cache. const char* cacheHome = getenv("XDG_CACHE_HOME"); if (cacheHome && *cacheHome) { rv = NS_NewNativeLocalFile(nsDependentCString(cacheHome), true, getter_AddRefs(localDir)); } else { rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true, getter_AddRefs(localDir)); if (NS_SUCCEEDED(rv)) rv = localDir->AppendNative(NS_LITERAL_CSTRING(".cache")); } } else { rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true, getter_AddRefs(localDir)); } #else #error "Don't know how to get product dir on your platform" #endif NS_IF_ADDREF(*aFile = localDir); return rv; }
nsresult nsXREDirProvider::GetUpdateRootDir(nsIFile* *aResult) { nsCOMPtr<nsIFile> updRoot; #if defined(MOZ_WIDGET_GONK) nsresult rv = NS_NewNativeLocalFile(nsDependentCString("/data/local"), true, getter_AddRefs(updRoot)); NS_ENSURE_SUCCESS(rv, rv); #else nsCOMPtr<nsIFile> appFile; bool per = false; nsresult rv = GetFile(XRE_EXECUTABLE_FILE, &per, getter_AddRefs(appFile)); NS_ENSURE_SUCCESS(rv, rv); rv = appFile->GetParent(getter_AddRefs(updRoot)); NS_ENSURE_SUCCESS(rv, rv); #ifdef XP_MACOSX nsCOMPtr<nsIFile> appRootDirFile; nsCOMPtr<nsIFile> localDir; nsAutoString appDirPath; if (NS_FAILED(appFile->GetParent(getter_AddRefs(appRootDirFile))) || NS_FAILED(appRootDirFile->GetPath(appDirPath)) || NS_FAILED(GetUserDataDirectoryHome(getter_AddRefs(localDir), true))) { return NS_ERROR_FAILURE; } int32_t dotIndex = appDirPath.RFind(".app"); if (dotIndex == kNotFound) { dotIndex = appDirPath.Length(); } appDirPath = Substring(appDirPath, 1, dotIndex - 1); bool hasVendor = gAppData->vendor && strlen(gAppData->vendor) != 0; if (hasVendor || gAppData->name) { if (NS_FAILED(localDir->AppendNative(nsDependentCString(hasVendor ? gAppData->vendor : gAppData->name)))) { return NS_ERROR_FAILURE; } } else if (NS_FAILED(localDir->AppendNative(NS_LITERAL_CSTRING("Mozilla")))) { return NS_ERROR_FAILURE; } if (NS_FAILED(localDir->Append(NS_LITERAL_STRING("updates"))) || NS_FAILED(localDir->AppendRelativePath(appDirPath))) { return NS_ERROR_FAILURE; } localDir.forget(aResult); return NS_OK; #elif XP_WIN nsAutoString pathHash; bool pathHashResult = false; bool hasVendor = gAppData->vendor && strlen(gAppData->vendor) != 0; nsAutoString appDirPath; if (SUCCEEDED(updRoot->GetPath(appDirPath))) { // Figure out where we should check for a cached hash value. If the // application doesn't have the nsXREAppData vendor value defined check // under SOFTWARE\Mozilla. wchar_t regPath[1024] = { L'\0' }; swprintf_s(regPath, mozilla::ArrayLength(regPath), L"SOFTWARE\\%S\\%S\\TaskBarIDs", (hasVendor ? gAppData->vendor : "Mozilla"), MOZ_APP_BASENAME); // If we pre-computed the hash, grab it from the registry. pathHashResult = GetCachedHash(HKEY_LOCAL_MACHINE, nsDependentString(regPath), appDirPath, pathHash); if (!pathHashResult) { pathHashResult = GetCachedHash(HKEY_CURRENT_USER, nsDependentString(regPath), appDirPath, pathHash); } } // Get the local app data directory and if a vendor name exists append it. // If only a product name exists, append it. If neither exist fallback to // old handling. We don't use the product name on purpose because we want a // shared update directory for different apps run from the same path. nsCOMPtr<nsIFile> localDir; if (pathHashResult && (hasVendor || gAppData->name) && NS_SUCCEEDED(GetUserDataDirectoryHome(getter_AddRefs(localDir), true)) && NS_SUCCEEDED(localDir->AppendNative(nsDependentCString(hasVendor ? gAppData->vendor : gAppData->name))) && NS_SUCCEEDED(localDir->Append(NS_LITERAL_STRING("updates"))) && NS_SUCCEEDED(localDir->Append(pathHash))) { localDir.forget(aResult); return NS_OK; } nsAutoString appPath; rv = updRoot->GetPath(appPath); NS_ENSURE_SUCCESS(rv, rv); // AppDir may be a short path. Convert to long path to make sure // the consistency of the update folder location nsString longPath; wchar_t* buf; uint32_t bufLength = longPath.GetMutableData(&buf, MAXPATHLEN); NS_ENSURE_TRUE(bufLength >= MAXPATHLEN, NS_ERROR_OUT_OF_MEMORY); DWORD len = GetLongPathNameW(appPath.get(), buf, bufLength); // Failing GetLongPathName() is not fatal. if (len <= 0 || len >= bufLength) longPath.Assign(appPath); else longPath.SetLength(len); // Use <UserLocalDataDir>\updates\<relative path to app dir from // Program Files> if app dir is under Program Files to avoid the // folder virtualization mess on Windows Vista nsAutoString programFiles; rv = GetShellFolderPath(CSIDL_PROGRAM_FILES, programFiles); NS_ENSURE_SUCCESS(rv, rv); programFiles.Append('\\'); uint32_t programFilesLen = programFiles.Length(); nsAutoString programName; if (_wcsnicmp(programFiles.get(), longPath.get(), programFilesLen) == 0) { programName = Substring(longPath, programFilesLen); } else { // We need the update root directory to live outside of the installation // directory, because otherwise the updater writing the log file can cause // the directory to be locked, which prevents it from being replaced after // background updates. programName.AssignASCII(MOZ_APP_NAME); } rv = GetUserLocalDataDirectory(getter_AddRefs(updRoot)); NS_ENSURE_SUCCESS(rv, rv); rv = updRoot->AppendRelativePath(programName); NS_ENSURE_SUCCESS(rv, rv); #endif // XP_WIN #endif updRoot.forget(aResult); return NS_OK; }
nsresult nsXREDirProvider::GetUserDataDirectoryHome(nsIFile** aFile, bool aLocal) { // Copied from nsAppFileLocationProvider (more or less) nsresult rv; nsCOMPtr<nsIFile> localDir; #if defined(XP_MACOSX) FSRef fsRef; OSType folderType; if (aLocal) { folderType = kCachedDataFolderType; } else { #ifdef MOZ_THUNDERBIRD folderType = kDomainLibraryFolderType; #else folderType = kApplicationSupportFolderType; #endif } OSErr err = ::FSFindFolder(kUserDomain, folderType, kCreateFolder, &fsRef); NS_ENSURE_FALSE(err, NS_ERROR_FAILURE); rv = NS_NewNativeLocalFile(EmptyCString(), true, getter_AddRefs(localDir)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsILocalFileMac> dirFileMac = do_QueryInterface(localDir); NS_ENSURE_TRUE(dirFileMac, NS_ERROR_UNEXPECTED); rv = dirFileMac->InitWithFSRef(&fsRef); NS_ENSURE_SUCCESS(rv, rv); localDir = do_QueryInterface(dirFileMac, &rv); #elif defined(XP_WIN) nsString path; if (aLocal) { rv = GetShellFolderPath(CSIDL_LOCAL_APPDATA, path); if (NS_FAILED(rv)) rv = GetRegWindowsAppDataFolder(aLocal, path); } if (!aLocal || NS_FAILED(rv)) { rv = GetShellFolderPath(CSIDL_APPDATA, path); if (NS_FAILED(rv)) { if (!aLocal) rv = GetRegWindowsAppDataFolder(aLocal, path); } } NS_ENSURE_SUCCESS(rv, rv); rv = NS_NewLocalFile(path, true, getter_AddRefs(localDir)); #elif defined(XP_OS2) #if 0 /* For OS/2 we want to always use MOZILLA_HOME */ // we want an environment variable of the form // FIREFOX_HOME, etc if (!gAppData) return NS_ERROR_FAILURE; nsDependentCString envVar(nsDependentCString(gAppData->name)); envVar.Append("_HOME"); char *pHome = getenv(envVar.get()); #endif char *pHome = getenv("MOZILLA_HOME"); if (pHome && *pHome) { rv = NS_NewNativeLocalFile(nsDependentCString(pHome), true, getter_AddRefs(localDir)); } else { PPIB ppib; PTIB ptib; char appDir[CCHMAXPATH]; DosGetInfoBlocks(&ptib, &ppib); DosQueryModuleName(ppib->pib_hmte, CCHMAXPATH, appDir); *strrchr(appDir, '\\') = '\0'; rv = NS_NewNativeLocalFile(nsDependentCString(appDir), true, getter_AddRefs(localDir)); } #elif defined(MOZ_WIDGET_GONK) rv = NS_NewNativeLocalFile(NS_LITERAL_CSTRING("/data/b2g"), true, getter_AddRefs(localDir)); #elif defined(XP_UNIX) const char* homeDir = getenv("HOME"); if (!homeDir || !*homeDir) return NS_ERROR_FAILURE; #ifdef ANDROID /* We want (ProfD == ProfLD) on Android. */ aLocal = false; #endif if (aLocal) { // If $XDG_CACHE_HOME is defined use it, otherwise use $HOME/.cache. const char* cacheHome = getenv("XDG_CACHE_HOME"); if (cacheHome && *cacheHome) { rv = NS_NewNativeLocalFile(nsDependentCString(cacheHome), true, getter_AddRefs(localDir)); } else { rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true, getter_AddRefs(localDir)); if (NS_SUCCEEDED(rv)) rv = localDir->AppendNative(NS_LITERAL_CSTRING(".cache")); } } else { rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true, getter_AddRefs(localDir)); } #else #error "Don't know how to get product dir on your platform" #endif NS_IF_ADDREF(*aFile = localDir); return rv; }
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // // GetShellFolderPath // // Wrapper around SHGetSpecialFolderLocation to get around the lack of // SHGetSpecialFolderPath on Win95. Also fetches the QuickLaunch folder. // bool GetShellFolderPath(int nFolder, LPTSTR ptzPath, size_t cchPath) { ASSERT(cchPath >= MAX_PATH); ASSERT(NULL != ptzPath); HRESULT hr = E_FAIL; PIDLIST_ABSOLUTE pidl = NULL; if (nFolder == LS_CSIDL_QUICKLAUNCH) { if (IsVistaOrAbove()) { // // Vista turned the QuickLaunch folder into a "Known Folder" // whose location can be customized. But it didn't retroactively // get a CSIDL constant so we have to use the known folder API. // hr = LSGetKnownFolderIDList(FOLDERID_QuickLaunch, &pidl); } else { // // Prior to Vista there is no documented way of getting the path. // We try to hardcode as little as possible. // hr = GetShellFolderPath(CSIDL_APPDATA, ptzPath, cchPath); if (SUCCEEDED(hr)) { PathAppend(ptzPath, _T("Microsoft\\Internet Explorer\\Quick Launch")); // // SHGetSpecialFolderLocation only returns directories that // exist, so we do the same for our custom QuickLaunch case. // if (!PathFileExists(ptzPath)) { hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); } } } } else { // Starting with Vista, the "ALT" folders don't exist any more. // SHGetSpecialFolderLocation maps them to the non-"ALT" versions. if (IsVistaOrAbove() && (nFolder == CSIDL_ALTSTARTUP || nFolder == CSIDL_COMMON_ALTSTARTUP)) { hr = E_FAIL; } else { hr = SHGetSpecialFolderLocation(NULL, nFolder, &pidl); } } // // Convert PIDL to path // if (pidl != NULL) { if (SUCCEEDED(hr) && !SHGetPathFromIDList(pidl, ptzPath)) { hr = E_FAIL; } CoTaskMemFree(pidl); } if (FAILED(hr)) { ptzPath[0] = '\0'; } return (SUCCEEDED(hr)); }
//--------------------------------------------------------------------------- UnicodeString __fastcall TConfiguration::GetIniFileStorageName(bool ReadingOnly) { if (FIniFileStorageName.IsEmpty()) { UnicodeString ProgramPath = ParamStr(0); UnicodeString ProgramIniPath = ChangeFileExt(ProgramPath, L".ini"); UnicodeString IniPath; if (FileExists(ProgramIniPath)) { IniPath = ProgramIniPath; } else { UnicodeString AppDataIniPath = IncludeTrailingBackslash(GetShellFolderPath(CSIDL_APPDATA)) + ExtractFileName(ProgramIniPath); if (FileExists(AppDataIniPath)) { IniPath = AppDataIniPath; } else { // avoid expensive test if we are interested in existing files only if (!ReadingOnly && (FProgramIniPathWrittable < 0)) { UnicodeString ProgramDir = ExtractFilePath(ProgramPath); FProgramIniPathWrittable = IsDirectoryWriteable(ProgramDir) ? 1 : 0; } // does not really matter what we return when < 0 IniPath = (FProgramIniPathWrittable == 0) ? AppDataIniPath : ProgramIniPath; } } // BACKWARD COMPATIBILITY with 4.x if (FVirtualIniFileStorageName.IsEmpty() && TPath::IsDriveRooted(IniPath)) { UnicodeString LocalAppDataPath = GetShellFolderPath(CSIDL_LOCAL_APPDATA); // virtual store for non-system drives have a different virtual store, // do not bother about them if (TPath::IsDriveRooted(LocalAppDataPath) && SameText(ExtractFileDrive(IniPath), ExtractFileDrive(LocalAppDataPath))) { FVirtualIniFileStorageName = IncludeTrailingBackslash(LocalAppDataPath) + L"VirtualStore\\" + IniPath.SubString(4, IniPath.Length() - 3); } } if (!FVirtualIniFileStorageName.IsEmpty() && FileExists(FVirtualIniFileStorageName)) { return FVirtualIniFileStorageName; } else { return IniPath; } } else { return FIniFileStorageName; } }
nsresult nsXREDirProvider::GetUserDataDirectoryHome(nsILocalFile** aFile, PRBool aLocal) { // Copied from nsAppFileLocationProvider (more or less) nsresult rv; nsCOMPtr<nsILocalFile> localDir; #if defined(MOZ_WIDGET_COCOA) FSRef fsRef; OSType folderType; if (aLocal) { folderType = kCachedDataFolderType; } else { #ifdef MOZ_THUNDERBIRD folderType = kDomainLibraryFolderType; #else folderType = kApplicationSupportFolderType; #endif } OSErr err = ::FSFindFolder(kUserDomain, folderType, kCreateFolder, &fsRef); NS_ENSURE_FALSE(err, NS_ERROR_FAILURE); rv = NS_NewNativeLocalFile(EmptyCString(), PR_TRUE, getter_AddRefs(localDir)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsILocalFileMac> dirFileMac = do_QueryInterface(localDir); NS_ENSURE_TRUE(dirFileMac, NS_ERROR_UNEXPECTED); rv = dirFileMac->InitWithFSRef(&fsRef); NS_ENSURE_SUCCESS(rv, rv); localDir = do_QueryInterface(dirFileMac, &rv); #elif defined(XP_WIN) nsString path; if (aLocal) { rv = GetShellFolderPath(CSIDL_LOCAL_APPDATA, path); #ifndef WINCE if (NS_FAILED(rv)) rv = GetRegWindowsAppDataFolder(aLocal, path); #endif } if (!aLocal || NS_FAILED(rv)) { rv = GetShellFolderPath(CSIDL_APPDATA, path); #ifndef WINCE if (NS_FAILED(rv)) { if (!aLocal) rv = GetRegWindowsAppDataFolder(aLocal, path); } #endif } NS_ENSURE_SUCCESS(rv, rv); rv = NS_NewLocalFile(path, PR_TRUE, getter_AddRefs(localDir)); #elif defined(XP_OS2) #if 0 /* For OS/2 we want to always use MOZILLA_HOME */ // we want an environment variable of the form // FIREFOX_HOME, etc if (!gAppData) return NS_ERROR_FAILURE; nsDependentCString envVar(nsDependentCString(gAppData->name)); envVar.Append("_HOME"); char *pHome = getenv(envVar.get()); #endif char *pHome = getenv("MOZILLA_HOME"); if (pHome && *pHome) { rv = NS_NewNativeLocalFile(nsDependentCString(pHome), PR_TRUE, getter_AddRefs(localDir)); } else { PPIB ppib; PTIB ptib; char appDir[CCHMAXPATH]; DosGetInfoBlocks(&ptib, &ppib); DosQueryModuleName(ppib->pib_hmte, CCHMAXPATH, appDir); *strrchr(appDir, '\\') = '\0'; rv = NS_NewNativeLocalFile(nsDependentCString(appDir), PR_TRUE, getter_AddRefs(localDir)); } #elif defined(XP_BEOS) char appDir[MAXPATHLEN]; if (find_directory(B_USER_SETTINGS_DIRECTORY, NULL, true, appDir, MAXPATHLEN)) return NS_ERROR_FAILURE; int len = strlen(appDir); appDir[len] = '/'; appDir[len+1] = '\0'; rv = NS_NewNativeLocalFile(nsDependentCString(appDir), PR_TRUE, getter_AddRefs(localDir)); #elif defined(ANDROID) // used for setting the patch to our profile // XXX: investigate putting the profile somewhere else const char* homeDir = "/data/data/org.mozilla." MOZ_APP_NAME; rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), PR_TRUE, getter_AddRefs(localDir)); #elif defined(XP_UNIX) const char* homeDir = getenv("HOME"); if (!homeDir || !*homeDir) return NS_ERROR_FAILURE; rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), PR_TRUE, getter_AddRefs(localDir)); #else #error "Don't know how to get product dir on your platform" #endif NS_IF_ADDREF(*aFile = localDir); return rv; }