-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathtrashwdx.lua
110 lines (103 loc) · 3.34 KB
/
trashwdx.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
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
-- trashwdx.lua (cross-platform)
-- 2021.11.19
--[[
Getting info about deleted (moved to trash) files: original filename and deletion date.
Use in a trash directory!
Supported fields: see table "fields".
URI decode: http://lua-users.org/wiki/StringRecipes
]]
local fields = {
{"Original filename", "", 8},
{"Parts of full filename", "full|path|name|base name|extension", 8},
{"Deletion date", "", 8},
{"Not older than:", "today|12 hours|1 day|3 days|1 week", 6}
}
local atps = {
"[/\\]%.local[/\\]share[/\\]Trash[/\\]files[/\\]",
"[/\\]%.Trash%-%d+[/\\]files[/\\]",
"[/\\]%.Trash[/\\]%d+[/\\]files[/\\]"
}
-- 12 hours, 1 day, 3 days, 1 week
local atm ={43200, 86400, 259200, 604800}
function ContentGetSupportedField(FieldIndex)
if fields[FieldIndex + 1] ~= nil then
return fields[FieldIndex + 1][1], fields[FieldIndex + 1][2], fields[FieldIndex + 1][3]
end
return "", "", 0
end
function ContentGetDetectString()
return 'EXT="*"'
end
function ContentGetValue(FileName, FieldIndex, UnitIndex, flags)
local fn = SysUtils.ExtractFileName(FileName)
if (fn == '.') or (fn == '..') then return nil end
if CheckPath(FileName) == nil then return nil end
local tmp = SysUtils.ExtractFileDir(FileName)
if SysUtils.ExtractFileName(tmp) ~= 'files' then return nil end
local ft = SysUtils.ExtractFileDir(tmp) .. SysUtils.PathDelim .. 'info' .. SysUtils.PathDelim .. fn .. '.trashinfo'
local h = io.open(ft, 'r')
if h == nil then return nil end
local ftc = h:read('*a')
h:close()
fn = string.match(ftc, 'Path=([^\r\n]+)')
if string.find(fn, '%', 1, true) ~= nil then
fn = string.gsub(fn, "%%(%x%x)",
function(h) return string.char(tonumber(h,16)) end)
end
if FieldIndex == 0 then
return SysUtils.ExtractFileName(fn)
elseif FieldIndex == 1 then
if UnitIndex == 0 then
return fn
elseif UnitIndex == 1 then
return SysUtils.ExtractFileDir(fn)
elseif UnitIndex == 2 then
return SysUtils.ExtractFileName(fn)
elseif UnitIndex == 3 then
local t = SysUtils.ExtractFileName(fn)
local e = SysUtils.ExtractFileExt(t)
if string.len(e) > 1 then
return string.sub(t, 1, string.len(t) - string.len(e))
else
return t
end
elseif UnitIndex == 4 then
local t = SysUtils.ExtractFileExt(fn)
if string.len(t) > 1 then
return string.sub(t, 2, -1)
else
return nil
end
end
else
local ds = string.match(ftc, 'DeletionDate=([^\r\n]+)')
if FieldIndex == 2 then
return string.gsub(ds, 'T', ' ')
elseif FieldIndex == 3 then
local dd = {}
dd.year, dd.month, dd.day, dd.hour, dd.min, dd.sec = string.match(ds, '(%d%d%d%d)%-(%d%d)%-(%d%d)T(%d%d):(%d%d):(%d%d)')
for k, v in pairs(dd) do dd[k] = tonumber(v) end
if UnitIndex == 0 then --today
local cd = os.date('*t')
if (dd.year == cd.year) and (dd.month == cd.month) and (dd.day == cd.day) then
return true
else
return false
end
else
local cd = os.time()
local i = cd - os.time(dd)
if atm[UnitIndex + 1] ~= nil then
if i < atm[UnitIndex + 1] then return true else return false end
end
end
end
end
return nil
end
function CheckPath(s)
for i = 1, #atps do
if string.find(s, atps[i]) ~= nil then return true end
end
return nil
end