mirror of
https://github.com/IgorTimofeev/MineOS.git
synced 2026-01-07 19:52:40 +01:00
aefaef
This commit is contained in:
parent
1e9c2ef369
commit
f71dfa528f
@ -226,6 +226,10 @@ local function checkImage(url, mneTolkoSprosit)
|
||||
chunk, reason = handle.read(math.huge)
|
||||
if chunk then
|
||||
data = data .. chunk
|
||||
|
||||
progressIndicator:roll()
|
||||
workspace:draw()
|
||||
|
||||
if needCheck and #data > 8 then
|
||||
if data:sub(1, 4) == "OCIF" then
|
||||
if string.byte(data:sub(5, 5)) == 6 then
|
||||
@ -542,7 +546,14 @@ local function getPublicationIcon(publication)
|
||||
if filesystem.exists(path) then
|
||||
return loadImage(path)
|
||||
else
|
||||
progressIndicator.active = true
|
||||
workspace:draw()
|
||||
|
||||
local data, reason = checkImage(publication.icon_url)
|
||||
|
||||
progressIndicator.active = false
|
||||
workspace:draw()
|
||||
|
||||
if data then
|
||||
filesystem.write(path, data)
|
||||
|
||||
|
||||
59
Libraries/XML.lua
Normal file
59
Libraries/XML.lua
Normal file
@ -0,0 +1,59 @@
|
||||
|
||||
local xml = {}
|
||||
|
||||
------------------------------------------------------------------------------------------------------------
|
||||
|
||||
function xml.parseargs(s)
|
||||
local arg = {}
|
||||
string.gsub(s, "([%-%w]+)=([\"'])(.-)%2", function (w, _, a)
|
||||
arg[w] = a
|
||||
end)
|
||||
return arg
|
||||
end
|
||||
|
||||
function xml.collect(s)
|
||||
local stack = {}
|
||||
local top = {}
|
||||
table.insert(stack, top)
|
||||
local ni,c,label,xarg, empty
|
||||
local i, j = 1, 1
|
||||
while true do
|
||||
ni,j,c,label,xarg, empty = string.find(s, "<(%/?)([%w:]+)(.-)(%/?)>", i)
|
||||
if not ni then break end
|
||||
local text = string.sub(s, i, ni-1)
|
||||
if not string.find(text, "^%s*$") then
|
||||
table.insert(top, text)
|
||||
end
|
||||
if empty == "/" then -- empty element tag
|
||||
table.insert(top, {label=label, xarg=xml.parseargs(xarg), empty=1})
|
||||
elseif c == "" then -- start tag
|
||||
top = {label=label, xarg=xml.parseargs(xarg)}
|
||||
table.insert(stack, top) -- new level
|
||||
else -- end tag
|
||||
local toclose = table.remove(stack) -- remove top
|
||||
top = stack[#stack]
|
||||
if #stack < 1 then
|
||||
error("nothing to close with "..label)
|
||||
end
|
||||
if toclose.label ~= label then
|
||||
error("trying to close "..toclose.label.." with "..label)
|
||||
end
|
||||
table.insert(top, toclose)
|
||||
end
|
||||
i = j+1
|
||||
end
|
||||
local text = string.sub(s, i)
|
||||
if not string.find(text, "^%s*$") then
|
||||
table.insert(stack[#stack], text)
|
||||
end
|
||||
if #stack > 1 then
|
||||
error("unclosed "..stack[#stack].label)
|
||||
end
|
||||
return stack[1]
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------------------------------------
|
||||
|
||||
return xml
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user