Skip to content

Commit

Permalink
show Attrib parameter as 7z 17.01
Browse files Browse the repository at this point in the history
  • Loading branch information
w17 committed Sep 14, 2017
1 parent 28bbe60 commit cec3d40
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 25 deletions.
115 changes: 91 additions & 24 deletions plugins/arclite/attr.cpp
Expand Up @@ -84,43 +84,110 @@ wstring format_crc_prop(const PropVariant& prop) {
return uint_to_hex_str(prop.get_uint(), prop.get_int_size() * 2);
}

wstring format_attrib_prop(const PropVariant& prop) {
static const wchar_t kPosixTypes[16 + 1] = L"0pc3d5b7-9lBsDEF";
#define ATTR_CHAR(a, n, c) (((a) & (1 << (n))) ? c : L'-')

wstring format_posix_attrib_prop(const PropVariant& prop)
{
if (!prop.is_uint())
return wstring();
const wchar_t c_win_attr[] = L"RHS8DAdNTsrCOnE_";
wchar_t attr[ARRAYSIZE(c_win_attr)];
unsigned pos = 0;

unsigned val = static_cast<unsigned>(prop.get_uint());
for (unsigned i = 0; i < ARRAYSIZE(c_win_attr); i++) {
if ((val & (1 << i)) && i != 7) {
attr[pos] = c_win_attr[i];
pos++;
}
wchar_t attr[10];

attr[0] = kPosixTypes[(val >> 12) & 0xF];
for (int i = 6; i >= 0; i -= 3)
{
attr[7 - i] = ATTR_CHAR(val, i + 2, L'r');
attr[8 - i] = ATTR_CHAR(val, i + 1, L'w');
attr[9 - i] = ATTR_CHAR(val, i + 0, L'x');
}
return wstring(attr, pos);
if ((val & 0x800) != 0) attr[3] = ((val & (1 << 6)) ? L's' : L'S');
if ((val & 0x400) != 0) attr[6] = ((val & (1 << 3)) ? L's' : L'S');
if ((val & 0x200) != 0) attr[9] = ((val & (1 << 0)) ? L't' : L'T');

val &= ~(unsigned)0xFFFF;
return val ? wstring(attr, 10) + L' ' + uint_to_hex_str(val, 8) : wstring(attr, 10);
}

#define ATTR_CHAR(a, n, c) (((a) & (1 << (n))) ? c : L'-')
wstring format_posix_attrib_prop(const PropVariant& prop) {
static const unsigned kNumWinAtrribFlags = 21;
static const wchar_t g_WinAttribChars[kNumWinAtrribFlags + 1] = L"RHS8DAdNTsLCOIEV.X.PU";

/* FILE_ATTRIBUTE_
0 READONLY
1 HIDDEN
2 SYSTEM
3 (Volume label - obsolete)
4 DIRECTORY
5 ARCHIVE
6 DEVICE
7 NORMAL
8 TEMPORARY
9 SPARSE_FILE
10 REPARSE_POINT
11 COMPRESSED
12 OFFLINE
13 NOT_CONTENT_INDEXED (I - Win10 attrib/Explorer)
14 ENCRYPTED
15 INTEGRITY_STREAM (V - ReFS Win8/Win2012)
16 VIRTUAL (reserved)
17 NO_SCRUB_DATA (X - ReFS Win8/Win2012 attrib)
18 RECALL_ON_OPEN or EA
19 PINNED
20 UNPINNED
21 STRICTLY_SEQUENTIAL
22 RECALL_ON_DATA_ACCESS
*/

wstring format_attrib_prop(const PropVariant& prop)
{
if (!prop.is_uint())
return wstring();

// some programs store posix attributes in high 16 bits.
// p7zip - stores additional 0x8000 flag marker.
// macos - stores additional 0x4000 flag marker.
// info-zip - no additional marker.

unsigned val = static_cast<unsigned>(prop.get_uint());
wchar_t attr[10];
attr[0] = ATTR_CHAR(val, 14, L'd');
for (int i = 6; i >= 0; i -= 3) {
attr[7 - i] = ATTR_CHAR(val, i + 2, L'r');
attr[8 - i] = ATTR_CHAR(val, i + 1, L'w');
attr[9 - i] = ATTR_CHAR(val, i + 0, L'x');
bool isPosix = ((val & 0xF0000000) != 0);

unsigned posix = 0;
if (isPosix) {
posix = val >> 16;
val &= (unsigned)0x3FFF;
}

wchar_t attr[kNumWinAtrribFlags];
size_t na = 0;
for (unsigned i = 0; i < kNumWinAtrribFlags; i++) {
unsigned flag = (1U << i);
if ((val & flag) != 0) {
auto c = g_WinAttribChars[i];
if (c != L'.') {
val &= ~flag;
// if (i != 7) // we can disable N (NORMAL) printing
attr[na++] = c;
}
}
}
auto res = wstring(attr, na);

if (val != 0) {
if (na)
res += L' ';
res += uint_to_hex_str(val, 8);
}

if (isPosix) {
if (!res.empty())
res += L' ';
PropVariant p((UInt32)posix);
res += format_posix_attrib_prop(p);
}
wstring res(attr, ARRAYSIZE(attr));

unsigned extra = val & 0x3E00;
if (extra)
res = uint_to_hex_str(extra, 4) + L' ' + res;
return res;
}
#undef ATTR_CHAR


typedef wstring (*PropToString)(const PropVariant& var);

Expand Down
4 changes: 4 additions & 0 deletions plugins/arclite/changelog
@@ -1,3 +1,7 @@
w17 14.09.2017 13:03:45 +0300 - build 260

1. Доработка показа атрибутов архива (как в 7z 17.01).

w17 13.09.2017 13:11:58 +0300 - build 259

1. Новые имена параметров в диалоге атрибутов (Ctrl-A).
Expand Down
2 changes: 1 addition & 1 deletion plugins/arclite/project.ini
Expand Up @@ -2,4 +2,4 @@
MODULE = arclite
VER_MAJOR = 3
VER_MINOR = 0
VER_BUILD = 259
VER_BUILD = 260

0 comments on commit cec3d40

Please sign in to comment.