From 8bfd7ca340c380bdf2c7f1717bb4991cf36c25a8 Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Sat, 19 Feb 2022 14:52:38 +0200 Subject: [PATCH] warning on file size over 400000 b --- frontend/apps/filemanager/filemanager.lua | 37 +++++++++++++++++------ 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/frontend/apps/filemanager/filemanager.lua b/frontend/apps/filemanager/filemanager.lua index 9bc154b02..53026f86b 100644 --- a/frontend/apps/filemanager/filemanager.lua +++ b/frontend/apps/filemanager/filemanager.lua @@ -1286,16 +1286,33 @@ function FileManager:showFiles(path, focused_file) end function FileManager:openTextViewer(file_path) - local file = io.open(file_path, "rb") - if not file then return end - local file_content = file:read("*all") - file:close() - UIManager:show(require("ui/widget/textviewer"):new{ - title = file_path, - title_multilines = true, - justified = false, - text = file_content, - }) + local function _openTextViewer(filepath) + local file = io.open(filepath, "rb") + if not file then return end + local file_content = file:read("*all") + file:close() + UIManager:show(require("ui/widget/textviewer"):new{ + title = filepath, + title_multilines = true, + justified = false, + text = file_content, + }) + end + local attr = lfs.attributes(file_path) + if attr then + if attr.size > 400000 then + UIManager:show(ConfirmBox:new{ + text = T(_("This file is %2:\n\n%1\n\nAre you sure you want to open it?\n\nOpening big files may take some time."), + BD.filepath(file_path), util.getFriendlySize(attr.size)), + ok_text = _("Open"), + ok_callback = function() + _openTextViewer(file_path) + end, + }) + else + _openTextViewer(file_path) + end + end end --- A shortcut to execute mv.