1
0
Fork 0

Fix 'restart the app' functionality on Windows

The read-only lock in fghome was tripping things up. Explicitly
release the lock in the restart-the-app situation.
This commit is contained in:
James Turner 2018-07-02 23:13:36 +01:00
parent 08c7707782
commit c684701b7f
3 changed files with 23 additions and 2 deletions

View file

@ -292,6 +292,9 @@ void initApp(int& argc, char** argv, bool doInitQSettings)
void shutdownQtApp()
{
// restore default message handler, otherwise Qt logging on
// shutdown crashes once sglog is killed
qInstallMessageHandler(nullptr);
static_qApp.reset();
}
@ -334,6 +337,10 @@ void restartTheApp()
QProcess proc;
QStringList args;
// ensure we release whatever mutex/lock file we have in home,
// so the new instance runs in writeable mode
fgShutdownHome();
#if defined(Q_OS_MAC)
QDir dir(qApp->applicationDirPath()); // returns the 'MacOS' dir
dir.cdUp(); // up to 'contents' dir

View file

@ -408,6 +408,10 @@ static SGPath platformDefaultDataPath()
}
#endif
#if defined(SG_WINDOWS)
static HANDLE static_fgHomeWriteMutex = nullptr;
#endif
bool fgInitHome()
{
SGPath dataPath = SGPath::fromEnv("FG_HOME", platformDefaultDataPath());
@ -438,8 +442,8 @@ bool fgInitHome()
// unreliable and causes false-positives. Instead, use a named
// mutex.
HANDLE hMutex = CreateMutexA(nullptr, FALSE, "org.flightgear.fgfs.primary");
if (hMutex == nullptr) {
static_fgHomeWriteMutex = CreateMutexA(nullptr, FALSE, "org.flightgear.fgfs.primary");
if (static_fgHomeWriteMutex == nullptr) {
printf("CreateMutex error: %d\n", GetLastError());
SG_LOG(SG_GENERAL, SG_POPUP, "Failed to create mutex for multi-app protection");
return false;
@ -488,6 +492,15 @@ bool fgInitHome()
return result;
}
void fgShutdownHome()
{
#if defined(SG_WINDOWS)
if (static_fgHomeWriteMutex) {
CloseHandle(static_fgHomeWriteMutex);
}
#endif
}
static void createBaseStorageDirForAddons(const SGPath& exportDir)
{
SGPath addonStorageBasePath = exportDir / "Addons";

View file

@ -36,6 +36,7 @@ class SGPath;
std::string fgBasePackageVersion(const SGPath& path);
bool fgInitHome();
void fgShutdownHome();
// Read in configuration (file and command line)
int fgInitConfig ( int argc, char **argv, bool reinit );