From bbeeb40d6a67aa51bd5ccd7463c9bc39373c2dcc Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Mon, 15 Mar 2021 21:48:58 +0800 Subject: [PATCH] =?UTF-8?q?cmd=E5=8A=A0=E5=85=A5tree=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/scenes/app_cmd.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/parts/scenes/app_cmd.lua b/parts/scenes/app_cmd.lua index 30d060ff..c7aa8bb4 100644 --- a/parts/scenes/app_cmd.lua +++ b/parts/scenes/app_cmd.lua @@ -12,6 +12,8 @@ log{COLOR.dRed,"DO NOT RUN ANY CODE YOU DON'T UNDERSTAND"} local history,hisPtr={"?"} local the_secret=(14^2*10)..(2*11) + + local commands={} --Basic commands do--commands.help(arg) @@ -71,6 +73,14 @@ do--commands.help(arg) "Usage: url [url]", }, }, + tree={ + description="List all files & directories in the save directory", + details={ + "List all files & directories in the save directory", + "", + "Usage: tree", + }, + }, cls={ description="Clear the log output.", details={ @@ -188,6 +198,7 @@ do--commands.help(arg) "exit", "echo", "url", + "tree", "cls", "rst", "shutdown", @@ -256,6 +267,28 @@ function commands.url(url) log{COLOR.water,"Usage: url [url]"} end end +local function tree(path,name,depth) + local info=love.filesystem.getInfo(path..name) + if info.type=="file"then + log(string.rep("\t\t",depth)..name) + elseif info.type=="directory"then + log(string.rep("\t\t",depth)..name..">") + local L=love.filesystem.getDirectoryItems(path..name) + for _,subName in next,L do + tree(path..name.."/",subName,depth+1) + end + else + log("Unkown item type: %s (%s)"):format(name,info.type) + end +end +function commands.tree() + local L=love.filesystem.getDirectoryItems("") + for _,name in next,L do + if love.filesystem.getRealDirectory(name)==SAVEDIR then + tree("",name,0) + end + end +end commands.exit=backScene commands.quit=backScene commands.bye=backScene