JustDoesGames

OS FREEWARE

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