diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2019-10-08 23:24:53 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-08 23:24:53 -0400 |
| commit | c01e80a651f5e25441330ad20253bb47ad0f516c (patch) | |
| tree | c801c21b793f2fd4d9c141b7c0efe9836912a99a /src/shared/util.cpp | |
| parent | 94b40b328b7e455ad4799b98c2b00cd5d96f86f3 (diff) | |
| parent | 3d97b0efd04326c0252411fc6639c4c6df2f2160 (diff) | |
Merge pull request #858 from isanae/proper-exit
Proper exit procedure
Diffstat (limited to 'src/shared/util.cpp')
| -rw-r--r-- | src/shared/util.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/shared/util.cpp b/src/shared/util.cpp index 07983e12..58f4eb2b 100644 --- a/src/shared/util.cpp +++ b/src/shared/util.cpp @@ -19,6 +19,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include "util.h"
#include "windows_error.h"
+#include "mainwindow.h"
namespace MOShared
{
@@ -244,3 +245,49 @@ MOBase::VersionInfo createVersionInfo() }
} // namespace MOShared
+
+
+static bool g_exiting = false;
+
+MainWindow* findMainWindow()
+{
+ for (auto* tl : qApp->topLevelWidgets()) {
+ if (auto* mw=dynamic_cast<MainWindow*>(tl)) {
+ return mw;
+ }
+ }
+
+ return nullptr;
+}
+
+bool ExitModOrganizer(ExitFlags e)
+{
+ if (g_exiting) {
+ return true;
+ }
+
+ if (!e.testFlag(Exit::Force)) {
+ if (auto* mw=findMainWindow()) {
+ if (!mw->canExit()) {
+ return false;
+ }
+ }
+ }
+
+ g_exiting = true;
+
+ const int code = (e.testFlag(Exit::Restart) ? RestartExitCode : 0);
+ qApp->exit(code);
+
+ return true;
+}
+
+bool ModOrganizerExiting()
+{
+ return g_exiting;
+}
+
+void ResetExitFlag()
+{
+ g_exiting = false;
+}
|
