]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/main.cpp
Disable wayland backend on Linux and BSD
[xonotic/netradiant.git] / radiant / main.cpp
index cd328b3734b1666c405f2c1f13c6ea645402ad77..3df10170085eddb32f17e53830fa55b3495ad5dc 100644 (file)
@@ -64,8 +64,6 @@
 #include "main.h"
 #include "globaldefs.h"
 
-#include "version.h"
-
 #include "debugging/debugging.h"
 
 #include "iundo.h"
@@ -304,12 +302,12 @@ bool handleMessage(){
                ScopedLock lock( m_lock );
         if (GDEF_DEBUG) {
             m_buffer << "Break into the debugger?\n";
-            bool handled = ui::alert(ui::root, m_buffer.c_str(), "Radiant - Runtime Error", ui::alert_type::YESNO, ui::alert_icon::Error) == ui::alert_response::NO;
+            bool handled = ui::alert(ui::root, m_buffer.c_str(), RADIANT_NAME " - Runtime Error", ui::alert_type::YESNO, ui::alert_icon::Error) == ui::alert_response::NO;
             m_buffer.clear();
             return handled;
         } else {
             m_buffer << "Please report this error to the developers\n";
-            ui::alert(ui::root, m_buffer.c_str(), "Radiant - Runtime Error", ui::alert_type::OK, ui::alert_icon::Error);
+            ui::alert(ui::root, m_buffer.c_str(), RADIANT_NAME " - Runtime Error", ui::alert_type::OK, ui::alert_icon::Error);
             m_buffer.clear();
         }
        }
@@ -329,7 +327,10 @@ void paths_init(){
 
        Q_mkdir( g_strSettingsPath.c_str() );
 
+       g_strAppFilePath = environment_get_app_filepath();
        g_strAppPath = environment_get_app_path();
+       g_strLibPath = environment_get_lib_path();
+       g_strDataPath = environment_get_data_path();
 
        // radiant is installed in the parent dir of "tools/"
        // NOTE: this is not very easy for debugging
@@ -337,12 +338,12 @@ void paths_init(){
        // (for now I had to create symlinks)
        {
                StringOutputStream path( 256 );
-               path << g_strAppPath.c_str() << "bitmaps/";
+               path << g_strDataPath.c_str() << "bitmaps/";
                BitmapsPath_set( path.c_str() );
        }
 
        // we will set this right after the game selection is done
-       g_strGameToolsPath = g_strAppPath;
+       g_strGameToolsPath = g_strDataPath;
 }
 
 bool check_version_file( const char* filename, const char* version ){
@@ -362,39 +363,6 @@ bool check_version_file( const char* filename, const char* version ){
        return false;
 }
 
-bool check_version(){
-       // a safe check to avoid people running broken installations
-       // (otherwise, they run it, crash it, and blame us for not forcing them hard enough to pay attention while installing)
-       // make something idiot proof and someone will make better idiots, this may be overkill
-       // let's leave it disabled in debug mode in any case
-       // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=431
-    if (GDEF_DEBUG) {
-        return true;
-    }
-    // locate and open RADIANT_MAJOR and RADIANT_MINOR
-    bool bVerIsGood = true;
-    {
-        StringOutputStream ver_file_name(256);
-        ver_file_name << AppPath_get() << "RADIANT_MAJOR";
-        bVerIsGood = check_version_file(ver_file_name.c_str(), RADIANT_MAJOR_VERSION);
-    }
-    {
-        StringOutputStream ver_file_name(256);
-        ver_file_name << AppPath_get() << "RADIANT_MINOR";
-        bVerIsGood = check_version_file(ver_file_name.c_str(), RADIANT_MINOR_VERSION);
-    }
-
-    if (!bVerIsGood) {
-        StringOutputStream msg(256);
-        msg
-                << "This editor binary (" RADIANT_VERSION ") doesn't match what the latest setup has configured in this directory\n"
-                        "Make sure you run the right/latest editor binary you installed\n"
-                << AppPath_get();
-        ui::alert(ui::root, msg.c_str(), "Radiant", ui::alert_type::OK, ui::alert_icon::Default);
-    }
-    return bVerIsGood;
-}
-
 void create_global_pid(){
        /*!
           the global prefs loading / game selection dialog might fail for any reason we don't know about
@@ -415,31 +383,31 @@ void create_global_pid(){
                if ( remove( g_pidFile.c_str() ) == -1 ) {
                        StringOutputStream msg( 256 );
                        msg << "WARNING: Could not delete " << g_pidFile.c_str();
-                       ui::alert( ui::root, msg.c_str(), "Radiant", ui::alert_type::OK, ui::alert_icon::Error );
+                       ui::alert( ui::root, msg.c_str(), RADIANT_NAME, ui::alert_type::OK, ui::alert_icon::Error );
                }
 
                // in debug, never prompt to clean registry, turn console logging auto after a failed start
                if (!GDEF_DEBUG) {
                        StringOutputStream msg(256);
-                       msg << "Radiant failed to start properly the last time it was run.\n"
+                       msg << RADIANT_NAME " failed to start properly the last time it was run.\n"
                                        "The failure may be related to current global preferences.\n"
                                        "Do you want to reset global preferences to defaults?";
 
-                       if (ui::alert(ui::root, msg.c_str(), "Radiant - Startup Failure", ui::alert_type::YESNO, ui::alert_icon::Question) == ui::alert_response::YES) {
+                       if (ui::alert(ui::root, msg.c_str(), RADIANT_NAME " - Startup Failure", ui::alert_type::YESNO, ui::alert_icon::Question) == ui::alert_response::YES) {
                                g_GamesDialog.Reset();
                        }
 
                        msg.clear();
                        msg << "Logging console output to " << SettingsPath_get()
-                               << "radiant.log\nRefer to the log if Radiant fails to start again.";
+                               << "radiant.log\nRefer to the log if " RADIANT_NAME " fails to start again.";
 
-                       ui::alert(ui::root, msg.c_str(), "Radiant - Console Log", ui::alert_type::OK);
+                       ui::alert(ui::root, msg.c_str(), RADIANT_NAME " - Console Log", ui::alert_type::OK);
                }
 
                // 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
@@ -457,7 +425,7 @@ void remove_global_pid(){
        if ( remove( g_pidFile.c_str() ) == -1 ) {
                StringOutputStream msg( 256 );
                msg << "WARNING: Could not delete " << g_pidFile.c_str();
-               ui::alert( ui::root, msg.c_str(), "Radiant", ui::alert_type::OK, ui::alert_icon::Error );
+               ui::alert( ui::root, msg.c_str(), RADIANT_NAME, ui::alert_type::OK, ui::alert_icon::Error );
        }
 }
 
@@ -475,30 +443,30 @@ void create_local_pid(){
                if ( remove( g_pidGameFile.c_str() ) == -1 ) {
                        StringOutputStream msg;
                        msg << "WARNING: Could not delete " << g_pidGameFile.c_str();
-                       ui::alert( ui::root, msg.c_str(), "Radiant", ui::alert_type::OK, ui::alert_icon::Error );
+                       ui::alert( ui::root, msg.c_str(), RADIANT_NAME, ui::alert_type::OK, ui::alert_icon::Error );
                }
 
                // in debug, never prompt to clean registry, turn console logging auto after a failed start
                if (!GDEF_DEBUG) {
                        StringOutputStream msg;
-                       msg << "Radiant failed to start properly the last time it was run.\n"
+                       msg << RADIANT_NAME " failed to start properly the last time it was run.\n"
                                        "The failure may be caused by current preferences.\n"
                                        "Do you want to reset all preferences to defaults?";
 
-                       if (ui::alert(ui::root, msg.c_str(), "Radiant - Startup Failure", ui::alert_type::YESNO, ui::alert_icon::Question) == ui::alert_response::YES) {
+                       if (ui::alert(ui::root, msg.c_str(), RADIANT_NAME " - Startup Failure", ui::alert_type::YESNO, ui::alert_icon::Question) == ui::alert_response::YES) {
                                Preferences_Reset();
                        }
 
                        msg.clear();
                        msg << "Logging console output to " << SettingsPath_get()
-                               << "radiant.log\nRefer to the log if Radiant fails to start again.";
+                               << "radiant.log\nRefer to the log if " RADIANT_NAME " fails to start again.";
 
-                       ui::alert(ui::root, msg.c_str(), "Radiant - Console Log", ui::alert_type::OK);
+                       ui::alert(ui::root, msg.c_str(), RADIANT_NAME " - Console Log", ui::alert_type::OK);
                }
 
                // force console logging on! (will go in prefs too)
                g_GamesDialog.m_bForceLogConsole = true;
-               Sys_LogFile( true );
+               Sys_EnableLogFile( true );
        }
        else
        {
@@ -535,6 +503,13 @@ void user_shortcuts_save(){
 }
 
 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();
@@ -552,29 +527,40 @@ int main( int argc, char* argv[] ){
 #endif
 
        const char* mapname = NULL;
+
+#if GDEF_OS_WINDOWS
+       StringOutputStream mapname_buffer( 256 );
+#endif
+
     char const *error = NULL;
+
        if ( !ui::init( &argc, &argv, "<filename.map>", &error) ) {
                g_print( "%s\n", error );
                return -1;
        }
 
        // Gtk already removed parsed `--options`
-       if (argc == 2) {
-               if ( strlen( argv[1] ) > 1 ) {
-                       if ( g_str_has_suffix( argv[1], ".map" ) ) {
-                               if ( g_path_is_absolute( argv[1] ) ) {
-                                       mapname = argv[1];
-                               }
-                               else {
-                                       mapname = g_build_filename( g_get_current_dir(), argv[1], NULL );
+       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 );
                                }
+
+#if GDEF_OS_WINDOWS
+                               mapname_buffer << PathCleaned( mapname );
+                               mapname = mapname_buffer.c_str();
+#endif
                        }
                        else {
-                               g_print( "bad file name, will not load: %s\n", argv[1] );
+                               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;
        }
@@ -597,10 +583,6 @@ int main( int argc, char* argv[] ){
 
        paths_init();
 
-       if ( !check_version() ) {
-               return EXIT_FAILURE;
-       }
-
        show_splash();
 
        create_global_pid();
@@ -621,7 +603,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;
        }
@@ -675,7 +657,7 @@ int main( int argc, char* argv[] ){
        Radiant_Shutdown();
 
        // close the log file if any
-       Sys_LogFile( false );
+       Sys_EnableLogFile( false );
 
        return EXIT_SUCCESS;
 }