forked from Openarl/PathOfBuilding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateApply.lua
46 lines (45 loc) · 1012 Bytes
/
UpdateApply.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
#@
-- Path of Building
--
-- Module: Update Apply
-- Applies updates.
--
local opFileName = ...
print("Applying update...")
local opFile = io.open(opFileName, "r")
if not opFile then
print("No operations list present.\n")
return
end
local lines = { }
for line in opFile:lines() do
table.insert(lines, line)
end
opFile:close()
os.remove(opFileName)
for _, line in ipairs(lines) do
local op, args = line:match("(%a+) ?(.*)")
if op == "move" then
local src, dst = args:match('"(.*)" "(.*)"')
print("Updating '"..dst.."'")
local srcFile = io.open(src, "rb")
assert(srcFile, "couldn't open "..src)
local dstFile
while not dstFile do
dstFile = io.open(dst, "w+b")
end
if dstFile then
dstFile:write(srcFile:read("*a"))
dstFile:close()
end
srcFile:close()
os.remove(src)
elseif op == "delete" then
local file = args:match('"(.*)"')
print("Deleting '"..file.."'")
os.remove(file)
elseif op == "start" then
local target = args:match('"(.*)"')
SpawnProcess(target)
end
end