BOOL CopyCheck( CHAR *pchPath, FILENAME *fnCurrent ) { WORD wFatDate; WORD wFatTime; WORD wDATFatDate; WORD wDATFatTime; BOOL b; if ( fnCurrent->dwDATFileSizeLow != fnCurrent->dwFileSizeLow ) { return( TRUE ); } if ( fnCurrent->dwDATFileSizeHigh != fnCurrent->dwFileSizeHigh ) { return( TRUE ); } b = FileTimeToDosDateTime( &fnCurrent->ftDATFileTime, &wDATFatDate, &wDATFatTime ); if ( !b ) { return( TRUE ); } b = FileTimeToDosDateTime( &fnCurrent->ftFileTime, &wFatDate, &wFatTime ); if ( !b ) { return( TRUE ); } if ( wDATFatTime != wFatTime ) { return( TRUE ); } if ( wDATFatDate != wFatDate ) { return( TRUE ); } return( FALSE ); }
static INT_PTR CDECL fci_get_open_info( char *name, USHORT *date, USHORT *time, USHORT *attribs, int *err, void *ptr ) { HANDLE handle; BY_HANDLE_FILE_INFORMATION info; WCHAR *p, *nameW = strdupAtoW( CP_UTF8, name ); handle = CreateFileW( nameW, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL ); if (handle == INVALID_HANDLE_VALUE) { *err = GetLastError(); WINE_ERR( "failed to open %s: error %u\n", wine_dbgstr_w(nameW), *err ); cab_free( nameW ); return -1; } if (!GetFileInformationByHandle( handle, &info )) { *err = GetLastError(); CloseHandle( handle ); cab_free( nameW ); return -1; } FileTimeToDosDateTime( &info.ftLastWriteTime, date, time ); *attribs = info.dwFileAttributes & (_A_RDONLY | _A_HIDDEN | _A_SYSTEM | _A_ARCH); for (p = nameW; *p; p++) if (*p >= 0x80) break; if (*p) *attribs |= _A_NAME_IS_UTF; cab_free( nameW ); return (INT_PTR)handle; }
DOS_TIME DateTimeFile( LPSTR DirName, LPSTR FileName ) { char path[ DB_MAX_PATH_LENGTH ] = { 0 }; WIN32_FIND_DATA FindFileData; HDIR FindHandle; DOS_TIME FileDateTime; if (DirName == NULL || DirName[0] == '\0') { FindHandle = FindFirstFile( FileName, &FindFileData ); } else { sprintf( path, "%s" PATH_SEPARATOR "%s", DirName, FileName ); FindHandle = FindFirstFile( path, &FindFileData ); } if (FindHandle == (HDIR)INVALID_HANDLE_VALUE) { FileDateTime.value = 0; } else { FindClose( FindHandle ); FileDateTime.value = 0; FileTimeToDosDateTime( &FindFileData.ftLastWriteTime, &FileDateTime.time.wDate, &FileDateTime.time.wTime ); } return( FileDateTime ); }
static FNFCIGETOPENINFO(cb_getopeninfo) { BY_HANDLE_FILE_INFORMATION bhfi; FILETIME filetime; HANDLE handle; /* Need Win32 handle to get time stamps */ handle = CreateFile(pszName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (handle == INVALID_HANDLE_VALUE) return -1; if (GetFileInformationByHandle(handle, &bhfi) == FALSE) { CloseHandle(handle); return -1; } FileTimeToLocalFileTime(&bhfi.ftLastWriteTime, &filetime); FileTimeToDosDateTime(&filetime, pdate, ptime); *pattribs = (int)(bhfi.dwFileAttributes & (_A_RDONLY | _A_SYSTEM | _A_HIDDEN | _A_ARCH)); CloseHandle(handle); return _open(pszName, _O_RDONLY | _O_BINARY | O_NOINHERIT); }
DWORD WINAPI demFileFindNext(OUT PVOID lpFindFileData) { WIN32_FIND_DATAA FindData; PDOS_FIND_FILE_BLOCK FindFileBlock = (PDOS_FIND_FILE_BLOCK)lpFindFileData; do { if (!FindNextFileA(FindFileBlock->SearchHandle, &FindData)) return GetLastError(); /* Update the block */ FindFileBlock->Attributes = LOBYTE(FindData.dwFileAttributes); FileTimeToDosDateTime(&FindData.ftLastWriteTime, &FindFileBlock->FileDate, &FindFileBlock->FileTime); FindFileBlock->FileSize = FindData.nFileSizeHigh ? 0xFFFFFFFF : FindData.nFileSizeLow; strcpy(FindFileBlock->FileName, FindData.cAlternateFileName); } while((FindData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_DIRECTORY)) & ~FindFileBlock->AttribMask); return ERROR_SUCCESS; }
int main() { DWORD r; HANDLE pl; PROCESSENTRY32 pe; HANDLE stdout = GetStdHandle(STD_OUTPUT_HANDLE); WriteFile(stdout, title, lstrlen(title), &r, NULL); pl = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); pe.dwSize = sizeof(PROCESSENTRY32); pe.th32ParentProcessID = 0; if (Process32First(pl, &pe)) do { int hour; int minute; WORD fatdate; WORD fattime; HANDLE p = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pe.th32ProcessID); FILETIME cr; FILETIME ex; FILETIME kt; FILETIME ut; GetProcessTimes(p, &cr, &ex, &kt, &ut); FileTimeToDosDateTime(&cr, &fatdate, &fattime); hour = (fattime & 0xf800) >> 11; minute = (fattime & 0x07e0) >> 5; wsprintf(buf,"%08X %08X %2d:%02d %s\n", pe.th32ProcessID, pe.th32ParentProcessID, hour, minute, pe.szExeFile); WriteFile(stdout, buf, lstrlen(buf), &r, NULL); CloseHandle(p); pe.th32ParentProcessID = 0; } while (Process32Next(pl, &pe)); CloseHandle(pl); }
/**************************************************************************** * * Open Watcom Project * * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== * * This file contains Original Code and/or Modifications of Original * Code as defined in and that are subject to the Sybase Open Watcom * Public License version 1.0 (the 'License'). You may not use this file * except in compliance with the License. BY USING THIS FILE YOU AGREE TO * ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is * provided with the Original Code and Modifications, and is also * available at www.sybase.com/developer/opensource. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR * NON-INFRINGEMENT. Please see the License for the specific language * governing rights and limitations under the License. * * ======================================================================== * * Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE * DESCRIBE IT HERE! * ****************************************************************************/ #include "variety.h" #include "widechar.h" #include <stdio.h> #include <string.h> #include <direct.h> #include <windows.h> #include "libwin32.h" #include "ntex.h" #ifndef __WIDECHAR__ /* same for wide char, so only compile this once */ void __MakeDOSDT( FILETIME *NT_stamp, unsigned short *d, unsigned short *t ) { FILETIME local_ft; FileTimeToLocalFileTime( NT_stamp, &local_ft ); FileTimeToDosDateTime( &local_ft, d, t ); }
static INT_PTR CDECL get_open_info(char *pszName, USHORT *pdate, USHORT *ptime, USHORT *pattribs, int *err, void *pv) { BY_HANDLE_FILE_INFORMATION finfo; FILETIME filetime; HANDLE handle; DWORD attrs; BOOL res; handle = CreateFile(pszName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); ok(handle != INVALID_HANDLE_VALUE, "Failed to CreateFile %s\n", pszName); res = GetFileInformationByHandle(handle, &finfo); ok(res, "Expected GetFileInformationByHandle to succeed\n"); FileTimeToLocalFileTime(&finfo.ftLastWriteTime, &filetime); FileTimeToDosDateTime(&filetime, pdate, ptime); attrs = GetFileAttributes(pszName); ok(attrs != INVALID_FILE_ATTRIBUTES, "Failed to GetFileAttributes\n"); return (INT_PTR)handle; }
uint NTTimeToDos(FILETIME *ft) { WORD DosDate,DosTime; FILETIME ct; FileTimeToLocalFileTime(ft,&ct); FileTimeToDosDateTime(&ct,&DosDate,&DosTime); return(((uint)DosDate<<16)|DosTime); }
//----------------------------------------------------------------------------- // CZLib::AddFile // // Adds a file to the zip archive // BOOL CZLib::AddFile(string f_file) { BOOL bReturn = FALSE; // Open file being added HANDLE hFile = NULL; hFile = CreateFile(f_file.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile) { // Get file creation date FILETIME ft = CUtility::getLastWriteFileTime(f_file); zip_fileinfo zi = {0}; FileTimeToDosDateTime( &ft, // last write FILETIME ((LPWORD)&zi.dosDate)+1, // dos date ((LPWORD)&zi.dosDate)+0); // dos time // Trim path off file name string sFileName = f_file.substr(f_file.find_last_of(_T('\\')) + 1); // Start a new file in Zip if (ZIP_OK == zipOpenNewFileInZip(m_zf, sFileName.c_str(), &zi, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_BEST_COMPRESSION)) { // Write file to Zip in 4 KB chunks const DWORD BUFFSIZE = 4096; TCHAR buffer[BUFFSIZE] = _T(""); DWORD dwBytesRead = 0; while (ReadFile(hFile, &buffer, BUFFSIZE, &dwBytesRead, NULL) && dwBytesRead) { if (ZIP_OK == zipWriteInFileInZip(m_zf, buffer, dwBytesRead) && dwBytesRead < BUFFSIZE) { // Success bReturn = TRUE; } } bReturn &= (ZIP_OK == zipCloseFileInZip(m_zf)); } bReturn &= CloseHandle(hFile); } return bReturn; }
uLong filetime(const char *filename, tm_zip *tmzip, uLong *dostime) { int ret = 0; #ifdef _WIN32 FILETIME ftLocal; HANDLE hFind; WIN32_FIND_DATAA ff32; hFind = FindFirstFileA(filename, &ff32); if (hFind != INVALID_HANDLE_VALUE) { FileTimeToLocalFileTime(&(ff32.ftLastWriteTime), &ftLocal); FileTimeToDosDateTime(&ftLocal,((LPWORD)dostime)+1,((LPWORD)dostime)+0); FindClose(hFind); ret = 1; } #else #if defined unix || defined __APPLE__ struct stat s = {0}; struct tm* filedate; time_t tm_t = 0; if (strcmp(filename,"-") != 0) { char name[MAXFILENAME+1]; size_t len = strlen(filename); if (len > MAXFILENAME) len = MAXFILENAME; strncpy(name, filename, MAXFILENAME - 1); name[MAXFILENAME] = 0; if (name[len - 1] == '/') name[len - 1] = 0; /* not all systems allow stat'ing a file with / appended */ if (stat(name,&s) == 0) { tm_t = s.st_mtime; ret = 1; } } filedate = localtime(&tm_t); tmzip->tm_sec = filedate->tm_sec; tmzip->tm_min = filedate->tm_min; tmzip->tm_hour = filedate->tm_hour; tmzip->tm_mday = filedate->tm_mday; tmzip->tm_mon = filedate->tm_mon ; tmzip->tm_year = filedate->tm_year; #endif #endif return ret; }
static void pc_get_system_date(DATESTR * pd) { #ifdef RTFS_WINDOWS /* Windows runtime provides rotuines specifically for this purpose */ SYSTEMTIME systemtime; FILETIME filetime; GetLocalTime(&systemtime); SystemTimeToFileTime(&systemtime, &filetime); FileTimeToDosDateTime(&filetime, &pd->date, &pd->time); #else word year; /* relative to 1980 */ word month; /* 1 - 12 */ word day; /* 1 - 31 */ word hour; word minute; word sec; /* Note: seconds are 2 second/per. ie 3 == 6 seconds */ #ifdef RTFS_LINUX #define USE_ANSI_TIME 1 /* Linux supports it */ #else #define USE_ANSI_TIME 0 /* Enable if your runtime environment supports ansi time functions */ #endif #if (USE_ANSI_TIME) { /* Use ansi time functions. */ struct tm *timeptr; time_t timer; time(&timer); timeptr = localtime(&timer); hour = (word) timeptr->tm_hour; minute = (word) timeptr->tm_min; sec = (word) (timeptr->tm_sec/2); /* Date comes back relative to 1900 (eg 93). The pc wants it relative to 1980. so subtract 80 */ year = (word) (timeptr->tm_year-80); month = (word) (timeptr->tm_mon+1); day = (word) timeptr->tm_mday; } #else /* In not windows and not using ansi time functions use hardwired values. */ /* Modify this code if you have a clock calendar chip and can retrieve the values from that device instead */ hour = 19; /* 7:37:28 PM */ minute = 37; sec = 14; /* 3-28-2008 */ year = 18; /* relative to 1980 */ month = 3; /* 1 - 12 */ day = 28; /* 1 - 31 */ #endif pd->time = (word) ( (hour << 11) | (minute << 5) | sec); pd->date = (word) ( (year << 9) | (month << 5) | day); #endif /* #ifdef WINDOWS #else */ }
int GetFileDateTime(int filehandle, FILETIMESTRUCT *ftstruct) { FILETIME filetime; int retval; retval = GetFileTime((HANDLE)filehandle, NULL, NULL, &filetime); if (retval) { FileTimeToDosDateTime(&filetime, &ftstruct->date, &ftstruct->time); return 0; } else return 1; }
DWORD WINAPI demFileFindFirst(OUT PVOID lpFindFileData, IN LPCSTR FileName, IN WORD AttribMask) { BOOLEAN Success = TRUE; WIN32_FIND_DATAA FindData; HANDLE SearchHandle; PDOS_FIND_FILE_BLOCK FindFileBlock = (PDOS_FIND_FILE_BLOCK)lpFindFileData; /* Start a search */ SearchHandle = FindFirstFileA(FileName, &FindData); if (SearchHandle == INVALID_HANDLE_VALUE) return GetLastError(); do { /* Check the attributes and retry as long as we haven't found a matching file */ if (!((FindData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_DIRECTORY)) & ~AttribMask)) { break; } } while ((Success = FindNextFileA(SearchHandle, &FindData))); /* If we failed at some point, close the search and return an error */ if (!Success) { FindClose(SearchHandle); return GetLastError(); } /* Fill the block */ FindFileBlock->DriveLetter = DosData->Sda.CurrentDrive + 'A'; FindFileBlock->AttribMask = AttribMask; FindFileBlock->SearchHandle = SearchHandle; FindFileBlock->Attributes = LOBYTE(FindData.dwFileAttributes); FileTimeToDosDateTime(&FindData.ftLastWriteTime, &FindFileBlock->FileDate, &FindFileBlock->FileTime); FindFileBlock->FileSize = FindData.nFileSizeHigh ? 0xFFFFFFFF : FindData.nFileSizeLow; /* Build a short path name */ if (*FindData.cAlternateFileName) strncpy(FindFileBlock->FileName, FindData.cAlternateFileName, sizeof(FindFileBlock->FileName)); else GetShortPathNameA(FindData.cFileName, FindFileBlock->FileName, sizeof(FindFileBlock->FileName)); return ERROR_SUCCESS; }
static bool mzGetFileTime(const std::string &filename, tm_zip *tmzip, uLong *dostime) { // Don't fail when building with -Werror (void) filename; (void) tmzip; (void) dostime; #ifdef _WIN32 FILETIME ftLocal; HANDLE hFind; WIN32_FIND_DATAW ff32; std::wstring wFilename = utf8::utf8ToUtf16(filename); hFind = FindFirstFileW(wFilename.c_str(), &ff32); if (hFind != INVALID_HANDLE_VALUE) { FileTimeToLocalFileTime(&ff32.ftLastWriteTime, &ftLocal); FileTimeToDosDateTime(&ftLocal, ((LPWORD) dostime) + 1, ((LPWORD) dostime) + 0); FindClose(hFind); return true; } else { FLOGE("%s: FindFirstFileW() failed: %s", filename.c_str(), win32ErrorToString(GetLastError()).c_str()); } #elif defined unix || defined __APPLE__ || defined __ANDROID__ struct stat sb; struct tm t; if (stat(filename.c_str(), &sb) == 0) { time_t mtime = sb.st_mtime; if (!localtime_r(&mtime, &t)) { LOGE("localtime() failed"); return false; } tmzip->tm_sec = t.tm_sec; tmzip->tm_min = t.tm_min; tmzip->tm_hour = t.tm_hour; tmzip->tm_mday = t.tm_mday; tmzip->tm_mon = t.tm_mon ; tmzip->tm_year = t.tm_year; return true; } else { FLOGE("%s: stat() failed: %s", filename.c_str(), strerror(errno)); } #endif return false; }
// // MakeTimeString // static void MakeTimeString(FILETIME time, LPTSTR str) { WORD d, t; str[0] = _T('\0'); if(FileTimeToLocalFileTime(&time, &time) && FileTimeToDosDateTime(&time, &d, &t)) { wsprintf(str, _T("%d/%d/%d %02d:%02d:%02d"), (d / 32) & 15, d & 31, d / 512 + 1980, t >> 11, (t >> 5) & 0x3F, (t & 0x1F) * 2); }
static bool get_file_time(const std::string &filename, uint32_t *dostime) { // Don't fail when building with -Werror (void) filename; (void) dostime; #ifdef _WIN32 FILETIME ft_local; HANDLE h_find; WIN32_FIND_DATAW ff32; auto w_filename = utf8_to_wcs(filename); if (!w_filename) { return false; } h_find = FindFirstFileW(w_filename.value().c_str(), &ff32); if (h_find != INVALID_HANDLE_VALUE) { FileTimeToLocalFileTime(&ff32.ftLastWriteTime, &ft_local); FileTimeToDosDateTime(&ft_local, reinterpret_cast<LPWORD>(dostime) + 1, reinterpret_cast<LPWORD>(dostime) + 0); FindClose(h_find); return true; } else { LOGE("%s: FindFirstFileW() failed: %s", filename.c_str(), ec_from_win32().message().c_str()); } #elif defined unix || defined __APPLE__ || defined __ANDROID__ struct stat sb; struct tm t; if (stat(filename.c_str(), &sb) == 0) { time_t mtime = sb.st_mtime; if (!localtime_r(&mtime, &t)) { LOGE("localtime() failed"); return false; } *dostime = tm_to_dosdate(&t); return true; } else { LOGE("%s: stat() failed: %s", filename.c_str(), strerror(errno)); } #endif return false; }
static void test_FileTimeToDosDateTime(void) { FILETIME ft = { 0 }; WORD fatdate, fattime; BOOL ret; if (0) { /* Crashes */ FileTimeToDosDateTime(NULL, NULL, NULL); } /* Parameter checking */ SetLastError(0xdeadbeef); ret = FileTimeToDosDateTime(&ft, NULL, NULL); ok(!ret, "expected failure\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); SetLastError(0xdeadbeef); ret = FileTimeToDosDateTime(&ft, &fatdate, NULL); ok(!ret, "expected failure\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); SetLastError(0xdeadbeef); ret = FileTimeToDosDateTime(&ft, NULL, &fattime); ok(!ret, "expected failure\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); SetLastError(0xdeadbeef); ret = FileTimeToDosDateTime(&ft, &fatdate, &fattime); ok(!ret, "expected failure\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); }
static void PrintTime(char *output, FILETIME TimeToPrint) { WORD Date, Time; if (FileTimeToLocalFileTime(&TimeToPrint, &TimeToPrint) && FileTimeToDosDateTime(&TimeToPrint, &Date, &Time)) { // What a silly way to print out the file date/time. Oh well, // it works, and I'm not aware of a cleaner way to do it. wsprintf(output, "%d/%d/%d %02d:%02d:%02d", (Date / 32) & 15, Date & 31, (Date / 512) + 1980, (Time / 2048), (Time / 32) & 63, (Time & 31) * 2); } else output[0] = 0; }
//--------------------------------------------------------------------------- DWORD __fastcall TFile::GetDosTime(void) { DWORD dos = 0L; FILETIME CT, LAT, LWT, NORMAL; if( ! handle ) return dos; Error = ! GetFileTime(handle, &CT, &LAT, &LWT); FileTimeToLocalFileTime(&LWT, &NORMAL); //FileTimeToDosDateTime(&CT, ((LPWORD)&dos)+1, (LPWORD)&dos); //FileTimeToDosDateTime(&LAT, ((LPWORD)&dos)+1, (LPWORD)&dos); FileTimeToDosDateTime(&NORMAL, ((LPWORD)&dos)+1, (LPWORD)&dos); if( Exceptions && Error ) throw 0; return dos; }
uLong filetime(const char *f, tm_zip *tmzip, uLong *dt) { int ret = 0; FILETIME ftLocal; HANDLE hFind; WIN32_FIND_DATA ff32; FILETIME tmp; hFind = FindFirstFile(f,&ff32); if (hFind != INVALID_HANDLE_VALUE) { FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0); FindClose(hFind); ret = 1; } else { GetSystemTimeAsFileTime(&tmp); FileTimeToLocalFileTime(&tmp,&ftLocal); FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0); } return ret; }
uLong PackerJob::getFileTime(wchar_t *file, tm_zip*, uLong *dt) { FILETIME ftLocal; HANDLE hFind; WIN32_FIND_DATA ff32; hFind = FindFirstFile(file, &ff32); if (hFind != INVALID_HANDLE_VALUE) { FileTimeToLocalFileTime(&(ff32.ftLastWriteTime), &ftLocal); FileTimeToDosDateTime(&ftLocal, ((LPWORD)dt) + 1, ((LPWORD)dt) + 0); FindClose(hFind); return 1; } return 0; }
DOS_TIME DateTimeFile2( LPSTR DirName, LPSTR FileName ) { char path[ DB_MAX_PATH_LENGTH ]; WIN32_FILE_ATTRIBUTE_DATA FileData; DOS_TIME FileDateTime; BOOL rc; if (DirName == NULL || DirName[0] == '\0') { strcpy( path, FileName ); } else { sprintf( path, "%s" PATH_SEPARATOR "%s", DirName, FileName ); } rc = (*pGetFileAttributesExA) (path, GetFileExInfoStandard, (LPVOID)&FileData); if (!rc) { FileDateTime.value = 0; } else { FILETIME ftSystemTime; unsigned __int64 ui64Local, ui64File; GetSystemTimeAsFileTime(&ftSystemTime); ui64Local = (((unsigned __int64) ftSystemTime.dwHighDateTime) << 32) + (unsigned __int64) ftSystemTime.dwLowDateTime; ui64File = (((unsigned __int64) FileData.ftLastWriteTime.dwHighDateTime) << 32) + (unsigned __int64) FileData.ftLastWriteTime.dwLowDateTime; // Take into account that file times may have two second intervals (0x989680 = 1 second) // for FAT drives. if (ui64File > (ui64Local + (0x989680*2))) { BuildError("ERROR - \"%s\" file time is in the future.\n", path); } FileDateTime.value = 0L; FileTimeToDosDateTime( &FileData.ftLastWriteTime, &FileDateTime.time.wDate, &FileDateTime.time.wTime ); } return( FileDateTime ); }
long GetTheFileTime(char *name) { HANDLE h; FILETIME ft, lft; WORD dh, dl; h = CreateFile(name, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if ( h != INVALID_HANDLE_VALUE ) { GetFileTime(h, NULL, NULL, &ft); FileTimeToLocalFileTime( &ft, &lft); FileTimeToDosDateTime( &lft, &dh, &dl); CloseHandle(h); return(dh<<16) | dl; } else return 0L; }
uLong filetime(WCHAR *filename,tm_zip *tmzip, uLong *dt) { int ret=0; { FILETIME ftLocal; HANDLE hFind; WIN32_FIND_DATAW ff32; hFind=FindFirstFileW(filename,&ff32); if (hFind != INVALID_HANDLE_VALUE) { FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0); FindClose(hFind); ret=1; } } return ret; }
static bool mzGetFileTime(const std::string &filename, tm_zip *tmzip, uLong *dostime) { // Don't fail when building with -Werror (void) filename; (void) tmzip; (void) dostime; #ifdef _WIN32 FILETIME ftLocal; HANDLE hFind; WIN32_FIND_DATAA ff32; hFind = FindFirstFileA(filename.c_str(), &ff32); if (hFind != INVALID_HANDLE_VALUE) { FileTimeToLocalFileTime(&ff32.ftLastWriteTime, &ftLocal); FileTimeToDosDateTime(&ftLocal, ((LPWORD) dostime) + 1, ((LPWORD) dostime) + 0); FindClose(hFind); return true; } #elif defined unix || defined __APPLE__ /* || defined __ANDROID__ */ struct stat sb; struct tm *t; if (stat(filename.c_str(), &sb) == 0) { t = localtime(&sb.st_mtime); tmzip->tm_sec = t->tm_sec; tmzip->tm_min = t->tm_min; tmzip->tm_hour = t->tm_hour; tmzip->tm_mday = t->tm_mday; tmzip->tm_mon = t->tm_mon ; tmzip->tm_year = t->tm_year; return true; } #endif return false; }
DWORD WINAPI demFileFindFirst(OUT PVOID lpFindFileData, IN LPCSTR FileName, IN WORD AttribMask) { BOOLEAN Success = TRUE; WIN32_FIND_DATAA FindData; PDOS_FIND_FILE_BLOCK FindFileBlock = (PDOS_FIND_FILE_BLOCK)lpFindFileData; /* Fill the block */ FindFileBlock->DriveLetter = CurrentDrive + 'A'; FindFileBlock->AttribMask = AttribMask; FindFileBlock->SearchHandle = FindFirstFileA(FileName, &FindData); if (FindFileBlock->SearchHandle == INVALID_HANDLE_VALUE) return GetLastError(); do { /* Check the attributes */ if (!((FindData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_DIRECTORY)) & ~AttribMask)) { break; } } while ((Success = FindNextFileA(FindFileBlock->SearchHandle, &FindData))); if (!Success) return GetLastError(); FindFileBlock->Attributes = LOBYTE(FindData.dwFileAttributes); FileTimeToDosDateTime(&FindData.ftLastWriteTime, &FindFileBlock->FileDate, &FindFileBlock->FileTime); FindFileBlock->FileSize = FindData.nFileSizeHigh ? 0xFFFFFFFF : FindData.nFileSizeLow; strcpy(FindFileBlock->FileName, FindData.cAlternateFileName); return ERROR_SUCCESS; }
uLong filetime( const char *f, /* name of file to get info on */ tm_zip *tmzip, /* return value: access, modific. and creation times */ uLong *dt /* dostime */ ) { int ret = 0; { FILETIME ftLocal; HANDLE hFind; WIN32_FIND_DATAA ff32; hFind = FindFirstFileA(f,&ff32); if (hFind != INVALID_HANDLE_VALUE) { FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0); FindClose(hFind); ret = 1; } } return ret; }
/* ======================== idZipBuilder::GetFileTime ======================== */ bool idZipBuilder::GetFileTime( const idStr& filename, unsigned long* dostime ) const { // RB: FIXME #if defined(_WIN32) { FILETIME filetime; WIN32_FIND_DATA fileData; HANDLE findHandle = FindFirstFile( filename.c_str(), &fileData ); if( findHandle != INVALID_HANDLE_VALUE ) { FileTimeToLocalFileTime( &( fileData.ftLastWriteTime ), &filetime ); FileTimeToDosDateTime( &filetime, ( ( LPWORD )dostime ) + 1, ( ( LPWORD )dostime ) + 0 ); FindClose( findHandle ); return true; } FindClose( findHandle ); } #endif // RB end return false; }
const zip_fileinfo* setFileInfo(zip_fileinfo* fi, unsigned long long itemFiletime) { const zip_fileinfo* fip; if (itemFiletime == 0) { fip = 0; } else { filetime64_t filetime = {itemFiletime}; FILETIME localFileTime; FileTimeToLocalFileTime(&filetime.ft, &localFileTime); unsigned short dosDate; unsigned short dosTime; FileTimeToDosDateTime(&localFileTime, &dosDate, &dosTime); memset(fi, 0, sizeof(*fi)); fi->dosDate = (static_cast<unsigned long>(dosDate) << 16) | dosTime; fip = fi; } return fip; }