/* game-cube-header.c generated by valac 0.36.6.6-c7bee, 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.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <libgnome-games.h>
#include <glib/gi18n-lib.h>


#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;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#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 gpointer games_game_cube_header_parent_class = NULL;
static GType games_game_cube_header_type_id = 0;

GType games_game_cube_header_get_type (void) G_GNUC_CONST;
#define GAMES_GAME_CUBE_HEADER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_GAME_CUBE_HEADER, GamesGameCubeHeaderPrivate))
enum  {
	GAMES_GAME_CUBE_HEADER_0_PROPERTY
};
#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)
GamesGameCubeHeader* games_game_cube_header_new (GFile* file);
GamesGameCubeHeader* games_game_cube_header_construct (GType object_type, GFile* file);
void games_game_cube_header_check_validity (GamesGameCubeHeader* self, GError** error);
GQuark games_game_cube_error_quark (void);
gchar* games_game_cube_header_get_game_id (GamesGameCubeHeader* self, GError** error);
static void games_game_cube_header_finalize (GObject * obj);


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_;
	GFile* _tmp1_;
	g_return_val_if_fail (file != NULL, NULL);
	self = (GamesGameCubeHeader*) g_object_new (object_type, NULL);
	_tmp0_ = file;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->file);
	self->priv->file = _tmp1_;
	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_;
	gboolean _tmp4_;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->file;
	_tmp1_ = games_string_input_stream_new (_tmp0_);
	stream = _tmp1_;
	_tmp3_ = stream;
	_tmp4_ = games_string_input_stream_has_string (_tmp3_, GAMES_GAME_CUBE_HEADER_MAGIC_OFFSET, GAMES_GAME_CUBE_HEADER_MAGIC_VALUE, &_inner_error_);
	_tmp2_ = _tmp4_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (stream);
		return;
	}
	if (!_tmp2_) {
		GError* _tmp5_;
		_tmp5_ = g_error_new_literal (GAMES_GAME_CUBE_ERROR, GAMES_GAME_CUBE_ERROR_INVALID_HEADER, _ ("The file doesn’t have a Game Cube header."));
		_inner_error_ = _tmp5_;
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (stream);
		return;
	}
	_g_object_unref0 (stream);
}


gchar* games_game_cube_header_get_game_id (GamesGameCubeHeader* self, GError** error) {
	gchar* result = NULL;
	GamesStringInputStream* stream = NULL;
	GFile* _tmp0_;
	GamesStringInputStream* _tmp1_;
	gchar* _tmp2_ = NULL;
	gchar* _tmp3_;
	gchar* _tmp4_;
	GError * _inner_error_ = NULL;
	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_error_);
	_tmp2_ = _tmp3_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_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) {
	games_game_cube_header_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesGameCubeHeaderPrivate));
	G_OBJECT_CLASS (klass)->finalize = games_game_cube_header_finalize;
}


static void games_game_cube_header_instance_init (GamesGameCubeHeader * self) {
	self->priv = GAMES_GAME_CUBE_HEADER_GET_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);
	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");
}



