-
Notifications
You must be signed in to change notification settings - Fork 24
/
filewinattrexwdx.lua
84 lines (75 loc) · 1.83 KB
/
filewinattrexwdx.lua
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
-- filewinattrexwdx.lua (Windows only)
-- 2022.03.21
--[[
Return file attributes (Windows only!)
A - Archive;
C - Compressed;
D - Directory;
E - Encrypted;
H - Hidden;
I - Not content indexed;
L - Symbolic link/Junction/Mount point;
O - Offline;
P - Pinned (OneDrive "always available files");
R - Read-only;
S - System;
T - Temporary;
U - Unpinned (OneDrive "online-only files");
V - Integrity;
X - No scrub.
as string "ACDEHILOPRSTUVX" (i.e. only set attributes).
]]
local ffi = require("ffi")
local flib = ffi.load("kernel32")
ffi.cdef[[
int GetFileAttributesW(const char *lpFileName);
]]
local afattr = {
{0x00000020, "A"},
{0x00000800, "C"},
{0x00000010, "D"},
{0x00004000, "E"},
{0x00000002, "H"},
{0x00002000, "I"},
{0x00000400, "L"},
{0x00001000, "O"},
{0x00080000, "P"},
{0x00000001, "R"},
{0x00000004, "S"},
{0x00000100, "T"},
{0x00100000, "U"},
{0x00008000, "V"},
{0x00020000, "X"}
}
function ContentGetSupportedField(FieldIndex)
if FieldIndex == 0 then
return "AttrEx", "", 8
end
return "", "", 0
end
function ContentGetDefaultSortOrder(FieldIndex)
return 1; --or -1
end
function ContentGetDetectString()
return 'EXT="*"'
end
function ContentGetValue(FileName, FieldIndex, UnitIndex, flags)
if FieldIndex == 0 then
local tmp
if string.sub(FileName, 1, 2) == '\\\\' then
tmp = LazUtf8.ConvertEncoding(FileName, 'utf8', 'ucs2le')
else
tmp = LazUtf8.ConvertEncoding('\\\\?\\' .. FileName, 'utf8', 'ucs2le')
end
local attr = flib.GetFileAttributesW(tmp)
if attr < 0 then return nil end
-- Skip directories
--if math.floor(attr / 0x00000010) % 2 ~= 0 then return nil end
tmp = ''
for i = 1, #afattr do
if math.floor(attr / afattr[i][1]) % 2 ~= 0 then tmp = tmp .. afattr[i][2] end
end
if tmp ~= '' then return tmp end
end
return nil
end