1370b324cSopenharmony_ci// Windows/TimeUtils.h 2370b324cSopenharmony_ci 3370b324cSopenharmony_ci#ifndef ZIP7_INC_WINDOWS_TIME_UTILS_H 4370b324cSopenharmony_ci#define ZIP7_INC_WINDOWS_TIME_UTILS_H 5370b324cSopenharmony_ci 6370b324cSopenharmony_ci#include "../Common/MyTypes.h" 7370b324cSopenharmony_ci#include "../Common/MyWindows.h" 8370b324cSopenharmony_ci#include "PropVariant.h" 9370b324cSopenharmony_ci 10370b324cSopenharmony_ciinline UInt64 FILETIME_To_UInt64(const FILETIME &ft) 11370b324cSopenharmony_ci{ 12370b324cSopenharmony_ci return (((UInt64)ft.dwHighDateTime) << 32) + ft.dwLowDateTime; 13370b324cSopenharmony_ci} 14370b324cSopenharmony_ci 15370b324cSopenharmony_ciinline void FILETIME_Clear(FILETIME &ft) 16370b324cSopenharmony_ci{ 17370b324cSopenharmony_ci ft.dwLowDateTime = 0; 18370b324cSopenharmony_ci ft.dwHighDateTime = 0; 19370b324cSopenharmony_ci} 20370b324cSopenharmony_ci 21370b324cSopenharmony_ciinline bool FILETIME_IsZero(const FILETIME &ft) 22370b324cSopenharmony_ci{ 23370b324cSopenharmony_ci return (ft.dwHighDateTime == 0 && ft.dwLowDateTime == 0); 24370b324cSopenharmony_ci} 25370b324cSopenharmony_ci 26370b324cSopenharmony_ci 27370b324cSopenharmony_ci#ifdef _WIN32 28370b324cSopenharmony_ci #define CFiTime FILETIME 29370b324cSopenharmony_ci #define Compare_FiTime ::CompareFileTime 30370b324cSopenharmony_ci inline void FiTime_To_FILETIME(const CFiTime &ts, FILETIME &ft) 31370b324cSopenharmony_ci { 32370b324cSopenharmony_ci ft = ts; 33370b324cSopenharmony_ci } 34370b324cSopenharmony_ci /* 35370b324cSopenharmony_ci inline void FILETIME_To_FiTime(const FILETIME &ft, CFiTime &ts) 36370b324cSopenharmony_ci { 37370b324cSopenharmony_ci ts = ft; 38370b324cSopenharmony_ci } 39370b324cSopenharmony_ci */ 40370b324cSopenharmony_ci inline void FiTime_Clear(CFiTime &ft) 41370b324cSopenharmony_ci { 42370b324cSopenharmony_ci ft.dwLowDateTime = 0; 43370b324cSopenharmony_ci ft.dwHighDateTime = 0; 44370b324cSopenharmony_ci } 45370b324cSopenharmony_ci#else 46370b324cSopenharmony_ci 47370b324cSopenharmony_ci #include <sys/stat.h> 48370b324cSopenharmony_ci 49370b324cSopenharmony_ci #if defined(_AIX) 50370b324cSopenharmony_ci #define CFiTime st_timespec 51370b324cSopenharmony_ci #else 52370b324cSopenharmony_ci #define CFiTime timespec 53370b324cSopenharmony_ci #endif 54370b324cSopenharmony_ci int Compare_FiTime(const CFiTime *a1, const CFiTime *a2); 55370b324cSopenharmony_ci bool FILETIME_To_timespec(const FILETIME &ft, CFiTime &ts); 56370b324cSopenharmony_ci void FiTime_To_FILETIME(const CFiTime &ts, FILETIME &ft); 57370b324cSopenharmony_ci void FiTime_To_FILETIME_ns100(const CFiTime &ts, FILETIME &ft, unsigned &ns100); 58370b324cSopenharmony_ci inline void FiTime_Clear(CFiTime &ft) 59370b324cSopenharmony_ci { 60370b324cSopenharmony_ci ft.tv_sec = 0; 61370b324cSopenharmony_ci ft.tv_nsec = 0; 62370b324cSopenharmony_ci } 63370b324cSopenharmony_ci 64370b324cSopenharmony_ci #ifdef __APPLE__ 65370b324cSopenharmony_ci #define ST_MTIME(st) st.st_mtimespec 66370b324cSopenharmony_ci #define ST_ATIME(st) st.st_atimespec 67370b324cSopenharmony_ci #define ST_CTIME(st) st.st_ctimespec 68370b324cSopenharmony_ci #else 69370b324cSopenharmony_ci #define ST_MTIME(st) st.st_mtim 70370b324cSopenharmony_ci #define ST_ATIME(st) st.st_atim 71370b324cSopenharmony_ci #define ST_CTIME(st) st.st_ctim 72370b324cSopenharmony_ci #endif 73370b324cSopenharmony_ci 74370b324cSopenharmony_ci#endif 75370b324cSopenharmony_ci 76370b324cSopenharmony_ci// void FiTime_Normalize_With_Prec(CFiTime &ft, unsigned prec); 77370b324cSopenharmony_ci 78370b324cSopenharmony_cinamespace NWindows { 79370b324cSopenharmony_cinamespace NTime { 80370b324cSopenharmony_ci 81370b324cSopenharmony_cibool DosTime_To_FileTime(UInt32 dosTime, FILETIME &fileTime) throw(); 82370b324cSopenharmony_cibool UtcFileTime_To_LocalDosTime(const FILETIME &utc, UInt32 &dosTime) throw(); 83370b324cSopenharmony_cibool FileTime_To_DosTime(const FILETIME &fileTime, UInt32 &dosTime) throw(); 84370b324cSopenharmony_ci 85370b324cSopenharmony_ci// UInt32 Unix Time : for dates 1970-2106 86370b324cSopenharmony_ciUInt64 UnixTime_To_FileTime64(UInt32 unixTime) throw(); 87370b324cSopenharmony_civoid UnixTime_To_FileTime(UInt32 unixTime, FILETIME &fileTime) throw(); 88370b324cSopenharmony_ci 89370b324cSopenharmony_ci// Int64 Unix Time : negative values for dates before 1970 90370b324cSopenharmony_ciUInt64 UnixTime64_To_FileTime64(Int64 unixTime) throw(); // no check 91370b324cSopenharmony_cibool UnixTime64_To_FileTime64(Int64 unixTime, UInt64 &fileTime) throw(); 92370b324cSopenharmony_cibool UnixTime64_To_FileTime(Int64 unixTime, FILETIME &fileTime) throw(); 93370b324cSopenharmony_ci 94370b324cSopenharmony_ciInt64 FileTime64_To_UnixTime64(UInt64 ft64) throw(); 95370b324cSopenharmony_cibool FileTime_To_UnixTime(const FILETIME &fileTime, UInt32 &unixTime) throw(); 96370b324cSopenharmony_ciInt64 FileTime_To_UnixTime64(const FILETIME &ft) throw(); 97370b324cSopenharmony_ciInt64 FileTime_To_UnixTime64_and_Quantums(const FILETIME &ft, UInt32 &quantums) throw(); 98370b324cSopenharmony_ci 99370b324cSopenharmony_cibool GetSecondsSince1601(unsigned year, unsigned month, unsigned day, 100370b324cSopenharmony_ci unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds) throw(); 101370b324cSopenharmony_ci 102370b324cSopenharmony_civoid GetCurUtc_FiTime(CFiTime &ft) throw(); 103370b324cSopenharmony_ci#ifdef _WIN32 104370b324cSopenharmony_ci#define GetCurUtcFileTime GetCurUtc_FiTime 105370b324cSopenharmony_ci#else 106370b324cSopenharmony_civoid GetCurUtcFileTime(FILETIME &ft) throw(); 107370b324cSopenharmony_ci#endif 108370b324cSopenharmony_ci 109370b324cSopenharmony_ci}} 110370b324cSopenharmony_ci 111370b324cSopenharmony_ciinline void PropVariant_SetFrom_UnixTime(NWindows::NCOM::CPropVariant &prop, UInt32 unixTime) 112370b324cSopenharmony_ci{ 113370b324cSopenharmony_ci FILETIME ft; 114370b324cSopenharmony_ci NWindows::NTime::UnixTime_To_FileTime(unixTime, ft); 115370b324cSopenharmony_ci prop.SetAsTimeFrom_FT_Prec(ft, k_PropVar_TimePrec_Unix); 116370b324cSopenharmony_ci} 117370b324cSopenharmony_ci 118370b324cSopenharmony_ciinline void PropVariant_SetFrom_NtfsTime(NWindows::NCOM::CPropVariant &prop, const FILETIME &ft) 119370b324cSopenharmony_ci{ 120370b324cSopenharmony_ci prop.SetAsTimeFrom_FT_Prec(ft, k_PropVar_TimePrec_100ns); 121370b324cSopenharmony_ci} 122370b324cSopenharmony_ci 123370b324cSopenharmony_ciinline void PropVariant_SetFrom_FiTime(NWindows::NCOM::CPropVariant &prop, const CFiTime &fts) 124370b324cSopenharmony_ci{ 125370b324cSopenharmony_ci #ifdef _WIN32 126370b324cSopenharmony_ci PropVariant_SetFrom_NtfsTime(prop, fts); 127370b324cSopenharmony_ci #else 128370b324cSopenharmony_ci unsigned ns100; 129370b324cSopenharmony_ci FILETIME ft; 130370b324cSopenharmony_ci FiTime_To_FILETIME_ns100(fts, ft, ns100); 131370b324cSopenharmony_ci prop.SetAsTimeFrom_FT_Prec_Ns100(ft, k_PropVar_TimePrec_1ns, ns100); 132370b324cSopenharmony_ci #endif 133370b324cSopenharmony_ci} 134370b324cSopenharmony_ci 135370b324cSopenharmony_ciinline bool PropVariant_SetFrom_DosTime(NWindows::NCOM::CPropVariant &prop, UInt32 dosTime) 136370b324cSopenharmony_ci{ 137370b324cSopenharmony_ci FILETIME localFileTime, utc; 138370b324cSopenharmony_ci if (!NWindows::NTime::DosTime_To_FileTime(dosTime, localFileTime)) 139370b324cSopenharmony_ci return false; 140370b324cSopenharmony_ci if (!LocalFileTimeToFileTime(&localFileTime, &utc)) 141370b324cSopenharmony_ci return false; 142370b324cSopenharmony_ci prop.SetAsTimeFrom_FT_Prec(utc, k_PropVar_TimePrec_DOS); 143370b324cSopenharmony_ci return true; 144370b324cSopenharmony_ci} 145370b324cSopenharmony_ci 146370b324cSopenharmony_ci#endif 147