Forte40

Craft - Auto crafting and inventory management (AE knockoff)

Aug 30th, 2013
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.56 KB | None | 0 0
  1. --http://pastebin.com/XCyjKvzP
  2.  
  3. local branch = "master"
  4. if fs.exists(".craft.branch") then
  5.   local f = fs.open(".craft.branch", "r")
  6.   branch = f.readAll()
  7.   f.close()
  8. end  
  9.  
  10. local files = {
  11.   {
  12.     name = "craft-get",
  13.     url = "https://raw.github.com/Forte40/craft/"..branch.."/craft-get.lua"
  14.   },
  15.   {
  16.     name = "craft",
  17.     url = "https://raw.github.com/Forte40/craft/"..branch.."/craft.lua"
  18.   },
  19.   {
  20.     name = "panel",
  21.     folder = "apis",
  22.     url = "https://raw.github.com/Forte40/panel/master/panel.lua"
  23.   },
  24. }
  25.  
  26. local scripts = {"Unleashed_1.1.3"}
  27.  
  28. local cmd = ...
  29. if cmd == "list" then
  30.   textutils.pagedPrint(table.concat(scripts, "\n"))
  31.   return
  32. elseif cmd then
  33.   local found = false
  34.   for _, name in ipairs(scripts) do
  35.     if cmd == name then
  36.       found = true
  37.       break
  38.     end
  39.   end
  40.   if found then
  41.     files = {
  42.       {
  43.         name = "item.dat",
  44.         url = "https://raw.github.com/Forte40/craft/"..branch.."/"..cmd.."/item.dat"
  45.       },
  46.       {
  47.         name = "dictionary.dat",
  48.         url = "https://raw.github.com/Forte40/craft/"..branch.."/"..cmd.."/dictionary.dat"
  49.       },
  50.       {
  51.         name = "recipe.dat",
  52.         url = "https://raw.github.com/Forte40/craft/"..branch.."/"..cmd.."/recipe.dat"
  53.       },
  54.     }
  55.   else
  56.     print("script '"..cmd.."' does not exists")
  57.     return
  58.   end
  59. end
  60.  
  61. if not http then
  62.   print("No access to web")
  63.   return
  64. end
  65.  
  66. for _, file in ipairs(files) do
  67.   local path
  68.   if file.folder then
  69.     if not fs.exists(file.folder) then
  70.       fs.makeDir(file.folder)
  71.     end
  72.     path = fs.combine(file.folder, file.name)
  73.   else
  74.     path = file.name
  75.   end
  76.   local currText = ""
  77.   if fs.exists(path) then
  78.     local f = fs.open(path, "r")
  79.     currText = f.readAll()
  80.     f.close()
  81.     io.write("update  ")
  82.   else
  83.     io.write("install ")
  84.   end
  85.   io.write("'"..file.name.."'"..string.rep(" ", math.max(0, 8 - #file.name)))
  86.   if file.folder then
  87.     io.write(" in '"..file.folder.."'"..string.rep(".", math.max(0, 8 - #file.folder)).."...")
  88.   else
  89.     io.write("    .............")
  90.   end
  91.   local request = http.get(file.url)
  92.   if request then
  93.     local response = request.getResponseCode()
  94.     if response == 200 then
  95.       local newText = request.readAll()
  96.       if newText == currText then
  97.         print("skip")
  98.       else
  99.         local f = fs.open(path, "w")
  100.         f.write(newText)
  101.         f.close()
  102.         print("done")
  103.       end
  104.     else
  105.       print(" bad HTTP response code " .. response)
  106.     end
  107.   else
  108.     print(" no request handle")
  109.   end
  110.   os.sleep(0.1)
  111. end
Advertisement
Add Comment
Please, Sign In to add comment