+26
data/core/init.lua
+26
data/core/init.lua
···
120
end
121
122
123
+
math.randomseed(system.get_time() * 1000)
124
+
125
+
local function uid()
126
+
return string.gsub("xxxxxx", ".", function()
127
+
local chars = "0123456789abcdefghijklmnopqrstuvwxyz"
128
+
local n = math.random(#chars)
129
+
return chars:sub(n, n)
130
+
end)
131
+
end
132
+
133
+
local temp_file_prefix = ".temp_" .. uid()
134
+
135
+
local function delete_temp_files()
136
+
for _, filename in ipairs(system.list_dir(EXEDIR)) do
137
+
if filename:find(temp_file_prefix, 1, true) == 1 then
138
+
os.remove(EXEDIR .. PATHSEP .. filename)
139
+
end
140
+
end
141
+
end
142
+
143
+
function core.temp_filename(ext)
144
+
return EXEDIR .. PATHSEP .. temp_file_prefix .. uid() .. (ext or "")
145
+
end
146
+
147
+
148
function core.quit(force)
149
if force then
150
+
delete_temp_files()
151
os.exit()
152
end
153
local dirty_count = 0