00001
00002
00003
00004
00005 #include "StdAfx.h"
00006
00007 #include <stdio.h>
00008
00009 #include "PropVariantConversions.h"
00010
00011 #include "Defs.h"
00012
00013 #include "StringConvert.h"
00014 #include "IntToString.h"
00015
00016 static UString ConvertUInt64ToString(UInt64 value)
00017 {
00018 wchar_t buffer[32];
00019 ConvertUInt64ToString(value, buffer);
00020 return buffer;
00021 }
00022
00023 static UString ConvertInt64ToString(Int64 value)
00024 {
00025 wchar_t buffer[32];
00026 ConvertInt64ToString(value, buffer);
00027 return buffer;
00028 }
00029
00030 bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds)
00031 {
00032 s[0] = '\0';
00033 SYSTEMTIME st;
00034 if(!BOOLToBool(FileTimeToSystemTime(&ft, &st)))
00035 return false;
00036
00037 sprintf(s, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay);
00038 if (includeTime)
00039 {
00040 sprintf(s + strlen(s), " %02d:%02d", st.wHour, st.wMinute);
00041 if (includeSeconds)
00042 sprintf(s + strlen(s), ":%02d", st.wSecond);
00043 }
00044 return true;
00045 }
00046
00047 UString ConvertFileTimeToString(const FILETIME &fileTime, bool includeTime, bool includeSeconds)
00048 {
00049 char s[32];
00050 ConvertFileTimeToString(fileTime, s, includeTime, includeSeconds);
00051 return GetUnicodeString(s);
00052 }
00053
00054
00055 UString ConvertPropVariantToString(const PROPVARIANT &propVariant)
00056 {
00057 switch (propVariant.vt)
00058 {
00059 case VT_EMPTY:
00060 return UString();
00061 case VT_BSTR:
00062 return propVariant.bstrVal;
00063 case VT_UI1:
00064 return ConvertUInt64ToString(propVariant.bVal);
00065 case VT_UI2:
00066 return ConvertUInt64ToString(propVariant.uiVal);
00067 case VT_UI4:
00068 return ConvertUInt64ToString(propVariant.ulVal);
00069 case VT_UI8:
00070 return ConvertUInt64ToString(propVariant.uhVal.QuadPart);
00071 case VT_FILETIME:
00072 return ConvertFileTimeToString(propVariant.filetime, true, true);
00073
00074 case VT_I2:
00075 return ConvertInt64ToString(propVariant.iVal);
00076 case VT_I4:
00077 return ConvertInt64ToString(propVariant.lVal);
00078 case VT_I8:
00079 return ConvertInt64ToString(propVariant.hVal.QuadPart);
00080
00081 case VT_BOOL:
00082 return VARIANT_BOOLToBool(propVariant.boolVal) ? L"1" : L"0";
00083 default:
00084 #ifndef _WIN32_WCE
00085 throw 150245;
00086 #else
00087 return UString();
00088 #endif
00089 }
00090 }
00091
00092 UInt64 ConvertPropVariantToUInt64(const PROPVARIANT &propVariant)
00093 {
00094 switch (propVariant.vt)
00095 {
00096 case VT_UI1:
00097 return propVariant.bVal;
00098 case VT_UI2:
00099 return propVariant.uiVal;
00100 case VT_UI4:
00101 return propVariant.ulVal;
00102 case VT_UI8:
00103 return (UInt64)propVariant.uhVal.QuadPart;
00104 default:
00105 #ifndef _WIN32_WCE
00106 throw 151199;
00107 #else
00108 return 0;
00109 #endif
00110 }
00111 }