-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathWarlockScriptsInstaller.xml
131 lines (115 loc) · 4.5 KB
/
WarlockScriptsInstaller.xml
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MudletPackage>
<MudletPackage version="1.000">
<ScriptPackage>
<Script isActive="yes" isFolder="no">
<name>WarlockScriptsInstaller</name>
<packageName></packageName>
<script>local installer = {}
function lfs.isdir(dir)
local current = lfs.currentdir()
local exists = lfs.chdir(dir)
lfs.chdir(current)
return exists
end
local latest_release = "https://api.github.com/repos/WarlockMud/mudlet-scripts/releases/latest"
local download_base_url = "https://codeload.github.com/WarlockMud/mudlet-scripts/zip/"
local latest_file = getMudletHomeDir() .. "/latest.json"
local scriptsZip = getMudletHomeDir() .. "/warlock_scripts.zip"
local installerXML = getMudletHomeDir() .. "/WarlockScriptsInstaller.xml"
local unzipDirectory = ""
local scriptsDirectory = getMudletHomeDir() .. "/warlock_scripts/"
local unzippedDirectoryName = "mudlet-scripts-"
if lfs.isdir(scriptsDirectory .. ".git/") then
cecho("\n<CadetBlue>(skrypty)<tomato>: Katalog " .. scriptsDirectory .. " to repozytorium .git\n")
cecho("<CadetBlue>(skrypty)<tomato>: Chyba nie chcesz nadpisac repozytorium w ten sposob? :)\n")
return
end
function installScripts()
downloadFile(latest_file, latest_release)
registerAnonymousEventHandler("sysDownloadDone", "handleVersionDownload", true)
registerAnonymousEventHandler("sysDownloadError", "handleDownloadErrors", 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() .. "/warlock_scripts"
tempTimer(0.1, function() downloadScripts(response.tag_name) end)
end
end
function handleDownloadErrors(_, errorFound)
cecho("\n<CadetBlue>(skrypty)<tomato>: Blad podczas pobieranie skryptow: ".. errorFound ..")\n")
uninstallPackage(installer.name)
end
function downloadScripts(tag_name)
pcall(deleteDir, scriptsDirectory)
registerAnonymousEventHandler("sysDownloadDone", "handleDownload", true)
registerAnonymousEventHandler("sysDownloadError", "handleDownloadErrors", true)
unzippedDirectoryName = unzippedDirectoryName .. tag_name
downloadFile(scriptsZip, download_base_url .. tag_name)
cecho("\n<CadetBlue>(skrypty)<tomato>: Pobieram aktualna paczke skryptow (".. tag_name ..")\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
local args = {...}
local zipName = args[1]
local unzipLocation = args[2]
os.remove(scriptsZip)
os.remove(installerXML)
disableScript("WarlockScriptsInstaller")
uninstallPackage("warlock")
uninstallPackage("Warlock")
uninstallPackage("generic_mapper")
tempTimer(2, function()
os.rename(getMudletHomeDir() .. "/" .. unzippedDirectoryName, scriptsDirectory)
installPackage(scriptsDirectory .. "warlock_scripts.xml")
tempTimer(2, function()
if not saveProfile() then
tempTimer(5, function() saveProfile() end)
end
cecho("\n<CadetBlue>(skrypty)<tomato>: Skrypty zainstalowane\n")
end)
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
function WarlockScriptsInstaller(_, name)
installer.name = name
installScripts()
clearCmdLine()
end
</script>
<eventHandlerList>
<string>sysInstallPackage</string>
</eventHandlerList>
</Script>
</ScriptPackage>
</MudletPackage>