Advertisement
Redxone

RedOS - VHD

Jul 20th, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 53.30 KB | None | 0 0
  1. local redos_files = {
  2.   [ "vhd/RedOS/ea" ] = {
  3.     content = "function s(...) return sleep(...) end\
  4. function w(...) return write(...) end\
  5. function p(...) return print(...) end\
  6. function tw(...) return term.write(...) end\
  7. function scp(...) return term.setCursorPos(...) end\
  8. function sbc(...) return term.setBackgroundColor(...) end\
  9. function stc(...) return term.setTextColor(...) end\
  10. function tc(...) return term.clear(...) end\
  11. function tcl(...) return term.clearLine() end\
  12. function scb(...) return term.setCursorBlink(...) end\
  13. function ts(...) return term.scroll(...) end\
  14. function r(...) return shell.run(...) end\
  15. function para(...) return parallel.waitForAny(...) end\
  16. function sw(...) return textutils.slowWrite(...) end\
  17. function sp(...) return textutils.slowPrint(...) end",
  18.   },
  19.   [ "vhd/RedOS/.RedOS/startmenu/apps/cozyfile" ] = {
  20.     content = "local arg = { ... }\
  21. \
  22. local selFile = \"\"\
  23. local fPath = \"rom/\"\
  24. local fDefault = fPath\
  25. local fPrePath = fPath\
  26. local printoff = 0\
  27. local mfoff = 0\
  28. local fs_ver = \"RedOS - v1.0 Alpha\"\
  29. local copy_path = \"\"\
  30. local copy_file = \"\"\
  31. local fName = \"\"\
  32. shell.setDir(\"\")\
  33.         function checkShort(name)\
  34.                return fs.isDir(\".RedOS/desktop/\"..name)\
  35.         end\
  36. \
  37.         function deleteShort (name)\
  38.                 fs.delete(\".RedOS/desktop/\"..name)\
  39.                 inContext = false\
  40.                 inRun = true\
  41.                 fileSystem()\
  42.         end\
  43. \
  44.        function makeShortcut (name,mkLoc)\
  45.                 fs.makeDir(\".RedOS/desktop/\"..name)\
  46.                 fs.copy(mkLoc, \".RedOS/desktop/\"..name..\"/\"..name)\
  47.                 shell.run(\"paint\",\".RedOS/desktop/\"..name..\"/icon\")\
  48.                 inContext = false\
  49.                 inRun = true\
  50.                 fileSystem()\
  51. \
  52.         end\
  53. \
  54. local theme = {\
  55.        \
  56.         foldercolor = colors.lime,\
  57.         filecolor = colors.orange,\
  58.         iconbgcolor = colors.gray,\
  59.         folderIcon = \"[=]\",\
  60.         fileIcon = \"-~-\",\
  61.         bgcolor = colors.white,\
  62.         tbcolor = colors.gray,\
  63.         tbtcolor = colors.yellow,\
  64.         textcolor = colors.black,\
  65.         dimtextcolor = colors.gray,\
  66.         selectedcolor = colors.blue,\
  67.         mbcolor = colors.black,\
  68.         mtcolor = colors.white,\
  69.         infocolor = colors.lightGray,\
  70.         shortcolor = colors.blue,\
  71. }\
  72. \
  73. \
  74. if(#arg > 0)then\
  75.        f = fs.open(arg[1],\"r\")\
  76.        filetheme = textutils.unserialize(f.readAll())\
  77.        f.close()\
  78. \
  79.        theme = setmetatable(filetheme, {__index = theme})\
  80. end\
  81. \
  82. \
  83. inRun = true\
  84. inContext=false\
  85. \
  86. \
  87. local contextEmpty = {\
  88.        [\"____________\"] = {x=0,y=0,yoff = 1, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() end};\
  89.        [\" New Folder \"] = {x=0,y=0,yoff = 2, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() ea.scp(1,1) ea.sbc(theme.tbcolor) ea.stc(theme.mtcolor); term.clearLine() write(\"New Folder: \") nFn = read(); if(not fs.isDir(nFn) and nFn ~= \"\")then fs.makeDir(fPath..\"/\"..nFn) inContext = false; inRun = true; cEmpty = false; fileSystem() end end};\
  90.        [\" New  File  \"] = {x=0,y=0,yoff = 3, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() ea.scp(1,1) ea.sbc(theme.tbcolor) ea.stc(theme.mtcolor); term.clearLine() write(\"New File: \") nFn = read(); if(not fs.exists(fPath..\"/\"..nFn) and nFn ~= \"\")then f=fs.open(fPath..\"/\"..nFn,\"w\") f.writeLine(\" \") f.close(); cEmpty = false; inContext = false; inRun = true; fileSystem() end end};\
  91.        [\"   Paste    \"] = {x=0,y=0,yoff = 4, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() if(fs.exists(fPath..\"/\"..copy_file))then cut =false inContext = false inRun = true selFile = fPath..copy_file; copy_path = \"\" copy_file = \"\" fileSystem() end if(copy_path ~= \"\" and not fs.exists(fPath..\"/\"..copy_file))then if(not cut)then fs.copy(copy_path,fPath..\"/\"..copy_file); else fs.move(copy_path,fPath..\"/\"..copy_file); cut =false end inContext = false inRun = true selFile = fPath..copy_file; copy_path = \"\" copy_file = \"\" fileSystem() end end}; \
  92.        [\"------------\"] = {x=0,y=0,yoff = 5, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() end};\
  93. }\
  94. \
  95. \
  96. local folderMenu = {\
  97.        \
  98.                [\"_____________\"] = {yoff = 1, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() end};\
  99.                [\" Open Folder \"] = {yoff = 2, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() fPrePath = fPath; fPath = fPath..fName..\"/\";  selFile = \"\"; loadFS(fPath); inContext=false inRun = true fileSystem(); end};\
  100.                [\" New Folder  \"] = {yoff = 3, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() ea.scp(1,1) ea.sbc(theme.tbcolor) ea.stc(theme.textcolor); term.clearLine() write(\"New Folder: \") nFn = read(); if(not fs.isDir(nFn) and nFn ~= \"\")then fs.makeDir(fPath..\"/\"..nFn) inContext = false; inRun = true; fileSystem() end end};\
  101.                [\" Cut         \"] = {yoff=  4, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() cut = true; copy_path = selFile; copy_file = fName inContext = false inRun = true fileSystem() end};\
  102.                [\" Copy        \"] = {yoff=  5, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() cut = false; copy_path = selFile; copy_file = fName inContext = false inRun = true fileSystem() end};\
  103.                [\"Rename Folder\"] = {yoff = 6, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() ea.sbc(theme.bgcolor) ea.stc(theme.textcolor); ea.scp(4,renameY) write(string.rep(\" \",15)) ea.scp(4,renameY); nFn = read(); if(not fs.isDir(fPath..\"/\"..nFn))then fs.move(selFile, fPath..\"/\"..nFn) inContext = false inRun = true fileSystem(); end end};\
  104.                [\"Delete Folder\"] = {yoff = 7, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() fs.delete(selFile); selFile = \"\"; inContext = false; inRun = true fileSystem(); end};\
  105.                [\"-------------\"] = {yoff = 8, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() end};\
  106. }\
  107. \
  108. \
  109. \
  110. local contextMenu = {\
  111. \
  112.        --[\"____________\"] = {yoff = 1, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() end};\
  113.        --[\"Run File    \"] = {yoff = 2, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() os.run({},selFile) inContext = false; inRun = true; fileSystem() ;end};\
  114.        [\"Edit File   \"] = {yoff = 1, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() shell.run(\"edit\",selFile);  inContext = false; inRun = true; fileSystem() end};\
  115.        [\"New File    \"] = {yoff = 2, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() \
  116.                ea.scp(1,1) \
  117.                ea.sbc(theme.tbcolor) \
  118.                ea.stc(theme.mtcolor); \
  119.                term.clearLine() \
  120.                write(\"New File: \") \
  121.                nFn = read(); \
  122.                if(not fs.exists(nFn) and nFn ~= \"\")then \
  123.                        f = fs.open(fPath..\"/\"..nFn,\"w\") \
  124.                        f.writeLine(\" \") \
  125.                        f.close(); \
  126. \
  127.                        inContext = false; \
  128.                        inRun = true; \
  129.                        fileSystem() \
  130.                end end};\
  131.        [\"New Folder  \"] = {yoff = 3, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() ea.scp(1,1) ea.sbc(theme.tbcolor) ea.stc(theme.mtcolor); term.clearLine() write(\"New Folder: \") nFn = read(); if(not fs.isDir(nFn) and nFn ~= \"\")then fs.makeDir(fPath..\"/\"..nFn) inContext = false; inRun = true; fileSystem() end end};         \
  132.        [\"Cut         \"] = {yoff=  4, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() cut = true; copy_path = selFile; copy_file = fName inContext = false inRun = true fileSystem() end};\
  133.        [\"Copy        \"] = {yoff=  5, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() cut = false; copy_path = selFile; copy_file = fName inContext = false inRun = true fileSystem() end};\
  134.        [\"Link File   \"] = {yoff=  6, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() makeShortcut(fName, selFile) end};\
  135.        [\"Remove Link \"] = {yoff=  7, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() if(checkShort(fName))then deleteShort(fName) end end};\
  136.        [\"Rename File \"] = {yoff = 8, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() ea.scp(4,renameY); ea.stc(theme.textcolor) ea.sbc(theme.bgcolor); print(\"                     \") ea.scp(5,renameY) nFn = read() if(not fs.exists(fPath..nFn) and nFn ~= \"\")then fs.move(selFile,fPath..nFn); end inRun = true; inContext = false; fileSystem() end};\
  137.        [\"Delete File \"] = {yoff = 9, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() if(fs.exists(selFile))then fs.delete(selFile); inContext = false; inRun = true; fileSystem(); end end};\
  138.        [\"------------\"] = {yoff = 10,bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() end};\
  139. } \
  140. \
  141. local w,h = term.getSize()\
  142. \
  143. os.loadAPI(\"ea\")\
  144. os.loadAPI(\"cozy_string\")\
  145. \
  146. function clear() ea.sbc(theme.bgcolor); term.clear() end\
  147. clear()\
  148. \
  149. --]] FILE SYSTEM [[--\
  150. local filetable = {}\
  151. \
  152. function loadFS(fsl)\
  153. \
  154.         mfoff = 0\
  155. \
  156. \
  157.        if(filetable ~= {})then filetable = {}\
  158. \
  159.        for k, v in pairs(fs.list(fsl)) do \
  160.        \
  161.                if(fs.isDir(fsl..v))then isdir=true; else isdir = false; end\
  162. \
  163.                if(not filetable[v])then\
  164.                        filetable[v] = v\
  165.                        filetable[v] = {offset = k, dir = isdir};\
  166.                        mfoff = mfoff + 1 \
  167.                end\
  168. \
  169.        end\
  170. \
  171. end\
  172. end\
  173. \
  174. \
  175. function drawMenu(x,y)\
  176. \
  177. \
  178.        for k, v in pairs(contextMenu)do\
  179. \
  180.                ea.sbc(v.bcol)\
  181.                ea.stc(v.tcol)\
  182.                ea.scp(x+2,y+v.yoff)\
  183.                print(k)\
  184. \
  185.        end\
  186.                \
  187. end\
  188. \
  189. function drawEmptyContext(x,y)\
  190. \
  191.        for k, v in pairs(contextEmpty)do\
  192. \
  193.                v.x=x\
  194.                v.y=y+v.yoff\
  195.                ea.sbc(v.bcol)\
  196.                ea.stc(v.tcol)\
  197.                ea.scp(x+2,y+v.yoff)\
  198.                print(k)\
  199. \
  200.        end\
  201. \
  202. end\
  203. \
  204. \
  205. function drawFolderMenu(x,y)\
  206. \
  207. \
  208.        for k, v in pairs(folderMenu)do\
  209. \
  210.                ea.sbc(v.bcol)\
  211.                ea.stc(v.tcol)\
  212.                ea.scp(x+2,y+v.yoff)\
  213.                print(k)\
  214. \
  215.        end\
  216.                \
  217. end\
  218. \
  219. \
  220. function fileSystem()\
  221. \
  222.                \
  223. \
  224.        while inRun do \
  225. \
  226.                clear()\
  227. \
  228.                ea.scp(1,2)\
  229. \
  230.                moff = 14\
  231. \
  232. \
  233.                loadFS(fPath)\
  234.                \
  235. \
  236.                ea.sbc(theme.bgcolor)\
  237.                term.clear()\
  238.                ea.sbc(theme.tbcolor)\
  239.                ea.scp(1,1)\
  240.                term.clearLine()\
  241.                ea.stc(theme.tbtcolor)\
  242.                ea.scp(1,1)\
  243.                print(\"Cozy File Manager \")\
  244.                ea.scp(w-#fs_ver,1)\
  245.                print(fs_ver)\
  246.                ea.stc(theme.infocolor)\
  247.                ea.sbc(theme.bgcolor)\
  248.                print(fPath)\
  249.                print(\"[BACK]                                       [EXIT]\")\
  250. \
  251. \
  252. \
  253.                for k, v in pairs(filetable) do\
  254. \
  255.                        if(v.offset-printoff < moff+1 and v.offset >= printoff)then\
  256. \
  257.                                if( ((v.offset)-printoff)+3 < 4)then addl = 4 else addl = ( (v.offset) - printoff )+3 end\
  258.                                \
  259.                                if(checkShort(k))then \
  260.                                        ea.stc(theme.shortcolor) \
  261.                                else \
  262.                                        if(v.dir)then \
  263.                                                ea.stc(theme.foldercolor) \
  264.                                        else \
  265.                                                ea.stc(theme.filecolor)\
  266.                                        end \
  267.                                end\
  268. \
  269.                                if(v.dir)then ea.sbc(theme.iconbgcolor); ea.scp(1,addl); write(theme.folderIcon); if(cut and copy_path == fPath..k)then ea.stc(theme.dimtextcolor) else ea.stc(theme.textcolor); end ea.sbc(theme.bgcolor); if(fPath..k == selFile)then ea.sbc(theme.selectedcolor) else ea.sbc(theme.bgcolor) end; print(\" \"..k) end\
  270.                                if(not v.dir)then ea.sbc(theme.iconbgcolor); ea.scp(1,addl); write(theme.fileIcon); ea.sbc(theme.bgcolor); if(cut and copy_path == fPath..k)then ea.stc(theme.dimtextcolor) else ea.stc(theme.textcolor); end if(fPath..k == selFile)then ea.sbc(theme.selectedcolor) else ea.sbc(theme.bgcolor) end; print(\" \"..k) end\
  271.                        end\
  272. \
  273.                        if(mfoff-printoff > moff)then\
  274. \
  275.                                        ea.stc(theme.infocolor)\
  276.                                        ea.scp(10,3)\
  277.                                        print(\"+\")\
  278.                        end\
  279. \
  280.                        if(printoff+1 > 1)then\
  281. \
  282.                                        ea.stc(theme.infocolor)\
  283.                                        ea.scp(11,3)\
  284.                                        print(\"-\")\
  285.                        end\
  286. \
  287.                end\
  288. \
  289. \
  290.                mi = {os.pullEvent()}\
  291. \
  292. \
  293.                if(mi[1] == \"mouse_click\" and mi[2] == 1)then\
  294. \
  295.                        fBi = 1\
  296.                        clkF = 0\
  297. \
  298.                        for k, v in pairs(filetable) do\
  299. \
  300.                                if(mi[3] >= 1 and mi[3] <= 4+#k and mi[4] == (v.offset-printoff)+3)then\
  301. \
  302.                                        clkF = 1\
  303.                                        if(v.dir and selFile == fPath..k)then fPrePath = fPath; fPath = fPath..k..\"/\"; loadFS(fPath); selFile = \"\"; printoff = 0 end\
  304.                                        if(selFile == fPath..k)then ea.stc(colors.white); ea.sbc(colors.black); ea.scp(1,1); os.run({},fPath..k); term.setCursorBlink(false) ea.sbc(colors.black) ea.stc(colors.white) term.clear() print(\"Press Any Key\") os.pullEvent(\"key\")\
  305.                                                else selFile = \"\"; selFile = fPath..k; fName = k end\
  306.                                \
  307.                                end\
  308. \
  309.                        end\
  310.                                if(clkF == 0)then selFile = \"\" end\
  311. \
  312.                                if( mi[3] >= 1 and mi[3] <= 6 and mi[4] == 3)then \
  313.                                        fPrePath = cozy_string.split(fPrePath,\"/\",(cozy_string.pathLen(fPath)-fBi))\
  314.                                        fPath = fPrePath;  \
  315.                                        printoff = 0 \
  316.                                        selFile = \"\"\
  317.                                        loadFS(fPath)\
  318.                                        fBi = 0\
  319.                                end\
  320. \
  321.                                if( mi[3] >= w-6 and mi[3] <= w and mi[4] == 3)then inRun=false; ea.sbc(colors.black) ea.stc(colors.white) ea.scp(1,1)  end\
  322. \
  323.                else\
  324. \
  325.                        fBi = 1\
  326. \
  327.                        if(mi[1] == \"key\" or mi[1] == \"mouse_scroll\")then\
  328. \
  329.                                ea.scp(1,1)\
  330.                                pfc = mfoff\
  331.                                if(mi[2] == keys.up or mi[2] == -1)then if(printoff > 0)then printoff = printoff - 1 end end\
  332.                                if(mi[2] == keys.down or mi[2] == 1)then if(printoff < mfoff-moff)then printoff = printoff + 1 end end\
  333. \
  334.                        end\
  335. \
  336.                end\
  337. \
  338.                if(mi[1] == \"mouse_click\" and mi[2] == 2)then\
  339. \
  340.                        i = 0\
  341. \
  342.                        for k, v in pairs(filetable) do\
  343.                                \
  344.                                i = i + 1\
  345. \
  346.                                if(mi[3] >= 1 and mi[3] <= #k+5 and mi[4] == (v.offset-printoff)+3 and not inContext)then\
  347.                                        \
  348.                                        if(selFile == fPath..k)then\
  349.                                                \
  350.                                                if(mi[4] >= h-9)then\
  351.                                                        prntedY = ((v.offset-printoff)+3)-9\
  352.                                                else\
  353.                                                        prntedY = (v.offset-printoff)+3\
  354.                                                end\
  355. \
  356.                                                renameY = (v.offset-printoff)+3 \
  357. \
  358.                                                if(not fs.isDir(selFile))then drawMenu(1,prntedY) else if(mi[4] >= h-10)then end drawFolderMenu(1,prntedY) end\
  359.                                                contextY = prntedY\
  360.                                                cEmpty=false\
  361.                                                inContext = true\
  362.                                                inRun = false\
  363.                                                fileSystem()\
  364. \
  365.                                                \
  366.                                        end\
  367.                                end\
  368. \
  369.                                if(selFile == \"\" and not (mi[3] >= w-6 and mi[3] <= w and mi[4] == 3) )then\
  370. \
  371.                                                if(mi[4] >= h-5)then pY = mi[4]-10 else pY = mi[4] end\
  372.                                                if(mi[3] >= w-12)then pX = w-22 else pX = mi[3] end\
  373.                                                drawEmptyContext(pX,pY) \
  374.                                                cEmpty = true\
  375.                                                inContext=true\
  376.                                                inRun=false\
  377. \
  378.                                end\
  379. \
  380.                        end\
  381. \
  382.                if(i == 0 )then\
  383. \
  384.                        if(mi[4] >= h-5)then\
  385.                                pY = mi[4]-10\
  386.                        else\
  387.                                pY = mi[4]\
  388.                        end\
  389. \
  390.                        if(mi[3] >= w-12)then\
  391.                                pX = w-22\
  392.                        else\
  393.                                pX = mi[3]\
  394.                        end\
  395. \
  396.                        drawEmptyContext(pX,pY) \
  397.                        cEmpty = true\
  398.                        inContext=true\
  399.                        inRun=false\
  400. \
  401.                end\
  402. \
  403.        end\
  404. end\
  405. \
  406. \
  407.        while inContext and not inRun do\
  408. \
  409.                m = {os.pullEvent()}\
  410. \
  411.                if(m[1] == \"mouse_click\")then\
  412. \
  413.                        if(m[2] == 2)then inContext = false; inRun = true; fileSystem() end\
  414. \
  415.                        if(cEmpty)then\
  416.                                for k, v in pairs(contextEmpty) do\
  417. \
  418.                                        if(m[2] == 1 and m[3] >= v.x and m[3] <= (#k)+v.x and m[4] == v.y)then\
  419. \
  420.                                                v.fcmd()\
  421. \
  422.                                        end\
  423. \
  424.                                end\
  425.                        end\
  426. \
  427. \
  428.                        if(not fs.isDir(selFile) and not cEmpty)then\
  429. \
  430.                                for k, v in pairs(contextMenu) do\
  431. \
  432.                                        if(m[2] == 1 and m[3] >=3 and m[3] <= #k+3 and m[4] == v.yoff+contextY)then\
  433. \
  434.                                                v.fcmd()\
  435. \
  436.                                        end\
  437. \
  438.                                end\
  439.                        end\
  440. \
  441.                        if(not cEmpty and fs.isDir(selFile))then\
  442.                                for k, v in pairs(folderMenu) do\
  443. \
  444.                                        if(m[2] == 1 and m[3] >=3 and m[3] <= #k+3 and m[4] == v.yoff+contextY)then\
  445. \
  446.                                                v.fcmd()\
  447. \
  448.                                        end\
  449. \
  450.                                end\
  451.                        end                             \
  452. \
  453.                end\
  454. \
  455.        end\
  456. \
  457. end\
  458. fileSystem()",
  459.   },
  460.   [ "vhd/RedOS/redos" ] = {
  461.     content = "\
  462. \
  463. -- Life Easier Commands -- \
  464. local w, h = term.getSize()\
  465. local scp = term.setCursorPos\
  466. local sbc = term.setBackgroundColor\
  467. local stc = term.setTextColor\
  468. local sp = textutils.slowPrint\
  469. local cl = term.clear\
  470. local needUpdate = false\
  471. local iconContent = {}\
  472. local clk = function(btext,x,y,color,time) sbc(color) scp(x,y) write(btext) sleep(time) end\
  473. shell.setDir(\"\")\
  474. \
  475. function checkUpdate()\
  476.        local res = http.get(\"http://www.pastebin.com/raw.php?i=mZi6TjgU\")\
  477. \
  478.        if res then \
  479.                con = res.readAll() \
  480.                res.close() \
  481. \
  482.                f = fs.open(shell.getRunningProgram(),\"r\")\
  483.                compare = f.readAll()\
  484.                f.close()\
  485. \
  486.                if(con ~= compare)then \
  487.                        needUpdate = true\
  488.                else\
  489.                        needUpdate = false\
  490.                end\
  491. \
  492.        end\
  493. \
  494. end\
  495. \
  496. function UncodeColor(code)\
  497. \
  498.        local code_colors = {\
  499. \
  500.                [\"0\"] = colors.white,\
  501.                [\"1\"] = colors.orange,\
  502.                [\"2\"] = colors.magenta,\
  503.                [\"3\"] = colors.lightBlue,\
  504.                [\"4\"] = colors.yellow,\
  505.                [\"5\"] = colors.lime,\
  506.                [\"6\"] = colors.pink,\
  507.                [\"7\"] = colors.gray,\
  508.                [\"8\"] = colors.lightGray,\
  509.                [\"9\"] = colors.cyan,\
  510.                [\"a\"] = colors.purple,\
  511.                [\"b\"] = colors.blue,\
  512.                [\"c\"] = colors.brown,\
  513.                [\"d\"] = colors.green,\
  514.                [\"e\"] = colors.red,\
  515.                [\"f\"] = colors.black,\
  516. \
  517.        }\
  518. \
  519. \
  520.        for k, v in pairs(code_colors) do\
  521.                if(code == k)then return v end\
  522.        end\
  523. \
  524. end\
  525. \
  526. \
  527. function drawIcon(file,x,y)\
  528. \
  529.        x = x - 1\
  530.        y = y - 1\
  531. \
  532.        file = \"tut/lol\"\
  533.        -- get file and content from a 5x5 pixel area --\
  534.        f = fs.open(file,\"r\")\
  535.        for i = 1, 5 do\
  536.                table.insert(iconContent,f.readLine():sub(1,5))\
  537.        end\
  538.        f.close()\
  539. \
  540.        -- now to draw the contents grabed from the icon\
  541.        for i = 1, #iconContent do\
  542.                -- how do i set the color?\
  543.                for cf = 1, 5 do\
  544.                        scp(x+cf,y+i)\
  545.                        sbc(UncodeColor(iconContent[i]:sub(cf,cf)))\
  546.                        write(\" \")\
  547.                end\
  548.        end\
  549. \
  550. end\
  551. \
  552. \
  553. function fadeScr()\
  554.        local fadecolors = {colors.black,colors.gray,colors.lightGray,colors.white}\
  555.                for i = 1, #fadecolors do\
  556.             term.setBackgroundColor(fadecolors[i])\
  557.             term.clear()\
  558.             sleep(rate)\
  559.           end\
  560. end\
  561. \
  562. function fadeout_complete(rate,text)\
  563.        local fadecolors = {colors.white,colors.lightGray,colors.gray,colors.black}\
  564.        local txtfcolors = {colors.black,colors.gray,colors.lightGray,colors.black}\
  565.                for i = 1, #fadecolors do\
  566.                 term.setBackgroundColor(fadecolors[i])\
  567.             term.clear()\
  568.                 term.setTextColor(txtfcolors[i])\
  569.                 center_complete(text)\
  570.             sleep(rate)\
  571.           end\
  572. end\
  573. \
  574. function center_x(text,y)\
  575.   term.setCursorPos((w/2) - (#text/2), y)\
  576.   print(text)\
  577. end\
  578. \
  579. function center_y(text,x)\
  580.   term.setCursorPos(x, (h/2))\
  581.   print(text)\
  582. end\
  583. \
  584. function center_complete(text,optional_yoffset)\
  585.   if(not optional_yoffset)then term.setCursorPos((w/2) - (#text/2), (h/2) ) end\
  586.   if(optional_yoffset)then term.setCursorPos((w/2) - (#text/2), (h/2)+optional_yoffset) end\
  587.   write(text)\
  588. end\
  589. -----------------------------\
  590. \
  591. \
  592. -- Program Enviorment\
  593. local programs = {\
  594.         prgs = {},\
  595.         progpath = \".RedOS/docs/\",\
  596.         selected=false,\
  597.         inMenu = false,\
  598.         menutype = '',\
  599.         selID = 1,\
  600. \
  601.        shortAddMenu = {\
  602. \
  603.                {g=\"                                          \"};\
  604.                {g=\"               Add Shortcut?              \"};\
  605.                {g=\"                                          \"};\
  606.                {g=\"                                          \"};\
  607.                {g=\"           [Accept]  -  [Cancel]          \"};\
  608. \
  609.        },\
  610. \
  611.        remMenu = {\
  612. \
  613.                {g=\"                                          \"};\
  614.                {g=\"              Delete Program?             \"};\
  615.                {g=\"                                          \"};\
  616.                {g=\"                                          \"};\
  617.                {g=\"           [Accept]  -  [Cancel]          \"};\
  618. \
  619.        },\
  620. \
  621.        shortRemMenu = {\
  622. \
  623.                {g=\"                                          \"};\
  624.                {g=\"              Remove Shortcut?            \"};\
  625.                {g=\"                                          \"};\
  626.                {g=\"                                          \"};\
  627.                {g=\"           [Accept]  -  [Cancel]          \"};\
  628. \
  629.        },\
  630. \
  631.         draw_short = function(self, state)\
  632.                if(state)then shm = self.shortRemMenu else shm = self.shortAddMenu end\
  633.                scp(1,(h/2) - (#shm)/2)\
  634.                for i = 1, #shm do\
  635.                        sbc(colors.orange)\
  636.                        stc(colors.white)\
  637.                        scp(5,((h/2) - ((#shm)/2))+i)\
  638.                        print(shm[i].g)\
  639.                        sleep(0.01)\
  640.                end\
  641.        end,\
  642. \
  643.        draw_del = function(self)\
  644.                shm = self.remMenu\
  645.                scp(1,(h/2) - (#shm)/2)\
  646.                for i = 1, #shm do\
  647.                        sbc(colors.orange)\
  648.                        stc(colors.white)\
  649.                        scp(5,((h/2) - ((#shm)/2))+i)\
  650.                        print(shm[i].g)\
  651.                        sleep(0.01)\
  652.                end\
  653.        end,\
  654. \
  655. \
  656. \
  657.         checkShort = function(self,name)\
  658.                return fs.isDir(\".RedOS/desktop/\"..name)\
  659.         end,\
  660. \
  661.         deleteShort = function(self,name)\
  662.                 fs.delete(\".RedOS/desktop/\"..name)\
  663.         end,\
  664. \
  665.        makeShortcut = function(self,name,mkLoc)\
  666.                 fs.makeDir(\".RedOS/desktop/\"..name)\
  667.                 fs.copy(mkLoc, \".RedOS/desktop/\"..name..\"/\"..name)\
  668.                 \
  669.                 shell.run(\"paint\",\".RedOS/desktop/\"..name..\"/icon\")\
  670.         end,\
  671. \
  672.        getprogs = function(self)\
  673.                self.prgs = {}\
  674.                for k, v in pairs(fs.list(self.progpath)) do\
  675.                        self.prgs[k] = {sel=false,file=v,off=k,dir = fs.isDir(self.progpath..v)}\
  676.                end\
  677.        end,\
  678. \
  679. \
  680. \
  681.        clear = function(self)\
  682.                sbc(colors.white)\
  683.                cl()\
  684. \
  685.                sbc(colors.red)\
  686.                scp(1,1)\
  687.                term.clearLine()\
  688.                scp(1,1)\
  689.                stc(colors.white)\
  690.                write(\"Programs\")\
  691.                sbc(colors.orange)\
  692.                scp(w,1)\
  693.                write(\"X\")\
  694.                scp((w)-9,2)\
  695.                sbc(colors.red)\
  696.                stc(colors.white)\
  697.                self:getprogs()\
  698.                for i = 2, h do \
  699.                        scp(w-9,i)\
  700.                        write(string.rep(\" \",10))\
  701.                end\
  702.        end,\
  703. \
  704.        draw = function(self)\
  705.                self:clear()\
  706.        end,\
  707. \
  708.        update = function(self)\
  709. \
  710.                sbc(colors.orange)\
  711.                stc(colors.white)\
  712.                center_x(\"Downloaded Programs\",3)\
  713. \
  714. \
  715.                stc(colors.black)\
  716.                sbc(colors.red)\
  717.                scp(w-8,3)\
  718.                write(\"Shortcut\")\
  719.                scp(w-8,4)\
  720.                write(\"Delete\")\
  721.                sbc(colors.white)\
  722.                -- print out programs--\
  723. \
  724.                -- draw programs --\
  725.                \
  726. \
  727.                for i = 1, #self.prgs do\
  728.                        if(not self.prgs[i].dir)then \
  729.                                scp(1,i+3)\
  730.                                stc(colors.black)\
  731.                                if(self.prgs[i].sel)then sbc(colors.lightBlue) else sbc(colors.white) end\
  732.                                if(self:checkShort(self.prgs[i].file))then stc(colors.green) else stc(colors.black) end\
  733.                                print(self.prgs[i].file)\
  734.                        end\
  735.                end\
  736. \
  737.                a = {os.pullEvent()}\
  738. \
  739.                if( (a[1] == \"mouse_drag\" or a[1] == \"mouse_click\") and a[2] == 1)then\
  740.                                if(a[3] >= w and a[4] == 1)then \
  741.                                        clk(\"X\",w,1,colors.red,0.2)\
  742.                                        self.selected=false\
  743.                                        setState('desktop') \
  744.                                end\
  745.                        scp(1,2)\
  746.                        stc(colors.black)\
  747.                        --print(a[3]..\" | \"..a[4])\
  748. \
  749.                        -- Button Clicks --\
  750.                        if(a[3] >= w-10 and a[4] == 4 and self.selected)then -- Remove File\
  751.                                self:draw_del()\
  752.                                self.inMenu = true\
  753.                                menutype = 'remove'\
  754.                        end\
  755. \
  756.                        if(a[3] >= w-10 and a[4] == 3 and self.selected)then -- Manage Shortcut File\
  757.                                \
  758.                                if(self:checkShort(self.prgs[self.selID].file))then \
  759.                                        self:draw_short(true)\
  760.                                        self.inMenu = true\
  761.                                    menutype = 'shortcut-' \
  762.                                else \
  763.                                        self:draw_short(false)\
  764.                                        self.inMenu = true\
  765.                                        menutype = 'shortcut+' \
  766.                                end\
  767.                        end\
  768. \
  769.                        -- cancel button --\
  770. \
  771.                        if(a[3] >= 29 and a[3] <= 36 and a[4] == 12 and self.inMenu == true)then\
  772.                                self.selected=false\
  773.                                self.inMenu=false\
  774.                                self:clear()\
  775.                        end\
  776. \
  777.                        -- accept button --\
  778.                        if(a[3] >= 16 and a[3] <= 23 and a[4] == 12 and self.inMenu == true)then\
  779.                                if(menutype == 'remove')then\
  780.                                        fs.delete(self.progpath..self.prgs[self.selID].file)\
  781.                                        if(self:checkShort(self.prgs[self.selID].file))then self:deleteShort(self.prgs[self.selID].file) end\
  782.                                        self:clear()\
  783.                                        self:update()\
  784.                                        self.inMenu = false\
  785.                                        self.selected=false\
  786.                                elseif(menutype=='shortcut+')then\
  787.                                        self:makeShortcut(self.prgs[self.selID].file,self.progpath..self.prgs[self.selID].file)\
  788.                                        self.inMenu = false\
  789.                                        self.selected=false\
  790.                                        setState('desktop')\
  791.                                elseif(menutype=='shortcut-')then\
  792.                                        self:deleteShort(self.prgs[self.selID].file)\
  793.                                        self:clear()\
  794.                                        self:update()\
  795.                                        self.inMenu = false\
  796.                                        self.selected=false\
  797.                                end\
  798.                        end\
  799. \
  800.                                -- program selection / management --\
  801.                        for i = 1, #self.prgs do\
  802.                                if(not self.prgs[i].dir)then \
  803. \
  804.                                        if(a[3] >= 1 and a[3] <= #self.prgs[i].file and a[4] == i+3)then\
  805.                                                if(self.selected)then\
  806.                                                        if(self.prgs[i].sel)then self.prgs[i].sel=false self.selected=false end\
  807.                                                else\
  808.                                                        self.prgs[i].sel = true\
  809.                                                        self.selected=true\
  810.                                                        self.selID = i\
  811.                                                end\
  812.                                                self:update()\
  813.                                        end\
  814.                                end\
  815.                        end\
  816.                end\
  817.        end,\
  818. }\
  819. \
  820. \
  821. -- Downloader Enviorment\
  822. local downloader = {\
  823.                \
  824.        downloading=false,\
  825. \
  826.        dwnFiles = {\
  827.                {text=\"Kosy Mail\",url=\"Tsjq5eVa\",locdir = \".RedOS/docs/cozymail\",down=false,install=true,has=false};\
  828.                {text=\"Kosy Chat\",url=\"cj8SKTMj\", locdir = \".RedOS/docs/cozychat\",down=false,install=false,has=true};\
  829.        },\
  830. \
  831. \
  832.        draw = function(self)\
  833.                sbc(colors.white)\
  834.                cl()\
  835.                sbc(colors.red)\
  836.                scp(1,1)\
  837.                term.clearLine()\
  838.                scp(1,1)\
  839.                stc(colors.white)\
  840.                write(\"Downloader\")\
  841.                sbc(colors.orange)\
  842.                scp(w,1)\
  843.                write(\"X\")\
  844.        end,\
  845.        download = function(self)\
  846. \
  847.                if(not http)then setState('desktop') end\
  848.                self.downloading=true\
  849. \
  850.                sleep(1)\
  851.                for i = 1, #self.dwnFiles do\
  852.                        if(self.dwnFiles[i].down)then\
  853.                                 local res = http.get(\"http://www.pastebin.com/raw.php?i=\"..textutils.urlEncode(self.dwnFiles[i].url) )\
  854. \
  855.                                if res then \
  856.                                         con = res.readAll() \
  857.                                        res.close() \
  858.                                else\
  859.                                        changeState('desktop')\
  860.                                end\
  861. \
  862.                                if(self.dwnFiles[i].install)then\
  863.                                        f = fs.open(\".temp\",\"w\")\
  864.                                        f.write(con)\
  865.                                        f.close()\
  866.                                        shell.run(\".temp\")\
  867.                                        fs.delete(\".temp\")\
  868.                                        self.dwnFiles[i].down = false\
  869.                                        self.downloading=false\
  870.                                else\
  871.                                        f = fs.open(self.dwnFiles[i].locdir,\"w\")\
  872.                                        f.write(con)\
  873.                                        f.close()\
  874.                                        self.dwnFiles[i].down = false\
  875.                                        self.downloading=false\
  876.                                end\
  877.                        end\
  878.                end\
  879.                \
  880.        end,\
  881.        update = function(self)\
  882. \
  883. \
  884.                if(self.downloading)then sbc(colors.red) else sbc(colors.green) end\
  885.                stc(colors.white)\
  886.                scp(1,h-1)\
  887.                write(string.rep(\" \",w))\
  888.                center_x(\"Download\",h-1)\
  889. \
  890.                sbc(colors.orange)\
  891.                stc(colors.white)\
  892.                center_x(\"Available RedOS Software\",3)\
  893. \
  894.                sbc(colors.white)\
  895.                stc(colors.black)\
  896. \
  897.                -- print out downloadablez --\
  898.                for i = 1, #self.dwnFiles do\
  899.                        if(fs.exists(self.dwnFiles[i].locdir))then self.dwnFiles[i].has = true else self.dwnFiles[i].has = false end\
  900.                        if(not self.dwnFiles[i].has)then stc(colors.black) else stc(colors.red) end\
  901.                        if(self.dwnFiles[i].down)then sbc(colors.lightBlue) else sbc(colors.white) end\
  902.                        scp(1,i+4)\
  903.                        write(self.dwnFiles[i].text)\
  904.                        scp(30,i+4)\
  905.                        stc(colors.lightGray)\
  906.                        sbc(colors.white)\
  907.                        write(self.dwnFiles[i].url)\
  908.                end\
  909. \
  910.                a = {os.pullEvent()}\
  911. \
  912.                if( (a[1] == \"mouse_drag\" or a[1] == \"mouse_click\") and a[2] == 1)then\
  913.                                if(a[3] >= w and a[4] == 1)then \
  914.                                        clk(\"X\",w,1,colors.red,0.2)\
  915.                                        setState('desktop') \
  916.                                end\
  917. \
  918.                                --Download--\
  919.                                if(a[4] == 18)then\
  920.                                        self:download()\
  921.                                end\
  922. \
  923.                                for i = 1, #self.dwnFiles do\
  924.                                                if(a[3] >= 1 and a[3] <= #self.dwnFiles[i].text \
  925.                                                        and a[4] == i+4 and not self.dwnFiles[i].has)then\
  926.                                                        if(not self.dwnFiles[i].down)then self.dwnFiles[i].down = true \
  927.                                                        else self.dwnFiles[i].down = false end \
  928.                                                end\
  929.                                end\
  930.                end\
  931.        end,\
  932.        clear = function(self)\
  933.                sbc(colors.white)\
  934.                cl()\
  935.                sbc(colors.red)\
  936.                scp(1,1)\
  937.                term.clearLine()\
  938.                scp(1,1)\
  939.                stc(colors.white)\
  940.                write(\"Downloader\")\
  941.                sbc(colors.orange)\
  942.                scp(w,1)\
  943.                write(\"X\")\
  944.        end,\
  945. \
  946. }\
  947. \
  948. \
  949. -- Desktop Enviorment\
  950. local desktop = {\
  951.        \
  952.        sMenuWidth = 10,\
  953.        inMenu = false, \
  954.        deskLoc = \".RedOS/desktop/\",\
  955.        deskProgs = {};\
  956.        ficons = {},\
  957.        icon_width = 4,\
  958.        icon_height = 5,\
  959.        needUpdateInstance=false,\
  960. \
  961. \
  962.        get_desk = function(self)\
  963.                self.deskProgs = {}\
  964.                for k, v in pairs(fs.list(self.deskLoc)) do\
  965.                        if(fs.isDir(self.deskLoc..v))then\
  966.                                self.deskProgs[k] = {name=v,file=self.deskLoc..v..\"/\"..v,icon=self.deskLoc..v..\"/icon\"}\
  967.                        end\
  968.                end\
  969.        end,\
  970. \
  971.        loadBack = function(self)\
  972.                if(fs.exists(\".RedOS/graphics/background\"))then\
  973.                        paintutils.drawImage(paintutils.loadImage(\".RedOS/graphics/background\"), 2, 1)\
  974.                end\
  975.        end,\
  976. \
  977.        draw_desk = function(self)\
  978.                \
  979.                self.ficons = {}\
  980. \
  981.                local c_tab = 0\
  982.                local sp_count = 0\
  983.                local mx_tab = 2\
  984.                local x_degree = 10\
  985.                local y_degree = 7\
  986. \
  987.                for i = 1, #self.deskProgs do\
  988.                        -- get current files icon\
  989.                        if(c_tab == 2)then sp_count = sp_count + 1 c_tab = 0 end\
  990.                        c_tab = c_tab + 1\
  991.                        self.ficons[i] = {icon = self.deskProgs[i].icon, x = 2, y = i+((i-1)*y_degree)}\
  992.                        local fileico = paintutils.loadImage(self.ficons[i].icon)\
  993.                        local calc_x = sp_count*x_degree\
  994.                        local calc_y = (c_tab-1)*y_degree\
  995.                        self.ficons[i].x = self.ficons[i].x + calc_x\
  996.                        self.ficons[i].y = calc_y + 2\
  997.                        paintutils.drawImage(fileico, self.ficons[i].x, self.ficons[i].y)\
  998.                        scp( self.ficons[i].x - 1, 1 + self.ficons[i].y + 3 )\
  999.                        sbc(colors.white)\
  1000.                    stc(colors.black)\
  1001.                        print(self.deskProgs[i].name)\
  1002. \
  1003.                end\
  1004.                \
  1005.        end,\
  1006. \
  1007.        draw_avaupdate = function(self)\
  1008.                scp(1,(h/2) - (#self.updateMenu)/2)\
  1009.                for i = 1, #self.updateMenu do\
  1010.                        sbc(colors.red)\
  1011.                        stc(colors.white)\
  1012.                        scp(5,((h/2) - ((#self.updateMenu)/2))+i)\
  1013.                        print(self.updateMenu[i].g)\
  1014.                        sleep(0.01)\
  1015.                end\
  1016.        end,\
  1017. \
  1018.        reboot = function(self)\
  1019.                sbc(colors.white)\
  1020.                cl()\
  1021.                stc(colors.black)\
  1022.                print()\
  1023.                fadeout_complete(0.2,\"Rebooting...\")\
  1024.                sleep(0.4)\
  1025.                os.reboot()\
  1026.        end,\
  1027.        shutdown = function(self)\
  1028.                sbc(colors.white)\
  1029.                cl()\
  1030.                stc(colors.black)\
  1031.                print()\
  1032.                fadeout_complete(0.2,\"Shutting Down...\")\
  1033.                sleep(0.4)\
  1034.                os.shutdown()\
  1035.        end,\
  1036. \
  1037.        startMenu = {\
  1038. \
  1039.                {text=\"           \",run = function() end};\
  1040.                {text=\" Settings> \",run = function(self)  self.inMenu = false shell.run(\"paint\", \".RedOS/graphics/background\") self:draw() end};\
  1041.                {text=\" Download> \",run = function() changeState('downloader') end};\
  1042.                {text=\" Explorer> \",run = function(self) shell.run(\".RedOS/startmenu/apps/cozyfile\") self.inMenu = false self:draw() end};\
  1043.                {text=\" Programs> \",run = function(self) changeState('programs') end};\
  1044.                {text=\" Shell     \",run = function() sbc(colors.black) stc(colors.white) scp(1,1) cl() shell.run(\"shell\") end};\
  1045.                {text=\" Reboot    \",run = function(self) self:reboot() end};\
  1046.                {text=\" Shutdown  \",run = function(self) self:shutdown() end};\
  1047.                {text=\" Update    \",run = function(self) checkUpdate() self.inMenu =false self:draw() end};\
  1048.                {text=\"           \",run = function() end};\
  1049.        },\
  1050. \
  1051. \
  1052.        updateMenu = {\
  1053. \
  1054.                {g=\"                                          \"};\
  1055.                {g=\"             Update Available             \"};\
  1056.                {g=\"                                          \"};\
  1057.                {g=\"                                          \"};\
  1058.                {g=\"         [Download]  -  [Not Now]         \"};\
  1059. \
  1060.        },\
  1061. \
  1062.        clear = function(self)\
  1063.                fadeScr(0.08)\
  1064.                self:loadBack()\
  1065.                sbc(colors.red)\
  1066.                scp(1,19)\
  1067.                sleep(0.1)\
  1068.                write(string.rep(\" \",w))\
  1069.                stc(colors.white)\
  1070.                scp(1,19)\
  1071.                checkUpdate()\
  1072.                self.needUpdateInstance = needUpdate\
  1073.                write(\"RedOS\")\
  1074.                if(not self.needUpdateInstance)then\
  1075.                        write(\"              Up to Date!\")\
  1076.                else\
  1077.                        write(\"             Needs Update!\")   \
  1078.                end\
  1079.                sbc(colors.black)\
  1080.                self:get_desk()\
  1081.                self:draw_desk()\
  1082.        end,\
  1083.        draw = function(self)\
  1084.                sbc(colors.white)\
  1085.                cl()\
  1086.                self:loadBack()\
  1087.                sbc(colors.red)\
  1088.                scp(1,19)\
  1089.                write(string.rep(\" \",w))\
  1090.                stc(colors.white)\
  1091.                scp(1,19)\
  1092.                write(\"RedOS\")\
  1093.                if(not self.needUpdateInstance)then\
  1094.                        write(\"              Up to Date!\")    \
  1095.                else\
  1096.                        write(\"             Needs Update!\")   \
  1097.                end\
  1098.                sbc(colors.black)\
  1099.                self:get_desk()         \
  1100.        end,\
  1101.        update = function(self)\
  1102.                \
  1103. \
  1104.                --Events--\
  1105.                self:draw_desk()\
  1106. \
  1107. \
  1108.                --- Check if a update is needed -- \
  1109.                if(needUpdate)then\
  1110.                        self:draw_avaupdate()\
  1111.                end\
  1112. \
  1113.                if(self.inMenu)then\
  1114.                        -- Drawing Da Menu --\
  1115.                         \
  1116.                         for i =1, #self.startMenu do\
  1117.                                sbc(colors.gray)\
  1118.                                stc(colors.white)\
  1119.                                scp(1,18-#self.startMenu+i)\
  1120.                                write(self.startMenu[i].text)\
  1121.                         end\
  1122. \
  1123.                end\
  1124. \
  1125.                e = {os.pullEvent()}\
  1126.                \
  1127.                if(e[1] == \"mouse_click\" and not self.inMenu)then\
  1128.                                        -- desktop item clicks brah --\
  1129.                        for i = 1, #self.deskProgs do\
  1130. \
  1131.                                -- Click detection --\
  1132.                                if(e[3] >= self.ficons[i].x and \
  1133.                                        e[3] <= self.icon_width+self.ficons[i].x and \
  1134.                                        e[4] >= self.ficons[i].y and \
  1135.                                        e[4] <= self.icon_height+self.ficons[i].y ) then\
  1136. \
  1137.                                        -- run program -- \
  1138.                                        sbc(colors.black)\
  1139.                                        stc(colors.white)\
  1140.                                        term.clear()\
  1141.                                        if(e[2] == 1)then\
  1142.                                                os.run({},self.deskProgs[i].file)\
  1143.                                                center_complete(\"Press Any Key To Return to RedOS\")\
  1144.                                                center_complete(\"Program Ran: \"..self.deskProgs[i].file,1)\
  1145.                                                os.pullEvent(\"key\")\
  1146.                                        elseif(e[2] == 2)then\
  1147.                                                \
  1148.                                                shell.run(\"paint \",self.deskProgs[i].icon)\
  1149.                                        end\
  1150. \
  1151.                                        self:draw()\
  1152.                                end\
  1153.                        end\
  1154.                end\
  1155. \
  1156.                if(e[1] == \"mouse_click\" and e[2] == 1)then\
  1157. \
  1158.                        -- Start Menu Clicked --\
  1159.                        -- e[2] == mouse_button e[3] == mouse_x, e[4] == mouse_y, \
  1160.                        --scp(1,1)\
  1161.                        --print(\"X: \"..e[3]..\"Y: \"..e[4])\
  1162.                        if(needUpdate)then\
  1163.                                if(e[3] >= 14 and e[3] <= 23 and e[4] == 12)then\
  1164.                                        -- download update --\
  1165.                                        sbc(colors.white)\
  1166.                                        cl()\
  1167.                                        stc(colors.black)\
  1168.                                        center_x(\"Downloading Update....\",2)\
  1169.                                        scp(1,4)\
  1170.                                        stc(colors.lightGray)\
  1171.                                        print(\"Pinging RedOS File...\")\
  1172.                                        local redRes = http.get(\"http://www.pastebin.com/raw.php?i=mZi6TjgU\")\
  1173.                                        if(redRes)then\
  1174.                                                local con = redRes.readAll()\
  1175.                                                redRes.close()\
  1176.                                                stc(colors.green)\
  1177.                                                print(\"Success!.\")\
  1178.                                                stc(colors.gray)\
  1179.                                                print(\"Replaceing File...\")\
  1180.                                                fs.delete(shell.getRunningProgram())\
  1181.                                                f = fs.open(shell.getRunningProgram(),\"w\")\
  1182.                                                f.write(con)\
  1183.                                                stc(colors.black)\
  1184.                                                center_x(\"Press Any Key To Reboot\",7)\
  1185.                                                os.pullEvent(\"key\")\
  1186.                                                os.reboot()\
  1187.                                        else\
  1188.                                                stc(colors.red)\
  1189.                                                print(\"Failed.\")\
  1190.                                                stc(colors.gray)\
  1191.                                                print(\"Please check your connection to the internet\")\
  1192.                                                stc(colors.black)\
  1193.                                                center_x(\"Press Any Key\",7)\
  1194.                                                os.pullEvent(\"key\")\
  1195.                                                self:draw()\
  1196.                                        end\
  1197.                                end\
  1198. \
  1199.                                if(e[3] >= 29 and e[3] <= 37 and e[4] == 12)then\
  1200.                                        -- not now\
  1201.                                        needUpdate=false\
  1202.                                        self:draw()\
  1203.                                end     \
  1204.                        end\
  1205. \
  1206.                        if(e[3] >= 1 and e[3] <= 5 and e[4] == 19)then\
  1207. \
  1208.                                if(not self.inMenu) then self.inMenu = true; \
  1209.                                elseif(self.inMenu) then self.inMenu=false end\
  1210. \
  1211.                                sbc(colors.gray)\
  1212.                                scp(1,h)\
  1213.                                write(\"RedOS\")\
  1214.                                sleep(0.1)\
  1215. \
  1216.                                self:draw()\
  1217.                                self:update()\
  1218. \
  1219.                        end\
  1220. \
  1221. \
  1222. \
  1223.                        -- Menu Button Clicks --\
  1224.                                for i = 1, #self.startMenu do \
  1225.                                        if(e[3] >= 1 and e[3] <= self.sMenuWidth and e[4] >= h-#self.startMenu and e[4] <= h and self.inMenu)then\
  1226.                                                if(self.inMenu and e[4] == i+((h-1) - #self.startMenu))then self.startMenu[i].run(self) end\
  1227.                                        elseif(self.inMenu)then self.inMenu = false self:draw()  end\
  1228.                                end\
  1229.                        end\
  1230. \
  1231.        end,\
  1232. \
  1233. }\
  1234. \
  1235. --- Without transition --\
  1236. function setState(s)\
  1237.        if(s == 'desktop')then desktop:draw() state = 'desktop' end\
  1238.        if(s == 'downloader')then downloader:draw() state = 'downloader' end\
  1239.        if(s == 'programs')then programs:draw() state = 'programs' end\
  1240.        ros()\
  1241. end\
  1242. \
  1243. -- With Transition --\
  1244. function changeState(s)\
  1245.        if(s == 'desktop')then desktop:clear() state = 'desktop' end\
  1246.        if(s == 'downloader')then downloader:clear() state = 'downloader' end\
  1247.        if(s == 'programs')then programs:clear() state = 'programs' end\
  1248.        ros()\
  1249. end\
  1250. \
  1251. function ros()\
  1252. while true do\
  1253.        sleep(0.001)\
  1254.        if(state == 'desktop')then desktop:update() end\
  1255.        if(state == 'downloader')then downloader:update() end\
  1256.        if(state == 'programs')then programs:update() end\
  1257. end\
  1258. end\
  1259. \
  1260. changeState('desktop')\
  1261. ros()",
  1262.   },
  1263.   [ "vhd/RedOS/cozy_string" ] = {
  1264.     content = "function split(inputstr, sep, index)\
  1265.       \
  1266.                i=1\
  1267. \
  1268.                t={}\
  1269. \
  1270.                s=\"\"\
  1271. \
  1272.       for str in string.gmatch(inputstr, \"([^\"..sep..\"]+)\") do\
  1273.               t[i] = str  \
  1274.               i = i + 1\
  1275.       end\
  1276. \
  1277.       for k, v in pairs(t) do\
  1278.               if(k <= index)then s = s..t[k]..\"/\" end\
  1279.       end\
  1280. \
  1281.       return s\
  1282. end\
  1283. \
  1284. \
  1285. \
  1286. function pathLen(inputstr)\
  1287. \
  1288.       i=1\
  1289.       t={}\
  1290.       s=\"\"\
  1291.       ki=0\
  1292. \
  1293.       for str in string.gmatch(inputstr, \"([^/]+)\") do\
  1294.               t[i] = str  \
  1295.               i = i + 1\
  1296.       end\
  1297. \
  1298.       for k, v in pairs(t) do\
  1299.              ki=k\
  1300.       end\
  1301. \
  1302.       return ki\
  1303. end",
  1304.   },
  1305. }
  1306.  
  1307. -- ]] wit auto extractor [[ --
  1308. function install(from)
  1309.     for k, v in pairs(fs.list(from)) do
  1310.      
  1311.       if(fs.isDir(from.."/"..v))then
  1312.         install(from..v.."/")
  1313.       else
  1314.       print("Installing: "..from..v)
  1315.       sleep(0.3)
  1316.          f = fs.open(from..v,"r")
  1317.          content = f.readAll()
  1318.          f.close()
  1319.      f = fs.open(v,"w")
  1320.      f.write(content)  
  1321.      f.close()
  1322.       end
  1323.     end
  1324. end
  1325.  
  1326. print("Extracting RedOS...")
  1327.  
  1328. local _system = {}
  1329.  
  1330. local
  1331. -- ]] make all files in _system [[ --
  1332. function loadFiles()
  1333.   for k, v in pairs(_system) do
  1334.     f = fs.open(k,"w")
  1335.     f.write(v.content)
  1336.     f.close()
  1337.     print(k)
  1338.   end
  1339.   print("RedOS Extracted!")
  1340.   print("Installing...")
  1341.   install("vhd/RedOS/")
  1342.   fs.delete("vhd")
  1343.   print("Completed!")
  1344. end
  1345.  
  1346.  
  1347. -- ]] load harddisk [[ --
  1348. _system = redos_files
  1349. fs.makeDir(".RedOS/desktop/")
  1350. loadFiles()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement