From 13a35764a80c550824157149bc433d474ef8f901 Mon Sep 17 00:00:00 2001 From: KokaKiwi Date: Sat, 11 Jun 2022 23:08:31 +0200 Subject: [PATCH 2/2] fix: Deduplicate resources directories It seems to actually happens despite xdgpp already doing that... --- lib/libimhex/include/hex/helpers/utils.hpp | 11 +++++++++++ lib/libimhex/source/helpers/fs.cpp | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/lib/libimhex/include/hex/helpers/utils.hpp b/lib/libimhex/include/hex/helpers/utils.hpp index 025b5f76..f6baaaa6 100644 --- a/lib/libimhex/include/hex/helpers/utils.hpp +++ b/lib/libimhex/include/hex/helpers/utils.hpp @@ -182,6 +182,17 @@ namespace hex { return result; } + template + void deduplicateVector(std::vector &items) { + auto end = items.end(); + + for (auto it = items.begin(); it != end; ++it) { + end = std::remove(it + 1, end, *it); + } + + items.erase(end, items.end()); + } + std::vector splitString(const std::string &string, const std::string &delimiter); std::string combineStrings(const std::vector &strings, const std::string &delimiter = ""); diff --git a/lib/libimhex/source/helpers/fs.cpp b/lib/libimhex/source/helpers/fs.cpp index 55dc08b2..8e52cfce 100644 --- a/lib/libimhex/source/helpers/fs.cpp +++ b/lib/libimhex/source/helpers/fs.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -159,6 +160,8 @@ namespace hex::fs { auto additionalDirs = ImHexApi::System::getAdditionalFolderPaths(); std::copy(additionalDirs.begin(), additionalDirs.end(), std::back_inserter(paths)); + hex::deduplicateVector(paths); + return paths; } @@ -175,6 +178,8 @@ namespace hex::fs { auto dataDirs = xdg::DataDirs(); std::copy(dataDirs.begin(), dataDirs.end(), std::back_inserter(paths)); + hex::deduplicateVector(paths); + return paths; #endif } -- 2.37.1