]> de.git.xonotic.org Git - xonotic/netradiant.git/commitdiff
radiant: code to make radiant able to restart itself
authorThomas Debesse <dev@illwieckz.net>
Sun, 14 Jul 2019 00:53:50 +0000 (02:53 +0200)
committerThomas Debesse <dev@illwieckz.net>
Mon, 22 Jul 2019 02:09:24 +0000 (04:09 +0200)
- save preferences
- check for map being modified (this asks user for saving if not yet saved)
- check for a map being currently edited
- start a new instance, with the current map as parameter if exists
- quit current instance if new instance started correctly

radiant/mainframe.cpp
radiant/mainframe.h
radiant/preferences.cpp

index d3e869000efabaea592091d880bedcc05708add4..663ca30374b3ef35e8144f0b7b02890afaa0ee6c 100644 (file)
 #include "referencecache.h"
 #include "texwindow.h"
 
+#if GDEF_OS_WINDOWS
+#include <process.h>
+#else
+#include <spawn.h>
+#endif
+
 #ifdef WORKAROUND_WINDOWS_GTK2_GLWIDGET
 /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
 #define WORKAROUND_GOBJECT_SET_GLWIDGET(window, widget) g_object_set_data( G_OBJECT( window ), "glwidget", G_OBJECT( widget ) )
@@ -3616,3 +3622,44 @@ void GLWindow_Construct(){
 
 void GLWindow_Destroy(){
 }
+
+void Radiant_Restart(){
+       // preferences are expected to be already saved in any way
+       // this is just to be sure and be future proof
+       Preferences_Save();
+
+       // this asks user for saving if map is modified
+       // user can chose to not save, it's ok
+       ConfirmModified( "Restart " RADIANT_NAME );
+
+       int status;
+
+       char *argv[ 3 ];
+       char exe_file[ 256 ];
+       char map_file[ 256 ];
+       bool with_map = false;
+
+       strncpy( exe_file, g_strAppFilePath.c_str(), 256 );
+
+       if ( !Map_Unnamed( g_map ) ) {
+               strncpy( map_file, Map_Name( g_map ), 256 );
+               with_map = true;
+       }
+
+       argv[ 0 ] = exe_file;
+       argv[ 1 ] = with_map ? map_file : NULL;
+       argv[ 2 ] = NULL;
+
+#if GDEF_OS_WINDOWS
+       status = !_spawnvpe( P_NOWAIT, exe_file, argv, environ );
+#else
+       pid_t pid;
+
+       status = posix_spawn( &pid, exe_file, NULL, NULL, argv, environ );
+#endif
+
+       // quit if radiant successfully started
+       if ( status == 0 ) {
+               gtk_main_quit();
+       }
+}
index f101c25eabc34f4a740905d56f9902f66a876428..ca0c4c97e95bd683826d5b60721e74790f88a156 100644 (file)
@@ -271,6 +271,8 @@ void Radiant_detachHomePathsObserver( ModuleObserver& observer );
 void MainFrame_Construct();
 void MainFrame_Destroy();
 
+extern char **environ;
+void Radiant_Restart();
 
 extern float ( *GridStatus_getGridSize )();
 extern int ( *GridStatus_getRotateIncrement )();
index 14a39f71c3e1293bdf4d276bc5eb085109390401..e31bc0487f063b6a33a97f380a53d539f56b3b52 100644 (file)
@@ -909,10 +909,12 @@ void PreferencesDialog_showDialog(){
                if ( !g_restart_required.empty() ) {
                        StringOutputStream message( 256 );
                        message << "Preference changes require a restart:\n";
+
                        for ( std::vector<const char*>::iterator i = g_restart_required.begin(); i != g_restart_required.end(); ++i )
                        {
                                message << ( *i ) << '\n';
                        }
+
                        ui::alert( MainFrame_getWindow(), message.c_str() );
                        g_restart_required.clear();
                }