From 4ac7df699d15d26908a256895c5bc7939c210be5 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 6 Jul 2021 20:59:15 +0200 Subject: [PATCH] Windows: limit to single-instance only This may fix corrupt config files, which may happen when multiple instances write the same file. --- gtk2_ardour/main.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gtk2_ardour/main.cc b/gtk2_ardour/main.cc index ab85302782..37828482e7 100644 --- a/gtk2_ardour/main.cc +++ b/gtk2_ardour/main.cc @@ -70,6 +70,7 @@ #include "pbd/i18n.h" #ifdef PLATFORM_WINDOWS +#include // CreateMutex #include // Needed for '_fmode' #include // console #endif @@ -337,6 +338,17 @@ int main (int argc, char *argv[]) << endl; } +#ifdef PLATFORM_WINDOWS + CreateMutexA (0, 1, string_compose ("%1%2", PROGRAM_NAME, PROGRAM_VERSION).c_str ()); + if (GetLastError() == ERROR_ALREADY_EXISTS) { + Gtk::Main main (argc, argv); + Gtk::MessageDialog msg (string_compose (_("%1 is already running."), PROGRAM_NAME), + false, Gtk::MESSAGE_ERROR , Gtk::BUTTONS_OK, true); + msg.run (); + exit (EXIT_FAILURE); + } +#endif + #ifdef HAVE_DRMINGW /* prevent missing libs popups */ UINT prev_error_mode = SetErrorMode (SEM_FAILCRITICALERRORS);