/* importer.c generated by valac 0.56.0, the Vala compiler
 * generated from 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 <gio/gio.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib-object.h>

enum  {
	GAMES_SCORES_IMPORTER_0_PROPERTY,
	GAMES_SCORES_IMPORTER_NUM_PROPERTIES
};
static GParamSpec* games_scores_importer_properties[GAMES_SCORES_IMPORTER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

static gpointer games_scores_importer_parent_class = NULL;

static void games_scores_importer_real_importOldScores (GamesScoresImporter* self,
                                                 GamesScoresContext* context,
                                                 GFile* new_scores_dir,
                                                 GError** error);
VALA_EXTERN void games_scores_importer_run (GamesScoresImporter* self,
                                GamesScoresContext* context,
                                const gchar* new_scores_dir);
static GType games_scores_importer_get_type_once (void);

static void
games_scores_importer_real_importOldScores (GamesScoresImporter* self,
                                            GamesScoresContext* context,
                                            GFile* new_scores_dir,
                                            GError** error)
{
	g_critical ("Type `%s' does not implement abstract method `games_scores_importer_importOldScores'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return;
}

void
games_scores_importer_importOldScores (GamesScoresImporter* self,
                                       GamesScoresContext* context,
                                       GFile* new_scores_dir,
                                       GError** error)
{
	GamesScoresImporterClass* _klass_;
	g_return_if_fail (self != NULL);
	_klass_ = GAMES_SCORES_IMPORTER_GET_CLASS (self);
	if (_klass_->importOldScores) {
		_klass_->importOldScores (self, context, new_scores_dir, error);
	}
}

void
games_scores_importer_run (GamesScoresImporter* self,
                           GamesScoresContext* context,
                           const gchar* new_scores_dir)
{
	GFile* new_dir = NULL;
	GFile* _tmp0_;
	GFile* _tmp1_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (context != NULL);
	g_return_if_fail (new_scores_dir != NULL);
	_tmp0_ = g_file_new_for_path (new_scores_dir);
	new_dir = _tmp0_;
	_tmp1_ = new_dir;
	if (g_file_query_exists (_tmp1_, NULL)) {
		_g_object_unref0 (new_dir);
		return;
	}
	{
		GFile* _tmp2_;
		GFile* _tmp3_;
		_tmp2_ = new_dir;
		g_file_make_directory_with_parents (_tmp2_, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp3_ = new_dir;
		games_scores_importer_importOldScores (self, context, _tmp3_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp4_;
		const gchar* _tmp5_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp4_ = e;
		_tmp5_ = _tmp4_->message;
		g_warning ("importer.vala:83: Failed to import scores: %s", _tmp5_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (new_dir);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	_g_object_unref0 (new_dir);
}

GamesScoresImporter*
games_scores_importer_construct (GType object_type)
{
	GamesScoresImporter * self = NULL;
	self = (GamesScoresImporter*) g_object_new (object_type, NULL);
	return self;
}

static void
games_scores_importer_class_init (GamesScoresImporterClass * klass,
                                  gpointer klass_data)
{
	games_scores_importer_parent_class = g_type_class_peek_parent (klass);
	((GamesScoresImporterClass *) klass)->importOldScores = (void (*) (GamesScoresImporter*, GamesScoresContext*, GFile*, GError**)) games_scores_importer_real_importOldScores;
}

static void
games_scores_importer_instance_init (GamesScoresImporter * self,
                                     gpointer klass)
{
}

static GType
games_scores_importer_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GamesScoresImporterClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_scores_importer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesScoresImporter), 0, (GInstanceInitFunc) games_scores_importer_instance_init, NULL };
	GType games_scores_importer_type_id;
	games_scores_importer_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesScoresImporter", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	return games_scores_importer_type_id;
}

GType
games_scores_importer_get_type (void)
{
	static volatile gsize games_scores_importer_type_id__once = 0;
	if (g_once_init_enter (&games_scores_importer_type_id__once)) {
		GType games_scores_importer_type_id;
		games_scores_importer_type_id = games_scores_importer_get_type_once ();
		g_once_init_leave (&games_scores_importer_type_id__once, games_scores_importer_type_id);
	}
	return games_scores_importer_type_id__once;
}

