/* sega-cd-plugin.c generated by valac 0.36.6.6-c7bee, the Vala compiler
 * generated from sega-cd-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_CD_PLUGIN (games_sega_cd_plugin_get_type ())
#define GAMES_SEGA_CD_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_SEGA_CD_PLUGIN, GamesSegaCDPlugin))
#define GAMES_SEGA_CD_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_SEGA_CD_PLUGIN, GamesSegaCDPluginClass))
#define GAMES_IS_SEGA_CD_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_SEGA_CD_PLUGIN))
#define GAMES_IS_SEGA_CD_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_SEGA_CD_PLUGIN))
#define GAMES_SEGA_CD_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_SEGA_CD_PLUGIN, GamesSegaCDPluginClass))

typedef struct _GamesSegaCDPlugin GamesSegaCDPlugin;
typedef struct _GamesSegaCDPluginClass GamesSegaCDPluginClass;
typedef struct _GamesSegaCDPluginPrivate GamesSegaCDPluginPrivate;
#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_CD_HEADER (games_sega_cd_header_get_type ())
#define GAMES_SEGA_CD_HEADER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_SEGA_CD_HEADER, GamesSegaCDHeader))
#define GAMES_SEGA_CD_HEADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_SEGA_CD_HEADER, GamesSegaCDHeaderClass))
#define GAMES_IS_SEGA_CD_HEADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_SEGA_CD_HEADER))
#define GAMES_IS_SEGA_CD_HEADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_SEGA_CD_HEADER))
#define GAMES_SEGA_CD_HEADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_SEGA_CD_HEADER, GamesSegaCDHeaderClass))

typedef struct _GamesSegaCDHeader GamesSegaCDHeader;
typedef struct _GamesSegaCDHeaderClass GamesSegaCDHeaderClass;
#define _games_uri_unref0(var) ((var == NULL) ? NULL : (var = (games_uri_unref (var), NULL)))

struct _GamesSegaCDPlugin {
	GObject parent_instance;
	GamesSegaCDPluginPrivate * priv;
};

struct _GamesSegaCDPluginClass {
	GObjectClass parent_class;
};

typedef enum  {
	GAMES_SEGA_CD_ERROR_INVALID_HEADER,
	GAMES_SEGA_CD_ERROR_INVALID_CUE_SHEET,
	GAMES_SEGA_CD_ERROR_INVALID_FILE_TYPE
} GamesSegaCDError;
#define GAMES_SEGA_CD_ERROR games_sega_cd_error_quark ()

static gpointer games_sega_cd_plugin_parent_class = NULL;
static GamesPluginIface * games_sega_cd_plugin_games_plugin_parent_iface = NULL;
static GType games_sega_cd_plugin_type_id = 0;

GType games_sega_cd_plugin_get_type (void) G_GNUC_CONST;
enum  {
	GAMES_SEGA_CD_PLUGIN_0_PROPERTY
};
#define GAMES_SEGA_CD_PLUGIN_32X_MIME_TYPE "application/x-genesis-32x-rom"
#define GAMES_SEGA_CD_PLUGIN_SEGA_CD_PREFIX "mega-cd"
#define GAMES_SEGA_CD_PLUGIN_CUE_MIME_TYPE "application/x-cue"
#define GAMES_SEGA_CD_PLUGIN_SEGA_CD_MIME_TYPE "application/x-sega-cd-rom"
#define GAMES_SEGA_CD_PLUGIN_SEGA_CD_PLATFORM "SegaCD"
#define GAMES_SEGA_CD_PLUGIN_SEGA_CD_32X_PLATFORM "SegaCD32X"
static gchar** games_sega_cd_plugin_real_get_mime_types (GamesPlugin* base, int* result_length1);
static GamesUriGameFactory** games_sega_cd_plugin_real_get_uri_game_factories (GamesPlugin* base, int* result_length1);
static GamesGame* games_sega_cd_plugin_game_for_uri (GamesUri* uri, GError** error);
static GamesGame* _games_sega_cd_plugin_game_for_uri_games_generic_game_uri_adapter_game_for_uri (GamesUri* uri, gpointer self, GError** error);
static GFile* games_sega_cd_plugin_get_binary_file (GamesCueSheet* cue, GError** error);
GQuark games_sega_cd_error_quark (void);
GType games_sega_cd_header_get_type (void) G_GNUC_CONST;
GamesSegaCDHeader* games_sega_cd_header_new (GFile* file);
GamesSegaCDHeader* games_sega_cd_header_construct (GType object_type, GFile* file);
void games_sega_cd_header_check_validity (GamesSegaCDHeader* self, GError** error);
gboolean games_sega_cd_header_is_sega_cd (GamesSegaCDHeader* self);
gboolean games_sega_cd_header_is_sega_cd_32x (GamesSegaCDHeader* self);
gsize games_sega_cd_header_get_offset (GamesSegaCDHeader* self, GError** error);
#define GAMES_SEGA_CD_HEADER_HEADER_LENGTH ((gsize) 0x200)
GamesSegaCDPlugin* games_sega_cd_plugin_new (void);
GamesSegaCDPlugin* games_sega_cd_plugin_construct (GType object_type);
GType register_games_plugin (GTypeModule* module);
GType games_sega_cd_header_register_type (GTypeModule * module);
GType games_sega_cd_plugin_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_cd_plugin_real_get_mime_types (GamesPlugin* base, int* result_length1) {
	GamesSegaCDPlugin * self;
	gchar** result = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar** _tmp2_;
	gchar** _tmp3_;
	gint _tmp3__length1;
	self = (GamesSegaCDPlugin*) base;
	_tmp0_ = g_strdup (GAMES_SEGA_CD_PLUGIN_CUE_MIME_TYPE);
	_tmp1_ = g_strdup (GAMES_SEGA_CD_PLUGIN_SEGA_CD_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_cd_plugin_game_for_uri_games_generic_game_uri_adapter_game_for_uri (GamesUri* uri, gpointer self, GError** error) {
	GamesGame* result;
	result = games_sega_cd_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_cd_plugin_real_get_uri_game_factories (GamesPlugin* base, int* result_length1) {
	GamesSegaCDPlugin * 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 = (GamesSegaCDPlugin*) base;
	_tmp0_ = games_generic_game_uri_adapter_new (_games_sega_cd_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_CD_PLUGIN_CUE_MIME_TYPE);
	games_generic_uri_game_factory_add_mime_type (factory, GAMES_SEGA_CD_PLUGIN_SEGA_CD_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_cd_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;
	GamesSegaCDHeader* header = NULL;
	GFile* _tmp25_;
	GamesSegaCDHeader* _tmp26_;
	GamesSegaCDHeader* _tmp27_;
	gchar** mime_types = NULL;
	gint mime_types_length1 = 0;
	gint _mime_types_size_ = 0;
	gchar* platform = NULL;
	GamesSegaCDHeader* _tmp28_;
	gboolean _tmp29_;
	GamesUri* bin_uri = NULL;
	GFile* _tmp41_;
	gchar* _tmp42_;
	gchar* _tmp43_;
	GamesUri* _tmp44_;
	GamesUri* _tmp45_;
	gsize header_offset = 0UL;
	GamesSegaCDHeader* _tmp46_;
	gsize _tmp47_;
	GamesFingerprintUid* uid = NULL;
	GamesUri* _tmp48_;
	gsize _tmp49_;
	GamesFingerprintUid* _tmp50_;
	GamesFilenameTitle* title = NULL;
	GamesUri* _tmp51_;
	GamesFilenameTitle* _tmp52_;
	GamesDummyIcon* icon = NULL;
	GamesDummyIcon* _tmp53_;
	GamesGriloMedia* media = NULL;
	GamesFilenameTitle* _tmp54_;
	GamesGriloMedia* _tmp55_;
	GamesCompositeCover* cover = NULL;
	GamesUri* _tmp56_;
	GamesLocalCover* _tmp57_;
	GamesGriloMedia* _tmp58_;
	GamesFingerprintUid* _tmp59_;
	GamesGriloCover* _tmp60_;
	GamesCover** _tmp61_;
	GamesCover** _tmp62_;
	gint _tmp62__length1;
	GamesCompositeCover* _tmp63_;
	GamesCompositeCover* _tmp64_;
	GamesRetroCoreSource* core_source = NULL;
	const gchar* _tmp65_;
	gchar** _tmp66_;
	gint _tmp66__length1;
	GamesRetroCoreSource* _tmp67_;
	GamesRetroRunner* runner = NULL;
	GamesRetroCoreSource* _tmp68_;
	GamesUri* _tmp69_;
	GamesFingerprintUid* _tmp70_;
	GamesFilenameTitle* _tmp71_;
	GamesRetroRunner* _tmp72_;
	GamesFilenameTitle* _tmp73_;
	GamesDummyIcon* _tmp74_;
	GamesCompositeCover* _tmp75_;
	GamesRetroRunner* _tmp76_;
	GamesGenericGame* _tmp77_;
	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_CD_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_cd_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_CD_PLUGIN_SEGA_CD_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_CD_ERROR, GAMES_SEGA_CD_ERROR_INVALID_FILE_TYPE, "Invalid file type: expected %s or %s but got %s for file %s.", GAMES_SEGA_CD_PLUGIN_CUE_MIME_TYPE, GAMES_SEGA_CD_PLUGIN_SEGA_CD_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_cd_header_new (_tmp25_);
	header = _tmp26_;
	_tmp27_ = header;
	games_sega_cd_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_cd_header_is_sega_cd (_tmp28_);
	if (_tmp29_) {
		gchar* _tmp30_;
		gchar* _tmp31_;
		gchar** _tmp32_;
		gchar* _tmp33_;
		_tmp30_ = g_strdup (GAMES_SEGA_CD_PLUGIN_CUE_MIME_TYPE);
		_tmp31_ = g_strdup (GAMES_SEGA_CD_PLUGIN_SEGA_CD_MIME_TYPE);
		_tmp32_ = g_new0 (gchar*, 2 + 1);
		_tmp32_[0] = _tmp30_;
		_tmp32_[1] = _tmp31_;
		mime_types = (_vala_array_free (mime_types, mime_types_length1, (GDestroyNotify) g_free), NULL);
		mime_types = _tmp32_;
		mime_types_length1 = 2;
		_mime_types_size_ = mime_types_length1;
		_tmp33_ = g_strdup (GAMES_SEGA_CD_PLUGIN_SEGA_CD_PLATFORM);
		_g_free0 (platform);
		platform = _tmp33_;
	} else {
		GamesSegaCDHeader* _tmp34_;
		gboolean _tmp35_;
		_tmp34_ = header;
		_tmp35_ = games_sega_cd_header_is_sega_cd_32x (_tmp34_);
		if (_tmp35_) {
			gchar* _tmp36_;
			gchar* _tmp37_;
			gchar* _tmp38_;
			gchar** _tmp39_;
			gchar* _tmp40_;
			_tmp36_ = g_strdup (GAMES_SEGA_CD_PLUGIN_CUE_MIME_TYPE);
			_tmp37_ = g_strdup (GAMES_SEGA_CD_PLUGIN_SEGA_CD_MIME_TYPE);
			_tmp38_ = g_strdup (GAMES_SEGA_CD_PLUGIN_32X_MIME_TYPE);
			_tmp39_ = g_new0 (gchar*, 3 + 1);
			_tmp39_[0] = _tmp36_;
			_tmp39_[1] = _tmp37_;
			_tmp39_[2] = _tmp38_;
			mime_types = (_vala_array_free (mime_types, mime_types_length1, (GDestroyNotify) g_free), NULL);
			mime_types = _tmp39_;
			mime_types_length1 = 3;
			_mime_types_size_ = mime_types_length1;
			_tmp40_ = g_strdup (GAMES_SEGA_CD_PLUGIN_SEGA_CD_32X_PLATFORM);
			_g_free0 (platform);
			platform = _tmp40_;
		} else {
			g_assert_not_reached ();
		}
	}
	_tmp41_ = bin_file;
	_tmp42_ = g_file_get_uri (_tmp41_);
	_tmp43_ = _tmp42_;
	_tmp44_ = games_uri_new (_tmp43_);
	_tmp45_ = _tmp44_;
	_g_free0 (_tmp43_);
	bin_uri = _tmp45_;
	_tmp46_ = header;
	_tmp47_ = games_sega_cd_header_get_offset (_tmp46_, &_inner_error_);
	header_offset = _tmp47_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_games_uri_unref0 (bin_uri);
		_g_free0 (platform);
		mime_types = (_vala_array_free (mime_types, mime_types_length1, (GDestroyNotify) g_free), NULL);
		_g_object_unref0 (header);
		_g_object_unref0 (bin_file);
		_g_free0 (mime_type);
		_g_object_unref0 (file_info);
		_g_object_unref0 (file);
		return NULL;
	}
	_tmp48_ = bin_uri;
	_tmp49_ = header_offset;
	_tmp50_ = games_fingerprint_uid_new_for_chunk (_tmp48_, GAMES_SEGA_CD_PLUGIN_SEGA_CD_PREFIX, _tmp49_, GAMES_SEGA_CD_HEADER_HEADER_LENGTH);
	uid = _tmp50_;
	_tmp51_ = uri;
	_tmp52_ = games_filename_title_new (_tmp51_);
	title = _tmp52_;
	_tmp53_ = games_dummy_icon_new ();
	icon = _tmp53_;
	_tmp54_ = title;
	_tmp55_ = games_grilo_media_new ((GamesTitle*) _tmp54_, GAMES_SEGA_CD_PLUGIN_SEGA_CD_MIME_TYPE);
	media = _tmp55_;
	_tmp56_ = uri;
	_tmp57_ = games_local_cover_new (_tmp56_);
	_tmp58_ = media;
	_tmp59_ = uid;
	_tmp60_ = games_grilo_cover_new (_tmp58_, (GamesUid*) _tmp59_);
	_tmp61_ = g_new0 (GamesCover*, 2 + 1);
	_tmp61_[0] = (GamesCover*) _tmp57_;
	_tmp61_[1] = (GamesCover*) _tmp60_;
	_tmp62_ = _tmp61_;
	_tmp62__length1 = 2;
	_tmp63_ = games_composite_cover_new (_tmp62_, 2);
	_tmp64_ = _tmp63_;
	_tmp62_ = (_vala_array_free (_tmp62_, _tmp62__length1, (GDestroyNotify) g_object_unref), NULL);
	cover = _tmp64_;
	_tmp65_ = platform;
	_tmp66_ = mime_types;
	_tmp66__length1 = mime_types_length1;
	_tmp67_ = games_retro_core_source_new (_tmp65_, _tmp66_, _tmp66__length1);
	core_source = _tmp67_;
	_tmp68_ = core_source;
	_tmp69_ = uri;
	_tmp70_ = uid;
	_tmp71_ = title;
	_tmp72_ = games_retro_runner_new (_tmp68_, _tmp69_, (GamesUid*) _tmp70_, (GamesTitle*) _tmp71_);
	runner = _tmp72_;
	_tmp73_ = title;
	_tmp74_ = icon;
	_tmp75_ = cover;
	_tmp76_ = runner;
	_tmp77_ = games_generic_game_new ((GamesTitle*) _tmp73_, (GamesIcon*) _tmp74_, (GamesCover*) _tmp75_, (GamesRunner*) _tmp76_);
	result = (GamesGame*) _tmp77_;
	_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);
	_games_uri_unref0 (bin_uri);
	_g_free0 (platform);
	mime_types = (_vala_array_free (mime_types, mime_types_length1, (GDestroyNotify) g_free), NULL);
	_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_cd_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_;
	GamesSegaCDHeader* header = NULL;
	GamesCueSheetFileNode* _tmp44_;
	GFile* _tmp45_;
	GFile* _tmp46_;
	GamesSegaCDHeader* _tmp47_;
	GamesSegaCDHeader* _tmp48_;
	GamesCueSheetFileNode* _tmp49_;
	GFile* _tmp50_;
	GFile* _tmp51_;
	GFile* _tmp52_;
	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_CD_ERROR, GAMES_SEGA_CD_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_CD_ERROR, GAMES_SEGA_CD_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_CD_ERROR, GAMES_SEGA_CD_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_ = games_sega_cd_header_new (_tmp46_);
	header = _tmp47_;
	_tmp48_ = header;
	games_sega_cd_header_check_validity (_tmp48_, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (header);
		_g_object_unref0 (file);
		_g_object_unref0 (track);
		return NULL;
	}
	_tmp49_ = file;
	_tmp50_ = games_cue_sheet_file_node_get_file (_tmp49_);
	_tmp51_ = _tmp50_;
	_tmp52_ = _g_object_ref0 (_tmp51_);
	result = _tmp52_;
	_g_object_unref0 (header);
	_g_object_unref0 (file);
	_g_object_unref0 (track);
	return result;
}


GamesSegaCDPlugin* games_sega_cd_plugin_construct (GType object_type) {
	GamesSegaCDPlugin * self = NULL;
	self = (GamesSegaCDPlugin*) g_object_new (object_type, NULL);
	return self;
}


GamesSegaCDPlugin* games_sega_cd_plugin_new (void) {
	return games_sega_cd_plugin_construct (GAMES_TYPE_SEGA_CD_PLUGIN);
}


static void games_sega_cd_plugin_class_init (GamesSegaCDPluginClass * klass) {
	games_sega_cd_plugin_parent_class = g_type_class_peek_parent (klass);
}


static void games_sega_cd_plugin_games_plugin_interface_init (GamesPluginIface * iface) {
	games_sega_cd_plugin_games_plugin_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_mime_types = (gchar** (*) (GamesPlugin *, int*)) games_sega_cd_plugin_real_get_mime_types;
	iface->get_uri_game_factories = (GamesUriGameFactory** (*) (GamesPlugin *, int*)) games_sega_cd_plugin_real_get_uri_game_factories;
}


static void games_sega_cd_plugin_instance_init (GamesSegaCDPlugin * self) {
}


GType games_sega_cd_plugin_get_type (void) {
	return games_sega_cd_plugin_type_id;
}


GType games_sega_cd_plugin_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (GamesSegaCDPluginClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_sega_cd_plugin_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesSegaCDPlugin), 0, (GInstanceInitFunc) games_sega_cd_plugin_instance_init, NULL };
	static const GInterfaceInfo games_plugin_info = { (GInterfaceInitFunc) games_sega_cd_plugin_games_plugin_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	games_sega_cd_plugin_type_id = g_type_module_register_type (module, G_TYPE_OBJECT, "GamesSegaCDPlugin", &g_define_type_info, 0);
	g_type_module_add_interface (module, games_sega_cd_plugin_type_id, GAMES_TYPE_PLUGIN, &games_plugin_info);
	return games_sega_cd_plugin_type_id;
}


GType register_games_plugin (GTypeModule* module) {
	GType result = 0UL;
	g_return_val_if_fail (module != NULL, 0UL);
	games_sega_cd_header_register_type (module);
	games_sega_cd_plugin_register_type (module);
	result = GAMES_TYPE_SEGA_CD_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);
}



