]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/main.cpp
contrib: fix bobToolz loading
[xonotic/netradiant.git] / radiant / main.cpp
index 172c3fa92db5532fc1062c61b36221cfe1bc04b7..20bea80fde8533800f6a74ef0f68226c95c745d6 100644 (file)
@@ -64,8 +64,6 @@
 #include "main.h"
 #include "globaldefs.h"
 
-#include "version.h"
-
 #include "debugging/debugging.h"
 
 #include "iundo.h"
@@ -409,7 +407,7 @@ void create_global_pid(){
                // set without saving, the class is not in a coherent state yet
                // just do the value change and call to start logging, CGamesDialog will pickup when relevant
                g_GamesDialog.m_bForceLogConsole = true;
-               Sys_LogFile( true );
+               Sys_EnableLogFile( true );
        }
 
        // create a primary .pid for global init run
@@ -468,7 +466,7 @@ void create_local_pid(){
 
                // force console logging on! (will go in prefs too)
                g_GamesDialog.m_bForceLogConsole = true;
-               Sys_LogFile( true );
+               Sys_EnableLogFile( true );
        }
        else
        {
@@ -504,7 +502,48 @@ void user_shortcuts_save(){
        SaveCommandMap( path.c_str() );
 }
 
+void add_local_rc_files(){
+#define GARUX_DISABLE_GTKTHEME
+#ifndef GARUX_DISABLE_GTKTHEME
+/* FIXME: HACK: not GTK3 compatible
+ https://developer.gnome.org/gtk2/stable/gtk2-Resource-Files.html#gtk-rc-add-default-file
+ https://developer.gnome.org/gtk3/stable/gtk3-Resource-Files.html#gtk-rc-add-default-file
+ > gtk_rc_add_default_file has been deprecated since version 3.0 and should not be used in newly-written code.
+ > Use GtkStyleContext with a custom GtkStyleProvider instead
+*/
+
+       {
+               StringOutputStream path( 512 );
+               path << AppPath_get() << ".gtkrc-2.0.radiant";
+               gtk_rc_add_default_file( path.c_str() );
+       }
+#ifdef WIN32
+       {
+               StringOutputStream path( 512 );
+               path << AppPath_get() << ".gtkrc-2.0.win";
+               gtk_rc_add_default_file( path.c_str() );
+       }
+#endif
+#endif // GARUX_DISABLE_GTKTHEME
+}
+
+/* HACK: If ui::main is not called yet,
+gtk_main_quit will not quit, so tell main
+to not call ui::main. This happens when a
+map is loaded from command line and require
+a restart because of wrong format.
+Delete this when the code to not have to
+restart to load another format is merged. */
+bool g_dontStart = false;
+
 int main( int argc, char* argv[] ){
+#if GTK_TARGET == 3
+       // HACK: force legacy GL backend as we don't support GL3 yet
+       setenv("GDK_GL", "LEGACY", 0);
+#if GDEF_OS_LINUX || GDEF_OS_BSD
+       setenv("GDK_BACKEND", "x11", 0);
+#endif
+#endif // GTK_TARGET == 3
        crt_init();
 
        streams_init();
@@ -515,10 +554,22 @@ int main( int argc, char* argv[] ){
        if ( lib != 0 ) {
                void ( WINAPI *qDwmEnableComposition )( bool bEnable ) = ( void (WINAPI *) ( bool bEnable ) )GetProcAddress( lib, "DwmEnableComposition" );
                if ( qDwmEnableComposition ) {
-                       qDwmEnableComposition( FALSE );
+                       bool Aero = false;
+                       for ( int i = 1; i < argc; ++i ){
+                               if ( !stricmp( argv[i], "-aero" ) ){
+                                       Aero = true;
+                                       qDwmEnableComposition( TRUE );
+                                       break;
+                               }
+                       }
+                       // disable Aero
+                       if ( !Aero ){
+                               qDwmEnableComposition( FALSE );
+                       }
                }
                FreeLibrary( lib );
        }
+       _setmaxstdio(2048);
 #endif
 
        const char* mapname = NULL;
@@ -535,11 +586,11 @@ int main( int argc, char* argv[] ){
        }
 
        // Gtk already removed parsed `--options`
-       if ( argc == 2 ) {
-               if ( strlen( argv[ 1 ] ) > 1 ) {
-                       if ( g_str_has_suffix( argv[ 1 ], ".map" ) ) {
-                               mapname = argv[ 1 ];
+       if (argc == 2) {
+               if ( strlen( argv[1] ) > 1 ) {
+                                       mapname = argv[1];
 
+                       if ( g_str_has_suffix( mapname, ".map" ) ) {
                                if ( !g_path_is_absolute( mapname ) ) {
                                        mapname = g_build_filename( g_get_current_dir(), mapname, NULL );
                                }
@@ -551,10 +602,11 @@ int main( int argc, char* argv[] ){
                        }
                        else {
                                g_print( "bad file name, will not load: %s\n", mapname );
+                               mapname = NULL;
                        }
                }
        }
-       else if ( argc > 2 ) {
+       else if (argc > 2) {
                g_print ( "%s\n", "too many arguments" );
                return -1;
        }
@@ -577,6 +629,8 @@ int main( int argc, char* argv[] ){
 
        paths_init();
 
+       add_local_rc_files();
+
        show_splash();
 
        create_global_pid();
@@ -597,7 +651,7 @@ int main( int argc, char* argv[] ){
        // we may have the console turned on and want to keep it that way
        // so we use a latching system
        if ( g_GamesDialog.m_bForceLogConsole ) {
-               Sys_LogFile( true );
+               Sys_EnableLogFile( true );
                g_Console_enableLogging = true;
                g_GamesDialog.m_bForceLogConsole = false;
        }
@@ -612,7 +666,10 @@ int main( int argc, char* argv[] ){
 
        hide_splash();
 
-       if ( mapname != NULL ) {
+       if( openCmdMap && *openCmdMap ){
+               Map_LoadFile( openCmdMap );
+       }
+       else if ( mapname != NULL ) {
                Map_LoadFile( mapname );
        }
        else if ( g_bLoadLastMap && !g_strLastMap.empty() ) {
@@ -630,7 +687,17 @@ int main( int argc, char* argv[] ){
 
        remove_local_pid();
 
+       /* HACK: If ui::main is not called yet,
+       gtk_main_quit will not quit, so tell main
+       to not call ui::main. This happens when a
+       map is loaded from command line and require
+       a restart because of wrong format.
+       Delete this when the code to not have to
+       restart to load another format is merged. */
+       if ( !g_dontStart )
+       {
        ui::main();
+       }
 
        // avoid saving prefs when the app is minimized
        if ( g_pParentWnd->IsSleeping() ) {
@@ -651,7 +718,7 @@ int main( int argc, char* argv[] ){
        Radiant_Shutdown();
 
        // close the log file if any
-       Sys_LogFile( false );
+       Sys_EnableLogFile( false );
 
        return EXIT_SUCCESS;
 }