From f7a0cece087c4b0f8284e017ca922b186bf63201 Mon Sep 17 00:00:00 2001 From: tritao Date: Sun, 19 Jan 2025 19:05:06 +0000 Subject: [PATCH] Base: Remove Boost-based `filesystem` and switch to standard `` --- cMake/FreeCAD_Helpers/SetupBoost.cmake | 2 +- .../salomesmesh/src/DriverSTL/SMESH_File.cpp | 21 +++++----- .../salomesmesh/src/SMESH/DriverGMF.cpp | 4 +- src/App/Application.cpp | 20 ++++----- src/App/Document.cpp | 4 +- src/App/Metadata.cpp | 8 ++-- src/App/Metadata.h | 30 +++++++------- src/App/PropertyStandard.cpp | 10 ++--- src/App/PropertyStandard.h | 6 +-- src/App/StringHasher.cpp | 1 + src/Base/FileInfo.cpp | 16 ++++---- src/Base/FileInfo.h | 6 +-- src/Base/Unit.cpp | 1 + src/Gui/Dialogs/DlgAbout.cpp | 8 ++-- .../DlgPreferencePackManagementImp.cpp | 2 +- .../Dialogs/DlgPreferencePackManagementImp.h | 2 +- .../Dialogs/DlgRevertToBackupConfigImp.cpp | 14 ++++++- src/Gui/PreferencePackManager.cpp | 41 +++++++++++-------- src/Gui/PreferencePackManager.h | 24 +++++------ .../PreferencePages/DlgSettingsGeneral.cpp | 2 +- src/Gui/Window.h | 1 + src/Mod/Material/App/MaterialManager.h | 4 +- src/Mod/Test/Document.py | 2 - tests/src/Base/Reader.cpp | 25 +++++++++-- 24 files changed, 144 insertions(+), 110 deletions(-) diff --git a/cMake/FreeCAD_Helpers/SetupBoost.cmake b/cMake/FreeCAD_Helpers/SetupBoost.cmake index 0bb1343c3f..4e07e2e7c0 100644 --- a/cMake/FreeCAD_Helpers/SetupBoost.cmake +++ b/cMake/FreeCAD_Helpers/SetupBoost.cmake @@ -3,7 +3,7 @@ macro(SetupBoost) set(_boost_TEST_VERSIONS ${Boost_ADDITIONAL_VERSIONS}) - set (BOOST_COMPONENTS filesystem program_options regex system thread date_time) + set (BOOST_COMPONENTS program_options regex system thread date_time) find_package(Boost ${BOOST_MIN_VERSION} COMPONENTS ${BOOST_COMPONENTS} REQUIRED) diff --git a/src/3rdParty/salomesmesh/src/DriverSTL/SMESH_File.cpp b/src/3rdParty/salomesmesh/src/DriverSTL/SMESH_File.cpp index 481110f4b2..08794202cd 100644 --- a/src/3rdParty/salomesmesh/src/DriverSTL/SMESH_File.cpp +++ b/src/3rdParty/salomesmesh/src/DriverSTL/SMESH_File.cpp @@ -34,9 +34,10 @@ #include #endif -#include +#include +#include -namespace boofs = boost::filesystem; +namespace stdfs = std::filesystem; //================================================================================ /*! @@ -168,8 +169,8 @@ bool SMESH_File::remove() { close(); - boost::system::error_code err; - boofs::remove( _name, err ); + std::error_code err; + stdfs::remove( _name, err ); _error = err.message(); return !err; @@ -185,8 +186,8 @@ long SMESH_File::size() { if ( _size >= 0 ) return _size; // size of an open file - boost::system::error_code err; - boost::uintmax_t size = boofs::file_size( _name, err ); + std::error_code err; + std::uintmax_t size = stdfs::file_size( _name, err ); _error = err.message(); return err ? -1 : (long) size; @@ -200,8 +201,8 @@ long SMESH_File::size() bool SMESH_File::exists() { - boost::system::error_code err; - bool res = boofs::exists( _name, err ); + std::error_code err; + bool res = stdfs::exists( _name, err ); _error = err.message(); return err ? false : res; @@ -215,8 +216,8 @@ bool SMESH_File::exists() bool SMESH_File::isDirectory() { - boost::system::error_code err; - bool res = boofs::is_directory( _name, err ); + std::error_code err; + bool res = stdfs::is_directory( _name, err ); _error = err.message(); return err ? false : res; diff --git a/src/3rdParty/salomesmesh/src/SMESH/DriverGMF.cpp b/src/3rdParty/salomesmesh/src/SMESH/DriverGMF.cpp index f108cbbcb2..372ea90d50 100644 --- a/src/3rdParty/salomesmesh/src/SMESH/DriverGMF.cpp +++ b/src/3rdParty/salomesmesh/src/SMESH/DriverGMF.cpp @@ -25,7 +25,7 @@ #include "DriverGMF.hxx" -#include +#include extern "C" { @@ -55,7 +55,7 @@ namespace DriverGMF bool isExtensionCorrect( const std::string& fileName ) { - std::string ext = boost::filesystem::path(fileName).extension().string(); + std::string ext = std::filesystem::path(fileName).extension().string(); switch ( ext.size() ) { case 5: return ( ext == ".mesh" || ext == ".solb" ); case 6: return ( ext == ".meshb" ); diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 0498634b8e..e59a61a522 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -3221,7 +3221,7 @@ QString findUserHomePath(const QString& userHome) * Returns the path where to store application files to. * If \a customHome is not empty it will be used, otherwise a path starting from \a stdHome will be used. */ -boost::filesystem::path findPath(const QString& stdHome, const QString& customHome, +std::filesystem::path findPath(const QString& stdHome, const QString& customHome, const std::vector& paths, bool create) { QString dataPath = customHome; @@ -3229,7 +3229,7 @@ boost::filesystem::path findPath(const QString& stdHome, const QString& customHo dataPath = stdHome; } - boost::filesystem::path appData(Base::FileInfo::stringToPath(dataPath.toStdString())); + std::filesystem::path appData(Base::FileInfo::stringToPath(dataPath.toStdString())); // If a custom user home path is given then don't modify it if (customHome.isEmpty()) { @@ -3238,10 +3238,10 @@ boost::filesystem::path findPath(const QString& stdHome, const QString& customHo } // In order to write to our data path, we must create some directories, first. - if (create && !boost::filesystem::exists(appData) && !Py_IsInitialized()) { + if (create && !std::filesystem::exists(appData) && !Py_IsInitialized()) { try { - boost::filesystem::create_directories(appData); - } catch (const boost::filesystem::filesystem_error& e) { + std::filesystem::create_directories(appData); + } catch (const std::filesystem::filesystem_error& e) { throw Base::FileSystemError("Could not create directories. Failed with: " + e.code().message()); } } @@ -3373,13 +3373,13 @@ void Application::ExtractUserPath() // User data path // - boost::filesystem::path data = findPath(dataHome, customData, subdirs, true); + std::filesystem::path data = findPath(dataHome, customData, subdirs, true); mConfig["UserAppData"] = Base::FileInfo::pathToString(data) + PATHSEP; // User config path // - boost::filesystem::path config = findPath(configHome, customHome, subdirs, true); + std::filesystem::path config = findPath(configHome, customHome, subdirs, true); mConfig["UserConfigPath"] = Base::FileInfo::pathToString(config) + PATHSEP; @@ -3387,14 +3387,14 @@ void Application::ExtractUserPath() // std::vector cachedirs = subdirs; cachedirs.emplace_back("Cache"); - boost::filesystem::path cache = findPath(cacheHome, customTemp, cachedirs, true); + std::filesystem::path cache = findPath(cacheHome, customTemp, cachedirs, true); mConfig["UserCachePath"] = Base::FileInfo::pathToString(cache) + PATHSEP; // Set application tmp. directory // std::vector empty; - boost::filesystem::path tmp = findPath(tempPath, customTemp, empty, true); + std::filesystem::path tmp = findPath(tempPath, customTemp, empty, true); mConfig["AppTempPath"] = Base::FileInfo::pathToString(tmp) + PATHSEP; @@ -3402,7 +3402,7 @@ void Application::ExtractUserPath() // std::vector macrodirs = subdirs; macrodirs.emplace_back("Macro"); - boost::filesystem::path macro = findPath(dataHome, customData, macrodirs, true); + std::filesystem::path macro = findPath(dataHome, customData, macrodirs, true); mConfig["UserMacroPath"] = Base::FileInfo::pathToString(macro) + PATHSEP; } diff --git a/src/App/Document.cpp b/src/App/Document.cpp index a67312fe0f..5a074d2a44 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -60,7 +60,7 @@ recompute path. Also, it enables more complicated dependencies beyond trees. #ifndef _PreComp_ #include #include -#include +#include #endif #include @@ -131,7 +131,7 @@ using namespace zipios; #define FC_LOGFEATUREUPDATE #endif -namespace fs = boost::filesystem; +namespace fs = std::filesystem; namespace App { diff --git a/src/App/Metadata.cpp b/src/App/Metadata.cpp index 4e9df6f5fe..364453a721 100644 --- a/src/App/Metadata.cpp +++ b/src/App/Metadata.cpp @@ -57,7 +57,7 @@ directly. If you did not intend to use a system-defined macro #endif using namespace App; -namespace fs = boost::filesystem; +namespace fs = std::filesystem; #ifndef XERCES_CPP_NAMESPACE_BEGIN #define XERCES_CPP_NAMESPACE_QUALIFIER using namespace XERCES_CPP_NAMESPACE; @@ -246,7 +246,7 @@ std::string Metadata::classname() const return _classname; } -boost::filesystem::path Metadata::subdirectory() const +std::filesystem::path Metadata::subdirectory() const { return _subdirectory; } @@ -370,7 +370,7 @@ void Metadata::setClassname(const std::string& name) _classname = name; } -void Metadata::setSubdirectory(const boost::filesystem::path& path) +void Metadata::setSubdirectory(const std::filesystem::path& path) { _subdirectory = path; } @@ -475,7 +475,7 @@ void Metadata::removeTag(const std::string& tag) _tag.erase(new_end, _tag.end()); } -void Metadata::removeFile(const boost::filesystem::path& path) +void Metadata::removeFile(const std::filesystem::path& path) { auto new_end = std::remove(_file.begin(), _file.end(), path); _file.erase(new_end, _file.end()); diff --git a/src/App/Metadata.h b/src/App/Metadata.h index 868315e638..271a112483 100644 --- a/src/App/Metadata.h +++ b/src/App/Metadata.h @@ -25,7 +25,7 @@ #include "FCConfig.h" -#include +#include #include #include @@ -67,11 +67,11 @@ struct AppExport Contact struct AppExport License { License() = default; - License(std::string name, boost::filesystem::path file); + License(std::string name, std::filesystem::path file); explicit License(const XERCES_CPP_NAMESPACE::DOMElement* elem); std::string name; //< Short name of license, e.g. "LGPL2", "MIT", "Mozilla Public License", etc. - boost::filesystem::path + std::filesystem::path file; //< Optional path to the license file, relative to the XML file's location bool operator==(const License& rhs) const; }; @@ -205,7 +205,7 @@ public: * This constructor takes a path to an XML file and loads the XML from that file as * metadata. */ - explicit Metadata(const boost::filesystem::path& metadataFile); + explicit Metadata(const std::filesystem::path& metadataFile); /** * Construct a Metadata object from a DOM node. @@ -248,12 +248,12 @@ public: std::vector replace() const; //< Zero or more packages this package is intended to replace. std::vector tag() const; //< Zero or more text tags related to this package. - boost::filesystem::path icon() const; //< Path to an icon file. + std::filesystem::path icon() const; //< Path to an icon file. std::string classname() const; //< Recognized for convenience -- generally only used by Workbenches. - boost::filesystem::path + std::filesystem::path subdirectory() const; //< Optional, override the default subdirectory name for this item. - std::vector + std::vector file() const; //< Arbitrary files associated with this package or content item. Meta::Version freecadmin() const; //< The minimum FreeCAD version. Meta::Version freecadmax() const; //< The maximum FreeCAD version. @@ -307,10 +307,10 @@ public: void addConflict(const Meta::Dependency& dep); void addReplace(const Meta::Dependency& dep); void addTag(const std::string& tag); - void setIcon(const boost::filesystem::path& path); + void setIcon(const std::filesystem::path& path); void setClassname(const std::string& name); - void setSubdirectory(const boost::filesystem::path& path); - void addFile(const boost::filesystem::path& path); + void setSubdirectory(const std::filesystem::path& path); + void addFile(const std::filesystem::path& path); void addContentItem(const std::string& tag, const Metadata& item); void setFreeCADMin(const Meta::Version& version); void setFreeCADMax(const Meta::Version& version); @@ -327,7 +327,7 @@ public: void removeConflict(const Meta::Dependency& dep); void removeReplace(const Meta::Dependency& dep); void removeTag(const std::string& tag); - void removeFile(const boost::filesystem::path& path); + void removeFile(const std::filesystem::path& path); // Utility functions to clear lists void clearContent(); @@ -344,7 +344,7 @@ public: /** * Write the metadata to an XML file */ - void write(const boost::filesystem::path& file) const; + void write(const std::filesystem::path& file) const; /** * Determine whether this package satisfies the given dependency @@ -371,10 +371,10 @@ private: std::vector _conflict; std::vector _replace; std::vector _tag; - boost::filesystem::path _icon; + std::filesystem::path _icon; std::string _classname; - boost::filesystem::path _subdirectory; - std::vector _file; + std::filesystem::path _subdirectory; + std::vector _file; Meta::Version _freecadmin; Meta::Version _freecadmax; Meta::Version _pythonmin; diff --git a/src/App/PropertyStandard.cpp b/src/App/PropertyStandard.cpp index 9eb638ad91..238df5d8b5 100644 --- a/src/App/PropertyStandard.cpp +++ b/src/App/PropertyStandard.cpp @@ -177,7 +177,7 @@ PropertyPath::~PropertyPath() = default; //************************************************************************** // Setter/getter for the property -void PropertyPath::setValue(const boost::filesystem::path& Path) +void PropertyPath::setValue(const std::filesystem::path& Path) { aboutToSetValue(); _cValue = Path; @@ -187,15 +187,11 @@ void PropertyPath::setValue(const boost::filesystem::path& Path) void PropertyPath::setValue(const char* Path) { aboutToSetValue(); -#if (BOOST_FILESYSTEM_VERSION == 2) - _cValue = boost::filesystem::path(Path, boost::filesystem::no_check); -#else - _cValue = boost::filesystem::path(Path); -#endif + _cValue = std::filesystem::path(Path); hasSetValue(); } -const boost::filesystem::path& PropertyPath::getValue() const +const std::filesystem::path& PropertyPath::getValue() const { return _cValue; } diff --git a/src/App/PropertyStandard.h b/src/App/PropertyStandard.h index d592935d62..e85f985323 100644 --- a/src/App/PropertyStandard.h +++ b/src/App/PropertyStandard.h @@ -117,7 +117,7 @@ public: /** Sets the property */ - void setValue(const boost::filesystem::path&); + void setValue(const std::filesystem::path&); /** Sets the property */ @@ -125,7 +125,7 @@ public: /** This method returns a string representation of the property */ - const boost::filesystem::path& getValue() const; + const std::filesystem::path& getValue() const; const char* getEditorName() const override { @@ -153,7 +153,7 @@ public: } protected: - boost::filesystem::path _cValue; + std::filesystem::path _cValue; }; /// Property wrapper around an Enumeration object. diff --git a/src/App/StringHasher.cpp b/src/App/StringHasher.cpp index 7cdc892dd1..3e2a211841 100644 --- a/src/App/StringHasher.cpp +++ b/src/App/StringHasher.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include "MappedElement.h" diff --git a/src/Base/FileInfo.cpp b/src/Base/FileInfo.cpp index e5669ca658..d10a3c65b1 100644 --- a/src/Base/FileInfo.cpp +++ b/src/Base/FileInfo.cpp @@ -208,18 +208,18 @@ std::string FileInfo::getTempFileName(const char* FileName, const char* Path) #endif } -boost::filesystem::path FileInfo::stringToPath(const std::string& str) +std::filesystem::path FileInfo::stringToPath(const std::string& str) { #if defined(FC_OS_WIN32) std::wstring_convert> converter; - boost::filesystem::path path(converter.from_bytes(str)); + std::filesystem::path path(converter.from_bytes(str)); #else - boost::filesystem::path path(str); + std::filesystem::path path(str); #endif return path; } -std::string FileInfo::pathToString(const boost::filesystem::path& path) +std::string FileInfo::pathToString(const std::filesystem::path& path) { #if defined(FC_OS_WIN32) std::wstring_convert> converter; @@ -583,14 +583,14 @@ bool FileInfo::createDirectory() const bool FileInfo::createDirectories() const { try { - boost::filesystem::path path(stringToPath(FileName)); - if (boost::filesystem::exists(path)) { + std::filesystem::path path(stringToPath(FileName)); + if (std::filesystem::exists(path)) { return true; } - boost::filesystem::create_directories(path); + std::filesystem::create_directories(path); return true; } - catch (const boost::filesystem::filesystem_error&) { + catch (const std::filesystem::filesystem_error&) { return false; } } diff --git a/src/Base/FileInfo.h b/src/Base/FileInfo.h index 502dec3f4a..7e0ddbb9a4 100644 --- a/src/Base/FileInfo.h +++ b/src/Base/FileInfo.h @@ -25,7 +25,7 @@ #ifndef BASE_FILEINFO_H #define BASE_FILEINFO_H -#include +#include #include #include #include @@ -158,9 +158,9 @@ public: /// Get the path to the dir which is considered to temp files static const std::string& getTempPath(); /// Convert from filesystem path to string - static std::string pathToString(const boost::filesystem::path& path); + static std::string pathToString(const std::filesystem::path& path); /// Convert from string to filesystem path - static boost::filesystem::path stringToPath(const std::string& str); + static std::filesystem::path stringToPath(const std::string& str); //@} private: diff --git a/src/Base/Unit.cpp b/src/Base/Unit.cpp index 6aaa117af1..45a53dedb1 100644 --- a/src/Base/Unit.cpp +++ b/src/Base/Unit.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include diff --git a/src/Gui/Dialogs/DlgAbout.cpp b/src/Gui/Dialogs/DlgAbout.cpp index 191f09517b..3c25f6b731 100644 --- a/src/Gui/Dialogs/DlgAbout.cpp +++ b/src/Gui/Dialogs/DlgAbout.cpp @@ -48,7 +48,7 @@ #include #include -#include +#include #include #include @@ -60,7 +60,7 @@ using namespace Gui; using namespace Gui::Dialog; -namespace fs = boost::filesystem; +namespace fs = std::filesystem; static QString prettyProductInfoWrapper() { @@ -548,8 +548,8 @@ void AboutDialog::addModuleInfo(QTextStream& str, const QString& modPath, bool& str << " * " << (mod.isDir() ? QDir(modPath).dirName() : mod.fileName()); try { auto metadataFile = - boost::filesystem::path(mod.absoluteFilePath().toStdString()) / "package.xml"; - if (boost::filesystem::exists(metadataFile)) { + std::filesystem::path(mod.absoluteFilePath().toStdString()) / "package.xml"; + if (std::filesystem::exists(metadataFile)) { App::Metadata metadata(metadataFile); if (metadata.version() != App::Meta::Version()) { str << QLatin1String(" ") + QString::fromStdString(metadata.version().str()); diff --git a/src/Gui/Dialogs/DlgPreferencePackManagementImp.cpp b/src/Gui/Dialogs/DlgPreferencePackManagementImp.cpp index 11b7f15a15..e310ce0708 100644 --- a/src/Gui/Dialogs/DlgPreferencePackManagementImp.cpp +++ b/src/Gui/Dialogs/DlgPreferencePackManagementImp.cpp @@ -33,7 +33,7 @@ using namespace Gui::Dialog; -namespace fs = boost::filesystem; +namespace fs = std::filesystem; /* TRANSLATOR Gui::Dialog::DlgPreferencePackManagementImp */ diff --git a/src/Gui/Dialogs/DlgPreferencePackManagementImp.h b/src/Gui/Dialogs/DlgPreferencePackManagementImp.h index f4a41bdb03..49bd8c7d4d 100644 --- a/src/Gui/Dialogs/DlgPreferencePackManagementImp.h +++ b/src/Gui/Dialogs/DlgPreferencePackManagementImp.h @@ -26,7 +26,7 @@ #include #include -#include +#include #include diff --git a/src/Gui/Dialogs/DlgRevertToBackupConfigImp.cpp b/src/Gui/Dialogs/DlgRevertToBackupConfigImp.cpp index d82f4f6921..5f9df07c99 100644 --- a/src/Gui/Dialogs/DlgRevertToBackupConfigImp.cpp +++ b/src/Gui/Dialogs/DlgRevertToBackupConfigImp.cpp @@ -34,7 +34,7 @@ using namespace Gui; using namespace Gui::Dialog; -namespace fs = boost::filesystem; +namespace fs = std::filesystem; /* TRANSLATOR Gui::Dialog::DlgRevertToBackupConfigImp */ @@ -71,12 +71,22 @@ void DlgRevertToBackupConfigImp::changeEvent(QEvent *e) } } +// FIXME: Replace with more accurate C++20 solution once its usable: https://stackoverflow.com/a/68593141 +template +static std::time_t to_time_t(TP tp) +{ + using namespace std::chrono; + auto sctp = time_point_cast(tp - TP::clock::now() + + system_clock::now()); + return system_clock::to_time_t(sctp); +} + void DlgRevertToBackupConfigImp::showEvent(QShowEvent* event) { ui->listWidget->clear(); const auto& backups = Application::Instance->prefPackManager()->configBackups(); for (const auto& backup : backups) { - auto modification_date = QDateTime::fromSecsSinceEpoch(fs::last_write_time(backup)); + auto modification_date = QDateTime::fromSecsSinceEpoch(to_time_t(fs::last_write_time(backup))); auto item = new QListWidgetItem(QLocale().toString(modification_date)); item->setData(Qt::UserRole, QString::fromStdString(backup.string())); ui->listWidget->addItem(item); diff --git a/src/Gui/PreferencePackManager.cpp b/src/Gui/PreferencePackManager.cpp index d443926d8b..45d471ff27 100644 --- a/src/Gui/PreferencePackManager.cpp +++ b/src/Gui/PreferencePackManager.cpp @@ -29,7 +29,7 @@ # include #endif -#include +#include #include #include @@ -48,15 +48,15 @@ using namespace Gui; using namespace xercesc; -namespace fs = boost::filesystem; +namespace fs = std::filesystem; -static boost::filesystem::path getSavedPrefPacksPath() +static std::filesystem::path getSavedPrefPacksPath() { return fs::path(Base::FileInfo::stringToPath(App::Application::getUserAppDataDir())) / "SavedPreferencePacks"; } -static boost::filesystem::path getResourcePrefPacksPath() +static std::filesystem::path getResourcePrefPacksPath() { return fs::path(Base::FileInfo::stringToPath(App::Application::getResourceDir())) / "Gui" / "PreferencePacks"; @@ -228,29 +228,25 @@ void Gui::PreferencePackManager::AddPackToMetadata(const std::string &packName) } void Gui::PreferencePackManager::importConfig(const std::string& packName, - const boost::filesystem::path& path) + const std::filesystem::path& path) { AddPackToMetadata(packName); auto savedPreferencePacksDirectory = getSavedPreferencePacksPath(); auto cfgFilename = savedPreferencePacksDirectory / packName / (packName + ".cfg"); -#if BOOST_VERSION >= 107400 fs::copy_file(path, cfgFilename, fs::copy_options::overwrite_existing); -#else - fs::copy_file(path, cfgFilename, fs::copy_option::overwrite_if_exists); -#endif rescan(); } // TODO(Shvedov): Is this suitable place for this method? It is more generic, // and maybe more suitable place at Application? -std::vector Gui::PreferencePackManager::modPaths() const +std::vector Gui::PreferencePackManager::modPaths() const { auto userModPath = fs::path(Base::FileInfo::stringToPath(App::Application::getUserAppDataDir())) / "Mod"; auto& config = App::Application::Config(); auto additionalModules = config.find("AdditionalModulePaths"); - std::vector result; + std::vector result; if (additionalModules != config.end()) { boost::split(result, @@ -262,12 +258,12 @@ std::vector Gui::PreferencePackManager::modPaths() cons return result; } -boost::filesystem::path Gui::PreferencePackManager::getSavedPreferencePacksPath() const +std::filesystem::path Gui::PreferencePackManager::getSavedPreferencePacksPath() const { return getSavedPrefPacksPath(); } -boost::filesystem::path Gui::PreferencePackManager::getResourcePreferencePacksPath() const +std::filesystem::path Gui::PreferencePackManager::getResourcePreferencePacksPath() const { return getResourcePrefPacksPath(); } @@ -309,7 +305,7 @@ void Gui::PreferencePackManager::FindPreferencePacksInPackage(const fs::path &mo } } -void PreferencePackManager::TryFindPreferencePacksInPackage(const boost::filesystem::path& mod) +void PreferencePackManager::TryFindPreferencePacksInPackage(const std::filesystem::path& mod) { auto packageMetadataFile = mod / "package.xml"; static const auto modDirectory = fs::path(Base::FileInfo::stringToPath(App::Application::getUserAppDataDir())) / "Mod" / "SavedPreferencePacks"; @@ -625,6 +621,16 @@ void Gui::PreferencePackManager::BackupCurrentConfig() const App::GetApplication().GetUserParameter().SaveDocument(Base::FileInfo::pathToString(filename).c_str()); } +// FIXME: Replace with more accurate C++20 solution once its usable: https://stackoverflow.com/a/68593141 +template +static std::time_t to_time_t(TP tp) +{ + using namespace std::chrono; + auto sctp = time_point_cast(tp - TP::clock::now() + + system_clock::now()); + return system_clock::to_time_t(sctp); +} + void Gui::PreferencePackManager::DeleteOldBackups() const { constexpr auto oneWeek = 60.0 * 60.0 * 24.0 * 7.0; @@ -632,7 +638,7 @@ void Gui::PreferencePackManager::DeleteOldBackups() const auto backupDirectory = getSavedPreferencePacksPath() / "Backups"; if (fs::exists(backupDirectory) && fs::is_directory(backupDirectory)) { for (const auto& backup : fs::directory_iterator(backupDirectory)) { - if (std::difftime(now, fs::last_write_time(backup)) > oneWeek) { + if (std::difftime(now, to_time_t(fs::last_write_time(backup))) > oneWeek) { try { fs::remove(backup); } @@ -642,9 +648,10 @@ void Gui::PreferencePackManager::DeleteOldBackups() const } } -std::vector Gui::PreferencePackManager::configBackups() const +// FIXME: Replace with more accurate C++20 solution once its usable: https://stackoverflow.com/a/68593141 +std::vector Gui::PreferencePackManager::configBackups() const { - std::vector results; + std::vector results; auto backupDirectory = getSavedPreferencePacksPath() / "Backups"; if (fs::exists(backupDirectory) && fs::is_directory(backupDirectory)) { for (const auto& backup : fs::directory_iterator(backupDirectory)) { diff --git a/src/Gui/PreferencePackManager.h b/src/Gui/PreferencePackManager.h index bb87917447..5250b3407b 100644 --- a/src/Gui/PreferencePackManager.h +++ b/src/Gui/PreferencePackManager.h @@ -44,7 +44,7 @@ namespace Gui { * \param path A path to a mod directory that contains a preferencePack * \param metadata The metadata from the package.xml file describing this preferencePack */ - PreferencePack(const boost::filesystem::path& path, const App::Metadata& metadata); + PreferencePack(const std::filesystem::path& path, const App::Metadata& metadata); ~PreferencePack() = default; @@ -68,7 +68,7 @@ namespace Gui { void applyConfigChanges() const; - boost::filesystem::path _path; + std::filesystem::path _path; App::Metadata _metadata; }; @@ -168,7 +168,7 @@ namespace Gui { struct TemplateFile { std::string group; // Generally the Add-On/Mod/Package name std::string name; - boost::filesystem::path path; + std::filesystem::path path; }; /** @@ -184,37 +184,37 @@ namespace Gui { /** * Get a list of all available config file backups. Backups are currently stored for one week. */ - std::vector configBackups() const; + std::vector configBackups() const; /** * Import an existing config file as a preference pack with a given name. */ - void importConfig(const std::string &packName, const boost::filesystem::path &path); + void importConfig(const std::string &packName, const std::filesystem::path &path); /** * Get a list of all mod directories. */ - std::vector modPaths() const; + std::vector modPaths() const; /** * Get the path to the saved preference packs. */ - boost::filesystem::path getSavedPreferencePacksPath() const; + std::filesystem::path getSavedPreferencePacksPath() const; /** * Get the path to the preference packs of the resource directory. */ - boost::filesystem::path getResourcePreferencePacksPath() const; + std::filesystem::path getResourcePreferencePacksPath() const; /** * Collect all preference packs of a directory. */ - std::vector getPacksFromDirectory(const boost::filesystem::path& path) const; + std::vector getPacksFromDirectory(const std::filesystem::path& path) const; private: - void FindPreferencePacksInPackage(const boost::filesystem::path& mod); - void TryFindPreferencePacksInPackage(const boost::filesystem::path& mod); + void FindPreferencePacksInPackage(const std::filesystem::path& mod); + void TryFindPreferencePacksInPackage(const std::filesystem::path& mod); void BackupCurrentConfig() const; @@ -222,7 +222,7 @@ namespace Gui { void AddPackToMetadata(const std::string &packName) const; - std::vector _preferencePackPaths; + std::vector _preferencePackPaths; std::vector _templateFiles; std::map _preferencePacks; mutable std::mutex _mutex; diff --git a/src/Gui/PreferencePages/DlgSettingsGeneral.cpp b/src/Gui/PreferencePages/DlgSettingsGeneral.cpp index 6f370c719f..e4f57f0e0d 100644 --- a/src/Gui/PreferencePages/DlgSettingsGeneral.cpp +++ b/src/Gui/PreferencePages/DlgSettingsGeneral.cpp @@ -62,7 +62,7 @@ using namespace Gui; using namespace Gui::Dialog; -namespace fs = boost::filesystem; +namespace fs = std::filesystem; using namespace Base; /* TRANSLATOR Gui::Dialog::DlgSettingsGeneral */ diff --git a/src/Gui/Window.h b/src/Gui/Window.h index 179c7a88d8..a57fe5e4c3 100644 --- a/src/Gui/Window.h +++ b/src/Gui/Window.h @@ -25,6 +25,7 @@ #define GUI_WINDOW_H #include +#include namespace Gui { diff --git a/src/Mod/Material/App/MaterialManager.h b/src/Mod/Material/App/MaterialManager.h index c263e5d8c4..63f06dc772 100644 --- a/src/Mod/Material/App/MaterialManager.h +++ b/src/Mod/Material/App/MaterialManager.h @@ -24,7 +24,7 @@ #include -#include +#include #include @@ -34,7 +34,7 @@ #include "MaterialLibrary.h" #include "MaterialFilter.h" -namespace fs = boost::filesystem; +namespace fs = std::filesystem; class QMutex; diff --git a/src/Mod/Test/Document.py b/src/Mod/Test/Document.py index 4a08d51c4b..9ad30c9f28 100644 --- a/src/Mod/Test/Document.py +++ b/src/Mod/Test/Document.py @@ -187,8 +187,6 @@ class DocumentBasicCases(unittest.TestCase): self.assertTrue(L1.Float - 47.11 < 0.001) self.assertTrue(L1.Bool == True) self.assertTrue(L1.String == "4711") - # temporarily not checked because of strange behavior of boost::filesystem JR - # self.assertTrue(L1.Path == "c:/temp") self.assertTrue(float(L1.Angle) - 3.0 < 0.001) self.assertTrue(float(L1.Distance) - 47.11 < 0.001) diff --git a/tests/src/Base/Reader.cpp b/tests/src/Base/Reader.cpp index da308a41c8..b692bf5979 100644 --- a/tests/src/Base/Reader.cpp +++ b/tests/src/Base/Reader.cpp @@ -9,11 +9,29 @@ #include "Base/Exception.h" #include "Base/Reader.h" #include -#include +#include #include +#include +#include #include -namespace fs = boost::filesystem; +namespace fs = std::filesystem; + +static std::string random_string(size_t length) +{ + const std::string digits = "0123456789"; + + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dis(0, digits.size() - 1); + + std::string result; + for (size_t i = 0; i < length; ++i) { + result += digits[dis(gen)]; + } + + return result; +} class ReaderXML { @@ -21,7 +39,8 @@ public: ReaderXML() { _tempDir = fs::temp_directory_path(); - fs::path filename = fs::unique_path("unit_test_Reader-%%%%.xml"); + fs::path filename = + std::string("unit_test_Reader-") + random_string(4) + std::string(".xml"); _tempFile = _tempDir / filename; } ~ReaderXML()