bool ProjectFile::LinkFile(QString oldFile, QString newDir) { QString newLink = newDir + QDir::separator() + QFileInfo(oldFile).fileName(); #ifdef Q_OS_WIN32 newLinkName.append(".lnk"); #endif if (CheckForExistingFile(newLink)) { if (WarnFileExists(newLink)) { RemoveFile(newLink); } else { return false; } } QFile file (oldFile); if (file.exists()) { return file.link(newLink); } return false; }
//----------------------------------------------------------------------------- LISTNODE ApplyExternalProgram(LISTNODE Head,StatusType AsStatus, ANNOTATEDFORMULA Conjecture,char * ExecuteFormatString,SIGNATURE Signature) { String ProblemFileName; String ExecuteCommand; FILE * ProcessHandle; LISTNODE AppliedHead; if(!MakeProblemFile("/tmp",NULL,NULL,ProblemFileName,Head,AsStatus, Conjecture,conjecture)) { return(NULL); } if (sprintf(ExecuteCommand,ExecuteFormatString,ProblemFileName) == -1) { printf("ERROR: Cannot make command from %s\n",ExecuteFormatString); RemoveFile(ProblemFileName); return(NULL); } if ((ProcessHandle = popen(ExecuteCommand,"r")) == NULL) { perror(ExecuteCommand); printf("ERROR: Cannot execute %s\n",ExecuteCommand); RemoveFile(ProblemFileName); return(NULL); } AppliedHead = ParseFILEOfFormulae(ProcessHandle,Signature,1,NULL); pclose(ProcessHandle); RemoveFile(ProblemFileName); return(AppliedHead); }
bool RemoveFile(const string& path, bool recurse) { if (!IsDir(path)) return RemoveFile(path); if (!recurse) return RemoveDir(path); vector<string> filenames; if (GetDirEntries(path, filenames)) { string save_cwd; GetCwd(save_cwd); if (!ChangeDir(path)) return false; for (size_t i = 0; i < filenames.size(); i++) RemoveFile(filenames[i], true); if (!ChangeDir(save_cwd)) return false; } return RemoveDir(path); }
static void RemoveGambitTempFiles( const CString& appDir ) { RemoveFile( appDir + GAMBIT_JOU_FILE ); RemoveFile( appDir + GAMBIT_TRN_FILE ); RemoveFile( appDir + GAMBIT_DBS_FILE ); RemoveFile( appDir + GAMBIT_LOK_FILE ); RemoveFile( appDir + GAMBIT_ERROR_FILE ); }
void WorkspaceWork::DelFile() { if(!filelist.IsCursor() || filelist[fileindex[filelist.GetCursor()]].isdir) return; String file = GetActiveFilePath(); if(IsFolder(file)) { if(!PromptYesNo("Remove the topic group and discard ALL topics?")) return; RemoveFile(); DeleteFolderDeep(file); } else { if(!PromptYesNo("Remove the file from package and discard it ?")) return; RemoveFile(); ::DeleteFile(file); } }
void SceneryPage::CheckAutosave(int& debugPagesSaved, int& debugPropsSaved) { if(mPendingChanges == 0) return; char buffer[256]; if(mSceneryList.size() == 0) { GetFileName(buffer, sizeof(buffer)); RemoveFile(buffer); mPendingChanges = 0; } else { if(mHasSourceFile == false) { GetFolderName(buffer, sizeof(buffer)); Platform::MakeDirectory(buffer); } GetFileName(buffer, sizeof(buffer)); if(SaveFile(buffer) == true) { mPendingChanges = 0; debugPropsSaved += mSceneryList.size(); mHasSourceFile = true; } } debugPagesSaved++; }
acoral_32 acoral_unlink(const acoral_char *pathname) { acoral_u32 ret; acoral_u8 fs_ret,len; acoral_char *path; len=acoral_str_len(pathname); if(path=(acoral_char *)acoral_malloc2(len+1)) { acoral_str_cpy(path,pathname); path[len]=0; } else return -1; ret=acoral_mutex_pend(fs_mutex,0); if(ret!=MUTEX_SUCCED) { acoral_free2(path); return -1; } fs_ret=RemoveFile(path); acoral_mutex_post(fs_mutex); acoral_free2(path); if(fs_ret!=RETURN_OK) return -1; return 0; }
size_t TokensTree::ReserveFileForParsing(const wxString& filename,bool preliminary) { size_t index = GetFileIndex(filename); if(m_FilesToBeReparsed.count(index) && (!m_FilesStatus.count(index) || m_FilesStatus[index]==fpsDone)) { RemoveFile(filename); m_FilesToBeReparsed.erase(index); m_FilesStatus[index]=fpsNotParsed; } if(m_FilesStatus.count(index)) { FileParsingStatus status = m_FilesStatus[index]; if(preliminary) { if(status >= fpsAssigned) return 0; // Already assigned } else { if(status > fpsAssigned) return 0; // No parsing needed } } m_FilesToBeReparsed.erase(index); m_FilesStatus[index]=preliminary ? fpsAssigned : fpsBeingParsed; // Reserve file return index; }
int XCatch::Clear(XU8 bAll) { int nCount=0; int nTotalCount=0; ClearShared(); XStackC<XString8> paths; paths.Push(m_strWorkPath); while(paths.GetSize()>0) { XString8 strPath;//=paths[paths.GetSize()-1]; paths.Pop(strPath); //paths.RemoveAt(paths.GetSize()-1); XString8 strRoot=strPath; XFileFinder find; XU8 bEmpty=XTRUE; if(find.FindFirst(strPath))//) continue; { while(XTRUE) { //XString8 strFile=strRoot; XString8 strFile=find.cFileName; if(find.IsDirectory()) { if(strFile!="."&& strFile!="..") { strFile=strRoot; strFile += "/"; strFile+=find.cFileName; paths.Push(strFile); } } else { strFile=strRoot; strFile += "/"; strFile+=find.cFileName; nTotalCount++; if(RemoveFile(strFile,bAll)) { nCount++; } else bEmpty=XFALSE; } if(!find.FindNext()) break; } find.Close(); } nTotalCount++; find.Close(); if((bAll||bEmpty)&&strRoot!=m_strWorkPath) { XFile::RemoveFolder(strRoot); nCount++; } } return nCount; }
// add new header using the argument as a template CZipFileHeader* CZipCentralDir::AddNewFile(const CZipFileHeader & header, int iReplaceIndex) { CZipFileHeader* pHeader = new CZipFileHeader(header); m_pOpenedFile = pHeader; WORD uIndex; DWORD uOffset = 0; bool bReplace = IsValidIndex(iReplaceIndex); if (bReplace) { CZipFileHeader* pfh = m_headers[iReplaceIndex]; uOffset = pfh->m_uOffset + m_info.m_uBytesBeforeZip; RemoveFile(pfh, iReplaceIndex, false); m_headers.InsertAt(iReplaceIndex, pHeader); uIndex = (WORD)iReplaceIndex; } else uIndex = m_headers.Add(pHeader); if (m_bFindFastEnabled) InsertFindFastElement(pHeader, uIndex); // GetCount > 0, 'cos we've just added a header RemoveFromDisk(); if (bReplace) m_pStorage->m_pFile->Seek(uOffset, CZipAbstractFile::begin); else m_pStorage->m_pFile->SeekToEnd(); return pHeader; }
TimeSmoother::TimeSmoother() : pImpl(new TimeSmootherImpl) { //read in S std::string tmpFileName = CreateTemporaryEmptyFile(); WriteCharBufferToFile(tmpFileName, globalsmoothtvmatrix_dat, globalsmoothtvmatrix_dat_len); Harwell_Boeing_load(tmpFileName.c_str(), pImpl->S); RemoveFile(tmpFileName); std::string prior = WriteCharBufferToString(timevaryingprior_dat, timevaryingprior_dat_len); std::stringstream ss(std::stringstream::in | std::stringstream::out); ss << prior; for (int row = 0; row < 11; row++) { for (int col = 0; col < 134; col++) { ss >> pImpl->Priors(row, col); } for (int col = 0; col < 80; col++) { double temp; ss >> temp; // mu and theta? } } }
bool UninstallToolRecord( bool adjust_uac ) { TCHAR path_dst[MAX_PATH * 2]; if (!GetProductBinDir(path_dst, ARRAYSIZE(path_dst))) { return false; } ::PathAppend(path_dst, TEXT("toolRecord.dll")); if (INVALID_FILE_ATTRIBUTES == ::GetFileAttributes(path_dst)) { return true; } if (!RemoveFile(path_dst)) { if (adjust_uac) { if (!IsRunAsAdmin()) { TCHAR path_exe[MAX_PATH * 2]; ::GetModuleFileName(NULL, path_exe, ARRAYSIZE(path_exe)); LaunchUacApp(path_exe, TEXT("unst_tool_record"), true); } } } DWORD file_attr = GetFileAttributes(path_dst); return INVALID_FILE_ATTRIBUTES == file_attr; }
/*** SetMarkFile - Change markfile * * Purpose: * * Changes to a new markfile. * * Input: * val - String after the 'markfile' switch * * Output: * * Returns Error string if error, NULL otherwise * * Notes: * * We: * * UNDONE:o Magically ensure that the current markfile is up to date and * saved to disk. This means, at the very least, that there * can be no dirty files. * * o Remove the current markfile from the file list. * * o Read in the new markfile. * * o Invalidate all current marks. This is just marking them * invalid in the PFILE. * * *************************************************************************/ char * SetMarkFile ( char *val ) { REGISTER PFILE pFile; buffer tmpval; pathbuf pathname; strcpy ((char *) tmpval, val); if (NULL == CanonFilename (tmpval, pathname)) { sprintf (buf, "'%s': name is malformed", tmpval); return buf; } if (!(pFile = FileNameToHandle (pathname, NULL))) { pFile = AddFile (pathname); } if (!TESTFLAG(FLAGS(pFile), REAL) && !FileRead (pathname, pFile, FALSE)) { RemoveFile (pFile); sprintf (buf, "'%s' - %s", pathname, error()); return buf; } pFileMark = pFile; for (pFile = pFileHead; pFile; pFile = pFile->pFileNext) { if (!TESTFLAG(FLAGS(pFile), FAKE)) { RSETFLAG (FLAGS(pFile), VALMARKS); } } return NULL; }
size_t TokenTree::ReserveFileForParsing(const wxString& filename, bool preliminary) { const size_t fileIdx = InsertFileOrGetIndex(filename); if ( m_FilesToBeReparsed.count(fileIdx) && (!m_FileStatusMap.count(fileIdx) || m_FileStatusMap[fileIdx]==fpsDone) ) { RemoveFile(filename); m_FilesToBeReparsed.erase(fileIdx); m_FileStatusMap[fileIdx]=fpsNotParsed; } if (m_FileStatusMap.count(fileIdx)) { FileParsingStatus status = m_FileStatusMap[fileIdx]; if (preliminary) { if (status >= fpsAssigned) return 0; // Already assigned } else { if (status > fpsAssigned) return 0; // No parsing needed } } m_FilesToBeReparsed.erase(fileIdx); m_FileStatusMap[fileIdx] = preliminary ? fpsAssigned : fpsBeingParsed; // Reserve file return fileIdx; }
HRESULT CFileHelper::RemoveFolder(LPCTSTR path, BOOL removeChildren) { vector<WIN32_FIND_DATA> fileDatas; if(_ListChildren(path, fileDatas)) { for(int i=0,size = fileDatas.size() ; i<size;i++) { LPCTSTR path = fileDatas[i].cFileName; if(BIT_IS_TRUE( fileDatas[i].dwFileAttributes, FILE_ATTRIBUTE_DIRECTORY) && removeChildren) { HRESULT hr = RemoveFolder(path, removeChildren); if(FAILED(hr)) return hr; } else { HRESULT hr = RemoveFile(path); if(FAILED(hr)) return hr; } } return S_OK; } return E_FAIL; }
/* DecFileRef - remove a reference to a file * * When the reference count goes to zero, we remove the file from the memory * set */ void DecFileRef ( PFILE pFileTmp ) { if (--(pFileTmp->refCount) <= 0) { RemoveFile (pFileTmp); } }
static void DeleteChildren (dir_s *dir) { chdir(dir->name); while (!CheckEmpty(dir)) { rmdir(dir->file[0].name); RemoveFile(dir, dir->file[0].name); } chdir(".."); }
/**************************************************************************** * UpdateApp from a given url. The dol is downloaded and overwrites the old one. ***************************************************************************/ int UpdateTask::DownloadApp(const char *url) { if(!url) { ThrowMsg(tr("Error"), tr("URL is empty.")); return -1; } //! append slash if it is missing std::string destPath = Settings.UpdatePath; if(destPath.size() > 0 && destPath[destPath.size()-1] != '/') destPath += '/'; destPath += "boot.zip"; CreateSubfolder(Settings.UpdatePath); int res = DownloadFileToPath(url, destPath.c_str(), false); if(res < 102400) { RemoveFile(destPath.c_str()); ThrowMsg(tr("Update failed"), tr("Could not download file.")); return -1; } else { StartProgress(tr("Extracting file...")); ZipFile zip(destPath.c_str()); zip.ExtractAll(Settings.UpdatePath); RemoveFile(destPath.c_str()); StopProgress(); if(Settings.UpdateMetaxml) DownloadMetaXml(); if(Settings.UpdateIconpng) DownloadIconPNG(); } return 1; }
XBOOL XCatch::RemoveCatch(CONNECTREQ &req, XBOOL bForce) { if(req.URL.m_nProto>=XPROTO_FILE) return XFALSE; CONNECTINFO r; r.URL=req.URL; r.outData.Append(req.data); r.nMethod=req.nMethod; MakeFile(r); return RemoveFile(m_strFile,bForce); }
void FileCollection::AddFileFromMemory(const String &FileCollectionName, const Vector<BYTE> &Data) { _FileListMutex.Acquire(); RemoveFile(FileCollectionName); FileCollectionFile *NewFile = new FileCollectionFile; NewFile->Filename = FileCollectionName; NewFile->Data = Data; _FileList.PushEnd(NewFile); _FileMap[NewFile->Filename.CString()] = NewFile; _FileListMutex.Release(); }
/** \fn GalleryDatabaseHelper::RemoveData(ImageMetadata *) * \brief Deletes either a directory or file from the database * \param im Information of the given item * \return void */ void GalleryDatabaseHelper::RemoveData(ImageMetadata *im) { if (!im) return; if (im->m_type == kSubDirectory || im->m_type == kUpDirectory) RemoveDirectory(im); if (im->m_type == kImageFile || im->m_type == kVideoFile) RemoveFile(im); }
llvm::Module *ClangCompiler::Compile(const string &source, LLVMContext *context) const { // write the source to a temporary file and invoke the compiler string temp_tmpl = ".tmp_XXXXXX"; const char *tmpfile = UniqueFilename(temp_tmpl); //const char *tmpfile = "temp.c"; SourceToFile(tmpfile, source); FrontendOptions &opts = invocation_->getFrontendOpts(); #if CLANG_VERSION_MAJOR == 3 # if CLANG_VERSION_MINOR == 0 opts.Inputs.clear(); // clear any old inputs opts.Inputs.push_back(make_pair(IK_C, tmpfile)); # elif CLANG_VERSION_MINOR == 5 opts.Inputs.clear(); // clear any old inputs opts.Inputs.push_back(FrontendInputFile(tmpfile, IK_C)); # endif #endif // compiler_->setInvocation(invocation_.get()); compiler_->setInvocation(invocation_); // Setup diagnostics for the compilation process itself #if CLANG_VERSION_MAJOR == 3 # if CLANG_VERSION_MINOR == 0 const char *const dummy_argv[] = { "" }; compiler_->createDiagnostics(1, dummy_argv); # elif CLANG_VERSION_MINOR == 5 compiler_->createDiagnostics(); # endif #endif if (!compiler_->hasDiagnostics()) { *log_stream_ << "createDiagnostics() failed\n"; return 0; } // Compile and emit LLVM IR // OwningPtr<CodeGenAction> llvm_codegen(new EmitLLVMOnlyAction(context)); CodeGenAction *llvm_codegen(new EmitLLVMOnlyAction(context)); if (!compiler_->ExecuteAction(*llvm_codegen)) { *log_stream_ << "compilation failed: " << "generated source is in " << tmpfile << "\n"; return 0; } // Remove input file and return the compiled module if (!keep_temporaries_) RemoveFile(tmpfile); return llvm_codegen->takeModule(); }
bool plFileUtils::FileMove(const wchar_t* existingFile, const wchar_t* newFile) { #if HS_BUILD_FOR_WIN32 return (::MoveFileW(existingFile, newFile) != 0); #elif HS_BUILD_FOR_UNIX FileCopy(existingFile,newFile); return( RemoveFile( existingFile )==0); #else hsAssert(0, "Not implemented"); return false; #endif }
bool DestroyHandlerUtil (void) { bool success_flag = true; if (s_mapped_filenames_p) { size_t handler_index; json_t *handler_p; json_array_foreach (s_mapped_filenames_p, handler_index, handler_p) { const char *user_key_s; json_t *user_p; json_object_foreach (handler_p, user_key_s, user_p) { const char *obj_key_s; json_t *obj_p; json_object_foreach (user_p, obj_key_s, obj_p) { json_t *filename_p = json_object_get (obj_p, S_FILENAME_KEY_S); if (filename_p) { if (json_is_string (filename_p)) { const char *filename_s = json_string_value (filename_p); if (!RemoveFile (filename_s)) { } } } /* if (filename_p) */ } /* json_object_foreach (user_p, obj_index, obj_p) */ } /* json_object_foreach (handler_p, user_index, user_p) */ } /* json_array_foreach (s_mapped_filenames_p, handler_index, handler_p) */ if (json_array_clear (s_mapped_filenames_p) == 0) { json_decref (s_mapped_filenames_p); } else { success_flag = false; } }
int MiiAllTools::Internal_DeleteAll_Miis_Dev(std::string miiPath) { bool result = RemoveFile(miiPath.c_str()); if(AbortRequested) return -10; if (result == false) return -1; return 1; }
void FileCollection::AddFileFromDisk(const String &FileCollectionName, const String &ExistingFilename) { _FileListMutex.Acquire(); Vector<BYTE> Data; RemoveFile(FileCollectionName); if(!Utility::FileExists(ExistingFilename)) { SignalError(String("Required file not found: ") + FileCollectionName); } Utility::GetFileData(ExistingFilename, Data); AddFileFromMemory(FileCollectionName, Data); _FileListMutex.Release(); }
ERMsg CDirectoryManagerBase::DeleteFile(const std::string& fileName, const std::string& fileExt)const { ERMsg msg; std::string filePath = GetFilePath(fileName, fileExt); while (FileExists(filePath)) { msg += RemoveFile(filePath); filePath = GetFilePath(fileName, fileExt); } return msg; }
/*---------------------------------------------------------------------- | NPT_File::Remove +---------------------------------------------------------------------*/ NPT_Result NPT_File::Remove(const char* path, bool recurse /* = false */) { NPT_FileInfo info; // make sure the path exists NPT_CHECK_WARNING(GetInfo(path, &info)); if (info.m_Type == NPT_FileInfo::FILE_TYPE_DIRECTORY) { return RemoveDir(path, recurse); } else { return RemoveFile(path); } }
bool plFileUtils::RemoveFile(const wchar_t* filename, bool delReadOnly) { #ifdef HS_BUILD_FOR_WIN32 if (delReadOnly) _wchmod(filename, S_IWRITE); return (_wunlink(filename) == 0); #elif HS_BUILD_FOR_UNIX const char* cfilename = hsWStringToString(filename); bool ret = RemoveFile(cfilename, delReadOnly); delete[] cfilename; /* Free the string */ return ret; #endif }
int main( int argc, char *argv[] ) { DEBUG_BREAK; #if defined (LOCAL_DEBUG) qDebug() << "Decrypted rads_password to" << decrypt( "AwKel0QzUiZmEkIw", 89473829 ); //AwKqGyUhayqpheog or AwIfrpCU3p8cMF+V with default_key? qDebug() << "Encrypted rads_password to" << encrypt( "rat@tu1", 89473829 ); qDebug() << "Encrypted rads_password to" << encrypt( "rat@tu1", 89473829 ); QString to_decrypt = encrypt( "rat@tu1", 89473829 ); //AwKqGyUhayqpheog with default_key qDebug() << "Encrypted rads_password to" << to_decrypt; qDebug() << "Decrypted rads_password to" << decrypt( to_decrypt, 89473829 ); #endif #if !defined(Q_OS_WIN) // QtService stores service settings in SystemScope, which normally require root privileges. // To allow testing this example as non-root, we change the directory of the SystemScope settings file. QSettings::setPath(QSettings::NativeFormat, QSettings::SystemScope, QDir::tempPath()); qWarning("(Example uses dummy settings file: %s/QtSoftware.conf)", QDir::tempPath().toLatin1().constData()); #endif const CApplicationStaticPaths brat_paths( argv[ 0 ], RADS_SERVICE_NAME ); const std::string log_path = brat_paths.mExecutableDir + "/RadsServiceLog.txt"; qputenv( "QGIS_LOG_FILE", log_path.c_str() ); if ( IsFile( log_path ) ) { QFileInfo info( log_path.c_str() ); if ( info.size() > 10000 ) { std::string old_path = CreateUniqueFileName( log_path ); //old_path is a new path, to save old contents if ( old_path.empty() || !DuplicateFile( log_path, old_path ) ) //save "old" file LOG_WARN( "Could not create new log file. Trying to use existing one." ); else RemoveFile( log_path ); } } #if defined (LOCAL_DEBUG) QCoreApplication service( argc, argv ); new CRadsDaemon( brat_paths ); return service.exec(); #else CRadsService service( argc, argv, brat_paths ); return service.exec(); #endif }