Advertisement
guitarplayer616

SchemMarket

Nov 25th, 2016
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.50 KB | None | 0 0
  1. --upload to Market
  2. local tArgs = {...}
  3.  
  4. -- Usage: market upload [file]
  5. -- market (list schematics)
  6. -- market [file] (download schematic)
  7.  
  8. function convertToStringFile(inputFileName, outputFileName)
  9.   if not fs.exists(inputFileName) then
  10.     print("InputFile: " .. inputFileName .. " does not exist.")
  11.     printUsage()
  12.     return
  13.   end
  14.   if fs.exists(outputFileName) then
  15.     print("OutputFile: " .. outputFileName .. " does exist, please delete it before or choose another filename.")
  16.     printUsage()
  17.     return
  18.   end
  19.  
  20.   local inFile = fs.open(inputFileName, "rb")
  21.  
  22.   local byteArray = {}
  23.   local byte = 0
  24.   while byte ~= nil do
  25.     byte = inFile.read()
  26.     table.insert(byteArray, byte)
  27.   end
  28.  
  29.   outFile = fs.open(outputFileName, "w")
  30.   outFile.write(textutils.serialize(byteArray))
  31.   outFile.close()
  32. end
  33.  
  34. function convertToByteFile(inputFileName, outputFileName)
  35.  
  36.   if not fs.exists(inputFileName) then
  37.     print("InputFile: " .. inputFileName .. " does not exist.")
  38.     printUsage()
  39.     return
  40.   end
  41.   if fs.exists(outputFileName) then
  42.     print("OutputFile: " .. outputFileName .. " does exist, please delete it before or choose another filename.")
  43.     printUsage()
  44.     return
  45.   end
  46.  
  47.   local inFile = fs.open(inputFileName, "r")
  48.   local charArray = {}
  49.   charArray = textutils.unserialize(inFile.readAll())
  50.   inFile.close()
  51.  
  52.  
  53.   local outFile = fs.open(outputFileName, "wb")
  54.  
  55.   for _, byte in ipairs(charArray) do
  56.     outFile.write(byte)
  57.   end
  58.   outFile.close()
  59. end
  60.  
  61. --[[if not fs.exists("convert") then
  62.     local h = fs.open("convert","w")
  63.     h.write(http.post("http://pastebin.com/raw/NUspW9KB").readAll())
  64.     h.close()
  65. end]]
  66.  
  67. local schematics = {
  68.  
  69.     tent = "UskC5qpE",
  70.     chicken = "VisRJwkw",
  71.     villageHouse = "0r2YMjaf",
  72.     mobSpawner = "Cg6jgTqn",
  73.     introHouse = "cWpAN2vw",
  74.     genericModern = "dPBCAp5W",
  75. }
  76.  
  77. local bugged_schematics = {
  78.     star = "7im48RBP",
  79.    
  80. }
  81.  
  82. if not tArgs[1] then
  83.     if term.isColor() then
  84.         term.setTextColor(colors.lime)
  85.     end
  86.     for i,v in pairs(schematics) do
  87.         print(" "..tostring(i))
  88.     end
  89.     term.setTextColor(colors.white)
  90. elseif tArgs[1] == "upload" then
  91.     if fs.exists("sSchematic") then
  92.         fs.delete("sSchematic")
  93.     end
  94.     if not fs.exists("packager") then
  95.         write("initializing...")
  96.         shell.run("pastebin get gqgTcNEV packager")
  97.         print(" finished")
  98.     end
  99.     fs.makeDir("bash_temp")
  100.     fs.copy(tArgs[2],"bash_temp/"..tostring(tArgs[2]))
  101.     shell.run("packager bash_temp package"..tostring(tArgs[2]).." "..tostring(tArgs[2]) )
  102.     shell.run("pastebin put package"..tostring(tArgs[2]))
  103.     fs.delete("package"..tostring(tArgs[2]))
  104.     fs.delete("bash_temp")
  105. else
  106.     for name,address in pairs(schematics) do
  107.         if tArgs[1] == name then
  108.            
  109.             if name == "tent" or name == "chicken" or name == "star" or name == "villageHouse" or name == "mobSpawner" then
  110.                 local schem = http.get("http://pastebin.com/raw/"..tostring(address)).readAll()
  111.                 local h = fs.open("temp","w")
  112.                 h.write(schem)
  113.                 h.close()
  114.                 convertToByteFile("temp", name)
  115.                 if fs.exists("temp") then
  116.                     fs.delete("temp")
  117.                 end
  118.             else
  119.  
  120.                 shell.run("pastebin get "..schematics[tArgs[1]].." package")   
  121.                 os.queueEvent("char","p")
  122.                 os.queueEvent("char","_")
  123.                 os.queueEvent("char","2")
  124.                 os.queueEvent("key",keys.enter)
  125.                 shell.run("package")
  126.                 for i,v in pairs(fs.list("p_2")) do
  127.                     print("extracting "..tostring(v))
  128.                     fs.move("p_2/"..tostring(v),shell.dir().."/"..tostring(v))
  129.                 end
  130.                 fs.delete("p_2")
  131.                 fs.delete("package")
  132.             end
  133.         end
  134.     end
  135. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement