diff options
| author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2024-05-14 00:00:00 +0000 |
|---|---|---|
| committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2024-05-15 23:55:04 +0500 |
| commit | fc662341e6f85da78ada0e443f6116b978f79f22 (patch) | |
| tree | 1be1cc402a7a9cbc18d4eeea6b141354c2d559e3 /CPP/Windows/PropVariantConv.cpp | |
| parent | 5b39dc76f1bc82f941d5c800ab9f34407a06b53a (diff) | |
| download | 7zip-fc662341e6f85da78ada0e443f6116b978f79f22.tar.gz 7zip-fc662341e6f85da78ada0e443f6116b978f79f22.tar.bz2 7zip-fc662341e6f85da78ada0e443f6116b978f79f22.zip | |
24.0524.05
Diffstat (limited to 'CPP/Windows/PropVariantConv.cpp')
| -rw-r--r-- | CPP/Windows/PropVariantConv.cpp | 104 |
1 files changed, 94 insertions, 10 deletions
diff --git a/CPP/Windows/PropVariantConv.cpp b/CPP/Windows/PropVariantConv.cpp index 5fb96a7..21a7b4e 100644 --- a/CPP/Windows/PropVariantConv.cpp +++ b/CPP/Windows/PropVariantConv.cpp | |||
| @@ -9,12 +9,45 @@ | |||
| 9 | 9 | ||
| 10 | #define UINT_TO_STR_2(c, val) { s[0] = (c); s[1] = (char)('0' + (val) / 10); s[2] = (char)('0' + (val) % 10); s += 3; } | 10 | #define UINT_TO_STR_2(c, val) { s[0] = (c); s[1] = (char)('0' + (val) / 10); s[2] = (char)('0' + (val) % 10); s += 3; } |
| 11 | 11 | ||
| 12 | bool ConvertUtcFileTimeToString2(const FILETIME &utc, unsigned ns100, char *s, int level) throw() | 12 | static const unsigned k_TimeStringBufferSize = 64; |
| 13 | |||
| 14 | bool g_Timestamp_Show_UTC; | ||
| 15 | #if 0 | ||
| 16 | bool g_Timestamp_Show_DisableZ; | ||
| 17 | bool g_Timestamp_Show_TDelimeter; | ||
| 18 | bool g_Timestamp_Show_ZoneOffset; | ||
| 19 | #endif | ||
| 20 | |||
| 21 | Z7_NO_INLINE | ||
| 22 | bool ConvertUtcFileTimeToString2(const FILETIME &utc, unsigned ns100, char *s, int level, unsigned flags) throw() | ||
| 13 | { | 23 | { |
| 14 | *s = 0; | 24 | *s = 0; |
| 15 | FILETIME ft; | 25 | FILETIME ft; |
| 16 | if (!FileTimeToLocalFileTime(&utc, &ft)) | 26 | |
| 17 | return false; | 27 | #if 0 |
| 28 | Int64 bias64 = 0; | ||
| 29 | #endif | ||
| 30 | |||
| 31 | const bool show_utc = | ||
| 32 | (flags & kTimestampPrintFlags_Force_UTC) ? true : | ||
| 33 | (flags & kTimestampPrintFlags_Force_LOCAL) ? false : | ||
| 34 | g_Timestamp_Show_UTC; | ||
| 35 | |||
| 36 | if (show_utc) | ||
| 37 | ft = utc; | ||
| 38 | else | ||
| 39 | { | ||
| 40 | if (!FileTimeToLocalFileTime(&utc, &ft)) | ||
| 41 | return false; | ||
| 42 | #if 0 | ||
| 43 | if (g_Timestamp_Show_ZoneOffset) | ||
| 44 | { | ||
| 45 | const UInt64 utc64 = (((UInt64)utc.dwHighDateTime) << 32) + utc.dwLowDateTime; | ||
| 46 | const UInt64 loc64 = (((UInt64) ft.dwHighDateTime) << 32) + ft.dwLowDateTime; | ||
| 47 | bias64 = (Int64)utc64 - (Int64)loc64; | ||
| 48 | } | ||
| 49 | #endif | ||
| 50 | } | ||
| 18 | 51 | ||
| 19 | SYSTEMTIME st; | 52 | SYSTEMTIME st; |
| 20 | if (!BOOLToBool(FileTimeToSystemTime(&ft, &st))) | 53 | if (!BOOLToBool(FileTimeToSystemTime(&ft, &st))) |
| @@ -41,7 +74,12 @@ bool ConvertUtcFileTimeToString2(const FILETIME &utc, unsigned ns100, char *s, i | |||
| 41 | 74 | ||
| 42 | if (level > kTimestampPrintLevel_DAY) | 75 | if (level > kTimestampPrintLevel_DAY) |
| 43 | { | 76 | { |
| 44 | UINT_TO_STR_2(' ', st.wHour) | 77 | const char setChar = |
| 78 | #if 0 | ||
| 79 | g_Timestamp_Show_TDelimeter ? 'T' : // ISO 8601 | ||
| 80 | #endif | ||
| 81 | ' '; | ||
| 82 | UINT_TO_STR_2(setChar, st.wHour) | ||
| 45 | UINT_TO_STR_2(':', st.wMinute) | 83 | UINT_TO_STR_2(':', st.wMinute) |
| 46 | 84 | ||
| 47 | if (level >= kTimestampPrintLevel_SEC) | 85 | if (level >= kTimestampPrintLevel_SEC) |
| @@ -84,6 +122,52 @@ bool ConvertUtcFileTimeToString2(const FILETIME &utc, unsigned ns100, char *s, i | |||
| 84 | } | 122 | } |
| 85 | } | 123 | } |
| 86 | 124 | ||
| 125 | if (show_utc) | ||
| 126 | { | ||
| 127 | if ((flags & kTimestampPrintFlags_DisableZ) == 0 | ||
| 128 | #if 0 | ||
| 129 | && !g_Timestamp_Show_DisableZ | ||
| 130 | #endif | ||
| 131 | ) | ||
| 132 | *s++ = 'Z'; | ||
| 133 | } | ||
| 134 | #if 0 | ||
| 135 | else if (g_Timestamp_Show_ZoneOffset) | ||
| 136 | { | ||
| 137 | #if 1 | ||
| 138 | { | ||
| 139 | char c; | ||
| 140 | if (bias64 < 0) | ||
| 141 | { | ||
| 142 | bias64 = -bias64; | ||
| 143 | c = '+'; | ||
| 144 | } | ||
| 145 | else | ||
| 146 | c = '-'; | ||
| 147 | UInt32 bias = (UInt32)((UInt64)bias64 / (10000000 * 60)); | ||
| 148 | #else | ||
| 149 | TIME_ZONE_INFORMATION zi; | ||
| 150 | const DWORD dw = GetTimeZoneInformation(&zi); | ||
| 151 | if (dw <= TIME_ZONE_ID_DAYLIGHT) // == 2 | ||
| 152 | { | ||
| 153 | // UTC = LOCAL + Bias | ||
| 154 | Int32 bias = zi.Bias; | ||
| 155 | char c; | ||
| 156 | if (bias < 0) | ||
| 157 | { | ||
| 158 | bias = -bias; | ||
| 159 | c = '+'; | ||
| 160 | } | ||
| 161 | else | ||
| 162 | c = '-'; | ||
| 163 | #endif | ||
| 164 | const UInt32 hours = (UInt32)bias / 60; | ||
| 165 | const UInt32 mins = (UInt32)bias % 60; | ||
| 166 | UINT_TO_STR_2(c, hours) | ||
| 167 | UINT_TO_STR_2(':', mins) | ||
| 168 | } | ||
| 169 | } | ||
| 170 | #endif | ||
| 87 | *s = 0; | 171 | *s = 0; |
| 88 | return true; | 172 | return true; |
| 89 | } | 173 | } |
| @@ -96,11 +180,11 @@ bool ConvertUtcFileTimeToString(const FILETIME &utc, char *s, int level) throw() | |||
| 96 | 180 | ||
| 97 | bool ConvertUtcFileTimeToString2(const FILETIME &ft, unsigned ns100, wchar_t *dest, int level) throw() | 181 | bool ConvertUtcFileTimeToString2(const FILETIME &ft, unsigned ns100, wchar_t *dest, int level) throw() |
| 98 | { | 182 | { |
| 99 | char s[32]; | 183 | char s[k_TimeStringBufferSize]; |
| 100 | bool res = ConvertUtcFileTimeToString2(ft, ns100, s, level); | 184 | const bool res = ConvertUtcFileTimeToString2(ft, ns100, s, level); |
| 101 | for (unsigned i = 0;; i++) | 185 | for (unsigned i = 0;; i++) |
| 102 | { | 186 | { |
| 103 | Byte c = (Byte)s[i]; | 187 | const Byte c = (Byte)s[i]; |
| 104 | dest[i] = c; | 188 | dest[i] = c; |
| 105 | if (c == 0) | 189 | if (c == 0) |
| 106 | break; | 190 | break; |
| @@ -110,11 +194,11 @@ bool ConvertUtcFileTimeToString2(const FILETIME &ft, unsigned ns100, wchar_t *de | |||
| 110 | 194 | ||
| 111 | bool ConvertUtcFileTimeToString(const FILETIME &ft, wchar_t *dest, int level) throw() | 195 | bool ConvertUtcFileTimeToString(const FILETIME &ft, wchar_t *dest, int level) throw() |
| 112 | { | 196 | { |
| 113 | char s[32]; | 197 | char s[k_TimeStringBufferSize]; |
| 114 | bool res = ConvertUtcFileTimeToString(ft, s, level); | 198 | const bool res = ConvertUtcFileTimeToString(ft, s, level); |
| 115 | for (unsigned i = 0;; i++) | 199 | for (unsigned i = 0;; i++) |
| 116 | { | 200 | { |
| 117 | Byte c = (Byte)s[i]; | 201 | const Byte c = (Byte)s[i]; |
| 118 | dest[i] = c; | 202 | dest[i] = c; |
| 119 | if (c == 0) | 203 | if (c == 0) |
| 120 | break; | 204 | break; |
