diff --git a/Plugins/TablesDock/AutoUpdater/AutoUpdater/autoupdater.lua b/Plugins/TablesDock/AutoUpdater/AutoUpdater/autoupdater.lua index 0b202eda..499a4c7b 100644 --- a/Plugins/TablesDock/AutoUpdater/AutoUpdater/autoupdater.lua +++ b/Plugins/TablesDock/AutoUpdater/AutoUpdater/autoupdater.lua @@ -2,6 +2,7 @@ require("rrpg.lua"); require("vhd.lua"); require("utils.lua"); require("async.lua"); +require("plugins.lua"); local Internet = require("internet.lua"); local Locale = require("locale.lua"); local NDB = require("ndb.lua"); @@ -29,6 +30,10 @@ function dump(o) end local function write(str, chat) + if chat == nil then + -- showMessage(str) + return + end if str then chat:escrever(str); else @@ -36,6 +41,36 @@ local function write(str, chat) end; end; +local function isNewVersion(installed, downloaded) + local installedVersion = {}; + local installedIndex = 0; + for i in string.gmatch(installed, "[^%.]+") do + installedIndex = installedIndex +1; + installedVersion[installedIndex] = i; + end + + local downloadedVersion = {}; + local downloadedIndex = 0; + for i in string.gmatch(downloaded, "[^%.]+") do + downloadedIndex = downloadedIndex +1; + downloadedVersion[downloadedIndex] = i; + end + + for i=1, math.min(installedIndex, downloadedIndex), 1 do + if (tonumber(installedVersion[i]) or 0) > (tonumber(downloadedVersion[i]) or 0) then + return false; + elseif (tonumber(installedVersion[i]) or 0) < (tonumber(downloadedVersion[i]) or 0) then + return true; + end; + end; + + if downloadedIndex > installedIndex then + return true; + else + return false; + end; +end; + local function tryTranslate(text) local trans = Locale.tryLang(text); if trans == nil then trans = text end; @@ -43,7 +78,7 @@ local function tryTranslate(text) end local function downloadID(url, id, chat) - local install = true; + local install Internet.download(url, function(stream, contentType) if stream ~= nil then @@ -298,4 +333,22 @@ Firecast.Messaging.listen("ListChatCommands", function(message) message.response = {{comando="/autoupdater", descricao=tryTranslate("help.desc")}, {comando="/autoupdater ", descricao=tryTranslate("help.download")}}; - end); \ No newline at end of file + end); + +-- Automatically Update + +local installed = Firecast.Plugins.getInstalledPlugins() +local promise = Async.execute(loadPluginsXMLAsNode) +promise:thenDo( + function(node) + local available = NDB.getChildNodes(node) + + for i=1, #installed, 1 do + for j=1, #available, 1 do + if installed[i].moduleId == available[j].id and isNewVersion(installed[i].version, available[j].version) then + downloadID(available[j].url, available[j].id, nil) + break + end + end + end + end) \ No newline at end of file diff --git a/Plugins/TablesDock/AutoUpdater/module.xml b/Plugins/TablesDock/AutoUpdater/module.xml index 8c117c05..a8a89fca 100644 --- a/Plugins/TablesDock/AutoUpdater/module.xml +++ b/Plugins/TablesDock/AutoUpdater/module.xml @@ -1,7 +1,7 @@ Ambesek.Auto.Updater - 1.2 + 1.3 true diff --git a/Plugins/TablesDock/AutoUpdater/output/AutoUpdater.rpk b/Plugins/TablesDock/AutoUpdater/output/AutoUpdater.rpk index b5ad576a..b1a3743c 100644 Binary files a/Plugins/TablesDock/AutoUpdater/output/AutoUpdater.rpk and b/Plugins/TablesDock/AutoUpdater/output/AutoUpdater.rpk differ