NS_IMETHODIMP nsMailWinSearchHelper::RunSetup(PRBool aEnable) { nsresult rv; if (!mCurProcD) { rv = NS_GetSpecialDirectory("CurProcD", getter_AddRefs(mCurProcD)); NS_ENSURE_SUCCESS(rv, rv); rv = mCurProcD->Append(NS_LITERAL_STRING("WSEnable.exe")); NS_ENSURE_SUCCESS(rv, rv); } nsAutoString filePath; rv = mCurProcD->GetPath(filePath); NS_ENSURE_SUCCESS(rv, rv); // The parameters are of the format "1 <path>" for enabling and "0 <path>" for disabling nsAutoString params(aEnable ? NS_LITERAL_STRING("1 \"") : NS_LITERAL_STRING("0 \"")); nsAutoString profDPath; rv = mProfD->GetPath(profDPath); NS_ENSURE_SUCCESS(rv, rv); params.Append(profDPath); params.Append(NS_LITERAL_STRING("\"")); // We need an hWnd to cause UAC to pop up immediately // If GetForegroundWindow returns NULL, then the UAC prompt will still appear, // but minimized. HWND hWnd = GetForegroundWindow(); SHELLEXECUTEINFOW executeInfo = {0}; executeInfo.cbSize = sizeof(SHELLEXECUTEINFOW); executeInfo.hwnd = hWnd; executeInfo.fMask = SEE_MASK_NOCLOSEPROCESS; executeInfo.lpDirectory = NULL; executeInfo.lpFile = filePath.get(); executeInfo.lpParameters = params.get(); executeInfo.nShow = SW_SHOWNORMAL; DWORD dwRet; if (ShellExecuteExW(&executeInfo)) { // We want to block until the program exits DWORD dwSignaled = WaitForSingleObject(executeInfo.hProcess, INFINITE); if (dwSignaled == WAIT_OBJECT_0) if (!GetExitCodeProcess(executeInfo.hProcess, &dwRet)) dwRet = GetLastError(); } else return NS_ERROR_ABORT; return SUCCEEDED(HRESULT_FROM_WIN32(dwRet)) ? NS_OK : NS_ERROR_FAILURE; }
NS_IMETHOD Run() { MOZ_ASSERT(NS_IsMainThread()); nsCOMPtr<nsIFile> tmpFile; nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tmpFile)); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } tmpFile->GetPath(mPath); return NS_OK; }
void nsDogbertProfileMigrator::GetSourceProfile(const PRUnichar* aProfile) { nsresult rv; nsCOMPtr<nsIFile> regFile; rv = NS_GetSpecialDirectory(OLDREG_DIR, getter_AddRefs(regFile)); if (NS_FAILED(rv)) return; regFile->AppendNative(NS_LITERAL_CSTRING(OLDREG_NAME)); nsCAutoString path; rv = regFile->GetNativePath(path); if (NS_FAILED(rv)) return; if (NR_StartupRegistry()) return; HREG reg = nsnull; RKEY profile = nsnull; if (NR_RegOpen(path.get(), ®)) goto cleanup; { // on macos, registry entries are UTF8 encoded NS_ConvertUTF16toUTF8 profileName(aProfile); if (NR_RegGetKey(reg, ROOTKEY_USERS, profileName.get(), &profile)) goto cleanup; } char profilePath[MAXPATHLEN]; if (NR_RegGetEntryString(reg, profile, "ProfileLocation", profilePath, MAXPATHLEN)) goto cleanup; mSourceProfile = do_CreateInstance("@mozilla.org/file/local;1"); if (!mSourceProfile) goto cleanup; { // the string is UTF8 encoded, which forces us to do some strange string-do rv = mSourceProfile->InitWithPath(NS_ConvertUTF8toUTF16(profilePath)); } if (NS_FAILED(rv)) mSourceProfile = nsnull; cleanup: if (reg) NR_RegClose(reg); NR_ShutdownRegistry(); }
/* void Load (); */ NS_IMETHODIMP mozPersonalDictionary::Load() { //FIXME Deinst -- get dictionary name from prefs; nsresult res; nsCOMPtr<nsIFile> theFile; PRBool dictExists; res = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(theFile)); if(NS_FAILED(res)) return res; if(!theFile)return NS_ERROR_FAILURE; res = theFile->Append(NS_LITERAL_STRING(MOZ_PERSONAL_DICT_NAME)); if(NS_FAILED(res)) return res; res = theFile->Exists(&dictExists); if(NS_FAILED(res)) return res; if (!dictExists) { // Nothing is really wrong... return NS_OK; } nsCOMPtr<nsIInputStream> inStream; NS_NewLocalFileInputStream(getter_AddRefs(inStream), theFile); nsCOMPtr<nsIUnicharInputStream> convStream; res = nsSimpleUnicharStreamFactory::GetInstance()-> CreateInstanceFromUTF8Stream(inStream, getter_AddRefs(convStream)); if(NS_FAILED(res)) return res; // we're rereading to get rid of the old data -- we shouldn't have any, but... mDictionaryTable.Clear(); PRUnichar c; PRUint32 nRead; PRBool done = PR_FALSE; do{ // read each line of text into the string array. if( (NS_OK != convStream->Read(&c, 1, &nRead)) || (nRead != 1)) break; while(!done && ((c == '\n') || (c == '\r'))){ if( (NS_OK != convStream->Read(&c, 1, &nRead)) || (nRead != 1)) done = PR_TRUE; } if (!done){ nsAutoString word; while((c != '\n') && (c != '\r') && !done){ word.Append(c); if( (NS_OK != convStream->Read(&c, 1, &nRead)) || (nRead != 1)) done = PR_TRUE; } mDictionaryTable.PutEntry(word.get()); } } while(!done); mDirty = PR_FALSE; return res; }
nsresult nsResProtocolHandler::AddSpecialDir(const char* aSpecialDir, const nsACString& aSubstitution) { nsCOMPtr<nsIFile> file; nsresult rv = NS_GetSpecialDirectory(aSpecialDir, getter_AddRefs(file)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIURI> uri; rv = mIOService->NewFileURI(file, getter_AddRefs(uri)); NS_ENSURE_SUCCESS(rv, rv); return SetSubstitution(aSubstitution, uri); }
bool GetEMEVoucherPath(nsIFile** aPath) { nsCOMPtr<nsIFile> path; NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(path)); if (!path) { NS_WARNING("GetEMEVoucherPath can't get NS_GRE_DIR!"); return false; } path->AppendNative(NS_LITERAL_CSTRING("voucher.bin")); path.forget(aPath); return true; }
void InitLateWriteChecks() { nsCOMPtr<nsIFile> mozFile; NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(mozFile)); if (mozFile) { nsAutoCString nativePath; nsresult rv = mozFile->GetNativePath(nativePath); if (NS_SUCCEEDED(rv) && nativePath.get()) { sLateWriteObserver = new LateWriteObserver(nativePath.get()); } } }
/* readonly attribute nsILocalFile binDir; */ NS_IMETHODIMP nsXPCToolsCompiler::GetBinDir(nsILocalFile * *aBinDir) { *aBinDir = nsnull; nsCOMPtr<nsIFile> file; nsresult rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, getter_AddRefs(file)); if(NS_FAILED(rv)) return rv; nsCOMPtr<nsILocalFile> lfile = do_QueryInterface(file); NS_ADDREF(*aBinDir = lfile); return NS_OK; }
nsresult LocalStoreImpl::LoadData() { nsresult rv; // Look for localstore.rdf in the current profile // directory. Bomb if we can't find it. nsCOMPtr<nsIFile> aFile; rv = NS_GetSpecialDirectory(NS_APP_LOCALSTORE_50_FILE, getter_AddRefs(aFile)); if (NS_FAILED(rv)) return rv; bool fileExistsFlag = false; (void)aFile->Exists(&fileExistsFlag); if (!fileExistsFlag) { // if file doesn't exist, create it rv = CreateLocalStore(aFile); if (NS_FAILED(rv)) return rv; } mInner = do_CreateInstance(NS_RDF_DATASOURCE_CONTRACTID_PREFIX "xml-datasource", &rv); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(mInner, &rv); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIURI> aURI; rv = NS_NewFileURI(getter_AddRefs(aURI), aFile); if (NS_FAILED(rv)) return rv; nsCAutoString spec; rv = aURI->GetSpec(spec); if (NS_FAILED(rv)) return rv; rv = remote->Init(spec.get()); if (NS_FAILED(rv)) return rv; // Read the datasource synchronously. rv = remote->Refresh(true); if (NS_FAILED(rv)) { // Load failed, delete and recreate a fresh localstore aFile->Remove(true); rv = CreateLocalStore(aFile); if (NS_FAILED(rv)) return rv; rv = remote->Refresh(true); } return rv; }
nsresult sbTemporaryFileService::Initialize() { nsresult rv; // Add observers. if (!mObserverService) { mObserverService = do_GetService("@mozilla.org/observer-service;1", &rv); NS_ENSURE_SUCCESS(rv, rv); rv = mObserverService->AddObserver(this, "profile-after-change", PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); rv = mObserverService->AddObserver(this, "quit-application", PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); } // Wait for the user profile to be available. if (!mProfileAvailable) return NS_OK; // Set up the root temporary directory residing in the OS temporary directory. nsCOMPtr<nsIFile> rootTemporaryDirectory; rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(rootTemporaryDirectory)); NS_ENSURE_SUCCESS(rv, rv); // Ensure the root temporary directory exists. bool exists; rv = rootTemporaryDirectory->Append (NS_LITERAL_STRING(SB_TEMPORARY_FILE_SERVICE_ROOT_DIR_NAME)); NS_ENSURE_SUCCESS(rv, rv); rv = rootTemporaryDirectory->Exists(&exists); NS_ENSURE_SUCCESS(rv, rv); if (!exists) { rv = rootTemporaryDirectory->Create(nsIFile::DIRECTORY_TYPE, SB_DEFAULT_DIRECTORY_PERMISSIONS); NS_ENSURE_SUCCESS(rv, rv); } // Create the root temporary file factory. mRootTemporaryFileFactory = do_CreateInstance("@songbirdnest.com/Songbird/TemporaryFileFactory;1", &rv); NS_ENSURE_SUCCESS(rv, rv); rv = mRootTemporaryFileFactory->SetRootTemporaryDirectory (rootTemporaryDirectory); NS_ENSURE_SUCCESS(rv, rv); // Services are now initialized. mInitialized = PR_TRUE; return NS_OK; }
NS_IMETHODIMP nsAbManager::GetUserProfileDirectory(nsILocalFile **userDir) { NS_ENSURE_ARG_POINTER(userDir); *userDir = nsnull; nsresult rv; nsCOMPtr<nsIFile> profileDir; nsCAutoString pathBuf; rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(profileDir)); NS_ENSURE_SUCCESS(rv, rv); return CallQueryInterface(profileDir, userDir); }
nsresult nsSafariProfileMigrator::CopyOtherData(bool aReplace) { // Get the Safari user style sheet and copy it into the active profile's // chrome folder nsCOMPtr<nsILocalFile> stylesheetFile; if (NS_SUCCEEDED(GetSafariUserStyleSheet(getter_AddRefs(stylesheetFile)))) { nsCOMPtr<nsIFile> userChromeDir; NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR, getter_AddRefs(userChromeDir)); stylesheetFile->CopyTo(userChromeDir, NS_LITERAL_STRING("userContent.css")); } return NS_OK; }
void nsSuiteDirectoryProvider::EnsureProfileFile(const nsACString& aLeafName, nsIFile* aParentDir, nsIFile* aTarget) { nsCOMPtr<nsIFile> defaults; NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_50_DIR, getter_AddRefs(defaults)); if (!defaults) return; defaults->AppendNative(aLeafName); defaults->CopyToNative(aParentDir, aLeafName); }
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; }
void InitWritePoisoning() { // Stdout and Stderr are OK. MozillaRegisterDebugFD(1); MozillaRegisterDebugFD(2); nsCOMPtr<nsIFile> mozFile; NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(mozFile)); if (mozFile) { nsAutoCString nativePath; nsresult rv = mozFile->GetNativePath(nativePath); if (NS_SUCCEEDED(rv)) { sProfileDirectory = PL_strdup(nativePath.get()); } } }
nsSpamSettings::nsSpamSettings() { mLevel = 0; mMoveOnSpam = false; mMoveTargetMode = nsISpamSettings::MOVE_TARGET_MODE_ACCOUNT; mPurge = false; mPurgeInterval = 14; // 14 days mServerFilterTrustFlags = 0; mUseWhiteList = false; mUseServerFilter = false; nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(mLogFile)); if (NS_SUCCEEDED(rv)) mLogFile->Append(NS_LITERAL_STRING("junklog.html")); }
// see the comment in GLLibraryEGL::EnsureInitialized() for the rationale here. static PRLibrary* LoadLibraryForEGLOnWindows(const nsAString& filename) { nsCOMPtr<nsIFile> file; nsresult rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(file)); if (NS_FAILED(rv)) return nullptr; file->Append(filename); PRLibrary* lib = nullptr; rv = file->Load(&lib); if (NS_FAILED(rv)) { nsPrintfCString msg("Failed to load %s - Expect EGL initialization to fail", NS_LossyConvertUTF16toASCII(filename).get()); NS_WARNING(msg.get()); } return lib; }
NS_IMETHODIMP nsDogbertProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult) { if (!mProfiles) { nsresult rv; mProfiles = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIFile> regFile; rv = NS_GetSpecialDirectory(OLDREG_DIR, getter_AddRefs(regFile)); NS_ENSURE_SUCCESS(rv, rv); regFile->AppendNative(NS_LITERAL_CSTRING(OLDREG_NAME)); nsCAutoString path; rv = regFile->GetNativePath(path); NS_ENSURE_SUCCESS(rv, rv); if (NR_StartupRegistry()) return NS_ERROR_FAILURE; HREG reg = nsnull; REGENUM enumstate = 0; if (NR_RegOpen(path.get(), ®)) { NR_ShutdownRegistry(); return NS_ERROR_FAILURE; } char profileName[MAXREGNAMELEN]; while (!NR_RegEnumSubkeys(reg, ROOTKEY_USERS, &enumstate, profileName, MAXREGNAMELEN, REGENUM_CHILDREN)) { nsCOMPtr<nsISupportsString> nameString (do_CreateInstance("@mozilla.org/supports-string;1")); if (nameString) { nameString->SetData(NS_ConvertUTF8toUTF16(profileName)); mProfiles->AppendElement(nameString); } } } NS_IF_ADDREF(*aResult = mProfiles); return NS_OK; }
nsresult nsGNOMEShellService::Init() { nsresult rv; // Check G_BROKEN_FILENAMES. If it's set, then filenames in glib use // the locale encoding. If it's not set, they use UTF-8. mUseLocaleFilenames = PR_GetEnv("G_BROKEN_FILENAMES") != nullptr; nsCOMPtr<nsIFile> appPath; rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, getter_AddRefs(appPath)); NS_ENSURE_SUCCESS(rv, rv); rv = appPath->AppendNative(NS_LITERAL_CSTRING(MOZ_APP_NAME)); NS_ENSURE_SUCCESS(rv, rv); return appPath->GetNativePath(mAppPath); }
void nsSuiteDirectoryProvider::EnsureProfileFile(const nsACString& aLeafName, nsIFile* aParentDir, nsIFile* aTarget) { nsCOMPtr<nsIFile> defaultsDir; NS_GetSpecialDirectory(NS_APP_DEFAULTS_50_DIR, getter_AddRefs(defaultsDir)); if (!defaultsDir) return; nsresult rv = defaultsDir->AppendNative(NS_LITERAL_CSTRING("profile")); NS_ENSURE_SUCCESS_VOID(rv); defaultsDir->AppendNative(aLeafName); defaultsDir->CopyToNative(aParentDir, aLeafName); }
nsresult nsPrefService::UseDefaultPrefFile() { nsresult rv, rv2; nsCOMPtr<nsIFile> aFile; rv = NS_GetSpecialDirectory(NS_APP_PREFS_50_FILE, getter_AddRefs(aFile)); if (NS_SUCCEEDED(rv)) { rv = ReadAndOwnUserPrefFile(aFile); // Most likely cause of failure here is that the file didn't // exist, so save a new one. mUserPrefReadFailed will be // used to catch an error in actually reading the file. if (NS_FAILED(rv)) { rv2 = SavePrefFileInternal(aFile); NS_ASSERTION(NS_SUCCEEDED(rv2), "Failed to save new shared pref file"); } } return rv; }
static UniquePtr<LookupCacheV4> SetupLookupCacheV4(const _PrefixArray& prefixArray) { nsCOMPtr<nsIFile> file; NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(file)); file->AppendNative(GTEST_SAFEBROWSING_DIR); UniquePtr<LookupCacheV4> cache = MakeUnique<LookupCacheV4>(GTEST_TABLE, EmptyCString(), file); nsresult rv = cache->Init(); EXPECT_EQ(rv, NS_OK); PrefixStringMap map; PrefixArrayToPrefixStringMap(prefixArray, map); rv = cache->Build(map); EXPECT_EQ(rv, NS_OK); return Move(cache); }
/* void Save (); */ NS_IMETHODIMP mozPersonalDictionary::Save() { nsCOMPtr<nsIFile> theFile; nsresult res; if(!mDirty) return NS_OK; //FIXME Deinst -- get dictionary name from prefs; res = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(theFile)); if(NS_FAILED(res)) return res; if(!theFile)return NS_ERROR_FAILURE; res = theFile->Append(NS_LITERAL_STRING(MOZ_PERSONAL_DICT_NAME)); if(NS_FAILED(res)) return res; nsCOMPtr<nsIOutputStream> outStream; NS_NewSafeLocalFileOutputStream(getter_AddRefs(outStream), theFile, PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE ,0664); // get a buffered output stream 4096 bytes big, to optimize writes nsCOMPtr<nsIOutputStream> bufferedOutputStream; res = NS_NewBufferedOutputStream(getter_AddRefs(bufferedOutputStream), outStream, 4096); if (NS_FAILED(res)) return res; nsTArray<nsString> array(mDictionaryTable.Count()); mDictionaryTable.EnumerateEntries(AddHostToStringArray, &array); uint32_t bytesWritten; nsAutoCString utf8Key; for (uint32_t i = 0; i < array.Length(); ++i ) { CopyUTF16toUTF8(array[i], utf8Key); bufferedOutputStream->Write(utf8Key.get(), utf8Key.Length(), &bytesWritten); bufferedOutputStream->Write("\n", 1, &bytesWritten); } nsCOMPtr<nsISafeOutputStream> safeStream = do_QueryInterface(bufferedOutputStream); NS_ASSERTION(safeStream, "expected a safe output stream!"); if (safeStream) { res = safeStream->Finish(); if (NS_FAILED(res)) { NS_WARNING("failed to save personal dictionary file! possible data loss"); } } return res; }
void test_file_perms() { nsCOMPtr<nsIFile> profDir; nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(profDir)); nsCOMPtr<nsILocalFile> sqlite_file = do_QueryInterface(profDir); sqlite_file->Append(NS_LITERAL_STRING("places.sqlite")); PRUint32 perms = 0; sqlite_file->GetPermissions(&perms); // This reflexts the permissions defined by SQLITE_DEFAULT_FILE_PERMISSIONS in // db/sqlite3/src/Makefile.in and must be kept in sync with that #ifdef ANDROID do_check_true(perms == PR_IRUSR | PR_IWUSR); #else do_check_true(perms == PR_IRUSR | PR_IWUSR | PR_IRGRP | PR_IWGRP | PR_IROTH | PR_IWOTH); #endif }
// Ensures that we have no old ICO files left in the jump list cache nsresult JumpListBuilder::RemoveIconCacheForAllItems() { // Construct the path of our jump list cache nsCOMPtr<nsIFile> jumpListCacheDir; nsresult rv = NS_GetSpecialDirectory("ProfLDS", getter_AddRefs(jumpListCacheDir)); NS_ENSURE_SUCCESS(rv, rv); rv = jumpListCacheDir->AppendNative(nsDependentCString( mozilla::widget::FaviconHelper::kJumpListCacheDir)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsISimpleEnumerator> entries; rv = jumpListCacheDir->GetDirectoryEntries(getter_AddRefs(entries)); NS_ENSURE_SUCCESS(rv, rv); // Loop through each directory entry and remove all ICO files found do { bool hasMore = false; if (NS_FAILED(entries->HasMoreElements(&hasMore)) || !hasMore) break; nsCOMPtr<nsISupports> supp; if (NS_FAILED(entries->GetNext(getter_AddRefs(supp)))) break; nsCOMPtr<nsIFile> currFile(do_QueryInterface(supp)); nsAutoString path; if (NS_FAILED(currFile->GetPath(path))) continue; int32_t len = path.Length(); if (StringTail(path, 4).LowerCaseEqualsASCII(".ico")) { // Check if the cached ICO file exists bool exists; if (NS_FAILED(currFile->Exists(&exists)) || !exists) continue; // We found an ICO file that exists, so we should remove it currFile->Remove(false); } } while(true); return NS_OK; }
nsCOMPtr<nsIFile> DriverCrashGuard::GetGuardFile() { MOZ_ASSERT(XRE_IsParentProcess()); nsCString filename; filename.Assign(sCrashGuardNames[size_t(mType)]); filename.Append(".guard"); nsCOMPtr<nsIFile> file; NS_GetSpecialDirectory(NS_APP_USER_PROFILE_LOCAL_50_DIR, getter_AddRefs(file)); if (!file) { return nullptr; } if (!NS_SUCCEEDED(file->AppendNative(filename))) { return nullptr; } return file; }
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; }
nsresult nsPrefService::UseUserPrefFile() { nsresult rv = NS_OK; nsCOMPtr<nsIFile> aFile; nsDependentCString prefsDirProp(NS_APP_PREFS_50_DIR); rv = NS_GetSpecialDirectory(prefsDirProp.get(), getter_AddRefs(aFile)); if (NS_SUCCEEDED(rv) && aFile) { rv = aFile->AppendNative(NS_LITERAL_CSTRING("user.js")); if (NS_SUCCEEDED(rv)) { PRBool exists = PR_FALSE; aFile->Exists(&exists); if (exists) { rv = openPrefFile(aFile); } else { rv = NS_ERROR_FILE_NOT_FOUND; } } } return rv; }
nsresult nsAutoConfig::writeFailoverFile() { nsresult rv; nsCOMPtr<nsIFile> failoverFile; nsCOMPtr<nsIOutputStream> outStr; PRUint32 amt; rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(failoverFile)); if (NS_FAILED(rv)) return rv; failoverFile->AppendNative(NS_LITERAL_CSTRING("failover.jsc")); rv = NS_NewLocalFileOutputStream(getter_AddRefs(outStr), failoverFile); if (NS_FAILED(rv)) return rv; rv = outStr->Write(mBuf.get(),mBuf.Length(),&amt); outStr->Close(); return rv; }
//------------------------------------------------------------------------- nsIFile* DataStruct::GetFileSpec(const char * aFileName) { nsIFile* cacheFile; NS_GetSpecialDirectory(NS_OS_TEMP_DIR, &cacheFile); if (cacheFile == nullptr) return nullptr; // if the param aFileName contains a name we should use that // because the file probably already exists // otherwise create a unique name if (!aFileName) { cacheFile->AppendNative(NS_LITERAL_CSTRING("clipboardcache")); cacheFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600); } else { cacheFile->AppendNative(nsDependentCString(aFileName)); } return cacheFile; }