update libraries

This commit is contained in:
Kirigaya Kazuto 2018-02-13 11:59:23 +08:00
parent db306383c2
commit 1f15b7529a
3 changed files with 34 additions and 17 deletions

View File

@ -1,19 +1,17 @@
local component=require("component") local component=require("component")
function DownloadFromGitHub(RepoName,Branch,FileAddress) local function doRealDownload(url)
local hwtable=component.list() local hwtable=component.list("internet")
local found=false local found=false
for k,v in pairs(hwtable) do for k,v in pairs(hwtable) do
if(v=="internet") then found=true
found=true
end
end end
if(not found) then if(not found) then
error("The downloader requires an Internet card.") error("The downloader requires an Internet card.")
end end
local url="https://raw.githubusercontent.com/" .. RepoName .. "/" .. Branch .. "/" .. FileAddress
local handle=component.internet.request(url) local handle=component.internet.request(url)
local ans="" local ans=""
while true do while true do
local tmp=handle.read() local tmp=handle.read()
@ -25,6 +23,11 @@ function DownloadFromGitHub(RepoName,Branch,FileAddress)
return ans return ans
end end
function DownloadFromGitHub(RepoName,Branch,FileAddress)
local url="https://raw.githubusercontent.com/" .. RepoName .. "/" .. Branch .. "/" .. FileAddress
return doRealDownload(url)
end
function DownloadFromOCS(FileAddress) function DownloadFromOCS(FileAddress)
return DownloadFromGitHub("Kiritow/OpenComputerScripts","master",FileAddress) return DownloadFromGitHub("Kiritow/OpenComputerScripts","master",FileAddress)
end end
@ -43,5 +46,4 @@ function WriteStringToFile(StringValue,FileName,IsAppend)
handle:close() handle:close()
return true,"Success" return true,"Success"
end end

View File

@ -1,7 +1,8 @@
-- From Downloader ---------------------------- Begin of From Downloader
local component=require("component") local component=require("component")
function DownloadFromGitHub(RepoName,Branch,FileAddress) local function doRealDownload(url)
local hwtable=component.list("internet") local hwtable=component.list("internet")
local found=false local found=false
for k,v in pairs(hwtable) do for k,v in pairs(hwtable) do
@ -11,8 +12,8 @@ function DownloadFromGitHub(RepoName,Branch,FileAddress)
error("The downloader requires an Internet card.") error("The downloader requires an Internet card.")
end end
local url="https://raw.githubusercontent.com/" .. RepoName .. "/" .. Branch .. "/" .. FileAddress
local handle=component.internet.request(url) local handle=component.internet.request(url)
local ans="" local ans=""
while true do while true do
local tmp=handle.read() local tmp=handle.read()
@ -24,6 +25,11 @@ function DownloadFromGitHub(RepoName,Branch,FileAddress)
return ans return ans
end end
function DownloadFromGitHub(RepoName,Branch,FileAddress)
local url="https://raw.githubusercontent.com/" .. RepoName .. "/" .. Branch .. "/" .. FileAddress
return doRealDownload(url)
end
function DownloadFromOCS(FileAddress) function DownloadFromOCS(FileAddress)
return DownloadFromGitHub("Kiritow/OpenComputerScripts","master",FileAddress) return DownloadFromGitHub("Kiritow/OpenComputerScripts","master",FileAddress)
end end
@ -44,7 +50,7 @@ function WriteStringToFile(StringValue,FileName,IsAppend)
return true,"Success" return true,"Success"
end end
-- From Downloader ----------------------------- End of From Downloader
local code_lst= local code_lst=
{ {

View File

@ -1,4 +1,13 @@
local component=require("component") local component=require("component")
local serialization = require("serialization")
function serialize(value)
return serialization.serialize(value)
end
function unserialize(str)
return serialization.unserialize(str)
end
function getTableSize(t) function getTableSize(t)
local cnt=0 local cnt=0
@ -20,7 +29,7 @@ function proxy(componentType,beginWith)
local t=component.list(componentType) local t=component.list(componentType)
local sz=getTableSize(t) local sz=getTableSize(t)
if(sz==0) then if(sz==0) then
print("Query List is Empty") print("proxy: Query List is Empty")
return nil return nil
elseif(sz==1) then elseif(sz==1) then
for k in pairs(t) do for k in pairs(t) do
@ -28,11 +37,11 @@ function proxy(componentType,beginWith)
end end
else else
if(beginWith == nil) then if(beginWith == nil) then
print("beginWith value required.") print("proxy: beginWith value required.")
return nil return nil
end end
if(type(beginWith) ~= "string") then if(type(beginWith) ~= "string") then
print("beginWith is not string") print("proxy: beginWith is not string")
return nil return nil
end end
local bsz=string.len(beginWith) local bsz=string.len(beginWith)
@ -44,14 +53,14 @@ function proxy(componentType,beginWith)
traw=rawproxy(k) traw=rawproxy(k)
cnt=1 cnt=1
else else
print("Found more than 1 target.") print("proxy: Found more than 1 target.")
return nil return nil
end end
end end
end end
if(cnt==0) then if(cnt==0) then
print("Not found with beginWith value") print("proxy: Not found with beginWith value")
return nil return nil
else else
return traw return traw