diff --git a/sonorancad/core/http.js b/sonorancad/core/http.js index 674fe0c..7783a01 100644 --- a/sonorancad/core/http.js +++ b/sonorancad/core/http.js @@ -1,8 +1,11 @@ +const { format } = require("path"); + function byteCount(s) { return encodeURI(s).split(/%..|./).length - 1; } exports('HandleHttpRequest', (dest, callback, method, data, headers) => { + emit("SonoranCAD::core:writeLog", "debug", "[http] to: " + dest + " - data: " + dest, JSON.stringify(data)); const urlObj = url.parse(dest) const options = { hostname: urlObj.hostname, @@ -30,7 +33,7 @@ exports('HandleHttpRequest', (dest, callback, method, data, headers) => { }) req.on('error', (error) => { - console.error(error); + console.error("HTTP error caught: " + JSON.stringify(error)); }) if (method == "POST") { req.write(data); diff --git a/sonorancad/core/plugin_loader.lua b/sonorancad/core/plugin_loader.lua index c15a9b1..ab96151 100644 --- a/sonorancad/core/plugin_loader.lua +++ b/sonorancad/core/plugin_loader.lua @@ -41,6 +41,7 @@ local function downloadPlugin(name, url) local releaseUrl = ("%s/archive/latest.zip"):format(url) PerformHttpRequest(releaseUrl, function(code, data, headers) if code == 200 then + exports[GetCurrentResourceName()]:CreateFolderIfNotExisting(GetResourcePath(GetCurrentResourceName()).."/pluginupdates/") local savePath = GetResourcePath(GetCurrentResourceName()).."/pluginupdates/"..name..".zip" local f = assert(io.open(savePath, 'wb')) f:write(data) @@ -62,7 +63,7 @@ function CheckForPluginUpdate(name, checkUrl) if plugin == nil then errorLog(("Plugin %s not found."):format(name)) return - elseif plugin.check_url == nil then + elseif plugin.check_url == nil or plugin.check_url == "" then warnLog(("Plugin %s does not have check_url set. Please update it manually."):format(name)) return end @@ -79,7 +80,7 @@ function CheckForPluginUpdate(name, checkUrl) local localVersion = string.gsub(plugin.version, "%.", "") if localVersion < latestVersion then warnLog(("Plugin Updater: %s has an available update! %s -> %s"):format(name, plugin.version, remote.version)) - if remote.download_url ~= nil then + if remote.download_url ~= nil and remote.download_url ~= "" then if Config.allowAutoUpdate then infoLog(("Attempting to automatically update %s..."):format(name)) downloadPlugin(name, remote.download_url) @@ -87,6 +88,8 @@ function CheckForPluginUpdate(name, checkUrl) else warnLog("Automatic updates are disabled. Please update this plugin ASAP.") end + else + warnLog(("Plugin %s does not have download_url set. Please update it manually."):format(name)) end end if remote.configVersion ~= nil then diff --git a/sonorancad/core/unzipper/unzip.js b/sonorancad/core/unzipper/unzip.js index 28b6aa2..9cdf489 100644 --- a/sonorancad/core/unzipper/unzip.js +++ b/sonorancad/core/unzipper/unzip.js @@ -23,4 +23,10 @@ exports('UnzipFolder', (file, name, dest) => { entry.autodrain(); } }) +}); + +exports('CreateFolderIfNotExisting', (path) => { + if (!fs.existsSync(path)) { + fs.mkdirSync(path); + } }); \ No newline at end of file diff --git a/sonorancad/pluginupdates/.gitkeep b/sonorancad/pluginupdates/.gitkeep deleted file mode 100644 index e69de29..0000000