Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- STD Graphical User Interface! (STDGUI)
- Made by LDDestroier/EldidiStroyrr (same guy)
- This program is a standalone GUI for Super Text Downloader, or STD for short.
- It has category sorting, program searching, smooth scrolling, and run support (not just download)
- This will tell you if you're overwriting a file, so no worry.
- As of May 15th (my goddamn birthday), STDGUI now lets you install SimSoft applications in the store interface!
- pastebin get P9dDhQ2m stdgui
- std pb P9dDhQ2m stdgui
- std ld stdgui stdgui
- --]]
- stdList = ".std_list"
- local scr_x, scr_y = term.getSize()
- local doDisplayTitle = false
- local relativePath = false
- local overrideNoSimSoft = false --prevent SimSoft functions, even if it's installed
- local isSimSoft = false --special integration into SimSoft!
- if (fs.isDir("SimSoft/Daten/SappS") and fs.isDir("SimSoft/SappS")) and (not overrideNoSimSoft) then --checks if SimSoft is installed
- isSimSoft = true
- end
- cprint = function(txt,y)
- local cX,cY = term.getCursorPos()
- term.setCursorPos(math.ceil(scr_x/2)-math.floor(#txt/2),y or cY)
- print(txt)
- end
- scroll = 1 --one is the loneliest number...weaboo
- scrollX = 1 --to view longer program names
- std_version = 100 --to prevent updating to std command line
- setMaxScroll = function(catagory)
- output = 0
- for k,v in pairs(storeURLs) do
- if (v.catagory == catagory) or catagory == 0 then
- output = output + 1
- end
- end
- return (output*4)-(scr_y-4)
- end
- local catag = 0
- local setDefaultColors = function()
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- end
- local displayHelp = function(cli)
- local helptext = [[
- This is a graphical interface to the STD downloader program.
- Use 'stdgui update' to update the list, or use 'F5'.
- If you want your program on it, PM LDDestroier on the CC forums.
- Hotkeys:
- 'Q' quit or back
- 'F5' refresh
- 'F1' menu
- 'F' or 'F6' search
- 'F12' update stdgui
- ]]
- if cli then
- return print(helptext)
- else
- setDefaultColors()
- term.clear()
- term.setCursorPos(2,2)
- print(helptext)
- sleep(0)
- print("\nPress a key to go back.")
- os.pullEvent("key")
- return
- end
- end
- local getTableSize = function(tbl)
- local amnt = 0
- for k,v in pairs(tbl) do
- amnt = amnt + 1
- end
- return amnt
- end
- function runURL(url, ...)
- local program = http.get(url)
- if not program then return false end
- program = program.readAll()
- local func = loadstring(program)
- setfenv(func, getfenv())
- return func(...)
- end
- bow = function()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- end
- getFile = function(filename,url)
- if fs.isReadOnly(filename) then
- return false, "access denied"
- end
- local prog = http.get(url)
- if not prog then
- return false, "could not connect"
- end
- prog = prog.readAll()
- local fyle = fs.open(filename,"w")
- fyle.write(prog)
- fyle.close()
- return true, fs.getSize(filename)
- end
- runFile = function(path)
- if not fs.exists(path) then
- return false, "No such file!"
- end
- local file = fs.open(path,"r")
- local contents = file.readAll()
- file.close()
- local func = loadstring(contents)
- setfenv(func, getfenv())
- func()
- return true
- end
- getSTDList = function()
- local url = "http://pastebin.com/raw/FSCzZRUk" --URL of URL list.
- local contents = http.get(url)
- if not contents then
- if shell then
- print("Couldn't update list!")
- end
- return false, "Couldn't update list!"
- else
- local uut
- if fs.exists(stdList) then
- uut = runFile(stdList)
- end
- if not uut then storeURLs = {} end
- local beforeSize = getTableSize(storeURLs or {})
- if not fs.isReadOnly(stdList) then
- local program = contents.readAll()
- local file = fs.open(stdList,"w")
- file.writeLine(program)
- file.close()
- runFile(stdList)
- else
- runURL(url)
- end
- local afterSize = getTableSize(storeURLs or {})
- local diff = afterSize-beforeSize
- local output
- if not fs.isReadOnly(stdList) then
- output = "Downloaded to "..stdList
- else
- output = "Got store codes."
- end
- if diff > 0 then
- output = output.." (got "..diff.." new store entries)"
- end
- return true, output
- end
- end
- local cisf = function(str,fin)
- return string.find(str:lower(),fin:lower())
- end
- local simSoftInstall = function(obj,objname,livesys)
- pFname = obj.title:gsub(" ","-")
- local pF = {
- name = pFname,
- folder = objname,
- colorCode = math.random(1,20),
- liveSystem = livesys or "",
- files = {
- [pFname] = obj.url, --I can't use pastebin codes for this
- }
- }
- local getFromPastebin = function(code,path) --modified to work with URLs as well
- if not type(code) == "string" then
- error("Expected pastebin code")
- elseif not type(path) == "string" then
- error("Expected file path")
- end
- local prog
- if #code == 8 then
- prog = http.get("http://pastebin.com/raw/"..code)
- else
- prog = http.get(code)
- end
- if not code then
- return false, "Could not connect."
- end
- prog = prog.readAll()
- if fs.exists(fs.getName(path)) and not fs.isDir(fs.getName(path)) then
- return false, "There's already a file there"
- end
- if not fs.exists(fs.getDir(path)) then
- fs.makeDir(fs.getDir(path))
- end
- local file = fs.open(path,"w")
- file.write(prog)
- file.close()
- return true, fs.getSize(path)
- end
- local function appInstaller(name,farbe,ver,loesch,LiveJaNein,LivePfad)
- term.setBackgroundColor(128)
- term.setTextColor(1)
- term.clear()
- term.setCursorPos(2,3)
- print("Starting installation...")
- local file = fs.open("SimSoft/Daten/SappS/A","r")
- local fileData = {}
- local line = file.readLine()
- repeat
- table.insert(fileData,line)
- line = file.readLine()
- until line == nil
- file.close()
- anz = tonumber(fileData[1])
- if anz >= 15 then
- return false, "App limit has been reached! Delete one to make space. Sorry."
- else
- anz = (anz+1)
- local file = fs.open("SimSoft/Daten/SappS/A","w")
- file.write(anz)
- file.close()
- local file = fs.open("SimSoft/Daten/SappS/"..anz,"w")
- file.writeLine(name)
- file.writeLine(anz)
- file.writeLine(farbe.."\n")
- file.writeLine(ver)
- file.writeLine(loesch)
- if LiveJaNein ~= "" then
- file.writeLine("t")
- file.writeLine(LiveJaNein)
- else
- file.writeLine("f\n")
- end
- file.close()
- end
- return true, "Installed!"
- end
- for k,v in pairs(pF.files) do
- getFromPastebin(v,fs.combine(fs.combine("SimSoft/SappS",pF.folder),k))
- end
- return appInstaller(string.sub(pF.name,1,6),tostring(pF.colorCode)..".0",fs.combine(pF.folder,pF.name),pF.folder,pF.liveSystem)
- end
- getFindList = function(name)
- local output = {}
- for k,v in pairs(storeURLs) do
- if cisf(k,name) or cisf(v.title,name) or cisf(v.creator,name) then
- output[k] = v
- end
- if output[k] ~= v and v.keywords then
- for a = 1, #v.keywords do
- if cisf(v.keywords[a],name) then
- output[k] = v
- break
- end
- end
- end
- end
- return output
- end
- doFindFunc = function(name)
- scroll = 1
- maxScroll = setMaxScroll(catag)
- renderStore(getFindList(name),catag,scroll,scrollX)
- term.setCursorPos(1,1)
- bow()
- term.clearLine()
- write("Find: ")
- end
- funcread = function(repchar,rHistory,doFunc,noNewLine)
- local scr_x,scr_y = term.getSize()
- local sx,sy = term.getCursorPos()
- local cursor = 1
- local output = ""
- term.setCursorBlink(true)
- while true do
- local evt,key = os.pullEvent()
- if evt == "key" then
- if key == keys.enter then
- if not noNewLine then
- write("\n")
- end
- term.setCursorBlink(false)
- return output
- elseif key == keys.left then
- if cursor-1 >= 1 then
- cursor = cursor - 1
- end
- elseif key == keys.right then
- if cursor+1 <= #output then
- cursor = cursor + 1
- end
- elseif key == keys.backspace then
- if cursor > 1 and #output > 0 then
- output = output:sub(1,cursor-2)..output:sub(cursor)
- cursor = cursor - 1
- pleaseDoFunc = true
- end
- elseif key == keys.delete then
- if #output:sub(cursor,cursor) == 1 then
- output = output:sub(1,cursor-1)..output:sub(cursor+1)
- pleaseDoFunc = true
- end
- end
- elseif evt == "char" then
- output = output..key
- cursor = cursor + 1
- pleaseDoFunc = true
- end
- if pleaseDoFunc then
- pleaseDoFunc = false
- if doFunc then
- doFunc(output)
- end
- term.setCursorPos(sx,sy)
- local pOut = output
- if #output >= scr_x-(sx-2) then
- pOut = output:sub((#output+(sx))-scr_x)
- end
- if repchar then
- term.write(repchar:sub(1,1):rep(#pOut).." ")
- else
- term.write(pOut.." ")
- end
- local cx,cy = term.getCursorPos()
- term.setCursorPos(cx-1,cy)
- end
- end
- end
- local findPrompt = function()
- local cX,cY = term.getCursorPos()
- sleep(0)
- doFindFunc("")
- storeURLs = getFindList(funcread(nil,{},doFindFunc,false))
- term.setCursorBlink(false)
- maxScroll = setMaxScroll(catag)
- end
- local clearMostline = function(length)
- local pX,pY = term.getCursorPos()
- term.setCursorPos(1,pY)
- term.write(string.rep(" ",length or (scr_x-1)))
- term.setCursorPos(pX,pY)
- end
- local displayTitle = function()
- local title = {{},{},{},{},{0,0,0,0,0,1,1,1,1,1,0,0,2,2,2,2,2,2,2,0,2,2,2,2,0,0,32768,},{0,0,0,0,1,1,0,0,0,1,1,0,0,0,0,2,0,0,0,0,0,2,0,2,2,0,32768,},{0,0,0,0,1,0,0,0,0,0,1,0,0,0,2,2,0,0,0,0,2,2,0,0,2,0,32768,},{0,0,0,0,1,1,0,0,0,0,0,0,0,0,2,0,0,0,0,0,2,0,0,0,2,0,32768,},{0,0,0,0,0,1,1,1,1,1,0,0,0,0,2,0,0,0,0,2,2,0,0,2,2,0,32768,},{0,0,0,0,0,0,0,0,0,1,0,0,0,2,2,0,0,0,2,2,0,0,2,2,0,0,32768,},{0,0,0,1,1,0,0,0,1,1,0,0,2,2,0,0,0,2,2,0,0,2,2,0,0,32768,1,},{0,0,0,0,1,1,1,1,1,0,0,0,2,0,0,0,2,2,2,2,2,2,0,0,32768,1,1,},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32768,1,1,1,},{0,0,0,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,1,1,1,1,},}
- setDefaultColors()
- term.clear()
- paintutils.drawImage(title,-1,1)
- setDefaultColors()
- term.setCursorPos(4,16)
- term.write("STD-GUI appstore")
- sleep(0)
- local evt
- repeat
- evt = os.pullEvent()
- until evt == "mouse_click" or evt == "key"
- sleep(0)
- end
- local dotY
- local doScrollBar = false
- local fixDotY
- renderStoreItem = function(obj)
- if not obj.title then return false end
- setDefaultColors()
- term.clear()
- term.setCursorPos(2,2)
- term.setTextColor(colors.yellow)
- print(obj.title)
- term.setTextColor(colors.white)
- write(" by ")
- print(obj.creator)
- write(" Catagory: ")
- if (catag ~= 0) then term.setTextColor(colors.lightGray) end
- print(storeCatagoryNames[obj.catagory])
- term.setTextColor(colors.white)
- print("\n "..obj.description)
- term.setTextColor(colors.lightGray)
- local post = " "..obj.forumPost:gsub("http://www.",""):sub(1,-2)
- local fy = (scr_y-1)-math.floor(#post / scr_x)
- term.setCursorPos(1,fy-1)
- print("Forum URL:")
- write(post)
- term.setTextColor(colors.white)
- term.setCursorPos(1,scr_y)
- term.setBackgroundColor(colors.red)
- term.clearLine()
- term.write("CLOSE")
- term.setCursorPos((scr_x-11),scr_y)
- term.setBackgroundColor(colors.green)
- term.write("RUN")
- term.setCursorPos((scr_x-7),scr_y)
- if isSimSoft then
- term.write("INSTALL!")
- else
- term.write("DOWNLOAD")
- end
- return true
- end
- renderCatagoryMenu = function(expanded)
- if expanded then
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.gray)
- term.clearLine()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.gray)
- term.write("Select category:")
- term.setTextColor(colors.black)
- local yposes = {}
- local longestLen = 0
- for a = 1, #storeCatagoryNames do
- if #storeCatagoryNames[a]+2 > longestLen then
- longestLen = #storeCatagoryNames[a]+2
- end
- end
- for a = 1, #storeCatagoryNames do
- term.setCursorPos(2,a+1)
- clearMostline(longestLen+2)
- term.write("@ "..storeCatagoryNames[a])
- table.insert(yposes,a+1)
- end
- return yposes,longestLen+2
- else
- term.setCursorPos(1,1)
- term.setTextColor(colors.lightGray)
- term.setBackgroundColor(colors.gray)
- if not storeCatagoryNames[catag] then
- if pocket then
- term.write("Set category")
- else
- term.write("Click to set category")
- end
- else
- if pocket then
- term.write(storeCatagoryNames[catag])
- else
- term.write("Category: "..storeCatagoryNames[catag])
- end
- end
- end
- term.setCursorPos(scr_x-4,1)
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.white)
- term.write("CLOSE")
- setDefaultColors()
- end
- renderStore = function(list,filter,scrollY,namescroll,fixedDotY)
- local fullrend = {}
- local visiblerend = {}
- local amnt = 0
- local output = {}
- local num = 0
- term.current().setVisible(false)
- for k,v in pairs(list) do
- if (v.catagory == filter) or filter == 0 then
- table.insert(fullrend,{string.sub(" *"..v.title,namescroll),v})
- table.insert(fullrend,{" by "..v.creator,v})
- if filter == 0 then
- table.insert(fullrend,{" Catagory: "..storeCatagoryNames[v.catagory],v})
- else
- table.insert(fullrend,{"",v,k})
- end
- table.insert(fullrend,"nilline")
- end
- end
- dotY = fixedDotY or math.floor((scr_y-2)*((scroll-1)/(maxScroll-1)))+2
- for a = scrollY, (scr_y+scrollY)-1 do
- if type(fullrend[a]) == "table" then
- table.insert(visiblerend,fullrend[a][1])
- table.insert(output,fullrend[a][2])
- else
- table.insert(visiblerend,fullrend[a])
- table.insert(output,{})
- end
- end
- setDefaultColors()
- term.clear()
- for a = 1, #visiblerend do
- term.setCursorPos(1,a+1)
- if visiblerend[a] == "nilline" then
- setDefaultColors()
- clearMostline()
- else
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colors.black)
- clearMostline()
- term.write(visiblerend[a])
- end
- end
- for a = 2, scr_y do
- term.setCursorPos(scr_x,a)
- if a == dotY then
- term.blit(" ","f","f")
- else
- term.blit(" ","0","0")
- end
- end
- term.current().setVisible(true)
- return output
- end
- local tArg = {...}
- function explode(div,str)
- if (div=='') then return false end
- local pos,arr = 0,{}
- for st,sp in function() return string.find(str,div,pos,true) end do
- table.insert(arr,string.sub(str,pos,st-1))
- pos = sp + 1
- end
- table.insert(arr,string.sub(str,pos))
- return arr
- end
- if tArg[1] == "update" then
- local res, outcome = getSTDList()
- print(outcome)
- return
- elseif tArg[1] == "help" then
- return displayHelp(true)
- elseif tArg[1] == "upgrade" then
- local res, outcome = getFile(shell.getRunningProgram(),"http://pastebin.com/raw/P9dDhQ2m")
- if not res then
- error(outcome)
- else
- print("Updated STD-GUI to latest version ("..outcome.." bytes)")
- return
- end
- end
- cleanExit = function()
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.clear()
- local out
- if pocket then
- out = "Thanks for using STD!"
- else
- out = "Thank you for using STD-GUI!"
- end
- if isSimSoft then
- term.setCursorBlink(false)
- end
- cprint(out,scr_y/2)
- term.setCursorPos(1,scr_y)
- sleep(0)
- error()
- end
- STDdownloadPrompt = function(item)
- term.setCursorPos(1,scr_y)
- bow()
- term.clearLine()
- write("Save as: ")
- local savepath = funcread(nil,{},nil,true)
- term.setCursorBlink(false)
- if savepath:gsub(" ","") == "" then
- sleep(0)
- return
- else
- if fs.exists(savepath) then
- term.setCursorPos(1,scr_y)
- term.clearLine()
- write("Overwrite? (Y/N)")
- local key
- repeat
- _,key = os.pullEvent("char")
- until string.find("yn",key)
- if key == "n" then
- sleep(0)
- return
- end
- end
- if relativePath then
- savepath = fs.combine(shell.dir(),savepath)
- end
- term.setCursorPos(1,scr_y)
- term.clearLine()
- term.write("Downloading...")
- local res, outcome = getFile(savepath,item.url)
- term.setCursorPos(1,scr_y)
- term.clearLine()
- if not res then
- term.write(outcome)
- sleep(0.6)
- else
- term.write("Downloaded! ("..outcome.." bytes)")
- sleep(0.7)
- end
- end
- return
- end
- doEverything = function() --do I have to do EVERYTHING?
- if fs.exists(stdList) then
- shell.run(stdList)
- else
- if not storeURLs then
- getSTDList()
- end
- end
- maxScroll = setMaxScroll(catag)
- while true do
- if scroll > maxScroll then
- scroll = maxScroll
- end
- if scroll < 1 then
- scroll = 1
- end
- local yposes = renderStore(storeURLs,catag,scroll,scrollX,fixDotY)
- renderCatagoryMenu(false)
- local evt = {os.pullEvent()}
- if evt[1] == "mouse_scroll" then
- if scroll+evt[2] >= 1 and scroll+evt[2] <= maxScroll then
- scroll = scroll+evt[2]
- end
- elseif evt[1] == "mouse_click" then
- if evt[3] == scr_x and evt[4] == dotY then
- doScrollBar = true
- end
- if evt[4] == 1 then
- if evt[3] >= scr_x-4 then
- return cleanExit()
- end
- local cats,longth = renderCatagoryMenu(true)
- local evt,butt,x,y
- while true do
- local evt,butt,x,y = os.pullEvent()
- if evt == "mouse_click" or (evt == "mouse_up" and y ~= 1) then
- if y == 1 then
- catag = 0
- break
- else
- for a = 1, #cats do
- if cats[a] == y and x <= longth then
- catag = a
- scroll = 1
- end
- end
- break
- end
- elseif evt == "key" then
- if butt == keys.f1 then
- break
- end
- end
- end
- maxScroll = setMaxScroll(catag)
- elseif yposes[evt[4]-1] and evt[3] ~= scr_x then
- local y = evt[4]-1
- local guud = renderStoreItem(yposes[y])
- scrollX = 1
- while true do
- if not guud then break end
- local event,butt,cx,cy = os.pullEvent()
- if event == "key" then
- if butt == keys.q then
- sleep(0)
- break
- elseif butt == keys.d then
- sleep(0)
- STDdownloadPrompt(yposes[y])
- break
- end
- elseif event == "mouse_click" then
- if cy == scr_y then
- if (cx < scr_x-7) or (cx > scr_x) then
- if cx >= scr_x-11 and cx < scr_x-8 then
- term.setCursorPos(1,scr_y)
- bow()
- term.clearLine()
- if pocket then
- write("Args.: ")
- else
- write("Arguments:")
- end
- local arguments = explode(" ",funcread(nil,{},nil,true)) or {}
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- if #arguments == 0 then
- runURL(yposes[y].url)
- else
- runURL(yposes[y].url,unpack(arguments))
- end
- sleep(0)
- write("[press a key]")
- os.pullEvent("key")
- end
- sleep(0)
- break
- else
- term.setCursorPos(1,scr_y)
- bow()
- term.clearLine()
- if isSimSoft then
- local itname
- for k,v in pairs(storeURLs) do
- if yposes[y].url == v.url then
- itname = k
- break
- end
- end
- term.setCursorPos(1,scr_y)
- term.clearLine()
- term.write("Downloading...")
- local res, outcome = simSoftInstall(yposes[y],itname or yposes[y].title,lspath)
- term.setCursorPos(1,scr_y)
- term.write(outcome)
- sleep(#outcome/13)
- break
- else
- STDdownloadPrompt(yposes[y])
- break
- end
- end
- end
- end
- end
- end
- elseif evt[1] == "mouse_up" then
- doScrollBar = false
- fixDotY = nil
- elseif evt[1] == "mouse_drag" then
- if doScrollBar then
- local my = evt[4]
- if my > 1 then
- scroll = math.floor( (my-2)/(scr_y-2) * (maxScroll)) + 1
- fixDotY = my
- end
- end
- elseif evt[1] == "key" then
- if evt[2] == keys.q then
- return cleanExit()
- elseif evt[2] == keys.down then
- scroll = scroll + 4
- elseif evt[2] == keys.up then
- scroll = scroll - 4
- elseif evt[2] == keys.pageDown then
- scroll = scroll + (scr_y-1)
- elseif evt[2] == keys.pageUp then
- scroll = scroll - (scr_y-1)
- elseif evt[2] == keys.home then
- scroll = 1
- elseif evt[2] == keys['end'] then
- scroll = maxScroll
- elseif evt[2] == keys.h then --help screen!
- displayHelp(false)
- elseif evt[2] == keys.right then
- scrollX = scrollX + 1
- elseif evt[2] == keys.left then
- if scrollX > 1 then
- scrollX = scrollX - 1
- end
- elseif evt[2] == keys.numPadAdd then
- catag = catag + 1
- if catag > #storeCatagoryNames then
- catag = 0
- end
- scroll = 1
- maxScroll = setMaxScroll(catag)
- elseif evt[2] == keys.minus then
- catag = catag - 1
- if catag < 0 then
- catag = #storeCatagoryNames
- end
- scroll = 1
- maxScroll = setMaxScroll(catag)
- elseif evt[2] == keys.f5 then
- getSTDList()
- elseif evt[2] == keys.f12 then
- getFile(shell.getRunningProgram(),"http://pastebin.com/raw/P9dDhQ2m")
- local flashes = {
- colors.black,
- colors.white,
- colors.lightGray,
- colors.red,
- colors.gray,
- colors.black,
- }
- for a = 1, #flashes do
- term.setBackgroundColor(flashes[a])
- term.clear()
- sleep(0)
- end
- return
- elseif evt[2] == keys.f1 then
- os.queueEvent("mouse_click",1,1,1)
- elseif evt[2] == keys.f or evt[2] == keys.f6 then
- runFile(stdList)
- findPrompt()
- end
- end
- end
- end
- if doDisplayTitle then
- displayTitle()
- end
- if storeURLs then storeURLs = getFindList("") end
- doEverything()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement