Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Name: Discover App Store
- Author: DannySMc (dannysmc95)
- Requirements: HTTP, Colour, Whitelist dannysmc.com/ in the HTTP config.
- ]]
- -- Set variables
- os.getEvent = os.pullEvent
- os.pullEvent = os.pullEventRaw
- local system = {
- ["name"] = "Discover Store";
- ["auth"] = "DannySMc (dannysmc95)";
- ["paths"] = {
- ["config"] = ".DiscoverConfig";
- ["plugins"] = "/DPlugins/";
- };
- ["plugins"] = true;
- ["storeconfig"] = true;
- ["lock_program"] = false;
- ["storeuser"] = false;
- }
- -- Used for applications to send data between each other
- local temp = {}
- local side_scroll = 0
- local viewapps = {}
- -- Create Discover Object
- discover = {
- data = {
- username = nil;
- password = nil;
- authkey = nil;
- errormsg = nil;
- cmessage = nil;
- loggedin = false;
- urls = {
- user = "https://api.dannysmc.com/user.php";
- store = "https://api.dannysmc.com/store.php";
- projects = "https://api.dannysmc.com/projects.php";
- };
- apps = {};
- versions = {};
- categories = {};
- version = "4.2";
- build = "12";
- version_api = "2.2.12:116";
- newupdate = nil;
- };
- -- Project Check
- get_update = function( self )
- local uniqueid = "db613a9197c76e8f0fd61cd67547920a3805ee380aabee241298d3379c7c0dcddc0b5c411ee393615f142f750e8bfdc349720782a4d07cde4e083147a4149d20"
- local query = "command=check_update&uniqueid="..textutils.urlEncode(tostring(uniqueid)).."&version="..textutils.urlEncode(tostring(self.data.version))
- local req = http.post(self.data.urls.projects, query)
- req = textutils.unserialize(req.readAll())
- if req.status then
- local url = req.url
- local dat = http.post(url)
- self.data.newupdate = dat.readAll()
- return true
- else
- return false
- end
- end;
- -- Set Username and Password
- set = function( self, username, password )
- self.data.username = username
- self.data.password = crypt.sha256(password)
- return true
- end;
- -- Get function to return a certain bit of information
- get = function ( self, name )
- return self.data[name]
- end;
- -- Main login function to get authkey
- login = function( self, username, password )
- if username then
- self.data.username = username
- end
- if password then
- self.data.password = password
- end
- if self.data.username and self.data.password then
- local query = "cmd=login&username="..textutils.urlEncode(tostring(self.data.username)).."&password="..textutils.urlEncode(tostring(self.data.password))
- local res = http.post(self.data.urls.user, query)
- res = textutils.unserialize(res.readAll())
- if res.status == true then
- self.data.authkey = res.authkey
- self.data.loggedin = true;
- return true
- elseif res.status == false then
- self.data.errormsg = res.error
- return false
- end
- else
- return false
- end
- end;
- -- Registration
- register = function( self, username, password, email )
- if username and password and email then
- local query = "cmd=register&username="..textutils.urlEncode(tostring(username)).."&password="..textutils.urlEncode(tostring(password)).."&email="..textutils.urlEncode(tostring(email))
- local req = http.post(self.data.urls.user, query)
- req = textutils.unserialize(req.readAll())
- if req.status then
- self.data.cmessage = tostring(req.message)
- return true
- else
- self.data.errormsg = req.error
- return false
- end
- else
- self.data.errormsg = "Please supply a username, password and email!"
- return false
- end
- end;
- -- Log out user
- logout = function( self )
- local req = http.post(self.data.urls.user, "cmd=logout&authkey="..textutils.urlEncode(tostring(self.data.authkey)))
- req = textutils.unserialize(req.readAll())
- if req.status then
- discover.data.loggedin = false
- discover.data.username = nil
- discover.data.password = nil
- discover.data.authkey = nil
- self.data.cmessage = req.message
- return true
- else
- self.data.errormsg = req.error
- return false
- end
- end;
- -- Check if a authkey is still valid
- validate = function( self )
- if self.data.authkey then
- local query = "cmd=validate&authkey="..textutils.urlEncode(tostring(self.data.authkey))
- local res = http.post(self.data.urls.user, query)
- res = textutils.unserialize(res.readAll())
- if res.status == true then
- self.data.cmessage = res.message
- self.data.loggedin = true;
- return true
- elseif res.status == false then
- self.data.errormsg = res.error
- return false
- end
- else
- return false
- end
- end;
- store_init = function( self )
- local ret = http.post(self.data.urls.store, "cmd=list_apps")
- ret = textutils.unserialize(ret.readAll())
- if ret.status == true then
- self.data.apps = ret.data
- else
- return false
- end
- local ret = http.post(self.data.urls.store, "cmd=list_categories")
- ret = textutils.unserialize(ret.readAll())
- if ret.status == true then
- self.data.categories = ret.data
- else
- return false
- end
- local ret = http.post(self.data.urls.store, "cmd=list_versions")
- ret = textutils.unserialize(ret.readAll())
- if ret.status == true then
- self.data.versions = ret.data
- else
- return false
- end
- return true
- end;
- store_comments_get = function( self, appid )
- local query = "cmd=view_comments&appid="..textutils.urlEncode(tostring(appid))
- local req = http.post(self.data.urls.store, query)
- req = textutils.unserialize(req.readAll())
- if req.status == true then
- discover.data.cmessage = "Successful"
- discover.data.comments = req.data
- return true
- else
- discover.data.errormsg = req.error
- return false
- end
- end;
- store_comments_set = function( self, appid, comment )
- local query = "cmd=add_comment&appid="..textutils.urlEncode(tostring(appid)).."&comment="..textutils.urlEncode(tostring(comment))
- local req = http.post(self.data.urls.store, query)
- req = textutils.unserialize(req.readAll())
- if req.status then
- self.data.cmessage = req.message
- return true
- else
- self.data.errormsg = req.error
- return false
- end
- end;
- store_download = function( self, appid )
- local query = "cmd=download&appid="..textutils.urlEncode(tostring(appid))
- local req = http.post(self.data.urls.store, query)
- return req
- end;
- store_upload = function ( self, appname, appdesc, appcate, appvers, appstat, appdata )
- local query = "cmd=upload&authkey="..textutils.urlEncode(tostring(self.data.authkey)).."&name="..textutils.urlEncode(tostring(appname)).."&desc="..textutils.urlEncode(tostring(appdesc)).."&vers="..textutils.urlEncode(tostring(appvers)).."&cate="..textutils.urlEncode(tostring(appcate)).."&status="..textutils.urlEncode(tostring(appstat)).."&data="..textutils.urlEncode(tostring(appdata))
- local req = http.post(self.data.urls.store, query)
- local f = fs.open("output.lua", "w")
- req = textutils.unserialize(req.readAll())
- if req.status then
- self.data.cmessage = req.message
- return true
- else
- self.data.errormsg = req.error
- return false
- end
- end;
- store_update = function( self, appid, vers, stat, data )
- if appid and vers and stat and data then
- local query = "cmd=update&authkey="..textutils.urlEncode(tostring(self.data.authkey)).."&appid="..textutils.urlEncode(tostring(appid)).."&vers="..textutils.urlEncode(tostring(vers)).."&status="..textutils.urlEncode(tostring(stat)).."&data="..textutils.urlEncode(tostring(data))
- local req = http.post(self.data.urls.store, query)
- req = textutils.unserialize(req.readAll())
- if req.status then
- self.data.cmessage = tostring(req.message)
- return true
- else
- self.data.errormsg = req.error
- return false
- end
- else
- self.data.errormsg = "Please fill in all fields"
- return false
- end
- end;
- store_apps_user = function( self, username )
- if not username then
- query = "cmd=list_apps_user&authkey="..textutils.urlEncode(tostring(self.data.authkey))
- else
- query = "cmd=list_apps_user&authkey="..textutils.urlEncode(tostring(self.data.authkey)).."&username="..textutils.urlEncode(tostring(username))
- end
- local req = http.post(self.data.urls.store, query)
- req = textutils.unserialize(req.readAll())
- if req.status then
- discover.data.appsuser = req.data
- return true
- else
- discover.data.errormsg = req.error
- return false
- end
- end;
- store_edit = function( self, appid, name, desc, vers, cate, stat )
- if appid and name and desc and vers and stat and cate then
- local query = "cmd=edit&authkey="..textutils.urlEncode(tostring(self.data.authkey)).."&appid="..textutils.urlEncode(tostring(appid)).."&vers="..textutils.urlEncode(tostring(vers)).."&status="..textutils.urlEncode(tostring(stat)).."&name="..textutils.urlEncode(tostring(name)).."&desc="..textutils.urlEncode(tostring(desc)).."&category="..textutils.urlEncode(tostring(cate))
- local req = http.post(self.data.urls.store, query)
- req = textutils.unserialize(req.readAll())
- if req.status then
- self.data.cmessage = tostring(req.message)
- return true
- else
- self.data.errormsg = req.error
- return false
- end
- else
- self.data.errormsg = "Please fill in all fields"
- return false
- end
- end;
- store_delete = function( self, appid )
- if appid then
- local query = "cmd=delete&authkey="..textutils.urlEncode(tostring(self.data.authkey)).."&appid="..textutils.urlEncode(tostring(appid))
- local req = http.post(self.data.urls.store, query)
- req = textutils.unserialize(req.readAll())
- if req.status then
- self.data.cmessage = tostring(req.message)
- return true
- else
- self.data.errormsg = req.error
- return false
- end
- else
- self.data.errormsg = "Please fill in all fields"
- return false
- end
- end;
- }
- -- Get Store API
- local downloadapi = false
- local nTries = 0
- while not downloadapi do
- local ok, err = pcall( function()
- if http then
- aa = aa or {}
- local a = http.get("https://api.dannysmc.com/files/apis/progutils.lua")
- a = a.readAll()
- local env = {}
- a = loadstring(a)
- local env = getfenv()
- setfenv(a,env)
- local status, err = pcall(a, unpack(aa))
- if (not status) and err then
- printError("Error loading api")
- return false
- end
- local returned = err
- env = env
- _G["progutils"] = env
- end
- end)
- if not ok then
- term.clear()
- term.setCursorPos(1,1)
- print("Download API (Attempt: "..nTries.."/".."5)")
- if nTries >= 5 then
- shell.run("shell")
- end
- else
- downloadapi = true
- end
- end
- -- Set Object Methods (Better naming convention)
- store = {}
- store.__index = store
- store.account = {}
- store.account.__index = store.account
- store.apps = {}
- store.apps.__index = store.apps
- store.draw = {}
- store.draw.__index = store.draw
- -- Discover Store Main Code:
- function store.draw.menu(screen)
- draw.box(1, 51, 1, 2, " ", "grey", "grey")
- draw.texta("Discover:", 1, 1, false, "cyan", "grey")
- if screen then
- draw.texta(screen, 10, 1, false, "white", "grey")
- end
- draw.textr(misc.time(), 1, false, "lime", "grey")
- chars = {2, 12, 22, 32, 42}
- for i=1, #chars do
- coun = i + side_scroll
- if coun > #threads then
- break
- end
- if threads[coun].name == currentThread.name then
- draw.texta(" "..threads[coun].name:sub(1, 8).." ", chars[i], 2, false, "blue", "grey")
- draw.texta("x", chars[i], 2, false, "red", "grey")
- else
- draw.texta(" "..threads[coun].name:sub(1,8).." ", chars[i], 2, false, "orange", "grey")
- end
- end
- draw.texta(tostring(#threads), 45, 1, false, "lightBlue", "grey")
- if side_scroll == 0 then
- draw.texta("<", 1, 2, false, "lightGrey", "grey")
- else
- draw.texta("<", 1, 2, false, "lightBlue", "grey")
- end
- if side_scroll + 5 >= #threads then
- draw.texta(">", 51, 2, false, "lightGrey", "grey")
- else
- draw.texta(">", 51, 2, false, "lightBlue", "grey")
- end
- end
- function store.draw.menu_input(screen, intx, inty)
- if inty == 2 then
- -- Check Task Deletion First
- if intx == 2 then
- if #threads >= side_scroll + 1 then
- if threads[1+side_scroll].name == currentThread.name then
- -- Remove Thread
- thread:remove(threads[1+side_scroll].name)
- if not thread:find("Home") then
- thread:create("Home", store.home)
- end
- thread:switch("Home")
- return true
- end
- end
- elseif intx == 12 then
- if #threads >= side_scroll + 2 then
- if threads[2+side_scroll].name == currentThread.name then
- -- Remove Thread
- thread:remove(threads[2+side_scroll].name)
- if not thread:find("Home") then
- thread:create("Home", store.home)
- end
- thread:switch("Home")
- return true
- end
- end
- elseif intx == 22 then
- if #threads >= side_scroll + 3 then
- if threads[3+side_scroll].name == currentThread.name then
- -- Remove Thread
- thread:remove(threads[3+side_scroll].name)
- if not thread:find("Home") then
- thread:create("Home", store.home)
- end
- thread:switch("Home")
- return true
- end
- end
- elseif intx == 32 then
- if #threads >= side_scroll + 4 then
- if threads[4+side_scroll].name == currentThread.name then
- -- Remove Thread
- thread:remove(threads[4+side_scroll].name)
- if not thread:find("Home") then
- thread:create("Home", store.home)
- end
- thread:switch("Home")
- return true
- end
- end
- elseif intx == 42 then
- if #threads >= side_scroll + 5 then
- if threads[5+side_scroll].name == currentThread.name then
- -- Remove Thread
- thread:remove(threads[5+side_scroll].name)
- if not thread:find("Home") then
- thread:create("Home", store.home)
- end
- thread:switch("Home")
- return true
- end
- end
- end
- -- Task Switching
- if intx >= 2 and intx <= 10 then
- if #threads >= side_scroll + 1 then
- thread:switch(threads[1+side_scroll].name)
- store.draw.menu(screen)
- end
- elseif intx >= 12 and intx <= 20 then
- if #threads >= side_scroll + 2 then
- thread:switch(threads[2+side_scroll].name)
- store.draw.menu(screen)
- end
- elseif intx >= 22 and intx <= 30 then
- if #threads >= side_scroll + 3 then
- thread:switch(threads[3+side_scroll].name)
- store.draw.menu(screen)
- end
- elseif intx >= 32 and intx <= 40 then
- if #threads >= side_scroll + 4 then
- thread:switch(threads[4+side_scroll].name)
- store.draw.menu(screen)
- end
- elseif intx >= 42 and intx <= 50 then
- if #threads >= side_scroll + 5 then
- thread:switch(threads[5+side_scroll].name)
- store.draw.menu(screen)
- end
- elseif intx == 1 then
- if side_scroll > 0 then
- side_scroll = side_scroll - 1
- store.draw.menu(screen)
- end
- elseif intx == 51 then
- if (side_scroll + 5) < #threads then
- side_scroll = side_scroll + 1
- store.draw.menu(screen)
- end
- end
- end
- end
- function store.draw.logo(intx, inty)
- local text = "Welcome to the Discover App Store. This makes use of my new Discover API System, A * following a button means you need to be logged in."
- for k,v in ipairs(data.wordwrap(text, 41)) do
- draw.textc(v, k+3, false, "grey", "white")
- end
- if discover.data.loggedin then
- draw.box(2, 24, 9, 1, false, "red", "red")
- draw.texta("Log out", 3, 9, false, "white", "red")
- else
- draw.box(2, 24, 9, 1, false, "cyan", "cyan")
- draw.texta("Log In", 3, 9, false, "white", "cyan")
- end
- draw.box(2, 24, 11, 1, false, "cyan", "cyan")
- draw.box(2, 24, 13, 1, false, "cyan", "cyan")
- draw.box(2, 24, 15, 1, false, "cyan", "cyan")
- draw.box(2, 24, 17, 1, false, "cyan", "cyan")
- draw.box(27, 24, 9, 1, false, "cyan", "cyan")
- draw.box(27, 24, 11, 1, false, "cyan", "cyan")
- draw.box(27, 24, 13, 1, false, "cyan", "cyan")
- draw.box(27, 24, 15, 1, false, "cyan", "cyan")
- draw.box(27, 24, 17, 1, false, "cyan", "cyan")
- draw.texta("All Apps", 3, 11, false, "white", "cyan")
- draw.texta("All Versions", 3, 13, false, "white", "cyan")
- draw.texta("All Categories", 3, 15, false, "white", "cyan")
- draw.texta("My Statistics*", 3, 17, false, "white", "cyan")
- draw.texta("My Account*", 28, 9, false, "white", "cyan")
- draw.texta("Help / FAQ", 28, 11, false, "white", "cyan")
- draw.texta("Update Log", 28, 13, false, "white", "cyan")
- draw.texta("Settings", 28, 15, false, "white", "cyan")
- draw.texta("Credits", 28, 17, false, "white", "cyan")
- draw.textc("Powered By DiscoverAPI - Created By DannySMc", 19, false, "lightGrey", "white")
- end
- function store.init()
- col.screen("lightGrey")
- draw.textc("Discover Initialisation", 2, false, "white", "lightGrey")
- sleep(0.5)
- draw.box(1, 51, 10, 1, " ", "lightGrey", "lightGrey")
- draw.textc("Loading Configurations...", 10, false, "red", "lightGrey")
- -- Load Configurations
- if fs.exists(system.paths.config) then
- local f = fs.open(system.paths.config, "r")
- local dat = basesf.decode( f.readAll() )
- local c = textutils.unserialize( dat )
- system.storeconfig = c.storeconfig
- system.plugins = c.plugins
- system.lock = c.lock
- discover.data.username = c.username
- discover.data.password = c.password
- discover.data.authkey = c.authkey
- f.close()
- end
- -- Check for Update
- draw.box(1, 51, 10, 1, " ", "lightGrey", "lightGrey")
- draw.textc("Checking for update...", 10, false, "red", "lightGrey")
- local status = discover:get_update()
- if status then
- draw.box(1, 51, 10, 1, " ", "lightGrey", "lightGrey")
- draw.textc("Update found, please wait...", 10, false, "red", "lightGrey")
- sleep(3)
- local name = shell.getRunningProgram()
- local f = fs.open(name, "w")
- f.write(discover.data.newupdate)
- f.close()
- else
- draw.box(1, 51, 10, 1, " ", "lightGrey", "lightGrey")
- draw.textc("You are currently running the latest version", 10, false, "red", "lightGrey")
- end
- -- Loading User Settings / Login
- if system.storeconfig then
- draw.box(1, 51, 10, 1, " ", "lightGrey", "lightGrey")
- draw.textc("Attempting to Login...", 10, false, "red", "lightGrey")
- local ok = discover:login(discover.data.username, discover.data.password)
- if ok then
- draw.box(1, 51, 10, 1, " ", "lightGrey", "lightGrey")
- draw.textc("You was successfully logged in!", 10, false, "red", "lightGrey")
- sleep(0.5)
- else
- draw.box(1, 51, 10, 1, " ", "lightGrey", "lightGrey")
- draw.textc(tostring(discover.data.errormsg), 10, false, "red", "lightGrey")
- sleep(1)
- end
- end
- -- Unlock Termination if system.lock is false
- if not system.lock then
- os.pullEvent = os.getEvent
- end
- -- Install System Plugins
- if system.plugins then
- draw.box(1, 51, 10, 1, " ", "lightGrey", "lightGrey")
- draw.textc("Installing Plugins...", 10, false, "red", "lightGrey")
- local ok, err = pcall(function()
- -- Plugin Function
- local function install(path)
- local tLetters = {"a","b","c","d","e","f"}; new = {}
- for i=1,4 do table.insert(new, tLetters[math.ceil(math.random(5))]) end
- newname = table.concat(new, "")
- aa = aa or {}
- local a = fs.open(path, "r")
- a = a.readAll()
- local env = {}
- a = loadstring(a)
- local env = getfenv()
- setfenv(a,env)
- local status, err = pcall(a, unpack(aa))
- if (not status) and err then
- printError("Error loading api")
- return false
- end
- local returned = err
- env = env
- _G[newname] = env
- end
- -- Get Plugins
- if fs.exists(system.paths.plugins) then
- local list = fs.list(system.paths.plugins)
- for k,v in ipairs(list) do
- local path = fs.combine(system.paths.plugins, v)
- install(path)
- end
- end
- end)
- if not ok then
- store.crash(err)
- end
- end
- -- Start Threads
- local ok, err = pcall(function()
- -- Draw Screen
- col.screen("white")
- draw.textc("Downloading Store Directory, Please Wait", 9, false, "grey", "white")
- sleep(0.5)
- discover:store_init()
- thread:create("Home", store.home)
- thread:switch("Home")
- thread:run()
- end)
- if not ok then
- store.crash(err)
- end
- end
- function store.crash(errmsg)
- col.screen("lightGrey")
- draw.box(1, 51, 1, 1, "-", "grey", "lightGrey")
- draw.textc("Discover Store has Crashed", 2, false, "grey", "lightGrey")
- draw.box(1, 51, 3, 1, "-", "grey", "lightGrey")
- local text = "Discover Store has been completely re-coded from scratch so if it has crashed for you please, do submit a comment on the forums thread, and I can have a look at how to fix it or go to: https://projects.dannysmc.com/ and choose the \"Discover Store\" and submit an issue with the error message (Which is below)."
- for k,v in ipairs(data.wordwrap(text, 51)) do
- draw.textl(v, k+3, false, "white", "lightGrey")
- end
- for k,v in ipairs(data.wordwrap(errmsg, 47)) do
- draw.texta(v, 3, k+12, false, "red", "lightGrey")
- end
- draw.textc("- Press \"Enter\" to reboot the computer -", 19, false, "orange", "lightGrey")
- while true do
- local args = { os.pullEvent() }
- if args[1] == "key" then
- if args[2] == 28 then
- popup.alert("Rebooting...")
- sleep(1)
- os.reboot()
- end
- end
- end
- end
- function store.home()
- col.screen("white")
- store.draw.menu("Home")
- store.draw.logo()
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("Home")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Home", args[3], args[4])
- elseif (args[3] >= 2 and args[3] <= 25) and (args[4] == 9) then
- if discover.data.loggedin then
- store.account.logout()
- col.screen("white")
- store.draw.menu("Home")
- store.draw.logo()
- else
- store.account.login()
- col.screen("white")
- store.draw.menu("Home")
- store.draw.logo()
- end
- elseif (args[3] >= 2 and args[3] <= 25) and (args[4] == 11) then
- if not thread:find("Apps") then
- thread:create("Apps", store.apps.all)
- end
- thread:switch("Apps")
- elseif (args[3] >= 2 and args[3] <= 25) and (args[4] == 13) then
- if not thread:find("Versions") then
- thread:create("Versions", store.apps.versions)
- end
- thread:switch("Versions")
- elseif (args[3] >= 2 and args[3] <= 25) and (args[4] == 15) then
- if not thread:find("Categories") then
- thread:create("Categories", store.apps.categories)
- end
- thread:switch("Categories")
- elseif (args[3] >= 2 and args[3] <= 25) and (args[4] == 17) then
- if discover.data.loggedin then
- if not thread:find("Stats") then
- thread:create("Stats", store.account.stats)
- end
- thread:switch("Stats")
- else
- popup.alert("Please login")
- sleep(1)
- col.screen("white")
- store.draw.menu("Home")
- store.draw.logo()
- end
- elseif (args[3] >= 27 and args[3] <= 50) and (args[4] == 9) then
- if discover.data.loggedin then
- if not thread:find("Account") then
- thread:create("Account", store.account.home)
- end
- thread:switch("Account")
- else
- popup.alert("Please login")
- sleep(1)
- col.screen("white")
- store.draw.menu("Home")
- store.draw.logo()
- end
- elseif (args[3] >= 27 and args[3] <= 50) and (args[4] == 11) then
- if not thread:find("Help") then
- thread:create("Help", store.help)
- end
- thread:switch("Help")
- elseif (args[3] >= 27 and args[3] <= 50) and (args[4] == 13) then
- if not thread:find("Updates") then
- thread:create("Updates", store.updates)
- end
- thread:switch("Updates")
- elseif (args[3] >= 27 and args[3] <= 50) and (args[4] == 15) then
- if not thread:find("Settings") then
- thread:create("Settings", store.settings)
- end
- thread:switch("Settings")
- elseif (args[3] >= 27 and args[3] <= 50) and (args[4] == 17) then
- if not thread:find("Credits") then
- thread:create("Credits", store.credits)
- end
- thread:switch("Credits")
- end
- end
- end
- end
- function store.apps.all()
- col.screen("white")
- store.draw.menu("All Apps")
- local scroll = 0
- appslist = discover:get("apps")
- draw.box(1, 51, 19, 1, " ", "grey", "grey")
- draw.texta("Total Apps: "..#appslist, 2, 19, false, "lightBlue", "grey")
- draw.textr("Scroll Enabled ", 19, false, "orange", "grey")
- local function fix(num)
- if tostring(num):len() == 1 then
- return " "..tostring(num)
- elseif tostring(num):len() == 2 then
- return " "..tostring(num)
- else
- return tostring(num)
- end
- end
- local function run(scroll)
- for i = 1, 14 do
- if #appslist >= i + scroll then
- draw.box(1, 51, i+3, 1, " ", "white", "white")
- draw.textl(fix(i+scroll)..": "..appslist[i+scroll].name, i+3, false, "grey", "white")
- end
- end
- end
- run(scroll)
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("All Apps")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Help / FAQ", args[3], args[4])
- elseif (args[3] >= 1 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 17) then
- local curid = args[4] - 3 + scroll
- local tname = "View"..tostring(appslist[curid].id)
- thread:create(tname, store.apps.view)
- viewapps[1] = appslist[curid].id
- viewapps[2] = appslist
- thread:switch(tname)
- end
- elseif args[1] == "mouse_scroll" then
- if args[2] == -1 then
- if scroll > 0 then
- scroll = scroll - 1
- run(scroll)
- end
- elseif args[2] == 1 then
- if scroll + 14 <= #appslist-1 then
- scroll = scroll + 1
- run(scroll)
- end
- end
- end
- end
- end
- function store.apps.versions(version)
- col.screen("white")
- store.draw.menu("Versions")
- draw.box(21, 1, 3, 17, " ", "grey", "grey")
- draw.box(1, 51, 19, 1, " ", "grey", "grey")
- draw.texta("Total Versions: "..#discover.data.versions, 2, 19, false, "lightBlue", "grey")
- draw.textr("SCroll Enabled", 19, false, "orange", "grey")
- -- Vars
- local lscroll = 0
- local rscroll = 0
- local ldata = discover.data.versions
- local rdata = {}
- local lselect = ""
- local allapps = discover.data.apps
- local function lrun(lscroll)
- for i=1, 14 do
- if #ldata >= i + lscroll then
- if lselect == ldata[i+lscroll] then
- draw.box(1, 19, i+3, 1, " ", "white", "white")
- draw.texta(ldata[i+lscroll], 1, i+3, false, "grey", "white")
- else
- draw.box(1, 19, i+3, 1, " ", "white", "white")
- draw.texta(ldata[i+lscroll], 1, i+3, false, "cyan", "white")
- end
- end
- end
- end
- local function rrun(rscroll)
- for i=1, 14 do
- if #rdata >= i + rscroll then
- draw.box(22, 29, i+3, 1, " ", "white", "white")
- draw.texta(rdata[i+rscroll].name:sub(1, 25), 23, i+3, false, "grey", "white")
- end
- end
- end
- lrun(lscroll)
- rrun(rscroll)
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("Versions")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Versions", args[3], args[4])
- elseif (args[3] >= 1 and args[3] <= 20) and (args[4] >= 4 and args[4] <= 17) then
- -- Choose
- local cid = args[4] - 3 + lscroll
- if #ldata >= cid then
- lselect = ldata[cid]
- rdata = {}
- for k,v in ipairs(allapps) do
- if v.version == lselect then
- rdata[#rdata+1] = v
- end
- end
- for i=1, 14 do
- draw.box(22, 29, i+3, 1, false, "white", "white")
- end
- rscroll = 0
- rrun(rscroll)
- lrun(lscroll)
- end
- elseif (args[3] >= 22 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 17) then
- -- View app
- local cid = args[4] - 3 + rscroll
- if #rdata >= cid then
- viewapps[1] = rdata[cid].id
- viewapps[2] = discover.data.apps
- if not thread:find("View"..tostring(rdata[cid].id)) then
- thread:create("View"..tostring(rdata[cid].id), store.apps.view)
- end
- thread:switch("View"..tostring(rdata[cid].id))
- end
- end
- elseif args[1] == "mouse_scroll" then
- if args[2] == -1 then
- if (args[3] >= 1 and args[3] <= 20) and (args[4] >= 4 and args[4] <= 17) then
- if lscroll > 0 then
- lscroll = lscroll - 1
- lrun(lscroll)
- end
- elseif (args[3] >= 22 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 17) then
- if rscroll > 0 then
- rscroll = rscroll - 1
- rrun(rscroll)
- end
- end
- elseif args[2] == 1 then
- if (args[3] >= 1 and args[3] <= 20) and (args[4] >= 4 and args[4] <= 17) then
- if lscroll + 14 <= #ldata-1 then
- lscroll = lscroll + 1
- lrun(lscroll)
- end
- elseif (args[3] >= 22 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 17) then
- if rscroll + 14 <= #rdata-1 then
- rscroll = rscroll + 1
- rrun(rscroll)
- end
- end
- end
- end
- end
- end
- function store.apps.categories()
- col.screen("white")
- store.draw.menu("Categories")
- draw.box(21, 1, 3, 17, " ", "grey", "grey")
- draw.box(1, 51, 19, 1, " ", "grey", "grey")
- draw.texta("Total Categories: "..#discover.data.categories, 2, 19, false, "lightBlue", "grey")
- draw.textr("SCroll Enabled", 19, false, "orange", "grey")
- -- Vars
- local lscroll = 0
- local rscroll = 0
- local ldata = discover.data.categories
- local rdata = {}
- local lselect = ""
- local allapps = discover.data.apps
- local function lrun(lscroll)
- for i=1, 14 do
- if #ldata >= i + lscroll then
- if lselect == ldata[i+lscroll] then
- draw.box(1, 19, i+3, 1, " ", "white", "white")
- draw.texta(ldata[i+lscroll], 1, i+3, false, "grey", "white")
- else
- draw.box(1, 19, i+3, 1, " ", "white", "white")
- draw.texta(ldata[i+lscroll], 1, i+3, false, "cyan", "white")
- end
- end
- end
- end
- local function rrun(rscroll)
- for i=1, 14 do
- if #rdata >= i + rscroll then
- draw.box(22, 29, i+3, 1, " ", "white", "white")
- draw.texta(rdata[i+rscroll].name:sub(1, 25), 23, i+3, false, "grey", "white")
- end
- end
- end
- lrun(lscroll)
- rrun(rscroll)
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("Categories")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Categories", args[3], args[4])
- elseif (args[3] >= 1 and args[3] <= 20) and (args[4] >= 4 and args[4] <= 17) then
- -- Choose
- local cid = args[4] - 3 + lscroll
- if #ldata >= cid then
- lselect = ldata[cid]
- rdata = {}
- for k,v in ipairs(allapps) do
- if v.category == lselect then
- rdata[#rdata+1] = v
- end
- end
- for i=1, 14 do
- draw.box(22, 29, i+3, 1, false, "white", "white")
- end
- rscroll = 0
- rrun(rscroll)
- lrun(lscroll)
- end
- elseif (args[3] >= 22 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 17) then
- -- View app
- local cid = args[4] - 3 + rscroll
- if #rdata >= cid then
- viewapps[1] = rdata[cid].id
- viewapps[2] = discover.data.apps
- if not thread:find("View"..tostring(rdata[cid].id)) then
- thread:create("View"..tostring(rdata[cid].id), store.apps.view)
- end
- thread:switch("View"..tostring(rdata[cid].id))
- end
- end
- elseif args[1] == "mouse_scroll" then
- if args[2] == -1 then
- if (args[3] >= 1 and args[3] <= 20) and (args[4] >= 4 and args[4] <= 17) then
- if lscroll > 0 then
- lscroll = lscroll - 1
- lrun(lscroll)
- end
- elseif (args[3] >= 22 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 17) then
- if rscroll > 0 then
- rscroll = rscroll - 1
- rrun(rscroll)
- end
- end
- elseif args[2] == 1 then
- if (args[3] >= 1 and args[3] <= 20) and (args[4] >= 4 and args[4] <= 17) then
- if lscroll + 14 <= #ldata-1 then
- lscroll = lscroll + 1
- lrun(lscroll)
- end
- elseif (args[3] >= 22 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 17) then
- if rscroll + 14 <= #rdata-1 then
- rscroll = rscroll + 1
- rrun(rscroll)
- end
- end
- end
- end
- end
- end
- function store.apps.view()
- col.screen("white")
- draw.textc("Loading...", 9, false, "grey", "white")
- local scroll = 0
- local appid = viewapps[1]
- local appslist = viewapps[2]
- for k,v in ipairs(appslist) do
- if tonumber(v.id) == tonumber(appid) then
- apppos = k
- break
- end
- end
- local appdesc = data.wordwrap(appslist[apppos].description, 49)
- col.screen("white")
- store.draw.menu("View App "..tostring(appslist[apppos].id))
- draw.box(1, 51, 19, 1, " ", "grey", "grey")
- draw.texta("Comments", 2, 19, false, "lightBlue", "grey")
- local function drawdesc(scroll)
- for i = 1, 7 do
- if #appdesc >= i + scroll then
- draw.box(1, 51, i+9, 1, " ", "white", "white")
- draw.textl(appdesc[i+scroll], i+9, false, "grey", "white")
- end
- end
- end
- local function run()
- draw.textl("Name (ID):", 4, false, "lightGrey", "white")
- draw.texta(appslist[apppos].name.." ("..appslist[apppos].id..")", 12, 4, false, "grey", "white")
- draw.textl("Category:", 5, false, "lightGrey", "white")
- draw.texta(appslist[apppos].category, 12, 5, false, "grey", "white")
- draw.textl("Version:", 6, false, "lightGrey", "white")
- draw.texta(appslist[apppos].version, 12, 6, false, "grey", "white")
- draw.textl("Creator:", 7, false, "lightGrey", "white")
- draw.texta(appslist[apppos].creator, 12, 7, false, "grey", "white")
- draw.textl("App Hash:", 18, false, "lightGrey", "white")
- draw.texta(appslist[apppos].hash, 11, 18, false, "grey", "white")
- draw.textl("Description", 9, false, "lightGrey", "white")
- draw.textr(appslist[apppos].downloads.." download(s) ", 19, false, "orange", "grey")
- drawdesc(scroll)
- draw.texta(" Download ", 41, 5, false, "white", "cyan")
- draw.texta(" App! ", 41, 6, false, "white", "cyan")
- end
- run()
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("View App "..tostring(appslist[apppos].id))
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Help / FAQ", args[3], args[4])
- elseif (args[3] >= 41 and args[3] <= 50) and (args[4] >= 5 and args[4] <= 6) then
- temp.download = appslist[apppos].id
- thread:create("Download"..tostring(appslist[apppos].id), store.apps.download)
- thread:switch("Download"..tostring(appslist[apppos].id))
- elseif (args[3] >= 2 and args[3] <= 9) and args[4] == 19 then
- store.apps.comments(appslist[apppos].id)
- col.screen("white")
- store.draw.menu("View App "..tostring(appslist[apppos].id))
- draw.box(1, 51, 19, 1, " ", "grey", "grey")
- draw.texta("Comments", 2, 19, false, "lightBlue", "grey")
- run()
- end
- elseif args[1] == "mouse_scroll" then
- if args[2] == -1 then
- if scroll > 0 then
- scroll = scroll - 1
- run(scroll)
- end
- elseif args[2] == 1 then
- if scroll + 14 <= #appdesc then
- scroll = scroll + 1
- run(scroll)
- end
- end
- end
- end
- end
- function store.apps.comments(appid)
- col.screen("white")
- draw.textc("Download comments...", 9, false, "grey", "white")
- local scroll = 0
- local ok = discover:store_comments_get(appid)
- if not ok then
- viewapps[1] = appid
- store.apps.view()
- end
- comments = discover.data.comments
- col.screen("white")
- store.draw.menu("Comments: "..tostring(appid))
- draw.box(1, 51, 19, 1, " ", "grey", "grey")
- if discover.data.loggedin then
- draw.textl(" Add", 19, false, "lightBlue", "grey")
- end
- draw.textr("Back ", 19, false, "orange", "grey")
- local function run(scroll)
- if #comments == 0 then
- draw.textc("No comments to display", 9, false, "grey", "white")
- end
- for i=1, 14 do
- if #comments >= i + scroll then
- draw.box(1, 51, i+9, 1, " ", "white", "white")
- draw.textl(comments[i+scroll].comment, i+3, false, "grey", "white")
- draw.textr(comments[i+scroll].username, i+3, false, "cyan", "white")
- end
- end
- end
- run(scroll)
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("Comments: "..tostring(appid))
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Help / FAQ", args[3], args[4])
- elseif (args[3] >= 2 and args[3] <= 4) and (args[4] == 19) then
- if discover.data.loggedin then
- local comment = popup.input("Comment Text:")
- local status = discover:store_comments_set( appid, comment )
- if status then
- popup.alert("Added!")
- sleep(0.5)
- else
- popup.alert("Failed")
- sleep(1)
- end
- col.screen("white")
- draw.textc("Download comments...", 9, false, "grey", "white")
- local scroll = 0
- local ok = discover:store_comments_get(appid)
- if not ok then
- viewapps[1] = appid
- store.apps.view()
- end
- comments = discover.data.comments
- col.screen("white")
- store.draw.menu("Comments: "..tostring(appid))
- draw.box(1, 51, 19, 1, " ", "grey", "grey")
- if discover.data.loggedin then
- draw.textl(" Add", 19, false, "lightBlue", "grey")
- end
- draw.textr("Back ", 19, false, "orange", "grey")
- run(scroll)
- end
- elseif (args[3] >= 47 and args[3] <= 50) and (args[4] == 19) then
- break
- end
- elseif args[1] == "mouse_scroll" then
- if args[2] == -1 then
- if scroll > 0 then
- scroll = scroll - 1
- run(scroll)
- end
- elseif args[2] == 1 then
- if scroll + 14 <= #comments then
- scroll = scroll + 1
- run(scroll)
- end
- end
- end
- end
- end
- function store.account.login()
- col.screen("white")
- store.draw.menu("Login")
- draw.box(1, 51, 19, 1, " ", "grey", "grey")
- draw.textl(" Cancel", 19, false, "orange", "grey")
- draw.textr("Login ", 19, false, "cyan", "grey")
- local function run()
- draw.textc("Discover API Login", 4, false, "grey", "white")
- draw.texta("Username:", 8, 7, false, "lightGrey", "white")
- draw.box(8, 36, 8, 1, " ", "cyan", "cyan")
- draw.texta("Password:", 8, 10, false, "lightGrey", "white")
- draw.box(8, 36, 11, 1, " ", "cyan", "cyan")
- draw.textc("Need an account? Register here!", 14, false, "grey", "white")
- end
- run()
- restart_home = true
- while not discover.data.loggedin or restart_home do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("Login")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Login", args[3], args[4])
- elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 8) then
- draw.box(8, 36, 8, 1, " ", "cyan", "cyan")
- col.set("white", "cyan")
- term.setCursorPos(8, 8)
- write(": ")
- username = tostring(read())
- elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 11) then
- draw.box(8, 36, 11, 1, " ", "cyan", "cyan")
- col.set("white", "cyan")
- term.setCursorPos(8, 11)
- write(": ")
- password = tostring(read("*"))
- password = crypt.sha256(password)
- elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 14) then
- store.account.register()
- elseif (args[3] >= 2 and args[3] <= 10) and (args[4] == 19) then
- break
- elseif (args[3] >= 46 and args[3] <= 50) and (args[4] == 19) then
- if username and password then
- draw.textc("Requesting Authentication, Please Wait", 17, false, "lightGrey", "white")
- if discover:login(username, password) then
- discover.data.loggedin = true
- popup.alert("Logged In!")
- if system.storeconfig then
- new = {}
- new.username = discover.data.username
- new.password = discover.data.password
- new.storeconfig = system.storeconfig
- new.plugins = system.plugins
- new.authkey = discover.data.authkey
- dat = textutils.serialize(new)
- local f = fs.open(system.paths.config, "w")
- f.write(basesf.encode(dat))
- f.close()
- end
- sleep(0.8)
- store.home()
- else
- draw.box(1, 51, 17, 1, " ", "white", "white")
- draw.textc(tostring(discover.data.errormsg), 17, false, "lightGrey", "white")
- sleep(1)
- store.home()
- end
- else
- draw.textc("Please fill in the fields", 17, false, "lightGrey", "white")
- end
- end
- end
- end
- end
- function store.account.register()
- col.screen("white")
- store.draw.menu("Login")
- draw.box(1, 51, 19, 1, " ", "grey", "grey")
- draw.textl(" Cancel", 19, false, "orange", "grey")
- draw.textr("Register ", 19, false, "cyan", "grey")
- local function run()
- draw.textc("Discover API Registration", 4, false, "grey", "white")
- draw.texta("Username:", 8, 7, false, "lightGrey", "white")
- draw.box(8, 36, 8, 1, " ", "cyan", "cyan")
- draw.texta("Password:", 8, 10, false, "lightGrey", "white")
- draw.box(8, 36, 11, 1, " ", "cyan", "cyan")
- draw.texta("Email:", 8, 13, false, "lightGrey", "white")
- draw.box(8, 36, 14, 1, " ", "cyan", "cyan")
- draw.textc("Have an account? Login here!", 17, false, "grey", "white")
- end
- run()
- restart_home = true
- while not discover.data.loggedin or restart_home do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("Login")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Login", args[3], args[4])
- elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 8) then
- draw.box(8, 36, 8, 1, " ", "cyan", "cyan")
- col.set("white", "cyan")
- term.setCursorPos(8, 8)
- write(": ")
- username = tostring(read())
- elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 11) then
- draw.box(8, 36, 11, 1, " ", "cyan", "cyan")
- col.set("white", "cyan")
- term.setCursorPos(8, 11)
- write(": ")
- password = tostring(read("*"))
- password = crypt.sha256(password)
- elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 14) then
- draw.box(8, 36, 14, 1, " ", "cyan", "cyan")
- col.set("white", "cyan")
- term.setCursorPos(8, 14)
- write(": ")
- email = tostring(read())
- elseif (args[3] >= 9 and args[3] <= 42) and (args[4] == 17) then
- store.account.login()
- elseif (args[3] >= 2 and args[3] <= 10) and (args[4] == 19) then
- break
- elseif (args[3] >= 43 and args[3] <= 50) and (args[4] == 19) then
- if username and password and email then
- draw.textc("Requesting Authentication, Please Wait", 17, false, "lightGrey", "white")
- if discover:register(username, password, email) then
- popup.alert("Registered. Obtaining authkey, please wait")
- sleep(0.5)
- local status = discover:login(username, password)
- if status then
- popup.alert("Logged in!")
- sleep(0.8)
- store.home()
- else
- popup.alert(discover.data.errormsg)
- sleep(1.5)
- store.home()
- end
- else
- draw.box(1, 51, 17, 1, " ", "white", "white")
- draw.textc(tostring(discover.data.errormsg), 17, false, "lightGrey", "white")
- sleep(1)
- store.account.home()
- end
- else
- draw.textc("Please fill in the fields", 17, false, "lightGrey", "white")
- end
- end
- end
- end
- end
- function store.account.logout()
- popup.alert("Logging out...")
- sleep(0.5)
- discover:logout()
- popup.alert("Logged out!")
- sleep(0.5)
- end
- function store.account.upload(step)
- if not step then
- step = ""
- end
- if step == "1" then
- col.screen("white")
- store.draw.menu("Upload (Step 1)")
- draw.box(1, 51, 19, 11, " ", "grey", "grey")
- draw.textl(" Cancel", 19, false, "orange", "grey")
- draw.textr("Next Step ", 19, false, "orange", "grey")
- draw.textc("Press \"up\" to see preset versions / categories.", 18, false, "lightGrey", "white")
- local function run()
- draw.textc("Please follow on-screen instructions!", 4, false, "cyan", "white")
- draw.texta("App Name:", 8, 6, false, "lightGrey", "white")
- draw.box(8, 36, 7, 1, " ", "cyan", "cyan")
- draw.texta("App Description:", 8, 9, false, "lightGrey", "white")
- draw.box(8, 36, 10, 1, " ", "cyan", "cyan")
- draw.texta("App Version:", 8, 12, false, "lightGrey", "white")
- draw.box(8, 36, 13, 1, " ", "cyan", "cyan")
- draw.texta("App Category:", 8, 15, false, "lightGrey", "white")
- draw.box(8, 36, 16, 1, " ", "cyan", "cyan")
- end
- local function render()
- if up_name then
- draw.texta(tostring(": "..up_name), 8, 7, false, "white", "cyan")
- end
- if up_desc then
- draw.texta(tostring(": "..up_desc), 8, 10, false, "white", "cyan")
- end
- if up_vers then
- draw.texta(tostring(": "..up_vers), 8, 13, false, "white", "cyan")
- end
- if up_cate then
- draw.texta(tostring(": "..up_cate), 8, 16, false, "white", "cyan")
- end
- end
- render()
- run()
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("Upload (Step 1)")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Upload", args[3], args[4])
- elseif (args[3] >= 2 and args[3] <= 7) and (args[4] == 19) then
- thread:remove("Upload")
- if not thread:find("Account") then
- thread:create("Account", store.account.home)
- end
- thread:switch("Account")
- elseif (args[3] >= 42 and args[3] <= 50) and (args[4] == 19) then
- if up_name and up_desc and up_vers and up_cate then
- store.account.upload("2")
- else
- draw.box(1, 51, 17, 1, " ", "white", "white")
- draw.textc("Please fill out all fields", 17, false, "red", "white")
- sleep(1)
- draw.box(1, 51, 17, 1, " ", "white", "white")
- end
- elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 7) then
- draw.box(1, 51, 7, 1, " ", "white", "white")
- draw.box(8, 36, 7, 1, " ", "cyan", "cyan")
- col.set("white", "cyan")
- term.setCursorPos(8, 7)
- write(": ")
- up_name = tostring(read())
- elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 10) then
- draw.box(1, 51, 10, 1, " ", "white", "white")
- draw.box(8, 36, 10, 1, " ", "cyan", "cyan")
- col.set("white", "cyan")
- term.setCursorPos(8, 10)
- write(": ")
- up_desc = tostring(read())
- elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 13) then
- draw.box(1, 51, 13, 1, " ", "white", "white")
- draw.box(8, 36, 13, 1, " ", "cyan", "cyan")
- col.set("white", "cyan")
- term.setCursorPos(8, 13)
- write(": ")
- up_vers = tostring(read(_, discover.data.versions))
- elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 16) then
- draw.box(1, 51, 16, 1, " ", "white", "white")
- draw.box(8, 36, 16, 1, " ", "cyan", "cyan")
- col.set("white", "cyan")
- term.setCursorPos(8, 16)
- write(": ")
- up_cate = tostring(read(_, discover.data.categories))
- end
- end
- end
- elseif step == "2" then
- col.screen("white")
- store.draw.menu("Upload (Step 2)")
- draw.box(1, 51, 19, 11, " ", "grey", "grey")
- draw.textl(" Back", 19, false, "orange", "grey")
- draw.textr("Upload ", 19, false, "orange", "grey")
- local function run()
- draw.textc("Please follow on-screen instructions!", 4, false, "cyan", "white")
- draw.texta("App Status:", 8, 6, false, "lightGrey", "white")
- draw.box(8, 36, 7, 1, " ", "cyan", "cyan")
- draw.texta("App\'s file path:", 8, 9, false, "lightGrey", "white")
- draw.box(8, 36, 10, 1, " ", "cyan", "cyan")
- end
- local function exit()
- up_stat = nil
- up_path = nil
- up_desc = nil
- up_cate = nil
- up_vers = nil
- up_name = nil
- thread:remove("Upload")
- if not thread:find("Account") then
- thread:create("Account", store.account.home)
- end
- thread:switch("Account")
- end
- local function render()
- if up_stat then
- draw.texta(tostring(": "..up_stat), 8, 7, false, "white", "cyan")
- end
- if up_path then
- draw.texta(tostring(": "..up_path), 8, 10, false, "white", "cyan")
- end
- end
- run()
- render()
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("Upload (Step 2)")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Upload", args[3], args[4])
- elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 7) then
- draw.box(1, 51, 7, 1, " ", "white", "white")
- draw.box(8, 36, 7, 1, " ", "cyan", "cyan")
- col.set("white", "cyan")
- term.setCursorPos(8, 7)
- write(": ")
- up_stat = tostring(read(_, {"public", "private"}))
- elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 10) then
- draw.box(1, 51, 10, 1, " ", "white", "white")
- draw.box(8, 36, 10, 1, " ", "cyan", "cyan")
- col.set("white", "cyan")
- term.setCursorPos(8, 10)
- write(": ")
- up_path = tostring(read())
- elseif (args[3] >= 45 and args[3] <= 50) and (args[4] == 19) then
- if up_stat and up_path then
- for i=12, 17 do
- draw.box(1, 51, i, 1, " ", "white", "white")
- end
- draw.texta(":: Finding File...", 8, 12, false, "grey", "white")
- if fs.exists(up_path) then
- draw.texta(":: Extracting Data...", 8, 13, false, "grey", "white")
- local up_path_content = fs.open(up_path, "r")
- up_path_content = up_path_content.readAll()
- draw.texta(":: Sending Server Request...", 8, 14, false, "grey", "white")
- local status = discover:store_upload( up_name, up_desc, up_cate, up_vers, up_stat, up_path_content )
- if status then
- draw.texta(":: Upload was successfull!", 8, 15, false, "grey", "white")
- sleep(1)
- exit()
- else
- draw.texta(":: Unable to store data", 8, 15, false, "grey", "white")
- draw.texta(":: "..tostring(discover.data.errormsg), 8, 15, false, "grey", "white")
- sleep(2)
- end
- else
- draw.texta(":: ERROR: No file found", 8, 13, false, "grey", "white")
- sleep(1)
- end
- else
- draw.box(1, 51, 18, 1, " ", "white", "white")
- draw.textc("Please fill out all fields", 18, false, "red", "white")
- sleep(1)
- draw.box(1, 51, 18, 1, " ", "white", "white")
- end
- elseif (args[3] >= 2 and args[3] <= 5) and (args[4] == 19) then
- store.account.upload("1")
- end
- end
- end
- else
- col.screen("white")
- store.draw.menu("Upload")
- draw.box(1, 51, 19, 11, " ", "grey", "grey")
- draw.textl(" Cancel", 19, false, "orange", "grey")
- draw.textr("Accept ", 19, false, "orange", "grey")
- local scroll = 0
- local function run(scroll)
- draw.textc("Please read the following before submitting:", 4, false, "lightGrey", "white")
- local text = "Apps uploaded to this system are saved on a web server, we do not edit your code and/or modify it for our own use, a moderator will check the code to make sure it is error proof and not malicous (malicous being you steal users information), if there are too many errors then your program will be set to private until an update to the code has been made. You will be notified via the automated Email system to your email on file."
- tText = data.wordwrap(text, 47)
- for i=1, 12 do
- if (scroll + i) <= #tText then
- draw.box(1, 51, i+5, 1, " ", "white", "white")
- draw.texta(tText[i+scroll], 3, i+5, false, "grey", "white")
- end
- end
- end
- run(scroll)
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("upload")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Upload", args[3], args[4])
- elseif (args[3] >= 2 and args[3] <= 7) and (args[4] == 19) then
- thread:remove("Upload")
- if not thread:find("Account") then
- thread:create("Account", store.account.home)
- end
- thread:switch("Account")
- elseif (args[3] >= 45 and args[3] <= 50) and (args[4] == 19) then
- store.account.upload("1")
- end
- elseif args[1] == "mouse_scroll" then
- if args[2] == -1 then
- if scroll > 0 then
- scroll = scroll - 1
- run(scroll)
- end
- elseif args[2] == 1 then
- if scroll + 12 < #tText then
- scroll = scroll + 1
- run(scroll)
- end
- end
- end
- end
- end
- end
- function store.apps.download()
- col.screen("white")
- store.draw.menu("Download")
- local appid = temp.download
- local text = "You are attempting to download an app, please choose a name for the file download";
- local function run()
- for k,v in ipairs(data.wordwrap(text, 45)) do
- draw.textc(v, k+3, false, "grey", "white")
- end
- draw.texta("File Name / Path:", 8, 8, false, "lightGrey", "white")
- draw.box(8, 36, 9, 1, " ", "cyan", "cyan")
- draw.texta(" Download ", 8, 12, false, "white", "cyan")
- draw.texta(" Cancel ", 36, 12, false, "white", "cyan")
- end
- run()
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("Download")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Download", args[3], args[4])
- elseif (args[3] >= 8 and args[3] <= 17) and (args[4] == 12) then
- if filepath then
- local data = discover:store_download(appid)
- if data then
- local f = fs.open(filepath, "w")
- f.write(data.readAll())
- f.close()
- popup.alert("Saved!")
- sleep(1)
- thread:remove("Download" .. tostring(appid))
- if thread:find("Apps") then
- thread:create("Apps", store.apps.all)
- end
- thread:switch("Apps")
- else
- draw.box(1, 51, 14, 1, " ", "white", "white")
- draw.textc("An error occured", 14, false, "lightGrey", "white")
- end
- else
- draw.box(1, 51, 14, 1, " ", "white", "white")
- draw.textc("Please supply a file path / name!", 14, false, "lightGrey", "white")
- end
- elseif (args[3] >= 36 and args[3] <= 43) and (args[4] == 12) then
- thread:remove("Download"..tostring(appid))
- thread:switch("Home")
- elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 9) then
- draw.box(8, 36, 9, 1, " ", "cyan", "cyan")
- col.set("white", "cyan")
- term.setCursorPos(8, 9)
- write(": ")
- filepath = tostring(read())
- end
- end
- end
- end
- function store.account.myapps()
- col.screen("white")
- draw.textc("Downloading your apps list...", 9, false, "grey", "white")
- if not discover:store_apps_user() then
- popup.alert("Could not obtain your Apps list...")
- sleep(1.5)
- if not thread:find("Account") then
- thread:create("Account", store.account.home)
- end
- thread:remove("MyApps")
- thread:switch("Account")
- end
- appslist = discover.data.appsuser
- draw.box(1, 51, 9, 1, " ", "white", "white")
- store.draw.menu("MyApps")
- draw.box(1, 51, 19, 1, " ", "grey", "grey")
- draw.texta("Your Apps: "..tostring(#appslist), 2, 19, false, "orange", "grey")
- scroll = 0
- local function fix(num)
- if tostring(num):len() == 1 then
- return " "..tostring(num)
- else
- return tostring(num)
- end
- end
- local function run(scroll)
- for i = 1, 14 do
- if #appslist >= i + scroll then
- draw.box(1, 51, i+3, 1, " ", "white", "white")
- draw.texta(tostring(fix(i+scroll)..": "..appslist[i+scroll].name):sub(1, 40), 1, i+3, false, "grey", "white")
- draw.texta("X", 50, i+3, false, "red", "white")
- draw.texta("Edit", 44, i+3, false, "lightBlue", "white")
- end
- end
- end
- run(scroll)
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("MyApps")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("MyApps", args[3], args[4])
- elseif (args[3] >= 44 and args[3] <= 47) and (args[4] >= 4 and args[4] <= 17) then
- -- Do Edit
- local appid = appslist[args[4] - 3 + scroll].id
- temp.edit_appid = appid
- thread:create("Edit", store.account.edit)
- thread:switch("Edit")
- elseif (args[3] == 50) and (args[4] >= 4 and args[4] <= 17) then
- -- Do Delete
- local appid = appslist[args[4] - 3 + scroll].id
- local appname = appslist[args[4] - 3 + scroll].name
- draw.box(8, 36, 8, 2, " ", "grey", "grey")
- draw.box(8, 36, 10, 2, " ", "grey", "grey")
- local text = "To delete the app: "..tostring(appname).." press \"enter\" otherwise please press any other button to exit."
- for k,v in ipairs(data.wordwrap(text, 34)) do
- draw.texta(v, 9, k+7, false, "white", "grey")
- end
- while true do
- local ev, nk = os.pullEvent("key")
- if ev == "key" then
- if nk == 28 then
- col.screen("white")
- store.draw.menu("MyApps")
- col.set("cyan", "white")
- term.setCursorPos(1, 4)
- print("Deleting...")
- local status = discover:store_delete( appid )
- if status then
- popup.alert("App Deleted!")
- sleep(0.5)
- store.account.myapps()
- else
- popup.alert(discover.data.errormsg)
- sleep(1.5)
- store.account.myapps()
- end
- else
- break
- end
- else
- break
- end
- end
- end
- elseif args[1] == "mouse_scroll" then
- if args[2] == -1 then
- if scroll > 0 then
- scroll = scroll - 1
- run(scroll)
- end
- elseif args[2] == 1 then
- if scroll + 14 < #appslist then
- scroll = scroll + 1
- run(scroll)
- end
- end
- end
- end
- end
- function store.account.home()
- col.screen("white")
- store.draw.menu("My Account")
- local function run()
- for i=1, 20 do
- draw.box(i, 1, 3, 17, " ", "lightGrey", "lightGrey")
- end
- draw.box(2, 18, 5, 1, " ", "orange", "orange")
- draw.box(2, 18, 7, 1, " ", "orange", "orange")
- draw.box(2, 18, 9, 1, " ", "orange", "orange")
- draw.texta("Upload an App", 3, 5, false, "white", "orange")
- draw.texta("Update an App", 3, 7, false, "white", "orange")
- draw.texta("View my Apps", 3, 9, false, "white", "orange")
- -- Draw info
- draw.texta("My Details", 31, 4, false, "grey", "white")
- draw.texta("Username:", 22, 7, false, "lightGrey", "white")
- draw.box(22, 29, 8, 1, " ", "cyan", "cyan")
- draw.texta(tostring(discover.data.username), 23, 8, false, "white", "cyan")
- draw.texta("AuthKey:", 22, 11, false, "lightGrey", "white")
- draw.box(22, 29, 12, 1, " ", "cyan", "cyan")
- draw.box(22, 29, 13, 1, " ", "cyan", "cyan")
- draw.box(22, 29, 14, 1, " ", "cyan", "cyan")
- draw.box(22, 29, 15, 1, " ", "cyan", "cyan")
- draw.box(22, 29, 16, 1, " ", "cyan", "cyan")
- draw.texta(discover.data.authkey:sub(1, 27) , 23, 12, false, "white", "cyan")
- draw.texta(discover.data.authkey:sub(28, 54) , 23, 13, false, "white", "cyan")
- draw.texta(discover.data.authkey:sub(55, 81) , 23, 14, false, "white", "cyan")
- draw.texta(discover.data.authkey:sub(82, 108) , 23, 15, false, "white", "cyan")
- draw.texta(discover.data.authkey:sub(109) , 23, 16, false, "white", "cyan")
- end
- run()
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("My Account")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Account", args[3], args[4])
- elseif (args[3] >= 2 and args[3] <= 18) and (args[4] == 5) then
- if not thread:find("Upload") then
- thread:create("Upload", store.account.upload)
- end
- thread:switch("Upload")
- elseif (args[3] >= 2 and args[3] <= 18) and (args[4] == 7) then
- if not thread:find("Update") then
- thread:create("Update", store.account.update)
- end
- thread:switch("Update")
- elseif (args[3] >= 2 and args[3] <= 18) and (args[4] == 9) then
- if not thread:find("MyApps") then
- thread:create("MyApps", store.account.myapps)
- end
- thread:switch("MyApps")
- end
- end
- end
- end
- function store.account.update()
- col.screen("white")
- store.draw.menu("Update")
- draw.box(1, 51, 19, 1, " ", "grey", "grey")
- draw.textl(" Cancel", 19, false, "orange", "grey")
- draw.textr("Update ", 19, false, "cyan", "grey")
- local function exit()
- upd_stat = nil
- upd_path = nil
- upd_vers = nil
- upd_path_content = nil
- upd_appid = nil
- thread:remove("Upload")
- if not thread:find("Account") then
- thread:create("Account", store.account.home)
- end
- thread:switch("Account")
- end
- local function run()
- draw.textc("Please follow on-screen instructions!", 4, false, "cyan", "white")
- draw.texta("App ID:", 8, 6, false, "lightGrey", "white")
- draw.box(8, 36, 7, 1, " ", "cyan", "cyan")
- draw.texta("Version:", 8, 9, false, "lightGrey", "white")
- draw.box(8, 36, 10, 1, " ", "cyan", "cyan")
- draw.texta("Status:", 8, 12, false, "lightGrey", "white")
- draw.box(8, 36, 13, 1, " ", "cyan", "cyan")
- draw.texta("File Path:", 8, 15, false, "lightGrey", "white")
- draw.box(8, 36, 16, 1, " ", "cyan", "cyan")
- end
- run()
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("Update")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Update", args[3], args[4])
- elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 7) then
- draw.box(1, 51, 7, 1, " ", "white", "white")
- draw.box(8, 36, 7, 1, " ", "cyan", "cyan")
- col.set("white", "cyan")
- term.setCursorPos(8, 7)
- write(": ")
- upd_appid = tostring(read())
- elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 10) then
- draw.box(1, 51, 10, 1, " ", "white", "white")
- draw.box(8, 36, 10, 1, " ", "cyan", "cyan")
- col.set("white", "cyan")
- term.setCursorPos(8, 10)
- write(": ")
- upd_vers = tostring(read(_, discover.data.versions))
- elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 13) then
- draw.box(1, 51, 13, 1, " ", "white", "white")
- draw.box(8, 36, 13, 1, " ", "cyan", "cyan")
- col.set("white", "cyan")
- term.setCursorPos(8, 13)
- write(": ")
- upd_stat = tostring(read(_, {"public", "private"}))
- elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 16) then
- draw.box(1, 51, 16, 1, " ", "white", "white")
- draw.box(8, 36, 16, 1, " ", "cyan", "cyan")
- col.set("white", "cyan")
- term.setCursorPos(8, 16)
- write(": ")
- upd_path = tostring(read(_, discover.data.categories))
- elseif (args[3] >= 45 and args[3] <= 50) and (args[4] == 19) then
- if upd_appid and upd_vers and upd_stat and upd_path then
- if fs.exists(upd_path) then
- local f = fs.open(upd_path, "r")
- local upd_path_content = f.readAll()
- local status = discover:store_update( upd_appid, upd_vers, upd_stat, upd_path_content )
- if status then
- popup.alert("App was updated!")
- sleep(1)
- exit()
- else
- draw.box(1, 51, 18, 1, " ", "white", "white")
- draw.textc(discover.data.errormsg, 18, false, "red", "white")
- sleep(1.2)
- draw.box(1, 51, 18, 1, " ", "white", "white")
- end
- else
- draw.box(1, 51, 18, 1, " ", "white", "white")
- draw.textc("No file found in the given path", 18, false, "red", "white")
- sleep(0.8)
- draw.box(1, 51, 18, 1, " ", "white", "white")
- end
- else
- draw.box(1, 51, 18, 1, " ", "white", "white")
- draw.textc("Please fill out all fields", 18, false, "red", "white")
- sleep(0.8)
- draw.box(1, 51, 18, 1, " ", "white", "white")
- end
- elseif (args[3] >= 2 and args[3] <= 7) and (args[4] == 19) then
- exit()
- end
- end
- end
- end
- function store.account.edit()
- local appid = temp.edit_appid
- if not appid then
- popup.alert("No App ID Supplied")
- sleep(1.5)
- thread:remove("Edit")
- if not thread:find("Account") then
- thread:create("Account", store.account.home)
- end
- thread:switch("Account")
- end
- col.screen("white")
- store.draw.menu("Edit")
- draw.box(1, 51, 19, 1, " ", "grey", "grey")
- draw.textl(" Cancel ", 19, false, "orange", "grey")
- draw.textr("Edit ", 19, false, "lightBlue", "grey")
- local function run(scroll)
- draw.texta("App Name:", 8, 4, false, "lightGrey", "white")
- draw.box(8, 36, 5, 1, " ", "cyan", "cyan")
- draw.texta("Description:", 8, 7, false, "lightGrey", "white")
- draw.box(8, 36, 8, 1, " ", "cyan", "cyan")
- draw.texta("Version:", 8, 10, false, "lightGrey", "white")
- draw.box(8, 36, 11, 1, " ", "cyan", "cyan")
- draw.texta("Category:", 8, 13, false, "lightGrey", "white")
- draw.box(8, 36, 14, 1, " ", "cyan", "cyan")
- draw.texta("Status:", 8, 16, false, "lightGrey", "white")
- draw.box(8, 36, 17, 1, " ", "cyan", "cyan")
- end
- run(scroll)
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("Edit")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Edit", args[3], args[4])
- elseif (args[3] >= 2 and args[3] <= 7) and (args[4] == 19) then
- if not thread:find("MyApps") then
- thread:create("MyApps", store.account.home)
- end
- thread:remove("Edit")
- thread:switch("MyApps")
- elseif (args[3] >= 47 and args[3] <= 50) and (args[4] == 19) then
- local status = discover:store_edit( appid, edit_name, edit_desc, edit_vers, edit_cate, edit_stat )
- if status then
- popup.alert("Edited!")
- sleep(0.5)
- if not thread:find("MyApps") then
- thread:create("MyApps", store.account.home)
- end
- thread:remove("Edit")
- thread:switch("MyApps")
- else
- popup.alert(discover.data.errormsg)
- sleep(1.2)
- if not thread:find("MyApps") then
- thread:create("MyApps", store.account.home)
- end
- thread:remove("Edit")
- thread:switch("MyApps")
- end
- elseif (args[3] >= 8 and args[3] <= 47) and (args[4] == 5) then
- draw.box(8, 36, 5, 1, " ", "cyan", "cyan")
- col.set("white", "cyan")
- term.setCursorPos(8, 5)
- write(": ")
- edit_name = tostring(read())
- elseif (args[3] >= 8 and args[3] <= 47) and (args[4] == 8) then
- draw.box(8, 36, 8, 1, " ", "cyan", "cyan")
- col.set("white", "cyan")
- term.setCursorPos(8, 8)
- write(": ")
- edit_desc = tostring(read())
- elseif (args[3] >= 8 and args[3] <= 47) and (args[4] == 11) then
- draw.box(8, 36, 11, 1, " ", "cyan", "cyan")
- col.set("white", "cyan")
- term.setCursorPos(8, 11)
- write(": ")
- edit_vers = tostring(read(_, discover.data.versions))
- elseif (args[3] >= 8 and args[3] <= 47) and (args[4] == 14) then
- draw.box(8, 36, 14, 1, " ", "cyan", "cyan")
- col.set("white", "cyan")
- term.setCursorPos(8, 14)
- write(": ")
- edit_cate = tostring(read(_, discover.data.categories))
- elseif (args[3] >= 8 and args[3] <= 47) and (args[4] == 17) then
- draw.box(8, 36, 17, 1, " ", "cyan", "cyan")
- col.set("white", "cyan")
- term.setCursorPos(8, 17)
- write(": ")
- edit_stat = tostring(read(_, {"public", "private"}))
- end
- end
- end
- end
- function store.account.stats()
- col.screen("white")
- store.draw.menu("My Statistics")
- local apps = discover.data.apps
- local ndata = {
- apps = 0;
- downloads = 0;
- myapps = {};
- }
- local function getstats()
- draw.textc("Processing...", 9, false, "grey", "white")
- sleep(0.5)
- for k,v in ipairs(apps) do
- if v.creator == discover.data.username then
- ndata.apps = ndata.apps + 1
- ndata.downloads = ndata.downloads + tonumber(v.downloads)
- ndata.myapps[#ndata.myapps+1] = v
- end
- end
- draw.box(1, 51, 9, 1, " ", "white", "white")
- end
- local function run()
- local text = "This is your stats page which will mainly show your counters for downloads, and uploads. For app controls, uploading and download etc, then please go to my account."
- for k,v in ipairs(data.wordwrap(text, 51)) do
- draw.texta(v, 1, k+3, false, "grey", "white")
- end
- draw.textl(" Uploaded Apps: "..tostring(ndata.apps), 10, false, "grey", "white")
- draw.textl(" Total Downloads: "..tostring(ndata.downloads), 12, false, "grey", "white")
- end
- getstats()
- run()
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("My Statistics")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Settings (System)", args[3], args[4])
- end
- end
- end
- end
- function store.settings(screen)
- local function clears()
- for i=1, 51 do
- if i >= 1 and i <= 20 then
- draw.box(i, 1, 3, 17, " ", "lightGrey", "lightGrey")
- end
- if i>= 21 and i <= 51 then
- draw.box(i, 1, 3, 17, " ", "white", "white")
- end
- end
- draw.box(1, 51, 19, 1, " ", "grey", "grey")
- end
- if not screen then
- screen = ""
- end
- local function draw_menu()
- draw.box(2, 18, 4, 1, " ", "orange", "orange")
- draw.box(2, 18, 6, 1, " ", "orange", "orange")
- draw.box(2, 18, 8, 1, " ", "orange", "orange")
- draw.texta("Main Menu", 3, 4, false, "white", "orange")
- draw.texta("System Settings", 3, 6, false, "white", "orange")
- draw.texta("Discover Details", 3, 8, false, "white", "orange")
- if screen == "System" then
- draw.box(2, 18, 6, 1, " ", "red", "red")
- draw.texta("System Settings", 3, 6, false, "white", "red")
- elseif screen == "Details" then
- draw.box(2, 18, 8, 1, " ", "red", "red")
- draw.texta("Discover Details", 3, 8, false, "white", "red")
- else
- draw.box(2, 18, 4, 1, " ", "red", "red")
- draw.texta("Main Menu", 3, 4, false, "white", "red")
- end
- end
- if screen == "System" then
- -- System
- local scroll = 0
- clears()
- store.draw.menu("Settings (System)")
- draw.box(1, 51, 19, 1, " ", "grey", "grey")
- draw.textr("Scroll Enabled ", 19, false, "orange", "grey")
- local function run(scroll)
- draw.textr("----------------------------- ", 4, false, "lightGrey", "white")
- draw.texta("Toggle config storage:", 22, 5, false, "grey", "white")
- draw.box(22, 29, 7, 1, " ", "white", "white")
- draw.texta("Status:", 22, 7, false, "grey", "white")
- if system.storeconfig then
- draw.texta("Enabled", 30, 7, false, "cyan", "white")
- new = {}
- new.username = discover.data.username
- new.password = discover.data.password
- new.storeconfig = system.storeconfig
- new.plugins = system.plugins
- new.authkey = discover.data.authkey
- dat = textutils.serialize(new)
- local f = fs.open(system.paths.config, "w")
- f.write(basesf.encode(dat))
- f.close()
- else
- draw.texta("Disabled", 30, 7, false, "red", "white")
- fs.delete(system.paths.config)
- end
- draw.textr("----------------------------- ", 8, false, "lightGrey", "white")
- draw.texta("Toggle plugins:", 22, 9, false, "grey", "white")
- draw.box(22, 29, 11, 1, " ", "white", "white")
- draw.texta("Status:", 22, 11, false, "grey", "white")
- if system.plugins then
- draw.texta("Enabled", 30, 11, false, "cyan", "white")
- else
- draw.texta("Disabled", 30, 11, false, "red", "white")
- end
- draw.textr("----------------------------- ", 12, false, "lightGrey", "white")
- draw.texta("Toggle program lock:", 22, 13, false, "grey", "white")
- draw.box(22, 29, 15, 1, " ", "white", "white")
- draw.texta("Status:", 22, 15, false, "grey", "white")
- if system.lock_program then
- draw.texta("Enabled", 30, 15, false, "cyan", "white")
- else
- draw.texta("Disabled", 30, 15, false, "red", "white")
- end
- draw.textr("----------------------------- ", 16, false, "lightGrey", "white")
- draw.texta(" T ", 48, 6, false, "white", "orange")
- draw.texta(" T ", 48, 10, false, "white", "orange")
- draw.texta(" T ", 48, 14, false, "white", "orange")
- end
- draw_menu()
- run(scroll)
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("Settings (System)")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Settings (System)", args[3], args[4])
- elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 4 then
- store.settings()
- elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 6 then
- store.settings("System")
- elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 8 then
- store.settings("Details")
- elseif (args[3] >= 48 and args[3] <= 50) and (args[4] == 6) then
- if system.storeconfig then
- system.storeconfig = false
- else
- system.storeconfig = true
- end
- run(scroll)
- elseif (args[3] >= 48 and args[3] <= 50) and (args[4] == 10) then
- if system.plugins then
- system.plugins = false
- else
- system.plugins = true
- end
- run(scroll)
- elseif (args[3] >= 48 and args[3] <= 50) and (args[4] == 14) then
- if system.lock_program then
- system.lock_program = false
- else
- system.lock_program = true
- end
- run(scroll)
- end
- end
- end
- elseif screen == "Details" then
- -- Details
- local scroll = 0
- clears()
- store.draw.menu("Settings (Discover Details)")
- draw.box(1, 51, 19, 1, " ", "grey", "grey")
- draw.textr("Scroll Enabled ", 19, false, "orange", "grey")
- local function run(scroll)
- draw.textr("----------------------------- ", 4, false, "lightGrey", "white")
- draw.texta("Discover API Version:", 22, 5, false, "grey", "white")
- draw.texta(tostring(discover:get("version_api")), 22, 7, false, "cyan", "white")
- draw.textr("----------------------------- ", 8, false, "lightGrey", "white")
- draw.texta("Discover System Version:", 22, 9, false, "grey", "white")
- draw.texta(tostring(discover:get("version")), 22, 11, false, "cyan", "white")
- draw.textr("----------------------------- ", 12, false, "lightGrey", "white")
- end
- draw_menu()
- run(scroll)
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("Settings (Discover Details)")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Settings (Menu)", args[3], args[4])
- elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 4 then
- store.settings()
- elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 6 then
- store.settings("System")
- elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 8 then
- store.settings("Details")
- end
- end
- end
- else
- -- Home
- col.screen("white")
- local scroll = 0
- store.draw.menu("Settings (Menu)")
- clears()
- draw.textr("Scroll Enabled ", 19, false, "orange", "grey")
- local function run(scoll)
- local text = "This is the settings menu, please choose a sub-category to see the available options. Some options are for use on servers and for custom App Stores, please see Discover API: Store Documentation for more information. The options are on the left side (orange buttons), and please note that the right side of the screen (in white) is scrollable."
- tText = data.wordwrap(text, 29)
- for i=1, 14 do
- if #tText >= i + scroll then
- draw.box(21, 30, i+3, 1, " ", "white", "white")
- draw.texta(tText[i+scroll], 22, i+3, false, "grey", "white")
- end
- end
- end
- draw_menu()
- run(scroll)
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("Settings (Menu)")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Settings (Menu)", args[3], args[4])
- elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 4 then
- store.settings()
- elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 6 then
- store.settings("System")
- elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 8 then
- store.settings("Details")
- end
- elseif args[1] == "mouse_scroll" then
- if args[2] == -1 then
- if scroll > 0 then
- scroll = scroll - 1
- run(scroll)
- end
- elseif args[2] == 1 then
- if scroll + 14 < #tText then
- scroll = scroll + 1
- run(scroll)
- end
- end
- end
- end
- end
- end
- function store.help(name)
- tData = {
- {
- ["name"] = "How to use the App Store";
- ["content"] = "Using the App Store is super simple. The Store uses a multitasking system with a task bar in the header, so you can have 20 screens open, and use the arrow buttons to switch between the task list, and click what you need. All tasks can be closed with the little \"x\" on the left of them. Most things you need are on the home screen, so if you need to upload an app, then you can simply click the button, a new thread will open with the content and you can switch back and forth with ease and no problems. Editing apps and updating apps is done in your \"My Account\" as this will display your apps and your details, all apps will have buttons by the side of their name (if you have permissions) to edit them. Statistics are simply a list of your downloads, comments and your best submitted apps.";
- };
- {
- ["name"] = "Discover API System";
- ["content"] = "Discover API System is the newest design I have made which combines a more secure approach at using the database, this is because the old API is going down due to it being abused so now this new version supports rate limiting, so you can not send a certain amount of requests in a time limit, you follow auth keys which expire and make it even more secure. You can learn to use it by going here: \"https://discover.dannysmc.com/\", thanks for reading.";
- };
- {
- ["name"] = "Store Settings";
- ["content"] = "Settings are simply a list of all your settings that are stored, so this can be what is stored against your file, so if you want to store your username and password, or just your authkey or even cache the Apps, Versions, and Categories lists. As well as the option to allow background processes to run, like auto-update and more.";
- };
- {
- ["name"] = "Store Statistics";
- ["content"] = "You can see the Statistics of your account and the Store, so you can see how many users, apps, comments, and downloads (total), as well as your personal amount. This also allows you to see how well you are doing and your position on the Discover System.";
- };
- {
- ["name"] = "Uploading/Downloading/Editing/Updating Apps";
- ["content"] = "Uploading apps is super easy using the drop downs for categories and versioning. We always suggest following the proper versioning system, but of course most users like to make their own. Downloading apps is now done via PHP instead of from a URL, this is to ensure you follow the download rules so we can log downloads. Editing and Updating are as simple as editing updating code for apps.";
- };
- {
- ["name"] = "Discover API Account";
- ["content"] = "A user account on Discover is super simple, we use an oAuth based system to allow API's to access your SocialNet system and App Store data. This is not mainly used but will be used for external applications wanting access to your details. You can revert this online using the Discover Systems Website (This is still under production.";
- };
- {
- ["name"] = "How do plugins work?";
- ["content"] = "If you found a function that is faulty or has broken, we allow you to rewrite code with the use of plugins. A plugin is loaded upon system startup which means you can use a plugin to add or remove functionality. An example would be that you want to add support for only allowing downloading programs and then sending them to a computer via rednet etc, then you can overwrite a function by just writing the same function and amending it how you need. This means you can extend it\'s functionality massively, by adding more functions. Of course if you wish to add more options then you will have to use my API, which is already loaded.";
- };
- {
- ["name"] = "What do you mean \"new api\"?";
- ["content"] = "Well if you follow the App Store's Development you will know that I stopped updating a month ago (or more), and this was to stop and re-develop the Store System, making it easier to use and to contain a whole new set of functions I had learnt while being at my current place of work. The new API introduces tons of the new systems like IP Blocking, Account Blocking, Rate limiting, and spam protection.";
- };
- {
- ["name"] = "How can I get involved?";
- ["content"] = "Well if you are genuinely interested in getting involved and helping development with your own ideas and coding skills then you are very welcome, I would love to be able to get players to join in and help build this into something, as the way the system works is super simple and easy to work with. Even with coroutines being used and a simple manager, all coroutines have their own buffer and will be inserted into the task manager as soon as they are created. Then resuming them is all built into the API.";
- };
- }
- if name:sub(1,7) == "content" then
- local scroll = 0
- conid = tonumber(name:sub(8))
- col.screen("white")
- store.draw.menu("Help / FAQ")
- draw.box(1, 51, 19, 1, " ", "grey", "grey")
- draw.texta("Back", 2, 19, false, "lightBlue", "grey")
- draw.textr("Scroll enabled ", 19, false, "orange", "grey")
- pagecontent = data.wordwrap(tData[conid].content, 49)
- local function run(scroll)
- for i=1, 14 do
- if #pagecontent >= i + scroll then
- draw.box(1, 51, i+3, 1, " ", "white", "white")
- draw.textl(pagecontent[i+scroll], i+3, false, "cyan", "white")
- else
- break
- end
- end
- end
- run(scroll)
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("Help / FAQ")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Help / FAQ", args[3], args[4])
- elseif (args[3] >= 2 and args[3] <= 5) and args[4] == 19 then
- store.help("menu")
- end
- elseif args[1] == "mouse_scroll" then
- if args[2] == -1 then
- if scroll > 0 then
- scroll = scroll - 1
- run(scroll)
- end
- elseif args[2] == 1 then
- if scroll + 14 < #pagecontent then
- scroll = scroll + 1
- run(scroll)
- end
- end
- end
- end
- else
- local scroll = 0
- col.screen("white")
- store.draw.menu("Help / FAQ")
- draw.box(1, 51, 19, 1, " ", "grey", "grey")
- draw.textc("Help Topics: "..tostring(#tData), 19, false, "lightBlue", "grey")
- local function fix(num)
- if tostring(num):len() == 1 then
- return " "..tostring(num)
- else
- return tostring(num)
- end
- end
- local function run(scroll)
- for i=1, 14 do
- if #tData >= i + scroll then
- draw.texta(tostring(fix(i+scroll)) .. ": " .. tData[i+scroll].name, 1, i+3, false, "cyan", "white")
- else
- break
- end
- end
- end
- run(scroll)
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("Help / FAQ")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Help / FAQ", args[3], args[4])
- elseif (args[3] >= 1 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 19) then
- -- Get current option
- local curid = args[4] - 3 + scroll
- if curid <= #tData then
- store.help("content"..tostring(curid))
- end
- end
- elseif args[1] == "mouse_scroll" then
- if args[2] == -1 then
- if scroll > 0 then
- scroll = scroll - 1
- run(scroll)
- end
- elseif args[2] == 1 then
- if scroll + 14 < #tData then
- scroll = scroll + 1
- run(scroll)
- end
- end
- end
- end
- end
- end
- function store.updates(name)
- tData = {
- {
- ["name"] = "Update: 4.1.4 (Beta)";
- ["content"] = "Fixed a few bugs, like Help / FAQ and Updates screens where there was problems with clickable regions. Fixed the inability to scroll up on certain emulators on the Versions and Categories screens, not sure why, just coded it a little more bullet proof. Added up new account screens, removed user settings because it was a waste of a button.";
- };
- {
- ["name"] = "Update: 4.1.1 (Beta)";
- ["content"] = "Currently the recent release, this is where everything was coded and functioning this is for all of the great store users to be able to test the Store, and tell me what they think, and give useful feedback, in the settings menu you can actually submit bugs, and review what you think of the Discover Store, and the new name. Also do you like the new API, this was built with security and ease in one.";
- };
- {
- ["name"] = "Update: 4.0.1 (Alpha)";
- ["content"] = "This update was the very first version of the new re-coded store App, this had all the correct versions of the new DiscoverAPI. This was coded without multitasking, but with the new system and the way the Store would function I felt it would be better to incorporate the new Thread System. The new threads manager harnesses ComputerCraft's alternative to multitasking allowing multiple threads, with little or no problem, and the new task manager I added to be able to flick through tasks with ease.";
- };
- }
- if name:sub(1,7) == "content" then
- local scroll = 0
- conid = tonumber(name:sub(8))
- col.screen("white")
- store.draw.menu("Updates Log")
- draw.box(1, 51, 19, 1, " ", "grey", "grey")
- draw.texta("Back", 2, 19, false, "lightBlue", "grey")
- draw.textr("Scroll enabled ", 19, false, "orange", "grey")
- pagecontent = data.wordwrap(tData[conid].content, 49)
- local function run(scroll)
- for i=1, 14 do
- if #pagecontent >= i + scroll then
- draw.box(1, 51, i+3, 1, " ", "white", "white")
- draw.textl(pagecontent[i+scroll], i+3, false, "cyan", "white")
- else
- break
- end
- end
- end
- run(scroll)
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("Updates Log")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Updates Log", args[3], args[4])
- elseif (args[3] >= 2 and args[3] <= 5) and args[4] == 19 then
- store.updates("menu")
- end
- elseif args[1] == "mouse_scroll" then
- if args[2] == -1 then
- if scroll > 0 then
- scroll = scroll - 1
- run(scroll)
- end
- elseif args[2] == 1 then
- if scroll + 14 < #pagecontent then
- scroll = scroll + 1
- run(scroll)
- end
- end
- end
- end
- else
- local scroll = 0
- col.screen("white")
- store.draw.menu("Updates Log")
- draw.box(1, 51, 19, 1, " ", "grey", "grey")
- draw.textc("Update Logs: "..tostring(#tData), 19, false, "lightBlue", "grey")
- local function fix(num)
- if tostring(num):len() == 1 then
- return " "..tostring(num)
- else
- return tostring(num)
- end
- end
- local function run(scroll)
- for i=1, 14 do
- if #tData >= i + scroll then
- draw.texta(tostring(fix(i+scroll)) .. ": " .. tData[i+scroll].name, 1, i+3, false, "cyan", "white")
- else
- break
- end
- end
- end
- run(scroll)
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("Updates Log")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Help / FAQ", args[3], args[4])
- elseif (args[3] >= 1 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 19) then
- -- Get current option
- local curid = args[4] - 3 + scroll
- if curid <= #tData then
- store.updates("content"..tostring(curid))
- end
- end
- elseif args[1] == "mouse_scroll" then
- if args[2] == -1 then
- if scroll > 0 then
- scroll = scroll - 1
- run(scroll)
- end
- elseif args[2] == 1 then
- if scroll + 14 < #tData then
- scroll = scroll + 1
- run(scroll)
- end
- end
- end
- end
- end
- end
- function store.credits()
- col.screen("white")
- store.draw.menu("Credits")
- local text = "I just wanted to say a big thank you to everyone who has helped keep the App Store alive, through name changes and updates, you have kept uploading apps, and this makes me happy! This new Store is my last API update I shall be giving, due to the API being moved over to DiscoverAPI (Which I built in PHP). All it is, is just a overly modified version of CCSystems, with tons of new functions to help stop database spamming, and more security on your account. Plus the use of oAuth :D."
- for k,v in ipairs(data.wordwrap(text, 51)) do
- draw.textl(v, k+3, false, "grey", "white")
- end
- draw.box(1, 51, 19, 1, " ", "grey" , "grey")
- draw.textc("Press the \"X\" in the taskbar to close", 19, false, "orange", "grey")
- while true do
- local args = { os.pullEvent() }
- if args[1] == "timer" then
- store.draw.menu("Credits")
- elseif args[1] == "mouse_click" then
- if args[4] >= 1 and args[4] <= 2 then
- store.draw.menu_input("Home", args[3], args[4])
- end
- end
- end
- end
- -- Run Discover Init
- if downloadapi then
- store.init()
- else
- print("Discover Crashed")
- sleep(2)
- shell.run("shell")
- end
- term.clear()
- term.setCursorPos(1, 1)
Add Comment
Please, Sign In to add comment