1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/other-licenses/7zstub/src/Windows/PropVariantConversions.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,145 @@ 1.4 +// PropVariantConversions.cpp 1.5 + 1.6 +#include "StdAfx.h" 1.7 + 1.8 +#include <stdio.h> 1.9 + 1.10 +#include "PropVariantConversions.h" 1.11 + 1.12 +#include "Windows/Defs.h" 1.13 + 1.14 +#include "Common/StringConvert.h" 1.15 +#include "Common/IntToString.h" 1.16 + 1.17 +static UString ConvertUInt64ToString(UInt64 value) 1.18 +{ 1.19 + wchar_t buffer[32]; 1.20 + ConvertUInt64ToString(value, buffer); 1.21 + return buffer; 1.22 +} 1.23 + 1.24 +static UString ConvertInt64ToString(Int64 value) 1.25 +{ 1.26 + wchar_t buffer[32]; 1.27 + ConvertInt64ToString(value, buffer); 1.28 + return buffer; 1.29 +} 1.30 + 1.31 +/* 1.32 +static void UIntToStringSpec(UInt32 value, char *s, int numPos) 1.33 +{ 1.34 + char s2[32]; 1.35 + ConvertUInt64ToString(value, s2); 1.36 + int len = strlen(s2); 1.37 + int i; 1.38 + for (i = 0; i < numPos - len; i++) 1.39 + s[i] = '0'; 1.40 + for (int j = 0; j < len; j++, i++) 1.41 + s[i] = s2[j]; 1.42 + s[i] = '\0'; 1.43 +} 1.44 +*/ 1.45 + 1.46 +bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds) 1.47 +{ 1.48 + s[0] = '\0'; 1.49 + SYSTEMTIME st; 1.50 + if(!BOOLToBool(FileTimeToSystemTime(&ft, &st))) 1.51 + return false; 1.52 + /* 1.53 + UIntToStringSpec(st.wYear, s, 4); 1.54 + strcat(s, "-"); 1.55 + UIntToStringSpec(st.wMonth, s + strlen(s), 2); 1.56 + strcat(s, "-"); 1.57 + UIntToStringSpec(st.wDay, s + strlen(s), 2); 1.58 + if (includeTime) 1.59 + { 1.60 + strcat(s, " "); 1.61 + UIntToStringSpec(st.wHour, s + strlen(s), 2); 1.62 + strcat(s, ":"); 1.63 + UIntToStringSpec(st.wMinute, s + strlen(s), 2); 1.64 + if (includeSeconds) 1.65 + { 1.66 + strcat(s, ":"); 1.67 + UIntToStringSpec(st.wSecond, s + strlen(s), 2); 1.68 + } 1.69 + } 1.70 + */ 1.71 + sprintf(s, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay); 1.72 + if (includeTime) 1.73 + { 1.74 + sprintf(s + strlen(s), " %02d:%02d", st.wHour, st.wMinute); 1.75 + if (includeSeconds) 1.76 + sprintf(s + strlen(s), ":%02d", st.wSecond); 1.77 + } 1.78 + return true; 1.79 +} 1.80 + 1.81 +UString ConvertFileTimeToString(const FILETIME &fileTime, bool includeTime, bool includeSeconds) 1.82 +{ 1.83 + char s[32]; 1.84 + ConvertFileTimeToString(fileTime, s, includeTime, includeSeconds); 1.85 + return GetUnicodeString(s); 1.86 +} 1.87 + 1.88 + 1.89 +UString ConvertPropVariantToString(const PROPVARIANT &propVariant) 1.90 +{ 1.91 + switch (propVariant.vt) 1.92 + { 1.93 + case VT_EMPTY: 1.94 + return UString(); 1.95 + case VT_BSTR: 1.96 + return propVariant.bstrVal; 1.97 + case VT_UI1: 1.98 + return ConvertUInt64ToString(propVariant.bVal); 1.99 + case VT_UI2: 1.100 + return ConvertUInt64ToString(propVariant.uiVal); 1.101 + case VT_UI4: 1.102 + return ConvertUInt64ToString(propVariant.ulVal); 1.103 + case VT_UI8: 1.104 + return ConvertUInt64ToString(propVariant.uhVal.QuadPart); 1.105 + case VT_FILETIME: 1.106 + return ConvertFileTimeToString(propVariant.filetime, true, true); 1.107 + /* 1.108 + case VT_I1: 1.109 + return ConvertInt64ToString(propVariant.cVal); 1.110 + */ 1.111 + case VT_I2: 1.112 + return ConvertInt64ToString(propVariant.iVal); 1.113 + case VT_I4: 1.114 + return ConvertInt64ToString(propVariant.lVal); 1.115 + case VT_I8: 1.116 + return ConvertInt64ToString(propVariant.hVal.QuadPart); 1.117 + 1.118 + case VT_BOOL: 1.119 + return VARIANT_BOOLToBool(propVariant.boolVal) ? L"1" : L"0"; 1.120 + default: 1.121 + #ifndef _WIN32_WCE 1.122 + throw 150245; 1.123 + #else 1.124 + return UString(); 1.125 + #endif 1.126 + } 1.127 +} 1.128 + 1.129 +UInt64 ConvertPropVariantToUInt64(const PROPVARIANT &propVariant) 1.130 +{ 1.131 + switch (propVariant.vt) 1.132 + { 1.133 + case VT_UI1: 1.134 + return propVariant.bVal; 1.135 + case VT_UI2: 1.136 + return propVariant.uiVal; 1.137 + case VT_UI4: 1.138 + return propVariant.ulVal; 1.139 + case VT_UI8: 1.140 + return (UInt64)propVariant.uhVal.QuadPart; 1.141 + default: 1.142 + #ifndef _WIN32_WCE 1.143 + throw 151199; 1.144 + #else 1.145 + return 0; 1.146 + #endif 1.147 + } 1.148 +}