/* sega-saturn-plugin.c generated by valac 0.36.6.6-c7bee, the Vala compiler
 * generated from sega-saturn-plugin.vala, do not modify */

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

#include <glib.h>
#include <glib-object.h>
#include <libgnome-games.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <glib/gi18n-lib.h>


#define GAMES_TYPE_SEGA_SATURN_PLUGIN (games_sega_saturn_plugin_get_type ())
#define GAMES_SEGA_SATURN_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_SEGA_SATURN_PLUGIN, GamesSegaSaturnPlugin))
#define GAMES_SEGA_SATURN_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_SEGA_SATURN_PLUGIN, GamesSegaSaturnPluginClass))
#define GAMES_IS_SEGA_SATURN_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_SEGA_SATURN_PLUGIN))
#define GAMES_IS_SEGA_SATURN_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_SEGA_SATURN_PLUGIN))
#define GAMES_SEGA_SATURN_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_SEGA_SATURN_PLUGIN, GamesSegaSaturnPluginClass))

typedef struct _GamesSegaSaturnPlugin GamesSegaSaturnPlugin;
typedef struct _GamesSegaSaturnPluginClass GamesSegaSaturnPluginClass;
typedef struct _GamesSegaSaturnPluginPrivate GamesSegaSaturnPluginPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

#define GAMES_TYPE_SEGA_SATURN_HEADER (games_sega_saturn_header_get_type ())
#define GAMES_SEGA_SATURN_HEADER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_SEGA_SATURN_HEADER, GamesSegaSaturnHeader))
#define GAMES_SEGA_SATURN_HEADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_SEGA_SATURN_HEADER, GamesSegaSaturnHeaderClass))
#define GAMES_IS_SEGA_SATURN_HEADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_SEGA_SATURN_HEADER))
#define GAMES_IS_SEGA_SATURN_HEADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_SEGA_SATURN_HEADER))
#define GAMES_SEGA_SATURN_HEADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_SEGA_SATURN_HEADER, GamesSegaSaturnHeaderClass))

typedef struct _GamesSegaSaturnHeader GamesSegaSaturnHeader;
typedef struct _GamesSegaSaturnHeaderClass GamesSegaSaturnHeaderClass;

#define GAMES_TYPE_SEGA_SATURN_UID (games_sega_saturn_uid_get_type ())
#define GAMES_SEGA_SATURN_UID(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_SEGA_SATURN_UID, GamesSegaSaturnUid))
#define GAMES_SEGA_SATURN_UID_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_SEGA_SATURN_UID, GamesSegaSaturnUidClass))
#define GAMES_IS_SEGA_SATURN_UID(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_SEGA_SATURN_UID))
#define GAMES_IS_SEGA_SATURN_UID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_SEGA_SATURN_UID))
#define GAMES_SEGA_SATURN_UID_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_SEGA_SATURN_UID, GamesSegaSaturnUidClass))

typedef struct _GamesSegaSaturnUid GamesSegaSaturnUid;
typedef struct _GamesSegaSaturnUidClass GamesSegaSaturnUidClass;

struct _GamesSegaSaturnPlugin {
	GObject parent_instance;
	GamesSegaSaturnPluginPrivate * priv;
};

struct _GamesSegaSaturnPluginClass {
	GObjectClass parent_class;
};

typedef enum  {
	GAMES_SEGA_SATURN_ERROR_INVALID_CUE_SHEET,
	GAMES_SEGA_SATURN_ERROR_INVALID_FILE_TYPE,
	GAMES_SEGA_SATURN_ERROR_CANT_READ_FILE,
	GAMES_SEGA_SATURN_ERROR_INVALID_HEADER
} GamesSegaSaturnError;
#define GAMES_SEGA_SATURN_ERROR games_sega_saturn_error_quark ()

static gpointer games_sega_saturn_plugin_parent_class = NULL;
static GamesPluginIface * games_sega_saturn_plugin_games_plugin_parent_iface = NULL;
static GType games_sega_saturn_plugin_type_id = 0;

GType games_sega_saturn_plugin_get_type (void) G_GNUC_CONST;
enum  {
	GAMES_SEGA_SATURN_PLUGIN_0_PROPERTY
};
#define GAMES_SEGA_SATURN_PLUGIN_CUE_MIME_TYPE "application/x-cue"
#define GAMES_SEGA_SATURN_PLUGIN_SEGA_SATURN_MIME_TYPE "application/x-saturn-rom"
#define GAMES_SEGA_SATURN_PLUGIN_PLATFORM "SegaSaturn"
static gchar** games_sega_saturn_plugin_real_get_mime_types (GamesPlugin* base, int* result_length1);
static GamesUriGameFactory** games_sega_saturn_plugin_real_get_uri_game_factories (GamesPlugin* base, int* result_length1);
static GamesGame* games_sega_saturn_plugin_game_for_uri (GamesUri* uri, GError** error);
static GamesGame* _games_sega_saturn_plugin_game_for_uri_games_generic_game_uri_adapter_game_for_uri (GamesUri* uri, gpointer self, GError** error);
static GFile* games_sega_saturn_plugin_get_binary_file (GamesCueSheet* cue, GError** error);
GQuark games_sega_saturn_error_quark (void);
GType games_sega_saturn_header_get_type (void) G_GNUC_CONST;
GamesSegaSaturnHeader* games_sega_saturn_header_new (GFile* file);
GamesSegaSaturnHeader* games_sega_saturn_header_construct (GType object_type, GFile* file);
void games_sega_saturn_header_check_validity (GamesSegaSaturnHeader* self, GError** error);
GType games_sega_saturn_uid_get_type (void) G_GNUC_CONST;
GamesSegaSaturnUid* games_sega_saturn_uid_new (GamesSegaSaturnHeader* header);
GamesSegaSaturnUid* games_sega_saturn_uid_construct (GType object_type, GamesSegaSaturnHeader* header);
GamesSegaSaturnPlugin* games_sega_saturn_plugin_new (void);
GamesSegaSaturnPlugin* games_sega_saturn_plugin_construct (GType object_type);
GType register_games_plugin (GTypeModule* module);
GType games_sega_saturn_header_register_type (GTypeModule * module);
GType games_sega_saturn_plugin_register_type (GTypeModule * module);
GType games_sega_saturn_uid_register_type (GTypeModule * module);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


static gchar** games_sega_saturn_plugin_real_get_mime_types (GamesPlugin* base, int* result_length1) {
	GamesSegaSaturnPlugin * self;
	gchar** result = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar** _tmp2_;
	gchar** _tmp3_;
	gint _tmp3__length1;
	self = (GamesSegaSaturnPlugin*) base;
	_tmp0_ = g_strdup (GAMES_SEGA_SATURN_PLUGIN_CUE_MIME_TYPE);
	_tmp1_ = g_strdup (GAMES_SEGA_SATURN_PLUGIN_SEGA_SATURN_MIME_TYPE);
	_tmp2_ = g_new0 (gchar*, 2 + 1);
	_tmp2_[0] = _tmp0_;
	_tmp2_[1] = _tmp1_;
	_tmp3_ = _tmp2_;
	_tmp3__length1 = 2;
	if (result_length1) {
		*result_length1 = _tmp3__length1;
	}
	result = _tmp3_;
	return result;
}


static GamesGame* _games_sega_saturn_plugin_game_for_uri_games_generic_game_uri_adapter_game_for_uri (GamesUri* uri, gpointer self, GError** error) {
	GamesGame* result;
	result = games_sega_saturn_plugin_game_for_uri (uri, error);
	return result;
}


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


static GamesUriGameFactory** games_sega_saturn_plugin_real_get_uri_game_factories (GamesPlugin* base, int* result_length1) {
	GamesSegaSaturnPlugin * self;
	GamesUriGameFactory** result = NULL;
	GamesGenericGameUriAdapter* game_uri_adapter = NULL;
	GamesGenericGameUriAdapter* _tmp0_;
	GamesGenericUriGameFactory* factory = NULL;
	GamesGenericUriGameFactory* _tmp1_;
	GamesUriGameFactory* _tmp2_;
	GamesUriGameFactory** _tmp3_;
	GamesUriGameFactory** _tmp4_;
	gint _tmp4__length1;
	self = (GamesSegaSaturnPlugin*) base;
	_tmp0_ = games_generic_game_uri_adapter_new (_games_sega_saturn_plugin_game_for_uri_games_generic_game_uri_adapter_game_for_uri, NULL, NULL);
	game_uri_adapter = _tmp0_;
	_tmp1_ = games_generic_uri_game_factory_new ((GamesGameUriAdapter*) game_uri_adapter);
	factory = _tmp1_;
	games_generic_uri_game_factory_add_mime_type (factory, GAMES_SEGA_SATURN_PLUGIN_CUE_MIME_TYPE);
	games_generic_uri_game_factory_add_mime_type (factory, GAMES_SEGA_SATURN_PLUGIN_SEGA_SATURN_MIME_TYPE);
	_tmp2_ = _g_object_ref0 ((GamesUriGameFactory*) factory);
	_tmp3_ = g_new0 (GamesUriGameFactory*, 1 + 1);
	_tmp3_[0] = _tmp2_;
	_tmp4_ = _tmp3_;
	_tmp4__length1 = 1;
	if (result_length1) {
		*result_length1 = _tmp4__length1;
	}
	result = _tmp4_;
	_g_object_unref0 (factory);
	_g_object_unref0 (game_uri_adapter);
	return result;
}


static GamesGame* games_sega_saturn_plugin_game_for_uri (GamesUri* uri, GError** error) {
	GamesGame* result = NULL;
	GFile* file = NULL;
	GamesUri* _tmp0_;
	GFile* _tmp1_;
	GFileInfo* file_info = NULL;
	GFile* _tmp2_;
	GFileInfo* _tmp3_;
	gchar* mime_type = NULL;
	GFileInfo* _tmp4_;
	const gchar* _tmp5_;
	gchar* _tmp6_;
	GFile* bin_file = NULL;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	GQuark _tmp10_ = 0U;
	GamesSegaSaturnHeader* header = NULL;
	GFile* _tmp25_;
	GamesSegaSaturnHeader* _tmp26_;
	GamesSegaSaturnHeader* _tmp27_;
	GamesSegaSaturnUid* uid = NULL;
	GamesSegaSaturnHeader* _tmp28_;
	GamesSegaSaturnUid* _tmp29_;
	GamesFilenameTitle* title = NULL;
	GamesUri* _tmp30_;
	GamesFilenameTitle* _tmp31_;
	GamesDummyIcon* icon = NULL;
	GamesDummyIcon* _tmp32_;
	GamesGriloMedia* media = NULL;
	GamesFilenameTitle* _tmp33_;
	GamesGriloMedia* _tmp34_;
	GamesCompositeCover* cover = NULL;
	GamesUri* _tmp35_;
	GamesLocalCover* _tmp36_;
	GamesGriloMedia* _tmp37_;
	GamesSegaSaturnUid* _tmp38_;
	GamesGriloCover* _tmp39_;
	GamesCover** _tmp40_;
	GamesCover** _tmp41_;
	gint _tmp41__length1;
	GamesCompositeCover* _tmp42_;
	GamesCompositeCover* _tmp43_;
	GamesRetroCoreSource* core_source = NULL;
	gchar* _tmp44_;
	gchar* _tmp45_;
	gchar** _tmp46_;
	gchar** _tmp47_;
	gint _tmp47__length1;
	GamesRetroCoreSource* _tmp48_;
	GamesRetroCoreSource* _tmp49_;
	GamesRetroRunner* runner = NULL;
	GamesRetroCoreSource* _tmp50_;
	GamesUri* _tmp51_;
	GamesSegaSaturnUid* _tmp52_;
	GamesFilenameTitle* _tmp53_;
	GamesRetroRunner* _tmp54_;
	GamesFilenameTitle* _tmp55_;
	GamesDummyIcon* _tmp56_;
	GamesCompositeCover* _tmp57_;
	GamesRetroRunner* _tmp58_;
	GamesGenericGame* _tmp59_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (uri != NULL, NULL);
	_tmp0_ = uri;
	_tmp1_ = games_uri_to_file (_tmp0_);
	file = _tmp1_;
	_tmp2_ = file;
	_tmp3_ = g_file_query_info (_tmp2_, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, &_inner_error_);
	file_info = _tmp3_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (file);
		return NULL;
	}
	_tmp4_ = file_info;
	_tmp5_ = g_file_info_get_content_type (_tmp4_);
	_tmp6_ = g_strdup (_tmp5_);
	mime_type = _tmp6_;
	_tmp7_ = mime_type;
	_tmp8_ = _tmp7_;
	_tmp10_ = (NULL == _tmp8_) ? 0 : g_quark_from_string (_tmp8_);
	if (_tmp10_ == g_quark_from_string (GAMES_SEGA_SATURN_PLUGIN_CUE_MIME_TYPE)) {
		switch (0) {
			default:
			{
				GamesCueSheet* cue = NULL;
				GFile* _tmp11_;
				GamesCueSheet* _tmp12_;
				GFile* _tmp13_ = NULL;
				GamesCueSheet* _tmp14_;
				GFile* _tmp15_;
				GFile* _tmp16_;
				_tmp11_ = file;
				_tmp12_ = games_cue_sheet_new (_tmp11_, &_inner_error_);
				cue = _tmp12_;
				if (G_UNLIKELY (_inner_error_ != NULL)) {
					g_propagate_error (error, _inner_error_);
					_g_object_unref0 (bin_file);
					_g_free0 (mime_type);
					_g_object_unref0 (file_info);
					_g_object_unref0 (file);
					return NULL;
				}
				_tmp14_ = cue;
				_tmp15_ = games_sega_saturn_plugin_get_binary_file (_tmp14_, &_inner_error_);
				_tmp13_ = _tmp15_;
				if (G_UNLIKELY (_inner_error_ != NULL)) {
					g_propagate_error (error, _inner_error_);
					_g_object_unref0 (cue);
					_g_object_unref0 (bin_file);
					_g_free0 (mime_type);
					_g_object_unref0 (file_info);
					_g_object_unref0 (file);
					return NULL;
				}
				_tmp16_ = _tmp13_;
				_tmp13_ = NULL;
				_g_object_unref0 (bin_file);
				bin_file = _tmp16_;
				_g_object_unref0 (_tmp13_);
				_g_object_unref0 (cue);
				break;
			}
		}
	} else if (_tmp10_ == g_quark_from_string (GAMES_SEGA_SATURN_PLUGIN_SEGA_SATURN_MIME_TYPE)) {
		switch (0) {
			default:
			{
				GFile* _tmp17_;
				GFile* _tmp18_;
				_tmp17_ = file;
				_tmp18_ = _g_object_ref0 (_tmp17_);
				_g_object_unref0 (bin_file);
				bin_file = _tmp18_;
				break;
			}
		}
	} else {
		switch (0) {
			default:
			{
				const gchar* _tmp19_;
				GamesUri* _tmp20_;
				gchar* _tmp21_;
				gchar* _tmp22_;
				GError* _tmp23_;
				GError* _tmp24_;
				_tmp19_ = mime_type;
				_tmp20_ = uri;
				_tmp21_ = games_uri_to_string (_tmp20_);
				_tmp22_ = _tmp21_;
				_tmp23_ = g_error_new (GAMES_SEGA_SATURN_ERROR, GAMES_SEGA_SATURN_ERROR_INVALID_FILE_TYPE, "Invalid file type: expected %s or %s but got %s for file %s.", GAMES_SEGA_SATURN_PLUGIN_CUE_MIME_TYPE, GAMES_SEGA_SATURN_PLUGIN_SEGA_SATURN_MIME_TYPE, _tmp19_, _tmp22_);
				_tmp24_ = _tmp23_;
				_g_free0 (_tmp22_);
				_inner_error_ = _tmp24_;
				g_propagate_error (error, _inner_error_);
				_g_object_unref0 (bin_file);
				_g_free0 (mime_type);
				_g_object_unref0 (file_info);
				_g_object_unref0 (file);
				return NULL;
			}
		}
	}
	_tmp25_ = bin_file;
	_tmp26_ = games_sega_saturn_header_new (_tmp25_);
	header = _tmp26_;
	_tmp27_ = header;
	games_sega_saturn_header_check_validity (_tmp27_, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (header);
		_g_object_unref0 (bin_file);
		_g_free0 (mime_type);
		_g_object_unref0 (file_info);
		_g_object_unref0 (file);
		return NULL;
	}
	_tmp28_ = header;
	_tmp29_ = games_sega_saturn_uid_new (_tmp28_);
	uid = _tmp29_;
	_tmp30_ = uri;
	_tmp31_ = games_filename_title_new (_tmp30_);
	title = _tmp31_;
	_tmp32_ = games_dummy_icon_new ();
	icon = _tmp32_;
	_tmp33_ = title;
	_tmp34_ = games_grilo_media_new ((GamesTitle*) _tmp33_, GAMES_SEGA_SATURN_PLUGIN_SEGA_SATURN_MIME_TYPE);
	media = _tmp34_;
	_tmp35_ = uri;
	_tmp36_ = games_local_cover_new (_tmp35_);
	_tmp37_ = media;
	_tmp38_ = uid;
	_tmp39_ = games_grilo_cover_new (_tmp37_, (GamesUid*) _tmp38_);
	_tmp40_ = g_new0 (GamesCover*, 2 + 1);
	_tmp40_[0] = (GamesCover*) _tmp36_;
	_tmp40_[1] = (GamesCover*) _tmp39_;
	_tmp41_ = _tmp40_;
	_tmp41__length1 = 2;
	_tmp42_ = games_composite_cover_new (_tmp41_, 2);
	_tmp43_ = _tmp42_;
	_tmp41_ = (_vala_array_free (_tmp41_, _tmp41__length1, (GDestroyNotify) g_object_unref), NULL);
	cover = _tmp43_;
	_tmp44_ = g_strdup (GAMES_SEGA_SATURN_PLUGIN_CUE_MIME_TYPE);
	_tmp45_ = g_strdup (GAMES_SEGA_SATURN_PLUGIN_SEGA_SATURN_MIME_TYPE);
	_tmp46_ = g_new0 (gchar*, 2 + 1);
	_tmp46_[0] = _tmp44_;
	_tmp46_[1] = _tmp45_;
	_tmp47_ = _tmp46_;
	_tmp47__length1 = 2;
	_tmp48_ = games_retro_core_source_new (GAMES_SEGA_SATURN_PLUGIN_PLATFORM, _tmp47_, 2);
	_tmp49_ = _tmp48_;
	_tmp47_ = (_vala_array_free (_tmp47_, _tmp47__length1, (GDestroyNotify) g_free), NULL);
	core_source = _tmp49_;
	_tmp50_ = core_source;
	_tmp51_ = uri;
	_tmp52_ = uid;
	_tmp53_ = title;
	_tmp54_ = games_retro_runner_new (_tmp50_, _tmp51_, (GamesUid*) _tmp52_, (GamesTitle*) _tmp53_);
	runner = _tmp54_;
	_tmp55_ = title;
	_tmp56_ = icon;
	_tmp57_ = cover;
	_tmp58_ = runner;
	_tmp59_ = games_generic_game_new ((GamesTitle*) _tmp55_, (GamesIcon*) _tmp56_, (GamesCover*) _tmp57_, (GamesRunner*) _tmp58_);
	result = (GamesGame*) _tmp59_;
	_g_object_unref0 (runner);
	_g_object_unref0 (core_source);
	_g_object_unref0 (cover);
	_g_object_unref0 (media);
	_g_object_unref0 (icon);
	_g_object_unref0 (title);
	_g_object_unref0 (uid);
	_g_object_unref0 (header);
	_g_object_unref0 (bin_file);
	_g_free0 (mime_type);
	_g_object_unref0 (file_info);
	_g_object_unref0 (file);
	return result;
}


static GFile* games_sega_saturn_plugin_get_binary_file (GamesCueSheet* cue, GError** error) {
	GFile* result = NULL;
	GamesCueSheet* _tmp0_;
	guint _tmp1_;
	guint _tmp2_;
	GamesCueSheetTrackNode* track = NULL;
	GamesCueSheet* _tmp10_;
	GamesCueSheetTrackNode* _tmp11_;
	GamesCueSheetFileNode* file = NULL;
	GamesCueSheetTrackNode* _tmp12_;
	GamesCueSheetFileNode* _tmp13_;
	GamesCueSheetFileNode* _tmp14_;
	GamesCueSheetFileNode* _tmp15_;
	gboolean _tmp16_ = FALSE;
	GamesCueSheetFileNode* _tmp17_;
	GamesCueSheetFileFormat _tmp18_;
	GamesCueSheetFileFormat _tmp19_;
	GamesCueSheetTrackNode* _tmp30_;
	GamesCueSheetTrackMode _tmp31_;
	GamesCueSheetTrackMode _tmp32_;
	gboolean _tmp33_;
	GFileInfo* file_info = NULL;
	GamesCueSheetFileNode* _tmp44_;
	GFile* _tmp45_;
	GFile* _tmp46_;
	GFileInfo* _tmp47_;
	GFileInfo* _tmp48_;
	const gchar* _tmp49_;
	GamesCueSheetFileNode* _tmp57_;
	GFile* _tmp58_;
	GFile* _tmp59_;
	GFile* _tmp60_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (cue != NULL, NULL);
	_tmp0_ = cue;
	_tmp1_ = games_cue_sheet_get_tracks_number (_tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_ == ((guint) 0)) {
		GamesCueSheet* _tmp3_;
		GFile* _tmp4_;
		GFile* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		GError* _tmp8_;
		GError* _tmp9_;
		_tmp3_ = cue;
		_tmp4_ = games_cue_sheet_get_file (_tmp3_);
		_tmp5_ = _tmp4_;
		_tmp6_ = g_file_get_uri (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp8_ = g_error_new (GAMES_SEGA_SATURN_ERROR, GAMES_SEGA_SATURN_ERROR_INVALID_CUE_SHEET, _ ("The file “%s” doesn’t have a track."), _tmp7_);
		_tmp9_ = _tmp8_;
		_g_free0 (_tmp7_);
		_inner_error_ = _tmp9_;
		g_propagate_error (error, _inner_error_);
		return NULL;
	}
	_tmp10_ = cue;
	_tmp11_ = games_cue_sheet_get_track (_tmp10_, (guint) 0, &_inner_error_);
	track = _tmp11_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		return NULL;
	}
	_tmp12_ = track;
	_tmp13_ = games_cue_sheet_track_node_get_file (_tmp12_);
	_tmp14_ = _tmp13_;
	_tmp15_ = _g_object_ref0 (_tmp14_);
	file = _tmp15_;
	_tmp17_ = file;
	_tmp18_ = games_cue_sheet_file_node_get_file_format (_tmp17_);
	_tmp19_ = _tmp18_;
	if (_tmp19_ != GAMES_CUE_SHEET_FILE_FORMAT_BINARY) {
		GamesCueSheetFileNode* _tmp20_;
		GamesCueSheetFileFormat _tmp21_;
		GamesCueSheetFileFormat _tmp22_;
		_tmp20_ = file;
		_tmp21_ = games_cue_sheet_file_node_get_file_format (_tmp20_);
		_tmp22_ = _tmp21_;
		_tmp16_ = _tmp22_ != GAMES_CUE_SHEET_FILE_FORMAT_UNKNOWN;
	} else {
		_tmp16_ = FALSE;
	}
	if (_tmp16_) {
		GamesCueSheet* _tmp23_;
		GFile* _tmp24_;
		GFile* _tmp25_;
		gchar* _tmp26_;
		gchar* _tmp27_;
		GError* _tmp28_;
		GError* _tmp29_;
		_tmp23_ = cue;
		_tmp24_ = games_cue_sheet_get_file (_tmp23_);
		_tmp25_ = _tmp24_;
		_tmp26_ = g_file_get_uri (_tmp25_);
		_tmp27_ = _tmp26_;
		_tmp28_ = g_error_new (GAMES_SEGA_SATURN_ERROR, GAMES_SEGA_SATURN_ERROR_INVALID_CUE_SHEET, _ ("The file “%s” doesn’t have a valid binary file format."), _tmp27_);
		_tmp29_ = _tmp28_;
		_g_free0 (_tmp27_);
		_inner_error_ = _tmp29_;
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (file);
		_g_object_unref0 (track);
		return NULL;
	}
	_tmp30_ = track;
	_tmp31_ = games_cue_sheet_track_node_get_track_mode (_tmp30_);
	_tmp32_ = _tmp31_;
	_tmp33_ = games_cue_sheet_track_mode_is_mode1 (_tmp32_);
	if (!_tmp33_) {
		GamesCueSheet* _tmp34_;
		GFile* _tmp35_;
		GFile* _tmp36_;
		gchar* _tmp37_;
		gchar* _tmp38_;
		GamesCueSheetTrackNode* _tmp39_;
		gint _tmp40_;
		gint _tmp41_;
		GError* _tmp42_;
		GError* _tmp43_;
		_tmp34_ = cue;
		_tmp35_ = games_cue_sheet_get_file (_tmp34_);
		_tmp36_ = _tmp35_;
		_tmp37_ = g_file_get_uri (_tmp36_);
		_tmp38_ = _tmp37_;
		_tmp39_ = track;
		_tmp40_ = games_cue_sheet_track_node_get_track_number (_tmp39_);
		_tmp41_ = _tmp40_;
		_tmp42_ = g_error_new (GAMES_SEGA_SATURN_ERROR, GAMES_SEGA_SATURN_ERROR_INVALID_CUE_SHEET, _ ("The file “%s” doesn’t have a valid track mode for track %d."), _tmp38_, _tmp41_);
		_tmp43_ = _tmp42_;
		_g_free0 (_tmp38_);
		_inner_error_ = _tmp43_;
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (file);
		_g_object_unref0 (track);
		return NULL;
	}
	_tmp44_ = file;
	_tmp45_ = games_cue_sheet_file_node_get_file (_tmp44_);
	_tmp46_ = _tmp45_;
	_tmp47_ = g_file_query_info (_tmp46_, "*", G_FILE_QUERY_INFO_NONE, NULL, &_inner_error_);
	file_info = _tmp47_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (file);
		_g_object_unref0 (track);
		return NULL;
	}
	_tmp48_ = file_info;
	_tmp49_ = g_file_info_get_content_type (_tmp48_);
	if (g_strcmp0 (_tmp49_, GAMES_SEGA_SATURN_PLUGIN_SEGA_SATURN_MIME_TYPE) != 0) {
		GamesCueSheet* _tmp50_;
		GFile* _tmp51_;
		GFile* _tmp52_;
		gchar* _tmp53_;
		gchar* _tmp54_;
		GError* _tmp55_;
		GError* _tmp56_;
		_tmp50_ = cue;
		_tmp51_ = games_cue_sheet_get_file (_tmp50_);
		_tmp52_ = _tmp51_;
		_tmp53_ = g_file_get_uri (_tmp52_);
		_tmp54_ = _tmp53_;
		_tmp55_ = g_error_new (GAMES_SEGA_SATURN_ERROR, GAMES_SEGA_SATURN_ERROR_INVALID_FILE_TYPE, _ ("The file “%s” doesn’t have a valid Sega Saturn binary file."), _tmp54_);
		_tmp56_ = _tmp55_;
		_g_free0 (_tmp54_);
		_inner_error_ = _tmp56_;
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (file_info);
		_g_object_unref0 (file);
		_g_object_unref0 (track);
		return NULL;
	}
	_tmp57_ = file;
	_tmp58_ = games_cue_sheet_file_node_get_file (_tmp57_);
	_tmp59_ = _tmp58_;
	_tmp60_ = _g_object_ref0 (_tmp59_);
	result = _tmp60_;
	_g_object_unref0 (file_info);
	_g_object_unref0 (file);
	_g_object_unref0 (track);
	return result;
}


GamesSegaSaturnPlugin* games_sega_saturn_plugin_construct (GType object_type) {
	GamesSegaSaturnPlugin * self = NULL;
	self = (GamesSegaSaturnPlugin*) g_object_new (object_type, NULL);
	return self;
}


GamesSegaSaturnPlugin* games_sega_saturn_plugin_new (void) {
	return games_sega_saturn_plugin_construct (GAMES_TYPE_SEGA_SATURN_PLUGIN);
}


static void games_sega_saturn_plugin_class_init (GamesSegaSaturnPluginClass * klass) {
	games_sega_saturn_plugin_parent_class = g_type_class_peek_parent (klass);
}


static void games_sega_saturn_plugin_games_plugin_interface_init (GamesPluginIface * iface) {
	games_sega_saturn_plugin_games_plugin_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_mime_types = (gchar** (*) (GamesPlugin *, int*)) games_sega_saturn_plugin_real_get_mime_types;
	iface->get_uri_game_factories = (GamesUriGameFactory** (*) (GamesPlugin *, int*)) games_sega_saturn_plugin_real_get_uri_game_factories;
}


static void games_sega_saturn_plugin_instance_init (GamesSegaSaturnPlugin * self) {
}


GType games_sega_saturn_plugin_get_type (void) {
	return games_sega_saturn_plugin_type_id;
}


GType games_sega_saturn_plugin_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (GamesSegaSaturnPluginClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_sega_saturn_plugin_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesSegaSaturnPlugin), 0, (GInstanceInitFunc) games_sega_saturn_plugin_instance_init, NULL };
	static const GInterfaceInfo games_plugin_info = { (GInterfaceInitFunc) games_sega_saturn_plugin_games_plugin_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	games_sega_saturn_plugin_type_id = g_type_module_register_type (module, G_TYPE_OBJECT, "GamesSegaSaturnPlugin", &g_define_type_info, 0);
	g_type_module_add_interface (module, games_sega_saturn_plugin_type_id, GAMES_TYPE_PLUGIN, &games_plugin_info);
	return games_sega_saturn_plugin_type_id;
}


GType register_games_plugin (GTypeModule* module) {
	GType result = 0UL;
	g_return_val_if_fail (module != NULL, 0UL);
	games_sega_saturn_header_register_type (module);
	games_sega_saturn_plugin_register_type (module);
	games_sega_saturn_uid_register_type (module);
	result = GAMES_TYPE_SEGA_SATURN_PLUGIN;
	return result;
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int 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, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



