Repository navigation
Expand file tree
/
Copy pathinstall.lua
More file actions
142 lines (112 loc) · 4.46 KB
/
Copy pathinstall.lua
File metadata and controls
142 lines (112 loc) · 4.46 KB
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
132
133
134
135
136
137
138
139
140
141
142
-- This plugin gets all plugins and runs the installation for each
function HandleInstallAllCMD(Player) -- run for each plugin
local Split = {}
ApiRequest(
{["PluginList"] = "true"},
"https://cuberite.krystilize.com",
function(Response)
-- parse into table
local Table = table.load(Response)
for Key, Value in pairs(Table) do -- log information on each
ApiRequest(
{["PluginInfo"] = Key},
"https://cuberite.krystilize.com",
function(Response)
HandleInstallPrepare(Key, Response, Player)
end
)
end
end
)
end
-- apt install <plugin>
function HandleInstallCMD(PluginName, Player) -- run for each plugin
-- ensure pluginname is set
if PluginName == nil then
SendWarning("You need to specify a plugin")
return
end
ApiRequest(
{["PluginInfo"] = PluginName},
"https://cuberite.krystilize.com",
function(Response)
HandleInstallPrepare(PluginName, Response, Player)
end
)
end
function HandleInstallPrepare(PluginName, Response, Player)
Info = table.load(Response)
local LocalInfo = {}
if Info == nil then
SendWarning("Plugin: " .. PluginName .. " not found.")
return
end
for Key, Value in pairs(Info) do
LocalInfo[Key] = Value
end
-- Save plugin info to Apt/Info
cFile:CreateFolderRecursive("Plugins/Apt/Info/" .. PluginName .. "/")
local file = io.open("Plugins/Apt/Info/" .. PluginName .. "/info.lua", "w+")
file:write(table.save(LocalInfo))
file:close()
local IsFirstDownload = true
-- Download file
DownloadToFile("Plugins/" .. LocalInfo.PluginDirectory .. ".zip", LocalInfo.DownloadDirectory,function(Success)
if Success and IsFirstDownload then
IsFirstDownload = false
local Query = string.find(LocalInfo.DownloadDirectory, "/zip/")
HandleInstall(PluginName, LocalInfo, Query, Player)
end
end)
-- os.execute([[curl "]] .. Table.DownloadDirectory .. [[" --output ]] .. "Plugins/" .. Table.PluginDirectory .. ".zip")
end
function HandleInstall(PluginName, Info, IsGithub, Player) -- Install plugin
local Table = Info
--TODO: support old win versions:
--[[
E.G.
path=whatever && powershell -command "Expand-Archive -Force '%path/my_zip_file.zip' '%path'"
]]
-- Check if plugin folder is occupied
if cFile:IsFolder("Plugins/" .. Table.PluginDirectory) then
SendWarning("Folder is occupied, is this plugin already installed?")
return
end
-- Extract
do
local InputFile = io.open("Plugins/" .. Table.PluginDirectory .. ".zip", "rb")
local LP = "Plugins/Apt/Libs/" -- Lib Path
if os.name() == "Linux" then
os.capture(LP .. "unzip" .. [[ "Plugins/]] .. Table.PluginDirectory .. [[.zip" -d "Plugins/]] .. Table.PluginDirectory .. [["]])
elseif os.name() == "Windows" then
local MakeDir = os.capture([[mkdir "Plugins/]] .. Table.PluginDirectory .. [["]])
local Extract = os.capture([[Plugins/Apt/ZipLib/pkunzip.exe Plugins/]] .. Table.PluginDirectory .. [[.zip]])
if #MakeDir > 1 or #Extract > 1 then
SendInfo(MakeDir)
SendInfo(Extract)
end
elseif os.name() == "MacOS" then
end
InputFile:close()
end
-- Fix file structure
local Dir = Table.PluginDirectory
for Key, Value in pairs(cFile:GetFolderContents("Plugins/" .. Dir)) do -- -master folder
if os.name() == "Windows" then
os.capture([[move "Plugins/]] .. Dir .. "/" .. Value .. [[/*" "Plugins/]] .. Dir .. "/")
else
os.capture([[mv -v -f "Plugins/]] .. Dir .. "/" .. Value .. [["/* "Plugins/]] .. Dir .. '/"')
os.capture([[rm -r -f "Plugins/]] .. Dir .. "/" .. Value .. [["]])
end
end
-- Update settings.ini
local IniFile = cIniFile()
if (IniFile:ReadFile("settings.ini")) then
IniFile:SetValue("Plugins", Table.PluginDirectory, 1, true)
IniFile:WriteFile("settings.ini")
end
-- Finalise and load plugin
cPluginManager:Get():RefreshPluginList()
cPluginManager:Get():LoadPlugin(Table.PluginDirectory)
SendInfo("Installed " .. Table.PluginDirectory .. "!")
end