NS_IMETHODIMP nsMailDirProvider::GetFile(const char *aKey, bool *aPersist, nsIFile **aResult) { // NOTE: This function can be reentrant through the NS_GetSpecialDirectory // call, so be careful not to cause infinite recursion. // i.e. the check for supported files must come first. const char* leafName = nullptr; bool isDirectory = true; if (!strcmp(aKey, NS_APP_MAIL_50_DIR)) leafName = MAIL_DIR_50_NAME; else if (!strcmp(aKey, NS_APP_IMAP_MAIL_50_DIR)) leafName = IMAP_MAIL_DIR_50_NAME; else if (!strcmp(aKey, NS_APP_NEWS_50_DIR)) leafName = NEWS_DIR_50_NAME; else if (!strcmp(aKey, NS_APP_MESSENGER_FOLDER_CACHE_50_FILE)) { isDirectory = false; leafName = MSG_FOLDER_CACHE_DIR_50_NAME; } else return NS_ERROR_FAILURE; nsCOMPtr<nsIFile> parentDir; nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(parentDir)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIFile> file; rv = parentDir->Clone(getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; nsDependentCString leafStr(leafName); rv = file->AppendNative(leafStr); if (NS_FAILED(rv)) return rv; bool exists; if (isDirectory && NS_SUCCEEDED(file->Exists(&exists)) && !exists) rv = EnsureDirectory(file); *aPersist = true; file.forget(aResult); return rv; }
NS_IMETHODIMP nsSuiteDirectoryProvider::GetFile(const char *aKey, PRBool *aPersist, nsIFile* *aResult) { // NOTE: This function can be reentrant through the NS_GetSpecialDirectory // call, so be careful not to cause infinite recursion. // i.e. the check for supported files must come first. const char* leafName = nsnull; if (!strcmp(aKey, NS_APP_BOOKMARKS_50_FILE)) leafName = "bookmarks.html"; else if (!strcmp(aKey, NS_APP_USER_PANELS_50_FILE)) leafName = "panels.rdf"; else if (!strcmp(aKey, NS_APP_SEARCH_50_FILE)) leafName = "search.rdf"; else return NS_ERROR_FAILURE; nsCOMPtr<nsIFile> parentDir; nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(parentDir)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIFile> file; rv = parentDir->Clone(getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; nsDependentCString leafStr(leafName); file->AppendNative(leafStr); PRBool exists; if (NS_SUCCEEDED(file->Exists(&exists)) && !exists) EnsureProfileFile(leafStr, parentDir, file); *aPersist = PR_TRUE; NS_IF_ADDREF(*aResult = file); return NS_OK; }