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