1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
// PropIDUtils.cpp
#include "StdAfx.h"
#include "Common/IntToString.h"
#include "Windows/FileFind.h"
#include "Windows/PropVariantConversions.h"
#include "../../PropID.h"
#include "PropIDUtils.h"
using namespace NWindows;
void ConvertUInt32ToHex(UInt32 value, wchar_t *s)
{
for (int i = 0; i < 8; i++)
{
int t = value & 0xF;
value >>= 4;
s[7 - i] = (wchar_t)((t < 10) ? (L'0' + t) : (L'A' + (t - 10)));
}
s[8] = L'\0';
}
#define MY_ATTR_CHAR(a, n, c) ((a )& (1 << (n))) ? c : L'-';
UString ConvertPropertyToString(const PROPVARIANT &prop, PROPID propID, bool full)
{
switch(propID)
{
case kpidCTime:
case kpidATime:
case kpidMTime:
{
if (prop.vt != VT_FILETIME)
break;
FILETIME localFileTime;
if ((prop.filetime.dwHighDateTime == 0 &&
prop.filetime.dwLowDateTime == 0) ||
!::FileTimeToLocalFileTime(&prop.filetime, &localFileTime))
return UString();
return ConvertFileTimeToString(localFileTime, true, full);
}
case kpidCRC:
{
if (prop.vt != VT_UI4)
break;
wchar_t temp[12];
ConvertUInt32ToHex(prop.ulVal, temp);
return temp;
}
case kpidAttrib:
{
if (prop.vt != VT_UI4)
break;
UString res;
UInt32 a = prop.ulVal;
if (NFile::NFind::NAttributes::IsReadOnly(a)) res += L'R';
if (NFile::NFind::NAttributes::IsHidden(a)) res += L'H';
if (NFile::NFind::NAttributes::IsSystem(a)) res += L'S';
if (NFile::NFind::NAttributes::IsDir(a)) res += L'D';
if (NFile::NFind::NAttributes::IsArchived(a)) res += L'A';
if (NFile::NFind::NAttributes::IsCompressed(a)) res += L'C';
if (NFile::NFind::NAttributes::IsEncrypted(a)) res += L'E';
return res;
}
case kpidPosixAttrib:
{
if (prop.vt != VT_UI4)
break;
UString res;
UInt32 a = prop.ulVal;
wchar_t temp[16];
temp[0] = MY_ATTR_CHAR(a, 14, L'd');
for (int i = 6; i >= 0; i -= 3)
{
temp[7 - i] = MY_ATTR_CHAR(a, i + 2, L'r');
temp[8 - i] = MY_ATTR_CHAR(a, i + 1, L'w');
temp[9 - i] = MY_ATTR_CHAR(a, i + 0, L'x');
}
temp[10] = 0;
res = temp;
a &= ~0x1FF;
a &= ~0xC000;
if (a != 0)
{
ConvertUInt32ToHex(a, temp);
res = UString(temp) + L' ' + res;
}
return res;
}
}
return ConvertPropVariantToString(prop);
}
|