-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy patharchivecommentwdx.lua
69 lines (62 loc) · 1.98 KB
/
archivecommentwdx.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
local settings = {
['zip' ] = {
'unzip -z "$FILE"', -- command
"^Archive[^\n]+\n(.+)\n$" -- pattern
},
['rar' ] = {
'rar l "$FILE" -p-',
"Type 'rar %-%?' for help\n\n(.+)\n\n\nArchive: "
},
}
local notfoundstr = "not found"
function ContentGetSupportedField(FieldIndex)
if (FieldIndex == 0) then
return "comment", 'default|show "' .. notfoundstr .. '"', 8; -- FieldName,Units,ft_string
end
return '', '', 0; -- ft_nomorefields
end
function ContentGetDetectString()
local detect_string = '';
for ext in pairs(settings) do
if (detect_string == '') then
detect_string = '(EXT="' .. ext:upper() .. '")';
else
detect_string = detect_string .. ' | (EXT="' .. ext:upper() .. '")';
end
end
return detect_string; -- return detect string
end
function ContentGetValue(FileName, FieldIndex, UnitIndex, flags)
if not SysUtils.DirectoryExists(FileName) and (FieldIndex == 0) then
local result = nil;
local ext = FileName:match(".+%.(.+)$");
if (ext ~= nil) then
ext = ext:lower();
if (settings[ext] ~= nil) then
local handle = io.popen(settings[ext][1]:gsub("$FILE", escapestr(FileName)), 'r');
local output = handle:read("*a");
handle:close();
if (output ~= nil) then
result = output:match(settings[ext][2]);
end
end
end
if (UnitIndex == 1) and (result == nil) then
return notfoundstr;
else
return result;
end
end
return nil; -- invalid
end
function escapestr(str)
local magic_chars = {"%", ".", "-", "+", "*", "?", "^", "$", "(", ")", "["};
local result = nil;
if (str ~= nil) then
result = str;
for k, chr in pairs(magic_chars) do
result = result:gsub("%" .. chr, "%%%" .. chr);
end
end
return result;
end