RadioNurshat

Untitled

Jun 11th, 2016
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. local function request(url)
  2. local success, response = pcall(component.internet.request, url)
  3. if success then
  4. local responseData = ""
  5. while true do
  6. local data, responseChunk = response.read()
  7. if data then
  8. responseData = responseData .. data
  9. else
  10. if responseChunk then
  11. return false, responseChunk
  12. else
  13. return responseData
  14. end
  15. end
  16. end
  17. else
  18. return false, reason
  19. end
  20. end
  21.  
  22. --БЕЗОПАСНАЯ ЗАГРУЗОЧКА
  23. local function getFromGitHubSafely(url, path)
  24. local success, reason = request(url)
  25. if success then
  26. fs.makeDirectory(fs.path(path) or "")
  27. fs.remove(path)
  28. local file = io.open(path, "w")
  29. file:write(success)
  30. file:close()
  31. return success
  32. else
  33. io.stderr:write("Can't download \"" .. url .. "\"!\n")
  34. return -1
  35. end
  36. end
  37.  
  38. local GitHubUserUrl = "https://raw.githubusercontent.com/"
  39.  
  40.  
  41. --------------------------------- Стадия стартовой загрузки всего необходимого ---------------------------------
  42.  
  43.  
  44. local preLoadApi = {
  45. { paste = "RadioNurshat/OMine/master/devka.pic", path = "MineOS/Desktop/"devka.pic },
  46. }
  47.  
  48. print("Downloading file list")
  49. applications = seri.unserialize(getFromGitHubSafely(GitHubUserUrl .. "IgorTimofeev/OpenComputers/master/Applications.txt", "MineOS/System/OS/Applications.txt"))
  50. print(" ")
  51.  
  52. for i = 1, #preLoadApi do
  53. print("Downloading \"" .. fs.name(preLoadApi[i].path) .. "\"")
  54. getFromGitHubSafely(GitHubUserUrl .. preLoadApi[i].paste, preLoadApi[i].path)
  55. end
Add Comment
Please, Sign In to add comment