From 6a2ac44d43f3e5ff7f1491d43587b1f68187cccf Mon Sep 17 00:00:00 2001 From: AlyssonRPG Date: Tue, 9 Apr 2024 12:02:26 -0300 Subject: [PATCH] Fix AutoUpdater available plugins filter + improve load performance --- .../AutoUpdater/AutoUpdater/AutoUpdater.lfm | 171 ++++++++++-------- .../AutoUpdater/AutoUpdater/Available.lfm | 103 ++++++----- .../AutoUpdater/DownloadedPlugin.lfm | 12 +- .../AutoUpdater/InstalledPlugin.lfm | 2 +- .../AutoUpdater/autoupdaterPopup.lfm | 2 +- .../AutoUpdater/output/AutoUpdater.rpk | Bin 155155 -> 156141 bytes .../TablesDock/AutoUpdater/sdk/rrpgGUI.lua | 2 + Plugins/plugins.xml | 2 +- 8 files changed, 156 insertions(+), 138 deletions(-) diff --git a/Plugins/TablesDock/AutoUpdater/AutoUpdater/AutoUpdater.lfm b/Plugins/TablesDock/AutoUpdater/AutoUpdater/AutoUpdater.lfm index dd3b5b94..2ddb352b 100644 --- a/Plugins/TablesDock/AutoUpdater/AutoUpdater/AutoUpdater.lfm +++ b/Plugins/TablesDock/AutoUpdater/AutoUpdater/AutoUpdater.lfm @@ -74,7 +74,7 @@ if updaterSheet.toLoad <= updaterSheet.loaded then self.loader.visible = false; - self.downloadedPluginsList:sort(); + self.downloadedPluginsList:reorganize(); end; if myNode ~= nil then @@ -101,46 +101,57 @@ -- Limpa os recordList e carrega a lista de plugins instaladados local installed = Firecast.Plugins.getInstalledPlugins(); - local nodesDownloaded = NDB.getChildNodes(updaterSheet.downloadedPluginsList); - for i=1, #nodesDownloaded, 1 do - NDB.deleteNode(nodesDownloaded[i]); - end; - local nodesInstalled = NDB.getChildNodes(updaterSheet.installedPluginsList); - for i=1, #nodesInstalled, 1 do - NDB.deleteNode(nodesInstalled[i]); - end; - local macros = NDB.getChildNodes(updaterSheet.macroList); - for i=1, #macros, 1 do - NDB.deleteNode(macros[i]); - end; + + NDB.beginUpdate(updaterSheet); + + tryFinally( + function() + local nodesDownloaded = NDB.getChildNodes(updaterSheet.downloadedPluginsList); + for i=1, #nodesDownloaded, 1 do + NDB.deleteNode(nodesDownloaded[i]); + end; + local nodesInstalled = NDB.getChildNodes(updaterSheet.installedPluginsList); + for i=1, #nodesInstalled, 1 do + NDB.deleteNode(nodesInstalled[i]); + end; + local macros = NDB.getChildNodes(updaterSheet.macroList); + for i=1, #macros, 1 do + NDB.deleteNode(macros[i]); + end; + + -- Adiciona os plugins instalados a lista + for i=1, #installed, 1 do + local item = self.installedPluginsList:append(); + item.name = installed[i].name; + item.moduleId = installed[i].moduleId; + item.author = installed[i].author; + item.version = installed[i].version; + item.enabled = true; + item.description = installed[i].description; + item.contact = installed[i].contact; + end; + + -- Adiciona o nome das colunas as listas. + local item = self.installedPluginsList:append(); + item.name = tryTranslate("name") + item.moduleId = tryTranslate("id") + item.author = tryTranslate("author") + item.version = tryTranslate("installed") + item.versionAvailable = tryTranslate("available") + item.enabled = false; - -- Adiciona os plugins instalados a lista - for i=1, #installed, 1 do - local item = self.installedPluginsList:append(); - item.name = installed[i].name; - item.moduleId = installed[i].moduleId; - item.author = installed[i].author; - item.version = installed[i].version; - item.enabled = true; - item.description = installed[i].description; - item.contact = installed[i].contact; - end; - - -- Adiciona o nome das colunas as listas. - local item = self.installedPluginsList:append(); - item.name = tryTranslate("name") - item.moduleId = tryTranslate("id") - item.author = tryTranslate("author") - item.version = tryTranslate("installed") - item.versionAvailable = tryTranslate("available") - item.enabled = false; + local item = self.downloadedPluginsList:append(); + item.name = tryTranslate("name") + item.moduleId = tryTranslate("id") + item.author = tryTranslate("author") + item.version = tryTranslate("installed") + item.enabled = false; + end, + + function() + NDB.endUpdate(updaterSheet); + end); - local item = self.downloadedPluginsList:append(); - item.name = tryTranslate("name") - item.moduleId = tryTranslate("id") - item.author = tryTranslate("author") - item.version = tryTranslate("installed") - item.enabled = false; self.installedPluginsList:sort(); @@ -155,27 +166,31 @@ end; local file = VHD.openFile("plugins.xml", "w"); file:copyFrom(stream, stream.size); - setTimeout( - function () - file:close(); - local import = NDB.load("plugins.xml"); + + file:close(); + local import = NDB.load("plugins.xml"); - local list = NDB.getChildNodes(import); + local list = NDB.getChildNodes(import); - updaterSheet.loaded = 0; - updaterSheet.toLoad = #list; - updaterSheet.loading = tryTranslate("loading") .. "0/" .. updaterSheet.toLoad; + NDB.beginUpdate(updaterSheet); + + tryFinally( + function() + updaterSheet.loaded = 0; + updaterSheet.toLoad = #list; + updaterSheet.loading = tryTranslate("loading") .. "0/" .. updaterSheet.toLoad; - for i=1, #list, 1 do - -- Verifica se tem updates em cada plugin - verifyUpdate(list[i]); - end; - - self.downloadedPluginsList:sort(); + for i=1, #list, 1 do + -- Verifica se tem updates em cada plugin + verifyUpdate(list[i]); + end; + end, + + function() + NDB.endUpdate(updaterSheet); + end); - end, - 1000 - ); + self.downloadedPluginsList:reorganize(); end, function (errorMsg) -- esta função será chamada quando ocorrer algum erro no download. @@ -196,28 +211,32 @@ end; local file = VHD.openFile("macros.xml", "w"); file:copyFrom(stream, stream.size); - setTimeout( - function () - file:close(); - local import = NDB.load("macros.xml"); - - local list = NDB.getChildNodes(import); - - for i=1, #list, 1 do - -- Adiciona cada macro a lista de macros - local macro = self.macroList:append() - if macro then - macro.name = list[i].name - macro.path = (list[i].path):gsub("%%20", " ") - macro.link = list[i].link - end - end; + + file:close(); + local import = NDB.load("macros.xml"); - self.macroList:sort(); + local list = NDB.getChildNodes(import); + + NDB.beginUpdate(updaterSheet); + + tryFinally( + function() + for i=1, #list, 1 do + -- Adiciona cada macro a lista de macros + local macro = self.macroList:append() + if macro then + macro.name = list[i].name + macro.path = (list[i].path):gsub("%%20", " ") + macro.link = list[i].link + end + end; + end, + + function() + NDB.endUpdate(updaterSheet); + end); - end, - 1000 - ); + self.macroList:sort(); end, function (errorMsg) -- esta função será chamada quando ocorrer algum erro no download. diff --git a/Plugins/TablesDock/AutoUpdater/AutoUpdater/Available.lfm b/Plugins/TablesDock/AutoUpdater/AutoUpdater/Available.lfm index dee44c3b..3f1aefa3 100644 --- a/Plugins/TablesDock/AutoUpdater/AutoUpdater/Available.lfm +++ b/Plugins/TablesDock/AutoUpdater/AutoUpdater/Available.lfm @@ -1,62 +1,67 @@
- - - - --write(self.scope.node); - if self.scope.node == nil then return end; + - local nodes = NDB.getChildNodes(self.scope.node.downloadedPluginsList); - --local mesa = Firecast.getMesaDe(self); - --local login = mesa.meuJogador.login; - local filter = string.lower(Utils.removerAcentos(self.scope.node.filter)); - - -- Deixe todos visiveis - if filter == nil or filter == "" then - for i = 1, #nodes, 1 do - nodes[i].priority = 0; - --NDB.setPermission(nodes[i], "user", login, "read", "allow"); - end; - -- Deixe apenas os matchs visiveis - else - for i = 1, #nodes, 1 do - local name = string.lower(Utils.removerAcentos(nodes[i].name)); - local moduleId = string.lower(Utils.removerAcentos(nodes[i].moduleId)); - local author = string.lower(Utils.removerAcentos(nodes[i].author)); - - if string.find(name, filter) or string.find(moduleId, filter) or string.find(author, filter) then - nodes[i].priority = 1; - --NDB.setPermission(nodes[i], "user", login, "read", "allow"); - else - nodes[i].priority = -1; - --NDB.setPermission(nodes[i], "user", login, "read", "deny"); - --showMessage(NDB.getPermission(nodes[i], "user", login, "read")); - end; - end; - end; - - - - + + + + + - if nodeA.enabled and nodeB.enabled then - if (tonumber(nodeA.priority) or 0) > (tonumber(nodeB.priority) or 0) then + if left.enabled and right.enabled then + if (tonumber(left.priority) or 0) > (tonumber(right.priority) or 0) then return -1; - elseif (tonumber(nodeB.priority) or 0) > (tonumber(nodeA.priority) or 0) then + elseif (tonumber(right.priority) or 0) > (tonumber(left.priority) or 0) then return 1; else - return Utils.compareStringPtBr(nodeA.name, nodeB.name); + return Utils.compareStringPtBr(left.name, right.name); end; - elseif nodeA.enabled then + elseif left.enabled then return 1; - elseif nodeB.enabled then + elseif right.enabled then return -1; end; - - - - + + + + if (currentFilterArgument == nil) or (currentFilterArgument == "") then + return true; + end; + + local name = prepareStrForFilter(node.name) or ""; + local moduleId = prepareStrForFilter(node.moduleId) or ""; + local author = prepareStrForFilter(node.author) or ""; + + return (name ~= "" and string.find(name, currentFilterArgument, 1, true)) or + (moduleId ~= "" and string.find(moduleId, currentFilterArgument, 1, true)) or + (author ~= "" and string.find(author, currentFilterArgument, 1, true)); + + + + + +
\ No newline at end of file diff --git a/Plugins/TablesDock/AutoUpdater/AutoUpdater/DownloadedPlugin.lfm b/Plugins/TablesDock/AutoUpdater/AutoUpdater/DownloadedPlugin.lfm index 6efcc95f..e57166b6 100644 --- a/Plugins/TablesDock/AutoUpdater/AutoUpdater/DownloadedPlugin.lfm +++ b/Plugins/TablesDock/AutoUpdater/AutoUpdater/DownloadedPlugin.lfm @@ -1,5 +1,5 @@ -
+ +