From e0c295dfd19a666dc3c6721868efd013748a2ccc Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Tue, 2 Sep 2025 10:13:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=AE=89=E8=A3=85=E7=B3=BB=E7=BB=9F):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BA=94=E7=94=A8=E5=90=AF=E5=8A=A8=E5=99=A8?= =?UTF-8?q?=E5=B9=B6=E6=9B=B4=E6=96=B0=E5=AE=89=E8=A3=85=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加新的应用启动器程序(app.lua)用于从/app目录运行应用 将包安装路径从/rom改为/app目录 更新安装器版本号至0.3.6 Beta 2 确保/app目录在安装过程中自动创建 --- data/computercraft/lua/rom/programs/app.lua | 51 +++++++++++++++++++++ data/computercraft/lua/rom/programs/pkg.lua | 8 +++- installer.lua | 8 +++- 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 data/computercraft/lua/rom/programs/app.lua diff --git a/data/computercraft/lua/rom/programs/app.lua b/data/computercraft/lua/rom/programs/app.lua new file mode 100644 index 0000000..65b220d --- /dev/null +++ b/data/computercraft/lua/rom/programs/app.lua @@ -0,0 +1,51 @@ +-- app.lua - Application launcher for LeonOS + +local function show_help() + print("Usage: app [arguments]") + print("Runs an application from the /app directory") + print("") + print("Options:") + print(" --help, -h Show this help message") +end + +local function main(args) + if #args == 0 or args[1] == "--help" or args[1] == "-h" then + show_help() + return + end + + local program_name = args[1] + local program_args = {} + + -- 提取程序参数 + for i=2, #args do + table.insert(program_args, args[i]) + end + + -- 构建程序路径 + local program_path = fs.combine("/app", program_name) + + -- 检查程序是否存在 + if not fs.exists(program_path) then + -- 尝试添加.lua扩展名 + program_path = program_path .. ".lua" + if not fs.exists(program_path) then + print("Error: Application '" .. args[1] .. "' not found in /app directory") + return + end + end + + -- 运行程序 + print("Running application: " .. program_name) + local success, error_msg = pcall(function() + shell.run(program_path, table.unpack(program_args)) + end) + + if not success then + print("Error running application: " .. error_msg) + end +end + +-- 运行主函数 +local args = {...} +main(args) \ No newline at end of file diff --git a/data/computercraft/lua/rom/programs/pkg.lua b/data/computercraft/lua/rom/programs/pkg.lua index 7b75f57..7a7b079 100644 --- a/data/computercraft/lua/rom/programs/pkg.lua +++ b/data/computercraft/lua/rom/programs/pkg.lua @@ -134,9 +134,15 @@ local function install_package(pkg_name, options) -- 安装文件 print("Installing version: " .. latest_version) + -- 确保app目录存在 + local app_dir = "/app" + if not fs.exists(app_dir) then + fs.makeDir(app_dir) + end + for _, file_path in ipairs(meta.files or {}) do local src = fs.combine(version_path, file_path) - local dest = fs.combine("/rom", file_path) + local dest = fs.combine(app_dir, file_path) -- 确保目标目录存在 local dest_dir = fs.getDir(dest) diff --git a/installer.lua b/installer.lua index 410fda9..50513c2 100644 --- a/installer.lua +++ b/installer.lua @@ -1,5 +1,5 @@ -- LeonOS installer -local INSTALLER_VERSION = "0.3.6 Beta 1" +local INSTALLER_VERSION = "0.3.6 Beta 2" local DEFAULT_ROM_DIR = "/leonos" print("Start loading LeonOS installer ("..INSTALLER_VERSION..")...") @@ -150,6 +150,12 @@ local cache_dir = "/packages/cache" if not fs.exists(cache_dir) then fs.makeDir(cache_dir) end + +-- 确保应用目录存在 +local app_dir = "/app" +if not fs.exists(app_dir) then + fs.makeDir(app_dir) +end for i=#to_dl, 1, -1 do local v = to_dl[i] if v.type == "tree" then