Advertisement
MeXaN1cK

launcher(PandaDoddo)

May 8th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.30 KB | None | 0 0
  1. local serialization = require("serialization")
  2. local filesystem = require("filesystem")
  3. local shell = require("shell")
  4. local args=shell.parse(...)
  5. local computer = require('computer')
  6. local internet = require("internet")
  7. local unicode = require('unicode')
  8.  
  9. local function saveTbl(tbl, fl) file = io.open(fl, 'w') file:write(serialization.serialize(tbl)) file:close() end
  10. local function loadTbl(fl) file = io.open(fl, 'r') if not file then file = io.open(fl, 'w') file:write('{}') return {} else return serialization.unserialize(file:read('*a')) end file:close() end
  11.  
  12. local function get(url,path)
  13.   local result, response = pcall(internet.request, url)
  14.   if result then
  15.     f = io.open(path,'w')
  16.     for chunk in response do
  17.       string.gsub(chunk, "\r\n", "\n")
  18.       f:write(chunk)
  19.     end
  20.     f:close()
  21.   end
  22.   return result
  23. end
  24.  
  25. local function downloadFile(paste,path)
  26.   if get(paste,path) == false then
  27.     for i=1,3 do
  28.       print(i)
  29.       if get(paste,path) then
  30.         break
  31.       end
  32.     end
  33.   end
  34. end
  35.  
  36. local function getFilesList(paste)
  37.   if filesystem.exists('/tmp/f') then
  38.     shell.execute('del /tmp/f')
  39.   end
  40.   print('Получаем манифест...')
  41.   downloadFile(paste,'/tmp/f')
  42.   return loadTbl('/tmp/f')
  43. end
  44.  
  45. function checkDir(path)
  46.   while true do
  47.     path = filesystem.path(path)
  48.   if lastPath == path then
  49.     break
  50.   end
  51.   if filesystem.isDirectory(path) == false then
  52.     filesystem.makeDirectory(path)
  53.   end
  54.     lastPath = path
  55.   end
  56. end
  57.  
  58. function download()
  59.   if args[1] ~= nil then
  60.     print('Начало установки... ')
  61.     local Files = getFilesList(tostring(args[1]))
  62.     print('Название: '..Files.name)
  63.     print('Описание: '..Files.description)
  64.     print('Версия '..Files.version)
  65.     local Manifest = Files.manifest
  66.     for i=1 , #Manifest do
  67.       checkDir(Manifest[i][2])
  68.     print(Manifest[i][2]..'...')
  69.       downloadFile(Manifest[i][1],Manifest[i][2])
  70.     end
  71.     print('Установка окончена! Перезагрузить компьютер? [Y/N]')
  72.     while true do
  73.       local str = tostring(io.read())
  74.       if unicode.upper(str) == 'Y'  then
  75.         computer.shutdown(true)
  76.       elseif unicode.upper(str) == 'N' then
  77.       break
  78.       end
  79.     end
  80.   end
  81. end
  82.  
  83. download()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement