forked from PathOfBuildingCommunity/PathOfBuilding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LaunchInstall.lua
55 lines (51 loc) · 1.33 KB
/
LaunchInstall.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#@ SimpleGraphic
-- Path of Building
--
-- Module: Launch Install
-- Installation bootstrap
--
local basicFiles = { "UpdateCheck.lua", "UpdateApply.lua", "Launch.lua" }
local xml = require("xml")
local curl = require("lcurl.safe")
ConClear()
ConPrintf("Preparing to complete installation...\n")
local localBranch, localSource
local localManXML = xml.LoadXMLFile("manifest.xml")
if localManXML and localManXML[1].elem == "PoBVersion" then
for _, node in ipairs(localManXML[1]) do
if type(node) == "table" then
if node.elem == "Version" then
localBranch = node.attrib.branch
elseif node.elem == "Source" then
if node.attrib.part == "program" then
localSource = node.attrib.url
end
end
end
end
end
if not localBranch or not localSource then
Exit("Install failed. (Missing or invalid manifest)")
return
end
localSource = localSource:gsub("{branch}", localBranch)
for _, name in ipairs(basicFiles) do
local text = ""
local easy = curl.easy()
easy:setopt_url(localSource..name)
easy:setopt_writefunction(function(data)
text = text..data
return true
end)
easy:perform()
local size = easy:getinfo(curl.INFO_SIZE_DOWNLOAD)
easy:close()
if size == 0 then
Exit("Install failed. (Couldn't download program files)")
return
end
local outFile = io.open(name, "wb")
outFile:write(text)
outFile:close()
end
Restart()