Add filesystem header to select between std::filesystem and std::experimental::filesystem depending on system availability.

Commit amended by Adam Honse <calcprogrammer1@gmail.com>
This commit is contained in:
k1-801 2021-04-24 21:40:24 +04:00 committed by Adam Honse
parent 05d72ba96f
commit ad2cd89128
6 changed files with 33 additions and 21 deletions

View file

@ -4,9 +4,7 @@
#include <iostream>
#include "ResourceManager.h"
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#include <experimental/filesystem>
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 |

View file

@ -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 \
}
#-------------------------------------------------------------------------------------------#

View file

@ -2,17 +2,15 @@
#include "ResourceManager.h"
#include "RGBController_Dummy.h"
#include "LogManager.h"
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#include <experimental/filesystem>
#include "filesystem.h"
#include <fstream>
#include <iostream>
#include <cstring>
#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();

View file

@ -12,9 +12,8 @@
#include "ResourceManager.h"
#include "ProfileManager.h"
#include "LogManager.h"
#include "filesystem.h"
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#include <experimental/filesystem>
#include <stdlib.h>
#include <string>
#include <hidapi/hidapi.h>
@ -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
{

17
filesystem.h Normal file
View file

@ -0,0 +1,17 @@
#ifndef FILESYSTEM_H
#define FILESYSTEM_H
#if defined(__has_include) && __has_include(<filesystem>)
#include <filesystem>
namespace filesystem = std::filesystem;
#else
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#include <experimental/filesystem>
namespace filesystem = std::experimental::filesystem;
#endif // C++17
#endif // FILESYSTEM_H

View file

@ -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