-
Notifications
You must be signed in to change notification settings - Fork 19
/
installer.lua
75 lines (67 loc) · 2.57 KB
/
installer.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
local latest_release = "https://api.github.com/repos/tjurczyk/arkadia/releases/latest"
local latest_file = getMudletHomeDir() .. "/latest.json"
local url = "https://codeload.github.com/tjurczyk/arkadia/zip/"
local scriptsZip = getMudletHomeDir() .. "/scripts.zip"
local unzipDirectory = ""
local scriptsDirectory = getMudletHomeDir() .. "/arkadia/"
function installScripts()
downloadFile(latest_file, latest_release)
registerAnonymousEventHandler("sysDownloadDone", "handleVersionDownload", true)
end
function handleVersionDownload(_, filename, callback)
if filename ~= latest_file then
return true
end
local file = io.open(latest_file, "rb")
if file then
local response = yajl.to_value(file:read("*a"))
file:close()
os.remove(latest_file)
unzipDirectory = getMudletHomeDir() .. "/arkadia-".. response.name .."/"
tempTimer(0.1, function() downloadScripts(response.name) end)
end
end
function downloadScripts(version)
pcall(deleteDir, scriptsDirectory)
registerAnonymousEventHandler("sysDownloadDone", "handleDownload", true)
downloadFile(scriptsZip, url .. version)
cecho("\n<CadetBlue>(skrypty)<tomato>: Pobieram aktualna paczke skryptow (".. version ..")\n")
end
function handleDownload(_, filename)
if filename ~= scriptsZip then
return true
end
registerAnonymousEventHandler("sysUnzipDone", "handleUnzipEvents", true)
registerAnonymousEventHandler("sysUnzipError", "handleUnzipEvents", true)
unzipAsync(scriptsZip, getMudletHomeDir())
end
function handleUnzipEvents(event, ...)
if event == "sysUnzipDone" then
os.remove(scriptsZip)
uninstallPackage("Arkadia")
uninstallPackage("generic_mapper")
uninstallPackage("skrypty_master3")
tempTimer(1, function()
os.rename(unzipDirectory, scriptsDirectory)
installPackage(scriptsDirectory .. "Arkadia.xml")
cecho("\n<CadetBlue>(skrypty)<tomato>: Skrypty zainstalowane\n")
end)
elseif event == "sysUnzipError" then
cecho("\n<CadetBlue>(skrypty)<tomato>: Blad podczas rozpakowywania skryptow\n")
end
end
function deleteDir(dir)
for file in lfs.dir(dir) do
local file_path = dir .. '/' .. file
if file ~= "." and file ~= ".." then
if lfs.attributes(file_path, 'mode') == 'file' then
os.remove(file_path)
elseif lfs.attributes(file_path, 'mode') == 'directory' then
deleteDir(file_path)
end
end
end
lfs.rmdir(dir)
end
installScripts()
clearCmdLine()