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:
parent
08c7707782
commit
c684701b7f
3 changed files with 23 additions and 2 deletions
|
@ -292,6 +292,9 @@ void initApp(int& argc, char** argv, bool doInitQSettings)
|
||||||
|
|
||||||
void shutdownQtApp()
|
void shutdownQtApp()
|
||||||
{
|
{
|
||||||
|
// restore default message handler, otherwise Qt logging on
|
||||||
|
// shutdown crashes once sglog is killed
|
||||||
|
qInstallMessageHandler(nullptr);
|
||||||
static_qApp.reset();
|
static_qApp.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,6 +337,10 @@ void restartTheApp()
|
||||||
QProcess proc;
|
QProcess proc;
|
||||||
QStringList args;
|
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)
|
#if defined(Q_OS_MAC)
|
||||||
QDir dir(qApp->applicationDirPath()); // returns the 'MacOS' dir
|
QDir dir(qApp->applicationDirPath()); // returns the 'MacOS' dir
|
||||||
dir.cdUp(); // up to 'contents' dir
|
dir.cdUp(); // up to 'contents' dir
|
||||||
|
|
|
@ -408,6 +408,10 @@ static SGPath platformDefaultDataPath()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(SG_WINDOWS)
|
||||||
|
static HANDLE static_fgHomeWriteMutex = nullptr;
|
||||||
|
#endif
|
||||||
|
|
||||||
bool fgInitHome()
|
bool fgInitHome()
|
||||||
{
|
{
|
||||||
SGPath dataPath = SGPath::fromEnv("FG_HOME", platformDefaultDataPath());
|
SGPath dataPath = SGPath::fromEnv("FG_HOME", platformDefaultDataPath());
|
||||||
|
@ -438,8 +442,8 @@ bool fgInitHome()
|
||||||
// unreliable and causes false-positives. Instead, use a named
|
// unreliable and causes false-positives. Instead, use a named
|
||||||
// mutex.
|
// mutex.
|
||||||
|
|
||||||
HANDLE hMutex = CreateMutexA(nullptr, FALSE, "org.flightgear.fgfs.primary");
|
static_fgHomeWriteMutex = CreateMutexA(nullptr, FALSE, "org.flightgear.fgfs.primary");
|
||||||
if (hMutex == nullptr) {
|
if (static_fgHomeWriteMutex == nullptr) {
|
||||||
printf("CreateMutex error: %d\n", GetLastError());
|
printf("CreateMutex error: %d\n", GetLastError());
|
||||||
SG_LOG(SG_GENERAL, SG_POPUP, "Failed to create mutex for multi-app protection");
|
SG_LOG(SG_GENERAL, SG_POPUP, "Failed to create mutex for multi-app protection");
|
||||||
return false;
|
return false;
|
||||||
|
@ -488,6 +492,15 @@ bool fgInitHome()
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fgShutdownHome()
|
||||||
|
{
|
||||||
|
#if defined(SG_WINDOWS)
|
||||||
|
if (static_fgHomeWriteMutex) {
|
||||||
|
CloseHandle(static_fgHomeWriteMutex);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static void createBaseStorageDirForAddons(const SGPath& exportDir)
|
static void createBaseStorageDirForAddons(const SGPath& exportDir)
|
||||||
{
|
{
|
||||||
SGPath addonStorageBasePath = exportDir / "Addons";
|
SGPath addonStorageBasePath = exportDir / "Addons";
|
||||||
|
|
|
@ -36,6 +36,7 @@ class SGPath;
|
||||||
std::string fgBasePackageVersion(const SGPath& path);
|
std::string fgBasePackageVersion(const SGPath& path);
|
||||||
|
|
||||||
bool fgInitHome();
|
bool fgInitHome();
|
||||||
|
void fgShutdownHome();
|
||||||
|
|
||||||
// Read in configuration (file and command line)
|
// Read in configuration (file and command line)
|
||||||
int fgInitConfig ( int argc, char **argv, bool reinit );
|
int fgInitConfig ( int argc, char **argv, bool reinit );
|
||||||
|
|
Loading…
Reference in a new issue