JustDoesGames

beta_freeware

Dec 14th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 59.42 KB | None | 0 0
  1. -----------------
  2. -- OS Freeware --
  3. ---------------------------------------
  4. -- Built simple and open for the user --
  5. ---------------------------------------
  6. ---------------------
  7. -- Created by      --
  8. -- Just Does Games --
  9. ---------------------
  10.  
  11.  
  12. if not term.isColor() then print("Advanced Computer Only") return end
  13.  
  14. local wl, wh = 51,19
  15. w,h = term.getSize()
  16. if w ~= wl or h ~= wh then print("Computer need to be "..wl.." by "..wh) return end
  17.  
  18.  
  19. -- Pre init --
  20.  
  21. local function setText(col) return term.setTextColor(colors[col]) end
  22. local function setBack(col) return term.setBackgroundColor(colors[col]) end
  23.  
  24. local function cp(x,y)
  25.     if x ~= nil and y ~= nil then
  26.         term.setCursorPos(x,y)
  27.     end
  28. end
  29.  
  30. local function clr()
  31.     term.clear()
  32. end
  33.  
  34. local dir = "/freeware/"
  35. local version = "OS Freeware 1.6"
  36.  
  37. --[[
  38.  
  39. version info:
  40.  
  41.  
  42. 1.1 (12/10/19)
  43. - init launch
  44.  
  45.  
  46. 1.2 (12/11/19)
  47. - fixed most obvious errors (moved some info below)
  48.  
  49.  
  50. 1.3 (12/13/19)
  51. -- General --
  52. - fixed sprite download error (loop endlessly)
  53. - created a directory for freeware things
  54. - redid app loading so implementing apps that modify apps are easier (Desktop app)
  55. - added page info next to home button (current page / max page)
  56.  
  57. -- Apps --
  58. - added 'System Info' app to display info about the system you are on
  59. - added 'Dino' (Buggy but made in within an hour)
  60. - added 'Desktop' app for managing apps on the desktop (coming soon)
  61.  
  62. -- File System --
  63. - you are now able to clear bin from the app directly
  64. - fixed bug where the last of a folder did not display at all
  65.  
  66.  
  67.  
  68. 1.4 (12/14/12 -> 12/15/19)
  69. -- General --
  70. - changed page number text color to black
  71. - apps can now be moved around and toggled on and off using the 'Desktop' app
  72. - fixed crash when no app is present
  73. - fixed some minor bugs
  74.  
  75. -- Apps --
  76. - added 'Desktop' app finally released at a stable point (new versions to come)
  77.  
  78. -- File System --
  79. - fixed bug where computer would crash clearing the bin
  80.  
  81. -- Homebrew --
  82. - fixed glitch that shows data from last app ran
  83.  
  84. -- Dino --
  85. - fixed collision with player and pilon
  86. - sprites for the dino and pillars are now boxes instead of letters and symbols
  87.  
  88.  
  89.  
  90. 1.5 (12/16/19)
  91. -- General --
  92. - patched some minor things on other apps
  93. - fixed bug where homebrew displays without the last bar (if 'Homebrew.nfp' doesn't exists)
  94. - app icons now need to be exactly 6x8 and cannot exeed 60 bytes
  95. - fixed issue where icons failed to download/update after deleting and restarting the computer
  96. - app icons no longer need to be downloaded from a separate file
  97. - fixed minor bug with boot logo
  98.  
  99. -- Apps --
  100. - added 'Landslide' app
  101. - soon to be added custom app addition where users can add their own programs to the desktop (can be added/removed using 'Desktop' app)
  102.  
  103. -- Desktop --
  104. - now compatable with touch
  105. - fixed issue where apps would duplicate
  106. - fixed apps losing the space in their names losing the app image
  107. - background color is alternative for easier read and better design
  108.  
  109. -- File System --
  110. - fixed major bug where the back button did not display! (opens 'rom' up to be explored)
  111.  
  112. -- System Info --
  113. - fixed bug where 'System OS version' did not display
  114. - peripherals now display on only 2 lines instead of 4 to fix the bug above and to open more room
  115. - added 'OS size' to give an idea of how much space the OS takes up
  116.  
  117.  
  118.  
  119. 1.6 (12/17/19)
  120. -- General --
  121. - nothin much yet, just some small patches, tweaks, and ideas to the base of the os
  122. - pressing 'f1' at boot screen exits to shell (like a bios screen)
  123. - 'System Info' and 'Lua' have been added to the home menu
  124. - style for the home menu has been changed to gray and lightblue
  125. - if a default app is missing from the computer on boot, the computer adds it back to the desktop (ONLY FOR DEFAULT APPS)
  126.  
  127. -- Apps --
  128. - added 'Emu Data' for users using the ccemux emulator
  129. - new app called 'UPM' still under development soon to be added to manage apps
  130. - new 'Settings' app soon to be in development
  131. - might consider a 'Peripheral' app
  132. - highly considering reverting back to an older version of the 'Desktop' app and updating it
  133.  
  134. -- File System --
  135. - fixed oversight where the user can delete a file and crash the system do to it not existing anymore
  136.  
  137. -- Desktop --
  138. - fixed graphical issue when moving apps
  139.  
  140.  
  141. ]]
  142.  
  143. clr()
  144.  
  145. local dimg = {
  146.  
  147. {
  148. "boot",
  149. "",
  150. " 5557   777777  777777",
  151. "555557 cccccc7 cccccc",
  152. "  c7   c7   c7 c7",
  153. "  c7   c7   c7 c777777",
  154. "  c7   c7   c7 cccccc7",
  155. "  c7   c7   c7      c7",
  156. "  c7777c7777c7  7777c7",
  157. "  ccccccccccc  cccccc",
  158. "",
  159. " 777777777777777777777777777777777777777777777",
  160. " 700007000077000070000707777070000700007700007",
  161. " 707777077077077770777707777070770707707707777",
  162. " 700077000077000770007707007070000700007700077",
  163. " 707777077707077770777707007070770707770707777",
  164. " 707777077707000070000700000070770707770700007",
  165. " 777777777777777777777777777777777777777777777"},
  166.  
  167. {
  168. "console",
  169. "11111111",
  170. "10fffff1",
  171. "1f0ffff1",
  172. "10ff00f1",
  173. "1ffffff1",
  174. "11111111"},
  175.  
  176. {
  177. "Crash",
  178. "  bbbb",
  179. " b0000b",
  180. "bb0bbbbb",
  181. "bb0bbbbb",
  182. " b0000b",
  183. "  bbbb"
  184. },
  185.  
  186. {
  187. "Desktop",
  188. "77777777",
  189. "7e717477",
  190. "77777777",
  191. "757b7a77",
  192. "77777777",
  193. "d3333333"
  194. },
  195.  
  196. {
  197. "Dino",
  198. "77777777",
  199. "7ffffff7",
  200. "7f0ffff7",
  201. "7ffff8f7",
  202. "70000007",
  203. "77777777"
  204. },
  205.  
  206. {
  207. "file",
  208. "0000",
  209. "00000",
  210. "00000",
  211. "00000",
  212. "00000"
  213. },
  214.  
  215. {
  216. "Files",
  217. "48884444",
  218. "48884444",
  219. "44444444",
  220. "44444444",
  221. "43333334",
  222. "43444434"
  223. },
  224.  
  225. {
  226. "folder",
  227. "4444",
  228. "44444",
  229. "44444",
  230. "44444",
  231. "44444"
  232. },
  233.  
  234. {
  235. "Homebrew",
  236. "90999909",
  237. "90999909",
  238. "90000009",
  239. "90000009",
  240. "90999909",
  241. "90999909"
  242. },
  243.  
  244. {
  245. "IconEditor",
  246. "43333333",
  247. "33ddd333",
  248. "3ddddd33",
  249. "333c3333",
  250. "333c3333",
  251. "55555555"
  252. },
  253.  
  254. {
  255. "Lua",
  256. "  bbbb",
  257. " b0bbbb",
  258. "bb0bbbbb",
  259. "bb0bbbbb",
  260. " b0000b",
  261. "  bbbb"
  262. },
  263.  
  264. {
  265. "noTexture",
  266. "bbbbbbbb",
  267. "bbb0bbbb",
  268. "b0b0bbbb",
  269. "b0b0b0bb",
  270. "b0b0b0bb",
  271. "bbbbbbbb"
  272. },
  273.  
  274. {
  275. "Pastebin",
  276. " 000000",
  277. "08887000",
  278. "08087770",
  279. "08887070",
  280. "08007770",
  281. " 000000"
  282. },
  283.  
  284. {
  285. "Reboot",
  286. " 77777",
  287. " 71117",
  288. " 71717",
  289. " 71117",
  290. " 71777",
  291. " 777"
  292. },
  293.  
  294. {
  295. "ShellOS",
  296. "11111111",
  297. "10fffff1",
  298. "1f0ffff1",
  299. "10ff00f1",
  300. "1ffffff1",
  301. "11111111"
  302. },
  303.  
  304. {
  305. "Shutdown",
  306. "  77777",
  307. "  7eee7",
  308. "  7e7e7",
  309. "  7eee7",
  310. "  7e777",
  311. "  777"
  312. },
  313.  
  314. {
  315. "SystemInfo",
  316. "44444444",
  317. "87000078",
  318. "87700778",
  319. "87700778",
  320. "87000078",
  321. "44444444"
  322. },
  323.  
  324. {
  325. "Worm",
  326. " 777777",
  327. "7777ddd7",
  328. "7e77d777",
  329. "7777d777",
  330. "7dddd7e7",
  331. " 777777"
  332. },
  333.  
  334. {
  335. "Adventure",
  336. " 777777",
  337. "77000077",
  338. "77077077",
  339. "77000077",
  340. "77077077",
  341. " 777777"
  342. },
  343.  
  344. {
  345. "Landslide",
  346. " cccccc ",
  347. "cc0ccccc",
  348. "cc0ccccc",
  349. "cc0ccccc",
  350. "cc0000cc",
  351. " cccccc "
  352. },
  353.  
  354. {
  355. "EmuData",
  356. " 788887 ",
  357. "74444447",
  358. "84444448",
  359. "84333348",
  360. "74344347",
  361. " 788887 "
  362. }
  363.  
  364. }
  365. local sprite_dir = dir.."sprites/"
  366.  
  367.  
  368. if not fs.exists(dir) or not fs.exists(dir.."sprites") then -- download images
  369.     setText("black") setBack("black") cp(1,-4)
  370.    
  371.     if fs.exists("freeware/sprites/imageDownload.lua") then -- passed
  372.         shell.run("freeware/sprites/imageDownload.lua")
  373.     else -- failed
  374.         parallel.waitForAny(function() sleep(5) end, function() shell.run("pastebin get ym6K6bLU freeware/sprites/imageDownload.lua") end)
  375.         if fs.exists("freeware/sprites/imageDownload.lua") then -- passed
  376.             shell.run("pastebin run LYMPVbUw")
  377.         else -- failed
  378.             -- nothing
  379.         end
  380.     end
  381. end
  382.  
  383.  
  384. for i=1, #dimg do
  385.     if not fs.exists(sprite_dir..dimg[i][1]..".nfp") then
  386.         local file = fs.open(sprite_dir..dimg[i][1]..".nfp", "w")
  387.         for ii=1, #dimg[i]-1 do
  388.             file.writeLine(dimg[i][ii+1])
  389.         end
  390.         file.close()
  391.     end
  392. end
  393.  
  394.  
  395. -- Boot Screen --
  396.  
  397. clr()
  398. local boot = paintutils.loadImage(sprite_dir.."boot.nfp")
  399. paintutils.drawImage(boot,2,2)
  400. local bypass = 0
  401. parallel.waitForAny(function() sleep(1) end, function() repeat a,bypass = os.pullEvent("key") until bypass == 59 end)
  402. if bypass ~= 0 then if bypass == 59 then setText("white") setBack("black") clr() cp(1,1) return print("Bypass") end end
  403.  
  404. -- Boot Screen --
  405.  
  406.  
  407. noTexture = paintutils.loadImage(sprite_dir.."noTexture.nfp")
  408. fileTexture = paintutils.loadImage(sprite_dir.."file.nfp")
  409. folderTexture = paintutils.loadImage(sprite_dir.."folder.nfp")
  410.  
  411. if noTexture == nil then error("Failed to load noTexture") end
  412.  
  413. maxAppName = 12
  414.  
  415. function loadApp(name, path)
  416.     if type(name) ~= "string" then return error("Expected string for name, got "..type(name)) end
  417.     if type(path) ~= "string" then return error("Expected string for path, got "..type(path)) end
  418.     if string.len(name) >= maxAppName then return false end
  419.    
  420.     if fs.exists(path..".nfp") then
  421.         if fs.getSize(path..".nfp") <= 60 then
  422.             local file = fs.open(path..".nfp","r")
  423.             local preLoad = {}
  424.             local tmp
  425.             repeat
  426.                 tmp = file.readLine()
  427.                 if tmp ~= nil then preLoad[#preLoad+1] = tmp end
  428.             until tmp == nil
  429.             file.close()
  430.             local longestTerm = 1
  431.             for i=1, #preLoad do
  432.                 if string.len(preLoad[i]) > longestTerm then longestTerm = string.len(preLoad[i]) end
  433.             end
  434.             if #preLoad <= 6 and longestTerm <= 8 then
  435.                 apps[#apps+1] = {name, paintutils.loadImage(path..".nfp")}
  436.             end
  437.         end
  438.     else
  439.         apps[#apps+1] = {name, noTexture}
  440.     end
  441. end
  442.  
  443.  
  444. -- OS --
  445.  
  446. bar_color = "lightBlue"
  447. home_color = "green"
  448. desktop_color = "black"
  449. scroll_color = "gray"
  450. scroll_text_color = "white"
  451. title_color = "white"
  452. home_menu_color = "gray"
  453. home_menu_text_color = "lightBlue"
  454.  
  455. dScroll = true
  456. dBar = true
  457. dApps = true
  458. home = false
  459.  
  460. local debug = false
  461. local running = true
  462. local update = true
  463.  
  464. apps = {}
  465. loaded_apps = {}
  466. user_apps = {}
  467. app_selected = 1
  468.  
  469. local load_order = {}
  470. local app_dir = dir.."apps/"
  471.  
  472. local tmp_lo = {}
  473. local tmp_s = {}
  474.  
  475. local default_apps = {"ShellOS", "Homebrew", "Desktop", "Files", "UPM", "Pastebin", "Lua", "Reboot", "Shutdown", "System Info", "Worm", "Adventure", "Dino", "Landslide", "Crash", "Connect"}
  476.  
  477. if fs.exists(app_dir.."load_order.lua") then
  478.     local file = fs.open(app_dir.."load_order.lua","r")
  479.     repeat
  480.         tmp = file.readLine()
  481.         if tmp ~= nil then
  482.             tmp_lo[#tmp_lo+1] = tmp
  483.         end
  484.     until tmp == nil
  485.     file.close()
  486. else
  487.     tmp_lo = default_apps
  488.     local a,i = pcall(function() ccemux.getVersion() end)
  489.     if a then
  490.         table.insert(tmp_lo, "Emu Data")
  491.     end
  492. end
  493.  
  494. for i=1, #default_apps do
  495.     local exists = false
  496.     for ii=1, #tmp_lo do
  497.         if tmp_lo[ii] == default_apps[i] then exists = true end
  498.     end
  499.     if not exists then
  500.         table.insert(tmp_lo, default_apps[i])
  501.     end
  502. end
  503.  
  504. if fs.exists(app_dir.."status.lua") then
  505.     local file = fs.open(app_dir.."status.lua","r")
  506.     repeat
  507.         tmp = file.readLine()
  508.         if tmp ~= nil then
  509.             tmp_s[#tmp_s+1] = tonumber(tmp)
  510.         end
  511.     until tmp == nil
  512.     file.close()
  513. else
  514.     tmp_s = {}
  515.     for i=1, #tmp_lo do tmp_s[#tmp_s+1] = 1 end
  516. end
  517.  
  518. if #tmp_s < #tmp_lo then
  519.     for i=1, #tmp_lo-#tmp_s do
  520.         table.insert(tmp_s, 1.0)
  521.     end
  522. end
  523.  
  524. --[[
  525. if fs.exists(app_dir.."user_apps.lua") then
  526.     local file = fs.open(app_dir.."user_apps.lua","r")
  527.     repeat
  528.         tmp = file.readLine()
  529.         tmp2 = file.readLine()
  530.         if tmp ~= nil and tmp2 ~= nil then
  531.             user_apps[#user_apps+1] = {0, tmp, tmp2}
  532.         end
  533.     until tmp == nil or tmp2 == nil
  534.     file.close()
  535. end
  536. ]]
  537.  
  538.  
  539.  
  540. function loadUserApps()
  541.     user_apps = {}
  542.     if fs.exists(app_dir.."user_apps.lua") then
  543.         local file = fs.open(app_dir.."user_apps.lua", "r")
  544.         repeat
  545.             tmp = file.readLine()
  546.             tmp2 = file.readLine()
  547.             if tmp ~= nil then
  548.                 table.insert(user_apps, {0,tmp,tmp2})
  549.             end
  550.         until tmp == nil
  551.         file.close()
  552.         return true
  553.     end
  554.     return false
  555. end
  556.  
  557. function saveUserApps()
  558.     if fs.exists(app_dir.."user_apps.lua") then fs.delete(app_dir.."user_apps.lua") end
  559.     local file = fs.open(app_dir.."user_apps.lua", "w")
  560.     for i=1, #user_apps do
  561.         file.writeLine(user_apps[i][2])
  562.         file.writeLine(user_apps[i][3])
  563.     end
  564.     file.close()
  565. end
  566.  
  567. loadUserApps()
  568.  
  569. function updateApps(new_load_order, new_status)
  570.     load_order = {}
  571.     apps = {}
  572.     local skip = false
  573.     for i=1, #new_load_order do
  574.         for ii=1, #load_order do
  575.             if new_load_order[i][1] == load_order[ii][1] then
  576.                 skip = true
  577.             end
  578.         end
  579.         if not skip then
  580.             if new_status ~= nil then
  581.                 table.insert(load_order, {new_load_order[i], new_status[i]})
  582.             else
  583.                 table.insert(load_order, {new_load_order[i][1], new_load_order[i][2]})
  584.             end
  585.             if new_status ~= nil then
  586.                 if new_status[i] == 1 then loadApp(new_load_order[i], sprite_dir..new_load_order[i]) end
  587.             else
  588.                 if new_load_order[i][2] == 1 then loadApp(new_load_order[i][1], sprite_dir..new_load_order[i][1]) end
  589.             end
  590.         else
  591.             skip = false
  592.         end
  593.     end
  594.     for i=1, #user_apps do
  595.         if user_apps[i][2] == load_order[i][1] then
  596.             user_apps[i][1] = i
  597.         end
  598.     end
  599.     maxPage = math.ceil(#apps/6)
  600.     current_page = 1
  601. end
  602.  
  603. -- Load Order Contains: {name, status} (for each app)
  604. updateApps(tmp_lo, tmp_s)
  605.  
  606. function AppIndex(name)
  607.     for i=1, #load_order do
  608.         if load_order[i][1] == name then
  609.             return i
  610.         end
  611.     end
  612.     return false
  613. end
  614.  
  615. function toggleApp(name)
  616.     name = AppIndex(name)
  617.     if name == false then return false end
  618.     if load_order[name][2] ~= nil then
  619.         if load_order[name][2] == 1 then
  620.             load_order[name][2] = 0
  621.         else
  622.             load_order[name][2] = 1
  623.         end
  624.     end
  625. end
  626.  
  627.  
  628. --toggleApp("Homebrew")
  629. --toggleApp("Shutdown")
  630. --toggleApp("Desktop")
  631.  
  632. --[[
  633. for i=1, 31 do
  634.     load_order[#load_order+1] = {"Debug "..i, 1}
  635. end
  636. updateApps(load_order)
  637. ]]
  638.  
  639. function appLoader()
  640.     apps = {}
  641.     for i=1, #load_order do
  642.         if load_order[i][2] == 1 then
  643.             loadApp(load_order[i][1], sprite_dir..string.gsub(load_order[i][1], " ", ""))
  644.         end
  645.     end
  646. end
  647.  
  648. appLoader()
  649.  
  650.  
  651. for i=1, 6 do
  652.     loaded_apps[i] = apps[i]
  653. end
  654.  
  655.  
  656.  
  657. maxPage = math.ceil(#apps/6)
  658. current_page = 1
  659. if #apps == 0 then error("no apps loaded") end
  660.  
  661.  
  662. --[[
  663. print("Apps: "..#apps)
  664. print("Pages: "..maxPage)
  665. print("Current Page: "..current_page)
  666. print("Apps/Current Page: "..#apps/current_page)
  667. error()
  668. ]]
  669.  
  670.  
  671. function drawBar()
  672.     if dBar then
  673.         cp(1,h)
  674.         setBack(home_color)
  675.         write(" ")
  676.         setBack(bar_color)
  677.         for i=1, w-1 do
  678.             write(" ")
  679.         end
  680.         setText("black") cp(2,h) write(current_page.."/"..maxPage)
  681.     else
  682.         cp(1,h)
  683.         setBack(desktop_color)
  684.         term.clearLine()
  685.     end
  686.     cp(1,1)
  687. end
  688.  
  689.  
  690. function drawScreen()
  691.     setBack(desktop_color)
  692.     for i=1, h-1 do
  693.         cp(1,i)
  694.         term.clearLine()
  695.     end
  696.  
  697.     if dScroll then
  698.         setBack(scroll_color)
  699.  
  700.         for i=1, 6 do
  701.             cp(1,h/2-i+4)
  702.             write(" ")
  703.         end
  704.  
  705.         for i=1, 6 do
  706.             cp(w, h/2-i+4)
  707.             write(" ")
  708.         end
  709.  
  710.         setText(scroll_text_color)
  711.  
  712.         cp(1,h/2-3)
  713.         write("<")
  714.         cp(1,h/2+3)
  715.         write("<")
  716.         cp(w,h/2-3)
  717.         write(">")
  718.         cp(w,h/2+3)
  719.         write(">")
  720.     end
  721. end
  722.  
  723. function toggleScroll()
  724.     dScroll = not dScroll
  725. end
  726.  
  727. function toggleBar()
  728.     dBar = not dBar
  729. end
  730.  
  731. function toggleApps()
  732.     dApps = not dApps
  733. end
  734.  
  735. function toggleHome()
  736.     home = not home
  737. end
  738.  
  739. local app_locations = {8,22,36} -- the x positions
  740.  
  741. function updateApps()
  742.     loaded_apps = {}
  743.     for i=1, 6 do
  744.         loaded_apps[i] = apps[i+(6*(current_page-1))]
  745.     end
  746. end
  747.  
  748. function drawApps()
  749.     if dApps then
  750.         setText(title_color) -- just text color (no biggy)
  751.         updateApps()
  752.         for i=1, #loaded_apps do
  753.             if i <= 3 then -- top
  754.                 setBack(desktop_color)
  755.                 cp(app_locations[i], 1) write(loaded_apps[i][1])
  756.                 paintutils.drawImage(loaded_apps[i][2], app_locations[i], 2)
  757.             else -- bottom
  758.                 setBack(desktop_color)
  759.                 cp(app_locations[i-3], h-8) write(loaded_apps[i][1])
  760.                 paintutils.drawImage(loaded_apps[i][2], app_locations[i-3], h-7)
  761.             end
  762.         end
  763.     end
  764. end
  765.  
  766.  
  767. home_options = {"System Info","ShellOS", "Lua", "Reboot", "Shutdown", "Files"}
  768. home_options_lt_f = function()
  769.     local tmp = 1
  770.     for i=1, #home_options do
  771.         if string.len(home_options[i]) > tmp then
  772.             tmp = string.len(home_options[i])
  773.         end
  774.     end
  775.     return tmp
  776. end
  777.  
  778.  
  779. function drawHome()
  780.     if home then
  781.         setBack(home_menu_color)
  782.         setText(home_menu_text_color)
  783.         local tmp = home_options_lt_f()
  784.         for i=1, #home_options do
  785.             cp(1,h-i)
  786.             for i=1, tmp+2 do
  787.                 write(" ")
  788.             end
  789.         end
  790.  
  791.         for i=1, #home_options do
  792.             cp(1,h-i)
  793.             write(home_options[i])
  794.         end
  795.     end
  796. end
  797.  
  798.  
  799.  
  800.  
  801.  
  802.  
  803.  
  804. function updateFiles(fPath)
  805.     local fFiles = fs.list(fPath)
  806.     local directory,readonly,file = {}, {}, {}
  807.     for i=1, #fFiles do
  808.         if fs.isReadOnly(fPath..fFiles[i]) then
  809.             readonly[#readonly+1] = fFiles[i]
  810.         elseif fs.isDir(fPath..fFiles[i]) then
  811.             directory[#directory+1] = fFiles[i]
  812.         else
  813.             file[#file+1] = fFiles[i]
  814.         end
  815.     end
  816.     fFiles = directory
  817.     for i=1, #readonly do
  818.         fFiles[#fFiles+1] = readonly[i]
  819.     end
  820.     for i=1, #file do
  821.         fFiles[#fFiles+1] = file[i]
  822.     end
  823.     return fFiles
  824. end
  825.  
  826. function displayFiles(path, files)
  827.     setText("white")
  828.     local bg = false
  829.     path = path.."/"
  830.  
  831.     for i=1, #files do
  832.         cp(1,i)
  833.         if bg then
  834.             bg = not bg
  835.             setBack("black")
  836.         else
  837.             bg = not bg
  838.             setBack("gray")
  839.         end
  840.  
  841.         if files[i] == "..." then
  842.             setText("orange")
  843.         elseif fs.isReadOnly(path..files[i]) then
  844.             setText("red")
  845.         elseif fs.isDir(path..files[i]) and files[i] == "bin" and path == "/" then
  846.             setText("purple")
  847.         elseif fs.isDir(path..files[i]) then
  848.             setText("yellow")
  849.         else
  850.             setText("white")
  851.         end
  852.         if string.len(files[i]) >= 25 then
  853.             local tmp = string.sub(files[i], 20)
  854.             files[i] = string.gsub(files[i], tmp, "...")
  855.         end
  856.         write(files[i])
  857.         for i=1, math.ceil((w/2-string.len(files[i]))+string.len(files[i])) do
  858.             write(" ")
  859.         end
  860.     end
  861.  
  862.     setText("white")
  863. end
  864.  
  865. function math.round(v, bracket)
  866.     bracket = bracket or 1
  867.     return math.floor(v/bracket + (v >= 0 and 1) or -1 * 0.5) * bracket
  868. end
  869.  
  870. function drawInfoScreen(file, options)
  871.     setBack("black") clr()
  872.     if fs.isDir(file) then
  873.         paintutils.drawImage(folderTexture, 1,1) setBack("black")
  874.         cp(1,8) setText("white") write("File type: ") setText("yellow") write("Directory")
  875.     else
  876.         paintutils.drawImage(fileTexture, 1,1) setBack("black")
  877.     end
  878.     cp(1,9)
  879.     setText("white") write("File Name: ") setText("yellow") print(fs.getName(file))
  880.     setText("white") write("Directory: ") setText("yellow") print(file)
  881.     if not fs.isDir(file) then
  882.         setText("white") write("Size: ") setText("yellow")
  883.         if fs.getSize(file) >= 1000 then
  884.             print(math.round((fs.getSize(file)/1000), 0.1).." KB")
  885.         else
  886.             print(fs.getSize(file).." Bytes")
  887.         end
  888.     end
  889.  
  890.     setBack("gray")
  891.     setText("white")
  892.     for i=1, #options do
  893.         cp(1,12+i)
  894.         write(options[i])
  895.         for i=1, w-string.len(options[i]) do
  896.             write(" ")
  897.         end
  898.     end
  899. end
  900.  
  901. function loadInfo(file)
  902.     local options = {}
  903.     if fs.isDir(file) and file == "/bin" then
  904.         -- Bin Exclusive
  905.         if #fs.list("bin") > 0 then table.insert(options, "Clear Bin") end
  906.     elseif fs.isDir(file) and file ~= "/rom" then
  907.         -- Dir Exclusive
  908.         if not fs.exists("bin/"..fs.getName(file)) then
  909.             table.insert(options, "Delete")
  910.         end
  911.     elseif fs.isReadOnly(file) then
  912.         -- Read Only Exclusive
  913.     elseif string.sub(file, -3) == "nfp" then
  914.         -- Paint Exclusive
  915.         table.insert(options, "Paint")
  916.         table.insert(options, "Edit")
  917.         if not fs.exists("bin/"..fs.getName(file)) then
  918.             table.insert(options, "Delete")
  919.         end
  920.     elseif string.sub(file, -3) == "lua" then
  921.         -- Lua Exclusive
  922.         table.insert(options, "Run")
  923.         table.insert(options, "Edit")
  924.         if not fs.exists("bin/"..fs.getName(file)) then
  925.             table.insert(options, "Delete")
  926.         end
  927.     else
  928.         -- File Exclusive
  929.         table.insert(options, "Run")
  930.         if not fs.exists("bin/"..fs.getName(file)) then
  931.             table.insert(options, "Delete")
  932.         end
  933.     end
  934.     table.insert(options, "Close")
  935.  
  936.     local run = true
  937.     while run do
  938.         if not fs.exists(file) then return false end
  939.         drawInfoScreen(file, options)
  940.  
  941.         a,i,x,y = os.pullEvent("mouse_click")
  942.         if i == 1 then
  943.             if y >= 13 and y <= 12+#options then
  944.                 if options[y] == "Close" then
  945.                     run = false
  946.                 else
  947.                     if options[y-12] == "Edit" then
  948.                         shell.run("edit "..file)
  949.                     elseif options[y-12] == "Paint" then
  950.                         shell.run("paint "..file)
  951.                     elseif options[y-12] == "Run" then
  952.                         setText("white") setBack("black") shell.run(file)
  953.                     elseif options[y-12] == "Delete" then
  954.                         --error()
  955.                         fs.move(file, "/bin/"..fs.getName(file)) run = false
  956.                     elseif options[y-12] == "Clear Bin" then
  957.                         local bin_list = fs.list("/bin/")
  958.                         for i=1, #bin_list do
  959.                             fs.delete("bin/"..bin_list[i])
  960.                         end
  961.                         run = false
  962.                     else
  963.                         run = false
  964.                     end
  965.                 end
  966.             end
  967.         end
  968.     end
  969. end
  970.  
  971. function drawRightClickMenu(xpos, ypos, options)
  972.     --
  973. end
  974.  
  975. function rightClick(xpos, ypos, file)
  976.     loadInfo(file)
  977.  
  978.     -- Add Right Click (4 Quads)
  979.     -- Add Copy
  980.     -- Add Paste
  981.     -- Add Restore
  982.     -- Add Perm Delete
  983.  
  984. end
  985.  
  986. function fileProgram()
  987.  
  988.     local cPath = ""
  989.     local cTable = {}
  990.     local cUpdate = true
  991.     local scroll = 0
  992.     local displayedFiles = {}
  993.     local loadedFiles = {}
  994.  
  995.     local run = true
  996.     while run do
  997.         if cUpdate then
  998.             cUpdate = not cUpdate
  999.             scroll = 0
  1000.             setBack("black") clr()
  1001.             paintutils.drawLine(1,h,w,h,colors["lightGray"])
  1002.             paintutils.drawPixel(w,h,colors["red"])
  1003.  
  1004.             cPath = ""
  1005.             for i=1, #cTable do
  1006.                 cPath = cPath.."/"..cTable[i]
  1007.             end
  1008.  
  1009.             local tmmp = cPath
  1010.             if string.len(cPath) >= 23 then
  1011.                 local tmp = string.sub(cPath, 18)
  1012.                 tmmp = string.gsub(cPath, tmp, "...")
  1013.             end
  1014.  
  1015.             cp(1,h) setBack("lightGray") setText("white") write(tmmp) setBack("black")
  1016.  
  1017.             loadedFiles = updateFiles(cPath)
  1018.             if #cTable > 0 then table.insert(loadedFiles, "...") end
  1019.         end
  1020.  
  1021.         displayedFiles = {}
  1022.         if #loadedFiles <= h-1 then
  1023.             displayedFiles = loadedFiles
  1024.         else
  1025.             for i=1, h-1 do
  1026.                 displayedFiles[#displayedFiles+1] = loadedFiles[i+scroll]
  1027.             end
  1028.         end
  1029.  
  1030.         displayFiles(cPath, displayedFiles)
  1031.  
  1032.         a,i,x,y = os.pullEvent()
  1033.         if a == "mouse_click" then
  1034.             if i == 1 then -- left
  1035.                 if x == w and y == h then
  1036.                     run = false
  1037.                 else
  1038.                     if y <= #displayedFiles--[[ and cPath..displayedFiles[y] ~= "rom" ]]then
  1039.                         if displayedFiles[y] == "..." then
  1040.                             table.remove(cTable, #cTable) cUpdate = true
  1041.                         elseif fs.isDir(cPath.."/"..displayedFiles[y]) then
  1042.                             table.insert(cTable, displayedFiles[y]) cUpdate = true
  1043.                         else
  1044.                             if fs.exists(cPath.."/"..displayedFiles[y]) then
  1045.                                 loadInfo(cPath.."/"..displayedFiles[y])
  1046.                             end
  1047.                             cUpdate = true
  1048.                         end
  1049.                     end
  1050.                 end
  1051.             elseif i == 2 then -- right
  1052.                 if y <= #displayedFiles then
  1053.                     --loadInfo(cPath.."/"..displayedFiles[y]) cUpdate = true
  1054.                     rightClick(x, y, cPath.."/"..displayedFiles[y]) cUpdate = true
  1055.                 end
  1056.             end
  1057.         elseif a == "mouse_scroll" then
  1058.             if i == 1 and scroll ~= #loadedFiles-h+1 then -- down
  1059.                 scroll = scroll + 1
  1060.             elseif i == -1 and scroll ~= 0 then -- up
  1061.                 scroll = scroll - 1
  1062.             end
  1063.         end
  1064.     end
  1065.     update = true
  1066. end
  1067.  
  1068.  
  1069. function playLandslide()
  1070.         -- Landslide --
  1071.     -- Just Does Games --
  1072.  
  1073.     term.clear()
  1074.  
  1075.     local x,y = term.getSize()
  1076.     local px = math.ceil(x/2)
  1077.     local rocks = {} -- Rock Data: {rock x, rock y, id}
  1078.     local maxRocks = 100
  1079.     local run = true
  1080.     local difficulty = {.1,.4}
  1081.     local gamespeed = 0.3
  1082.     local score = 0
  1083.     local maxGamespeed = 0.01
  1084.     local maxScore = 999999999
  1085.     local alt = true
  1086.  
  1087.     local function drawRedBar()
  1088.         term.setCursorPos(1,y-3)
  1089.         term.setBackgroundColor(colors["red"])
  1090.         term.clearLine() print("")
  1091.         term.clearLine()
  1092.     end
  1093.  
  1094.     local function drawRocks()
  1095.         if score > 500 then
  1096.             -- Do nothing
  1097.         elseif score > 400 then
  1098.             if alt then
  1099.                 term.setCursorPos(1,y-3)
  1100.                 for i=1, math.floor(x/2) do
  1101.                     write(" !")
  1102.                 end
  1103.                 term.setCursorPos(1,y-2)
  1104.                 for i=1, math.floor(x/2) do
  1105.                     write("! ")
  1106.                 end
  1107.             else
  1108.                 term.setCursorPos(1,y-3)
  1109.                 for i=1, math.floor(x/2) do
  1110.                     write("  ")
  1111.                 end
  1112.                 term.setCursorPos(1,y-2)
  1113.                 for i=1, math.floor(x/2) do
  1114.                     write("  ")
  1115.                 end
  1116.             end
  1117.             alt = not alt
  1118.         end
  1119.         for i=1, #rocks do
  1120.             term.setCursorPos(rocks[i][1],rocks[i][2]) term.setBackgroundColor(colors["lightGray"]) write(" ")
  1121.             if rocks[i][2] ~= y+1 then
  1122.                 term.setCursorPos(rocks[i][1],rocks[i][2]-1) term.setBackgroundColor(colors["black"]) write(" ")
  1123.             end
  1124.             if rocks[i] ~= nil then
  1125.                 if px == rocks[i][1] and rocks[i][2] == y then run = false end
  1126.             end
  1127.         end
  1128.         if score > 500 then
  1129.             drawRedBar()
  1130.         end
  1131.     end
  1132.  
  1133.     local function drawPlayer()
  1134.         term.setCursorPos(px,y) term.setBackgroundColor(colors["white"]) write(" ")
  1135.         if px ~= x then
  1136.         term.setCursorPos(px+1,y) term.setBackgroundColor(colors["black"]) write(" ")
  1137.         end
  1138.         if px ~= 1 then
  1139.             term.setCursorPos(px-1,y) term.setBackgroundColor(colors["black"]) write(" ")
  1140.         end
  1141.     end
  1142.     drawPlayer()
  1143.  
  1144.     local function spawnRock()
  1145.         if maxRocks ~= #rocks then
  1146.             table.insert(rocks, {math.random(1,x),0})
  1147.         end
  1148.     end
  1149.  
  1150.     local function destroyRock(rock)
  1151.         term.setCursorPos(rock[1],rock[2]) term.setBackgroundColor(colors["black"]) write(" ")
  1152.         table.remove(rocks, 1)
  1153.         if score ~= maxScore then score = score + 1 end
  1154.         if gamespeed < maxGamespeed then
  1155.             if score > 200 then
  1156.                 gamespeed = gamespeed - 0.01
  1157.             elseif score > 400 then
  1158.                 gamespeed = gamespeed - 0.02
  1159.             else
  1160.                 gamespeed = gamespeed - 0.03
  1161.             end
  1162.         elseif gamespeed < 0 then
  1163.             gamespeed = maxGamespeed
  1164.         end
  1165.     end
  1166.  
  1167.     local function engine1() -- player location
  1168.         while run do
  1169.             sleep(.0001)
  1170.             local a,i = os.pullEvent("key")
  1171.             if a == "key" then
  1172.                 if i == keys.a or i == keys.left then
  1173.                     if px ~= 1 then
  1174.                         px = px - 1
  1175.                     end
  1176.                 elseif i == keys.d or i == keys.right then
  1177.                     if px ~= x then
  1178.                         px = px + 1
  1179.                     end
  1180.                 end
  1181.             end
  1182.            
  1183.             for i=1, #rocks do
  1184.                 if rocks[i] ~= nil then
  1185.                     if px == rocks[i][1] and rocks[i][2] == y then run = false end
  1186.                 end
  1187.             end
  1188.             drawPlayer()
  1189.         end
  1190.     end
  1191.  
  1192.     local function engine2() -- rock spawner
  1193.         while true do
  1194.             sleep(math.random(difficulty[1],difficulty[2]))
  1195.             spawnRock()
  1196.         end
  1197.     end
  1198.  
  1199.     local function engine3() -- rock manager
  1200.         while run do
  1201.             local rocksToDestroy = {}
  1202.             for i=1, #rocks do
  1203.                 if rocks[i] ~= nil then
  1204.                     if rocks[i][2] ~= y+1 then
  1205.                         rocks[i][2] = rocks[i][2] + 1
  1206.                     else
  1207.                         table.insert(rocksToDestroy, rocks[i])
  1208.                     end
  1209.                 end
  1210.             end
  1211.             drawRocks()
  1212.            
  1213.             for i=1, #rocksToDestroy do
  1214.                 destroyRock(rocksToDestroy[i])
  1215.             end
  1216.             for i=1, #rocks do
  1217.                 if rocks[i] ~= nil then
  1218.                     if px == rocks[i][1] and rocks[i][2] == y then run = false end
  1219.                 end
  1220.             end
  1221.             sleep(gamespeed)
  1222.         end
  1223.     end
  1224.  
  1225.     local function gameover()
  1226.         sleep(.5)
  1227.         term.setTextColor(colors["white"])
  1228.         term.setBackgroundColor(colors["black"])
  1229.         term.clear()
  1230.         term.setCursorPos(x/2-(string.len("Game Over")/2), y/2-1)
  1231.         write("Game Over")
  1232.         term.setCursorPos(x/2-(string.len("Score - "..score)/2), y/2)
  1233.         write("Score - "..score)
  1234.         sleep(1)
  1235.         term.setCursorPos(x/2-(string.len("Press any key to exit...")/2), y/2+3)
  1236.         write("Press any key to exit...")
  1237.         os.pullEvent()
  1238.     end
  1239.  
  1240.     local function loop()
  1241.         parallel.waitForAny(engine1,engine2,engine3)
  1242.         gameover()
  1243.     end
  1244.  
  1245.     loop()
  1246. end
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252. function playDino()
  1253.  
  1254.     -- Dino Jump --
  1255.     -- Just Does Games --
  1256.  
  1257.     local x,y = term.getSize()
  1258.     local objects = {} -- {x pos, y pos, col}
  1259.     local objMax = 10
  1260.     local objSpawnSpeed = {1.1,3.3}
  1261.     local score = 0
  1262.     local jumps = 0
  1263.     local speed = .09
  1264.  
  1265.     local _px,_py = 2,y-1
  1266.  
  1267.     local s_object = "I"
  1268.  
  1269.     local run = true
  1270.  
  1271.     term.setTextColor(colors["white"])
  1272.     term.clear()
  1273.  
  1274.     local function drawObjects()
  1275.         for i=1, #objects do
  1276.             term.setCursorPos(objects[i][1], objects[i][2]) setBack("lightGray") write(" ") setBack("black")
  1277.             if objects[i][2] ~= w then
  1278.                 term.setCursorPos(objects[i][1]+1, objects[i][2]) write(" ")
  1279.             end
  1280.             if objects[i][1] == _px and objects[i][2] == _py then
  1281.                 run = false
  1282.             end
  1283.         end
  1284.     end
  1285.  
  1286.     local function drawDino()
  1287.         term.setCursorPos(_px,_py) setBack("white") write(" ") setBack("black")
  1288.         term.setCursorPos(_px,_py-1) write(" ")
  1289.         if _py ~= y-1 then
  1290.             term.setCursorPos(_px,_py+1) write(" ")
  1291.         end
  1292.         term.setCursorPos(1,1)
  1293.         print("Score: "..score)
  1294.         print("Jumps: "..jumps)
  1295.     end
  1296.  
  1297.     drawDino()
  1298.     paintutils.drawLine(1,y,x,y,colors["white"])
  1299.     term.setBackgroundColor(colors["black"])
  1300.  
  1301.     local function createObject()
  1302.         if #objects < objMax then
  1303.             table.insert(objects, {x,y-1,"yellow"})
  1304.         end
  1305.     end
  1306.  
  1307.     local function destroyObject()
  1308.         term.setCursorPos(objects[1][1],objects[1][2]) write(" ")
  1309.         table.remove(objects,1)
  1310.         score = score + 1
  1311.         if score > 50 then
  1312.             speed = 0.04
  1313.             objSpawnSpeed = {.8,1.3}
  1314.         elseif score > 30 then
  1315.             speed = 0.05
  1316.             objSpawnSpeed = {.9,1.5}
  1317.         elseif score > 20 then
  1318.             speed = 0.06
  1319.             objSpawnSpeed = {1,2}
  1320.         elseif score > 10 then
  1321.             speed = 0.07
  1322.             objSpawnSpeed = {1.1,3.3}
  1323.         elseif score > 5 then
  1324.             speed = 0.08
  1325.             objSpawnSpeed = {1.1,3.3}
  1326.         end
  1327.     end
  1328.  
  1329.     local function engine1() -- player & col
  1330.         while run do
  1331.             sleep(.0001)
  1332.             local a,i = os.pullEvent("key")
  1333.             if i == keys.space then
  1334.                 jumps = jumps + 1
  1335.                 _py = _py - 1 drawDino() sleep(.1)
  1336.                 _py = _py - 1 drawDino() sleep(.1)
  1337.                 _py = _py - 1 drawDino() sleep(.2)
  1338.                 _py = _py + 1 drawDino() sleep(.1)
  1339.                 _py = _py + 1 drawDino() sleep(.1)
  1340.                 _py = _py + 1 drawDino() sleep(.05)
  1341.                 term.setCursorPos(1,1)
  1342.                 print("Score: "..score)
  1343.                 print("Jumps: "..jumps)
  1344.                 for i=1, #objects do
  1345.                     if objects[i][1] == _px and objects[i][2] == _py then
  1346.                         run = false
  1347.                     end
  1348.                 end
  1349.             elseif i == keys.q then
  1350.                 run = false
  1351.             end
  1352.         end
  1353.     end
  1354.  
  1355.     local function engine2() -- objects
  1356.         while true do
  1357.             sleep(math.random(objSpawnSpeed[1],objSpawnSpeed[2]))
  1358.             createObject()
  1359.         end
  1360.     end
  1361.  
  1362.     local function engine3() -- object spawn and despawn
  1363.         while run do
  1364.             if #objects > 0 then
  1365.                 for i=1, #objects do
  1366.                     if objects[i] ~= nil then
  1367.                         if objects[i][1] == 1 then
  1368.                             destroyObject()
  1369.                         else
  1370.                             objects[i][1] = objects[i][1] - 1
  1371.                         end
  1372.                     end
  1373.                 end
  1374.                 drawObjects()
  1375.             end
  1376.             sleep(speed)
  1377.             for i=1, #objects do
  1378.                 if objects[i][1] == _px and objects[i][2] == _py then
  1379.                     run = false
  1380.                 end
  1381.             end
  1382.         end
  1383.     end
  1384.  
  1385.     local function gameover()
  1386.         term.clear()
  1387.         term.setCursorPos(x/2-string.len("Game Over")/2,y/2-3)
  1388.         write("Game Over")
  1389.         term.setCursorPos(x/2-string.len("Score: "..score)/2,y/2-1)
  1390.         write("Score: "..score)
  1391.         term.setCursorPos(x/2-string.len("Jumps: "..jumps)/2,y/2)
  1392.         write("Jumps: "..jumps)
  1393.         sleep(1)
  1394.         term.setCursorPos(x/2-string.len("Press any key to continue...")/2,y/2+2)
  1395.         write("Press any key to continue...")
  1396.         os.pullEvent()
  1397.         term.clear()
  1398.         term.setCursorPos(1,1)
  1399.     end
  1400.  
  1401.     local function loop()
  1402.         parallel.waitForAny(engine1,engine2,engine3)
  1403.         gameover()
  1404.     end
  1405.  
  1406.     loop()
  1407.  
  1408. end
  1409.  
  1410. function playConnect()
  1411.     cp(1,1) setText("white") setBack("black") clr() write("Running game...") sleep(1)
  1412.     shell.run("games/connect/main.lua")
  1413.     sleep(1)
  1414.     os.pullEvent()
  1415. end
  1416.  
  1417.  
  1418.  
  1419.  
  1420.  
  1421.  
  1422.  
  1423.  
  1424.  
  1425.  
  1426.  
  1427.  
  1428. function pbrun(code, action, name)
  1429.     if code == nil then
  1430.         return "Invalid Code"
  1431.     elseif string.len(code) < 8 then
  1432.         return "Invalid Code Length."
  1433.     elseif action == "get" and name == nil or name == "" then
  1434.         return "File Name Missing."
  1435.     elseif name ~= nil then
  1436.         if fs.exists(name) then
  1437.             return "File Already Exists"
  1438.         end
  1439.     end
  1440.     term.setCursorBlink(false)
  1441.     cp(1,h-3) setBack("white") setText("white")
  1442.     if action == "run" then
  1443.         cp(1,1) setText("white") setBack("black") clr()
  1444.         return shell.run("pastebin "..action.." "..code)
  1445.     elseif action == "get" then
  1446.         return shell.run("pastebin "..action.." "..code.." "..name)
  1447.     end
  1448. end
  1449.  
  1450. function pastebinProgram()
  1451.     term.setCursorBlink(true)
  1452.     local buttonToggle = true
  1453.     local updat = true
  1454.     local chars = ""
  1455.     local charSelected = true
  1456.     local fsSelected = false
  1457.     local fsPath = ""
  1458.     local runPB = false
  1459.     local stattoggle = true
  1460.     local statm = ""
  1461.  
  1462.     local run = true
  1463.  
  1464.     while run do
  1465.         if runPB then
  1466.             runPB = false
  1467.             local res
  1468.             setBack("white")
  1469.             cp(6,14+string.len("GO    Status: ")) setText("orange") write("Running...")
  1470.             if buttonToggle then
  1471.                 res = pbrun(chars, "get", fsPath)
  1472.             else
  1473.                 res = pbrun(chars, "run")
  1474.             end
  1475.             term.setCursorBlink(true)
  1476.             if res ~= true then
  1477.                 statm = res
  1478.             else
  1479.                 statm = "Success!"
  1480.             end
  1481.             setText("black")
  1482.         end
  1483.         if updat then
  1484.             updat = not updat
  1485.             cp(1,1)
  1486.             setText("black")
  1487.             setBack("white")
  1488.             clr()
  1489.             paintutils.drawLine(1,1,w,1,colors["lightGray"])
  1490.             cp(1,3)
  1491.  
  1492.             setBack("white")
  1493.             write("Pastebin Code: ")
  1494.             setBack("lightGray")
  1495.             for i=1, 9 do write(" ") end
  1496.  
  1497.             if buttonToggle then
  1498.                 paintutils.drawFilledBox(5,5,10,8,colors["green"])
  1499.                 cp(6,6) write("Get")
  1500.                 paintutils.drawFilledBox(12,5,17,8,colors["gray"])
  1501.                 cp(13,6) write("Run")
  1502.             else
  1503.                 paintutils.drawFilledBox(5,5,10,8,colors["gray"])
  1504.                 cp(6,6) write("Get")
  1505.                 paintutils.drawFilledBox(12,5,17,8,colors["green"])
  1506.                 cp(13,6) write("Run")
  1507.             end
  1508.             paintutils.drawFilledBox(5,12,10,15,colors["lime"])
  1509.             cp(6,13) write("GO   ")
  1510.             setBack("white") write(" Status: ")
  1511.             if stattoggle then setText("green") else setText("red") end
  1512.             write(statm) setText("black")
  1513.  
  1514.             if buttonToggle then
  1515.                 cp(1,10)
  1516.                 setBack("white")
  1517.                 write("File Name: ")
  1518.                 setBack("lightGray")
  1519.                 for i=1, w-string.len("File Name: ") do
  1520.                     write(" ")
  1521.                 end
  1522.             end
  1523.  
  1524.         end
  1525.  
  1526.         setBack("lightGray")
  1527.         cp(string.len("Pastebin Code: ")+1,3)
  1528.         write(chars.." ")
  1529.         cp(string.len("Pastebin Code: ")+1+string.len(chars),3)
  1530.  
  1531.         if buttonToggle then
  1532.             cp(string.len("File Name: ")+1,10)
  1533.             write(fsPath.." ")
  1534.  
  1535.             if charSelected then
  1536.                 cp(string.len("Pastebin Code: ")+1+#chars, 3)
  1537.             else
  1538.                 cp(string.len("File Name: ")+1+string.len(fsPath), 10)
  1539.             end
  1540.         end
  1541.  
  1542.         a,i,x,y = os.pullEvent()
  1543.         if a == "mouse_click" then
  1544.             if i == 1 then
  1545.                 if x >= string.len("Pastebin Code: ")+1 and x <= string.len("Pastebin Code: ")+9 and y == 3 then
  1546.                     term.setCursorBlink(true)
  1547.                     fsSelected = false
  1548.                     charSelected = true
  1549.                 elseif x >= string.len("File Name: ")+1 and y == 10 and buttonToggle then
  1550.                     term.setCursorBlink(true)
  1551.                     fsSelected = true
  1552.                     charSelected = false
  1553.                 else
  1554.                     term.setCursorBlink(false)
  1555.                     charSelected = false
  1556.                     if x >= 5 and x <= 10 and y >= 5 and y <= 8 then
  1557.                         buttonToggle = true updat = true
  1558.                     elseif x >= 12 and x <= 17 and y >= 5 and y <= 8 then
  1559.                         buttonToggle = false updat = true
  1560.                     end
  1561.                 end
  1562.             end
  1563.         elseif a == "paste" then
  1564.             if charSelected then
  1565.                 if string.len(chars..i) <= 8 then chars = chars..i end
  1566.             elseif fsSelected then
  1567.                 if string.len(fsPath..i) < w-string.len("File Name: ")-1 then fsPath = fsPath..i end
  1568.             end
  1569.         elseif a == "char" then
  1570.             if i ~= " " then
  1571.                 if charSelected then
  1572.                     if string.len(chars) ~= 8 then chars = chars..i end
  1573.                 else
  1574.                     if string.len(fsPath) < w-string.len("File Name: ")-1 then fsPath = fsPath..i end
  1575.                 end
  1576.             end
  1577.         elseif a == "key" then
  1578.             if i == keys.backspace and charSelected then
  1579.                 chars = string.sub(chars,1,-2)
  1580.             elseif i == keys.backspace and fsSelected then
  1581.                 fsPath = string.sub(fsPath,1,-2)
  1582.             elseif i == keys.enter or i == keys.tab then
  1583.                 if charSelected then
  1584.                     charSelected = false
  1585.                     if buttonToggle then
  1586.                         fsSelected = true
  1587.                     else
  1588.                         runPB = true updat = true
  1589.                     end
  1590.                 elseif fsSelected then
  1591.                     runPB = true updat = true
  1592.                 end
  1593.             end
  1594.         end
  1595.  
  1596.     end
  1597.     term.setCursorBlink(false)
  1598. end
  1599.  
  1600.  
  1601.  
  1602.  
  1603. function moveDesktopApp(selected, app_list, scroll)
  1604.     local sw,sh = term.getSize()
  1605.     local currently_displaying = {}
  1606.     local run = true
  1607.     local fr = false -- used to keep scroll from reseting when first running this
  1608.     local updat = true
  1609.     local bg = true
  1610.    
  1611.     while run do
  1612.         if #app_list > sh then
  1613.             for i=1, sh do
  1614.                 currently_displaying[i] = app_list[i+scroll]
  1615.             end
  1616.         else
  1617.             currently_displaying = app_list
  1618.         end
  1619.        
  1620.        
  1621.         -- Update Apps --
  1622.         load_order = {}
  1623.         apps = {}
  1624.         for i=1, #app_list do
  1625.             table.insert(load_order, {app_list[i][1], app_list[i][2]})
  1626.             if app_list[i][2] == 1 then loadApp(app_list[i][1], sprite_dir..string.gsub(app_list[i][1]," ","")) end
  1627.         end
  1628.        
  1629.         maxPage = math.ceil(#apps/6)
  1630.         current_page = 1
  1631.         -- Update Apps --
  1632.        
  1633.        
  1634.         -- Save Settings --
  1635.         if fs.exists(app_dir.."load_order.lua") then
  1636.             fs.delete(app_dir.."load_order.lua")
  1637.         end
  1638.         if fs.exists(app_dir.."status.lua") then
  1639.             fs.delete(app_dir.."status.lua")
  1640.         end
  1641.         local file = fs.open(app_dir.."load_order.lua", "w")
  1642.         for i=1, #app_list do
  1643.             file.writeLine(app_list[i][1])
  1644.         end
  1645.         file.close()
  1646.         local file = fs.open(app_dir.."status.lua", "w")
  1647.         for i=1, #app_list do
  1648.             file.writeLine(app_list[i][2])
  1649.         end
  1650.         file.close()
  1651.         -- Save Settings --
  1652.        
  1653.         -- Update Screen --
  1654.         if updat then
  1655.             updat = not updat
  1656.             if not fr then
  1657.                 fr = not fr
  1658.                 scroll = 0
  1659.                 setBack("black") clr()
  1660.             end
  1661.             --paintutils.drawLine(1,h,w,h,colors["lightGray"])
  1662.             --paintutils.drawPixel(w,h,colors["red"])
  1663.             cp(1,1)
  1664.             bg = true
  1665.             for i=1, #currently_displaying do
  1666.                 if bg then setBack("black") else setBack("gray") end bg = not bg
  1667.                 if i == selected then
  1668.                     setText("yellow")
  1669.                     write("> ")
  1670.                 end
  1671.                 if currently_displaying[i][1] == "ShellOS" or currently_displaying[i][1] == "Desktop" then
  1672.                     setText("purple")
  1673.                 else
  1674.                     if currently_displaying[i][2] == 1 then
  1675.                         setText("green")
  1676.                     else
  1677.                         setText("red")
  1678.                     end
  1679.                 end
  1680.                 print(currently_displaying[i][1].."           ")
  1681.             end
  1682.         end
  1683.         -- Update Screen --
  1684.        
  1685.         sleep(.00001)
  1686.         a,i,x,y = os.pullEvent("key")
  1687.        
  1688.         if i == keys.w or i == keys.up then
  1689.             if selected ~= 1 then
  1690.                 if selected ~= 1 then
  1691.                     local tmp = app_list[selected+scroll]
  1692.                     local tmp2 = app_list[selected+scroll-1]
  1693.                     app_list[selected+scroll] = tmp2
  1694.                     app_list[selected+scroll-1] = tmp
  1695.                     if selected == 3 and scroll ~= 0 then
  1696.                         scroll = scroll - 1
  1697.                     elseif selected ~= 1 then
  1698.                         selected = selected - 1
  1699.                     end
  1700.                 end
  1701.             end
  1702.         elseif i == keys.s or i == keys.down then
  1703.             if selected ~= #app_list-scroll then
  1704.                 local tmp = app_list[selected+scroll]
  1705.                 local tmp2 = app_list[selected+scroll+1]
  1706.                 app_list[selected+scroll] = tmp2
  1707.                 app_list[selected+scroll+1] = tmp
  1708.                 if selected == sh-2 and scroll ~= #app_list-sh then
  1709.                     scroll = scroll + 1
  1710.                 elseif selected ~= #app_list-scroll then
  1711.                     selected = selected + 1
  1712.                 end
  1713.             end
  1714.         elseif i == keys.d or i == keys.right or i == keys.a or i == keys.left then
  1715.             if app_list[selected+scroll][1] ~= "ShellOS" or app_list[selected+scroll][1] ~= "Desktop" then
  1716.                 if app_list[selected+scroll][2] == 1 then
  1717.                     app_list[selected+scroll][2] = 0
  1718.                 else
  1719.                     app_list[selected+scroll][2] = 1
  1720.                 end
  1721.             end
  1722.         elseif i == keys.enter or i == keys.e then
  1723.             return true
  1724.         end
  1725.         updat = true
  1726.     end
  1727. end
  1728.  
  1729. function loadDesktopinfo(dt_app_location)
  1730.     local options = {}
  1731.     cp(1,1) setText("white") setBack("black") clr()
  1732.     write("App: ")
  1733.     if dt_app_location[1] == "ShellOS" or dt_app_location[1] == "Desktop" then
  1734.         setText("purple")
  1735.     else
  1736.         if dt_app_location[2] == 1 then
  1737.             setText("green")
  1738.             table.insert(options, "Hide")
  1739.         else
  1740.             setText("red")
  1741.             table.insert(options, "Show")
  1742.         end
  1743.     end
  1744.     for i=1, #user_apps do
  1745.         if dt_app_location[1] == user_apps[i][2] then
  1746.             if options[#options] ~= "Remove" then
  1747.                 table.insert(options, "Remove")
  1748.             end
  1749.         end
  1750.     end
  1751.     table.insert(options, "Move")
  1752.     table.insert(options, "Exit")
  1753.     print(dt_app_location[1]) setText("white") cp(1,4)
  1754.     for i=1, #options do
  1755.         print(options[i])
  1756.     end
  1757.     local lx,ly
  1758.     repeat
  1759.         a,i,lx,ly = os.pullEvent("mouse_click")
  1760.     until ly >= 4 and ly <= #options+3
  1761.     ly = ly - 3
  1762.     if options[ly] == "Exit" then
  1763.         return ""
  1764.     elseif options[ly] == "Show" or options[ly] == "Hide" then
  1765.         return "toggle"
  1766.     elseif options[ly] == "Remove" then
  1767.         -- Delete an option
  1768.         return "remove"
  1769.     elseif options[ly] == "Move" then
  1770.         return "move"
  1771.     end
  1772. end
  1773.  
  1774. function desktopProgram()
  1775.     -- app manager for moving apps to places and removing them as needed. (could use this to create new apps)
  1776.     -- load_order contains: {name, status} (each app)
  1777.     local sw,sh = term.getSize()
  1778.     local new_load_order = load_order
  1779.     local run = true
  1780.     local updat = true
  1781.     print("-")
  1782.  
  1783.     local scroll = 0
  1784.     local options_displayed = {}
  1785.     local editing = false
  1786.     local selected = 1
  1787.     local bg = true
  1788.  
  1789.     while run do
  1790.         if #new_load_order > sh then
  1791.             for i=1, sh do
  1792.                 options_displayed[i] = new_load_order[i+scroll]
  1793.             end
  1794.         else
  1795.             options_displayed = new_load_order
  1796.         end
  1797.        
  1798.        
  1799.         -- Update Apps --
  1800.         load_order = {}
  1801.         apps = {}
  1802.         for i=1, #new_load_order do
  1803.             --new_load_order[i][1] = string.gsub(new_load_order[i][1], " ", "")
  1804.             if new_status ~= nil then
  1805.                 table.insert(load_order, {new_load_order[i], new_status[i]})
  1806.             else
  1807.                 table.insert(load_order, {new_load_order[i][1], new_load_order[i][2]})
  1808.             end
  1809.             if new_status ~= nil then
  1810.                 if new_status[i] == 1 then loadApp(new_load_order[i], sprite_dir..new_load_order[i]) end
  1811.             else
  1812.                 if new_load_order[i][2] == 1 then loadApp(new_load_order[i][1], sprite_dir..string.gsub(new_load_order[i][1]," ","")) end
  1813.             end
  1814.         end
  1815.         maxPage = math.ceil(#apps/6)
  1816.         current_page = 1
  1817.         -- Update Apps --
  1818.        
  1819.        
  1820.         -- Save Settings --
  1821.         if fs.exists(app_dir.."load_order.lua") then
  1822.             fs.delete(app_dir.."load_order.lua")
  1823.         end
  1824.         if fs.exists(app_dir.."status.lua") then
  1825.             fs.delete(app_dir.."status.lua")
  1826.         end
  1827.         if fs.exists(app_dir.."user_apps.lua") then
  1828.             fs.delete(app_dir.."user_apps.lua")
  1829.         end
  1830.         local file = fs.open(app_dir.."load_order.lua", "w")
  1831.         for i=1, #new_load_order do
  1832.             file.writeLine(new_load_order[i][1])
  1833.         end
  1834.         file.close()
  1835.         local file = fs.open(app_dir.."status.lua", "w")
  1836.         for i=1, #new_load_order do
  1837.             file.writeLine(new_load_order[i][2])
  1838.         end
  1839.         file.close()
  1840.         local file = fs.open(app_dir.."user_apps.lua", "w")
  1841.         for i=1, #user_apps do
  1842.             file.writeLine(user_apps[i][2])
  1843.             file.writeLine(user_apps[i][3])
  1844.         end
  1845.         file.close()
  1846.         -- Save Settings --
  1847.        
  1848.         -- Update Screen --
  1849.         if updat then
  1850.             updat = not updat
  1851.             scroll = 0
  1852.             setBack("black") clr()
  1853.             --paintutils.drawLine(1,h,w,h,colors["lightGray"])
  1854.             --paintutils.drawPixel(w,h,colors["red"])
  1855.             cp(1,1)
  1856.             bg = true
  1857.             for i=1, #options_displayed do
  1858.                 if bg then setBack("black") else setBack("gray") end bg = not bg
  1859.                 if editing then setText("yellow") else setText("white") end
  1860.                 if options_displayed[i][1] == "ShellOS" or options_displayed[i][1] == "Desktop" then
  1861.                     setText("purple")
  1862.                 else
  1863.                     if options_displayed[i][2] == 1 then
  1864.                         setText("green")
  1865.                     else
  1866.                         setText("red")
  1867.                     end
  1868.                 end
  1869.                 if i == #options_displayed then
  1870.                     write(options_displayed[i][1].."           ")
  1871.                 else
  1872.                     print(options_displayed[i][1].."           ")
  1873.                 end
  1874.             end
  1875.         end
  1876.         -- Update Screen --
  1877.        
  1878.         sleep(.00001)
  1879.         repeat
  1880.         a,i,x,y = os.pullEvent()
  1881.         until a == "mouse_click" or a == "mouse_scroll"
  1882.        
  1883.         if a == "mouse_click" then
  1884.             if y <= #options_displayed then
  1885.                 local tmpy = y
  1886.                 local tmp = loadDesktopinfo(new_load_order[y+scroll])
  1887.                 y = tmpy
  1888.                 if tmp == "toggle" then
  1889.                     if new_load_order[y+scroll][2] == 1 then
  1890.                         new_load_order[y+scroll][2] = 0
  1891.                     else
  1892.                         new_load_order[y+scroll][2] = 1
  1893.                     end
  1894.                 elseif tmp == "remove" then
  1895.                     table.remove(new_load_order, y+scroll)
  1896.                     table.remove(user_apps, y+scroll)
  1897.                     saveUserApps()
  1898.                 elseif tmp == "move" then
  1899.                     moveDesktopApp(y, new_load_order, scroll)
  1900.                 end
  1901.                 updat = true
  1902.             end
  1903.         elseif a == "mouse_scroll" then
  1904.             if i == 1 and scroll < #new_load_order-sh then -- down
  1905.                 scroll = scroll + 2 updat = true
  1906.             elseif i == -1 and scroll > -1 then -- up
  1907.                 scroll = scroll - 2 updat = true
  1908.             end
  1909.             if scroll < 0 then scroll = 0 end
  1910.         end
  1911.        
  1912.        
  1913.        
  1914.         --[[
  1915.        
  1916.         if i == keys.w or i == keys.up then
  1917.             if editing then
  1918.                 if selected ~= 1 then
  1919.                     local tmp = new_load_order[selected+scroll]
  1920.                     local tmp2 = new_load_order[selected+scroll-1]
  1921.                     new_load_order[selected+scroll] = tmp2
  1922.                     new_load_order[selected+scroll-1] = tmp
  1923.                     if selected == 3 and scroll ~= 0 then
  1924.                         scroll = scroll - 1
  1925.                     elseif selected ~= 1 then
  1926.                         selected = selected - 1
  1927.                     end
  1928.                 end
  1929.             else
  1930.                 if selected == 3 and scroll ~= 0 then
  1931.                     scroll = scroll - 1
  1932.                 elseif selected ~= 1 then
  1933.                     selected = selected - 1
  1934.                 end
  1935.             end
  1936.         elseif i == keys.s or i == keys.down then
  1937.             if editing then
  1938.                 if selected ~= #new_load_order-scroll then
  1939.                     local tmp = new_load_order[selected+scroll]
  1940.                     local tmp2 = new_load_order[selected+scroll+1]
  1941.                     new_load_order[selected+scroll] = tmp2
  1942.                     new_load_order[selected+scroll+1] = tmp
  1943.                     if selected == sh-2 and scroll ~= #new_load_order-sh then
  1944.                         scroll = scroll + 1
  1945.                     elseif selected ~= #new_load_order-scroll then
  1946.                         selected = selected + 1
  1947.                     end
  1948.                 end
  1949.             else
  1950.                 if selected == sh-3 and scroll ~= #new_load_order-sh+1 then
  1951.                     scroll = scroll + 1
  1952.                 elseif selected ~= #new_load_order-scroll then
  1953.                     selected = selected + 1
  1954.                 end
  1955.             end
  1956.         elseif i == keys.a or i == keys.left or i == keys.d or i == keys.right and editing then
  1957.             if new_load_order[selected+scroll][1] ~= "ShellOS" or new_load_order[selected+scroll][1] ~= "Desktop" then
  1958.                 if new_load_order[selected+scroll][2] == 1 then
  1959.                     new_load_order[selected+scroll][2] = 0
  1960.                 else
  1961.                     new_load_order[selected+scroll][2] = 1
  1962.                 end
  1963.             end
  1964.         elseif i == keys.enter or i == keys.e then
  1965.             editing = not editing
  1966.         elseif i == keys.q and editing then
  1967.             editing = false
  1968.             run = false
  1969.         end
  1970.         ]]
  1971.     end
  1972. end
  1973.  
  1974. function UserProgramManager()
  1975.     -- user_apps contain: {app location, name, dir}
  1976.     local sw,sy = term.getSize()
  1977.     local run = true
  1978.     sleep(.1)
  1979.     local _m = {"Manage Apps", "Add App", "Remove App", "Exit UPM"} -- main menu
  1980.     local selected_app
  1981.     local _m_ma = {"Edit Name", "Edit Dir", "Edit Icon", "Back"} -- manage apps menu
  1982.    
  1983.     local _m_app_list = user_apps -- For use in anything
  1984.     table.insert(_m_app_list, "Exit")
  1985.    
  1986.     local _m_actions = {
  1987.     ManageApps = function()
  1988.        
  1989.     end,
  1990.     AddApp = function()
  1991.         clr() setText("white") setBack("black") cp(1,1)
  1992.         print("Create an app!")
  1993.         print(" - App name can't be any longer than 12 letters and cannot be an pre-existing app")
  1994.         print(" - App dir can be any length and be run my other apps as long as it exists on the computer or in a disk")
  1995.         print(" - App Icons can not be any larger than 6x8")
  1996.         print(" - Any invalid inputs will exit back to the main menu")
  1997.         print("")
  1998.         write("Display name: ")
  1999.         local name = read()
  2000.         local val = true
  2001.         for i=1, #load_order do
  2002.             if name == load_order[i] then val = false end
  2003.         end
  2004.         if string.len(name) > 12 then
  2005.             print("Display name is > than 12 letters") sleep(1)
  2006.             return false
  2007.         elseif name == "" then
  2008.             print("Display name needs to be at least 1 letter") sleep(1)
  2009.             return false
  2010.         elseif val == false then
  2011.             print("App already exists") sleep(1)
  2012.         end
  2013.         write("Dir: ")
  2014.         local adir = read()
  2015.         if not fs.exists(adir) then
  2016.             print("Dir does not exists") sleep(1)
  2017.             return false
  2018.         end
  2019.        
  2020.         table.insert(user_apps, {#load_order+1, name, adir})
  2021.         table.insert(load_order, {user_apps[#user_apps][2], 1.0})
  2022.        
  2023.         if fs.exists(app_dir.."load_order.lua") then
  2024.             fs.delete(app_dir.."load_order.lua")
  2025.         end
  2026.         if fs.exists(app_dir.."status.lua") then
  2027.             fs.delete(app_dir.."status.lua")
  2028.         end
  2029.         local file = fs.open(app_dir.."load_order.lua", "w")
  2030.         for i=1, #load_order do
  2031.             file.writeLine(load_order[i][1])
  2032.         end
  2033.         file.close()
  2034.         local file = fs.open(app_dir.."status.lua", "w")
  2035.         for i=1, #load_order do
  2036.             file.writeLine(load_order[i][2])
  2037.         end
  2038.         file.close()
  2039.        
  2040.         saveUserApps()
  2041.         local file = fs.open(app_dir.."user_apps.lua", "w")
  2042.         for i=1, #user_apps do
  2043.             file.writeLine(user_apps[i][2])
  2044.             file.writeLine(user_apps[i][3])
  2045.         end
  2046.         file.close()
  2047.         loadApp(user_apps[#user_apps][2], sprite_dir..user_apps[#user_apps][2])
  2048.        
  2049.         print("App has been added sucessfully!") sleep(1.3)
  2050.     end,
  2051.     RemoveApp = function()
  2052.        
  2053.     end,
  2054.     ExitUPM = function()
  2055.         run = false
  2056.     end,
  2057.     EditName = function()
  2058.        
  2059.     end,
  2060.     EditDir = function()
  2061.        
  2062.     end,
  2063.     EditIcon = function()
  2064.        
  2065.     end
  2066.     }
  2067.    
  2068.     local _m_s = _m -- selected menu
  2069.    
  2070.     local updat = true
  2071.     local scroll = 0
  2072.     local selected = 1
  2073.    
  2074.     local function drawMenu()
  2075.         local m = {}
  2076.         if #_m_s <= 10 then
  2077.             m = _m_s
  2078.         else
  2079.             for i=1, 10 do
  2080.                 m[#m+1] = _m_s[i+scroll]
  2081.             end
  2082.         end
  2083.         cp(1,2) setText("yellow") write("UPM (User Program Manager)")
  2084.         cp(1,4)
  2085.         for i=1, #m do
  2086.             if i == selected then
  2087.                 setText("white")
  2088.                 print("> "..m[i].."            ")
  2089.             else
  2090.                 setText("gray")
  2091.                 print("  "..m[i].."            ")
  2092.             end
  2093.         end
  2094.     end
  2095.    
  2096.     while run do
  2097.         if updat then
  2098.             updat = false
  2099.             setBack("black") clr()
  2100.         end
  2101.         drawMenu()
  2102.        
  2103.         sleep(.001)
  2104.         a,i = os.pullEvent("key")
  2105.        
  2106.         if i == keys.w or i == keys.up then
  2107.             if selected == 3 and scroll ~= 0 then
  2108.                 scroll = scroll - 1
  2109.             else
  2110.                 if selected ~= 1 then
  2111.                     selected = selected - 1
  2112.                 end
  2113.             end
  2114.         elseif i == keys.s or i == keys.down then
  2115.             if selected == sy-10 and scroll ~= #_m_s-sy+8 then
  2116.                 scroll = scroll + 1
  2117.             else
  2118.                 if selected ~= #_m_s-scroll then   
  2119.                     selected = selected + 1
  2120.                 end
  2121.             end
  2122.         elseif i == keys.e or i == keys.enter then
  2123.             _m_actions[string.gsub(_m_s[selected], " ", "")]() selected = 1 updat = true
  2124.         end
  2125.     end
  2126. end
  2127.  
  2128. function runUserPrograms()
  2129.     -- app_selected >> points to where the app was selected (app #10 or app #5)
  2130.     -- user_apps >> user_apps[i] = {app_selected, "name", "dir"}
  2131.    
  2132.     local selected = 0
  2133.     for i=1, #user_apps do
  2134.         if app_selected == user_apps[i][1] then -- gets the program to run
  2135.             selected = i
  2136.         end
  2137.     end
  2138.    
  2139.     if selected == 0 then
  2140.         print("Program '"..load_order[app_selected][1].."' does not exists") -- HERE ===================
  2141.     else
  2142.         if fs.exists(user_apps[selected][3]) then
  2143.             local s,e = pcall(function() shell.run(user_apps[selected][3]) end)
  2144.             setText("white")
  2145.             setBack("black")
  2146.             clr()
  2147.             cp(1,1)
  2148.             if s then
  2149.                 return true
  2150.             else
  2151.                 print("Program failed with the error: ")
  2152.                 printError(e)
  2153.             end
  2154.         else
  2155.             print("Program does not exists")
  2156.         end
  2157.     end
  2158.     --[[
  2159.     if loaded_apps[app_selected] ~= nil then
  2160.         if fs.exists(loaded_apps[app_selected][2]) then
  2161.             local s,e = shell.run(loaded_apps[app_selected][2])
  2162.             setText("white")
  2163.             setBack("black")
  2164.             clr()
  2165.             cp(1,1)
  2166.             if s then
  2167.                 return true
  2168.             else
  2169.                 print("Program failed with the error: ")
  2170.                 printError(e)
  2171.             end
  2172.         else
  2173.             print("Program does not exists")
  2174.         end
  2175.     else
  2176.         print("Program does not exists")
  2177.     end
  2178.     ]]
  2179.    
  2180.     sleep(1)
  2181.     print("")
  2182.     print("Press any key to exit...")
  2183.     os.pullEvent()
  2184. end
  2185.  
  2186. function iconeditorProgram()
  2187.  
  2188. end
  2189.  
  2190.  
  2191.  
  2192.  
  2193. function displaySI()
  2194.     while true do
  2195.         cp(1,1) setBack("black") clr()
  2196.         setText("white") write("System Version: ") setText("yellow") print(os.version())
  2197.         setText("white") write("Freeware Version: ") setText("yellow") print(version)
  2198.         setText("white") write("System ID: ") setText("yellow") print(os.getComputerID())
  2199.         setText("white") write("System Label: ") setText("yellow") print(os.getComputerLabel())
  2200.         setText("white") write("System Storage: ") setText("yellow") print(fs.getFreeSpace("/").." bytes Free")
  2201.         setText("white") write("OS Size: ") setText("yellow") print(fs.getSize(shell.getRunningProgram()).." bytes")
  2202.        
  2203.  
  2204.         setText("white") print("Connected Devices: ")
  2205.         local sides = {{"Top", peripheral.getType("top")},{"Bottom", peripheral.getType("bottom")}, {"Left", peripheral.getType("left")}, {"Right", peripheral.getType("right")}, {"Front", peripheral.getType("front")}, {"Back", peripheral.getType("back")}}
  2206.         for i=1, #sides do
  2207.             setText("white") write(sides[i][1].." - ")
  2208.             if sides[i][2] ~= nil then
  2209.                 setText("green") write(sides[i][2].." ")
  2210.             else
  2211.                 setText("gray") write("nil ")
  2212.             end
  2213.         end
  2214.         print("")
  2215.  
  2216.         setText("white") write("Http Support: ")
  2217.         if http then
  2218.             setText("green") print("True")
  2219.         else
  2220.             setText("red") print("False")
  2221.         end
  2222.  
  2223.         setText("white") write("ccemux: ")
  2224.         local a,i = pcall(function() ccemux.getVersion() end)
  2225.         if a == true then
  2226.             setText("green") print("ccemux v."..ccemux.getVersion())
  2227.         else
  2228.             setText("red") print("False")
  2229.         end
  2230.  
  2231.         setText("white") write("CC:Tweaked: ")
  2232.         local a,i = pcall(function() return fs.exists("rom/help/Speakers.txt") end)
  2233.         if a == true then
  2234.             setText("green") print("True")
  2235.         else
  2236.             setText("red") print("False")
  2237.         end
  2238.  
  2239.         setText("white") write("World Day: ") setText("yellow") print(os.day())
  2240.         setText("white") write("World Time: ") setText("yellow") print(textutils.formatTime(os.time()))
  2241.  
  2242.  
  2243.         sleep(4)
  2244.     end
  2245. end
  2246.  
  2247.  
  2248.  
  2249. function runProgram(program)
  2250.     local old = term.current()
  2251.     local mainw = window.create(term.current(),1,1,w,h-1)
  2252.  
  2253.     setBack("black")
  2254.     setText("white")
  2255.     clr()
  2256.     paintutils.drawLine(1,h,w,h,colors["lightGray"])
  2257.     paintutils.drawPixel(w,h,colors["red"])
  2258.  
  2259.     local function window()
  2260.         local run = true
  2261.         while run do
  2262.             a,i,x,y = os.pullEvent()
  2263.             if a == "mouse_click" then
  2264.                 if x == w and y == h then
  2265.                     run = false
  2266.                 end
  2267.             end
  2268.         end
  2269.     end
  2270.    
  2271.     local oldTerm = term.redirect(mainw)
  2272.     parallel.waitForAny(window, program)
  2273.     local newTerm = term.redirect(old)
  2274.    
  2275.  
  2276.     term.setCursorBlink(false)
  2277.     update = true
  2278. end
  2279.  
  2280. function runEmuData()
  2281.     local a,i = pcall(function() ccemux.getVersion() end)
  2282.     if a then
  2283.         setText("white") setBack("black") clr() cp(1,1) print("Loading Emu Data folder...") sleep(.1) shell.run("emu data") sleep(.5)
  2284.     else
  2285.         setText("white") setBack("black") clr() cp(1,1) print("Loading Emu Data folder...") sleep(.1) print("Failed to load because system is most likely on an emulator or is outdated...") sleep(.5) print("") print("Press any key to exit...") os.pullEvent()
  2286.     end
  2287.     update = true
  2288. end
  2289.  
  2290. home_option_function = {
  2291.  
  2292. ShellOS = function()
  2293.     runProgram(function() shell.run("shell") end)
  2294. end,
  2295.  
  2296. Files = function()
  2297.     runProgram(function() fileProgram() end)
  2298.     --fileProgram()
  2299. end,
  2300.  
  2301. IconEditor = function()
  2302.     -- Nothing
  2303. end,
  2304.  
  2305. Shutdown = function()
  2306.     os.shutdown()
  2307. end,
  2308.  
  2309. Reboot = function()
  2310.     os.reboot()
  2311. end,
  2312.  
  2313. Crash = function()
  2314.     error("Crash App")
  2315. end,
  2316.  
  2317. Worm = function()
  2318.     runProgram(function() shell.run("worm") end)
  2319. end,
  2320.  
  2321. Adventure = function()
  2322.     runProgram(function() shell.run("adventure") end)
  2323. end,
  2324.  
  2325. Lua = function()
  2326.     runProgram(function() shell.run("lua") end)
  2327. end,
  2328.  
  2329. Pastebin = function()
  2330.     runProgram(function() pastebinProgram() end)
  2331. end,
  2332.  
  2333. SystemInfo = function()
  2334.     runProgram(function() displaySI() end)
  2335. end,
  2336.  
  2337. Homebrew = function()
  2338.     running = false
  2339. end,
  2340.  
  2341. Desktop = function()
  2342.     runProgram(function() desktopProgram() end)
  2343. end,
  2344.  
  2345. Dino = function()
  2346.     runProgram(function() playDino() end)
  2347. end,
  2348.  
  2349. Landslide = function()
  2350.     runProgram(function() playLandslide() end)
  2351. end,
  2352.  
  2353. UPM = function()
  2354.     runProgram(function() UserProgramManager() end)
  2355. end,
  2356.  
  2357. RunUserPrograms = function()
  2358.     runProgram(function() runUserPrograms() end)
  2359. end,
  2360.  
  2361. EmuData = function()
  2362.     runProgram(function() runEmuData() end)
  2363. end,
  2364.  
  2365. Connect = function()
  2366.     runProgram(function() playConnect() end)
  2367. end
  2368.  
  2369. }
  2370.  
  2371.  
  2372. function display()
  2373.     drawBar()
  2374.     drawScreen()
  2375.     drawApps()
  2376.     if home then
  2377.         drawHome()
  2378.     end
  2379. end
  2380.  
  2381. function clickEngine()
  2382.     running = true
  2383.     update = false
  2384.     while running do
  2385.         sEvent, param, param2, param3 = os.pullEvent("mouse_click")
  2386.         x,y = param2,param3
  2387.         if param == 1 then -- Left Click
  2388.             if home then
  2389.                 if x <= home_options_lt_f()+2 and y >= h-#home_options and y ~= h then
  2390.                     home_option_function[home_options[h-y]]()
  2391.                 end
  2392.                 toggleHome()
  2393.                 drawScreen()
  2394.                 drawApps()
  2395.             elseif x == 1 and y == h and dBar then
  2396.                 toggleHome()
  2397.                 drawHome()
  2398.             elseif x == 1 and y > h/2-4 and y < h/2+3 and dScroll then
  2399.                 if current_page ~= 1 then current_page = current_page - 1 update = true end
  2400.             elseif x == w and y > h/2-4 and y < h/2+3 and dScroll then
  2401.                 if current_page ~= maxPage then current_page = current_page + 1 update = true end
  2402.             elseif x >= app_locations[1] and x <= app_locations[1]+7 then
  2403.                 -- Left
  2404.                 if y >= 1 and y <= 7 then -- top
  2405.                     app_selected = 1+(6*(current_page-1))
  2406.                     if loaded_apps[1] ~= nil then
  2407.                         if home_option_function[string.gsub(loaded_apps[1][1], " ", "")] ~= nil then
  2408.                             home_option_function[string.gsub(loaded_apps[1][1], " ", "")]()
  2409.                         else
  2410.                             home_option_function["RunUserPrograms"]()
  2411.                         end
  2412.                     end
  2413.                 elseif y >= 11 and y <= h-2 and #loaded_apps >= 4 then -- bottom
  2414.                     app_selected = 4+(6*(current_page-1))
  2415.                     if loaded_apps[4] ~= nil then
  2416.                         if home_option_function[string.gsub(loaded_apps[4][1], " ", "")] ~= nil then
  2417.                             home_option_function[string.gsub(loaded_apps[4][1], " ", "")]()
  2418.                         else
  2419.                             home_option_function["RunUserPrograms"]()
  2420.                         end
  2421.                     end
  2422.                 end
  2423.             elseif x >= app_locations[2] and x <= app_locations[2]+7 then
  2424.                 -- Middle
  2425.                 if y >= 1 and y <= 7 and #loaded_apps >= 2 then -- top
  2426.                     app_selected = 2+(6*(current_page-1))
  2427.                     if loaded_apps[2] ~= nil then
  2428.                         if home_option_function[string.gsub(loaded_apps[2][1], " ", "")] ~= nil then
  2429.                             home_option_function[string.gsub(loaded_apps[2][1], " ", "")]()
  2430.                         else
  2431.                             home_option_function["RunUserPrograms"]()
  2432.                         end
  2433.                     end
  2434.                 elseif y >= 11 and y <= h-2 and #loaded_apps >= 5 then -- bottom
  2435.                     app_selected = 5+(6*(current_page-1))
  2436.                     if loaded_apps[5] ~= nil then
  2437.                         if home_option_function[string.gsub(loaded_apps[5][1], " ", "")] ~= nil then
  2438.                             home_option_function[string.gsub(loaded_apps[5][1], " ", "")]()
  2439.                         else
  2440.                             home_option_function["RunUserPrograms"]()
  2441.                         end
  2442.                     end
  2443.                 end
  2444.             elseif x >= app_locations[3] and x <= app_locations[3]+7 then
  2445.                 -- Right
  2446.                 if y >= 1 and y <= 7 and #loaded_apps >= 3 then -- top
  2447.                     app_selected = 3+(6*(current_page-1))
  2448.                     if loaded_apps[3] ~= nil then
  2449.                         if home_option_function[string.gsub(loaded_apps[3][1], " ", "")] ~= nil then
  2450.                             home_option_function[string.gsub(loaded_apps[3][1], " ", "")]()
  2451.                         else
  2452.                             home_option_function["RunUserPrograms"]()
  2453.                         end
  2454.                     end
  2455.                 elseif y >= 11 and y <= h-2 and #loaded_apps >= 6 then -- bottom
  2456.                     app_selected = 6+(6*(current_page-1))
  2457.                     if loaded_apps[6] ~= nil then
  2458.                         if home_option_function[string.gsub(loaded_apps[6][1], " ", "")] ~= nil then
  2459.                             home_option_function[string.gsub(loaded_apps[6][1], " ", "")]()
  2460.                         else
  2461.                             home_option_function["RunUserPrograms"]()
  2462.                         end
  2463.                     end
  2464.                 end
  2465.             end
  2466.         elseif param == 2 then -- Right Click
  2467.             --
  2468.         elseif param == 3 then -- Middle Click
  2469.             --
  2470.         end
  2471.  
  2472.         if update then
  2473.             update = not update
  2474.             display()
  2475.         end
  2476.         if debug then
  2477.             cp(1,1) setBack("black") setText("white")
  2478.             write("x:"..tostring(x).." y:"..tostring(y).." p:"..current_page.." ")
  2479.         end
  2480.     end
  2481. end
  2482.  
  2483.  
  2484. function runtime()
  2485.     display() -- 0.05 refresh rate flickers
  2486.     clickEngine() -- runs clicking os
  2487. end
  2488.  
  2489. local res, er = pcall(runtime)
  2490.  
  2491. if res then
  2492.     setBack("black")
  2493.     setText("white")
  2494.     clr()
  2495.     cp(1,1)
  2496.     print("OS FREEWARE")
  2497. else
  2498.     setBack("blue")
  2499.     setText("white")
  2500.     clr()
  2501.     cp(1,1)
  2502.     sleep(1)
  2503.     print("OS has crashed... :0")
  2504.     print("")
  2505.     print("Something you did caused this to happen. This happens when the OS is unable to do its job correctly on the first time. Hope that whatever you where doing was saved...")
  2506.     print("")
  2507.     print("====================")
  2508.     setText("yellow")
  2509.     print(er)
  2510.     setText("white")
  2511.     print("====================")
  2512.     print("")
  2513.     print("Press any key to reboot...")
  2514.     os.pullEvent()
  2515.     os.reboot()
  2516. end
Add Comment
Please, Sign In to add comment