Update store.lua

This commit is contained in:
Ale32bit 2016-11-17 15:59:53 +01:00 committed by GitHub
parent 3cf03e682f
commit 5332352174

View file

@ -1,9 +1,10 @@
local host = "https://raw.github.com/Sertex-Team/sPhone-Store/master/" local host = "https://raw.github.com/BeaconNet/sPhone-Store/master/"
local index = host.."index.lua" local index = host.."index.lua"
local apps = host.."apps/" local apps = host.."apps/"
local appsL = {} local appsL = {}
local w, h = term.getSize() local w, h = term.getSize()
local function redrawM()
local function redraw()
term.setBackgroundColor(colors.white) term.setBackgroundColor(colors.white)
term.setTextColor(colors.black) term.setTextColor(colors.black)
term.clear() term.clear()
@ -17,12 +18,12 @@ local function redrawM()
term.setCursorPos(1,3) term.setCursorPos(1,3)
end end
local function install(ap) local function install(path,name)
local data = http.get("https://raw.github.com/Sertex-Team/sPhone-Store/master/apps/"..ap.path).readAll() local data = http.get("https://raw.github.com/BeaconNet/sPhone-Store/master/apps/"..path).readAll()
local f = fs.open("/tmp/sPhoneStore/"..ap.id..".spk","w") local f = fs.open("/tmp/sPhoneStore/"..name..".spk","w")
f.write(data) f.write(data)
f.close() f.close()
local status = sPhone.install("/tmp/sPhoneStore/"..ap.id..".spk") local status = sPhone.install("/tmp/sPhoneStore/"..name..".spk")
if status then if status then
sPhone.winOk("Installed") sPhone.winOk("Installed")
else else
@ -30,7 +31,7 @@ local function install(ap)
end end
end end
redrawM() redraw()
term.setCursorPos(1,2) term.setCursorPos(1,2)
visum.align("center"," Loading",false,2) visum.align("center"," Loading",false,2)
@ -40,21 +41,8 @@ local c = http.get(index).readAll()
local appsIndex = textutils.unserialize(c) local appsIndex = textutils.unserialize(c)
function redrawA() redraw()
for k,v in pairs(appsIndex) do
print(v)
table.insert(appsL, {
path = k,
id = v,
})
end
end
local function redraw()
redrawM()
redrawA()
end
redrawA()
local mx,my = term.getCursorPos() local mx,my = term.getCursorPos()
term.setCursorPos(1,2) term.setCursorPos(1,2)
term.clearLine() term.clearLine()
@ -62,18 +50,27 @@ term.setCursorPos(mx,my)
while true do while true do
redraw() local path,name = sPhone.list(nil,{
local _, _, x, y = os.pullEvent("mouse_click") title = " Store",
if x == w and y == 1 then pairs = true,
break list = appsIndex,
bg1 = colors.white,
fg1 = colors.black,
bg2 = colors.green,
fg2 = colors.white,
bg3 = colors.green,
fg3 = colors.white,
})
if not path then
return
end end
if appsL[y-2] then local data = http.get("https://raw.github.com/BeaconNet/sPhone-Store/master/apps/"..path).readAll()
local data = http.get("https://raw.github.com/Sertex-Team/sPhone-Store/master/apps/"..appsL[y-2].path).readAll()
data = textutils.unserialise(data) data = textutils.unserialise(data)
if data then if data then
local _conf = textutils.unserialise(data.config) local _conf = textutils.unserialise(data.config)
redrawM() redraw()
term.setCursorPos(2,3) term.setCursorPos(2,3)
print(_conf.name) print(_conf.name)
term.setCursorPos(2,6) term.setCursorPos(2,6)
@ -118,7 +115,7 @@ while true do
end end
config.write("/.sPhone/config/spklist",_conf.id,nil) config.write("/.sPhone/config/spklist",_conf.id,nil)
else else
install(appsL[y-2]) install(path,name)
end end
break break
end end
@ -130,4 +127,3 @@ while true do
end end
end