Merge pull request #906 from jgmdev/PR/temp-file-other-dir

core: fixes and changes to temp files
This commit is contained in:
Jefferson González 2022-03-29 16:33:08 -04:00 committed by GitHub
commit 7372d2f82d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 6 deletions

View File

@ -809,17 +809,19 @@ local temp_uid = math.floor(system.get_time() * 1000) % 0xffffffff
local temp_file_prefix = string.format(".lite_temp_%08x", tonumber(temp_uid)) local temp_file_prefix = string.format(".lite_temp_%08x", tonumber(temp_uid))
local temp_file_counter = 0 local temp_file_counter = 0
local function delete_temp_files() function core.delete_temp_files(dir)
for _, filename in ipairs(system.list_dir(EXEDIR)) do dir = type(dir) == "string" and common.normalize_path(dir) or USERDIR
for _, filename in ipairs(system.list_dir(dir)) do
if filename:find(temp_file_prefix, 1, true) == 1 then if filename:find(temp_file_prefix, 1, true) == 1 then
os.remove(EXEDIR .. PATHSEP .. filename) os.remove(dir .. PATHSEP .. filename)
end end
end end
end end
function core.temp_filename(ext) function core.temp_filename(ext, dir)
dir = type(dir) == "string" and common.normalize_path(dir) or USERDIR
temp_file_counter = temp_file_counter + 1 temp_file_counter = temp_file_counter + 1
return USERDIR .. PATHSEP .. temp_file_prefix return dir .. PATHSEP .. temp_file_prefix
.. string.format("%06x", temp_file_counter) .. (ext or "") .. string.format("%06x", temp_file_counter) .. (ext or "")
end end
@ -834,7 +836,7 @@ end
local function quit_with_function(quit_fn, force) local function quit_with_function(quit_fn, force)
if force then if force then
delete_temp_files() core.delete_temp_files()
core.on_quit_project() core.on_quit_project()
save_session() save_session()
quit_fn() quit_fn()