From 124097d3a50ba4ae97478ce7d33e5d33690cef75 Mon Sep 17 00:00:00 2001 From: flow Date: Thu, 13 Oct 2022 18:38:52 -0300 Subject: [PATCH] feat!: use ghc/filesystem in place of std's one if needed Signed-off-by: flow --- launcher/FileSystem.cpp | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index 5d179641f..c2db0dbca 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -59,7 +59,24 @@ #include #endif +// Snippet from https://github.com/gulrak/filesystem#using-it-as-single-file-header + +#ifdef __APPLE__ +#include // for deployment target to support pre-catalina targets without std::fs +#endif // __APPLE__ + +#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include) +#if __has_include() && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) +#define GHC_USE_STD_FS #include +namespace fs = std::filesystem; +#endif // MacOS min version check +#endif // Other OSes version check + +#ifndef GHC_USE_STD_FS +#include +namespace fs = ghc::filesystem; +#endif #if defined Q_OS_WIN32 @@ -147,7 +164,7 @@ bool ensureFolderPathExists(QString foldernamepath) bool copy::operator()(const QString& offset) { - using copy_opts = std::filesystem::copy_options; + using copy_opts = fs::copy_options; // NOTE always deep copy on windows. the alternatives are too messy. #if defined Q_OS_WIN32 @@ -159,7 +176,7 @@ bool copy::operator()(const QString& offset) std::error_code err; - std::filesystem::copy_options opt = copy_opts::none; + fs::copy_options opt = copy_opts::none; // The default behavior is to follow symlinks if (!m_followSymlinks) @@ -182,7 +199,7 @@ bool copy::operator()(const QString& offset) auto dst_path = PathCombine(dst, relative_path); ensureFilePathExists(dst_path); - std::filesystem::copy(toStdString(src_path), toStdString(dst_path), opt, err); + fs::copy(toStdString(src_path), toStdString(dst_path), opt, err); if (err) { qWarning() << "Failed to copy files:" << QString::fromStdString(err.message()); qDebug() << "Source file:" << src_path; @@ -197,7 +214,7 @@ bool deletePath(QString path) { std::error_code err; - std::filesystem::remove_all(toStdString(path), err); + fs::remove_all(toStdString(path), err); if (err) { qWarning() << "Failed to remove files:" << QString::fromStdString(err.message()); @@ -376,15 +393,15 @@ bool createShortCut(QString location, QString dest, QStringList args, QString na bool overrideFolder(QString overwritten_path, QString override_path) { - using copy_opts = std::filesystem::copy_options; + using copy_opts = fs::copy_options; if (!FS::ensureFolderPathExists(overwritten_path)) return false; std::error_code err; - std::filesystem::copy_options opt = copy_opts::recursive | copy_opts::overwrite_existing; + fs::copy_options opt = copy_opts::recursive | copy_opts::overwrite_existing; - std::filesystem::copy(toStdString(override_path), toStdString(overwritten_path), opt, err); + fs::copy(toStdString(override_path), toStdString(overwritten_path), opt, err); if (err) { qCritical() << QString("Failed to apply override from %1 to %2").arg(override_path, overwritten_path);