/* retro-options.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from retro-options.vala, do not modify */

/* This file is part of GNOME Games. License: GPL-3.0+.*/

#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <retro-gtk.h>
#include "gnome-games.h"

#define GAMES_RETRO_OPTIONS_OPTIONS_GROUP "Options"
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define GAMES_TYPE_RETRO_OPTIONS (games_retro_options_get_type ())
#define GAMES_RETRO_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_RETRO_OPTIONS, GamesRetroOptions))
#define GAMES_RETRO_OPTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_RETRO_OPTIONS, GamesRetroOptionsClass))
#define GAMES_IS_RETRO_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_RETRO_OPTIONS))
#define GAMES_IS_RETRO_OPTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_RETRO_OPTIONS))
#define GAMES_RETRO_OPTIONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_RETRO_OPTIONS, GamesRetroOptionsClass))

typedef struct _GamesRetroOptions GamesRetroOptions;
typedef struct _GamesRetroOptionsClass GamesRetroOptionsClass;
typedef struct _GamesRetroOptionsPrivate GamesRetroOptionsPrivate;
enum  {
	GAMES_RETRO_OPTIONS_0_PROPERTY,
	GAMES_RETRO_OPTIONS_NUM_PROPERTIES
};
static GParamSpec* games_retro_options_properties[GAMES_RETRO_OPTIONS_NUM_PROPERTIES];
#define _g_key_file_unref0(var) ((var == NULL) ? NULL : (var = (g_key_file_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _GamesRetroOptions {
	GObject parent_instance;
	GamesRetroOptionsPrivate * priv;
};

struct _GamesRetroOptionsClass {
	GObjectClass parent_class;
};

struct _GamesRetroOptionsPrivate {
	GKeyFile* keyfile;
};

static gint GamesRetroOptions_private_offset;
static gpointer games_retro_options_parent_class = NULL;

VALA_EXTERN GType games_retro_options_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GamesRetroOptions* games_retro_options_new (const gchar* filename,
                                            GError** error);
VALA_EXTERN GamesRetroOptions* games_retro_options_construct (GType object_type,
                                                  const gchar* filename,
                                                  GError** error);
VALA_EXTERN void games_retro_options_apply (GamesRetroOptions* self,
                                RetroCore* core,
                                GError** error);
static void games_retro_options_finalize (GObject * obj);
static GType games_retro_options_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
games_retro_options_get_instance_private (GamesRetroOptions* self)
{
	return G_STRUCT_MEMBER_P (self, GamesRetroOptions_private_offset);
}

GamesRetroOptions*
games_retro_options_construct (GType object_type,
                               const gchar* filename,
                               GError** error)
{
	GamesRetroOptions * self = NULL;
	GKeyFile* _tmp0_;
	GKeyFile* _tmp1_;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (filename != NULL, NULL);
	self = (GamesRetroOptions*) g_object_new (object_type, NULL);
	_tmp0_ = g_key_file_new ();
	_g_key_file_unref0 (self->priv->keyfile);
	self->priv->keyfile = _tmp0_;
	_tmp1_ = self->priv->keyfile;
	g_key_file_load_from_file (_tmp1_, filename, G_KEY_FILE_NONE, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (self);
		return NULL;
	}
	return self;
}

GamesRetroOptions*
games_retro_options_new (const gchar* filename,
                         GError** error)
{
	return games_retro_options_construct (GAMES_TYPE_RETRO_OPTIONS, filename, error);
}

void
games_retro_options_apply (GamesRetroOptions* self,
                           RetroCore* core,
                           GError** error)
{
	gchar** options_keys = NULL;
	GKeyFile* _tmp0_;
	gsize _tmp1_ = 0;
	gchar** _tmp2_;
	gint options_keys_length1;
	gint _options_keys_size_;
	gchar** _tmp3_;
	gint _tmp3__length1;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (core != NULL);
	_tmp0_ = self->priv->keyfile;
	_tmp2_ = g_key_file_get_keys (_tmp0_, GAMES_RETRO_OPTIONS_OPTIONS_GROUP, &_tmp1_, &_inner_error0_);
	options_keys = _tmp2_;
	options_keys_length1 = _tmp1_;
	_options_keys_size_ = options_keys_length1;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
	_tmp3_ = options_keys;
	_tmp3__length1 = options_keys_length1;
	{
		gchar** key_collection = NULL;
		gint key_collection_length1 = 0;
		gint _key_collection_size_ = 0;
		gint key_it = 0;
		key_collection = _tmp3_;
		key_collection_length1 = _tmp3__length1;
		for (key_it = 0; key_it < key_collection_length1; key_it = key_it + 1) {
			gchar* _tmp4_;
			gchar* key = NULL;
			_tmp4_ = g_strdup (key_collection[key_it]);
			key = _tmp4_;
			{
				gchar* val = NULL;
				GKeyFile* _tmp5_;
				const gchar* _tmp6_;
				gchar* _tmp7_;
				const gchar* _tmp8_;
				const gchar* _tmp9_;
				_tmp5_ = self->priv->keyfile;
				_tmp6_ = key;
				_tmp7_ = g_key_file_get_string (_tmp5_, GAMES_RETRO_OPTIONS_OPTIONS_GROUP, _tmp6_, &_inner_error0_);
				val = _tmp7_;
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					g_propagate_error (error, _inner_error0_);
					_g_free0 (key);
					options_keys = (_vala_array_free (options_keys, options_keys_length1, (GDestroyNotify) g_free), NULL);
					return;
				}
				_tmp8_ = key;
				_tmp9_ = val;
				retro_core_override_option_default (core, _tmp8_, _tmp9_);
				_g_free0 (val);
				_g_free0 (key);
			}
		}
	}
	options_keys = (_vala_array_free (options_keys, options_keys_length1, (GDestroyNotify) g_free), NULL);
}

static void
games_retro_options_class_init (GamesRetroOptionsClass * klass,
                                gpointer klass_data)
{
	games_retro_options_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GamesRetroOptions_private_offset);
	G_OBJECT_CLASS (klass)->finalize = games_retro_options_finalize;
}

static void
games_retro_options_instance_init (GamesRetroOptions * self,
                                   gpointer klass)
{
	self->priv = games_retro_options_get_instance_private (self);
}

static void
games_retro_options_finalize (GObject * obj)
{
	GamesRetroOptions * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_RETRO_OPTIONS, GamesRetroOptions);
	_g_key_file_unref0 (self->priv->keyfile);
	G_OBJECT_CLASS (games_retro_options_parent_class)->finalize (obj);
}

static GType
games_retro_options_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GamesRetroOptionsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_retro_options_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesRetroOptions), 0, (GInstanceInitFunc) games_retro_options_instance_init, NULL };
	GType games_retro_options_type_id;
	games_retro_options_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesRetroOptions", &g_define_type_info, 0);
	GamesRetroOptions_private_offset = g_type_add_instance_private (games_retro_options_type_id, sizeof (GamesRetroOptionsPrivate));
	return games_retro_options_type_id;
}

GType
games_retro_options_get_type (void)
{
	static volatile gsize games_retro_options_type_id__once = 0;
	if (g_once_init_enter (&games_retro_options_type_id__once)) {
		GType games_retro_options_type_id;
		games_retro_options_type_id = games_retro_options_get_type_once ();
		g_once_init_leave (&games_retro_options_type_id__once, games_retro_options_type_id);
	}
	return games_retro_options_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

