mirror of
https://github.com/Kiritow/OpenComputerScripts.git
synced 2024-03-22 13:10:46 +08:00
new downloader and updater
This commit is contained in:
parent
d250973ea6
commit
35acd7c4af
|
@ -1,17 +1,24 @@
|
||||||
local component=require("component")
|
local component=require("component")
|
||||||
|
|
||||||
local function doRealDownload(url)
|
local function doRealDownload(url)
|
||||||
local hwtable=component.list("internet")
|
if(component.internet==nil) then
|
||||||
local found=false
|
|
||||||
for k,v in pairs(hwtable) do
|
|
||||||
found=true
|
|
||||||
end
|
|
||||||
if(not found) then
|
|
||||||
error("The downloader requires an Internet card.")
|
error("The downloader requires an Internet card.")
|
||||||
end
|
end
|
||||||
|
|
||||||
local handle=component.internet.request(url)
|
local handle=component.internet.request(url)
|
||||||
|
|
||||||
|
while true do
|
||||||
|
local ret,err=handle.finishConnect()
|
||||||
|
if(ret==nil) then
|
||||||
|
return false,err
|
||||||
|
elseif(ret==true) then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
--os.sleep(0.1)
|
||||||
|
end
|
||||||
|
|
||||||
|
local response_code=handle.response()
|
||||||
|
|
||||||
local ans=""
|
local ans=""
|
||||||
while true do
|
while true do
|
||||||
local tmp=handle.read()
|
local tmp=handle.read()
|
||||||
|
@ -20,7 +27,7 @@ local function doRealDownload(url)
|
||||||
end
|
end
|
||||||
handle.close()
|
handle.close()
|
||||||
|
|
||||||
return ans
|
return true,ans,response_code
|
||||||
end
|
end
|
||||||
|
|
||||||
function DownloadFromGitHub(RepoName,Branch,FileAddress)
|
function DownloadFromGitHub(RepoName,Branch,FileAddress)
|
||||||
|
|
72
update.lua
72
update.lua
|
@ -3,17 +3,24 @@
|
||||||
local component=require("component")
|
local component=require("component")
|
||||||
|
|
||||||
local function doRealDownload(url)
|
local function doRealDownload(url)
|
||||||
local hwtable=component.list("internet")
|
if(component.internet==nil) then
|
||||||
local found=false
|
|
||||||
for k,v in pairs(hwtable) do
|
|
||||||
found=true
|
|
||||||
end
|
|
||||||
if(not found) then
|
|
||||||
error("The downloader requires an Internet card.")
|
error("The downloader requires an Internet card.")
|
||||||
end
|
end
|
||||||
|
|
||||||
local handle=component.internet.request(url)
|
local handle=component.internet.request(url)
|
||||||
|
|
||||||
|
while true do
|
||||||
|
local ret,err=handle.finishConnect()
|
||||||
|
if(ret==nil) then
|
||||||
|
return false,err
|
||||||
|
elseif(ret==true) then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
--os.sleep(0.1)
|
||||||
|
end
|
||||||
|
|
||||||
|
local response_code=handle.response()
|
||||||
|
|
||||||
local ans=""
|
local ans=""
|
||||||
while true do
|
while true do
|
||||||
local tmp=handle.read()
|
local tmp=handle.read()
|
||||||
|
@ -22,7 +29,7 @@ local function doRealDownload(url)
|
||||||
end
|
end
|
||||||
handle.close()
|
handle.close()
|
||||||
|
|
||||||
return ans
|
return true,ans,response_code
|
||||||
end
|
end
|
||||||
|
|
||||||
function DownloadFromGitHub(RepoName,Branch,FileAddress)
|
function DownloadFromGitHub(RepoName,Branch,FileAddress)
|
||||||
|
@ -51,32 +58,51 @@ function WriteStringToFile(StringValue,FileName,IsAppend)
|
||||||
end
|
end
|
||||||
|
|
||||||
----------------------------- End of From Downloader
|
----------------------------- End of From Downloader
|
||||||
|
local shell=require("shell")
|
||||||
|
local args=shell.parse(...)
|
||||||
|
local argc=#args
|
||||||
|
|
||||||
local code_lst=
|
local file_lst={}
|
||||||
|
|
||||||
|
if(argc<1) then
|
||||||
|
file_lst=
|
||||||
{
|
{
|
||||||
"SignReader",
|
"SignReader.lua",
|
||||||
"checkarg",
|
"checkarg.lua",
|
||||||
"class",
|
"class.lua",
|
||||||
-- "downloader",
|
"downloader.lua",
|
||||||
"libevent",
|
"libevent.lua",
|
||||||
"libnetwork",
|
"queue.lua",
|
||||||
-- "mcssh",
|
"util.lua",
|
||||||
"queue",
|
"vector.lua",
|
||||||
"util",
|
"LICENSE"
|
||||||
"vector"
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
for i=1,argc,1 do
|
||||||
|
table.insert(file_lst,args[i])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local cnt_all=0
|
local cnt_all=0
|
||||||
for k,v in pairs(code_lst) do
|
for k,v in pairs(file_lst) do
|
||||||
cnt_all=cnt_all+1
|
cnt_all=cnt_all+1
|
||||||
end
|
end
|
||||||
|
|
||||||
local cnt_now=1
|
local cnt_now=1
|
||||||
|
|
||||||
-- Download from the list
|
-- Download from the list
|
||||||
for k,v in pairs(code_lst) do
|
for k,v in pairs(file_lst) do
|
||||||
print("Updating (" .. cnt_now .. "/" .. cnt_all .. "): " .. v)
|
io.write("Updating (" .. cnt_now .. "/" .. cnt_all .. "): " .. v .. " ")
|
||||||
local x=DownloadFromOCS(v .. ".lua")
|
local flag,x,y=DownloadFromOCS(v)
|
||||||
if(x~=nil) then WriteStringToFile(x,v .. ".lua") end
|
if((not flag) or (y~=200) ) then
|
||||||
|
print("[Download Failed]")
|
||||||
|
else
|
||||||
|
local ret=WriteStringToFile(x,v)
|
||||||
|
if(not ret) then
|
||||||
|
print("[Write Failed]")
|
||||||
|
else
|
||||||
|
print("[OK]")
|
||||||
|
end
|
||||||
cnt_now = cnt_now + 1
|
cnt_now = cnt_now + 1
|
||||||
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user