1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 18:19:55 +00:00

Workaround file lock being lost if the same file is closed elsewhere in the program (see https://svn.boost.org/trac/boost/ticket/3582)

This commit is contained in:
cc9cii 2014-12-05 07:50:03 +11:00
parent 8d0cca6cfc
commit ab693f1f64
2 changed files with 8 additions and 5 deletions

View file

@ -72,8 +72,10 @@ CS::Editor::Editor (OgreInit::OgreInit& ogreInit)
CS::Editor::~Editor ()
{
mPidFile.close();
if(mServer && boost::filesystem::exists(mPid))
remove(mPid.string().c_str()); // ignore error
remove(mPid.string().c_str()); // ignore any error
// cleanup global resources used by OEngine
delete OEngine::Physic::BulletShapeManager::getSingletonPtr();
@ -246,7 +248,7 @@ bool CS::Editor::makeIPCServer()
mPid /= "opencs.pid";
bool pidExists = boost::filesystem::exists(mPid);
boost::filesystem::ofstream tempFile(mPid);
mPidFile.open(mPid);
mLock = boost::interprocess::file_lock(mPid.string().c_str());
if(!mLock.try_lock())
@ -256,11 +258,10 @@ bool CS::Editor::makeIPCServer()
}
#ifdef _WIN32
tempFile << GetCurrentProcessId() << std::endl;
mPidFile << GetCurrentProcessId() << std::endl;
#else
tempFile << getpid() << std::endl;
mPidFile << getpid() << std::endl;
#endif
tempFile.close();
mServer = new QLocalServer(this);

View file

@ -4,6 +4,7 @@
#include <memory>
#include <boost/interprocess/sync/file_lock.hpp>
#include <boost/filesystem/fstream.hpp>
#include <QObject>
#include <QString>
@ -56,6 +57,7 @@ namespace CS
boost::filesystem::path mResources;
boost::filesystem::path mPid;
boost::interprocess::file_lock mLock;
boost::filesystem::ofstream mPidFile;
bool mFsStrict;
void setupDataFiles (const Files::PathContainer& dataDirs);