Gui: boost 1.76 provides an overloaded version of file_lock that accepts a wchar_t string

This commit is contained in:
wmayer
2021-12-19 21:24:17 +01:00
parent 43f4fffa61
commit 060f3bf8f3
2 changed files with 13 additions and 7 deletions

View File

@@ -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<boost::interprocess::file_lock> flock;
try {
flock = std::make_unique<boost::interprocess::file_lock>(s.str().c_str());
flock = std::make_unique<boost::interprocess::file_lock>(filename.c_str());
flock->lock();
}
catch (const boost::interprocess::interprocess_exception& e) {

View File

@@ -658,7 +658,12 @@ void DocumentRecoveryHandler::checkForPreviousCrashes(const std::function<void(Q
QString pid = QString::number(QCoreApplication::applicationPid());
if (bn.startsWith(exeName) && bn.indexOf(pid) < 0) {
QString fn = it->absoluteFilePath();
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);