Grab v2.5.1.1-alpha Registry used in package list updating

This commit is contained in:
Kirigaya Kazuto 2019-01-25 23:14:15 +08:00
parent 918fd406ad
commit 13f67e9773

View File

@ -9,7 +9,7 @@ local event=require('event')
local term=require('term') local term=require('term')
local args,options=shell.parse(...) local args,options=shell.parse(...)
local grab_version="Grab v2.5.1-alpha" local grab_version="Grab v2.5.1.1-alpha"
local grab_infos={ local grab_infos={
version=grab_version, version=grab_version,
grab_options=options grab_options=options
@ -502,6 +502,28 @@ local function CreateDB(tb,checked) -- If checked, merging is not allowed.
end end
end end
local function GetDBVersion()
local f=io.open(grab_dir .. "/list.version","rb")
if(not f) then
return ''
else
local s=f:read("*a")
f:close()
return s
end
end
local function SaveDBVersion(ver)
local f=io.open(grab_dir .. "/list.version","wb")
if(not f) then
return false
else
f:write(ver)
f:close()
return true
end
end
if(args[1]=="clear") then if(args[1]=="clear") then
print("Clearing programs info...") print("Clearing programs info...")
filesystem.remove(grab_dir .. "/programs.info") filesystem.remove(grab_dir .. "/programs.info")
@ -512,11 +534,25 @@ end
if(args[1]=="update") then if(args[1]=="update") then
if(not check_internet()) then return end if(not check_internet()) then return end
print("Updating programs info....") print("Checking package list version...")
io.write("Downloading... ") local ok,result=download("http://registry.kiritow.com/listver")
local ok,result=download(UrlGenerator("Kiritow/OpenComputerScripts","master","programs.info"))
if(not ok) then if(not ok) then
print("[Failed] " .. result) print("[Failed] " .. result)
return
end
if(GetDBVersion()==result) then
print("Already up to date.")
return
end
local remoteVer=result
print("Updating package list....")
io.write("Downloading... ")
ok,result=download("http://registry.kiritow.com/list/" .. remoteVer)
if(not ok) then
print("[Failed] " .. result)
return
else else
print("[OK]") print("[OK]")
io.write("Validating... ") io.write("Validating... ")
@ -528,15 +564,20 @@ if(args[1]=="update") then
local dbfilename=CreateDB(tb_data,false) local dbfilename=CreateDB(tb_data,false)
if(dbfilename) then if(dbfilename) then
print("[OK]") print("[OK]")
print("Programs info updated and saved to " .. dbfilename) print("Package list updated and saved to " .. dbfilename)
else else
print("[Failed] Unable to save programs info") print("[Failed] Unable to save package list.")
return
end end
else else
print("[Failed]" .. validate_err) print("[Failed]" .. validate_err)
return
end end
end end
print("Updating package list version...")
SaveDBVersion(remoteVer)
return return
end end