From 3046d147bae0580b07b3cb6305eea5011ba23195 Mon Sep 17 00:00:00 2001 From: TD-er Date: Thu, 22 Jun 2023 23:12:16 +0200 Subject: [PATCH] [Devices] Fix showing all included plugins in devices pull-down list --- src/src/Globals/Plugins.cpp | 2 +- src/src/Globals/Plugins.h | 3 ++- src/src/Helpers/_Plugin_init.cpp | 34 +++++++++----------------------- 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/src/src/Globals/Plugins.cpp b/src/src/Globals/Plugins.cpp index 73570c1904..bc872c14cb 100644 --- a/src/src/Globals/Plugins.cpp +++ b/src/src/Globals/Plugins.cpp @@ -38,7 +38,7 @@ int deviceCount = -1; -deviceIndex_t* DeviceIndex_sorted = nullptr; +std::vector DeviceIndex_sorted; bool validDeviceIndex(deviceIndex_t index) { diff --git a/src/src/Globals/Plugins.h b/src/src/Globals/Plugins.h index 00f1add71f..996dba6ede 100644 --- a/src/src/Globals/Plugins.h +++ b/src/src/Globals/Plugins.h @@ -9,6 +9,7 @@ #include "../DataTypes/DeviceIndex.h" #include "../DataTypes/TaskIndex.h" +#include /********************************************************************************************\ Structures to address the plugins and device configurations. @@ -44,7 +45,7 @@ extern int deviceCount; // Array containing "DeviceIndex" alfabetically sorted. -extern deviceIndex_t* DeviceIndex_sorted; +extern std::vector DeviceIndex_sorted; bool validDeviceIndex(deviceIndex_t index); diff --git a/src/src/Helpers/_Plugin_init.cpp b/src/src/Helpers/_Plugin_init.cpp index 4e48839fbe..8d369a2031 100644 --- a/src/src/Helpers/_Plugin_init.cpp +++ b/src/src/Helpers/_Plugin_init.cpp @@ -2159,36 +2159,20 @@ void PluginSetup() // ******************************************************************************** // First fill the existing number of the DeviceIndex. - if (DeviceIndex_sorted) { - delete[] DeviceIndex_sorted; - DeviceIndex_sorted = nullptr; - } - DeviceIndex_sorted = new deviceIndex_t[deviceCount + 1]; - + DeviceIndex_sorted.resize(deviceCount + 1); for (deviceIndex_t x = 0; x <= deviceCount; x++) { - DeviceIndex_sorted[x] = getPluginID_from_DeviceIndex(x); + DeviceIndex_sorted[x] = x; } - // Do the sorting. - int innerLoop; - int mainLoop; - - for (mainLoop = 1; mainLoop <= deviceCount; mainLoop++) + struct { - innerLoop = mainLoop; - - while (innerLoop >= 1) - { - const String cur(getPluginNameFromDeviceIndex(DeviceIndex_sorted[innerLoop])); - const String prev(getPluginNameFromDeviceIndex(DeviceIndex_sorted[innerLoop - 1])); - if (cur < prev) { - deviceIndex_t temp = DeviceIndex_sorted[innerLoop - 1]; - DeviceIndex_sorted[innerLoop - 1] = DeviceIndex_sorted[innerLoop]; - DeviceIndex_sorted[innerLoop] = temp; - } - innerLoop--; + bool operator()(deviceIndex_t a, deviceIndex_t b) const { + return getPluginNameFromDeviceIndex(a) < + getPluginNameFromDeviceIndex(b); } - } + } + customLess; + std::sort(DeviceIndex_sorted.begin(), DeviceIndex_sorted.end(), customLess); } void PluginInit(bool priorityOnly)