| OLD | NEW |
| (Empty) |
| 1 // PropVariantConversions.cpp | |
| 2 | |
| 3 #include "StdAfx.h" | |
| 4 | |
| 5 #include "PropVariantConversions.h" | |
| 6 | |
| 7 #include "Windows/Defs.h" | |
| 8 | |
| 9 #include "Common/StringConvert.h" | |
| 10 #include "Common/IntToString.h" | |
| 11 | |
| 12 static UString ConvertUInt64ToString(UInt64 value) | |
| 13 { | |
| 14 wchar_t buffer[32]; | |
| 15 ConvertUInt64ToString(value, buffer); | |
| 16 return buffer; | |
| 17 } | |
| 18 | |
| 19 static UString ConvertInt64ToString(Int64 value) | |
| 20 { | |
| 21 wchar_t buffer[32]; | |
| 22 ConvertInt64ToString(value, buffer); | |
| 23 return buffer; | |
| 24 } | |
| 25 | |
| 26 static char *UIntToStringSpec(char c, UInt32 value, char *s, int numPos) | |
| 27 { | |
| 28 if (c != 0) | |
| 29 *s++ = c; | |
| 30 char temp[16]; | |
| 31 int pos = 0; | |
| 32 do | |
| 33 { | |
| 34 temp[pos++] = (char)('0' + value % 10); | |
| 35 value /= 10; | |
| 36 } | |
| 37 while (value != 0); | |
| 38 int i; | |
| 39 for (i = 0; i < numPos - pos; i++) | |
| 40 *s++ = '0'; | |
| 41 do | |
| 42 *s++ = temp[--pos]; | |
| 43 while (pos > 0); | |
| 44 *s = '\0'; | |
| 45 return s; | |
| 46 } | |
| 47 | |
| 48 bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool
includeSeconds) | |
| 49 { | |
| 50 s[0] = '\0'; | |
| 51 SYSTEMTIME st; | |
| 52 if (!BOOLToBool(FileTimeToSystemTime(&ft, &st))) | |
| 53 return false; | |
| 54 s = UIntToStringSpec(0, st.wYear, s, 4); | |
| 55 s = UIntToStringSpec('-', st.wMonth, s, 2); | |
| 56 s = UIntToStringSpec('-', st.wDay, s, 2); | |
| 57 if (includeTime) | |
| 58 { | |
| 59 s = UIntToStringSpec(' ', st.wHour, s, 2); | |
| 60 s = UIntToStringSpec(':', st.wMinute, s, 2); | |
| 61 if (includeSeconds) | |
| 62 UIntToStringSpec(':', st.wSecond, s, 2); | |
| 63 } | |
| 64 return true; | |
| 65 } | |
| 66 | |
| 67 UString ConvertFileTimeToString(const FILETIME &fileTime, bool includeTime, bool
includeSeconds) | |
| 68 { | |
| 69 char s[32]; | |
| 70 ConvertFileTimeToString(fileTime, s, includeTime, includeSeconds); | |
| 71 return GetUnicodeString(s); | |
| 72 } | |
| 73 | |
| 74 | |
| 75 UString ConvertPropVariantToString(const PROPVARIANT &prop) | |
| 76 { | |
| 77 switch (prop.vt) | |
| 78 { | |
| 79 case VT_EMPTY: return UString(); | |
| 80 case VT_BSTR: return prop.bstrVal; | |
| 81 case VT_UI1: return ConvertUInt64ToString(prop.bVal); | |
| 82 case VT_UI2: return ConvertUInt64ToString(prop.uiVal); | |
| 83 case VT_UI4: return ConvertUInt64ToString(prop.ulVal); | |
| 84 case VT_UI8: return ConvertUInt64ToString(prop.uhVal.QuadPart); | |
| 85 case VT_FILETIME: return ConvertFileTimeToString(prop.filetime, true, true); | |
| 86 // case VT_I1: return ConvertInt64ToString(prop.cVal); | |
| 87 case VT_I2: return ConvertInt64ToString(prop.iVal); | |
| 88 case VT_I4: return ConvertInt64ToString(prop.lVal); | |
| 89 case VT_I8: return ConvertInt64ToString(prop.hVal.QuadPart); | |
| 90 case VT_BOOL: return VARIANT_BOOLToBool(prop.boolVal) ? L"+" : L"-"; | |
| 91 default: | |
| 92 #ifndef _WIN32_WCE | |
| 93 throw 150245; | |
| 94 #else | |
| 95 return UString(); | |
| 96 #endif | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 UInt64 ConvertPropVariantToUInt64(const PROPVARIANT &prop) | |
| 101 { | |
| 102 switch (prop.vt) | |
| 103 { | |
| 104 case VT_UI1: return prop.bVal; | |
| 105 case VT_UI2: return prop.uiVal; | |
| 106 case VT_UI4: return prop.ulVal; | |
| 107 case VT_UI8: return (UInt64)prop.uhVal.QuadPart; | |
| 108 default: | |
| 109 #ifndef _WIN32_WCE | |
| 110 throw 151199; | |
| 111 #else | |
| 112 return 0; | |
| 113 #endif | |
| 114 } | |
| 115 } | |
| OLD | NEW |