-
Notifications
You must be signed in to change notification settings - Fork 24
/
7zipwdx.lua
79 lines (73 loc) · 3.22 KB
/
7zipwdx.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
-- 7zipwdx.lua
local cmd = "7z l"
local params = "-p 2>&1"
local output = ''
local filename = ''
local fields = {
{"Type", 8, "\nType%s=%s([^\n]+)", false},
{"Method", 8, "\nMethod%s=%s([^\n]+)", false},
{"Solid", 8, "\nSolid%s=%s([^\n]+)", false},
{"Offset", 8, "\nOffset%s=%s([^\n]+)", false},
{"Headers Size", 2, "\nHeaders%sSize%s=%s([^\n]+)", false},
{"Tail Size", 2, "\nTail%sSize%s=%s([^\n]+)", false},
{"Blocks", 2, "\nBlocks%s=%s([^\n]+)", false},
{"Streams", 2, "\nStreams%s=%s([^\n]+)", false},
{"Comment", 8, "\nComment%s=%s([^\n]+)", false},
{"Multivolume", 8, "\nMultivolume%s=%s([^\n]+)", false},
{"Volumes", 2, "\nVolumes%s=%s([^\n]+)", false},
{"Code Page", 8, "\nCode%sPage%s=%s([^\n]+)", false},
{"Files", 2, "(%d+)%sfiles", true},
{"Folders", 2, "(%d+)%sfolders", true},
{"Size", 2, "(%d+)%s+%d+%s+%d+%sf", true},
{"Compressed", 2, "(%d+)%s+%d+%sf", true},
{"Date", 8, "%d%d%d%d%-%d%d%-%d%d%s%d%d:%d%d:%d%d", true},
{"Warnings", 2, "Warnings:%s(%d+)", true},
{"Errors", 2, "Errors:%s(%d+)", true},
{"Encrypted", 6, ":%sCan%snot%sopen%s(encrypted)%sarchive", true},
}
function ContentGetSupportedField(FieldIndex)
if (fields[FieldIndex + 1] ~= nil ) then
return fields[FieldIndex + 1][1], "", fields[FieldIndex + 1][2];
end
return '', '', 0; -- ft_nomorefields
end
function ContentGetDetectString()
return 'EXT="7Z" | EXT="ZIP" | EXT="RAR" | EXT="XZ" | EXT="GZ" | EXT="Z" | EXT="LZMA" | EXT="BZ2" | EXT="TAR" | EXT="ZIPX"';
end
function ContentGetValue(FileName, FieldIndex, UnitIndex, flags)
if (filename ~= FileName) then
local attr = SysUtils.FileGetAttr(FileName);
if (attr < 0) or (math.floor(attr / 0x00000004) % 2 ~= 0) or (math.floor(attr / 0x00000010) % 2 ~= 0) then
return nil;
end
local handle = io.popen(cmd .. ' "' .. FileName:gsub('"', '\\"') .. '" ' .. params, 'r');
output = handle:read("*a");
handle:close();
filename = FileName;
end
if (output ~= nil) then
local target = output;
local result = '';
if (fields[FieldIndex + 1][4] == true) then
target = output:match("%-([%w%s%-:,]+)\n$");
end
if (target ~= nil) and (fields[FieldIndex + 1][3] ~= nil) then
result = target:match(fields[FieldIndex + 1][3]);
else
return nil;
end
if (fields[FieldIndex + 1][2] == 6) then
if (result == nil) then
return false;
else
return true;
end
elseif (fields[FieldIndex + 1][2] == 2) and (result == nil) then
if (FieldIndex == 12) or (FieldIndex == 13) then
return 0;
end
end
return result;
end
return nil; -- invalid
end