-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileutil.lua
84 lines (68 loc) · 1.41 KB
/
fileutil.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
function EraseFiles(cb, files)
if not next(files) then
if cb then
cb(true, {})
end
end
local res = {
}
for i,v in pairs(files) do
res[v] = true
end
local overall_success = true
local deleted_files = {}
local function onerased(success, file)
res[file] = nil
if success then
table.insert(deleted_files, file)
else
overall_success = false
end
if not next(res) then
if cb then
cb(overall_success, deleted_files)
end
end
end
for i,v in pairs(files) do
if PLATFORM == "PS4" then
-- skip the file exists check on console
print("Erasing", v)
ErasePersistentString(v, function(success) onerased(success, v) end)
else
TheSim:CheckPersistentStringExists(v, function(exists)
if exists == true then
print("Erasing", v)
ErasePersistentString(v, function(success) onerased(success, v) end)
else
onerased(true, v)
end
end)
end
end
end
function CheckFiles(cb, files)
if not next(files) then
if cb then
cb{}
end
end
local res = {
}
for i,v in pairs(files) do
res[v] = true
end
local file_status = {}
local function onchecked(success, file)
res[file] = nil
file_status[file] = success
if not next(res) then
if cb then
cb(file_status)
end
end
end
for i,v in pairs(files) do
TheSim:CheckPersistentStringExists(v, function(exists) onchecked(exists, v) end)
end
end