Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local serialization = require("serialization")
- local filesystem = require("filesystem")
- local shell = require("shell")
- local args=shell.parse(...)
- local computer = require('computer')
- local internet = require("internet")
- local unicode = require('unicode')
- local function saveTbl(tbl, fl) file = io.open(fl, 'w') file:write(serialization.serialize(tbl)) file:close() end
- 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
- local function get(url,path)
- local result, response = pcall(internet.request, url)
- if result then
- f = io.open(path,'w')
- for chunk in response do
- string.gsub(chunk, "\r\n", "\n")
- f:write(chunk)
- end
- f:close()
- end
- return result
- end
- local function downloadFile(paste,path)
- if get(paste,path) == false then
- for i=1,3 do
- print(i)
- if get(paste,path) then
- break
- end
- end
- end
- end
- local function getFilesList(paste)
- if filesystem.exists('/tmp/f') then
- shell.execute('del /tmp/f')
- end
- print('Получаем манифест...')
- downloadFile(paste,'/tmp/f')
- return loadTbl('/tmp/f')
- end
- function checkDir(path)
- while true do
- path = filesystem.path(path)
- if lastPath == path then
- break
- end
- if filesystem.isDirectory(path) == false then
- filesystem.makeDirectory(path)
- end
- lastPath = path
- end
- end
- function download()
- if args[1] ~= nil then
- print('Начало установки... ')
- local Files = getFilesList(tostring(args[1]))
- print('Название: '..Files.name)
- print('Описание: '..Files.description)
- print('Версия '..Files.version)
- local Manifest = Files.manifest
- for i=1 , #Manifest do
- checkDir(Manifest[i][2])
- print(Manifest[i][2]..'...')
- downloadFile(Manifest[i][1],Manifest[i][2])
- end
- print('Установка окончена! Перезагрузить компьютер? [Y/N]')
- while true do
- local str = tostring(io.read())
- if unicode.upper(str) == 'Y' then
- computer.shutdown(true)
- elseif unicode.upper(str) == 'N' then
- break
- end
- end
- end
- end
- download()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement