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

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

#include <glib-object.h>
#include "gnome-games.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include "games-love-plugin.h"

#define GAMES_LOVE_PLUGIN_MIME_TYPE "application/x-love-game"
#define GAMES_LOVE_PLUGIN_PLATFORM_ID "LOVE"
#define GAMES_LOVE_PLUGIN_PLATFORM_NAME _ ("LÖVE")
#define GAMES_LOVE_PLUGIN_PLATFORM_UID_PREFIX "love"
#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_LOVE_PLUGIN (games_love_plugin_get_type ())
#define GAMES_LOVE_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_LOVE_PLUGIN, GamesLovePlugin))
#define GAMES_LOVE_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_LOVE_PLUGIN, GamesLovePluginClass))
#define GAMES_IS_LOVE_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_LOVE_PLUGIN))
#define GAMES_IS_LOVE_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_LOVE_PLUGIN))
#define GAMES_LOVE_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_LOVE_PLUGIN, GamesLovePluginClass))

typedef struct _GamesLovePlugin GamesLovePlugin;
typedef struct _GamesLovePluginClass GamesLovePluginClass;
typedef struct _GamesLovePluginPrivate GamesLovePluginPrivate;
enum  {
	GAMES_LOVE_PLUGIN_0_PROPERTY,
	GAMES_LOVE_PLUGIN_NUM_PROPERTIES
};
static GParamSpec* games_love_plugin_properties[GAMES_LOVE_PLUGIN_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define GAMES_TYPE_LOVE_PACKAGE (games_love_package_get_type ())
#define GAMES_LOVE_PACKAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_LOVE_PACKAGE, GamesLovePackage))
#define GAMES_LOVE_PACKAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_LOVE_PACKAGE, GamesLovePackageClass))
#define GAMES_IS_LOVE_PACKAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_LOVE_PACKAGE))
#define GAMES_IS_LOVE_PACKAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_LOVE_PACKAGE))
#define GAMES_LOVE_PACKAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_LOVE_PACKAGE, GamesLovePackageClass))

typedef struct _GamesLovePackage GamesLovePackage;
typedef struct _GamesLovePackageClass GamesLovePackageClass;
#define _g_free0(var) (var = (g_free (var), NULL))

#define GAMES_TYPE_LOVE_TITLE (games_love_title_get_type ())
#define GAMES_LOVE_TITLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_LOVE_TITLE, GamesLoveTitle))
#define GAMES_LOVE_TITLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_LOVE_TITLE, GamesLoveTitleClass))
#define GAMES_IS_LOVE_TITLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_LOVE_TITLE))
#define GAMES_IS_LOVE_TITLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_LOVE_TITLE))
#define GAMES_LOVE_TITLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_LOVE_TITLE, GamesLoveTitleClass))

typedef struct _GamesLoveTitle GamesLoveTitle;
typedef struct _GamesLoveTitleClass GamesLoveTitleClass;

#define GAMES_TYPE_LOVE_ICON (games_love_icon_get_type ())
#define GAMES_LOVE_ICON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_LOVE_ICON, GamesLoveIcon))
#define GAMES_LOVE_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_LOVE_ICON, GamesLoveIconClass))
#define GAMES_IS_LOVE_ICON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_LOVE_ICON))
#define GAMES_IS_LOVE_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_LOVE_ICON))
#define GAMES_LOVE_ICON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_LOVE_ICON, GamesLoveIconClass))

typedef struct _GamesLoveIcon GamesLoveIcon;
typedef struct _GamesLoveIconClass GamesLoveIconClass;

struct _GamesLovePlugin {
	GObject parent_instance;
	GamesLovePluginPrivate * priv;
};

struct _GamesLovePluginClass {
	GObjectClass parent_class;
};

static gpointer games_love_plugin_parent_class = NULL;
static GamesPlatform* games_love_plugin_platform;
static GamesPlatform* games_love_plugin_platform = NULL;
static GamesPluginIface * games_love_plugin_games_plugin_parent_iface = NULL;
static GType games_love_plugin_type_id = 0;

GType games_love_plugin_register_type (GTypeModule * module);
VALA_EXTERN GType games_love_plugin_get_type (void) G_GNUC_CONST ;
static GamesPlatform** games_love_plugin_real_get_platforms (GamesPlugin* base,
                                                      gint* result_length1);
static gchar** games_love_plugin_real_get_mime_types (GamesPlugin* base,
                                               gint* result_length1);
static GamesUriGameFactory** games_love_plugin_real_get_uri_game_factories (GamesPlugin* base,
                                                                     gint* result_length1);
static GamesGame* games_love_plugin_game_for_uri (GamesUri* uri,
                                           GError** error);
static GamesGame* _games_love_plugin_game_for_uri_games_generic_game_uri_adapter_game_for_uri (GamesUri* uri,
                                                                                        gpointer self,
                                                                                        GError** error);
static GamesRunnerFactory** games_love_plugin_real_get_runner_factories (GamesPlugin* base,
                                                                  gint* result_length1);
static GamesRunner* games_love_plugin_create_runner (GamesGame* game,
                                              GError** error);
static GamesRunner* _games_love_plugin_create_runner_games_generic_runner_factory_create_runner (GamesGame* game,
                                                                                          gpointer self,
                                                                                          GError** error);
GType games_love_package_register_type (GTypeModule * module);
VALA_EXTERN GType games_love_package_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GamesLovePackage* games_love_package_new (GamesUri* uri,
                                          GError** error);
VALA_EXTERN GamesLovePackage* games_love_package_construct (GType object_type,
                                                GamesUri* uri,
                                                GError** error);
GType games_love_title_register_type (GTypeModule * module);
VALA_EXTERN GType games_love_title_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GamesLoveTitle* games_love_title_new (GamesLovePackage* package);
VALA_EXTERN GamesLoveTitle* games_love_title_construct (GType object_type,
                                            GamesLovePackage* package);
GType games_love_icon_register_type (GTypeModule * module);
VALA_EXTERN GType games_love_icon_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GamesLoveIcon* games_love_icon_new (GamesLovePackage* package);
VALA_EXTERN GamesLoveIcon* games_love_icon_construct (GType object_type,
                                          GamesLovePackage* package);
VALA_EXTERN GamesLovePlugin* games_love_plugin_new (void);
VALA_EXTERN GamesLovePlugin* games_love_plugin_construct (GType object_type);
static void games_love_plugin_finalize (GObject * obj);
GType games_love_icon_register_type (GTypeModule * module);
GType games_love_package_register_type (GTypeModule * module);
GType games_love_title_register_type (GTypeModule * module);
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 gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static GamesPlatform**
games_love_plugin_real_get_platforms (GamesPlugin* base,
                                      gint* result_length1)
{
	GamesLovePlugin * self;
	GamesPlatform* _tmp0_;
	GamesPlatform* _tmp1_;
	GamesPlatform** _tmp2_;
	GamesPlatform** _tmp3_;
	gint _tmp3__length1;
	GamesPlatform** result;
	self = (GamesLovePlugin*) base;
	_tmp0_ = games_love_plugin_platform;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_tmp2_ = g_new0 (GamesPlatform*, 1 + 1);
	_tmp2_[0] = _tmp1_;
	_tmp3_ = _tmp2_;
	_tmp3__length1 = 1;
	if (result_length1) {
		*result_length1 = _tmp3__length1;
	}
	result = _tmp3_;
	return result;
}

static gchar**
games_love_plugin_real_get_mime_types (GamesPlugin* base,
                                       gint* result_length1)
{
	GamesLovePlugin * self;
	gchar* _tmp0_;
	gchar** _tmp1_;
	gchar** _tmp2_;
	gint _tmp2__length1;
	gchar** result;
	self = (GamesLovePlugin*) base;
	_tmp0_ = g_strdup (GAMES_LOVE_PLUGIN_MIME_TYPE);
	_tmp1_ = g_new0 (gchar*, 1 + 1);
	_tmp1_[0] = _tmp0_;
	_tmp2_ = _tmp1_;
	_tmp2__length1 = 1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

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

static GamesUriGameFactory**
games_love_plugin_real_get_uri_game_factories (GamesPlugin* base,
                                               gint* result_length1)
{
	GamesLovePlugin * self;
	GamesGenericGameUriAdapter* game_uri_adapter = NULL;
	GamesGenericGameUriAdapter* _tmp0_;
	GamesGenericUriGameFactory* factory = NULL;
	GamesGenericUriGameFactory* _tmp1_;
	GamesUriGameFactory* _tmp2_;
	GamesUriGameFactory** _tmp3_;
	GamesUriGameFactory** _tmp4_;
	gint _tmp4__length1;
	GamesUriGameFactory** result;
	self = (GamesLovePlugin*) base;
	_tmp0_ = games_generic_game_uri_adapter_new (_games_love_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_LOVE_PLUGIN_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 GamesRunner*
_games_love_plugin_create_runner_games_generic_runner_factory_create_runner (GamesGame* game,
                                                                             gpointer self,
                                                                             GError** error)
{
	GamesRunner* result;
	result = games_love_plugin_create_runner (game, error);
	return result;
}

static GamesRunnerFactory**
games_love_plugin_real_get_runner_factories (GamesPlugin* base,
                                             gint* result_length1)
{
	GamesLovePlugin * self;
	GamesGenericRunnerFactory* factory = NULL;
	GamesGenericRunnerFactory* _tmp0_;
	GamesPlatform* _tmp1_;
	GamesRunnerFactory* _tmp2_;
	GamesRunnerFactory** _tmp3_;
	GamesRunnerFactory** _tmp4_;
	gint _tmp4__length1;
	GamesRunnerFactory** result;
	self = (GamesLovePlugin*) base;
	_tmp0_ = games_generic_runner_factory_new (_games_love_plugin_create_runner_games_generic_runner_factory_create_runner, NULL, NULL);
	factory = _tmp0_;
	_tmp1_ = games_love_plugin_platform;
	games_generic_runner_factory_add_platform (factory, _tmp1_);
	_tmp2_ = _g_object_ref0 ((GamesRunnerFactory*) factory);
	_tmp3_ = g_new0 (GamesRunnerFactory*, 1 + 1);
	_tmp3_[0] = _tmp2_;
	_tmp4_ = _tmp3_;
	_tmp4__length1 = 1;
	if (result_length1) {
		*result_length1 = _tmp4__length1;
	}
	result = _tmp4_;
	_g_object_unref0 (factory);
	return result;
}

static GamesGame*
games_love_plugin_game_for_uri (GamesUri* uri,
                                GError** error)
{
	gchar* _tmp0_ = NULL;
	gchar* _tmp1_;
	GamesUid* uid = NULL;
	GamesUid* _tmp2_;
	GamesLovePackage* package = NULL;
	GamesLovePackage* _tmp3_;
	GamesLoveTitle* title = NULL;
	GamesLovePackage* _tmp4_;
	GamesLoveTitle* _tmp5_;
	GamesLoveIcon* icon = NULL;
	GamesLovePackage* _tmp6_;
	GamesLoveIcon* _tmp7_;
	GamesLocalCover* cover = NULL;
	GamesLocalCover* _tmp8_;
	GamesGame* game = NULL;
	GamesUid* _tmp9_;
	GamesLoveTitle* _tmp10_;
	GamesPlatform* _tmp11_;
	GamesGame* _tmp12_;
	GamesGame* _tmp13_;
	GamesLoveIcon* _tmp14_;
	GamesGame* _tmp15_;
	GamesLocalCover* _tmp16_;
	GError* _inner_error0_ = NULL;
	GamesGame* result;
	g_return_val_if_fail (uri != NULL, NULL);
	_tmp1_ = games_fingerprint_get_uid (uri, GAMES_LOVE_PLUGIN_PLATFORM_UID_PREFIX, &_inner_error0_);
	_tmp0_ = _tmp1_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return NULL;
	}
	_tmp2_ = games_uid_new (_tmp0_);
	uid = _tmp2_;
	_tmp3_ = games_love_package_new (uri, &_inner_error0_);
	package = _tmp3_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (uid);
		_g_free0 (_tmp0_);
		return NULL;
	}
	_tmp4_ = package;
	_tmp5_ = games_love_title_new (_tmp4_);
	title = _tmp5_;
	_tmp6_ = package;
	_tmp7_ = games_love_icon_new (_tmp6_);
	icon = _tmp7_;
	_tmp8_ = games_local_cover_new (uri);
	cover = _tmp8_;
	_tmp9_ = uid;
	_tmp10_ = title;
	_tmp11_ = games_love_plugin_platform;
	_tmp12_ = games_game_new (_tmp9_, uri, (GamesTitle*) _tmp10_, _tmp11_);
	game = _tmp12_;
	_tmp13_ = game;
	_tmp14_ = icon;
	games_game_set_icon (_tmp13_, (GamesIcon*) _tmp14_);
	_tmp15_ = game;
	_tmp16_ = cover;
	games_game_set_cover (_tmp15_, (GamesCover*) _tmp16_);
	result = game;
	_g_object_unref0 (cover);
	_g_object_unref0 (icon);
	_g_object_unref0 (title);
	_g_object_unref0 (package);
	_g_object_unref0 (uid);
	_g_free0 (_tmp0_);
	return result;
}

static GamesRunner*
games_love_plugin_create_runner (GamesGame* game,
                                 GError** error)
{
	gchar** args = NULL;
	gchar* _tmp0_;
	GamesUri* _tmp1_;
	GamesUri* _tmp2_;
	gchar* _tmp3_;
	gchar** _tmp4_;
	gint args_length1;
	gint _args_size_;
	GamesCommandRunner* _tmp5_;
	GamesRunner* result;
	g_return_val_if_fail (game != NULL, NULL);
	_tmp0_ = g_strdup ("love");
	_tmp1_ = games_game_get_uri (game);
	_tmp2_ = _tmp1_;
	_tmp3_ = games_uri_to_string (_tmp2_);
	_tmp4_ = g_new0 (gchar*, 2 + 1);
	_tmp4_[0] = _tmp0_;
	_tmp4_[1] = _tmp3_;
	args = _tmp4_;
	args_length1 = 2;
	_args_size_ = args_length1;
	_tmp5_ = games_command_runner_new (args, args_length1);
	result = (GamesRunner*) _tmp5_;
	args = (_vala_array_free (args, args_length1, (GDestroyNotify) g_free), NULL);
	return result;
}

GamesLovePlugin*
games_love_plugin_construct (GType object_type)
{
	GamesLovePlugin * self = NULL;
	self = (GamesLovePlugin*) g_object_new (object_type, NULL);
	return self;
}

GamesLovePlugin*
games_love_plugin_new (void)
{
	return games_love_plugin_construct (GAMES_TYPE_LOVE_PLUGIN);
}

static void
games_love_plugin_class_init (GamesLovePluginClass * klass,
                              gpointer klass_data)
{
	GamesGenericPlatform* _tmp0_;
	games_love_plugin_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = games_love_plugin_finalize;
	_tmp0_ = games_generic_platform_new (GAMES_LOVE_PLUGIN_PLATFORM_ID, GAMES_LOVE_PLUGIN_PLATFORM_NAME, GAMES_LOVE_PLUGIN_PLATFORM_UID_PREFIX);
	_g_object_unref0 (games_love_plugin_platform);
	games_love_plugin_platform = (GamesPlatform*) _tmp0_;
}

static void
games_love_plugin_games_plugin_interface_init (GamesPluginIface * iface,
                                               gpointer iface_data)
{
	games_love_plugin_games_plugin_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_platforms = (GamesPlatform** (*) (GamesPlugin*, gint*)) games_love_plugin_real_get_platforms;
	iface->get_mime_types = (gchar** (*) (GamesPlugin*, gint*)) games_love_plugin_real_get_mime_types;
	iface->get_uri_game_factories = (GamesUriGameFactory** (*) (GamesPlugin*, gint*)) games_love_plugin_real_get_uri_game_factories;
	iface->get_runner_factories = (GamesRunnerFactory** (*) (GamesPlugin*, gint*)) games_love_plugin_real_get_runner_factories;
}

static void
games_love_plugin_instance_init (GamesLovePlugin * self,
                                 gpointer klass)
{
}

static void
games_love_plugin_finalize (GObject * obj)
{
	GamesLovePlugin * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_LOVE_PLUGIN, GamesLovePlugin);
	G_OBJECT_CLASS (games_love_plugin_parent_class)->finalize (obj);
}

GType
games_love_plugin_get_type (void)
{
	return games_love_plugin_type_id;
}

GType
games_love_plugin_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (GamesLovePluginClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_love_plugin_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesLovePlugin), 0, (GInstanceInitFunc) games_love_plugin_instance_init, NULL };
	static const GInterfaceInfo games_plugin_info = { (GInterfaceInitFunc) games_love_plugin_games_plugin_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	games_love_plugin_type_id = g_type_module_register_type (module, G_TYPE_OBJECT, "GamesLovePlugin", &g_define_type_info, 0);
	g_type_module_add_interface (module, games_love_plugin_type_id, GAMES_TYPE_PLUGIN, &games_plugin_info);
	return games_love_plugin_type_id;
}

GType
register_games_plugin (GTypeModule* module)
{
	GType result;
	g_return_val_if_fail (module != NULL, 0UL);
	games_love_icon_register_type (module);
	games_love_package_register_type (module);
	games_love_plugin_register_type (module);
	games_love_title_register_type (module);
	result = GAMES_TYPE_LOVE_PLUGIN;
	return result;
}

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;
}

