aboutsummaryrefslogtreecommitdiff
path: root/launcher/icons/IconUtils.cpp
diff options
context:
space:
mode:
authorSefa Eyeoglu <contact@scrumplex.net>2023-08-10 20:38:32 +0200
committerSefa Eyeoglu <contact@scrumplex.net>2023-08-10 20:38:32 +0200
commitef6f9487f48ee6f114d47108977380fb4c278597 (patch)
tree57945b096640c87a976223daace6ecc27613d4c1 /launcher/icons/IconUtils.cpp
parent81bc9e488f653eba3e29d63b51c95f73f03ad182 (diff)
parent2090f958c8d1940238fe08f98eee2145edb12906 (diff)
downloadPrismLauncher-ef6f9487f48ee6f114d47108977380fb4c278597.tar.gz
PrismLauncher-ef6f9487f48ee6f114d47108977380fb4c278597.tar.bz2
PrismLauncher-ef6f9487f48ee6f114d47108977380fb4c278597.zip
Merge remote-tracking branch 'upstream/staging' into chore/add-compiler-warnings
Diffstat (limited to 'launcher/icons/IconUtils.cpp')
-rw-r--r--launcher/icons/IconUtils.cpp90
1 files changed, 50 insertions, 40 deletions
diff --git a/launcher/icons/IconUtils.cpp b/launcher/icons/IconUtils.cpp
index 4015b329..99c38f47 100644
--- a/launcher/icons/IconUtils.cpp
+++ b/launcher/icons/IconUtils.cpp
@@ -1,25 +1,51 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * This file incorporates work covered by the following copyright and
+ * permission notice:
+ *
+ * Copyright 2013-2021 MultiMC Contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#include "IconUtils.h"
-#include "FileSystem.h"
#include <QDirIterator>
-
-#include <array>
+#include "FileSystem.h"
namespace {
-std::array<const char *, 6> validIconExtensions = {{
- "svg",
- "png",
- "ico",
- "gif",
- "jpg",
- "jpeg"
-}};
+static const QStringList validIconExtensions = { { "svg", "png", "ico", "gif", "jpg", "jpeg" } };
}
-namespace IconUtils{
+namespace IconUtils {
-QString findBestIconIn(const QString &folder, const QString & iconKey) {
- size_t best_found = validIconExtensions.size();
+QString findBestIconIn(const QString& folder, const QString& iconKey)
+{
QString best_filename;
QDirIterator it(folder, QDir::NoDotAndDotDot | QDir::Files, QDirIterator::NoIteratorFlags);
@@ -27,36 +53,20 @@ QString findBestIconIn(const QString &folder, const QString & iconKey) {
it.next();
auto fileInfo = it.fileInfo();
- if(fileInfo.completeBaseName() != iconKey)
- continue;
-
- auto extension = fileInfo.suffix();
-
- for(size_t i = 0; i < best_found; i++) {
- if(extension == validIconExtensions[i]) {
- best_found = i;
- qDebug() << i << " : " << fileInfo.fileName();
- best_filename = fileInfo.fileName();
- }
- }
+ if (fileInfo.completeBaseName() == iconKey && isIconSuffix(fileInfo.suffix()))
+ return fileInfo.absoluteFilePath();
}
- return FS::PathCombine(folder, best_filename);
+ return {};
}
-QString getIconFilter() {
- QString out;
- QTextStream stream(&out);
- stream << '(';
- for(size_t i = 0; i < validIconExtensions.size() - 1; i++) {
- if(i > 0) {
- stream << " ";
- }
- stream << "*." << validIconExtensions[i];
- }
- stream << " *." << validIconExtensions[validIconExtensions.size() - 1];
- stream << ')';
- return out;
+QString getIconFilter()
+{
+ return "(*." + validIconExtensions.join(" *.") + ")";
}
+bool isIconSuffix(QString suffix)
+{
+ return validIconExtensions.contains(suffix);
}
+} // namespace IconUtils