From db0ed92823e15df98f7c376e5cf8d7ce754b2bb4 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Tue, 23 Oct 2018 21:48:24 +0200 Subject: [PATCH] Fixed a regression in 8fa44842. --- MUtilities_VS2017.vcxproj | 1 + MUtilities_VS2017.vcxproj.filters | 3 +++ src/Global.cpp | 4 ++++ src/Internal.h | 30 ++++++++++++++++++++++++++++++ src/OSSupport_Win32.cpp | 29 +++++++++++++++-------------- 5 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 src/Internal.h diff --git a/MUtilities_VS2017.vcxproj b/MUtilities_VS2017.vcxproj index b919019..b12d076 100644 --- a/MUtilities_VS2017.vcxproj +++ b/MUtilities_VS2017.vcxproj @@ -64,6 +64,7 @@ + diff --git a/MUtilities_VS2017.vcxproj.filters b/MUtilities_VS2017.vcxproj.filters index 685cfb1..f710dc2 100644 --- a/MUtilities_VS2017.vcxproj.filters +++ b/MUtilities_VS2017.vcxproj.filters @@ -182,6 +182,9 @@ Header Files + + Header Files + diff --git a/src/Global.cpp b/src/Global.cpp index 6c8c7ec..7b079f3 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -27,6 +27,7 @@ #include #include #include +#include "Internal.h" //Internal #include "DirLocker.h" @@ -53,6 +54,9 @@ #include #endif +//Global +const QString MUtils::Internal::g_empty; + /////////////////////////////////////////////////////////////////////////////// // Random Support /////////////////////////////////////////////////////////////////////////////// diff --git a/src/Internal.h b/src/Internal.h new file mode 100644 index 0000000..cd4e202 --- /dev/null +++ b/src/Internal.h @@ -0,0 +1,30 @@ +/////////////////////////////////////////////////////////////////////////////// +// MuldeR's Utilities for Qt +// Copyright (C) 2004-2018 LoRd_MuldeR +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// +// http://www.gnu.org/licenses/lgpl-2.1.txt +////////////////////////////////////////////////////////////////////////////////// + +#include + +namespace MUtils +{ + namespace Internal + { + extern const QString g_empty; + } +} diff --git a/src/OSSupport_Win32.cpp b/src/OSSupport_Win32.cpp index 6c43890..48fe8f1 100644 --- a/src/OSSupport_Win32.cpp +++ b/src/OSSupport_Win32.cpp @@ -40,6 +40,7 @@ #include #include #include +#include "Internal.h" #include "CriticalSection_Win32.h" #include "Utils_Win32.h" @@ -681,13 +682,12 @@ const bool &MUtils::OS::running_on_wine(void) // KNWON FOLDERS /////////////////////////////////////////////////////////////////////////////// -typedef QMap KFMap; +static QReadWriteLock g_known_folders_lock; +static QScopedPointer> g_known_folders_data; + typedef HRESULT (WINAPI *SHGetKnownFolderPath_t)(const GUID &rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath); typedef HRESULT (WINAPI *SHGetFolderPath_t) (HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath); -static QScopedPointer g_known_folders_map; -static QReadWriteLock g_known_folders_lock; - const QString &MUtils::OS::known_folder(known_folder_t folder_id) { typedef enum { KF_FLAG_CREATE = 0x00008000 } kf_flags_t; @@ -724,11 +724,11 @@ const QString &MUtils::OS::known_folder(known_folder_t folder_id) QReadLocker readLock(&g_known_folders_lock); //Already in cache? - if(!g_known_folders_map.isNull()) + if(!g_known_folders_data.isNull()) { - if(g_known_folders_map->contains(folderId)) + if(g_known_folders_data->contains(folderId)) { - return (*g_known_folders_map)[folderId]; + return (*g_known_folders_data)[folderId]; } } @@ -737,18 +737,18 @@ const QString &MUtils::OS::known_folder(known_folder_t folder_id) QWriteLocker writeLock(&g_known_folders_lock); //Still not in cache? - if(!g_known_folders_map.isNull()) + if(!g_known_folders_data.isNull()) { - if(g_known_folders_map->contains(folderId)) + if(g_known_folders_data->contains(folderId)) { - return (*g_known_folders_map)[folderId]; + return (*g_known_folders_data)[folderId]; } } //Initialize on first call - if(g_known_folders_map.isNull()) + if(g_known_folders_data.isNull()) { - g_known_folders_map.reset(new QMap()); + g_known_folders_data.reset(new QHash()); } QString folderPath; @@ -790,10 +790,11 @@ const QString &MUtils::OS::known_folder(known_folder_t folder_id) //Update cache if (!folderPath.isEmpty()) { - g_known_folders_map->insert(folderId, folderPath); + g_known_folders_data->insert(folderId, folderPath); + return (*g_known_folders_data)[folderId]; } - return folderPath; + return Internal::g_empty; } ///////////////////////////////////////////////////////////////////////////////