1 // PropVariantConvert.cpp
2
3 #include "StdAfx.h"
4
5 #include "../Common/IntToString.h"
6
7 #include "Defs.h"
8 #include "PropVariantConv.h"
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; }
11
ConvertFileTimeToString(const FILETIME & ft,char * s,bool includeTime,bool includeSeconds)12 bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds) throw()
13 {
14 SYSTEMTIME st;
15 if (!BOOLToBool(FileTimeToSystemTime(&ft, &st)))
16 {
17 *s = 0;
18 return false;
19 }
20 unsigned val = st.wYear;
21 if (val >= 10000)
22 {
23 *s++ = (char)('0' + val / 10000);
24 val %= 10000;
25 }
26 {
27 s[3] = (char)('0' + val % 10); val /= 10;
28 s[2] = (char)('0' + val % 10); val /= 10;
29 s[1] = (char)('0' + val % 10);
30 s[0] = (char)('0' + val / 10);
31 s += 4;
32 }
33 UINT_TO_STR_2('-', st.wMonth);
34 UINT_TO_STR_2('-', st.wDay);
35 if (includeTime)
36 {
37 UINT_TO_STR_2(' ', st.wHour);
38 UINT_TO_STR_2(':', st.wMinute);
39 if (includeSeconds)
40 UINT_TO_STR_2(':', st.wSecond);
41 }
42 *s = 0;
43 return true;
44 }
45
ConvertFileTimeToString(const FILETIME & ft,wchar_t * dest,bool includeTime,bool includeSeconds)46 void ConvertFileTimeToString(const FILETIME &ft, wchar_t *dest, bool includeTime, bool includeSeconds) throw()
47 {
48 char s[32];
49 ConvertFileTimeToString(ft, s, includeTime, includeSeconds);
50 for (unsigned i = 0;; i++)
51 {
52 unsigned char c = s[i];
53 dest[i] = c;
54 if (c == 0)
55 return;
56 }
57 }
58
ConvertPropVariantToShortString(const PROPVARIANT & prop,char * dest)59 void ConvertPropVariantToShortString(const PROPVARIANT &prop, char *dest) throw()
60 {
61 *dest = 0;
62 switch (prop.vt)
63 {
64 case VT_EMPTY: return;
65 case VT_BSTR: dest[0] = '?'; dest[1] = 0; return;
66 case VT_UI1: ConvertUInt32ToString(prop.bVal, dest); return;
67 case VT_UI2: ConvertUInt32ToString(prop.uiVal, dest); return;
68 case VT_UI4: ConvertUInt32ToString(prop.ulVal, dest); return;
69 case VT_UI8: ConvertUInt64ToString(prop.uhVal.QuadPart, dest); return;
70 case VT_FILETIME: ConvertFileTimeToString(prop.filetime, dest, true, true); return;
71 // case VT_I1: return ConvertInt64ToString(prop.cVal, dest); return;
72 case VT_I2: ConvertInt64ToString(prop.iVal, dest); return;
73 case VT_I4: ConvertInt64ToString(prop.lVal, dest); return;
74 case VT_I8: ConvertInt64ToString(prop.hVal.QuadPart, dest); return;
75 case VT_BOOL: dest[0] = VARIANT_BOOLToBool(prop.boolVal) ? '+' : '-'; dest[1] = 0; return;
76 default: dest[0] = '?'; dest[1] = ':'; ConvertUInt64ToString(prop.vt, dest + 2);
77 }
78 }
79
ConvertPropVariantToShortString(const PROPVARIANT & prop,wchar_t * dest)80 void ConvertPropVariantToShortString(const PROPVARIANT &prop, wchar_t *dest) throw()
81 {
82 *dest = 0;
83 switch (prop.vt)
84 {
85 case VT_EMPTY: return;
86 case VT_BSTR: dest[0] = '?'; dest[1] = 0; return;
87 case VT_UI1: ConvertUInt32ToString(prop.bVal, dest); return;
88 case VT_UI2: ConvertUInt32ToString(prop.uiVal, dest); return;
89 case VT_UI4: ConvertUInt32ToString(prop.ulVal, dest); return;
90 case VT_UI8: ConvertUInt64ToString(prop.uhVal.QuadPart, dest); return;
91 case VT_FILETIME: ConvertFileTimeToString(prop.filetime, dest, true, true); return;
92 // case VT_I1: return ConvertInt64ToString(prop.cVal, dest); return;
93 case VT_I2: ConvertInt64ToString(prop.iVal, dest); return;
94 case VT_I4: ConvertInt64ToString(prop.lVal, dest); return;
95 case VT_I8: ConvertInt64ToString(prop.hVal.QuadPart, dest); return;
96 case VT_BOOL: dest[0] = VARIANT_BOOLToBool(prop.boolVal) ? '+' : '-'; dest[1] = 0; return;
97 default: dest[0] = '?'; dest[1] = ':'; ConvertUInt32ToString(prop.vt, dest + 2);
98 }
99 }
100