Guest User

Untitled

a guest
Jan 3rd, 2018
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 87.46 KB | None | 0 0
  1. --[[
  2. Name: Discover App Store
  3. Author: DannySMc (dannysmc95)
  4. Requirements: HTTP, Colour, Whitelist dannysmc.com/ in the HTTP config.
  5. ]]
  6.  
  7. -- Set variables
  8. os.getEvent = os.pullEvent
  9. os.pullEvent = os.pullEventRaw
  10.  
  11. local system = {
  12. ["name"] = "Discover Store";
  13. ["auth"] = "DannySMc (dannysmc95)";
  14. ["paths"] = {
  15. ["config"] = ".DiscoverConfig";
  16. ["plugins"] = "/DPlugins/";
  17. };
  18. ["plugins"] = true;
  19. ["storeconfig"] = true;
  20. ["lock_program"] = false;
  21. ["storeuser"] = false;
  22. }
  23.  
  24. -- Used for applications to send data between each other
  25. local temp = {}
  26.  
  27. local side_scroll = 0
  28. local viewapps = {}
  29.  
  30.  
  31.  
  32. -- Create Discover Object
  33. discover = {
  34. data = {
  35. username = nil;
  36. password = nil;
  37. authkey = nil;
  38. errormsg = nil;
  39. cmessage = nil;
  40. loggedin = false;
  41. urls = {
  42. user = "https://api.dannysmc.com/user.php";
  43. store = "https://api.dannysmc.com/store.php";
  44. projects = "https://api.dannysmc.com/projects.php";
  45. };
  46. apps = {};
  47. versions = {};
  48. categories = {};
  49. version = "4.2";
  50. build = "12";
  51. version_api = "2.2.12:116";
  52. newupdate = nil;
  53. };
  54. -- Project Check
  55. get_update = function( self )
  56. local uniqueid = "db613a9197c76e8f0fd61cd67547920a3805ee380aabee241298d3379c7c0dcddc0b5c411ee393615f142f750e8bfdc349720782a4d07cde4e083147a4149d20"
  57. local query = "command=check_update&uniqueid="..textutils.urlEncode(tostring(uniqueid)).."&version="..textutils.urlEncode(tostring(self.data.version))
  58. local req = http.post(self.data.urls.projects, query)
  59. req = textutils.unserialize(req.readAll())
  60. if req.status then
  61. local url = req.url
  62.  
  63. local dat = http.post(url)
  64. self.data.newupdate = dat.readAll()
  65.  
  66. return true
  67. else
  68. return false
  69. end
  70. end;
  71. -- Set Username and Password
  72. set = function( self, username, password )
  73. self.data.username = username
  74. self.data.password = crypt.sha256(password)
  75. return true
  76. end;
  77. -- Get function to return a certain bit of information
  78. get = function ( self, name )
  79. return self.data[name]
  80. end;
  81. -- Main login function to get authkey
  82. login = function( self, username, password )
  83. if username then
  84. self.data.username = username
  85. end
  86. if password then
  87. self.data.password = password
  88. end
  89. if self.data.username and self.data.password then
  90. local query = "cmd=login&username="..textutils.urlEncode(tostring(self.data.username)).."&password="..textutils.urlEncode(tostring(self.data.password))
  91. local res = http.post(self.data.urls.user, query)
  92. res = textutils.unserialize(res.readAll())
  93. if res.status == true then
  94. self.data.authkey = res.authkey
  95. self.data.loggedin = true;
  96. return true
  97. elseif res.status == false then
  98. self.data.errormsg = res.error
  99. return false
  100. end
  101. else
  102. return false
  103. end
  104. end;
  105. -- Registration
  106. register = function( self, username, password, email )
  107. if username and password and email then
  108. local query = "cmd=register&username="..textutils.urlEncode(tostring(username)).."&password="..textutils.urlEncode(tostring(password)).."&email="..textutils.urlEncode(tostring(email))
  109. local req = http.post(self.data.urls.user, query)
  110. req = textutils.unserialize(req.readAll())
  111. if req.status then
  112. self.data.cmessage = tostring(req.message)
  113. return true
  114. else
  115. self.data.errormsg = req.error
  116. return false
  117. end
  118. else
  119. self.data.errormsg = "Please supply a username, password and email!"
  120. return false
  121. end
  122. end;
  123. -- Log out user
  124. logout = function( self )
  125. local req = http.post(self.data.urls.user, "cmd=logout&authkey="..textutils.urlEncode(tostring(self.data.authkey)))
  126. req = textutils.unserialize(req.readAll())
  127. if req.status then
  128. discover.data.loggedin = false
  129. discover.data.username = nil
  130. discover.data.password = nil
  131. discover.data.authkey = nil
  132. self.data.cmessage = req.message
  133. return true
  134. else
  135. self.data.errormsg = req.error
  136. return false
  137. end
  138. end;
  139. -- Check if a authkey is still valid
  140. validate = function( self )
  141. if self.data.authkey then
  142. local query = "cmd=validate&authkey="..textutils.urlEncode(tostring(self.data.authkey))
  143. local res = http.post(self.data.urls.user, query)
  144. res = textutils.unserialize(res.readAll())
  145. if res.status == true then
  146. self.data.cmessage = res.message
  147. self.data.loggedin = true;
  148. return true
  149. elseif res.status == false then
  150. self.data.errormsg = res.error
  151. return false
  152. end
  153. else
  154. return false
  155. end
  156. end;
  157. store_init = function( self )
  158. local ret = http.post(self.data.urls.store, "cmd=list_apps")
  159. ret = textutils.unserialize(ret.readAll())
  160. if ret.status == true then
  161. self.data.apps = ret.data
  162. else
  163. return false
  164. end
  165.  
  166. local ret = http.post(self.data.urls.store, "cmd=list_categories")
  167. ret = textutils.unserialize(ret.readAll())
  168. if ret.status == true then
  169. self.data.categories = ret.data
  170. else
  171. return false
  172. end
  173.  
  174. local ret = http.post(self.data.urls.store, "cmd=list_versions")
  175. ret = textutils.unserialize(ret.readAll())
  176. if ret.status == true then
  177. self.data.versions = ret.data
  178. else
  179. return false
  180. end
  181.  
  182. return true
  183. end;
  184. store_comments_get = function( self, appid )
  185. local query = "cmd=view_comments&appid="..textutils.urlEncode(tostring(appid))
  186. local req = http.post(self.data.urls.store, query)
  187. req = textutils.unserialize(req.readAll())
  188. if req.status == true then
  189. discover.data.cmessage = "Successful"
  190. discover.data.comments = req.data
  191. return true
  192. else
  193. discover.data.errormsg = req.error
  194. return false
  195. end
  196. end;
  197. store_comments_set = function( self, appid, comment )
  198. local query = "cmd=add_comment&appid="..textutils.urlEncode(tostring(appid)).."&comment="..textutils.urlEncode(tostring(comment))
  199. local req = http.post(self.data.urls.store, query)
  200. req = textutils.unserialize(req.readAll())
  201. if req.status then
  202. self.data.cmessage = req.message
  203. return true
  204. else
  205. self.data.errormsg = req.error
  206. return false
  207. end
  208. end;
  209. store_download = function( self, appid )
  210. local query = "cmd=download&appid="..textutils.urlEncode(tostring(appid))
  211. local req = http.post(self.data.urls.store, query)
  212. return req
  213. end;
  214. store_upload = function ( self, appname, appdesc, appcate, appvers, appstat, appdata )
  215. 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))
  216. local req = http.post(self.data.urls.store, query)
  217. local f = fs.open("output.lua", "w")
  218. req = textutils.unserialize(req.readAll())
  219. if req.status then
  220. self.data.cmessage = req.message
  221. return true
  222. else
  223. self.data.errormsg = req.error
  224. return false
  225. end
  226. end;
  227. store_update = function( self, appid, vers, stat, data )
  228. if appid and vers and stat and data then
  229. 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))
  230. local req = http.post(self.data.urls.store, query)
  231. req = textutils.unserialize(req.readAll())
  232. if req.status then
  233. self.data.cmessage = tostring(req.message)
  234. return true
  235. else
  236. self.data.errormsg = req.error
  237. return false
  238. end
  239. else
  240. self.data.errormsg = "Please fill in all fields"
  241. return false
  242. end
  243. end;
  244. store_apps_user = function( self, username )
  245. if not username then
  246. query = "cmd=list_apps_user&authkey="..textutils.urlEncode(tostring(self.data.authkey))
  247. else
  248. query = "cmd=list_apps_user&authkey="..textutils.urlEncode(tostring(self.data.authkey)).."&username="..textutils.urlEncode(tostring(username))
  249. end
  250. local req = http.post(self.data.urls.store, query)
  251. req = textutils.unserialize(req.readAll())
  252. if req.status then
  253. discover.data.appsuser = req.data
  254. return true
  255. else
  256. discover.data.errormsg = req.error
  257. return false
  258. end
  259. end;
  260. store_edit = function( self, appid, name, desc, vers, cate, stat )
  261. if appid and name and desc and vers and stat and cate then
  262. 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))
  263. local req = http.post(self.data.urls.store, query)
  264. req = textutils.unserialize(req.readAll())
  265. if req.status then
  266. self.data.cmessage = tostring(req.message)
  267. return true
  268. else
  269. self.data.errormsg = req.error
  270. return false
  271. end
  272. else
  273. self.data.errormsg = "Please fill in all fields"
  274. return false
  275. end
  276. end;
  277. store_delete = function( self, appid )
  278. if appid then
  279. local query = "cmd=delete&authkey="..textutils.urlEncode(tostring(self.data.authkey)).."&appid="..textutils.urlEncode(tostring(appid))
  280. local req = http.post(self.data.urls.store, query)
  281. req = textutils.unserialize(req.readAll())
  282. if req.status then
  283. self.data.cmessage = tostring(req.message)
  284. return true
  285. else
  286. self.data.errormsg = req.error
  287. return false
  288. end
  289. else
  290. self.data.errormsg = "Please fill in all fields"
  291. return false
  292. end
  293. end;
  294. }
  295.  
  296. -- Get Store API
  297. local downloadapi = false
  298. local nTries = 0
  299. while not downloadapi do
  300. local ok, err = pcall( function()
  301. if http then
  302. aa = aa or {}
  303. local a = http.get("https://api.dannysmc.com/files/apis/progutils.lua")
  304. a = a.readAll()
  305. local env = {}
  306. a = loadstring(a)
  307. local env = getfenv()
  308. setfenv(a,env)
  309. local status, err = pcall(a, unpack(aa))
  310. if (not status) and err then
  311. printError("Error loading api")
  312. return false
  313. end
  314. local returned = err
  315. env = env
  316. _G["progutils"] = env
  317. end
  318. end)
  319. if not ok then
  320. term.clear()
  321. term.setCursorPos(1,1)
  322. print("Download API (Attempt: "..nTries.."/".."5)")
  323. if nTries >= 5 then
  324. shell.run("shell")
  325. end
  326. else
  327. downloadapi = true
  328. end
  329. end
  330.  
  331. -- Set Object Methods (Better naming convention)
  332. store = {}
  333. store.__index = store
  334.  
  335. store.account = {}
  336. store.account.__index = store.account
  337.  
  338. store.apps = {}
  339. store.apps.__index = store.apps
  340.  
  341. store.draw = {}
  342. store.draw.__index = store.draw
  343.  
  344. -- Discover Store Main Code:
  345. function store.draw.menu(screen)
  346. draw.box(1, 51, 1, 2, " ", "grey", "grey")
  347. draw.texta("Discover:", 1, 1, false, "cyan", "grey")
  348. if screen then
  349. draw.texta(screen, 10, 1, false, "white", "grey")
  350. end
  351. draw.textr(misc.time(), 1, false, "lime", "grey")
  352. chars = {2, 12, 22, 32, 42}
  353. for i=1, #chars do
  354. coun = i + side_scroll
  355. if coun > #threads then
  356. break
  357. end
  358. if threads[coun].name == currentThread.name then
  359. draw.texta(" "..threads[coun].name:sub(1, 8).." ", chars[i], 2, false, "blue", "grey")
  360. draw.texta("x", chars[i], 2, false, "red", "grey")
  361. else
  362. draw.texta(" "..threads[coun].name:sub(1,8).." ", chars[i], 2, false, "orange", "grey")
  363. end
  364. end
  365. draw.texta(tostring(#threads), 45, 1, false, "lightBlue", "grey")
  366. if side_scroll == 0 then
  367. draw.texta("<", 1, 2, false, "lightGrey", "grey")
  368. else
  369. draw.texta("<", 1, 2, false, "lightBlue", "grey")
  370. end
  371. if side_scroll + 5 >= #threads then
  372. draw.texta(">", 51, 2, false, "lightGrey", "grey")
  373. else
  374. draw.texta(">", 51, 2, false, "lightBlue", "grey")
  375. end
  376. end
  377.  
  378. function store.draw.menu_input(screen, intx, inty)
  379. if inty == 2 then
  380. -- Check Task Deletion First
  381. if intx == 2 then
  382. if #threads >= side_scroll + 1 then
  383. if threads[1+side_scroll].name == currentThread.name then
  384. -- Remove Thread
  385. thread:remove(threads[1+side_scroll].name)
  386. if not thread:find("Home") then
  387. thread:create("Home", store.home)
  388. end
  389. thread:switch("Home")
  390. return true
  391. end
  392. end
  393. elseif intx == 12 then
  394. if #threads >= side_scroll + 2 then
  395. if threads[2+side_scroll].name == currentThread.name then
  396. -- Remove Thread
  397. thread:remove(threads[2+side_scroll].name)
  398. if not thread:find("Home") then
  399. thread:create("Home", store.home)
  400. end
  401. thread:switch("Home")
  402. return true
  403. end
  404. end
  405. elseif intx == 22 then
  406. if #threads >= side_scroll + 3 then
  407. if threads[3+side_scroll].name == currentThread.name then
  408. -- Remove Thread
  409. thread:remove(threads[3+side_scroll].name)
  410. if not thread:find("Home") then
  411. thread:create("Home", store.home)
  412. end
  413. thread:switch("Home")
  414. return true
  415. end
  416. end
  417. elseif intx == 32 then
  418. if #threads >= side_scroll + 4 then
  419. if threads[4+side_scroll].name == currentThread.name then
  420. -- Remove Thread
  421. thread:remove(threads[4+side_scroll].name)
  422. if not thread:find("Home") then
  423. thread:create("Home", store.home)
  424. end
  425. thread:switch("Home")
  426. return true
  427. end
  428. end
  429. elseif intx == 42 then
  430. if #threads >= side_scroll + 5 then
  431. if threads[5+side_scroll].name == currentThread.name then
  432. -- Remove Thread
  433. thread:remove(threads[5+side_scroll].name)
  434. if not thread:find("Home") then
  435. thread:create("Home", store.home)
  436. end
  437. thread:switch("Home")
  438. return true
  439. end
  440. end
  441. end
  442.  
  443. -- Task Switching
  444. if intx >= 2 and intx <= 10 then
  445. if #threads >= side_scroll + 1 then
  446. thread:switch(threads[1+side_scroll].name)
  447. store.draw.menu(screen)
  448. end
  449. elseif intx >= 12 and intx <= 20 then
  450. if #threads >= side_scroll + 2 then
  451. thread:switch(threads[2+side_scroll].name)
  452. store.draw.menu(screen)
  453. end
  454. elseif intx >= 22 and intx <= 30 then
  455. if #threads >= side_scroll + 3 then
  456. thread:switch(threads[3+side_scroll].name)
  457. store.draw.menu(screen)
  458. end
  459. elseif intx >= 32 and intx <= 40 then
  460. if #threads >= side_scroll + 4 then
  461. thread:switch(threads[4+side_scroll].name)
  462. store.draw.menu(screen)
  463. end
  464. elseif intx >= 42 and intx <= 50 then
  465. if #threads >= side_scroll + 5 then
  466. thread:switch(threads[5+side_scroll].name)
  467. store.draw.menu(screen)
  468. end
  469. elseif intx == 1 then
  470. if side_scroll > 0 then
  471. side_scroll = side_scroll - 1
  472. store.draw.menu(screen)
  473. end
  474. elseif intx == 51 then
  475. if (side_scroll + 5) < #threads then
  476. side_scroll = side_scroll + 1
  477. store.draw.menu(screen)
  478. end
  479. end
  480. end
  481. end
  482.  
  483. function store.draw.logo(intx, inty)
  484. 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."
  485. for k,v in ipairs(data.wordwrap(text, 41)) do
  486. draw.textc(v, k+3, false, "grey", "white")
  487. end
  488.  
  489. if discover.data.loggedin then
  490. draw.box(2, 24, 9, 1, false, "red", "red")
  491. draw.texta("Log out", 3, 9, false, "white", "red")
  492. else
  493. draw.box(2, 24, 9, 1, false, "cyan", "cyan")
  494. draw.texta("Log In", 3, 9, false, "white", "cyan")
  495. end
  496. draw.box(2, 24, 11, 1, false, "cyan", "cyan")
  497. draw.box(2, 24, 13, 1, false, "cyan", "cyan")
  498. draw.box(2, 24, 15, 1, false, "cyan", "cyan")
  499. draw.box(2, 24, 17, 1, false, "cyan", "cyan")
  500. draw.box(27, 24, 9, 1, false, "cyan", "cyan")
  501. draw.box(27, 24, 11, 1, false, "cyan", "cyan")
  502. draw.box(27, 24, 13, 1, false, "cyan", "cyan")
  503. draw.box(27, 24, 15, 1, false, "cyan", "cyan")
  504. draw.box(27, 24, 17, 1, false, "cyan", "cyan")
  505. draw.texta("All Apps", 3, 11, false, "white", "cyan")
  506. draw.texta("All Versions", 3, 13, false, "white", "cyan")
  507. draw.texta("All Categories", 3, 15, false, "white", "cyan")
  508. draw.texta("My Statistics*", 3, 17, false, "white", "cyan")
  509. draw.texta("My Account*", 28, 9, false, "white", "cyan")
  510. draw.texta("Help / FAQ", 28, 11, false, "white", "cyan")
  511. draw.texta("Update Log", 28, 13, false, "white", "cyan")
  512. draw.texta("Settings", 28, 15, false, "white", "cyan")
  513. draw.texta("Credits", 28, 17, false, "white", "cyan")
  514.  
  515.  
  516. draw.textc("Powered By DiscoverAPI - Created By DannySMc", 19, false, "lightGrey", "white")
  517. end
  518.  
  519. function store.init()
  520.  
  521. col.screen("lightGrey")
  522. draw.textc("Discover Initialisation", 2, false, "white", "lightGrey")
  523. sleep(0.5)
  524.  
  525. draw.box(1, 51, 10, 1, " ", "lightGrey", "lightGrey")
  526. draw.textc("Loading Configurations...", 10, false, "red", "lightGrey")
  527.  
  528. -- Load Configurations
  529. if fs.exists(system.paths.config) then
  530. local f = fs.open(system.paths.config, "r")
  531. local dat = basesf.decode( f.readAll() )
  532. local c = textutils.unserialize( dat )
  533. system.storeconfig = c.storeconfig
  534. system.plugins = c.plugins
  535. system.lock = c.lock
  536. discover.data.username = c.username
  537. discover.data.password = c.password
  538. discover.data.authkey = c.authkey
  539. f.close()
  540. end
  541.  
  542. -- Check for Update
  543. draw.box(1, 51, 10, 1, " ", "lightGrey", "lightGrey")
  544. draw.textc("Checking for update...", 10, false, "red", "lightGrey")
  545. local status = discover:get_update()
  546. if status then
  547. draw.box(1, 51, 10, 1, " ", "lightGrey", "lightGrey")
  548. draw.textc("Update found, please wait...", 10, false, "red", "lightGrey")
  549. sleep(3)
  550. local name = shell.getRunningProgram()
  551. local f = fs.open(name, "w")
  552. f.write(discover.data.newupdate)
  553. f.close()
  554. else
  555. draw.box(1, 51, 10, 1, " ", "lightGrey", "lightGrey")
  556. draw.textc("You are currently running the latest version", 10, false, "red", "lightGrey")
  557. end
  558.  
  559. -- Loading User Settings / Login
  560. if system.storeconfig then
  561. draw.box(1, 51, 10, 1, " ", "lightGrey", "lightGrey")
  562. draw.textc("Attempting to Login...", 10, false, "red", "lightGrey")
  563. local ok = discover:login(discover.data.username, discover.data.password)
  564. if ok then
  565. draw.box(1, 51, 10, 1, " ", "lightGrey", "lightGrey")
  566. draw.textc("You was successfully logged in!", 10, false, "red", "lightGrey")
  567. sleep(0.5)
  568. else
  569. draw.box(1, 51, 10, 1, " ", "lightGrey", "lightGrey")
  570. draw.textc(tostring(discover.data.errormsg), 10, false, "red", "lightGrey")
  571. sleep(1)
  572. end
  573. end
  574.  
  575. -- Unlock Termination if system.lock is false
  576. if not system.lock then
  577. os.pullEvent = os.getEvent
  578. end
  579.  
  580. -- Install System Plugins
  581. if system.plugins then
  582. draw.box(1, 51, 10, 1, " ", "lightGrey", "lightGrey")
  583. draw.textc("Installing Plugins...", 10, false, "red", "lightGrey")
  584.  
  585. local ok, err = pcall(function()
  586.  
  587. -- Plugin Function
  588. local function install(path)
  589. local tLetters = {"a","b","c","d","e","f"}; new = {}
  590. for i=1,4 do table.insert(new, tLetters[math.ceil(math.random(5))]) end
  591. newname = table.concat(new, "")
  592. aa = aa or {}
  593. local a = fs.open(path, "r")
  594. a = a.readAll()
  595. local env = {}
  596. a = loadstring(a)
  597. local env = getfenv()
  598. setfenv(a,env)
  599. local status, err = pcall(a, unpack(aa))
  600. if (not status) and err then
  601. printError("Error loading api")
  602. return false
  603. end
  604. local returned = err
  605. env = env
  606. _G[newname] = env
  607. end
  608.  
  609. -- Get Plugins
  610. if fs.exists(system.paths.plugins) then
  611. local list = fs.list(system.paths.plugins)
  612. for k,v in ipairs(list) do
  613. local path = fs.combine(system.paths.plugins, v)
  614. install(path)
  615. end
  616. end
  617.  
  618. end)
  619. if not ok then
  620. store.crash(err)
  621. end
  622. end
  623.  
  624. -- Start Threads
  625. local ok, err = pcall(function()
  626.  
  627. -- Draw Screen
  628. col.screen("white")
  629. draw.textc("Downloading Store Directory, Please Wait", 9, false, "grey", "white")
  630. sleep(0.5)
  631. discover:store_init()
  632.  
  633. thread:create("Home", store.home)
  634. thread:switch("Home")
  635. thread:run()
  636.  
  637. end)
  638.  
  639. if not ok then
  640. store.crash(err)
  641. end
  642. end
  643.  
  644. function store.crash(errmsg)
  645. col.screen("lightGrey")
  646. draw.box(1, 51, 1, 1, "-", "grey", "lightGrey")
  647. draw.textc("Discover Store has Crashed", 2, false, "grey", "lightGrey")
  648. draw.box(1, 51, 3, 1, "-", "grey", "lightGrey")
  649.  
  650. 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)."
  651. for k,v in ipairs(data.wordwrap(text, 51)) do
  652. draw.textl(v, k+3, false, "white", "lightGrey")
  653. end
  654.  
  655. for k,v in ipairs(data.wordwrap(errmsg, 47)) do
  656. draw.texta(v, 3, k+12, false, "red", "lightGrey")
  657. end
  658.  
  659. draw.textc("- Press \"Enter\" to reboot the computer -", 19, false, "orange", "lightGrey")
  660.  
  661. while true do
  662. local args = { os.pullEvent() }
  663. if args[1] == "key" then
  664. if args[2] == 28 then
  665. popup.alert("Rebooting...")
  666. sleep(1)
  667. os.reboot()
  668. end
  669. end
  670. end
  671. end
  672.  
  673. function store.home()
  674. col.screen("white")
  675. store.draw.menu("Home")
  676. store.draw.logo()
  677.  
  678. while true do
  679. local args = { os.pullEvent() }
  680. if args[1] == "timer" then
  681. store.draw.menu("Home")
  682. elseif args[1] == "mouse_click" then
  683. if args[4] >= 1 and args[4] <= 2 then
  684. store.draw.menu_input("Home", args[3], args[4])
  685. elseif (args[3] >= 2 and args[3] <= 25) and (args[4] == 9) then
  686. if discover.data.loggedin then
  687. store.account.logout()
  688. col.screen("white")
  689. store.draw.menu("Home")
  690. store.draw.logo()
  691. else
  692. store.account.login()
  693. col.screen("white")
  694. store.draw.menu("Home")
  695. store.draw.logo()
  696. end
  697. elseif (args[3] >= 2 and args[3] <= 25) and (args[4] == 11) then
  698. if not thread:find("Apps") then
  699. thread:create("Apps", store.apps.all)
  700. end
  701. thread:switch("Apps")
  702. elseif (args[3] >= 2 and args[3] <= 25) and (args[4] == 13) then
  703. if not thread:find("Versions") then
  704. thread:create("Versions", store.apps.versions)
  705. end
  706. thread:switch("Versions")
  707. elseif (args[3] >= 2 and args[3] <= 25) and (args[4] == 15) then
  708. if not thread:find("Categories") then
  709. thread:create("Categories", store.apps.categories)
  710. end
  711. thread:switch("Categories")
  712. elseif (args[3] >= 2 and args[3] <= 25) and (args[4] == 17) then
  713. if discover.data.loggedin then
  714. if not thread:find("Stats") then
  715. thread:create("Stats", store.account.stats)
  716. end
  717. thread:switch("Stats")
  718. else
  719. popup.alert("Please login")
  720. sleep(1)
  721. col.screen("white")
  722. store.draw.menu("Home")
  723. store.draw.logo()
  724. end
  725. elseif (args[3] >= 27 and args[3] <= 50) and (args[4] == 9) then
  726. if discover.data.loggedin then
  727. if not thread:find("Account") then
  728. thread:create("Account", store.account.home)
  729. end
  730. thread:switch("Account")
  731. else
  732. popup.alert("Please login")
  733. sleep(1)
  734. col.screen("white")
  735. store.draw.menu("Home")
  736. store.draw.logo()
  737. end
  738. elseif (args[3] >= 27 and args[3] <= 50) and (args[4] == 11) then
  739. if not thread:find("Help") then
  740. thread:create("Help", store.help)
  741. end
  742. thread:switch("Help")
  743. elseif (args[3] >= 27 and args[3] <= 50) and (args[4] == 13) then
  744. if not thread:find("Updates") then
  745. thread:create("Updates", store.updates)
  746. end
  747. thread:switch("Updates")
  748. elseif (args[3] >= 27 and args[3] <= 50) and (args[4] == 15) then
  749. if not thread:find("Settings") then
  750. thread:create("Settings", store.settings)
  751. end
  752. thread:switch("Settings")
  753. elseif (args[3] >= 27 and args[3] <= 50) and (args[4] == 17) then
  754. if not thread:find("Credits") then
  755. thread:create("Credits", store.credits)
  756. end
  757. thread:switch("Credits")
  758. end
  759. end
  760. end
  761. end
  762.  
  763. function store.apps.all()
  764. col.screen("white")
  765. store.draw.menu("All Apps")
  766. local scroll = 0
  767. appslist = discover:get("apps")
  768.  
  769. draw.box(1, 51, 19, 1, " ", "grey", "grey")
  770. draw.texta("Total Apps: "..#appslist, 2, 19, false, "lightBlue", "grey")
  771. draw.textr("Scroll Enabled ", 19, false, "orange", "grey")
  772.  
  773. local function fix(num)
  774. if tostring(num):len() == 1 then
  775. return " "..tostring(num)
  776. elseif tostring(num):len() == 2 then
  777. return " "..tostring(num)
  778. else
  779. return tostring(num)
  780. end
  781. end
  782.  
  783. local function run(scroll)
  784. for i = 1, 14 do
  785. if #appslist >= i + scroll then
  786. draw.box(1, 51, i+3, 1, " ", "white", "white")
  787. draw.textl(fix(i+scroll)..": "..appslist[i+scroll].name, i+3, false, "grey", "white")
  788. end
  789. end
  790. end
  791.  
  792. run(scroll)
  793.  
  794. while true do
  795. local args = { os.pullEvent() }
  796. if args[1] == "timer" then
  797. store.draw.menu("All Apps")
  798. elseif args[1] == "mouse_click" then
  799. if args[4] >= 1 and args[4] <= 2 then
  800. store.draw.menu_input("Help / FAQ", args[3], args[4])
  801. elseif (args[3] >= 1 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 17) then
  802. local curid = args[4] - 3 + scroll
  803. local tname = "View"..tostring(appslist[curid].id)
  804. thread:create(tname, store.apps.view)
  805. viewapps[1] = appslist[curid].id
  806. viewapps[2] = appslist
  807. thread:switch(tname)
  808. end
  809. elseif args[1] == "mouse_scroll" then
  810. if args[2] == -1 then
  811. if scroll > 0 then
  812. scroll = scroll - 1
  813. run(scroll)
  814. end
  815. elseif args[2] == 1 then
  816. if scroll + 14 <= #appslist-1 then
  817. scroll = scroll + 1
  818. run(scroll)
  819. end
  820. end
  821. end
  822. end
  823. end
  824.  
  825. function store.apps.versions(version)
  826. col.screen("white")
  827. store.draw.menu("Versions")
  828. draw.box(21, 1, 3, 17, " ", "grey", "grey")
  829. draw.box(1, 51, 19, 1, " ", "grey", "grey")
  830. draw.texta("Total Versions: "..#discover.data.versions, 2, 19, false, "lightBlue", "grey")
  831. draw.textr("SCroll Enabled", 19, false, "orange", "grey")
  832.  
  833. -- Vars
  834. local lscroll = 0
  835. local rscroll = 0
  836. local ldata = discover.data.versions
  837. local rdata = {}
  838. local lselect = ""
  839. local allapps = discover.data.apps
  840.  
  841. local function lrun(lscroll)
  842. for i=1, 14 do
  843. if #ldata >= i + lscroll then
  844. if lselect == ldata[i+lscroll] then
  845. draw.box(1, 19, i+3, 1, " ", "white", "white")
  846. draw.texta(ldata[i+lscroll], 1, i+3, false, "grey", "white")
  847. else
  848. draw.box(1, 19, i+3, 1, " ", "white", "white")
  849. draw.texta(ldata[i+lscroll], 1, i+3, false, "cyan", "white")
  850. end
  851. end
  852. end
  853. end
  854.  
  855. local function rrun(rscroll)
  856. for i=1, 14 do
  857. if #rdata >= i + rscroll then
  858. draw.box(22, 29, i+3, 1, " ", "white", "white")
  859. draw.texta(rdata[i+rscroll].name:sub(1, 25), 23, i+3, false, "grey", "white")
  860. end
  861. end
  862. end
  863.  
  864. lrun(lscroll)
  865. rrun(rscroll)
  866.  
  867. while true do
  868. local args = { os.pullEvent() }
  869. if args[1] == "timer" then
  870. store.draw.menu("Versions")
  871. elseif args[1] == "mouse_click" then
  872. if args[4] >= 1 and args[4] <= 2 then
  873. store.draw.menu_input("Versions", args[3], args[4])
  874. elseif (args[3] >= 1 and args[3] <= 20) and (args[4] >= 4 and args[4] <= 17) then
  875. -- Choose
  876. local cid = args[4] - 3 + lscroll
  877. if #ldata >= cid then
  878. lselect = ldata[cid]
  879. rdata = {}
  880. for k,v in ipairs(allapps) do
  881. if v.version == lselect then
  882. rdata[#rdata+1] = v
  883. end
  884. end
  885. for i=1, 14 do
  886. draw.box(22, 29, i+3, 1, false, "white", "white")
  887. end
  888. rscroll = 0
  889. rrun(rscroll)
  890. lrun(lscroll)
  891. end
  892. elseif (args[3] >= 22 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 17) then
  893. -- View app
  894. local cid = args[4] - 3 + rscroll
  895. if #rdata >= cid then
  896. viewapps[1] = rdata[cid].id
  897. viewapps[2] = discover.data.apps
  898. if not thread:find("View"..tostring(rdata[cid].id)) then
  899. thread:create("View"..tostring(rdata[cid].id), store.apps.view)
  900. end
  901. thread:switch("View"..tostring(rdata[cid].id))
  902. end
  903. end
  904. elseif args[1] == "mouse_scroll" then
  905. if args[2] == -1 then
  906. if (args[3] >= 1 and args[3] <= 20) and (args[4] >= 4 and args[4] <= 17) then
  907. if lscroll > 0 then
  908. lscroll = lscroll - 1
  909. lrun(lscroll)
  910. end
  911. elseif (args[3] >= 22 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 17) then
  912. if rscroll > 0 then
  913. rscroll = rscroll - 1
  914. rrun(rscroll)
  915. end
  916. end
  917. elseif args[2] == 1 then
  918. if (args[3] >= 1 and args[3] <= 20) and (args[4] >= 4 and args[4] <= 17) then
  919. if lscroll + 14 <= #ldata-1 then
  920. lscroll = lscroll + 1
  921. lrun(lscroll)
  922. end
  923. elseif (args[3] >= 22 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 17) then
  924. if rscroll + 14 <= #rdata-1 then
  925. rscroll = rscroll + 1
  926. rrun(rscroll)
  927. end
  928. end
  929. end
  930. end
  931. end
  932. end
  933.  
  934. function store.apps.categories()
  935. col.screen("white")
  936. store.draw.menu("Categories")
  937. draw.box(21, 1, 3, 17, " ", "grey", "grey")
  938. draw.box(1, 51, 19, 1, " ", "grey", "grey")
  939. draw.texta("Total Categories: "..#discover.data.categories, 2, 19, false, "lightBlue", "grey")
  940. draw.textr("SCroll Enabled", 19, false, "orange", "grey")
  941.  
  942. -- Vars
  943. local lscroll = 0
  944. local rscroll = 0
  945. local ldata = discover.data.categories
  946. local rdata = {}
  947. local lselect = ""
  948. local allapps = discover.data.apps
  949.  
  950. local function lrun(lscroll)
  951. for i=1, 14 do
  952. if #ldata >= i + lscroll then
  953. if lselect == ldata[i+lscroll] then
  954. draw.box(1, 19, i+3, 1, " ", "white", "white")
  955. draw.texta(ldata[i+lscroll], 1, i+3, false, "grey", "white")
  956. else
  957. draw.box(1, 19, i+3, 1, " ", "white", "white")
  958. draw.texta(ldata[i+lscroll], 1, i+3, false, "cyan", "white")
  959. end
  960. end
  961. end
  962. end
  963.  
  964. local function rrun(rscroll)
  965. for i=1, 14 do
  966. if #rdata >= i + rscroll then
  967. draw.box(22, 29, i+3, 1, " ", "white", "white")
  968. draw.texta(rdata[i+rscroll].name:sub(1, 25), 23, i+3, false, "grey", "white")
  969. end
  970. end
  971. end
  972.  
  973. lrun(lscroll)
  974. rrun(rscroll)
  975.  
  976. while true do
  977. local args = { os.pullEvent() }
  978. if args[1] == "timer" then
  979. store.draw.menu("Categories")
  980. elseif args[1] == "mouse_click" then
  981. if args[4] >= 1 and args[4] <= 2 then
  982. store.draw.menu_input("Categories", args[3], args[4])
  983. elseif (args[3] >= 1 and args[3] <= 20) and (args[4] >= 4 and args[4] <= 17) then
  984. -- Choose
  985. local cid = args[4] - 3 + lscroll
  986. if #ldata >= cid then
  987. lselect = ldata[cid]
  988. rdata = {}
  989. for k,v in ipairs(allapps) do
  990. if v.category == lselect then
  991. rdata[#rdata+1] = v
  992. end
  993. end
  994. for i=1, 14 do
  995. draw.box(22, 29, i+3, 1, false, "white", "white")
  996. end
  997. rscroll = 0
  998. rrun(rscroll)
  999. lrun(lscroll)
  1000. end
  1001. elseif (args[3] >= 22 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 17) then
  1002. -- View app
  1003. local cid = args[4] - 3 + rscroll
  1004. if #rdata >= cid then
  1005. viewapps[1] = rdata[cid].id
  1006. viewapps[2] = discover.data.apps
  1007. if not thread:find("View"..tostring(rdata[cid].id)) then
  1008. thread:create("View"..tostring(rdata[cid].id), store.apps.view)
  1009. end
  1010. thread:switch("View"..tostring(rdata[cid].id))
  1011. end
  1012. end
  1013. elseif args[1] == "mouse_scroll" then
  1014. if args[2] == -1 then
  1015. if (args[3] >= 1 and args[3] <= 20) and (args[4] >= 4 and args[4] <= 17) then
  1016. if lscroll > 0 then
  1017. lscroll = lscroll - 1
  1018. lrun(lscroll)
  1019. end
  1020. elseif (args[3] >= 22 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 17) then
  1021. if rscroll > 0 then
  1022. rscroll = rscroll - 1
  1023. rrun(rscroll)
  1024. end
  1025. end
  1026. elseif args[2] == 1 then
  1027. if (args[3] >= 1 and args[3] <= 20) and (args[4] >= 4 and args[4] <= 17) then
  1028. if lscroll + 14 <= #ldata-1 then
  1029. lscroll = lscroll + 1
  1030. lrun(lscroll)
  1031. end
  1032. elseif (args[3] >= 22 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 17) then
  1033. if rscroll + 14 <= #rdata-1 then
  1034. rscroll = rscroll + 1
  1035. rrun(rscroll)
  1036. end
  1037. end
  1038. end
  1039. end
  1040. end
  1041. end
  1042.  
  1043. function store.apps.view()
  1044. col.screen("white")
  1045. draw.textc("Loading...", 9, false, "grey", "white")
  1046. local scroll = 0
  1047.  
  1048. local appid = viewapps[1]
  1049. local appslist = viewapps[2]
  1050.  
  1051. for k,v in ipairs(appslist) do
  1052. if tonumber(v.id) == tonumber(appid) then
  1053. apppos = k
  1054. break
  1055. end
  1056. end
  1057.  
  1058. local appdesc = data.wordwrap(appslist[apppos].description, 49)
  1059.  
  1060. col.screen("white")
  1061. store.draw.menu("View App "..tostring(appslist[apppos].id))
  1062. draw.box(1, 51, 19, 1, " ", "grey", "grey")
  1063. draw.texta("Comments", 2, 19, false, "lightBlue", "grey")
  1064.  
  1065. local function drawdesc(scroll)
  1066. for i = 1, 7 do
  1067. if #appdesc >= i + scroll then
  1068. draw.box(1, 51, i+9, 1, " ", "white", "white")
  1069. draw.textl(appdesc[i+scroll], i+9, false, "grey", "white")
  1070. end
  1071. end
  1072. end
  1073.  
  1074. local function run()
  1075. draw.textl("Name (ID):", 4, false, "lightGrey", "white")
  1076. draw.texta(appslist[apppos].name.." ("..appslist[apppos].id..")", 12, 4, false, "grey", "white")
  1077. draw.textl("Category:", 5, false, "lightGrey", "white")
  1078. draw.texta(appslist[apppos].category, 12, 5, false, "grey", "white")
  1079. draw.textl("Version:", 6, false, "lightGrey", "white")
  1080. draw.texta(appslist[apppos].version, 12, 6, false, "grey", "white")
  1081. draw.textl("Creator:", 7, false, "lightGrey", "white")
  1082. draw.texta(appslist[apppos].creator, 12, 7, false, "grey", "white")
  1083. draw.textl("App Hash:", 18, false, "lightGrey", "white")
  1084. draw.texta(appslist[apppos].hash, 11, 18, false, "grey", "white")
  1085. draw.textl("Description", 9, false, "lightGrey", "white")
  1086. draw.textr(appslist[apppos].downloads.." download(s) ", 19, false, "orange", "grey")
  1087. drawdesc(scroll)
  1088. draw.texta(" Download ", 41, 5, false, "white", "cyan")
  1089. draw.texta(" App! ", 41, 6, false, "white", "cyan")
  1090. end
  1091.  
  1092. run()
  1093.  
  1094. while true do
  1095. local args = { os.pullEvent() }
  1096. if args[1] == "timer" then
  1097. store.draw.menu("View App "..tostring(appslist[apppos].id))
  1098. elseif args[1] == "mouse_click" then
  1099. if args[4] >= 1 and args[4] <= 2 then
  1100. store.draw.menu_input("Help / FAQ", args[3], args[4])
  1101. elseif (args[3] >= 41 and args[3] <= 50) and (args[4] >= 5 and args[4] <= 6) then
  1102. temp.download = appslist[apppos].id
  1103. thread:create("Download"..tostring(appslist[apppos].id), store.apps.download)
  1104. thread:switch("Download"..tostring(appslist[apppos].id))
  1105. elseif (args[3] >= 2 and args[3] <= 9) and args[4] == 19 then
  1106. store.apps.comments(appslist[apppos].id)
  1107. col.screen("white")
  1108. store.draw.menu("View App "..tostring(appslist[apppos].id))
  1109. draw.box(1, 51, 19, 1, " ", "grey", "grey")
  1110. draw.texta("Comments", 2, 19, false, "lightBlue", "grey")
  1111. run()
  1112. end
  1113. elseif args[1] == "mouse_scroll" then
  1114. if args[2] == -1 then
  1115. if scroll > 0 then
  1116. scroll = scroll - 1
  1117. run(scroll)
  1118. end
  1119. elseif args[2] == 1 then
  1120. if scroll + 14 <= #appdesc then
  1121. scroll = scroll + 1
  1122. run(scroll)
  1123. end
  1124. end
  1125. end
  1126. end
  1127. end
  1128.  
  1129. function store.apps.comments(appid)
  1130. col.screen("white")
  1131. draw.textc("Download comments...", 9, false, "grey", "white")
  1132. local scroll = 0
  1133. local ok = discover:store_comments_get(appid)
  1134. if not ok then
  1135. viewapps[1] = appid
  1136. store.apps.view()
  1137. end
  1138. comments = discover.data.comments
  1139. col.screen("white")
  1140. store.draw.menu("Comments: "..tostring(appid))
  1141. draw.box(1, 51, 19, 1, " ", "grey", "grey")
  1142. if discover.data.loggedin then
  1143. draw.textl(" Add", 19, false, "lightBlue", "grey")
  1144. end
  1145. draw.textr("Back ", 19, false, "orange", "grey")
  1146.  
  1147. local function run(scroll)
  1148. if #comments == 0 then
  1149. draw.textc("No comments to display", 9, false, "grey", "white")
  1150. end
  1151. for i=1, 14 do
  1152. if #comments >= i + scroll then
  1153. draw.box(1, 51, i+9, 1, " ", "white", "white")
  1154. draw.textl(comments[i+scroll].comment, i+3, false, "grey", "white")
  1155. draw.textr(comments[i+scroll].username, i+3, false, "cyan", "white")
  1156. end
  1157. end
  1158. end
  1159.  
  1160. run(scroll)
  1161. while true do
  1162. local args = { os.pullEvent() }
  1163. if args[1] == "timer" then
  1164. store.draw.menu("Comments: "..tostring(appid))
  1165. elseif args[1] == "mouse_click" then
  1166. if args[4] >= 1 and args[4] <= 2 then
  1167. store.draw.menu_input("Help / FAQ", args[3], args[4])
  1168. elseif (args[3] >= 2 and args[3] <= 4) and (args[4] == 19) then
  1169. if discover.data.loggedin then
  1170. local comment = popup.input("Comment Text:")
  1171. local status = discover:store_comments_set( appid, comment )
  1172. if status then
  1173. popup.alert("Added!")
  1174. sleep(0.5)
  1175. else
  1176. popup.alert("Failed")
  1177. sleep(1)
  1178. end
  1179. col.screen("white")
  1180. draw.textc("Download comments...", 9, false, "grey", "white")
  1181. local scroll = 0
  1182. local ok = discover:store_comments_get(appid)
  1183. if not ok then
  1184. viewapps[1] = appid
  1185. store.apps.view()
  1186. end
  1187. comments = discover.data.comments
  1188. col.screen("white")
  1189. store.draw.menu("Comments: "..tostring(appid))
  1190. draw.box(1, 51, 19, 1, " ", "grey", "grey")
  1191. if discover.data.loggedin then
  1192. draw.textl(" Add", 19, false, "lightBlue", "grey")
  1193. end
  1194. draw.textr("Back ", 19, false, "orange", "grey")
  1195. run(scroll)
  1196. end
  1197. elseif (args[3] >= 47 and args[3] <= 50) and (args[4] == 19) then
  1198. break
  1199. end
  1200. elseif args[1] == "mouse_scroll" then
  1201. if args[2] == -1 then
  1202. if scroll > 0 then
  1203. scroll = scroll - 1
  1204. run(scroll)
  1205. end
  1206. elseif args[2] == 1 then
  1207. if scroll + 14 <= #comments then
  1208. scroll = scroll + 1
  1209. run(scroll)
  1210. end
  1211. end
  1212. end
  1213. end
  1214. end
  1215.  
  1216. function store.account.login()
  1217. col.screen("white")
  1218. store.draw.menu("Login")
  1219. draw.box(1, 51, 19, 1, " ", "grey", "grey")
  1220. draw.textl(" Cancel", 19, false, "orange", "grey")
  1221. draw.textr("Login ", 19, false, "cyan", "grey")
  1222.  
  1223. local function run()
  1224. draw.textc("Discover API Login", 4, false, "grey", "white")
  1225. draw.texta("Username:", 8, 7, false, "lightGrey", "white")
  1226. draw.box(8, 36, 8, 1, " ", "cyan", "cyan")
  1227. draw.texta("Password:", 8, 10, false, "lightGrey", "white")
  1228. draw.box(8, 36, 11, 1, " ", "cyan", "cyan")
  1229. draw.textc("Need an account? Register here!", 14, false, "grey", "white")
  1230. end
  1231.  
  1232. run()
  1233. restart_home = true
  1234.  
  1235. while not discover.data.loggedin or restart_home do
  1236. local args = { os.pullEvent() }
  1237. if args[1] == "timer" then
  1238. store.draw.menu("Login")
  1239. elseif args[1] == "mouse_click" then
  1240. if args[4] >= 1 and args[4] <= 2 then
  1241. store.draw.menu_input("Login", args[3], args[4])
  1242. elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 8) then
  1243. draw.box(8, 36, 8, 1, " ", "cyan", "cyan")
  1244. col.set("white", "cyan")
  1245. term.setCursorPos(8, 8)
  1246. write(": ")
  1247. username = tostring(read())
  1248. elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 11) then
  1249. draw.box(8, 36, 11, 1, " ", "cyan", "cyan")
  1250. col.set("white", "cyan")
  1251. term.setCursorPos(8, 11)
  1252. write(": ")
  1253. password = tostring(read("*"))
  1254. password = crypt.sha256(password)
  1255. elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 14) then
  1256. store.account.register()
  1257. elseif (args[3] >= 2 and args[3] <= 10) and (args[4] == 19) then
  1258. break
  1259. elseif (args[3] >= 46 and args[3] <= 50) and (args[4] == 19) then
  1260. if username and password then
  1261. draw.textc("Requesting Authentication, Please Wait", 17, false, "lightGrey", "white")
  1262. if discover:login(username, password) then
  1263. discover.data.loggedin = true
  1264. popup.alert("Logged In!")
  1265. if system.storeconfig then
  1266. new = {}
  1267. new.username = discover.data.username
  1268. new.password = discover.data.password
  1269. new.storeconfig = system.storeconfig
  1270. new.plugins = system.plugins
  1271. new.authkey = discover.data.authkey
  1272. dat = textutils.serialize(new)
  1273. local f = fs.open(system.paths.config, "w")
  1274. f.write(basesf.encode(dat))
  1275. f.close()
  1276. end
  1277. sleep(0.8)
  1278. store.home()
  1279. else
  1280. draw.box(1, 51, 17, 1, " ", "white", "white")
  1281. draw.textc(tostring(discover.data.errormsg), 17, false, "lightGrey", "white")
  1282. sleep(1)
  1283. store.home()
  1284. end
  1285. else
  1286. draw.textc("Please fill in the fields", 17, false, "lightGrey", "white")
  1287. end
  1288. end
  1289. end
  1290. end
  1291. end
  1292.  
  1293. function store.account.register()
  1294. col.screen("white")
  1295. store.draw.menu("Login")
  1296. draw.box(1, 51, 19, 1, " ", "grey", "grey")
  1297. draw.textl(" Cancel", 19, false, "orange", "grey")
  1298. draw.textr("Register ", 19, false, "cyan", "grey")
  1299.  
  1300. local function run()
  1301. draw.textc("Discover API Registration", 4, false, "grey", "white")
  1302. draw.texta("Username:", 8, 7, false, "lightGrey", "white")
  1303. draw.box(8, 36, 8, 1, " ", "cyan", "cyan")
  1304. draw.texta("Password:", 8, 10, false, "lightGrey", "white")
  1305. draw.box(8, 36, 11, 1, " ", "cyan", "cyan")
  1306. draw.texta("Email:", 8, 13, false, "lightGrey", "white")
  1307. draw.box(8, 36, 14, 1, " ", "cyan", "cyan")
  1308. draw.textc("Have an account? Login here!", 17, false, "grey", "white")
  1309. end
  1310.  
  1311. run()
  1312. restart_home = true
  1313.  
  1314. while not discover.data.loggedin or restart_home do
  1315. local args = { os.pullEvent() }
  1316. if args[1] == "timer" then
  1317. store.draw.menu("Login")
  1318. elseif args[1] == "mouse_click" then
  1319. if args[4] >= 1 and args[4] <= 2 then
  1320. store.draw.menu_input("Login", args[3], args[4])
  1321. elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 8) then
  1322. draw.box(8, 36, 8, 1, " ", "cyan", "cyan")
  1323. col.set("white", "cyan")
  1324. term.setCursorPos(8, 8)
  1325. write(": ")
  1326. username = tostring(read())
  1327. elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 11) then
  1328. draw.box(8, 36, 11, 1, " ", "cyan", "cyan")
  1329. col.set("white", "cyan")
  1330. term.setCursorPos(8, 11)
  1331. write(": ")
  1332. password = tostring(read("*"))
  1333. password = crypt.sha256(password)
  1334. elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 14) then
  1335. draw.box(8, 36, 14, 1, " ", "cyan", "cyan")
  1336. col.set("white", "cyan")
  1337. term.setCursorPos(8, 14)
  1338. write(": ")
  1339. email = tostring(read())
  1340. elseif (args[3] >= 9 and args[3] <= 42) and (args[4] == 17) then
  1341. store.account.login()
  1342. elseif (args[3] >= 2 and args[3] <= 10) and (args[4] == 19) then
  1343. break
  1344. elseif (args[3] >= 43 and args[3] <= 50) and (args[4] == 19) then
  1345. if username and password and email then
  1346. draw.textc("Requesting Authentication, Please Wait", 17, false, "lightGrey", "white")
  1347. if discover:register(username, password, email) then
  1348. popup.alert("Registered. Obtaining authkey, please wait")
  1349. sleep(0.5)
  1350. local status = discover:login(username, password)
  1351. if status then
  1352. popup.alert("Logged in!")
  1353. sleep(0.8)
  1354. store.home()
  1355. else
  1356. popup.alert(discover.data.errormsg)
  1357. sleep(1.5)
  1358. store.home()
  1359. end
  1360. else
  1361. draw.box(1, 51, 17, 1, " ", "white", "white")
  1362. draw.textc(tostring(discover.data.errormsg), 17, false, "lightGrey", "white")
  1363. sleep(1)
  1364. store.account.home()
  1365. end
  1366. else
  1367. draw.textc("Please fill in the fields", 17, false, "lightGrey", "white")
  1368. end
  1369. end
  1370. end
  1371. end
  1372. end
  1373.  
  1374. function store.account.logout()
  1375. popup.alert("Logging out...")
  1376. sleep(0.5)
  1377. discover:logout()
  1378. popup.alert("Logged out!")
  1379. sleep(0.5)
  1380. end
  1381.  
  1382. function store.account.upload(step)
  1383. if not step then
  1384. step = ""
  1385. end
  1386. if step == "1" then
  1387. col.screen("white")
  1388. store.draw.menu("Upload (Step 1)")
  1389. draw.box(1, 51, 19, 11, " ", "grey", "grey")
  1390. draw.textl(" Cancel", 19, false, "orange", "grey")
  1391. draw.textr("Next Step ", 19, false, "orange", "grey")
  1392. draw.textc("Press \"up\" to see preset versions / categories.", 18, false, "lightGrey", "white")
  1393.  
  1394. local function run()
  1395. draw.textc("Please follow on-screen instructions!", 4, false, "cyan", "white")
  1396. draw.texta("App Name:", 8, 6, false, "lightGrey", "white")
  1397. draw.box(8, 36, 7, 1, " ", "cyan", "cyan")
  1398. draw.texta("App Description:", 8, 9, false, "lightGrey", "white")
  1399. draw.box(8, 36, 10, 1, " ", "cyan", "cyan")
  1400. draw.texta("App Version:", 8, 12, false, "lightGrey", "white")
  1401. draw.box(8, 36, 13, 1, " ", "cyan", "cyan")
  1402. draw.texta("App Category:", 8, 15, false, "lightGrey", "white")
  1403. draw.box(8, 36, 16, 1, " ", "cyan", "cyan")
  1404. end
  1405.  
  1406. local function render()
  1407. if up_name then
  1408. draw.texta(tostring(": "..up_name), 8, 7, false, "white", "cyan")
  1409. end
  1410. if up_desc then
  1411. draw.texta(tostring(": "..up_desc), 8, 10, false, "white", "cyan")
  1412. end
  1413. if up_vers then
  1414. draw.texta(tostring(": "..up_vers), 8, 13, false, "white", "cyan")
  1415. end
  1416. if up_cate then
  1417. draw.texta(tostring(": "..up_cate), 8, 16, false, "white", "cyan")
  1418. end
  1419. end
  1420.  
  1421. render()
  1422. run()
  1423. while true do
  1424. local args = { os.pullEvent() }
  1425. if args[1] == "timer" then
  1426. store.draw.menu("Upload (Step 1)")
  1427. elseif args[1] == "mouse_click" then
  1428. if args[4] >= 1 and args[4] <= 2 then
  1429. store.draw.menu_input("Upload", args[3], args[4])
  1430. elseif (args[3] >= 2 and args[3] <= 7) and (args[4] == 19) then
  1431. thread:remove("Upload")
  1432. if not thread:find("Account") then
  1433. thread:create("Account", store.account.home)
  1434. end
  1435. thread:switch("Account")
  1436. elseif (args[3] >= 42 and args[3] <= 50) and (args[4] == 19) then
  1437. if up_name and up_desc and up_vers and up_cate then
  1438. store.account.upload("2")
  1439. else
  1440. draw.box(1, 51, 17, 1, " ", "white", "white")
  1441. draw.textc("Please fill out all fields", 17, false, "red", "white")
  1442. sleep(1)
  1443. draw.box(1, 51, 17, 1, " ", "white", "white")
  1444. end
  1445. elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 7) then
  1446. draw.box(1, 51, 7, 1, " ", "white", "white")
  1447. draw.box(8, 36, 7, 1, " ", "cyan", "cyan")
  1448. col.set("white", "cyan")
  1449. term.setCursorPos(8, 7)
  1450. write(": ")
  1451. up_name = tostring(read())
  1452. elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 10) then
  1453. draw.box(1, 51, 10, 1, " ", "white", "white")
  1454. draw.box(8, 36, 10, 1, " ", "cyan", "cyan")
  1455. col.set("white", "cyan")
  1456. term.setCursorPos(8, 10)
  1457. write(": ")
  1458. up_desc = tostring(read())
  1459. elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 13) then
  1460. draw.box(1, 51, 13, 1, " ", "white", "white")
  1461. draw.box(8, 36, 13, 1, " ", "cyan", "cyan")
  1462. col.set("white", "cyan")
  1463. term.setCursorPos(8, 13)
  1464. write(": ")
  1465. up_vers = tostring(read(_, discover.data.versions))
  1466. elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 16) then
  1467. draw.box(1, 51, 16, 1, " ", "white", "white")
  1468. draw.box(8, 36, 16, 1, " ", "cyan", "cyan")
  1469. col.set("white", "cyan")
  1470. term.setCursorPos(8, 16)
  1471. write(": ")
  1472. up_cate = tostring(read(_, discover.data.categories))
  1473. end
  1474. end
  1475. end
  1476. elseif step == "2" then
  1477. col.screen("white")
  1478. store.draw.menu("Upload (Step 2)")
  1479. draw.box(1, 51, 19, 11, " ", "grey", "grey")
  1480. draw.textl(" Back", 19, false, "orange", "grey")
  1481. draw.textr("Upload ", 19, false, "orange", "grey")
  1482.  
  1483. local function run()
  1484. draw.textc("Please follow on-screen instructions!", 4, false, "cyan", "white")
  1485. draw.texta("App Status:", 8, 6, false, "lightGrey", "white")
  1486. draw.box(8, 36, 7, 1, " ", "cyan", "cyan")
  1487. draw.texta("App\'s file path:", 8, 9, false, "lightGrey", "white")
  1488. draw.box(8, 36, 10, 1, " ", "cyan", "cyan")
  1489. end
  1490.  
  1491. local function exit()
  1492. up_stat = nil
  1493. up_path = nil
  1494. up_desc = nil
  1495. up_cate = nil
  1496. up_vers = nil
  1497. up_name = nil
  1498. thread:remove("Upload")
  1499. if not thread:find("Account") then
  1500. thread:create("Account", store.account.home)
  1501. end
  1502. thread:switch("Account")
  1503. end
  1504.  
  1505. local function render()
  1506. if up_stat then
  1507. draw.texta(tostring(": "..up_stat), 8, 7, false, "white", "cyan")
  1508. end
  1509. if up_path then
  1510. draw.texta(tostring(": "..up_path), 8, 10, false, "white", "cyan")
  1511. end
  1512. end
  1513.  
  1514. run()
  1515. render()
  1516. while true do
  1517. local args = { os.pullEvent() }
  1518. if args[1] == "timer" then
  1519. store.draw.menu("Upload (Step 2)")
  1520. elseif args[1] == "mouse_click" then
  1521. if args[4] >= 1 and args[4] <= 2 then
  1522. store.draw.menu_input("Upload", args[3], args[4])
  1523. elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 7) then
  1524. draw.box(1, 51, 7, 1, " ", "white", "white")
  1525. draw.box(8, 36, 7, 1, " ", "cyan", "cyan")
  1526. col.set("white", "cyan")
  1527. term.setCursorPos(8, 7)
  1528. write(": ")
  1529. up_stat = tostring(read(_, {"public", "private"}))
  1530. elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 10) then
  1531. draw.box(1, 51, 10, 1, " ", "white", "white")
  1532. draw.box(8, 36, 10, 1, " ", "cyan", "cyan")
  1533. col.set("white", "cyan")
  1534. term.setCursorPos(8, 10)
  1535. write(": ")
  1536. up_path = tostring(read())
  1537. elseif (args[3] >= 45 and args[3] <= 50) and (args[4] == 19) then
  1538. if up_stat and up_path then
  1539. for i=12, 17 do
  1540. draw.box(1, 51, i, 1, " ", "white", "white")
  1541. end
  1542. draw.texta(":: Finding File...", 8, 12, false, "grey", "white")
  1543. if fs.exists(up_path) then
  1544. draw.texta(":: Extracting Data...", 8, 13, false, "grey", "white")
  1545. local up_path_content = fs.open(up_path, "r")
  1546. up_path_content = up_path_content.readAll()
  1547. draw.texta(":: Sending Server Request...", 8, 14, false, "grey", "white")
  1548. local status = discover:store_upload( up_name, up_desc, up_cate, up_vers, up_stat, up_path_content )
  1549. if status then
  1550. draw.texta(":: Upload was successfull!", 8, 15, false, "grey", "white")
  1551. sleep(1)
  1552. exit()
  1553. else
  1554. draw.texta(":: Unable to store data", 8, 15, false, "grey", "white")
  1555. draw.texta(":: "..tostring(discover.data.errormsg), 8, 15, false, "grey", "white")
  1556. sleep(2)
  1557. end
  1558. else
  1559. draw.texta(":: ERROR: No file found", 8, 13, false, "grey", "white")
  1560. sleep(1)
  1561. end
  1562. else
  1563. draw.box(1, 51, 18, 1, " ", "white", "white")
  1564. draw.textc("Please fill out all fields", 18, false, "red", "white")
  1565. sleep(1)
  1566. draw.box(1, 51, 18, 1, " ", "white", "white")
  1567. end
  1568. elseif (args[3] >= 2 and args[3] <= 5) and (args[4] == 19) then
  1569. store.account.upload("1")
  1570. end
  1571. end
  1572. end
  1573. else
  1574. col.screen("white")
  1575. store.draw.menu("Upload")
  1576. draw.box(1, 51, 19, 11, " ", "grey", "grey")
  1577. draw.textl(" Cancel", 19, false, "orange", "grey")
  1578. draw.textr("Accept ", 19, false, "orange", "grey")
  1579. local scroll = 0
  1580.  
  1581. local function run(scroll)
  1582. draw.textc("Please read the following before submitting:", 4, false, "lightGrey", "white")
  1583. 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."
  1584. tText = data.wordwrap(text, 47)
  1585. for i=1, 12 do
  1586. if (scroll + i) <= #tText then
  1587. draw.box(1, 51, i+5, 1, " ", "white", "white")
  1588. draw.texta(tText[i+scroll], 3, i+5, false, "grey", "white")
  1589. end
  1590. end
  1591. end
  1592.  
  1593. run(scroll)
  1594. while true do
  1595. local args = { os.pullEvent() }
  1596. if args[1] == "timer" then
  1597. store.draw.menu("upload")
  1598. elseif args[1] == "mouse_click" then
  1599. if args[4] >= 1 and args[4] <= 2 then
  1600. store.draw.menu_input("Upload", args[3], args[4])
  1601. elseif (args[3] >= 2 and args[3] <= 7) and (args[4] == 19) then
  1602. thread:remove("Upload")
  1603. if not thread:find("Account") then
  1604. thread:create("Account", store.account.home)
  1605. end
  1606. thread:switch("Account")
  1607. elseif (args[3] >= 45 and args[3] <= 50) and (args[4] == 19) then
  1608. store.account.upload("1")
  1609. end
  1610. elseif args[1] == "mouse_scroll" then
  1611. if args[2] == -1 then
  1612. if scroll > 0 then
  1613. scroll = scroll - 1
  1614. run(scroll)
  1615. end
  1616. elseif args[2] == 1 then
  1617. if scroll + 12 < #tText then
  1618. scroll = scroll + 1
  1619. run(scroll)
  1620. end
  1621. end
  1622. end
  1623. end
  1624. end
  1625. end
  1626.  
  1627. function store.apps.download()
  1628. col.screen("white")
  1629. store.draw.menu("Download")
  1630. local appid = temp.download
  1631.  
  1632. local text = "You are attempting to download an app, please choose a name for the file download";
  1633.  
  1634.  
  1635. local function run()
  1636. for k,v in ipairs(data.wordwrap(text, 45)) do
  1637. draw.textc(v, k+3, false, "grey", "white")
  1638. end
  1639. draw.texta("File Name / Path:", 8, 8, false, "lightGrey", "white")
  1640. draw.box(8, 36, 9, 1, " ", "cyan", "cyan")
  1641. draw.texta(" Download ", 8, 12, false, "white", "cyan")
  1642. draw.texta(" Cancel ", 36, 12, false, "white", "cyan")
  1643. end
  1644.  
  1645.  
  1646. run()
  1647.  
  1648. while true do
  1649. local args = { os.pullEvent() }
  1650. if args[1] == "timer" then
  1651. store.draw.menu("Download")
  1652. elseif args[1] == "mouse_click" then
  1653. if args[4] >= 1 and args[4] <= 2 then
  1654. store.draw.menu_input("Download", args[3], args[4])
  1655. elseif (args[3] >= 8 and args[3] <= 17) and (args[4] == 12) then
  1656. if filepath then
  1657. local data = discover:store_download(appid)
  1658. if data then
  1659. local f = fs.open(filepath, "w")
  1660. f.write(data.readAll())
  1661. f.close()
  1662. popup.alert("Saved!")
  1663. sleep(1)
  1664. thread:remove("Download" .. tostring(appid))
  1665. if thread:find("Apps") then
  1666. thread:create("Apps", store.apps.all)
  1667. end
  1668. thread:switch("Apps")
  1669. else
  1670. draw.box(1, 51, 14, 1, " ", "white", "white")
  1671. draw.textc("An error occured", 14, false, "lightGrey", "white")
  1672. end
  1673. else
  1674. draw.box(1, 51, 14, 1, " ", "white", "white")
  1675. draw.textc("Please supply a file path / name!", 14, false, "lightGrey", "white")
  1676. end
  1677. elseif (args[3] >= 36 and args[3] <= 43) and (args[4] == 12) then
  1678. thread:remove("Download"..tostring(appid))
  1679. thread:switch("Home")
  1680. elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 9) then
  1681. draw.box(8, 36, 9, 1, " ", "cyan", "cyan")
  1682. col.set("white", "cyan")
  1683. term.setCursorPos(8, 9)
  1684. write(": ")
  1685. filepath = tostring(read())
  1686. end
  1687. end
  1688. end
  1689. end
  1690.  
  1691. function store.account.myapps()
  1692. col.screen("white")
  1693. draw.textc("Downloading your apps list...", 9, false, "grey", "white")
  1694. if not discover:store_apps_user() then
  1695. popup.alert("Could not obtain your Apps list...")
  1696. sleep(1.5)
  1697. if not thread:find("Account") then
  1698. thread:create("Account", store.account.home)
  1699. end
  1700. thread:remove("MyApps")
  1701. thread:switch("Account")
  1702. end
  1703.  
  1704. appslist = discover.data.appsuser
  1705.  
  1706. draw.box(1, 51, 9, 1, " ", "white", "white")
  1707. store.draw.menu("MyApps")
  1708. draw.box(1, 51, 19, 1, " ", "grey", "grey")
  1709. draw.texta("Your Apps: "..tostring(#appslist), 2, 19, false, "orange", "grey")
  1710. scroll = 0
  1711.  
  1712. local function fix(num)
  1713. if tostring(num):len() == 1 then
  1714. return " "..tostring(num)
  1715. else
  1716. return tostring(num)
  1717. end
  1718. end
  1719.  
  1720. local function run(scroll)
  1721. for i = 1, 14 do
  1722. if #appslist >= i + scroll then
  1723. draw.box(1, 51, i+3, 1, " ", "white", "white")
  1724. draw.texta(tostring(fix(i+scroll)..": "..appslist[i+scroll].name):sub(1, 40), 1, i+3, false, "grey", "white")
  1725. draw.texta("X", 50, i+3, false, "red", "white")
  1726. draw.texta("Edit", 44, i+3, false, "lightBlue", "white")
  1727. end
  1728. end
  1729. end
  1730.  
  1731. run(scroll)
  1732.  
  1733. while true do
  1734. local args = { os.pullEvent() }
  1735. if args[1] == "timer" then
  1736. store.draw.menu("MyApps")
  1737. elseif args[1] == "mouse_click" then
  1738. if args[4] >= 1 and args[4] <= 2 then
  1739. store.draw.menu_input("MyApps", args[3], args[4])
  1740. elseif (args[3] >= 44 and args[3] <= 47) and (args[4] >= 4 and args[4] <= 17) then
  1741. -- Do Edit
  1742. local appid = appslist[args[4] - 3 + scroll].id
  1743. temp.edit_appid = appid
  1744. thread:create("Edit", store.account.edit)
  1745. thread:switch("Edit")
  1746. elseif (args[3] == 50) and (args[4] >= 4 and args[4] <= 17) then
  1747. -- Do Delete
  1748. local appid = appslist[args[4] - 3 + scroll].id
  1749. local appname = appslist[args[4] - 3 + scroll].name
  1750. draw.box(8, 36, 8, 2, " ", "grey", "grey")
  1751. draw.box(8, 36, 10, 2, " ", "grey", "grey")
  1752. local text = "To delete the app: "..tostring(appname).." press \"enter\" otherwise please press any other button to exit."
  1753. for k,v in ipairs(data.wordwrap(text, 34)) do
  1754. draw.texta(v, 9, k+7, false, "white", "grey")
  1755. end
  1756. while true do
  1757. local ev, nk = os.pullEvent("key")
  1758. if ev == "key" then
  1759. if nk == 28 then
  1760. col.screen("white")
  1761. store.draw.menu("MyApps")
  1762. col.set("cyan", "white")
  1763. term.setCursorPos(1, 4)
  1764. print("Deleting...")
  1765. local status = discover:store_delete( appid )
  1766. if status then
  1767. popup.alert("App Deleted!")
  1768. sleep(0.5)
  1769. store.account.myapps()
  1770. else
  1771. popup.alert(discover.data.errormsg)
  1772. sleep(1.5)
  1773. store.account.myapps()
  1774. end
  1775. else
  1776. break
  1777. end
  1778. else
  1779. break
  1780. end
  1781. end
  1782. end
  1783. elseif args[1] == "mouse_scroll" then
  1784. if args[2] == -1 then
  1785. if scroll > 0 then
  1786. scroll = scroll - 1
  1787. run(scroll)
  1788. end
  1789. elseif args[2] == 1 then
  1790. if scroll + 14 < #appslist then
  1791. scroll = scroll + 1
  1792. run(scroll)
  1793. end
  1794. end
  1795. end
  1796. end
  1797. end
  1798.  
  1799. function store.account.home()
  1800. col.screen("white")
  1801. store.draw.menu("My Account")
  1802.  
  1803. local function run()
  1804. for i=1, 20 do
  1805. draw.box(i, 1, 3, 17, " ", "lightGrey", "lightGrey")
  1806. end
  1807. draw.box(2, 18, 5, 1, " ", "orange", "orange")
  1808. draw.box(2, 18, 7, 1, " ", "orange", "orange")
  1809. draw.box(2, 18, 9, 1, " ", "orange", "orange")
  1810. draw.texta("Upload an App", 3, 5, false, "white", "orange")
  1811. draw.texta("Update an App", 3, 7, false, "white", "orange")
  1812. draw.texta("View my Apps", 3, 9, false, "white", "orange")
  1813.  
  1814. -- Draw info
  1815. draw.texta("My Details", 31, 4, false, "grey", "white")
  1816. draw.texta("Username:", 22, 7, false, "lightGrey", "white")
  1817. draw.box(22, 29, 8, 1, " ", "cyan", "cyan")
  1818. draw.texta(tostring(discover.data.username), 23, 8, false, "white", "cyan")
  1819. draw.texta("AuthKey:", 22, 11, false, "lightGrey", "white")
  1820. draw.box(22, 29, 12, 1, " ", "cyan", "cyan")
  1821. draw.box(22, 29, 13, 1, " ", "cyan", "cyan")
  1822. draw.box(22, 29, 14, 1, " ", "cyan", "cyan")
  1823. draw.box(22, 29, 15, 1, " ", "cyan", "cyan")
  1824. draw.box(22, 29, 16, 1, " ", "cyan", "cyan")
  1825. draw.texta(discover.data.authkey:sub(1, 27) , 23, 12, false, "white", "cyan")
  1826. draw.texta(discover.data.authkey:sub(28, 54) , 23, 13, false, "white", "cyan")
  1827. draw.texta(discover.data.authkey:sub(55, 81) , 23, 14, false, "white", "cyan")
  1828. draw.texta(discover.data.authkey:sub(82, 108) , 23, 15, false, "white", "cyan")
  1829. draw.texta(discover.data.authkey:sub(109) , 23, 16, false, "white", "cyan")
  1830. end
  1831.  
  1832. run()
  1833. while true do
  1834. local args = { os.pullEvent() }
  1835. if args[1] == "timer" then
  1836. store.draw.menu("My Account")
  1837. elseif args[1] == "mouse_click" then
  1838. if args[4] >= 1 and args[4] <= 2 then
  1839. store.draw.menu_input("Account", args[3], args[4])
  1840. elseif (args[3] >= 2 and args[3] <= 18) and (args[4] == 5) then
  1841. if not thread:find("Upload") then
  1842. thread:create("Upload", store.account.upload)
  1843. end
  1844. thread:switch("Upload")
  1845. elseif (args[3] >= 2 and args[3] <= 18) and (args[4] == 7) then
  1846. if not thread:find("Update") then
  1847. thread:create("Update", store.account.update)
  1848. end
  1849. thread:switch("Update")
  1850. elseif (args[3] >= 2 and args[3] <= 18) and (args[4] == 9) then
  1851. if not thread:find("MyApps") then
  1852. thread:create("MyApps", store.account.myapps)
  1853. end
  1854. thread:switch("MyApps")
  1855. end
  1856. end
  1857. end
  1858. end
  1859.  
  1860. function store.account.update()
  1861. col.screen("white")
  1862. store.draw.menu("Update")
  1863. draw.box(1, 51, 19, 1, " ", "grey", "grey")
  1864. draw.textl(" Cancel", 19, false, "orange", "grey")
  1865. draw.textr("Update ", 19, false, "cyan", "grey")
  1866.  
  1867. local function exit()
  1868. upd_stat = nil
  1869. upd_path = nil
  1870. upd_vers = nil
  1871. upd_path_content = nil
  1872. upd_appid = nil
  1873. thread:remove("Upload")
  1874. if not thread:find("Account") then
  1875. thread:create("Account", store.account.home)
  1876. end
  1877. thread:switch("Account")
  1878. end
  1879.  
  1880. local function run()
  1881. draw.textc("Please follow on-screen instructions!", 4, false, "cyan", "white")
  1882. draw.texta("App ID:", 8, 6, false, "lightGrey", "white")
  1883. draw.box(8, 36, 7, 1, " ", "cyan", "cyan")
  1884. draw.texta("Version:", 8, 9, false, "lightGrey", "white")
  1885. draw.box(8, 36, 10, 1, " ", "cyan", "cyan")
  1886. draw.texta("Status:", 8, 12, false, "lightGrey", "white")
  1887. draw.box(8, 36, 13, 1, " ", "cyan", "cyan")
  1888. draw.texta("File Path:", 8, 15, false, "lightGrey", "white")
  1889. draw.box(8, 36, 16, 1, " ", "cyan", "cyan")
  1890. end
  1891.  
  1892. run()
  1893. while true do
  1894. local args = { os.pullEvent() }
  1895. if args[1] == "timer" then
  1896. store.draw.menu("Update")
  1897. elseif args[1] == "mouse_click" then
  1898. if args[4] >= 1 and args[4] <= 2 then
  1899. store.draw.menu_input("Update", args[3], args[4])
  1900. elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 7) then
  1901. draw.box(1, 51, 7, 1, " ", "white", "white")
  1902. draw.box(8, 36, 7, 1, " ", "cyan", "cyan")
  1903. col.set("white", "cyan")
  1904. term.setCursorPos(8, 7)
  1905. write(": ")
  1906. upd_appid = tostring(read())
  1907. elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 10) then
  1908. draw.box(1, 51, 10, 1, " ", "white", "white")
  1909. draw.box(8, 36, 10, 1, " ", "cyan", "cyan")
  1910. col.set("white", "cyan")
  1911. term.setCursorPos(8, 10)
  1912. write(": ")
  1913. upd_vers = tostring(read(_, discover.data.versions))
  1914. elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 13) then
  1915. draw.box(1, 51, 13, 1, " ", "white", "white")
  1916. draw.box(8, 36, 13, 1, " ", "cyan", "cyan")
  1917. col.set("white", "cyan")
  1918. term.setCursorPos(8, 13)
  1919. write(": ")
  1920. upd_stat = tostring(read(_, {"public", "private"}))
  1921. elseif (args[3] >= 8 and args[3] <= 43) and (args[4] == 16) then
  1922. draw.box(1, 51, 16, 1, " ", "white", "white")
  1923. draw.box(8, 36, 16, 1, " ", "cyan", "cyan")
  1924. col.set("white", "cyan")
  1925. term.setCursorPos(8, 16)
  1926. write(": ")
  1927. upd_path = tostring(read(_, discover.data.categories))
  1928. elseif (args[3] >= 45 and args[3] <= 50) and (args[4] == 19) then
  1929. if upd_appid and upd_vers and upd_stat and upd_path then
  1930. if fs.exists(upd_path) then
  1931. local f = fs.open(upd_path, "r")
  1932. local upd_path_content = f.readAll()
  1933. local status = discover:store_update( upd_appid, upd_vers, upd_stat, upd_path_content )
  1934. if status then
  1935. popup.alert("App was updated!")
  1936. sleep(1)
  1937. exit()
  1938. else
  1939. draw.box(1, 51, 18, 1, " ", "white", "white")
  1940. draw.textc(discover.data.errormsg, 18, false, "red", "white")
  1941. sleep(1.2)
  1942. draw.box(1, 51, 18, 1, " ", "white", "white")
  1943. end
  1944. else
  1945. draw.box(1, 51, 18, 1, " ", "white", "white")
  1946. draw.textc("No file found in the given path", 18, false, "red", "white")
  1947. sleep(0.8)
  1948. draw.box(1, 51, 18, 1, " ", "white", "white")
  1949. end
  1950. else
  1951. draw.box(1, 51, 18, 1, " ", "white", "white")
  1952. draw.textc("Please fill out all fields", 18, false, "red", "white")
  1953. sleep(0.8)
  1954. draw.box(1, 51, 18, 1, " ", "white", "white")
  1955. end
  1956. elseif (args[3] >= 2 and args[3] <= 7) and (args[4] == 19) then
  1957. exit()
  1958. end
  1959. end
  1960. end
  1961. end
  1962.  
  1963. function store.account.edit()
  1964. local appid = temp.edit_appid
  1965. if not appid then
  1966. popup.alert("No App ID Supplied")
  1967. sleep(1.5)
  1968. thread:remove("Edit")
  1969. if not thread:find("Account") then
  1970. thread:create("Account", store.account.home)
  1971. end
  1972. thread:switch("Account")
  1973. end
  1974.  
  1975. col.screen("white")
  1976. store.draw.menu("Edit")
  1977. draw.box(1, 51, 19, 1, " ", "grey", "grey")
  1978. draw.textl(" Cancel ", 19, false, "orange", "grey")
  1979. draw.textr("Edit ", 19, false, "lightBlue", "grey")
  1980.  
  1981. local function run(scroll)
  1982. draw.texta("App Name:", 8, 4, false, "lightGrey", "white")
  1983. draw.box(8, 36, 5, 1, " ", "cyan", "cyan")
  1984.  
  1985. draw.texta("Description:", 8, 7, false, "lightGrey", "white")
  1986. draw.box(8, 36, 8, 1, " ", "cyan", "cyan")
  1987.  
  1988. draw.texta("Version:", 8, 10, false, "lightGrey", "white")
  1989. draw.box(8, 36, 11, 1, " ", "cyan", "cyan")
  1990.  
  1991. draw.texta("Category:", 8, 13, false, "lightGrey", "white")
  1992. draw.box(8, 36, 14, 1, " ", "cyan", "cyan")
  1993.  
  1994. draw.texta("Status:", 8, 16, false, "lightGrey", "white")
  1995. draw.box(8, 36, 17, 1, " ", "cyan", "cyan")
  1996. end
  1997.  
  1998. run(scroll)
  1999. while true do
  2000. local args = { os.pullEvent() }
  2001. if args[1] == "timer" then
  2002. store.draw.menu("Edit")
  2003. elseif args[1] == "mouse_click" then
  2004. if args[4] >= 1 and args[4] <= 2 then
  2005. store.draw.menu_input("Edit", args[3], args[4])
  2006. elseif (args[3] >= 2 and args[3] <= 7) and (args[4] == 19) then
  2007. if not thread:find("MyApps") then
  2008. thread:create("MyApps", store.account.home)
  2009. end
  2010. thread:remove("Edit")
  2011. thread:switch("MyApps")
  2012. elseif (args[3] >= 47 and args[3] <= 50) and (args[4] == 19) then
  2013. local status = discover:store_edit( appid, edit_name, edit_desc, edit_vers, edit_cate, edit_stat )
  2014. if status then
  2015. popup.alert("Edited!")
  2016. sleep(0.5)
  2017. if not thread:find("MyApps") then
  2018. thread:create("MyApps", store.account.home)
  2019. end
  2020. thread:remove("Edit")
  2021. thread:switch("MyApps")
  2022. else
  2023. popup.alert(discover.data.errormsg)
  2024. sleep(1.2)
  2025. if not thread:find("MyApps") then
  2026. thread:create("MyApps", store.account.home)
  2027. end
  2028. thread:remove("Edit")
  2029. thread:switch("MyApps")
  2030. end
  2031. elseif (args[3] >= 8 and args[3] <= 47) and (args[4] == 5) then
  2032. draw.box(8, 36, 5, 1, " ", "cyan", "cyan")
  2033. col.set("white", "cyan")
  2034. term.setCursorPos(8, 5)
  2035. write(": ")
  2036. edit_name = tostring(read())
  2037. elseif (args[3] >= 8 and args[3] <= 47) and (args[4] == 8) then
  2038. draw.box(8, 36, 8, 1, " ", "cyan", "cyan")
  2039. col.set("white", "cyan")
  2040. term.setCursorPos(8, 8)
  2041. write(": ")
  2042. edit_desc = tostring(read())
  2043. elseif (args[3] >= 8 and args[3] <= 47) and (args[4] == 11) then
  2044. draw.box(8, 36, 11, 1, " ", "cyan", "cyan")
  2045. col.set("white", "cyan")
  2046. term.setCursorPos(8, 11)
  2047. write(": ")
  2048. edit_vers = tostring(read(_, discover.data.versions))
  2049. elseif (args[3] >= 8 and args[3] <= 47) and (args[4] == 14) then
  2050. draw.box(8, 36, 14, 1, " ", "cyan", "cyan")
  2051. col.set("white", "cyan")
  2052. term.setCursorPos(8, 14)
  2053. write(": ")
  2054. edit_cate = tostring(read(_, discover.data.categories))
  2055. elseif (args[3] >= 8 and args[3] <= 47) and (args[4] == 17) then
  2056. draw.box(8, 36, 17, 1, " ", "cyan", "cyan")
  2057. col.set("white", "cyan")
  2058. term.setCursorPos(8, 17)
  2059. write(": ")
  2060. edit_stat = tostring(read(_, {"public", "private"}))
  2061. end
  2062. end
  2063. end
  2064. end
  2065.  
  2066. function store.account.stats()
  2067. col.screen("white")
  2068. store.draw.menu("My Statistics")
  2069.  
  2070. local apps = discover.data.apps
  2071. local ndata = {
  2072. apps = 0;
  2073. downloads = 0;
  2074. myapps = {};
  2075. }
  2076.  
  2077. local function getstats()
  2078. draw.textc("Processing...", 9, false, "grey", "white")
  2079. sleep(0.5)
  2080. for k,v in ipairs(apps) do
  2081. if v.creator == discover.data.username then
  2082. ndata.apps = ndata.apps + 1
  2083. ndata.downloads = ndata.downloads + tonumber(v.downloads)
  2084. ndata.myapps[#ndata.myapps+1] = v
  2085. end
  2086. end
  2087. draw.box(1, 51, 9, 1, " ", "white", "white")
  2088. end
  2089.  
  2090. local function run()
  2091. 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."
  2092. for k,v in ipairs(data.wordwrap(text, 51)) do
  2093. draw.texta(v, 1, k+3, false, "grey", "white")
  2094. end
  2095. draw.textl(" Uploaded Apps: "..tostring(ndata.apps), 10, false, "grey", "white")
  2096. draw.textl(" Total Downloads: "..tostring(ndata.downloads), 12, false, "grey", "white")
  2097. end
  2098.  
  2099. getstats()
  2100. run()
  2101.  
  2102. while true do
  2103. local args = { os.pullEvent() }
  2104. if args[1] == "timer" then
  2105. store.draw.menu("My Statistics")
  2106. elseif args[1] == "mouse_click" then
  2107. if args[4] >= 1 and args[4] <= 2 then
  2108. store.draw.menu_input("Settings (System)", args[3], args[4])
  2109. end
  2110. end
  2111. end
  2112. end
  2113.  
  2114. function store.settings(screen)
  2115. local function clears()
  2116. for i=1, 51 do
  2117. if i >= 1 and i <= 20 then
  2118. draw.box(i, 1, 3, 17, " ", "lightGrey", "lightGrey")
  2119. end
  2120. if i>= 21 and i <= 51 then
  2121. draw.box(i, 1, 3, 17, " ", "white", "white")
  2122. end
  2123. end
  2124. draw.box(1, 51, 19, 1, " ", "grey", "grey")
  2125. end
  2126.  
  2127. if not screen then
  2128. screen = ""
  2129. end
  2130.  
  2131. local function draw_menu()
  2132. draw.box(2, 18, 4, 1, " ", "orange", "orange")
  2133. draw.box(2, 18, 6, 1, " ", "orange", "orange")
  2134. draw.box(2, 18, 8, 1, " ", "orange", "orange")
  2135. draw.texta("Main Menu", 3, 4, false, "white", "orange")
  2136. draw.texta("System Settings", 3, 6, false, "white", "orange")
  2137. draw.texta("Discover Details", 3, 8, false, "white", "orange")
  2138. if screen == "System" then
  2139. draw.box(2, 18, 6, 1, " ", "red", "red")
  2140. draw.texta("System Settings", 3, 6, false, "white", "red")
  2141. elseif screen == "Details" then
  2142. draw.box(2, 18, 8, 1, " ", "red", "red")
  2143. draw.texta("Discover Details", 3, 8, false, "white", "red")
  2144. else
  2145. draw.box(2, 18, 4, 1, " ", "red", "red")
  2146. draw.texta("Main Menu", 3, 4, false, "white", "red")
  2147. end
  2148. end
  2149.  
  2150. if screen == "System" then
  2151. -- System
  2152. local scroll = 0
  2153.  
  2154. clears()
  2155. store.draw.menu("Settings (System)")
  2156.  
  2157. draw.box(1, 51, 19, 1, " ", "grey", "grey")
  2158. draw.textr("Scroll Enabled ", 19, false, "orange", "grey")
  2159.  
  2160. local function run(scroll)
  2161. draw.textr("----------------------------- ", 4, false, "lightGrey", "white")
  2162. draw.texta("Toggle config storage:", 22, 5, false, "grey", "white")
  2163. draw.box(22, 29, 7, 1, " ", "white", "white")
  2164. draw.texta("Status:", 22, 7, false, "grey", "white")
  2165. if system.storeconfig then
  2166. draw.texta("Enabled", 30, 7, false, "cyan", "white")
  2167. new = {}
  2168. new.username = discover.data.username
  2169. new.password = discover.data.password
  2170. new.storeconfig = system.storeconfig
  2171. new.plugins = system.plugins
  2172. new.authkey = discover.data.authkey
  2173. dat = textutils.serialize(new)
  2174. local f = fs.open(system.paths.config, "w")
  2175. f.write(basesf.encode(dat))
  2176. f.close()
  2177. else
  2178. draw.texta("Disabled", 30, 7, false, "red", "white")
  2179. fs.delete(system.paths.config)
  2180. end
  2181. draw.textr("----------------------------- ", 8, false, "lightGrey", "white")
  2182. draw.texta("Toggle plugins:", 22, 9, false, "grey", "white")
  2183. draw.box(22, 29, 11, 1, " ", "white", "white")
  2184. draw.texta("Status:", 22, 11, false, "grey", "white")
  2185. if system.plugins then
  2186. draw.texta("Enabled", 30, 11, false, "cyan", "white")
  2187. else
  2188. draw.texta("Disabled", 30, 11, false, "red", "white")
  2189. end
  2190. draw.textr("----------------------------- ", 12, false, "lightGrey", "white")
  2191. draw.texta("Toggle program lock:", 22, 13, false, "grey", "white")
  2192. draw.box(22, 29, 15, 1, " ", "white", "white")
  2193. draw.texta("Status:", 22, 15, false, "grey", "white")
  2194. if system.lock_program then
  2195. draw.texta("Enabled", 30, 15, false, "cyan", "white")
  2196. else
  2197. draw.texta("Disabled", 30, 15, false, "red", "white")
  2198. end
  2199. draw.textr("----------------------------- ", 16, false, "lightGrey", "white")
  2200. draw.texta(" T ", 48, 6, false, "white", "orange")
  2201. draw.texta(" T ", 48, 10, false, "white", "orange")
  2202. draw.texta(" T ", 48, 14, false, "white", "orange")
  2203. end
  2204.  
  2205. draw_menu()
  2206. run(scroll)
  2207. while true do
  2208. local args = { os.pullEvent() }
  2209. if args[1] == "timer" then
  2210. store.draw.menu("Settings (System)")
  2211. elseif args[1] == "mouse_click" then
  2212. if args[4] >= 1 and args[4] <= 2 then
  2213. store.draw.menu_input("Settings (System)", args[3], args[4])
  2214. elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 4 then
  2215. store.settings()
  2216. elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 6 then
  2217. store.settings("System")
  2218. elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 8 then
  2219. store.settings("Details")
  2220. elseif (args[3] >= 48 and args[3] <= 50) and (args[4] == 6) then
  2221. if system.storeconfig then
  2222. system.storeconfig = false
  2223. else
  2224. system.storeconfig = true
  2225. end
  2226. run(scroll)
  2227. elseif (args[3] >= 48 and args[3] <= 50) and (args[4] == 10) then
  2228. if system.plugins then
  2229. system.plugins = false
  2230. else
  2231. system.plugins = true
  2232. end
  2233. run(scroll)
  2234. elseif (args[3] >= 48 and args[3] <= 50) and (args[4] == 14) then
  2235. if system.lock_program then
  2236. system.lock_program = false
  2237. else
  2238. system.lock_program = true
  2239. end
  2240. run(scroll)
  2241. end
  2242. end
  2243. end
  2244. elseif screen == "Details" then
  2245. -- Details
  2246. local scroll = 0
  2247.  
  2248. clears()
  2249. store.draw.menu("Settings (Discover Details)")
  2250.  
  2251. draw.box(1, 51, 19, 1, " ", "grey", "grey")
  2252. draw.textr("Scroll Enabled ", 19, false, "orange", "grey")
  2253.  
  2254. local function run(scroll)
  2255. draw.textr("----------------------------- ", 4, false, "lightGrey", "white")
  2256. draw.texta("Discover API Version:", 22, 5, false, "grey", "white")
  2257. draw.texta(tostring(discover:get("version_api")), 22, 7, false, "cyan", "white")
  2258. draw.textr("----------------------------- ", 8, false, "lightGrey", "white")
  2259. draw.texta("Discover System Version:", 22, 9, false, "grey", "white")
  2260. draw.texta(tostring(discover:get("version")), 22, 11, false, "cyan", "white")
  2261. draw.textr("----------------------------- ", 12, false, "lightGrey", "white")
  2262. end
  2263.  
  2264. draw_menu()
  2265. run(scroll)
  2266. while true do
  2267. local args = { os.pullEvent() }
  2268. if args[1] == "timer" then
  2269. store.draw.menu("Settings (Discover Details)")
  2270. elseif args[1] == "mouse_click" then
  2271. if args[4] >= 1 and args[4] <= 2 then
  2272. store.draw.menu_input("Settings (Menu)", args[3], args[4])
  2273. elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 4 then
  2274. store.settings()
  2275. elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 6 then
  2276. store.settings("System")
  2277. elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 8 then
  2278. store.settings("Details")
  2279. end
  2280. end
  2281. end
  2282.  
  2283. else
  2284. -- Home
  2285. col.screen("white")
  2286. local scroll = 0
  2287. store.draw.menu("Settings (Menu)")
  2288.  
  2289. clears()
  2290.  
  2291. draw.textr("Scroll Enabled ", 19, false, "orange", "grey")
  2292.  
  2293. local function run(scoll)
  2294. 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."
  2295. tText = data.wordwrap(text, 29)
  2296.  
  2297. for i=1, 14 do
  2298. if #tText >= i + scroll then
  2299. draw.box(21, 30, i+3, 1, " ", "white", "white")
  2300. draw.texta(tText[i+scroll], 22, i+3, false, "grey", "white")
  2301. end
  2302. end
  2303. end
  2304.  
  2305. draw_menu()
  2306. run(scroll)
  2307. while true do
  2308. local args = { os.pullEvent() }
  2309. if args[1] == "timer" then
  2310. store.draw.menu("Settings (Menu)")
  2311. elseif args[1] == "mouse_click" then
  2312. if args[4] >= 1 and args[4] <= 2 then
  2313. store.draw.menu_input("Settings (Menu)", args[3], args[4])
  2314. elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 4 then
  2315. store.settings()
  2316. elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 6 then
  2317. store.settings("System")
  2318. elseif (args[3] >= 2 and args[3] <= 18) and args[4] == 8 then
  2319. store.settings("Details")
  2320. end
  2321. elseif args[1] == "mouse_scroll" then
  2322. if args[2] == -1 then
  2323. if scroll > 0 then
  2324. scroll = scroll - 1
  2325. run(scroll)
  2326. end
  2327. elseif args[2] == 1 then
  2328. if scroll + 14 < #tText then
  2329. scroll = scroll + 1
  2330. run(scroll)
  2331. end
  2332. end
  2333. end
  2334. end
  2335. end
  2336. end
  2337.  
  2338. function store.help(name)
  2339. tData = {
  2340. {
  2341. ["name"] = "How to use the App Store";
  2342. ["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.";
  2343. };
  2344. {
  2345. ["name"] = "Discover API System";
  2346. ["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.";
  2347. };
  2348. {
  2349. ["name"] = "Store Settings";
  2350. ["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.";
  2351. };
  2352. {
  2353. ["name"] = "Store Statistics";
  2354. ["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.";
  2355. };
  2356. {
  2357. ["name"] = "Uploading/Downloading/Editing/Updating Apps";
  2358. ["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.";
  2359. };
  2360. {
  2361. ["name"] = "Discover API Account";
  2362. ["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.";
  2363. };
  2364. {
  2365. ["name"] = "How do plugins work?";
  2366. ["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.";
  2367. };
  2368. {
  2369. ["name"] = "What do you mean \"new api\"?";
  2370. ["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.";
  2371. };
  2372. {
  2373. ["name"] = "How can I get involved?";
  2374. ["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.";
  2375. };
  2376. }
  2377.  
  2378. if name:sub(1,7) == "content" then
  2379. local scroll = 0
  2380. conid = tonumber(name:sub(8))
  2381. col.screen("white")
  2382. store.draw.menu("Help / FAQ")
  2383.  
  2384. draw.box(1, 51, 19, 1, " ", "grey", "grey")
  2385. draw.texta("Back", 2, 19, false, "lightBlue", "grey")
  2386. draw.textr("Scroll enabled ", 19, false, "orange", "grey")
  2387.  
  2388. pagecontent = data.wordwrap(tData[conid].content, 49)
  2389.  
  2390. local function run(scroll)
  2391. for i=1, 14 do
  2392. if #pagecontent >= i + scroll then
  2393. draw.box(1, 51, i+3, 1, " ", "white", "white")
  2394. draw.textl(pagecontent[i+scroll], i+3, false, "cyan", "white")
  2395. else
  2396. break
  2397. end
  2398. end
  2399. end
  2400.  
  2401. run(scroll)
  2402.  
  2403. while true do
  2404. local args = { os.pullEvent() }
  2405. if args[1] == "timer" then
  2406. store.draw.menu("Help / FAQ")
  2407. elseif args[1] == "mouse_click" then
  2408. if args[4] >= 1 and args[4] <= 2 then
  2409. store.draw.menu_input("Help / FAQ", args[3], args[4])
  2410. elseif (args[3] >= 2 and args[3] <= 5) and args[4] == 19 then
  2411. store.help("menu")
  2412. end
  2413. elseif args[1] == "mouse_scroll" then
  2414. if args[2] == -1 then
  2415. if scroll > 0 then
  2416. scroll = scroll - 1
  2417. run(scroll)
  2418. end
  2419. elseif args[2] == 1 then
  2420. if scroll + 14 < #pagecontent then
  2421. scroll = scroll + 1
  2422. run(scroll)
  2423. end
  2424. end
  2425. end
  2426. end
  2427. else
  2428. local scroll = 0
  2429. col.screen("white")
  2430. store.draw.menu("Help / FAQ")
  2431.  
  2432. draw.box(1, 51, 19, 1, " ", "grey", "grey")
  2433. draw.textc("Help Topics: "..tostring(#tData), 19, false, "lightBlue", "grey")
  2434.  
  2435. local function fix(num)
  2436. if tostring(num):len() == 1 then
  2437. return " "..tostring(num)
  2438. else
  2439. return tostring(num)
  2440. end
  2441. end
  2442.  
  2443. local function run(scroll)
  2444. for i=1, 14 do
  2445. if #tData >= i + scroll then
  2446. draw.texta(tostring(fix(i+scroll)) .. ": " .. tData[i+scroll].name, 1, i+3, false, "cyan", "white")
  2447. else
  2448. break
  2449. end
  2450. end
  2451. end
  2452.  
  2453. run(scroll)
  2454.  
  2455. while true do
  2456. local args = { os.pullEvent() }
  2457. if args[1] == "timer" then
  2458. store.draw.menu("Help / FAQ")
  2459. elseif args[1] == "mouse_click" then
  2460. if args[4] >= 1 and args[4] <= 2 then
  2461. store.draw.menu_input("Help / FAQ", args[3], args[4])
  2462. elseif (args[3] >= 1 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 19) then
  2463. -- Get current option
  2464. local curid = args[4] - 3 + scroll
  2465. if curid <= #tData then
  2466. store.help("content"..tostring(curid))
  2467. end
  2468. end
  2469. elseif args[1] == "mouse_scroll" then
  2470. if args[2] == -1 then
  2471. if scroll > 0 then
  2472. scroll = scroll - 1
  2473. run(scroll)
  2474. end
  2475. elseif args[2] == 1 then
  2476. if scroll + 14 < #tData then
  2477. scroll = scroll + 1
  2478. run(scroll)
  2479. end
  2480. end
  2481. end
  2482. end
  2483. end
  2484. end
  2485.  
  2486. function store.updates(name)
  2487. tData = {
  2488. {
  2489. ["name"] = "Update: 4.1.4 (Beta)";
  2490. ["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.";
  2491. };
  2492. {
  2493. ["name"] = "Update: 4.1.1 (Beta)";
  2494. ["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.";
  2495. };
  2496. {
  2497. ["name"] = "Update: 4.0.1 (Alpha)";
  2498. ["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.";
  2499. };
  2500. }
  2501.  
  2502. if name:sub(1,7) == "content" then
  2503. local scroll = 0
  2504. conid = tonumber(name:sub(8))
  2505. col.screen("white")
  2506. store.draw.menu("Updates Log")
  2507.  
  2508. draw.box(1, 51, 19, 1, " ", "grey", "grey")
  2509. draw.texta("Back", 2, 19, false, "lightBlue", "grey")
  2510. draw.textr("Scroll enabled ", 19, false, "orange", "grey")
  2511.  
  2512. pagecontent = data.wordwrap(tData[conid].content, 49)
  2513.  
  2514. local function run(scroll)
  2515. for i=1, 14 do
  2516. if #pagecontent >= i + scroll then
  2517. draw.box(1, 51, i+3, 1, " ", "white", "white")
  2518. draw.textl(pagecontent[i+scroll], i+3, false, "cyan", "white")
  2519. else
  2520. break
  2521. end
  2522. end
  2523. end
  2524.  
  2525. run(scroll)
  2526.  
  2527. while true do
  2528. local args = { os.pullEvent() }
  2529. if args[1] == "timer" then
  2530. store.draw.menu("Updates Log")
  2531. elseif args[1] == "mouse_click" then
  2532. if args[4] >= 1 and args[4] <= 2 then
  2533. store.draw.menu_input("Updates Log", args[3], args[4])
  2534. elseif (args[3] >= 2 and args[3] <= 5) and args[4] == 19 then
  2535. store.updates("menu")
  2536. end
  2537. elseif args[1] == "mouse_scroll" then
  2538. if args[2] == -1 then
  2539. if scroll > 0 then
  2540. scroll = scroll - 1
  2541. run(scroll)
  2542. end
  2543. elseif args[2] == 1 then
  2544. if scroll + 14 < #pagecontent then
  2545. scroll = scroll + 1
  2546. run(scroll)
  2547. end
  2548. end
  2549. end
  2550. end
  2551. else
  2552. local scroll = 0
  2553. col.screen("white")
  2554. store.draw.menu("Updates Log")
  2555.  
  2556. draw.box(1, 51, 19, 1, " ", "grey", "grey")
  2557. draw.textc("Update Logs: "..tostring(#tData), 19, false, "lightBlue", "grey")
  2558.  
  2559. local function fix(num)
  2560. if tostring(num):len() == 1 then
  2561. return " "..tostring(num)
  2562. else
  2563. return tostring(num)
  2564. end
  2565. end
  2566.  
  2567. local function run(scroll)
  2568. for i=1, 14 do
  2569. if #tData >= i + scroll then
  2570. draw.texta(tostring(fix(i+scroll)) .. ": " .. tData[i+scroll].name, 1, i+3, false, "cyan", "white")
  2571. else
  2572. break
  2573. end
  2574. end
  2575. end
  2576.  
  2577. run(scroll)
  2578.  
  2579. while true do
  2580. local args = { os.pullEvent() }
  2581. if args[1] == "timer" then
  2582. store.draw.menu("Updates Log")
  2583. elseif args[1] == "mouse_click" then
  2584. if args[4] >= 1 and args[4] <= 2 then
  2585. store.draw.menu_input("Help / FAQ", args[3], args[4])
  2586. elseif (args[3] >= 1 and args[3] <= 51) and (args[4] >= 4 and args[4] <= 19) then
  2587. -- Get current option
  2588. local curid = args[4] - 3 + scroll
  2589. if curid <= #tData then
  2590. store.updates("content"..tostring(curid))
  2591. end
  2592. end
  2593. elseif args[1] == "mouse_scroll" then
  2594. if args[2] == -1 then
  2595. if scroll > 0 then
  2596. scroll = scroll - 1
  2597. run(scroll)
  2598. end
  2599. elseif args[2] == 1 then
  2600. if scroll + 14 < #tData then
  2601. scroll = scroll + 1
  2602. run(scroll)
  2603. end
  2604. end
  2605. end
  2606. end
  2607. end
  2608. end
  2609.  
  2610. function store.credits()
  2611. col.screen("white")
  2612. store.draw.menu("Credits")
  2613. 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."
  2614. for k,v in ipairs(data.wordwrap(text, 51)) do
  2615. draw.textl(v, k+3, false, "grey", "white")
  2616. end
  2617.  
  2618. draw.box(1, 51, 19, 1, " ", "grey" , "grey")
  2619. draw.textc("Press the \"X\" in the taskbar to close", 19, false, "orange", "grey")
  2620.  
  2621. while true do
  2622. local args = { os.pullEvent() }
  2623. if args[1] == "timer" then
  2624. store.draw.menu("Credits")
  2625. elseif args[1] == "mouse_click" then
  2626. if args[4] >= 1 and args[4] <= 2 then
  2627. store.draw.menu_input("Home", args[3], args[4])
  2628. end
  2629. end
  2630. end
  2631. end
  2632.  
  2633. -- Run Discover Init
  2634.  
  2635. if downloadapi then
  2636. store.init()
  2637. else
  2638. print("Discover Crashed")
  2639. sleep(2)
  2640. shell.run("shell")
  2641. end
  2642. term.clear()
  2643. term.setCursorPos(1, 1)
Add Comment
Please, Sign In to add comment