misc/libphysfs/lzma/CPP/7zip/UI/Common/PropIDUtils.cpp
branchui-scaling
changeset 15283 c4fd2813b127
parent 13390 0135e64c6c66
parent 15279 7ab5cf405686
child 15663 d92eeb468dad
equal deleted inserted replaced
13390:0135e64c6c66 15283:c4fd2813b127
     1 // PropIDUtils.cpp
       
     2 
       
     3 #include "StdAfx.h"
       
     4 
       
     5 #include "PropIDUtils.h"
       
     6 
       
     7 #include "Common/IntToString.h"
       
     8 #include "Common/StringConvert.h"
       
     9 
       
    10 #include "Windows/FileFind.h"
       
    11 #include "Windows/PropVariantConversions.h"
       
    12 
       
    13 #include "../../PropID.h"
       
    14 
       
    15 using namespace NWindows;
       
    16 
       
    17 static UString ConvertUInt32ToString(UInt32 value)
       
    18 {
       
    19   wchar_t buffer[32];
       
    20   ConvertUInt64ToString(value, buffer);
       
    21   return buffer;
       
    22 }
       
    23 
       
    24 static void ConvertUInt32ToHex(UInt32 value, wchar_t *s)
       
    25 {
       
    26   for (int i = 0; i < 8; i++)
       
    27   {
       
    28     int t = value & 0xF;
       
    29     value >>= 4;
       
    30     s[7 - i] = (wchar_t)((t < 10) ? (L'0' + t) : (L'A' + (t - 10)));
       
    31   }
       
    32   s[8] = L'\0';
       
    33 }
       
    34 
       
    35 UString ConvertPropertyToString(const PROPVARIANT &propVariant, PROPID propID, bool full)
       
    36 {
       
    37   switch(propID)
       
    38   {
       
    39     case kpidCreationTime:
       
    40     case kpidLastWriteTime:
       
    41     case kpidLastAccessTime:
       
    42     {
       
    43       if (propVariant.vt != VT_FILETIME)
       
    44         return UString(); // It is error;
       
    45       FILETIME localFileTime;
       
    46       if (propVariant.filetime.dwHighDateTime == 0 && 
       
    47           propVariant.filetime.dwLowDateTime == 0)
       
    48         return UString();
       
    49       if (!::FileTimeToLocalFileTime(&propVariant.filetime, &localFileTime))
       
    50         return UString(); // It is error;
       
    51       return ConvertFileTimeToString(localFileTime, true, full);
       
    52     }
       
    53     case kpidCRC:
       
    54     {
       
    55       if(propVariant.vt != VT_UI4)
       
    56         break;
       
    57       wchar_t temp[12];
       
    58       ConvertUInt32ToHex(propVariant.ulVal, temp);
       
    59       return temp;
       
    60     }
       
    61     case kpidAttributes:
       
    62     {
       
    63       if(propVariant.vt != VT_UI4)
       
    64         break;
       
    65       UString result;
       
    66       UInt32 attributes = propVariant.ulVal;
       
    67       if (NFile::NFind::NAttributes::IsReadOnly(attributes)) result += L'R';
       
    68       if (NFile::NFind::NAttributes::IsHidden(attributes)) result += L'H';
       
    69       if (NFile::NFind::NAttributes::IsSystem(attributes)) result += L'S';
       
    70       if (NFile::NFind::NAttributes::IsDirectory(attributes)) result += L'D';
       
    71       if (NFile::NFind::NAttributes::IsArchived(attributes)) result += L'A';
       
    72       if (NFile::NFind::NAttributes::IsCompressed(attributes)) result += L'C';
       
    73       if (NFile::NFind::NAttributes::IsEncrypted(attributes)) result += L'E';
       
    74       return result;
       
    75     }
       
    76     case kpidDictionarySize:
       
    77     {
       
    78       if(propVariant.vt != VT_UI4)
       
    79         break;
       
    80       UInt32 size = propVariant.ulVal;
       
    81       if (size % (1 << 20) == 0)
       
    82         return ConvertUInt32ToString(size >> 20) + L"MB";
       
    83       if (size % (1 << 10) == 0)
       
    84         return ConvertUInt32ToString(size >> 10) + L"KB";
       
    85       return ConvertUInt32ToString(size);
       
    86     }
       
    87   }
       
    88   return ConvertPropVariantToString(propVariant);
       
    89 }