mirror of
https://github.com/CCLeonOS/LeonOS.git
synced 2026-03-03 15:17:01 +00:00
feat(安装系统): 添加应用启动器并更新安装路径
添加新的应用启动器程序(app.lua)用于从/app目录运行应用 将包安装路径从/rom改为/app目录 更新安装器版本号至0.3.6 Beta 2 确保/app目录在安装过程中自动创建
This commit is contained in:
51
data/computercraft/lua/rom/programs/app.lua
Normal file
51
data/computercraft/lua/rom/programs/app.lua
Normal file
@@ -0,0 +1,51 @@
|
||||
-- app.lua - Application launcher for LeonOS
|
||||
|
||||
local function show_help()
|
||||
print("Usage: app <program_name> [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)
|
||||
Reference in New Issue
Block a user