-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathextstatwdx.lua
More file actions
137 lines (125 loc) · 4.68 KB
/
extstatwdx.lua
File metadata and controls
137 lines (125 loc) · 4.68 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
local ext_allowed = { -- add extensions here
"mp3", "flac", "ogg", "wav",
"pdf", "doc", "docx", "odt",
}
local notfound = "no suitable filetypes found"
local bytes = 1024 -- or 1000
local extlist = {}
local lastdir = ''
local lastmode = nil
local units = ''
for i = 1, #ext_allowed do
if (units == '') then
units = ext_allowed[i];
else
units = units .. '|' .. ext_allowed[i];
end
end
local fields = {
{"count", 2, units, false, 0},
{"count (recursively)", 2, units, true, 0},
{"size", 2, units, false, 0},
{"size (recursively)", 2, units, true, 0},
{"size K", 3, units, false, 1},
{"size K (recursively)", 3, units, true, 1},
{"size M", 3, units, false, 2},
{"size M (recursively)", 3, units, true, 2},
{"size G", 3, units, false, 3},
{"size G (recursively)", 3, units, true, 3},
{"size T", 3, units, false, 4},
{"size T (recursively)", 3, units, true, 4},
{"tooltip", 8, '', false, 0},
{"tooltip (recursively)", 8, '', true, 0},
}
function ContentGetSupportedField(FieldIndex)
if (fields[FieldIndex + 1] ~= nil) then
return fields[FieldIndex + 1][1], fields[FieldIndex + 1][3], fields[FieldIndex + 1][2];
end
return '', '', 0; -- ft_nomorefields
end
function ContentGetValue(FileName, FieldIndex, UnitIndex, flags)
if SysUtils.DirectoryExists(FileName) then
if (lastdir ~= FileName) or (lastmode ~= fields[FieldIndex + 1][4]) then
extlist = {};
if (fields[FieldIndex + 1][4] == true) then
chkdir(FileName, true);
else
chkdir(FileName, false);
end
lastdir = FileName;
lastmode = fields[FieldIndex + 1][4];
end
local result = nil;
if (fields[FieldIndex + 1][2] == 8) then
result = '';
for ext, val in pairs(extlist) do
if string.find('|' .. units .. '|', '|' .. ext .. '|') then
if (result == '') then
result = ext .. ": " .. val["count"] .. ', ' .. strsize(val["size"]);
else
result = result .. '\n' .. ext .. ": " .. val["count"] .. ', ' .. strsize(val["size"]);
end
end
end
if (result == '') then
result = notfound;
end
else
local ext = ext_allowed[UnitIndex + 1];
if (extlist[ext] ~= nil) then
if (FieldIndex < 2) then
result = extlist[ext]["count"];
else
result = extlist[ext]["size"];
end
if (fields[FieldIndex + 1][5] > 0) then
result = result / math_pow(bytes, fields[FieldIndex + 1][5]);
end
end
end
return result;
end
return nil;
end
function chkdir(path, recursive)
local handle, FindData = SysUtils.FindFirst(path .. SysUtils.PathDelim .. '*');
if (handle ~= nil) then
repeat
if (FindData.Name ~= ".") and (FindData.Name ~= "..") then
if (math.floor(FindData.Attr / 0x00000010) % 2 ~= 0) and (recursive == true) then
chkdir(path .. SysUtils.PathDelim .. FindData.Name, recursive);
else
local ext = FindData.Name:match(".+%.(.+)$");
if (ext ~= nil) then
ext = ext:lower();
if (extlist[ext] ~= nil) then
extlist[ext]["count"] = extlist[ext]["count"] + 1;
extlist[ext]["size"] = extlist[ext]["size"] + FindData.Size;
else
extlist[ext] = {};
extlist[ext]["count"] = 1;
extlist[ext]["size"] = FindData.Size;
end
end
end
end
found, FindData = SysUtils.FindNext(handle);
until (found == nil)
SysUtils.FindClose(handle);
end
end
function math_pow(a, b)
return a ^ b
end
function strsize(size)
if (size > math_pow(bytes, 4)) then
return string.format("%.1f T", size / math_pow(bytes, 4));
elseif (size > math_pow(bytes, 3)) then
return string.format("%.1f G", size / math_pow(bytes, 3));
elseif (size > math_pow(bytes, 2)) then
return string.format("%.1f M", size / math_pow(bytes, 2));
elseif (size > bytes) then
return string.format("%.1f K", size / bytes);
end
return size;
end