From 060f3bf8f36a3bd8734d34dfcbcba3109ca065da Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 19 Dec 2021 21:24:17 +0100 Subject: [PATCH] Gui: boost 1.76 provides an overloaded version of file_lock that accepts a wchar_t string --- src/Gui/Application.cpp | 13 +++++++------ src/Gui/DocumentRecovery.cpp | 7 ++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index f0d93a351c..c2119f52a1 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -2282,14 +2282,15 @@ void Application::runApplication(void) Base::FileInfo fi(s.str()); Base::ofstream lock(fi); - // HINT: - // On Windows the creation of the file_lock may fail because of non-ASCII - // path names. The limiting factor is that boost doesn't provide a version - // with std::wstring. - // So, in this case handle the exception and start FreeCAD without IPC. + // In case the file_lock cannot be created start FreeCAD without IPC support. +#if !defined(FC_OS_WIN32) || (BOOST_VERSION < 107600) + std::string filename = s.str(); +#else + std::wstring filename = fi.toStdWString(); +#endif std::unique_ptr flock; try { - flock = std::make_unique(s.str().c_str()); + flock = std::make_unique(filename.c_str()); flock->lock(); } catch (const boost::interprocess::interprocess_exception& e) { diff --git a/src/Gui/DocumentRecovery.cpp b/src/Gui/DocumentRecovery.cpp index 9b3186733a..ac30809f5b 100644 --- a/src/Gui/DocumentRecovery.cpp +++ b/src/Gui/DocumentRecovery.cpp @@ -658,7 +658,12 @@ void DocumentRecoveryHandler::checkForPreviousCrashes(const std::functionabsoluteFilePath(); - boost::interprocess::file_lock flock((const char*)fn.toLocal8Bit()); + +#if !defined(FC_OS_WIN32) || (BOOST_VERSION < 107600) + boost::interprocess::file_lock flock(fn.toUtf8()); +#else + boost::interprocess::file_lock flock(fn.toStdWString().c_str()); +#endif if (flock.try_lock()) { // OK, this file is a leftover from a previous crash QString crashed_pid = bn.mid(exeName.length()+1);