/////////////////////////////////////////////////////////////////////// // Function: SetExistingTimes // // Author: $author$ // Date: 7/3/2009 /////////////////////////////////////////////////////////////////////// virtual EvError SetExistingTimes (const EvFileSystemEntry& fileEntry, const char* chars, LONG length=-1) { EvError error = EV_ERROR_FAILED; #if defined(WIN32) // Windows EvError error2; if ((m_findChars = GetFindName(chars, length))) if (!(error2 = m_win32File. Open(m_findChars, GENERIC_WRITE))) { error = SetFileTimes(fileEntry); Close(); } #else // defined(WIN32) // Unix int err; if ((m_findChars = GetFindName(chars, length))) if (!(err = stat(m_findChars, &m_st))) error = SetFileTimes(fileEntry); #endif // defined(WIN32) return error; }
void ObjExtract (const char* Name) /* Extract a module from the library */ { FILE* Obj; /* Make a module name from the file name */ const char* Module = GetModule (Name); /* Try to find the module in the library */ const ObjData* O = FindObjData (Module); /* Bail out if the module does not exist */ if (O == 0) { Error ("Module `%s' not found in library `%s'", Module, LibName); } /* Open the output file */ Obj = fopen (Name, "w+b"); if (Obj == 0) { Error ("Cannot open target file `%s': %s", Name, strerror (errno)); } /* Copy the complete object file data from the library to the new object * file. */ LibCopyFrom (O->Start, O->Size, Obj); /* Close the file */ if (fclose (Obj) != 0) { Error ("Problem closing object file `%s': %s", Name, strerror (errno)); } /* Set access and modification time */ if (SetFileTimes (Name, O->MTime) != 0) { Error ("Cannot set mod time on `%s': %s", Name, strerror (errno)); } }
DWORD CCpDialog::UpdateFolder(LPCSTR strSrcFolder, LPCSTR strDstFolder, bool bIncludeSubFolders) { CString strSrcPath = strSrcFolder + CString("*.*"); DWORD dwFileCount = 0; CFileFind FileFind; BOOL bFound = FileFind.FindFile(strSrcPath); while (bFound) { bFound = FileFind.FindNextFile(); if (FileFind.IsDots()) continue; CString strSrcFilePath = FileFind.GetFilePath(); CString strSrcFileName = FileFind.GetFileName(); if (FileFind.IsDirectory()) { if (!bIncludeSubFolders) continue; CString strNewDstFolder = CString(strDstFolder) + strSrcFileName + "\\"; bool bCreated = !!::CreateDirectory(strNewDstFolder, NULL); if (bCreated) dwFileCount++; CString strNewSrcFolder = strSrcFilePath + "\\"; dwFileCount += UpdateFolder(strNewSrcFolder, strNewDstFolder); continue; } FILETIME SrcCreationTime; FILETIME SrcAccessedTime; FILETIME SrcModfiedTime; FileFind.GetCreationTime(&SrcCreationTime); FileFind.GetLastAccessTime(&SrcAccessedTime); FileFind.GetLastWriteTime(&SrcModfiedTime); CString strDstFilePath = CString(strDstFolder) + strSrcFileName; if (FileExists(strDstFilePath)) { FILETIME DstCreationTime; FILETIME DstAccessedTime; FILETIME DstModfiedTime; bool bOK = GetFileTimes(strDstFilePath, DstCreationTime, DstAccessedTime, DstModfiedTime); if (CFileTime(SrcModfiedTime) <= CFileTime(DstModfiedTime)) continue; DWORD dwFileAttributes = ::GetFileAttributes(strDstFilePath); if (dwFileAttributes && FILE_ATTRIBUTE_READONLY) ::SetFileAttributes(strDstFilePath, dwFileAttributes & ~FILE_ATTRIBUTE_READONLY); } bool bCopied = !!::CopyFile(strSrcFilePath, strDstFilePath, false/*bFailIfExists*/); if (bCopied) { dwFileCount++; SetFileTimes(strDstFilePath, SrcCreationTime, SrcAccessedTime, SrcModfiedTime); } } FileFind.Close(); return dwFileCount; }