/* game-cube-header.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from game-cube-header.vala, do not modify */

/* This file is part of GNOME Games. License: GPL-3.0+.*/
/* Documentation: http://www.gc-forever.com/yagcd/chap13.html*/

#include <glib-object.h>
#include <gio/gio.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include "gnome-games.h"
#include "games-game-cube-plugin.h"

#define GAMES_GAME_CUBE_HEADER_MAGIC_OFFSET ((gsize) 0x1c)
#define GAMES_GAME_CUBE_HEADER_MAGIC_VALUE "\xc2\x33\x9f\x3d"
#define GAMES_GAME_CUBE_HEADER_ID_OFFSET ((gsize) 0)
#define GAMES_GAME_CUBE_HEADER_ID_SIZE ((gsize) 6)
#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_GAME_CUBE_HEADER (games_game_cube_header_get_type ())
#define GAMES_GAME_CUBE_HEADER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_GAME_CUBE_HEADER, GamesGameCubeHeader))
#define GAMES_GAME_CUBE_HEADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_GAME_CUBE_HEADER, GamesGameCubeHeaderClass))
#define GAMES_IS_GAME_CUBE_HEADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_GAME_CUBE_HEADER))
#define GAMES_IS_GAME_CUBE_HEADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_GAME_CUBE_HEADER))
#define GAMES_GAME_CUBE_HEADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_GAME_CUBE_HEADER, GamesGameCubeHeaderClass))

typedef struct _GamesGameCubeHeader GamesGameCubeHeader;
typedef struct _GamesGameCubeHeaderClass GamesGameCubeHeaderClass;
typedef struct _GamesGameCubeHeaderPrivate GamesGameCubeHeaderPrivate;
enum  {
	GAMES_GAME_CUBE_HEADER_0_PROPERTY,
	GAMES_GAME_CUBE_HEADER_NUM_PROPERTIES
};
static GParamSpec* games_game_cube_header_properties[GAMES_GAME_CUBE_HEADER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define GAMES_TYPE_GAME_CUBE_ERROR (games_game_cube_error_get_type ())
#define _g_free0(var) (var = (g_free (var), NULL))

struct _GamesGameCubeHeader {
	GObject parent_instance;
	GamesGameCubeHeaderPrivate * priv;
};

struct _GamesGameCubeHeaderClass {
	GObjectClass parent_class;
};

struct _GamesGameCubeHeaderPrivate {
	GFile* file;
};

typedef enum  {
	GAMES_GAME_CUBE_ERROR_INVALID_HEADER
} GamesGameCubeError;
#define GAMES_GAME_CUBE_ERROR games_game_cube_error_quark ()

static gint GamesGameCubeHeader_private_offset;
static gpointer games_game_cube_header_parent_class = NULL;
static GType games_game_cube_header_type_id = 0;

GType games_game_cube_header_register_type (GTypeModule * module);
VALA_EXTERN GType games_game_cube_header_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GamesGameCubeHeader* games_game_cube_header_new (GFile* file);
VALA_EXTERN GamesGameCubeHeader* games_game_cube_header_construct (GType object_type,
                                                       GFile* file);
VALA_EXTERN void games_game_cube_header_check_validity (GamesGameCubeHeader* self,
                                            GError** error);
VALA_EXTERN GQuark games_game_cube_error_quark (void);
VALA_EXTERN GType games_game_cube_error_get_type (void) G_GNUC_CONST ;
VALA_EXTERN gchar* games_game_cube_header_get_game_id (GamesGameCubeHeader* self,
                                           GError** error);
static void games_game_cube_header_finalize (GObject * obj);

static inline gpointer
games_game_cube_header_get_instance_private (GamesGameCubeHeader* self)
{
	return G_STRUCT_MEMBER_P (self, GamesGameCubeHeader_private_offset);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

GamesGameCubeHeader*
games_game_cube_header_construct (GType object_type,
                                  GFile* file)
{
	GamesGameCubeHeader * self = NULL;
	GFile* _tmp0_;
	g_return_val_if_fail (file != NULL, NULL);
	self = (GamesGameCubeHeader*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (file);
	_g_object_unref0 (self->priv->file);
	self->priv->file = _tmp0_;
	return self;
}

GamesGameCubeHeader*
games_game_cube_header_new (GFile* file)
{
	return games_game_cube_header_construct (GAMES_TYPE_GAME_CUBE_HEADER, file);
}

void
games_game_cube_header_check_validity (GamesGameCubeHeader* self,
                                       GError** error)
{
	GamesStringInputStream* stream = NULL;
	GFile* _tmp0_;
	GamesStringInputStream* _tmp1_;
	gboolean _tmp2_ = FALSE;
	GamesStringInputStream* _tmp3_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->file;
	_tmp1_ = games_string_input_stream_new (_tmp0_);
	stream = _tmp1_;
	_tmp3_ = stream;
	_tmp2_ = games_string_input_stream_has_string (_tmp3_, GAMES_GAME_CUBE_HEADER_MAGIC_OFFSET, GAMES_GAME_CUBE_HEADER_MAGIC_VALUE, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stream);
		return;
	}
	if (!_tmp2_) {
		GError* _tmp4_;
		_tmp4_ = g_error_new_literal (GAMES_GAME_CUBE_ERROR, GAMES_GAME_CUBE_ERROR_INVALID_HEADER, "The file doesn’t have a Game Cube header.");
		_inner_error0_ = _tmp4_;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stream);
		return;
	}
	_g_object_unref0 (stream);
}

gchar*
games_game_cube_header_get_game_id (GamesGameCubeHeader* self,
                                    GError** error)
{
	GamesStringInputStream* stream = NULL;
	GFile* _tmp0_;
	GamesStringInputStream* _tmp1_;
	gchar* _tmp2_ = NULL;
	gchar* _tmp3_;
	gchar* _tmp4_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->file;
	_tmp1_ = games_string_input_stream_new (_tmp0_);
	stream = _tmp1_;
	_tmp3_ = games_string_input_stream_read_string_for_size (stream, GAMES_GAME_CUBE_HEADER_ID_OFFSET, GAMES_GAME_CUBE_HEADER_ID_SIZE, &_inner_error0_);
	_tmp2_ = _tmp3_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stream);
		return NULL;
	}
	_tmp4_ = _tmp2_;
	_tmp2_ = NULL;
	result = _tmp4_;
	_g_free0 (_tmp2_);
	_g_object_unref0 (stream);
	return result;
}

static void
games_game_cube_header_class_init (GamesGameCubeHeaderClass * klass,
                                   gpointer klass_data)
{
	games_game_cube_header_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GamesGameCubeHeader_private_offset);
	G_OBJECT_CLASS (klass)->finalize = games_game_cube_header_finalize;
}

static void
games_game_cube_header_instance_init (GamesGameCubeHeader * self,
                                      gpointer klass)
{
	self->priv = games_game_cube_header_get_instance_private (self);
}

static void
games_game_cube_header_finalize (GObject * obj)
{
	GamesGameCubeHeader * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_GAME_CUBE_HEADER, GamesGameCubeHeader);
	_g_object_unref0 (self->priv->file);
	G_OBJECT_CLASS (games_game_cube_header_parent_class)->finalize (obj);
}

GType
games_game_cube_header_get_type (void)
{
	return games_game_cube_header_type_id;
}

GType
games_game_cube_header_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (GamesGameCubeHeaderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_game_cube_header_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesGameCubeHeader), 0, (GInstanceInitFunc) games_game_cube_header_instance_init, NULL };
	games_game_cube_header_type_id = g_type_module_register_type (module, G_TYPE_OBJECT, "GamesGameCubeHeader", &g_define_type_info, 0);
	GamesGameCubeHeader_private_offset = sizeof (GamesGameCubeHeaderPrivate);
	return games_game_cube_header_type_id;
}

GQuark
games_game_cube_error_quark (void)
{
	return g_quark_from_static_string ("games-game-cube-error-quark");
}

static GType
games_game_cube_error_get_type_once (void)
{
	static const GEnumValue values[] = {{GAMES_GAME_CUBE_ERROR_INVALID_HEADER, "GAMES_GAME_CUBE_ERROR_INVALID_HEADER", "invalid-header"}, {0, NULL, NULL}};
	GType games_game_cube_error_type_id;
	games_game_cube_error_type_id = g_enum_register_static ("GamesGameCubeError", values);
	return games_game_cube_error_type_id;
}

GType
games_game_cube_error_get_type (void)
{
	static volatile gsize games_game_cube_error_type_id__once = 0;
	if (g_once_init_enter (&games_game_cube_error_type_id__once)) {
		GType games_game_cube_error_type_id;
		games_game_cube_error_type_id = games_game_cube_error_get_type_once ();
		g_once_init_leave (&games_game_cube_error_type_id__once, games_game_cube_error_type_id);
	}
	return games_game_cube_error_type_id__once;
}

