2018-02-13 11:59:23 +08:00
|
|
|
---------------------------- Begin of From Downloader
|
|
|
|
|
2017-10-25 15:32:22 +08:00
|
|
|
local component=require("component")
|
|
|
|
|
2018-02-13 11:59:23 +08:00
|
|
|
local function doRealDownload(url)
|
2018-01-04 23:12:30 +08:00
|
|
|
local hwtable=component.list("internet")
|
2017-10-25 15:32:22 +08:00
|
|
|
local found=false
|
|
|
|
for k,v in pairs(hwtable) do
|
2018-01-04 23:12:30 +08:00
|
|
|
found=true
|
2017-10-25 15:32:22 +08:00
|
|
|
end
|
|
|
|
if(not found) then
|
|
|
|
error("The downloader requires an Internet card.")
|
|
|
|
end
|
|
|
|
|
|
|
|
local handle=component.internet.request(url)
|
2018-02-13 11:59:23 +08:00
|
|
|
|
2017-10-25 15:32:22 +08:00
|
|
|
local ans=""
|
|
|
|
while true do
|
|
|
|
local tmp=handle.read()
|
|
|
|
if(tmp==nil) then break end
|
|
|
|
ans=ans .. tmp
|
|
|
|
end
|
|
|
|
handle.close()
|
|
|
|
|
|
|
|
return ans
|
|
|
|
end
|
|
|
|
|
2018-02-13 11:59:23 +08:00
|
|
|
function DownloadFromGitHub(RepoName,Branch,FileAddress)
|
|
|
|
local url="https://raw.githubusercontent.com/" .. RepoName .. "/" .. Branch .. "/" .. FileAddress
|
|
|
|
return doRealDownload(url)
|
|
|
|
end
|
|
|
|
|
2017-10-25 15:32:22 +08:00
|
|
|
function DownloadFromOCS(FileAddress)
|
|
|
|
return DownloadFromGitHub("Kiritow/OpenComputerScripts","master",FileAddress)
|
|
|
|
end
|
|
|
|
|
|
|
|
function WriteStringToFile(StringValue,FileName,IsAppend)
|
|
|
|
if(IsAppend==nil) then IsAppend=false end
|
|
|
|
local handle,err
|
|
|
|
if(IsAppend) then
|
|
|
|
handle,err=io.open(FileName,"a")
|
|
|
|
else
|
|
|
|
handle,err=io.open(FileName,"w")
|
|
|
|
end
|
|
|
|
if(handle==nil) then return false,err end
|
|
|
|
|
|
|
|
handle:write(StringValue)
|
|
|
|
handle:close()
|
|
|
|
|
|
|
|
return true,"Success"
|
|
|
|
end
|
|
|
|
|
2018-02-13 11:59:23 +08:00
|
|
|
----------------------------- End of From Downloader
|
2017-10-23 21:27:48 +08:00
|
|
|
|
|
|
|
local code_lst=
|
|
|
|
{
|
|
|
|
"SignReader",
|
|
|
|
"checkarg",
|
|
|
|
"class",
|
2017-10-26 16:41:47 +08:00
|
|
|
-- "downloader",
|
2017-10-23 21:27:48 +08:00
|
|
|
"libevent",
|
|
|
|
"libnetwork",
|
|
|
|
-- "mcssh",
|
|
|
|
"queue",
|
|
|
|
"util",
|
|
|
|
"vector"
|
|
|
|
}
|
|
|
|
|
|
|
|
local cnt_all=0
|
|
|
|
for k,v in pairs(code_lst) do
|
|
|
|
cnt_all=cnt_all+1
|
|
|
|
end
|
|
|
|
|
|
|
|
local cnt_now=1
|
|
|
|
|
|
|
|
-- Download from the list
|
|
|
|
for k,v in pairs(code_lst) do
|
|
|
|
print("Updating (" .. cnt_now .. "/" .. cnt_all .. "): " .. v)
|
|
|
|
local x=DownloadFromOCS(v .. ".lua")
|
|
|
|
if(x~=nil) then WriteStringToFile(x,v .. ".lua") end
|
|
|
|
cnt_now = cnt_now + 1
|
|
|
|
end
|