From: Thomas Debesse Date: Sun, 14 Jul 2019 00:53:50 +0000 (+0200) Subject: radiant: code to make radiant able to restart itself X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f1fdd4e7e3dbb6d7d236912e4a26b3df15c0bd17;p=xonotic%2Fnetradiant.git radiant: code to make radiant able to restart itself - 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 --- diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index d3e86900..663ca303 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -101,6 +101,12 @@ #include "referencecache.h" #include "texwindow.h" +#if GDEF_OS_WINDOWS +#include +#else +#include +#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(); + } +} diff --git a/radiant/mainframe.h b/radiant/mainframe.h index f101c25e..ca0c4c97 100644 --- a/radiant/mainframe.h +++ b/radiant/mainframe.h @@ -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 )(); diff --git a/radiant/preferences.cpp b/radiant/preferences.cpp index 14a39f71..e31bc048 100644 --- a/radiant/preferences.cpp +++ b/radiant/preferences.cpp @@ -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::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(); }