local oldIni = ini_file
ini_file() = function (pfile, par)
if par then
return create_ini_file(parse(pfile))
else
return oldIni(pfile)
end
end
function parse (pfile)
local cdini = oldIni(pfile)
pfile = getFS():update_path("$game_config$", pfile)
local tbl, str = {{}, {}}, ""
local fcomm, pcomm, sec, key, val, parent
for line in io.lines(pfile) do
if string.find(line, "[[].+[]]") then
fcomm, sec = string.match(line, "([;]?)[[]([^;]+)[]]")
if fcomm and fcomm==";" then break end
tbl[1][sec] = {}
table.insert(tbl[2], sec)
parent = string.match(line, "[[].+[]][:](.+)")
if parent then
tbl[1][sec] = tbl[1][parent]
end
--**************************************--
for i=0, cdini:line_count(sec) do
_, key, val = cdini:r_line(sec ,i, "", "")
if string.len(key)<1 or string.len(val)<1 then break end
tbl[1][sec][key] = val
end
--**************************************--
end
end
local tlist = tbl[2]
local tdata = tbl[1]
for i=1, table.getn(tlist) do
str = string.format("%s\n\n[%s]", str, tlist[i])
if type(tdata[tlist[i]]) == 'table' then
for key, val in pairs(tdata[tlist[i]]) do
str = string.format("%s\n%s = %s", str, key, val)
end
end
end
return str
end