Advertisement
Piorjade

ComputerCraft MSI Maker

Jan 13th, 2016
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.98 KB | None | 0 0
  1. --MSI-Maker FIXED
  2. --Made by Piorjade
  3.  
  4. --Variablen
  5. mainFolder = "/Project/"
  6. destination = "/zip"
  7. show = false
  8.  
  9.  
  10. --Funktionen
  11. function compile(folder, ziel)
  12.     if folder == nil then
  13.         folder = mainFolder
  14.     else
  15.         mainFolder = folder
  16.     end
  17.     if ziel == nil then
  18.         ziel = destination
  19.     else
  20.         destination = ziel
  21.     end
  22.     directory = folder
  23.     files = {}
  24.     fileData = {}
  25.     folders = {}
  26.     currDir = ""
  27.     running = true
  28.     function search(directory)
  29.         if show == nil then show = false end
  30.         local fileList = fs.list(mainFolder..directory)
  31.         for _, file in ipairs(fileList) do
  32.             if show then print(file) end
  33.             isDir = fs.isDir(mainFolder..directory..file)
  34.             if isDir then
  35.                 if file == "rom" then
  36.                     if show then print("Skipping /rom"); sleep(2) end
  37.                 else
  38.                     term.setTextColor(colors.lime)
  39.                     if show then print("folder") end
  40.                     term.setTextColor(colors.white)
  41.                     table.insert(folders, directory..file)
  42.                 end
  43.             else
  44.                 term.setTextColor(colors.yellow)
  45.                 if show then print("file") end
  46.                 term.setTextColor(colors.white)
  47.                 table.insert(files, directory..file)
  48.                 local f = fs.open(mainFolder..directory..file,"r")
  49.                 local inhalt = f.readAll()
  50.                 f.close()
  51.                 table.insert(fileData, inhalt)
  52.             end
  53.  
  54.         end
  55.         for _, file in ipairs(fileList) do
  56.            
  57.         end
  58.     end
  59.     search("")
  60.     for _, fldr in ipairs(folders) do
  61.         term.setTextColor(colors.lightBlue)
  62.         if show then print(mainFolder..fldr) end
  63.         term.setTextColor(colors.white)
  64.         search(fldr.."/")
  65.     end
  66.  
  67.     local file = fs.open(ziel,"w")
  68.     file.write("--installable\n")
  69.     file.close()
  70.     local file = fs.open(ziel, "a")
  71.     file.write("files = "..textutils.serialize(files).."\n")
  72.     file.write("fileData = "..textutils.serialize(fileData).."\n")
  73.     file.write("folders = "..textutils.serialize(folders).."\n")
  74.     file.write("local args = {...}\n")
  75.     file.write("if #args < 1 then\n")
  76.     file.write("  print('Usage: <file> <destination>')\n")
  77.     file.write("else\n")
  78.     file.write("  args[1] = args[1]..'/'")
  79.     file.write("  for _, folder in ipairs(folders) do\n")
  80.     file.write("    fs.makeDir(args[1]..folder)\n")
  81.     file.write("  end\n")
  82.     file.write("  for _, file in ipairs(files) do\n")
  83.     file.write("    local file = fs.open(args[1]..file, 'w')\n")
  84.     file.write("    file.write(fileData[_])\n")
  85.     file.write("    file.close()\n")
  86.     file.write("  end\n")
  87.     file.write("end")
  88.     file.close()
  89. end
  90.  
  91. --Code
  92.  
  93. local args = {...}
  94.  
  95. if #args < 1 then
  96.     if fs.exists("/Project/") then
  97.         compile()
  98.     else
  99.         print("/Project/ not found!")
  100.         print("Usage: <thisfile> [folderWithProject] [destination]")
  101.     end
  102. elseif #args > 3 then
  103.     print("Too many arguments!")
  104.     print("Usage: <thisfile> [folderWithProject] [destination]")
  105. elseif #args == 1 then
  106.     if args[1] == "show" then
  107.         if fs.exists("/Project/") then
  108.             show = true
  109.             compile()
  110.         else
  111.             print("/Project/ not found!")
  112.             print("Usage: <thisfile> [folderWithProject] [destination]")
  113.         end
  114.     elseif fs.exists(args[1]) then
  115.         compile(args[1])
  116.     else
  117.         print(args[1].." not found!")
  118.         print("Usage: <thisfile> [folderWithProject] [destination]")
  119.     end
  120. elseif #args == 2 then
  121.     if args[2] == "show" then
  122.         if fs.exists(args[1]) then
  123.             show = true
  124.             compile(args[1])
  125.         else
  126.             print(args[1].." not found!")
  127.             print("Usage: <thisfile> [folderWithProject] [destination]")
  128.         end
  129.     elseif fs.exists(args[1]) then
  130.         if fs.exists(args[2]) then
  131.             print("Destinationfile already exists.")
  132.             print("Usage: <thisfile> [folderWithProject] [destination]")
  133.         else
  134.             compile(args[1], args[2])
  135.         end
  136.     else
  137.         print(args[1].." not found!")
  138.         print("Usage: <thisfile> [folderWithProject] [destination]")
  139.     end
  140. elseif #args == 3 then
  141.     if args[3] == "show" then show = true end
  142.     if fs.exists(args[1]) then
  143.         if fs.exists(args[2]) then
  144.             print("Destinationfile already exists.")
  145.             print("Usage: <thisfile> [folderWithProject] [destination]")
  146.         else
  147.             compile(args[1], args[2])
  148.         end
  149.     else
  150.         print(args[1].." not found!")
  151.         print("Usage: <thisfile> [folderWithProject] [destination]")
  152.     end
  153. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement