Advertisement
guitarplayer616

ConvertSchem

Nov 25th, 2016
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | None | 0 0
  1. --[[
  2. "but to copy the code i got CC-Copy, wish works fine for normal code, but not for schematics.
  3.  
  4. so i wrote a small program, to convert the schematic file into a table, searialize the table and safe the file local. Now i can copy the file with CC-Copy, on the Server i have the same converter running, to unsearilize the string, wish was given by CC-Copy and safe it as schematic file.
  5.  
  6. pretty easy thing, for "just" playing around with turtles and schematics ;) but in bigger projects i love it ;)
  7.  
  8.  
  9. Usage:
  10. goto your local minecraft world, copy the schematic file into your turtle folder, copy the "convert" script in the same folder
  11.  
  12. Run:
  13. convert toStringFile schematicFileName convertedFileName
  14.  
  15. than Copy the convertedFile and the convert scropt with CC-Copy to the Server you are on and run:
  16. convert toByteFile convertedFileName newSchematicFileName
  17.  
  18. as i said just usefull for ppl like me who are playing on a server without http and/or posibility to upload directly (like schematics)
  19.  
  20. fileName: convert" ]]--
  21.  
  22.  
  23. local tArgs = { ... }
  24.  
  25. function printUsage()
  26.   print("Usage: convert toByteFile <Input file name> <Output file>")
  27.   print("Usage: convert toStringFile <gunzipped schematic file | Input file name> <Output file>")
  28. end
  29.  
  30. function convertToStringFile(inputFileName, outputFileName)
  31.   if not fs.exists(inputFileName) then
  32.     print("InputFile: " .. inputFileName .. " does not exist.")
  33.     printUsage()
  34.     return
  35.   end
  36.   if fs.exists(outputFileName) then
  37.     print("OutputFile: " .. outputFileName .. " does exist, please delete it before or choose another filename.")
  38.     printUsage()
  39.     return
  40.   end
  41.  
  42.   local inFile = fs.open(inputFileName, "rb")
  43.  
  44.   local byteArray = {}
  45.   local byte = 0
  46.   while byte ~= nil do
  47.     byte = inFile.read()
  48.     table.insert(byteArray, byte)
  49.   end
  50.  
  51.   outFile = fs.open(outputFileName, "w")
  52.   outFile.write(textutils.serialize(byteArray))
  53.   outFile.close()
  54. end
  55.  
  56. function convertToByteFile(inputFileName, outputFileName)
  57.  
  58.   if not fs.exists(inputFileName) then
  59.     print("InputFile: " .. inputFileName .. " does not exist.")
  60.     printUsage()
  61.     return
  62.   end
  63.   if fs.exists(outputFileName) then
  64.     print("OutputFile: " .. outputFileName .. " does exist, please delete it before or choose another filename.")
  65.     printUsage()
  66.     return
  67.   end
  68.  
  69.   local inFile = fs.open(inputFileName, "r")
  70.   local charArray = {}
  71.   charArray = textutils.unserialize(inFile.readAll())
  72.   inFile.close()
  73.  
  74.  
  75.   local outFile = fs.open(outputFileName, "wb")
  76.  
  77.   for _, byte in ipairs(charArray) do
  78.     outFile.write(byte)
  79.   end
  80.   outFile.close()
  81. end
  82.  
  83. function main()
  84.  
  85.   if #tArgs ~= 3 then
  86.     printUsage()
  87.     return
  88.   end
  89.  
  90.   if tArgs[2] == tArgs[3] then
  91.     print("inputFileName and outputFileName are the same, please correct that")
  92.     printUsage()
  93.     return
  94.   end
  95.  
  96.   if tArgs[1] == "toByteFile" then
  97.     convertToByteFile(tArgs[2], tArgs[3])
  98.   elseif tArgs[1] == "toStringFile" then
  99.     convertToStringFile(tArgs[2], tArgs[3])
  100.   else
  101.     printUsage()
  102.   end
  103. end
  104.  
  105.  
  106. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement