Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local term = require("term")
- local shell = require("shell")
- local fs = require("filesystem")
- local component = require("component")
- local gpu = component.gpu
- local args = {"update"}
- local guthubfolder = "https://raw.githubusercontent.com/DarthWirthe/Wirthe16_2D_RPG_Game_Wraith_Onslaught/"
- local ghdir = guthubfolder.."main/games/testgame/"
- local localpath = "/games/testgame/"
- local libdir = guthubfolder.."main/lib/"
- local libpath = "/lib/"
- local data, delete = {},{}
- gpu.setBackground(0x000000)
- gpu.setForeground(0xFFFFFF)
- term.clear()
- local t={}
- t.list = {
- "*Загрузчик файлов для игры Wraith Onslaught*",
- "Для загрузки файлов необходима интернет карта.",
- "Системные требования игры Wraith Onslaught:",
- "Монитор и видеокарта 3-го уровня,",
- "2Мб оперативной памяти,",
- "(Память уровня 3.5 - 2шт.)",
- "500Кб свободного места на ",
- "жёстком диске, мышь, клавиатура.",
- "Потребление энергии компьютером:",
- "400 - 1200 EU/сек.",
- }
- for f = 1, #t.list do
- term.setCursor(2,7+f)
- print(t.list[f])
- end
- function t.downloadFromGit(gitdir,file)
- return shell.execute("wget "..ghdir..gitdir.." "..file.." -fQ")
- end
- function t.getCurrentVersion()
- local st
- if fs.exists(localpath.."data/version.data") then
- st = loadfile(localpath.."data/version.data")()
- return st:sub(1,1):byte()
- end
- return 1
- end
- function t.setCurrentVersion(ver)
- local file = io.open(localpath.."data/version.data","w")
- file:write('return "'..string.char(ver)..'"')
- file:close()
- end
- function t.getNewestVersion()
- local file, data = "/temp-005b83cf"
- t.downloadFromGit("newest_version",file)
- data = loadfile(file)()
- fs.remove(file)
- return data
- end
- function t.getFileList(version)
- local file, data1, data2 = "/temp-005b83d0"
- t.downloadFromGit("upd"..version,file)
- data1, data2 = loadfile(file)()
- fs.remove(file)
- return data1, data2
- end
- function t.nlog(text)
- gpu.setForeground(0xFFFFFF)
- term.setCursor(2,2)
- io.write(text..string.rep(" ",50))
- end
- local new
- function t.getUpdateList()
- if component.isAvailable("internet") then
- t.nlog("Проверка обновлений.")
- local current, flist, dlist = t.getCurrentVersion()
- new = t.getNewestVersion()
- local function addToData(input)
- local n = true
- for f = 1, #data do
- if data[f] == input then
- n = false
- break
- end
- end
- for f = 1, #delete do
- if delete[f] == input then
- table.remove(delete,f)
- end
- end
- if n then
- table.insert(data,input)
- end
- end
- local function addToDelete(input)
- local n = true
- for f = 1, #delete do
- if delete[f] == input then
- n = false
- break
- end
- end
- for f = 1, #data do
- if data[f] == input then
- table.remove(data,f)
- end
- end
- if n then
- table.insert(delete,input)
- end
- end
- if new > current then
- t.nlog("Текущая версия: "..current.." Новая версия: "..new.." Получение списка файлов.")
- for f = current + 1, new do
- flist, dlist = t.getFileList(f)
- for e = 1, #flist do
- addToData(flist[e])
- end
- for e = 1, #dlist do
- addToDelete(dlist[e])
- end
- end
- end
- end
- end
- function t.pbar(l,n1,n2,x,y)
- term.setCursor(x,y)
- io.write(string.rep("─",l))
- term.setCursor(x,y+1)
- io.write(string.rep("█",math.floor(n1*l/n2)))
- term.setCursor(x,y+2)
- io.write(string.rep("─",l))
- end
- t.getUpdateList()
- for i = 1, #delete do
- if fs.exists(localpath..delete[i]) then
- fs.remove(localpath..delete[i])
- end
- end
- local att
- for i = 1, #data do
- att = 1
- term.setCursor(2,3)
- io.write(math.floor(i*100/#data).."% ")
- t.pbar(80,i,#data,2,4)
- t.nlog("Проверка "..data[i])
- t.d1,t.d2 = ghdir, localpath
- if data[i]:sub(1,2) == "G_" then t.d1,t.d2 = libdir, libpath end
- t.d3 = t.d2..data[i]
- if not fs.exists(t.d3) or fs.size(t.d3) == 0 or args[1] == "update" then
- if not component.isAvailable("internet") then term.clear(); error("Для запуска нужна интернет-карта!") end
- t.nlog("Скачивание "..data[i])
- fs.makeDirectory(fs.path(t.d3) or "")
- while att < 100 do
- t.e = shell.execute("wget "..t.d1..data[i].." "..t.d3.." -fQ")
- if fs.size(t.d3) == 0 or t.e == nil then
- fs.remove(t.d3)
- att = att + 1
- t.nlog("Ошибка запроса. Попытка "..att.."/30")
- os.sleep(1)
- else
- t.nlog("Успешно!")
- break
- end
- if att == 30 then att = nil; break end
- end
- end
- if not att then term.clear(); t.nlog("Нет соединения с github.com."); break end
- os.sleep()
- end
- if att or ( #data == 0 and #delete == 0 ) then
- t.setCurrentVersion(new)
- term.clear()
- t.nlog("Загрузка завершена. Директория исполняемого файла: /games/testgame/game.lua")
- os.sleep(2)
- data,delete,t,att=nil
- shell.execute("/games/testgame/game.lua")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement