From 40ac8993605d45ae68157a6ee70d2550806a4f72 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sat, 12 Dec 2020 00:05:11 +0100 Subject: [PATCH] Restore core.quit and core.temp_filename to be compatible with Lite --- data/core/init.lua | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/data/core/init.lua b/data/core/init.lua index 59601d2e..e0ec3289 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -303,11 +303,33 @@ function core.confirm_close_all() return true end +local temp_uid = (system.get_time() * 1000) % 0xffffffff +local temp_file_prefix = string.format(".lite_temp_%08x", temp_uid) +local temp_file_counter = 0 + +local function delete_temp_files() + for _, filename in ipairs(system.list_dir(EXEDIR)) do + if filename:find(temp_file_prefix, 1, true) == 1 then + os.remove(EXEDIR .. PATHSEP .. filename) + end + end +end + +function core.temp_filename(ext) + temp_file_counter = temp_file_counter + 1 + return EXEDIR .. PATHSEP .. temp_file_prefix + .. string.format("%06x", temp_file_counter) .. (ext or "") +end + function core.quit(force) - if core.confirm_close_all() then + if force then + delete_temp_files() os.exit() end + if core.confirm_close_all() then + core.quit(true) + end end