Advertisement
Guest User

Computer Craft - From disk installer by Big SHiny Toys

a guest
Aug 18th, 2012
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.72 KB | None | 0 0
  1. local ver = 0.1
  2. local progName = "Random"
  3.  
  4. local bProblem = false
  5.  
  6. local function varifing()
  7.     local sParth = shell.getRunningProgram()
  8.         print("Parth:"..sParth)
  9.     if fs.getName(sParth) == "startup" then
  10.         local sDir = string.sub(sParth,1,#sParth-8)
  11.         print("Disk: "..sDir)
  12.         if fs.exists(sDir..[[\]].."install") and fs.isDir(sDir..[[\]].."install") and fs.exists(sDir..[[\]].."install"..[[\]].."LIST") and not fs.isDir(sDir..[[\]].."install"..[[\]].."LIST") then
  13.             print("Found Install folder")
  14.             file = io.open(sDir..[[\]].."install"..[[\]].."LIST","r")
  15.             local tInstruction = {}
  16.             local last = file:read()
  17.             repeat
  18.                 table.insert(tInstruction,last)
  19.                 last = file:read()
  20.                 print(last)
  21.             until last == nil
  22.             file:close()
  23.             -- check that files are avalible
  24.             local tNames = {}
  25.             local tParths = {}
  26.             print("Cheking LIST :")
  27.             local termX,termY = term.getCursorPos()
  28.             for i = 1,#tInstruction do
  29.                 term.setCursorPos(termX,termY)
  30.                 term.clearLine()
  31.                 write("Completed: "..tostring((100/#tInstruction)*i)..[[ %]])
  32.                
  33.                 if math.fmod(i,2) == 1 then -- odd number
  34.                     table.insert(tNames,tInstruction[i])
  35.                 else -- even number
  36.                     table.insert(tParths,tInstruction[i])
  37.                 end
  38.             end
  39.             local proceed = true
  40.             for i = 1,#tNames do
  41.                 if fs.exists(sDir..[[\]].."install"..[[\]]..tNames[i]) then
  42.                 else
  43.                     proceed = false
  44.                 end
  45.             end
  46.             if #tNames == #tParths then
  47.                
  48.             else
  49.                 proceed = false
  50.             end
  51.             if proceed then
  52.                 --local tFileList = fs.list(sDir..[[\]].."install")
  53.                 print("\nInstalling ...")
  54.                 termX,termY = term.getCursorPos()
  55.                 for i = 1,#tNames do
  56.                     term.setCursorPos(termX,termY)
  57.                     term.clearLine()
  58.                     write("Completed: "..tostring((100/#tNames)*i)..[[ %]])
  59.                     local temp = tParths[i] -- ..[[\]]..tNames[i]
  60.                     if fs.exists(temp) then -- fs.delete
  61.                         fs.delete(temp)
  62.                     end
  63.                     local temp2 = string.sub(temp,1,#temp - (string.len(fs.getName(temp))+1))
  64.                     if fs.isDir(temp2) then
  65.                        
  66.                     else
  67.                         fs.makeDir(temp2)
  68.                     end
  69.                     fs.copy(sDir..[[\]].."install"..[[\]]..tNames[i],tParths[i])
  70.                 end
  71.                 print("\nInstall Completed")
  72.             else
  73.                 print("[ERROR] installer varification failed")
  74.             end
  75.         end
  76.     end
  77. end
  78.  
  79. while true do
  80.     term.clear()
  81.     term.setCursorPos(1,1)
  82.     print("Welcom to Quick Install ver: "..ver)
  83.     print("[WARNING] Will override existing Files")
  84.     if bProblem then
  85.         print("Please select y Y n or N ")
  86.         bProblem = false
  87.     end
  88.     write("Do you want to install "..progName..[[ Y/N ]])
  89.     local selection = string.lower(read())
  90.     if selection == "y" then
  91.         print("varifing Install")
  92.         varifing()
  93.         break
  94.     elseif selection == "n" then
  95.         print("Install aborted")
  96.         break
  97.     else
  98.         bProblem = true
  99.     end
  100. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement