From fac04952b6bd3eb78d43067fde0343596b89f7af Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Wed, 25 Oct 2017 15:32:22 +0800 Subject: [PATCH] Update Program no more depends on downloader --- update.lua | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/update.lua b/update.lua index 86a82e2..f6c8ec4 100644 --- a/update.lua +++ b/update.lua @@ -1,4 +1,52 @@ -require("downloader") +-- From Downloader +local component=require("component") + +function DownloadFromGitHub(RepoName,Branch,FileAddress) + local hwtable=component.list() + local found=false + for k,v in pairs(hwtable) do + if(v=="internet") then + found=true + end + end + if(not found) then + error("The downloader requires an Internet card.") + end + + local url="https://raw.githubusercontent.com/" .. RepoName .. "/" .. Branch .. "/" .. FileAddress + local handle=component.internet.request(url) + local ans="" + while true do + local tmp=handle.read() + if(tmp==nil) then break end + ans=ans .. tmp + end + handle.close() + + return ans +end + +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 + +-- From Downloader local code_lst= {