Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // PropVariantConversions.cpp |
michael@0 | 2 | |
michael@0 | 3 | #include "StdAfx.h" |
michael@0 | 4 | |
michael@0 | 5 | #include <stdio.h> |
michael@0 | 6 | |
michael@0 | 7 | #include "PropVariantConversions.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "Windows/Defs.h" |
michael@0 | 10 | |
michael@0 | 11 | #include "Common/StringConvert.h" |
michael@0 | 12 | #include "Common/IntToString.h" |
michael@0 | 13 | |
michael@0 | 14 | static UString ConvertUInt64ToString(UInt64 value) |
michael@0 | 15 | { |
michael@0 | 16 | wchar_t buffer[32]; |
michael@0 | 17 | ConvertUInt64ToString(value, buffer); |
michael@0 | 18 | return buffer; |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | static UString ConvertInt64ToString(Int64 value) |
michael@0 | 22 | { |
michael@0 | 23 | wchar_t buffer[32]; |
michael@0 | 24 | ConvertInt64ToString(value, buffer); |
michael@0 | 25 | return buffer; |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | /* |
michael@0 | 29 | static void UIntToStringSpec(UInt32 value, char *s, int numPos) |
michael@0 | 30 | { |
michael@0 | 31 | char s2[32]; |
michael@0 | 32 | ConvertUInt64ToString(value, s2); |
michael@0 | 33 | int len = strlen(s2); |
michael@0 | 34 | int i; |
michael@0 | 35 | for (i = 0; i < numPos - len; i++) |
michael@0 | 36 | s[i] = '0'; |
michael@0 | 37 | for (int j = 0; j < len; j++, i++) |
michael@0 | 38 | s[i] = s2[j]; |
michael@0 | 39 | s[i] = '\0'; |
michael@0 | 40 | } |
michael@0 | 41 | */ |
michael@0 | 42 | |
michael@0 | 43 | bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds) |
michael@0 | 44 | { |
michael@0 | 45 | s[0] = '\0'; |
michael@0 | 46 | SYSTEMTIME st; |
michael@0 | 47 | if(!BOOLToBool(FileTimeToSystemTime(&ft, &st))) |
michael@0 | 48 | return false; |
michael@0 | 49 | /* |
michael@0 | 50 | UIntToStringSpec(st.wYear, s, 4); |
michael@0 | 51 | strcat(s, "-"); |
michael@0 | 52 | UIntToStringSpec(st.wMonth, s + strlen(s), 2); |
michael@0 | 53 | strcat(s, "-"); |
michael@0 | 54 | UIntToStringSpec(st.wDay, s + strlen(s), 2); |
michael@0 | 55 | if (includeTime) |
michael@0 | 56 | { |
michael@0 | 57 | strcat(s, " "); |
michael@0 | 58 | UIntToStringSpec(st.wHour, s + strlen(s), 2); |
michael@0 | 59 | strcat(s, ":"); |
michael@0 | 60 | UIntToStringSpec(st.wMinute, s + strlen(s), 2); |
michael@0 | 61 | if (includeSeconds) |
michael@0 | 62 | { |
michael@0 | 63 | strcat(s, ":"); |
michael@0 | 64 | UIntToStringSpec(st.wSecond, s + strlen(s), 2); |
michael@0 | 65 | } |
michael@0 | 66 | } |
michael@0 | 67 | */ |
michael@0 | 68 | sprintf(s, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay); |
michael@0 | 69 | if (includeTime) |
michael@0 | 70 | { |
michael@0 | 71 | sprintf(s + strlen(s), " %02d:%02d", st.wHour, st.wMinute); |
michael@0 | 72 | if (includeSeconds) |
michael@0 | 73 | sprintf(s + strlen(s), ":%02d", st.wSecond); |
michael@0 | 74 | } |
michael@0 | 75 | return true; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | UString ConvertFileTimeToString(const FILETIME &fileTime, bool includeTime, bool includeSeconds) |
michael@0 | 79 | { |
michael@0 | 80 | char s[32]; |
michael@0 | 81 | ConvertFileTimeToString(fileTime, s, includeTime, includeSeconds); |
michael@0 | 82 | return GetUnicodeString(s); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | |
michael@0 | 86 | UString ConvertPropVariantToString(const PROPVARIANT &propVariant) |
michael@0 | 87 | { |
michael@0 | 88 | switch (propVariant.vt) |
michael@0 | 89 | { |
michael@0 | 90 | case VT_EMPTY: |
michael@0 | 91 | return UString(); |
michael@0 | 92 | case VT_BSTR: |
michael@0 | 93 | return propVariant.bstrVal; |
michael@0 | 94 | case VT_UI1: |
michael@0 | 95 | return ConvertUInt64ToString(propVariant.bVal); |
michael@0 | 96 | case VT_UI2: |
michael@0 | 97 | return ConvertUInt64ToString(propVariant.uiVal); |
michael@0 | 98 | case VT_UI4: |
michael@0 | 99 | return ConvertUInt64ToString(propVariant.ulVal); |
michael@0 | 100 | case VT_UI8: |
michael@0 | 101 | return ConvertUInt64ToString(propVariant.uhVal.QuadPart); |
michael@0 | 102 | case VT_FILETIME: |
michael@0 | 103 | return ConvertFileTimeToString(propVariant.filetime, true, true); |
michael@0 | 104 | /* |
michael@0 | 105 | case VT_I1: |
michael@0 | 106 | return ConvertInt64ToString(propVariant.cVal); |
michael@0 | 107 | */ |
michael@0 | 108 | case VT_I2: |
michael@0 | 109 | return ConvertInt64ToString(propVariant.iVal); |
michael@0 | 110 | case VT_I4: |
michael@0 | 111 | return ConvertInt64ToString(propVariant.lVal); |
michael@0 | 112 | case VT_I8: |
michael@0 | 113 | return ConvertInt64ToString(propVariant.hVal.QuadPart); |
michael@0 | 114 | |
michael@0 | 115 | case VT_BOOL: |
michael@0 | 116 | return VARIANT_BOOLToBool(propVariant.boolVal) ? L"1" : L"0"; |
michael@0 | 117 | default: |
michael@0 | 118 | #ifndef _WIN32_WCE |
michael@0 | 119 | throw 150245; |
michael@0 | 120 | #else |
michael@0 | 121 | return UString(); |
michael@0 | 122 | #endif |
michael@0 | 123 | } |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | UInt64 ConvertPropVariantToUInt64(const PROPVARIANT &propVariant) |
michael@0 | 127 | { |
michael@0 | 128 | switch (propVariant.vt) |
michael@0 | 129 | { |
michael@0 | 130 | case VT_UI1: |
michael@0 | 131 | return propVariant.bVal; |
michael@0 | 132 | case VT_UI2: |
michael@0 | 133 | return propVariant.uiVal; |
michael@0 | 134 | case VT_UI4: |
michael@0 | 135 | return propVariant.ulVal; |
michael@0 | 136 | case VT_UI8: |
michael@0 | 137 | return (UInt64)propVariant.uhVal.QuadPart; |
michael@0 | 138 | default: |
michael@0 | 139 | #ifndef _WIN32_WCE |
michael@0 | 140 | throw 151199; |
michael@0 | 141 | #else |
michael@0 | 142 | return 0; |
michael@0 | 143 | #endif |
michael@0 | 144 | } |
michael@0 | 145 | } |