From ad2cd89128fba46562dc2c7d1776e9aefff24c5b Mon Sep 17 00:00:00 2001 From: k1-801 Date: Sat, 24 Apr 2021 21:40:24 +0400 Subject: [PATCH] Add filesystem header to select between std::filesystem and std::experimental::filesystem depending on system availability. Commit amended by Adam Honse --- LogManager.cpp | 8 +++----- OpenRGB.pro | 12 ++++++------ ProfileManager.cpp | 8 +++----- ResourceManager.cpp | 5 ++--- filesystem.h | 17 +++++++++++++++++ scripts/AppImage.patch | 4 ++-- 6 files changed, 33 insertions(+), 21 deletions(-) create mode 100644 filesystem.h diff --git a/LogManager.cpp b/LogManager.cpp index f6212841..5de38a63 100644 --- a/LogManager.cpp +++ b/LogManager.cpp @@ -4,9 +4,7 @@ #include #include "ResourceManager.h" -#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING -#include -namespace fs = std::experimental::filesystem; +#include "filesystem.h" static const char* log_codes[] = {"CRITICAL", "ERROR", "Message", "Warning", "Notice", "[verbose]", "Debug"}; @@ -77,13 +75,13 @@ void LogManager::configure(json config, const std::string &defaultDir) /*-------------------------------------------------*\ | If the path is relative, use logs dir | \*-------------------------------------------------*/ - fs::path p = logname; + filesystem::path p = logname; if(p.is_relative()) { p = defaultDir + "logs/"; p.append(logname); } - fs::create_directories(p.parent_path()); + filesystem::create_directories(p.parent_path()); /*-------------------------------------------------*\ | Open the logfile | diff --git a/OpenRGB.pro b/OpenRGB.pro index b87f7ef7..4ac7d491 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -11,6 +11,11 @@ QT += core \ gui \ +#-----------------------------------------------------------------------------------------------# +# Set compiler to use C++17 to make std::filesystem available # +#-----------------------------------------------------------------------------------------------# +CONFIG += c++17 + greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 5): DEFINES += _QT6 @@ -134,6 +139,7 @@ HEADERS += SettingsManager.h \ Detector.h \ DeviceDetector.h \ + filesystem.h \ qt/DetectorTableModel.h \ qt/OpenRGBClientInfoPage.h \ qt/OpenRGBDeviceInfoPage.h \ @@ -788,9 +794,6 @@ win32:contains(QMAKE_TARGET.arch, x86) { unix:!macx { TARGET = $$lower($$TARGET) - CONFIG += \ - c++14 \ - INCLUDEPATH += \ Controllers/FaustusController \ Controllers/LinuxLEDController \ @@ -884,9 +887,6 @@ macx { LIBS += \ -lusb-1.0 \ -lhidapi \ - - CONFIG += \ - c++14 \ } #-------------------------------------------------------------------------------------------# diff --git a/ProfileManager.cpp b/ProfileManager.cpp index 406cbb39..c881b954 100644 --- a/ProfileManager.cpp +++ b/ProfileManager.cpp @@ -2,17 +2,15 @@ #include "ResourceManager.h" #include "RGBController_Dummy.h" #include "LogManager.h" -#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING -#include +#include "filesystem.h" #include #include #include + #define OPENRGB_PROFILE_HEADER "OPENRGB_PROFILE" #define OPENRGB_PROFILE_VERSION OPENRGB_SDK_PROTOCOL_VERSION -namespace fs = std::experimental::filesystem; - ProfileManager::ProfileManager(std::string config_dir) { configuration_directory = config_dir; @@ -389,7 +387,7 @@ void ProfileManager::UpdateProfileList() /*---------------------------------------------------------*\ | Load profiles by looking for .orp files in current dir | \*---------------------------------------------------------*/ - for(const auto & entry : fs::directory_iterator(configuration_directory)) + for(const auto & entry : filesystem::directory_iterator(configuration_directory)) { std::string filename = entry.path().filename().string(); diff --git a/ResourceManager.cpp b/ResourceManager.cpp index 36d91643..210d7c6d 100644 --- a/ResourceManager.cpp +++ b/ResourceManager.cpp @@ -12,9 +12,8 @@ #include "ResourceManager.h" #include "ProfileManager.h" #include "LogManager.h" +#include "filesystem.h" -#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING -#include #include #include #include @@ -307,7 +306,7 @@ std::string ResourceManager::GetConfigurationDirectory() /*-------------------------------------------------------------------------*\ | Create OpenRGB configuration directory if it doesn't exist | \*-------------------------------------------------------------------------*/ - std::experimental::filesystem::create_directories(config_dir); + filesystem::create_directories(config_dir); } else { diff --git a/filesystem.h b/filesystem.h new file mode 100644 index 00000000..15e1ee98 --- /dev/null +++ b/filesystem.h @@ -0,0 +1,17 @@ +#ifndef FILESYSTEM_H +#define FILESYSTEM_H + +#if defined(__has_include) && __has_include() + +#include +namespace filesystem = std::filesystem; + +#else + +#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING +#include +namespace filesystem = std::experimental::filesystem; + +#endif // C++17 + +#endif // FILESYSTEM_H diff --git a/scripts/AppImage.patch b/scripts/AppImage.patch index 68ef3be0..95dc01f7 100644 --- a/scripts/AppImage.patch +++ b/scripts/AppImage.patch @@ -10,8 +10,8 @@ index 6295344a..d09bed44 100644 unix:!macx { - TARGET = $$lower($$TARGET) - - CONFIG += \ - c++14 \ + INCLUDEPATH += \ + Controllers/FaustusController \ diff --git a/qt/OpenRGB.desktop b/qt/OpenRGB.desktop index bd71a38a..b4a0f86a 100644