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

/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 *
 * Copyright © 2016 Michael Catanzaro <mcatanzaro@gnome.org>
 *
 * This file is part of libgnome-games-support.
 *
 * libgnome-games-support is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * libgnome-games-support is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with libgnome-games-support.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "libgnome-games-support.h"
#include <glib.h>
#include <gio/gio.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>

#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

enum  {
	GAMES_SCORES_DIRECTORY_IMPORTER_0_PROPERTY,
	GAMES_SCORES_DIRECTORY_IMPORTER_NUM_PROPERTIES
};
static GParamSpec* games_scores_directory_importer_properties[GAMES_SCORES_DIRECTORY_IMPORTER_NUM_PROPERTIES];
typedef struct _Block7Data Block7Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _GamesScoresDirectoryImporterPrivate {
	GamesScoresDirectoryImporterCategoryConvertFunc category_convert;
	gpointer category_convert_target;
	GDestroyNotify category_convert_target_destroy_notify;
};

struct _Block7Data {
	int _ref_count_;
	GamesScoresDirectoryImporter* self;
	GamesScoresDirectoryImporterCategoryConvertFunc category_convert;
	gpointer category_convert_target;
};

static gint GamesScoresDirectoryImporter_private_offset;
static gpointer games_scores_directory_importer_parent_class = NULL;

static gchar* __lambda15_ (GamesScoresDirectoryImporter* self,
                    const gchar* old_key);
static gchar* ___lambda15__games_scores_directory_importer_category_convert_func (const gchar* old_key,
                                                                           gpointer self);
static Block7Data* block7_data_ref (Block7Data* _data7_);
static void block7_data_unref (void * _userdata_);
static gchar* __lambda14_ (Block7Data* _data7_,
                    const gchar* old_key);
static gchar* ___lambda14__games_scores_directory_importer_category_convert_func (const gchar* old_key,
                                                                           gpointer self);
static void games_scores_directory_importer_real_importOldScores (GamesScoresImporter* base,
                                                           GamesScoresContext* context,
                                                           GFile* new_scores_dir,
                                                           GError** error);
static GObject * games_scores_directory_importer_constructor (GType type,
                                                       guint n_construct_properties,
                                                       GObjectConstructParam * construct_properties);
static void _games_scores_directory_importer___lambda16_ (GamesScoresDirectoryImporter* self);
static void __games_scores_directory_importer___lambda16__games_scores_importer_finished (GamesScoresImporter* _sender,
                                                                                   gpointer self);
static void games_scores_directory_importer_finalize (GObject * obj);
static GType games_scores_directory_importer_get_type_once (void);

static inline gpointer
games_scores_directory_importer_get_instance_private (GamesScoresDirectoryImporter* self)
{
	return G_STRUCT_MEMBER_P (self, GamesScoresDirectoryImporter_private_offset);
}

static gchar*
__lambda15_ (GamesScoresDirectoryImporter* self,
             const gchar* old_key)
{
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (old_key != NULL, NULL);
	_tmp0_ = g_strdup (old_key);
	result = _tmp0_;
	return result;
}

static gchar*
___lambda15__games_scores_directory_importer_category_convert_func (const gchar* old_key,
                                                                    gpointer self)
{
	gchar* result;
	result = __lambda15_ ((GamesScoresDirectoryImporter*) self, old_key);
	return result;
}

GamesScoresDirectoryImporter*
games_scores_directory_importer_construct (GType object_type)
{
	GamesScoresDirectoryImporter * self = NULL;
	self = (GamesScoresDirectoryImporter*) games_scores_importer_construct (object_type);
	games_scores_directory_importer_set_category_convert_func (self, ___lambda15__games_scores_directory_importer_category_convert_func, self);
	return self;
}

GamesScoresDirectoryImporter*
games_scores_directory_importer_new (void)
{
	return games_scores_directory_importer_construct (GAMES_SCORES_TYPE_DIRECTORY_IMPORTER);
}

GamesScoresDirectoryImporter*
games_scores_directory_importer_construct_with_convert_func (GType object_type,
                                                             GamesScoresDirectoryImporterCategoryConvertFunc category_convert,
                                                             gpointer category_convert_target)
{
	GamesScoresDirectoryImporter * self = NULL;
	self = (GamesScoresDirectoryImporter*) games_scores_importer_construct (object_type);
	games_scores_directory_importer_set_category_convert_func (self, category_convert, category_convert_target);
	return self;
}

GamesScoresDirectoryImporter*
games_scores_directory_importer_new_with_convert_func (GamesScoresDirectoryImporterCategoryConvertFunc category_convert,
                                                       gpointer category_convert_target)
{
	return games_scores_directory_importer_construct_with_convert_func (GAMES_SCORES_TYPE_DIRECTORY_IMPORTER, category_convert, category_convert_target);
}

static Block7Data*
block7_data_ref (Block7Data* _data7_)
{
	g_atomic_int_inc (&_data7_->_ref_count_);
	return _data7_;
}

static void
block7_data_unref (void * _userdata_)
{
	Block7Data* _data7_;
	_data7_ = (Block7Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data7_->_ref_count_)) {
		GamesScoresDirectoryImporter* self;
		self = _data7_->self;
		_g_object_unref0 (self);
		g_slice_free (Block7Data, _data7_);
	}
}

static gchar*
__lambda14_ (Block7Data* _data7_,
             const gchar* old_key)
{
	GamesScoresDirectoryImporter* self;
	gchar* _tmp0_;
	gchar* result;
	self = _data7_->self;
	g_return_val_if_fail (old_key != NULL, NULL);
	_tmp0_ = _data7_->category_convert (old_key, _data7_->category_convert_target);
	result = _tmp0_;
	return result;
}

static gchar*
___lambda14__games_scores_directory_importer_category_convert_func (const gchar* old_key,
                                                                    gpointer self)
{
	gchar* result;
	result = __lambda14_ (self, old_key);
	return result;
}

void
games_scores_directory_importer_set_category_convert_func (GamesScoresDirectoryImporter* self,
                                                           GamesScoresDirectoryImporterCategoryConvertFunc category_convert,
                                                           gpointer category_convert_target)
{
	Block7Data* _data7_;
	g_return_if_fail (self != NULL);
	_data7_ = g_slice_new0 (Block7Data);
	_data7_->_ref_count_ = 1;
	_data7_->self = g_object_ref (self);
	_data7_->category_convert = category_convert;
	_data7_->category_convert_target = category_convert_target;
	(self->priv->category_convert_target_destroy_notify == NULL) ? NULL : (self->priv->category_convert_target_destroy_notify (self->priv->category_convert_target), NULL);
	self->priv->category_convert = NULL;
	self->priv->category_convert_target = NULL;
	self->priv->category_convert_target_destroy_notify = NULL;
	self->priv->category_convert = ___lambda14__games_scores_directory_importer_category_convert_func;
	self->priv->category_convert_target = block7_data_ref (_data7_);
	self->priv->category_convert_target_destroy_notify = block7_data_unref;
	block7_data_unref (_data7_);
	_data7_ = NULL;
}

static void
games_scores_directory_importer_real_importOldScores (GamesScoresImporter* base,
                                                      GamesScoresContext* context,
                                                      GFile* new_scores_dir,
                                                      GError** error)
{
	GamesScoresDirectoryImporter * self;
	GFile* original_scores_dir = NULL;
	GFile* _tmp0_;
	GFile* _tmp1_;
	GFileEnumerator* enumerator = NULL;
	GFile* _tmp2_;
	GFileEnumerator* _tmp3_;
	GFileInfo* file_info = NULL;
	GError* _inner_error0_ = NULL;
	self = (GamesScoresDirectoryImporter*) base;
	g_return_if_fail (context != NULL);
	g_return_if_fail (new_scores_dir != NULL);
	_tmp0_ = g_file_get_parent (new_scores_dir);
	original_scores_dir = _tmp0_;
	_tmp1_ = original_scores_dir;
	_vala_assert (_tmp1_ != NULL, "original_scores_dir != null");
	_tmp2_ = original_scores_dir;
	_tmp3_ = g_file_enumerate_children (_tmp2_, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, &_inner_error0_);
	enumerator = _tmp3_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (original_scores_dir);
		return;
	}
	while (TRUE) {
		GFileInfo* _tmp4_ = NULL;
		GFileEnumerator* _tmp5_;
		GFileInfo* _tmp6_;
		GFileInfo* _tmp7_;
		GFileInfo* _tmp8_;
		GFileInfo* _tmp9_;
		const gchar* _tmp10_;
		gchar* new_key = NULL;
		GamesScoresDirectoryImporterCategoryConvertFunc _tmp11_;
		gpointer _tmp11__target;
		GFileInfo* _tmp12_;
		const gchar* _tmp13_;
		gchar* _tmp14_;
		const gchar* _tmp15_;
		GFile* new_file = NULL;
		const gchar* _tmp16_;
		GFile* _tmp17_;
		GFile* original_file = NULL;
		GFile* _tmp18_;
		GFileInfo* _tmp19_;
		const gchar* _tmp20_;
		GFile* _tmp21_;
		GFile* _tmp22_;
		gchar* _tmp23_;
		gchar* _tmp24_;
		GFile* _tmp25_;
		gchar* _tmp26_;
		gchar* _tmp27_;
		GFile* _tmp28_;
		GFile* _tmp29_;
		GFile* _tmp30_;
		_tmp5_ = enumerator;
		_tmp6_ = g_file_enumerator_next_file (_tmp5_, NULL, &_inner_error0_);
		_tmp4_ = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (file_info);
			_g_object_unref0 (enumerator);
			_g_object_unref0 (original_scores_dir);
			return;
		}
		_tmp7_ = _tmp4_;
		_tmp4_ = NULL;
		_g_object_unref0 (file_info);
		file_info = _tmp7_;
		_tmp8_ = file_info;
		if (!(_tmp8_ != NULL)) {
			_g_object_unref0 (_tmp4_);
			break;
		}
		_tmp9_ = file_info;
		_tmp10_ = g_file_info_get_name (_tmp9_);
		if (g_strcmp0 (_tmp10_, "scores") == 0) {
			_g_object_unref0 (_tmp4_);
			continue;
		}
		_tmp11_ = self->priv->category_convert;
		_tmp11__target = self->priv->category_convert_target;
		_tmp12_ = file_info;
		_tmp13_ = g_file_info_get_name (_tmp12_);
		_tmp14_ = _tmp11_ (_tmp13_, _tmp11__target);
		new_key = _tmp14_;
		_tmp15_ = new_key;
		if (_tmp15_ == NULL) {
			_g_free0 (new_key);
			_g_object_unref0 (_tmp4_);
			continue;
		}
		_tmp16_ = new_key;
		_tmp17_ = g_file_get_child (new_scores_dir, _tmp16_);
		new_file = _tmp17_;
		_tmp18_ = original_scores_dir;
		_tmp19_ = file_info;
		_tmp20_ = g_file_info_get_name (_tmp19_);
		_tmp21_ = g_file_resolve_relative_path (_tmp18_, _tmp20_);
		original_file = _tmp21_;
		_tmp22_ = original_file;
		_tmp23_ = g_file_get_path (_tmp22_);
		_tmp24_ = _tmp23_;
		_tmp25_ = new_file;
		_tmp26_ = g_file_get_path (_tmp25_);
		_tmp27_ = _tmp26_;
		g_debug ("directory-importer.vala:94: Moving scores from %s to %s", _tmp24_, _tmp27_);
		_g_free0 (_tmp27_);
		_g_free0 (_tmp24_);
		_tmp28_ = original_file;
		_tmp29_ = new_file;
		g_file_copy (_tmp28_, _tmp29_, G_FILE_COPY_NONE, NULL, NULL, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (original_file);
			_g_object_unref0 (new_file);
			_g_free0 (new_key);
			_g_object_unref0 (_tmp4_);
			_g_object_unref0 (file_info);
			_g_object_unref0 (enumerator);
			_g_object_unref0 (original_scores_dir);
			return;
		}
		_tmp30_ = original_file;
		g_file_delete (_tmp30_, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (original_file);
			_g_object_unref0 (new_file);
			_g_free0 (new_key);
			_g_object_unref0 (_tmp4_);
			_g_object_unref0 (file_info);
			_g_object_unref0 (enumerator);
			_g_object_unref0 (original_scores_dir);
			return;
		}
		_g_object_unref0 (original_file);
		_g_object_unref0 (new_file);
		_g_free0 (new_key);
		_g_object_unref0 (_tmp4_);
	}
	_g_object_unref0 (file_info);
	_g_object_unref0 (enumerator);
	_g_object_unref0 (original_scores_dir);
}

static void
_games_scores_directory_importer___lambda16_ (GamesScoresDirectoryImporter* self)
{
	(self->priv->category_convert_target_destroy_notify == NULL) ? NULL : (self->priv->category_convert_target_destroy_notify (self->priv->category_convert_target), NULL);
	self->priv->category_convert = NULL;
	self->priv->category_convert_target = NULL;
	self->priv->category_convert_target_destroy_notify = NULL;
	self->priv->category_convert = NULL;
	self->priv->category_convert_target = NULL;
	self->priv->category_convert_target_destroy_notify = NULL;
}

static void
__games_scores_directory_importer___lambda16__games_scores_importer_finished (GamesScoresImporter* _sender,
                                                                              gpointer self)
{
	_games_scores_directory_importer___lambda16_ ((GamesScoresDirectoryImporter*) self);
}

static GObject *
games_scores_directory_importer_constructor (GType type,
                                             guint n_construct_properties,
                                             GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GamesScoresDirectoryImporter * self;
	parent_class = G_OBJECT_CLASS (games_scores_directory_importer_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_SCORES_TYPE_DIRECTORY_IMPORTER, GamesScoresDirectoryImporter);
	g_signal_connect_object ((GamesScoresImporter*) self, "finished", (GCallback) __games_scores_directory_importer___lambda16__games_scores_importer_finished, self, 0);
	return obj;
}

static void
games_scores_directory_importer_class_init (GamesScoresDirectoryImporterClass * klass,
                                            gpointer klass_data)
{
	games_scores_directory_importer_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GamesScoresDirectoryImporter_private_offset);
	((GamesScoresImporterClass *) klass)->importOldScores = (void (*) (GamesScoresImporter*, GamesScoresContext*, GFile*, GError**)) games_scores_directory_importer_real_importOldScores;
	G_OBJECT_CLASS (klass)->constructor = games_scores_directory_importer_constructor;
	G_OBJECT_CLASS (klass)->finalize = games_scores_directory_importer_finalize;
}

static void
games_scores_directory_importer_instance_init (GamesScoresDirectoryImporter * self,
                                               gpointer klass)
{
	self->priv = games_scores_directory_importer_get_instance_private (self);
}

static void
games_scores_directory_importer_finalize (GObject * obj)
{
	GamesScoresDirectoryImporter * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_SCORES_TYPE_DIRECTORY_IMPORTER, GamesScoresDirectoryImporter);
	(self->priv->category_convert_target_destroy_notify == NULL) ? NULL : (self->priv->category_convert_target_destroy_notify (self->priv->category_convert_target), NULL);
	self->priv->category_convert = NULL;
	self->priv->category_convert_target = NULL;
	self->priv->category_convert_target_destroy_notify = NULL;
	G_OBJECT_CLASS (games_scores_directory_importer_parent_class)->finalize (obj);
}

static GType
games_scores_directory_importer_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GamesScoresDirectoryImporterClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_scores_directory_importer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesScoresDirectoryImporter), 0, (GInstanceInitFunc) games_scores_directory_importer_instance_init, NULL };
	GType games_scores_directory_importer_type_id;
	games_scores_directory_importer_type_id = g_type_register_static (GAMES_SCORES_TYPE_IMPORTER, "GamesScoresDirectoryImporter", &g_define_type_info, 0);
	GamesScoresDirectoryImporter_private_offset = g_type_add_instance_private (games_scores_directory_importer_type_id, sizeof (GamesScoresDirectoryImporterPrivate));
	return games_scores_directory_importer_type_id;
}

GType
games_scores_directory_importer_get_type (void)
{
	static volatile gsize games_scores_directory_importer_type_id__once = 0;
	if (g_once_init_enter (&games_scores_directory_importer_type_id__once)) {
		GType games_scores_directory_importer_type_id;
		games_scores_directory_importer_type_id = games_scores_directory_importer_get_type_once ();
		g_once_init_leave (&games_scores_directory_importer_type_id__once, games_scores_directory_importer_type_id);
	}
	return games_scores_directory_importer_type_id__once;
}

