diff --git a/cMake/FreeCAD_Helpers/SetupBoost.cmake b/cMake/FreeCAD_Helpers/SetupBoost.cmake index a87332b13fce..dae1935dbd96 100644 --- a/cMake/FreeCAD_Helpers/SetupBoost.cmake +++ b/cMake/FreeCAD_Helpers/SetupBoost.cmake @@ -2,8 +2,7 @@ macro(SetupBoost) # -------------------------------- Boost -------------------------------- set(_boost_TEST_VERSIONS ${Boost_ADDITIONAL_VERSIONS}) - - set (BOOST_COMPONENTS filesystem program_options regex thread date_time) + set (BOOST_COMPONENTS program_options regex thread date_time) # set (BOOST_COMPONENTS filesystem 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 481110f4b288..08794202cd49 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 f108cbbcb2cf..372ea90d505d 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 f62b73064546..22f31e13397f 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -3071,7 +3071,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; @@ -3079,7 +3079,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()) { @@ -3088,10 +3088,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()); } } @@ -3223,13 +3223,13 @@ void Application::ExtractUserPath() // User data path // - boost::filesystem::path data = findPath(dataHome, customData, subdirs, true); + std::filesystem::path data = findPath(dataHome, customHome, 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; @@ -3237,14 +3237,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; @@ -3252,7 +3252,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 52ba468f3456..057380aaf2fb 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 @@ -127,7 +127,7 @@ using namespace zipios; # define FC_LOGFEATUREUPDATE #endif -namespace fs = boost::filesystem; +namespace fs = std::filesystem; namespace App { diff --git a/src/App/ElementMap.cpp b/src/App/ElementMap.cpp index 3be76b9973b6..386f3cd486f8 100644 --- a/src/App/ElementMap.cpp +++ b/src/App/ElementMap.cpp @@ -14,7 +14,7 @@ #include #include - +#include FC_LOG_LEVEL_INIT("ElementMap", true, 2);// NOLINT diff --git a/src/App/Expression.cpp b/src/App/Expression.cpp index 639fb8dd2178..8300eb5e2232 100644 --- a/src/App/Expression.cpp +++ b/src/App/Expression.cpp @@ -31,6 +31,7 @@ #endif #include +#include #include #include diff --git a/src/App/Metadata.cpp b/src/App/Metadata.cpp index bac6822fc0ff..9667b97395d2 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; @@ -242,7 +242,7 @@ std::string Metadata::classname() const return _classname; } -boost::filesystem::path Metadata::subdirectory() const +std::filesystem::path Metadata::subdirectory() const { return _subdirectory; } @@ -361,7 +361,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; } @@ -466,7 +466,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 a3a7ad091026..2118dafbf0aa 100644 --- a/src/App/Metadata.h +++ b/src/App/Metadata.h @@ -25,7 +25,7 @@ #include "FCConfig.h" -#include +#include #include #include @@ -64,10 +64,10 @@ 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; }; @@ -196,7 +196,7 @@ class AppExport Metadata * 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. @@ -238,12 +238,12 @@ class AppExport Metadata 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. @@ -296,10 +296,10 @@ class AppExport Metadata 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); @@ -316,7 +316,7 @@ class AppExport Metadata 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(); @@ -333,7 +333,7 @@ class AppExport Metadata /** * 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 @@ -359,10 +359,10 @@ class AppExport Metadata 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 96b69440b05c..457f9be35e3a 100644 --- a/src/App/PropertyStandard.cpp +++ b/src/App/PropertyStandard.cpp @@ -172,7 +172,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; @@ -183,16 +183,16 @@ void PropertyPath::setValue(const char * Path) { aboutToSetValue(); #if (BOOST_FILESYSTEM_VERSION == 2) - _cValue = boost::filesystem::path(Path,boost::filesystem::no_check ); - //_cValue = boost::filesystem::path(Path,boost::filesystem::native ); - //_cValue = boost::filesystem::path(Path,boost::filesystem::windows_name ); + _cValue = std::filesystem::path(Path,std::filesystem::no_check ); + //_cValue = std::filesystem::path(Path,std::filesystem::native ); + //_cValue = std::filesystem::path(Path,std::filesystem::windows_name ); #else - _cValue = boost::filesystem::path(Path); + _cValue = std::filesystem::path(Path); #endif 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 04206c3d743c..bd74ab15e770 100644 --- a/src/App/PropertyStandard.h +++ b/src/App/PropertyStandard.h @@ -29,7 +29,7 @@ #include #include #include -#include +// #include #include #include "Property.h" @@ -104,7 +104,7 @@ class AppExport PropertyPath: public Property /** Sets the property */ - void setValue(const boost::filesystem::path &); + void setValue(const std::filesystem::path &); /** Sets the property */ @@ -112,7 +112,7 @@ class AppExport PropertyPath: public Property /** 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 { return "Gui::PropertyEditor::PropertyPathItem"; } @@ -135,7 +135,7 @@ class AppExport PropertyPath: public Property } 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 f4d0f94cb419..c9edcf17ed7a 100644 --- a/src/App/StringHasher.cpp +++ b/src/App/StringHasher.cpp @@ -36,8 +36,8 @@ #include #include #include +#include #include - #include "MappedElement.h" #include "StringHasher.h" #include "StringHasherPy.h" diff --git a/src/Base/FileInfo.cpp b/src/Base/FileInfo.cpp index a2fca09a7046..74cf994bf262 100644 --- a/src/Base/FileInfo.cpp +++ b/src/Base/FileInfo.cpp @@ -199,18 +199,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& p) +std::string FileInfo::pathToString(const std::filesystem::path& p) { #if defined(FC_OS_WIN32) std::wstring_convert> converter; @@ -539,13 +539,13 @@ 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 4b49173dd336..16d479f2f490 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 @@ -142,9 +142,9 @@ class BaseExport FileInfo /// 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& p); + static std::string pathToString(const std::filesystem::path& p); /// Convert from string to filesystem path - static boost::filesystem::path stringToPath(const std::string& str); + static std::filesystem::path stringToPath(const std::string& str); //@} protected: diff --git a/src/Base/Unit.cpp b/src/Base/Unit.cpp index f6fe74422445..82e691378d0f 100644 --- a/src/Base/Unit.cpp +++ b/src/Base/Unit.cpp @@ -23,6 +23,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ # include +# include # include # include #endif diff --git a/src/Gui/DlgGeneralImp.cpp b/src/Gui/DlgGeneralImp.cpp index 772ec6fb04e4..e8f1fc24b4ed 100644 --- a/src/Gui/DlgGeneralImp.cpp +++ b/src/Gui/DlgGeneralImp.cpp @@ -32,7 +32,7 @@ # include # include # include -# include +// # include #endif #include @@ -51,7 +51,7 @@ #include "Language/Translator.h" using namespace Gui::Dialog; -namespace fs = boost::filesystem; +namespace fs = std::filesystem; using namespace Base; /* TRANSLATOR Gui::Dialog::DlgGeneralImp */ diff --git a/src/Gui/DlgPreferencePackManagementImp.cpp b/src/Gui/DlgPreferencePackManagementImp.cpp index b956965e7922..efbd0c7f2750 100644 --- a/src/Gui/DlgPreferencePackManagementImp.cpp +++ b/src/Gui/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/DlgPreferencePackManagementImp.h b/src/Gui/DlgPreferencePackManagementImp.h index 0e3ab1ea9aa0..54592487d9eb 100644 --- a/src/Gui/DlgPreferencePackManagementImp.h +++ b/src/Gui/DlgPreferencePackManagementImp.h @@ -26,7 +26,7 @@ #include #include -#include +#include class QTreeWidgetItem; @@ -75,7 +75,7 @@ protected Q_SLOTS: std::unique_ptr ui; - std::vector getPacksFromDirectory(const boost::filesystem::path& path) const; + std::vector getPacksFromDirectory(const std::filesystem::path& path) const; void addTreeNode(const std::string& name, const std::vector& contents, TreeWidgetType twt); }; diff --git a/src/Gui/DlgRevertToBackupConfigImp.cpp b/src/Gui/DlgRevertToBackupConfigImp.cpp index 4cbb3f76fff2..2ddcaf6484ac 100644 --- a/src/Gui/DlgRevertToBackupConfigImp.cpp +++ b/src/Gui/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 */ @@ -73,13 +73,23 @@ 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 filename = backup.filename().string(); - 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 93e6920db932..2126751ce9fe 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,26 @@ 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 +259,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 +306,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 +622,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 +639,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 +649,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 ac5b9942e099..3ab78e39668c 100644 --- a/src/Gui/PreferencePackManager.h +++ b/src/Gui/PreferencePackManager.h @@ -44,7 +44,7 @@ * \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 @@ void applyConfigChanges() const; - boost::filesystem::path _path; + std::filesystem::path _path; App::Metadata _metadata; }; @@ -168,7 +168,7 @@ 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 @@ /** * 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 @@ 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/Splashscreen.cpp b/src/Gui/Splashscreen.cpp index e436be2446bd..660e20fe650b 100644 --- a/src/Gui/Splashscreen.cpp +++ b/src/Gui/Splashscreen.cpp @@ -47,7 +47,7 @@ #include #include -#include +#include #include #include @@ -58,7 +58,7 @@ using namespace Gui; using namespace Gui::Dialog; -namespace fs = boost::filesystem; +namespace fs = std::filesystem; namespace Gui { diff --git a/src/Gui/Window.h b/src/Gui/Window.h index 179c7a88d81a..a57fe5e4c3d6 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/Test/Document.py b/src/Mod/Test/Document.py index 3bfe503281a6..b36d522d5044 100644 --- a/src/Mod/Test/Document.py +++ b/src/Mod/Test/Document.py @@ -145,8 +145,6 @@ def testObjects(self): self.failUnless(L1.Float-47.11<0.001) self.failUnless(L1.Bool == True) self.failUnless(L1.String == "4711") - #temporarily not checked because of strange behavior of boost::filesystem JR - #self.failUnless(L1.Path == "c:/temp") self.failUnless(float(L1.Angle)-3.0<0.001) self.failUnless(float(L1.Distance)-47.11<0.001)