From 85422427b9794a3bb6765e9947c03844862035e4 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Tue, 22 Oct 2024 09:41:00 +0300 Subject: [PATCH] Replaced QSet with QHash Signed-off-by: Trial97 (cherry picked from commit 73d33f93b30f658f9671358ac52bf4e03afeaefd) --- launcher/Application.cpp | 13 +++++++++---- launcher/Application.h | 3 +-- launcher/PSaveFile.h | 27 ++++++++++++++------------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 686d934c2..ea749ca4c 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -1887,20 +1887,25 @@ const QString Application::javaPath() void Application::addQSavePath(QString path) { QMutexLocker locker(&m_qsaveResourcesMutex); - m_qsaveResources.insert(path); + m_qsaveResources[path] = m_qsaveResources.value(path, 0) + 1; } void Application::removeQSavePath(QString path) { QMutexLocker locker(&m_qsaveResourcesMutex); - m_qsaveResources.remove(path); + auto count = m_qsaveResources.value(path, 0) - 1; + if (count <= 0) { + m_qsaveResources.remove(path); + } else { + m_qsaveResources[path] = count; + } } bool Application::checkQSavePath(QString path) { QMutexLocker locker(&m_qsaveResourcesMutex); - for (auto r : m_qsaveResources) { - if (path.contains(r)) { + for (auto partialPath : m_qsaveResources.keys()) { + if (path.startsWith(partialPath) && m_qsaveResources.value(partialPath, 0) > 0) { return true; } } diff --git a/launcher/Application.h b/launcher/Application.h index 363130cdd..692625f4a 100644 --- a/launcher/Application.h +++ b/launcher/Application.h @@ -43,7 +43,6 @@ #include #include #include -#include #include #include @@ -312,6 +311,6 @@ class Application : public QApplication { bool checkQSavePath(QString); private: - QSet m_qsaveResources; + QHash m_qsaveResources; mutable QMutex m_qsaveResourcesMutex; }; diff --git a/launcher/PSaveFile.h b/launcher/PSaveFile.h index e0b5a7a2c..ba6154ad8 100644 --- a/launcher/PSaveFile.h +++ b/launcher/PSaveFile.h @@ -17,6 +17,7 @@ */ #pragma once +#include #include #include "Application.h" @@ -46,24 +47,24 @@ */ class PSaveFile : public QSaveFile { public: - PSaveFile(const QString& name) : QSaveFile(name) - { - if (auto app = APPLICATION_DYN) { - app->addQSavePath(name + "."); - } - } - PSaveFile(const QString& name, QObject* parent) : QSaveFile(name, parent) - { - if (auto app = APPLICATION_DYN) { - app->addQSavePath(name + "."); - } - } + PSaveFile(const QString& name) : QSaveFile(name) { addPath(name); } + PSaveFile(const QString& name, QObject* parent) : QSaveFile(name, parent) { addPath(name); } virtual ~PSaveFile() { if (auto app = APPLICATION_DYN) { - app->removeQSavePath(fileName() + "."); + app->removeQSavePath(m_absoluteFilePath); } } + + private: + void addPath(const QString& path) + { + m_absoluteFilePath = QFileInfo(path).absoluteFilePath() + "."; // add dot for tmp files only + if (auto app = APPLICATION_DYN) { + app->addQSavePath(m_absoluteFilePath); + } + } + QString m_absoluteFilePath; }; #else #define PSaveFile QSaveFile