function edit()
local configs = g_resources.listDirectoryFiles("/bot", false, false)
editWindow.manager.upload.config:clearOptions()
for i=1,#configs do
if configs[i] == "SW_BOT" then
editWindow.manager.upload.config:addOption(configs[i])
end
end
editWindow.manager.download.config:setText("")
editWindow:show()
editWindow:focus()
editWindow:raise()
end
function createDefaultConfigs()
local defaultConfigFiles = g_resources.listDirectoryFiles("default_configs", false, false)
for i, config_name in ipairs(defaultConfigFiles) do
if config_name == "SW_BOT" then
g_resources.makeDir("/bot/" .. config_name)
if not g_resources.directoryExists("/bot/" .. config_name) then
return onError("Can't create /bot/" .. config_name .. " directory in " .. g_resources.getWriteDir())
end
local defaultConfigFiles = g_resources.listDirectoryFiles("default_configs/" .. config_name, true, false)
for i, file in ipairs(defaultConfigFiles) do
local baseName = file:split("/")
baseName = baseName[#baseName]
if g_resources.directoryExists(file) then
g_resources.makeDir("/bot/" .. config_name .. "/" .. baseName)
if not g_resources.directoryExists("/bot/" .. config_name .. "/" .. baseName) then
return onError("Can't create /bot/" .. config_name .. "/" .. baseName .. " directory in " .. g_resources.getWriteDir())
end
local defaultConfigFiles2 = g_resources.listDirectoryFiles("default_configs/" .. config_name .. "/" .. baseName, true, false)
for i, file in ipairs(defaultConfigFiles2) do
local baseName2 = file:split("/")
baseName2 = baseName2[#baseName2]
local contents = g_resources.fileExists(file) and g_resources.readFileContents(file) or ""
if contents:len() > 0 then
g_resources.writeFileContents("/bot/" .. config_name .. "/" .. baseName .. "/" .. baseName2, contents)
end
end
else
local contents = g_resources.fileExists(file) and g_resources.readFileContents(file) or ""
if contents:len() > 0 then
g_resources.writeFileContents("/bot/" .. config_name .. "/" .. baseName, contents)
end
end
end
end
end
end
function uploadConfig()
-- local config = editWindow.manager.upload.config:getCurrentOption().text
-- local archive = compressConfig(config)
-- if not archive then
-- return displayErrorBox(tr("Config upload failed"), tr("Config %s is invalid (can't be compressed)", config))
-- end
-- if archive:len() > 1024 * 1024 then
-- return displayErrorBox(tr("Config upload failed"), tr("Config %s is too big, maximum size is 1024KB. Now it has %s KB.", config, math.floor(archive:len() / 1024)))
-- end
-- local infoBox = displayInfoBox(tr("Uploading config"), tr("Uploading config %s. Please wait.", config))
-- HTTP.postJSON(configManagerUrl .. "?config=" .. config:gsub("%s+", "_"), archive, function(data, err)
-- if infoBox then
-- infoBox:destroy()
-- end
-- if err or data["error"] then
-- return displayErrorBox(tr("Config upload failed"), tr("Error while upload config %s:\n%s", config, err or data["error"]))
-- end
-- displayInfoBox(tr("Succesful config upload"), tr("Config %s has been uploaded.\n%s", config, data["message"]))
-- end)
end
function downloadConfig()
-- local hash = editWindow.manager.download.config:getText()
-- if hash:len() == 0 then
-- return displayErrorBox(tr("Config download error"), tr("Enter correct config hash"))
-- end
-- local infoBox = displayInfoBox(tr("Downloading config"), tr("Downloading config with hash %s. Please wait.", hash))
-- HTTP.download(configManagerUrl .. "?hash=" .. hash, hash .. ".zip", function(path, checksum, err)
-- if infoBox then
-- infoBox:destroy()
-- end
-- if err then
-- return displayErrorBox(tr("Config download error"), tr("Config with hash %s cannot be downloaded", hash))
-- end
-- modules.client_textedit.show("", {
-- title="Enter name for downloaded config",
-- description="Config with hash " .. hash .. " has been downloaded. Enter name for new config.\nWarning: if config with same name already exist, it will be overwritten!",
-- width=500
-- }, function(configName)
-- decompressConfig(configName, "/downloads/" .. path)
-- refresh()
-- edit()
-- end)
-- end)
end