Generate-Config Fix
This commit is contained in:
@@ -24,9 +24,11 @@ local function serialize(t, indent)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function parseFile(filePath)
|
local function parseFile(filePath)
|
||||||
local file = fs.open(filePath, "r")
|
local file = io.open(filePath, "r")
|
||||||
local content = file.readAll()
|
if not file then return nil end
|
||||||
file.close()
|
|
||||||
|
local content = file:read("*all")
|
||||||
|
file:close()
|
||||||
|
|
||||||
local config = {
|
local config = {
|
||||||
description = "",
|
description = "",
|
||||||
@@ -74,21 +76,17 @@ end
|
|||||||
|
|
||||||
local function scanDirectory(baseDir, relativePath)
|
local function scanDirectory(baseDir, relativePath)
|
||||||
local files = {}
|
local files = {}
|
||||||
local items = fs.list(fs.combine(baseDir, relativePath))
|
|
||||||
|
|
||||||
for _, item in ipairs(items) do
|
-- Nutze io.popen um Verzeichnis zu scannen
|
||||||
local fullPath = fs.combine(relativePath, item)
|
local cmd = os.execute('dir "' .. baseDir .. '/' .. relativePath .. '" /b /s')
|
||||||
local absPath = fs.combine(baseDir, fullPath)
|
for path in io.popen(cmd):lines() do
|
||||||
|
if path:match("%.lua$") then
|
||||||
if fs.isDir(absPath) then
|
local config = parseFile(path)
|
||||||
for path, config in pairs(scanDirectory(baseDir, fullPath)) do
|
if config then
|
||||||
|
config.name = path:match("([^/\\]+)%.lua$")
|
||||||
|
config.path = path:gsub(baseDir .. "/", "")
|
||||||
files[path] = config
|
files[path] = config
|
||||||
end
|
end
|
||||||
elseif item:match("%.lua$") then
|
|
||||||
local config = parseFile(absPath)
|
|
||||||
config.name = item:gsub("%.lua$", "")
|
|
||||||
config.path = fullPath
|
|
||||||
files[fullPath] = config
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -143,10 +141,8 @@ local function generateConfig(srcPath)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Config generieren
|
-- Config generieren und speichern
|
||||||
local config = generateConfig("/c:/Users/rjsha/AppData/Roaming/CraftOS-PC/computer/0/Basalt2/src")
|
local config = generateConfig("src")
|
||||||
|
local configFile = io.open("config.lua", "w")
|
||||||
-- Config speichern
|
configFile:write("return " .. serialize(config))
|
||||||
local configFile = fs.open("/c:/Users/rjsha/AppData/Roaming/CraftOS-PC/computer/0/Basalt2/config.lua", "w")
|
configFile:close()
|
||||||
configFile.write("return " .. serialize(config))
|
|
||||||
configFile.close()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user