Skip to content

Commit

Permalink
Auto update v1.3
Browse files Browse the repository at this point in the history
* tries to update all plugins on firecast start up
  • Loading branch information
ViniciusDinizLima committed May 23, 2024
1 parent 8444ee4 commit 3baddf8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
57 changes: 55 additions & 2 deletions Plugins/TablesDock/AutoUpdater/AutoUpdater/autoupdater.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -29,21 +30,55 @@ function dump(o)
end

local function write(str, chat)
if chat == nil then
-- showMessage(str)
return
end
if str then
chat:escrever(str);
else
chat:escrever("String nula");
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;
return trans;
end

local function downloadID(url, id, chat)
local install = true;
local install
Internet.download(url,
function(stream, contentType)
if stream ~= nil then
Expand Down Expand Up @@ -298,4 +333,22 @@ Firecast.Messaging.listen("ListChatCommands",
function(message)
message.response = {{comando="/autoupdater", descricao=tryTranslate("help.desc")},
{comando="/autoupdater <id|nome>", descricao=tryTranslate("help.download")}};
end);
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)
2 changes: 1 addition & 1 deletion Plugins/TablesDock/AutoUpdater/module.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<module sdkVersion="3.7">
<id>Ambesek.Auto.Updater</id>
<version>1.2</version>
<version>1.3</version>
<settings>
<automaticStringLocalization>true</automaticStringLocalization>
</settings>
Expand Down
Binary file modified Plugins/TablesDock/AutoUpdater/output/AutoUpdater.rpk
Binary file not shown.

0 comments on commit 3baddf8

Please sign in to comment.