Exemple #1
0
/**
 * gva_mame_get_snapshot_directory:
 * @error: return location for a #GError, or %NULL
 *
 * Returns the value of the "snapshot_directory" configuration key.  The
 * function caches the result to avoid excessive MAME invocations.  If an
 * error occurs, the function returns %NULL and sets @error.
 *
 * Returns: the directory containing MAME snapshot files, or %NULL
 **/
const gchar *
gva_mame_get_snapshot_directory (GError **error)
{
        static gchar *directory = NULL;

        if (G_UNLIKELY (directory == NULL))
        {
                const gchar *config_key = "snapshot_directory";
                directory = gva_mame_get_config_value (config_key, error);
        }

        return directory;
}
Exemple #2
0
/**
 * gva_mame_has_config_value:
 * @config_key: a configuration key
 *
 * Returns %TRUE if the MAME configuration has a configuration value for
 * @config_key.  The function does not report errors that occur in the
 * course of spawning MAME, so false negatives are possible.
 *
 * Returns: %TRUE if a value for @config_key exists, %FALSE if no such
 *          value exists or if an error occurred
 **/
gboolean
gva_mame_has_config_value (const gchar *config_key)
{
        gchar *config_value;
        gboolean result;
        GError *error = NULL;

        config_value = gva_mame_get_config_value (config_key, &error);
        result = (config_value != NULL && *config_value != '\0');
        g_free (config_value);

        if (error != NULL)
        {
                /* Suppress warnings about unknown configuration
                 * keys, since that's what we're testing for. */
                if (error->code == GVA_ERROR_MAME)
                        g_clear_error (&error);
                else
                        gva_error_handle (&error);
        }

        return result;
}
Exemple #3
0
gint
main (gint argc, gchar **argv)
{
        GtkApplication *application;
        GApplicationFlags flags;
        gchar *path;
        GError *error = NULL;

        bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
        textdomain (GETTEXT_PACKAGE);

        gtk_init_with_args (
                &argc, &argv, NULL, entries, GETTEXT_PACKAGE, &error);
        if (error != NULL)
                g_error ("%s", error->message);

        /* This installs handlers for our custom debug log levels. */
        gva_get_debug_flags ();

        /* Change the working directory to that of the MAME executable.
         * Why?  Because SDLMAME's default configuration uses relative
         * search paths such as "rompath = roms".  The paths are relative
         * to the directory containing the MAME executable, so we must run
         * from that directory in order for SDLMAME's default configuration
         * to work.  Annoying, but a common problem for users. */
        path = g_path_get_dirname (MAME_PROGRAM);
        g_chdir (path);
        g_free (path);

        if (opt_inspect != NULL)
        {
                gchar *value;

                value = gva_mame_get_config_value (opt_inspect, &error);
                if (value != NULL)
                {
                        g_print ("%s\n", value);
                        g_free (value);
                }
                else
                {
                        g_printerr ("%s\n", error->message);
                        g_clear_error (&error);
                }
                exit (EXIT_SUCCESS);
        }

        if (opt_version)
        {
                g_print ("%s\n", PACKAGE_STRING);
                exit (EXIT_SUCCESS);
        }

        if (opt_which_emulator)
        {
                g_print ("%s\n", MAME_PROGRAM);
                exit (EXIT_SUCCESS);
        }

        /* Register the application with the session bus. */
        flags = G_APPLICATION_FLAGS_NONE;
        application = gtk_application_new (APPLICATION_ID, flags);
        g_application_register (G_APPLICATION (application), NULL, &error);

        if (error != NULL)
                g_error ("%s", error->message);

        /* If another instance is running, exit now. */
        if (g_application_get_is_remote (G_APPLICATION (application)))
        {
                gint exit_status;

                if (opt_build_database)
                {
                        g_printerr (
                                "Cannot build database: "
                                PACKAGE_NAME " is already running\n");
                        exit_status = EXIT_FAILURE;
                }
                else
                {
                        g_application_activate (G_APPLICATION (application));
                        exit_status = EXIT_SUCCESS;
                }

                g_object_unref (application);

                exit (exit_status);
        }
        else
        {
                GtkWindow *window;

                window = GTK_WINDOW (GVA_WIDGET_MAIN_WINDOW);
                gtk_application_add_window (application, window);
        }

        gtk_window_set_default_icon_name (PACKAGE);

        if (!gva_db_init (&error))
                g_error ("%s", error->message);

        gva_main_init ();
        gva_play_back_init ();
        gva_preferences_init ();
        gva_properties_init ();
        gva_ui_init ();

        gva_categories_init (&error);
        gva_error_handle (&error);

        gva_history_init (&error);
        gva_error_handle (&error);

        gva_nplayers_init (&error);
        gva_error_handle (&error);

        g_idle_add (idle_start, NULL);

        g_idle_add (tweak_css, NULL);

        gtk_main ();

        g_object_unref (application);

        return EXIT_SUCCESS;
}