mirror of
https://github.com/TES3MP/TES3MP.git
synced 2025-09-29 16:11:37 -04: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:
parent
8d0cca6cfc
commit
ab693f1f64
@ -72,8 +72,10 @@ CS::Editor::Editor (OgreInit::OgreInit& ogreInit)
|
|||||||
|
|
||||||
CS::Editor::~Editor ()
|
CS::Editor::~Editor ()
|
||||||
{
|
{
|
||||||
|
mPidFile.close();
|
||||||
|
|
||||||
if(mServer && boost::filesystem::exists(mPid))
|
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
|
// cleanup global resources used by OEngine
|
||||||
delete OEngine::Physic::BulletShapeManager::getSingletonPtr();
|
delete OEngine::Physic::BulletShapeManager::getSingletonPtr();
|
||||||
@ -246,7 +248,7 @@ bool CS::Editor::makeIPCServer()
|
|||||||
mPid /= "opencs.pid";
|
mPid /= "opencs.pid";
|
||||||
bool pidExists = boost::filesystem::exists(mPid);
|
bool pidExists = boost::filesystem::exists(mPid);
|
||||||
|
|
||||||
boost::filesystem::ofstream tempFile(mPid);
|
mPidFile.open(mPid);
|
||||||
|
|
||||||
mLock = boost::interprocess::file_lock(mPid.string().c_str());
|
mLock = boost::interprocess::file_lock(mPid.string().c_str());
|
||||||
if(!mLock.try_lock())
|
if(!mLock.try_lock())
|
||||||
@ -256,11 +258,10 @@ bool CS::Editor::makeIPCServer()
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
tempFile << GetCurrentProcessId() << std::endl;
|
mPidFile << GetCurrentProcessId() << std::endl;
|
||||||
#else
|
#else
|
||||||
tempFile << getpid() << std::endl;
|
mPidFile << getpid() << std::endl;
|
||||||
#endif
|
#endif
|
||||||
tempFile.close();
|
|
||||||
|
|
||||||
mServer = new QLocalServer(this);
|
mServer = new QLocalServer(this);
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <boost/interprocess/sync/file_lock.hpp>
|
#include <boost/interprocess/sync/file_lock.hpp>
|
||||||
|
#include <boost/filesystem/fstream.hpp>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
@ -56,6 +57,7 @@ namespace CS
|
|||||||
boost::filesystem::path mResources;
|
boost::filesystem::path mResources;
|
||||||
boost::filesystem::path mPid;
|
boost::filesystem::path mPid;
|
||||||
boost::interprocess::file_lock mLock;
|
boost::interprocess::file_lock mLock;
|
||||||
|
boost::filesystem::ofstream mPidFile;
|
||||||
bool mFsStrict;
|
bool mFsStrict;
|
||||||
|
|
||||||
void setupDataFiles (const Files::PathContainer& dataDirs);
|
void setupDataFiles (const Files::PathContainer& dataDirs);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user