From aab808b9ddbfb568216c5f16109608f103d6cb54 Mon Sep 17 00:00:00 2001 From: Ale32bit Date: Tue, 15 Nov 2016 23:18:20 +0100 Subject: [PATCH] new gui --- src/apps/store.lua | 83 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 10 deletions(-) diff --git a/src/apps/store.lua b/src/apps/store.lua index 3327cfe..9b813c5 100644 --- a/src/apps/store.lua +++ b/src/apps/store.lua @@ -7,16 +7,29 @@ local function redrawM() term.setBackgroundColor(colors.white) term.setTextColor(colors.black) term.clear() - term.setCursorPos(1,1) term.setTextColor(colors.white) - paintutils.drawLine(1,1,w,1,colors.orange) + paintutils.drawLine(1,1,w,1,colors.green) + term.setCursorPos(1,1) + write(" Store") visum.align("right","X",false,1) - visum.align("center"," Store",false,1) term.setTextColor(colors.black) term.setBackgroundColor(colors.white) term.setCursorPos(1,3) end +local function install(ap) + local data = http.get("https://raw.github.com/Sertex-Team/sPhone-Store/master/apps/"..ap.path).readAll() + local f = fs.open("/tmp/sPhoneStore/"..ap.id..".spk","w") + f.write(data) + f.close() + local status = sPhone.install("/tmp/sPhoneStore/"..ap.id..".spk") + if status then + sPhone.winOk("Installed") + else + sPhone.winOk("Error while installing") + end +end + redrawM() term.setCursorPos(1,2) @@ -57,14 +70,64 @@ while true do if appsL[y-2] then local data = http.get("https://raw.github.com/Sertex-Team/sPhone-Store/master/apps/"..appsL[y-2].path).readAll() - local f = fs.open("/tmp/sPhoneStore/"..appsL[y-2].id..".spk","w") - f.write(data) - f.close() - local status = sPhone.install("/tmp/sPhoneStore/"..appsL[y-2].id..".spk") - if status then - sPhone.winOk("Installed") + data = textutils.unserialise(data) + if data then + local _conf = textutils.unserialise(data.config) + redrawM() + term.setCursorPos(2,3) + print(_conf.name) + term.setCursorPos(2,6) + term.setTextColor(colors.black) + print("Author:") + term.setTextColor(colors.gray) + term.setCursorPos(2,7) + print(_conf.author) + term.setCursorPos(2,9) + term.setTextColor(colors.black) + print("Type:") + term.setTextColor(colors.gray) + term.setCursorPos(2,10) + print((_conf.type or "Normal")) + term.setCursorPos(2,12) + term.setTextColor(colors.black) + print("Version:") + term.setTextColor(colors.gray) + term.setCursorPos(2,13) + print(_conf.version) + + if config.read("/.sPhone/config/spklist",_conf.id) then + paintutils.drawLine(19,4,25,4,colors.red) + term.setTextColor(colors.white) + term.setCursorPos(19,4) + write("Delete") + else + paintutils.drawLine(19,4,25,4,colors.green) + term.setTextColor(colors.white) + term.setCursorPos(19,4) + write("Install") + end + + while true do + local _,_,mx,my = os.pullEvent("mouse_click") + if my == 1 and x == mw then + break + elseif (mx >= 19 and mx <= 25) and my == 4 then + if config.read("/.sPhone/config/spklist",_conf.id) then + if fs.exists("/.sPhone/apps/spk/".._conf.id) then + fs.delete("/.sPhone/apps/spk/".._conf.id) + end + config.write("/.sPhone/config/spklist",_conf.id,nil) + else + install(appsL[y-2]) + end + break + end + end else - sPhone.winOk("Error while installing") + sPhone.winOk("Cannot install","file corrupted") end + + + end end