Advertisement
Freack100

D-Burn_Installer

Aug 19th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.14 KB | None | 0 0
  1. local function box(startx, endx, starty, endy, col, _fillChar)
  2.     local curry = starty
  3.     term.setBackgroundColor(col)
  4.     for u = starty, endy do
  5.     term.setCursorPos(startx, curry)
  6.     for i = 1, endx do
  7.         term.write(" ")
  8.     end
  9.     curry = curry + 1
  10. end
  11. end
  12.  
  13. local function progress(startX, startY, endX, bgcol, loadcol, progressmessage, percent)
  14. term.setCursorPos(startX, startY)
  15. term.setBackgroundColor(bgcol)
  16. for i = startX, endX do
  17. term.write(" ")
  18. end
  19. term.setCursorPos(startX, startY+1)
  20. term.setBackgroundColor(colors.green)
  21. term.write("                            ")
  22. term.setCursorPos(startX, startY+1)
  23. term.write(progressmessage)
  24. term.setCursorPos(startX, startY)
  25. term.setBackgroundColor(loadcol)
  26. for i = 0, math.floor(percent), 10 do
  27. term.write(" ")
  28. end
  29. end
  30.  
  31. local progresses = {
  32.     [30] = "Creating Folders",
  33.     [60] = "Creating Files",
  34.     [90] = "Writing Files",
  35.     [100] = "Done"
  36. }
  37.  
  38. local buttons = {
  39.     [1] = {7, 17, 19, 19, "BACK"},
  40.     [2] = {35, 45, 19, 19, "INSTALL"}
  41. }
  42.  
  43. local files = {
  44.     ".D-Burn_Images/button.nfp",
  45.     ".D-Burn_Images/rsod.nfp",
  46.     ".D-Burn_Images/homeScreen.nfp",
  47.     "D-Burn"
  48. }
  49. local folder = {".D-Burn_Images"}
  50.  
  51. local fileContent = {
  52. [".D-Burn_Images/button.nfp"] = [[ddddddddddddd
  53. ddddddddddddd
  54. ddddddddddddd
  55. ]],
  56. [".D-Burn_Images/rsod.nfp"] = [[eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
  57. eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
  58. eeeeeeeeeeee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eeeeeeeeee    
  77.  eeeeeeeeeeeeeeee                         eeeeee      
  78.   ee eee e  eeee                                      
  79. ]],
  80. [".D-Burn_Images/homeScreen.nfp"] = [[888888888888888888888888888888888888888888888888888  
  81. 8888888ffffff8888888ffff888888888888888888888888888  
  82. 888888ff0000ff888888f888f8f888f8f8ff88ff88f88888888  
  83. 888888ff0ff0ff8ffff8fffff8f888f8ff88f8fff8f88888888  
  84. 888888ff0000ff888888f888f8f888f8f88888f8fff88888888  
  85. 8888888ffffff8888888ffff888fff88f88888f88ff88888888  
  86. 888888888888888888888888888888888888888888888888888  
  87. 888888888888888888888888888888888888888888888888888  
  88. 888888888888888888888888888888888888888888888888888  
  89. 888888888888888888888888888888888888888888888888888  
  90. 888888888888888888888888888888888888888888888888888  
  91. 888888888888888888888888888888888888888888888888888  
  92. 888888888888888888888888888888888888888888888888888  
  93. 888888888888888888888888888888888888888888888888888  
  94. 888888888888888888888888888888888888888888888888888  
  95. 8888888888888888888888888888888888888888888888888888  
  96. 88888888888888888888888888888888888888888888888888888
  97. 888888888888888888888888888888888888888888888888888888
  98. 88888888888888888888888888888888888888888888888888888
  99. 8888888888888888888888888888888888888888888888888888  
  100.                     88888888888 8 88 88888    88888  
  101.                                                888    
  102.                                                 8    
  103. ]],
  104. ["D-Burn"] = [[oldPull = os.pullEvent
  105. os.pullEvent = os.pullEventRaw
  106. local programData = {
  107.     Author = "Freack100",
  108.     ProgramName = "D-Burn",
  109.     Version = "0.1",
  110.     path = shell.resolve("/")
  111. }
  112.  
  113. local neededInformation = {
  114.     noEditFilename = ".No_Files"
  115. }
  116.  
  117. local images = {
  118. homeScreen = paintutils.loadImage(".D-Burn_Images/homeScreen.nfp"),
  119. button = paintutils.loadImage(".D-Burn_Images/button.nfp"),
  120. rsod = paintutils.loadImage(".D-Burn_Images/rsod.nfp")
  121. }
  122. term.setCursorBlink(false)
  123.  
  124. local crashed = false
  125.  
  126. local function printMenu(startX, startY, txtcol, options)
  127.     local startX = startX
  128.     local currY = startY
  129.     local buttonPositions = {}
  130.     for i = 1, #options do
  131.         paintutils.drawImage(images.button, startX, currY)
  132.         if string.len(options[i]) > 13 then
  133.             error("Can't print out more than 13 characters!")
  134.         end
  135.         term.setCursorPos(((startX + 31)-string.len(options[i]))/2, currY+1)
  136.         term.setTextColor(txtcol)
  137.         term.write(options[i])
  138.         table.insert(buttonPositions, {options[i], startX, startX+13, currY, currY+3})
  139.         currY = currY + 4
  140.     end
  141.     while true do
  142.         local sEvent, sButton, sX, sY = os.pullEvent()
  143.         if sEvent == "mouse_click" and sButton == 1 then
  144.             for i = 1, #buttonPositions do
  145.                 if sX >= buttonPositions[i][2] and sX <= buttonPositions[i][3] and sY >= buttonPositions[i][4] and sY <= buttonPositions[i][5] then
  146.                     return buttonPositions[i][1]
  147.                 end
  148.             end
  149.         end
  150.     end
  151. end
  152.  
  153. local function RSoD(message)
  154.     local x,y = term.getSize()
  155.     paintutils.drawImage(images.rsod, 1, 1)
  156.     term.setCursorPos(19,2)
  157.     term.setBackgroundColor(colors.red)
  158.     term.setTextColor(colors.white)
  159.     term.write("Oh no! A RSoD!")
  160.     term.setCursorPos((x-string.len(message))/2,6)
  161.     term.write(message)
  162.     term.setCursorPos(14, 10)
  163.     term.write("Press any Key to exit...")
  164.     local clicked = false
  165.     while not clicked do
  166.         local sEvent = os.pullEvent()
  167.         if sEvent == "key" then
  168.             clicked = true
  169.         end
  170.     end
  171.     crashed = true
  172.     term.setBackgroundColor(colors.black)
  173.     term.setTextColor(colors.white)
  174.     term.clear()
  175.     term.setCursorPos(1,1)
  176.     return
  177. end
  178.  
  179. local function success(Message, yOffset)
  180.     local x,y = term.getSize()
  181.     term.setBackgroundColor(colors.lightGray)
  182.     term.setTextColor(colors.lime)
  183.     term.clear()
  184.     term.setCursorPos((x-string.len(Message)-1)/2, yOffset)
  185.     for i = 1, #Message do
  186.         term.write(string.sub(Message, i,i))
  187.         sleep(0.025)
  188.     end
  189.     sleep(1)
  190. end
  191.  
  192. local function keyMenu(sX, sY, bgcol, txtcol, markcol, options)
  193.     local sX = sX
  194.     local currY = sY
  195.     local options  = options
  196.     options[#options+1] = "Back"
  197.     local selected = 1
  198.     term.setBackgroundColor(bgcol)
  199.     term.clear()
  200.     term.setCursorPos(sX,currY)
  201.     term.setTextColor(markcol)
  202.     local function redraw()
  203.         term.clear()
  204.         for k,v in ipairs(options) do
  205.             term.setCursorPos(sX, currY)
  206.             if k == selected then
  207.                 term.setTextColor(markcol)
  208.                 term.write("[")
  209.                 term.setTextColor(txtcol)
  210.                 term.write(options[k])
  211.                 term.setTextColor(markcol)
  212.                 term.write("]")
  213.             else
  214.                 term.setTextColor(txtcol)
  215.                 term.write(options[k])
  216.             end
  217.             currY = currY+1
  218.         end
  219.         currY = sY
  220.     end
  221.     redraw()
  222.     while true do
  223.         local sEvent, sKey = os.pullEvent()
  224.         if sEvent == "key" then
  225.             if sKey == keys.up then
  226.                 if selected > 1 then
  227.                     selected = selected - 1
  228.                 else
  229.                     selected = #options
  230.                 end
  231.                 redraw()
  232.             elseif sKey == keys.down then
  233.                 if selected < #options then
  234.                 selected = selected + 1
  235.             else
  236.                 selected = 1
  237.             end
  238.                 redraw()
  239.             elseif sKey == keys.enter then
  240.                 return options[selected]
  241.             end
  242.         end
  243.         sleep(0)
  244.     end
  245. end
  246.  
  247.     while true do
  248.         paintutils.drawImage(images.homeScreen,1,1)
  249.         local mainMenu = printMenu(18,8,colors.lime, {"Burn", "Clear", "Exit"})
  250.         if mainMenu == "Exit" then
  251.             term.setBackgroundColor(colors.black)
  252.             term.clear()
  253.             term.setTextColor(colors.yellow)
  254.             term.setCursorPos(13, 2)
  255.             term.write("Thx for using " .. programData.ProgramName .. " " .. programData.Version)
  256.             term.setCursorPos(16, 4)
  257.             term.write("Made by " .. programData.Author)
  258.             term.setCursorPos(1, 6)
  259.             term.setTextColor(colors.white)
  260.             return
  261.         elseif mainMenu == "Burn" then
  262.             local burnMenu = printMenu(18,8,colors.lime, {"Non Edit Burn", "Edit Burn", "Exit"})
  263.             if burnMenu == "Exit" then
  264.  
  265.             elseif burnMenu == "Non Edit Burn" then
  266.                 local drivers = {}
  267.                 for k,v in pairs(rs.getSides()) do
  268.                     if peripheral.isPresent(v) and peripheral.getType(v) == "drive" then
  269.                         table.insert(drivers, v)
  270.                     end
  271.                 end
  272.                 if drivers[1] == nil then
  273.                     RSoD(" Oh no! There is no driver attached to the Computer!")
  274.                 end
  275.                 if disk.isPresent(drivers[1]) ~= true then
  276.                     RSoD("Oh no! There is no floppy in your driver!")
  277.                 end
  278.                 local burnDriver = peripheral.wrap(drivers[1])
  279.                 if fs.exists(burnDriver.getMountPath() .. "/.No_Files") then
  280.                     RSoD("You cant Burn a season closed disk")
  281.                 end
  282.                 if crashed then
  283.                     break
  284.                 end
  285.                 local fileList = fs.list("/")
  286.                 for k,v in pairs(fileList) do
  287.                     if v == ("rom" or burnDriver.getMountPath()) then
  288.                         table.remove(fileList, k)
  289.                     end
  290.                 end
  291.                 fileList[#fileList+1] = "Whole computer"
  292.                 local fileMenu = keyMenu(20, 2, colors.lightGray, colors.gray, colors.lime, fileList)
  293.                 local uneditable = fs.open(burnDriver.getMountPath() .. "/" .. neededInformation.noEditFilename, "w")
  294.                 uneditable.close()
  295.                 if fileMenu == "Back" then
  296.  
  297.                 elseif fileMenu == "Whole computer" then
  298.                     local function wholeCopy()
  299.                         for k,v in pairs(fileList) do
  300.                             fs.copy("/" .. v, burnDriver.getMountPath() .. "/" .. v)
  301.                            
  302.                         end
  303.                         success("successfuly burned " .. #fileList-1 .. " files onto the disk", 4)
  304.                     end
  305.                     local _,err = pcall(wholeCopy)
  306.                
  307.                 elseif type(fileMenu) == "directory" then
  308.                     fs.makeDir(burnDriver.getMountPath() .. "/" .. fileMenu)
  309.                     for k,v in pairs(fs.list(fileMenu)) do
  310.                         fs.copy(fileMenu .. "/" .. v, burnDriver.getMountPath .. "/" .. fileMenu .. "/" .. v)
  311.                     end
  312.            
  313.                 else
  314.                     fs.copy(fileMenu, burnDriver.getMountPath() .. "/" .. fileMenu)
  315.                    
  316.                 end
  317.             elseif burnMenu == "Edit Burn" then
  318.                 local drivers = {}
  319.                 for k,v in pairs(rs.getSides()) do
  320.                     if peripheral.isPresent(v) and peripheral.getType(v) == "drive" then
  321.                         table.insert(drivers, v)
  322.                     end
  323.                 end
  324.                 if drivers[1] == nil then
  325.                     RSoD(" Oh no! There is no driver attached to the Computer!")
  326.                 end
  327.                 if disk.isPresent(drivers[1]) ~= true then
  328.                     RSoD("Oh no! There is no floppy in your driver!")
  329.                 end
  330.                 local burnDriver = peripheral.wrap(drivers[1])
  331.                 if fs.exists(burnDriver.getMountPath() .. "/.No_Files") then
  332.                     RSoD("You cant Burn a season closed disk")
  333.                 end
  334.                 if crashed then
  335.                     break
  336.                 end
  337.                 local fileList = fs.list("/")
  338.                 for k,v in pairs(fileList) do
  339.                     if v == ("rom" or burnDriver.getMountPath()) then
  340.                         table.remove(fileList, k)
  341.                     end
  342.                 end
  343.                 fileList[#fileList+1] = "Whole computer"
  344.                 local fileMenu = keyMenu(20, 2, colors.lightGray, colors.gray, colors.lime, fileList)
  345.                 if fileMenu == "Back" then
  346.  
  347.                 elseif fileMenu == "Whole computer" then
  348.                     local function wholeCopy()
  349.                         for k,v in pairs(fileList) do
  350.                             fs.copy("/" .. v, burnDriver.getMountPath() .. "/" .. v)
  351.                         end
  352.                     end
  353.                     local _,err = pcall(wholeCopy)
  354.                     success("successfuly burned " .. #fileList-1 .. " files onto the disk", 4)
  355.                
  356.                 elseif type(fileMenu) == "directory" then
  357.                     fs.makeDir(burnDriver.getMountPath() .. "/" .. fileMenu)
  358.                     for k,v in pairs(fs.list(fileMenu)) do
  359.                         fs.copy(fileMenu .. "/" .. v, burnDriver.getMountPath .. "/" .. fileMenu .. "/" .. v)
  360.                     end
  361.            
  362.                 else
  363.                     fs.copy(fileMenu, burnDriver.getMountPath() .. "/" .. fileMenu)
  364.                    
  365.                 end
  366.             end
  367.                 elseif mainMenu == "Clear" then
  368.                                    
  369.                 local clearMenu = printMenu(18, 8, colors.lime, {"Delete File", "Delete Disk", "Back"})
  370.                 if clearMenu == "Back" then
  371.  
  372.                 elseif clearMenu == "Delete Disk" then
  373.                 local drivers = {}
  374.                 for k,v in pairs(rs.getSides()) do
  375.                     if peripheral.isPresent(v) and peripheral.getType(v) == "drive" then
  376.                         table.insert(drivers, v)
  377.                     end
  378.                 end
  379.                 if drivers[1] == nil then
  380.                     RSoD(" Oh no! There is no driver attached to the Computer!")
  381.                 end
  382.                 if disk.isPresent(drivers[1]) ~= true then
  383.                     RSoD("Oh no! There is no floppy in your driver!")
  384.                 end
  385.                 local burnDriver = peripheral.wrap(drivers[1])
  386.                 if fs.exists(burnDriver.getMountPath() .. "/.No_Files") then
  387.                     RSoD("You cant delete a season closed disk")
  388.                 end
  389.                 if crashed then
  390.                     break
  391.                 end
  392.                 local fileList = fs.list(burnDriver.getMountPath() .."/")
  393.                 for k,v in pairs(fileList) do
  394.                     fs.delete(burnDriver.getMountPath() .. "/" .. v)
  395.                 end
  396.                 success("Successfuly cleared the floppy. Total Files:"..#fileList-1, 4)
  397.                 elseif clearMenu == "Delete File" then
  398.                     local drivers = {}
  399.                 for k,v in pairs(rs.getSides()) do
  400.                     if peripheral.isPresent(v) and peripheral.getType(v) == "drive" then
  401.                         table.insert(drivers, v)
  402.                     end
  403.                 end
  404.                 if drivers[1] == nil then
  405.                     RSoD(" Oh no! There is no driver attached to the Computer!")
  406.                 end
  407.                 if disk.isPresent(drivers[1]) ~= true then
  408.                     RSoD("Oh no! There is no floppy in your driver!")
  409.                 end
  410.                 local burnDriver = peripheral.wrap(drivers[1])
  411.                 if fs.exists(burnDriver.getMountPath() .. "/.No_Files") then
  412.                     RSoD("You cant delete a season closed disk")
  413.                 end
  414.                 if crashed then
  415.                     break
  416.                 end
  417.                 local fileList = fs.list(burnDriver.getMountPath() .."/")
  418.                 local deleteList = keyMenu(20,2,colors.lightGray, colors.gray,colors.lime,fileList)
  419.                 fs.delete(burnDriver.getMountPath() .. "/" .. deleteList)
  420.                 success("Successfuly deleted File: " .. deleteList,4)
  421.             end
  422.         end
  423.     end]]
  424. }
  425.  
  426. term.setCursorBlink(false)
  427. term.setBackgroundColor(colors.lightGray)
  428. term.setTextColor(colors.lime)
  429. term.clear()
  430. box(3, 51-4, 2, 19-2, colors.green)
  431. term.setCursorPos(35, 19)
  432. term.write("  Install  ")
  433. term.setCursorPos(7, 19)
  434. term.write("  Back  ")
  435. local function keypress()
  436. while true do
  437.     local sEvent, nButton, nX, nY = os.pullEvent()
  438.     if sEvent == "mouse_click" then
  439.         for i = 1, #buttons do
  440.             if nX >= buttons[i][1] and nX <= buttons[i][2] and nY == buttons[i][3] then
  441.                 return buttons[i][5]
  442.             end
  443.         end
  444.     end
  445. end
  446. end
  447. local clicked = keypress()
  448. term.setCursorPos(1, 1)
  449. if clicked == "INSTALL" then
  450.     local function install()
  451.         os.queueEvent("next_progress")
  452.         for i = 1, #folder do
  453.             fs.makeDir(folder[i])
  454.         end
  455.         sleep(.75)
  456.         os.queueEvent("next_progress")
  457.         for i = 1, #files do
  458.             local file = fs.open(files[i], "w")
  459.             file.writeLine(fileContent[files[i]])
  460.             file.close()
  461.         end
  462.         sleep(.75)
  463.         os.queueEvent("next_progress")
  464.         sleep(.75)
  465.         os.queueEvent("next_progress")
  466.         sleep(0.5)
  467.         term.setBackgroundColor(colors.black)
  468.         term.clear()
  469.         term.setTextColor(colors.white)
  470.         term.setCursorPos(1,1)
  471.     end
  472.     local function waitForEvent()
  473.         local count = 30
  474.         while count < 100 do
  475.             local sEvent = os.pullEvent()
  476.             if sEvent == "next_progress" then
  477.                 progress(15, 10, 25, colors.gray, colors.red, progresses[count], count)
  478.                 count = count + 30
  479.             end
  480.         end
  481.     end
  482.     parallel.waitForAll(install, waitForEvent)
  483.     shell.run("D-Burn")
  484.  
  485. elseif clicked  == "BACK" then
  486.     term.setBackgroundColor(colors.black)
  487.     term.setTextColor(colors.white)
  488.     term.clear()
  489.     term.setCursorPos(1,1)
  490. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement