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

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

#include "gnome-games.h"
#include <gio/gio.h>
#include <glib-object.h>
#include <glib.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_DIRECTORY_0_PROPERTY,
	GAMES_DIRECTORY_NUM_PROPERTIES
};
static GParamSpec* games_directory_properties[GAMES_DIRECTORY_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _GamesDirectoryForeachAsyncData GamesDirectoryForeachAsyncData;

struct _GamesDirectoryPrivate {
	GFile* file;
};

struct _GamesDirectoryForeachAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GamesDirectory* self;
	gchar* attributes;
	GamesDirectoryFileInfoTest file_info_test;
	gpointer file_info_test_target;
	GFileEnumerator* enumerator;
	GFile* _tmp0_;
	GFileEnumerator* _tmp1_;
	GList* file_infos;
	GFileEnumerator* _tmp2_;
	GList* _tmp3_;
	gboolean _tmp4_;
	GList* _tmp5_;
	GList* _tmp6_;
	GList* _tmp7_;
	GList* file_info_collection;
	GList* file_info_it;
	GFileInfo* _tmp8_;
	GFileInfo* file_info;
	gboolean _tmp9_;
	GFileInfo* _tmp10_;
	GError* _inner_error0_;
};

static gint GamesDirectory_private_offset;
static gpointer games_directory_parent_class = NULL;

static void games_directory_foreach_async_data_free (gpointer _data);
static gboolean games_directory_foreach_async_co (GamesDirectoryForeachAsyncData* _data_);
static void games_directory_foreach_async_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_);
static void _g_object_unref0_ (gpointer var);
static inline void _g_list_free__g_object_unref0_ (GList* self);
static void games_directory_finalize (GObject * obj);
static GType games_directory_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
games_directory_get_instance_private (GamesDirectory* self)
{
	return G_STRUCT_MEMBER_P (self, GamesDirectory_private_offset);
}

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

GamesDirectory*
games_directory_construct (GType object_type,
                           GFile* file)
{
	GamesDirectory * self = NULL;
	GFile* _tmp0_;
	g_return_val_if_fail (file != NULL, NULL);
	self = (GamesDirectory*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (file);
	_g_object_unref0 (self->priv->file);
	self->priv->file = _tmp0_;
	return self;
}

GamesDirectory*
games_directory_new (GFile* file)
{
	return games_directory_construct (GAMES_TYPE_DIRECTORY, file);
}

void
games_directory_foreach (GamesDirectory* self,
                         const gchar* attributes,
                         GamesDirectoryFileInfoTest file_info_test,
                         gpointer file_info_test_target,
                         GError** error)
{
	GFileEnumerator* enumerator = NULL;
	GFile* _tmp0_;
	GFileEnumerator* _tmp1_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (attributes != NULL);
	_tmp0_ = self->priv->file;
	_tmp1_ = g_file_enumerate_children (_tmp0_, attributes, G_FILE_QUERY_INFO_NONE, NULL, &_inner_error0_);
	enumerator = _tmp1_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
	{
		GFileInfo* file_info = NULL;
		GFileEnumerator* _tmp2_;
		GFileInfo* _tmp3_;
		_tmp2_ = enumerator;
		_tmp3_ = g_file_enumerator_next_file (_tmp2_, NULL, &_inner_error0_);
		file_info = _tmp3_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (enumerator);
			return;
		}
		{
			gboolean _tmp4_ = FALSE;
			_tmp4_ = TRUE;
			while (TRUE) {
				GFileInfo* _tmp9_;
				gboolean _tmp10_ = FALSE;
				GFileInfo* _tmp11_;
				if (!_tmp4_) {
					GFileInfo* _tmp5_ = NULL;
					GFileEnumerator* _tmp6_;
					GFileInfo* _tmp7_;
					GFileInfo* _tmp8_;
					_tmp6_ = enumerator;
					_tmp7_ = g_file_enumerator_next_file (_tmp6_, NULL, &_inner_error0_);
					_tmp5_ = _tmp7_;
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						g_propagate_error (error, _inner_error0_);
						_g_object_unref0 (file_info);
						_g_object_unref0 (enumerator);
						return;
					}
					_tmp8_ = _tmp5_;
					_tmp5_ = NULL;
					_g_object_unref0 (file_info);
					file_info = _tmp8_;
					_g_object_unref0 (_tmp5_);
				}
				_tmp4_ = FALSE;
				_tmp9_ = file_info;
				if (!(_tmp9_ != NULL)) {
					break;
				}
				_tmp11_ = file_info;
				_tmp10_ = file_info_test (_tmp11_, file_info_test_target, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					g_propagate_error (error, _inner_error0_);
					_g_object_unref0 (file_info);
					_g_object_unref0 (enumerator);
					return;
				}
				if (_tmp10_) {
					_g_object_unref0 (file_info);
					_g_object_unref0 (enumerator);
					return;
				}
			}
		}
		_g_object_unref0 (file_info);
	}
	_g_object_unref0 (enumerator);
}

static void
games_directory_foreach_async_data_free (gpointer _data)
{
	GamesDirectoryForeachAsyncData* _data_;
	_data_ = _data;
	_g_free0 (_data_->attributes);
	_g_object_unref0 (_data_->self);
	g_slice_free (GamesDirectoryForeachAsyncData, _data_);
}

void
games_directory_foreach_async (GamesDirectory* self,
                               const gchar* attributes,
                               GamesDirectoryFileInfoTest file_info_test,
                               gpointer file_info_test_target,
                               GAsyncReadyCallback _callback_,
                               gpointer _user_data_)
{
	GamesDirectoryForeachAsyncData* _data_;
	GamesDirectory* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (attributes != NULL);
	_data_ = g_slice_new0 (GamesDirectoryForeachAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, games_directory_foreach_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = g_strdup (attributes);
	_g_free0 (_data_->attributes);
	_data_->attributes = _tmp1_;
	_data_->file_info_test = file_info_test;
	_data_->file_info_test_target = file_info_test_target;
	games_directory_foreach_async_co (_data_);
}

void
games_directory_foreach_finish (GamesDirectory* self,
                                GAsyncResult* _res_,
                                GError** error)
{
	GamesDirectoryForeachAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
games_directory_foreach_async_ready (GObject* source_object,
                                     GAsyncResult* _res_,
                                     gpointer _user_data_)
{
	GamesDirectoryForeachAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	games_directory_foreach_async_co (_data_);
}

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

static inline void
_g_list_free__g_object_unref0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_object_unref0_);
}

static gboolean
games_directory_foreach_async_co (GamesDirectoryForeachAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->file;
	_data_->_state_ = 1;
	g_file_enumerate_children_async (_data_->_tmp0_, _data_->attributes, G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, NULL, games_directory_foreach_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp1_ = g_file_enumerate_children_finish (_data_->_tmp0_, _data_->_res_, &_data_->_inner_error0_);
	_data_->enumerator = _data_->_tmp1_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	while (TRUE) {
		_data_->_tmp2_ = _data_->enumerator;
		_data_->_state_ = 2;
		g_file_enumerator_next_files_async (_data_->_tmp2_, 25, G_PRIORITY_DEFAULT, NULL, games_directory_foreach_async_ready, _data_);
		return FALSE;
		_state_2:
		_data_->_tmp3_ = g_file_enumerator_next_files_finish (_data_->_tmp2_, _data_->_res_, &_data_->_inner_error0_);
		_data_->file_infos = _data_->_tmp3_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->enumerator);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp5_ = _data_->file_infos;
		if (_data_->_tmp5_ == NULL) {
			_data_->_tmp4_ = TRUE;
		} else {
			_data_->_tmp6_ = _data_->file_infos;
			_data_->_tmp4_ = g_list_length (_data_->_tmp6_) == ((guint) 0);
		}
		if (_data_->_tmp4_) {
			(_data_->file_infos == NULL) ? NULL : (_data_->file_infos = (_g_list_free__g_object_unref0_ (_data_->file_infos), NULL));
			break;
		}
		_data_->_tmp7_ = _data_->file_infos;
		{
			_data_->file_info_collection = _data_->_tmp7_;
			for (_data_->file_info_it = _data_->file_info_collection; _data_->file_info_it != NULL; _data_->file_info_it = _data_->file_info_it->next) {
				_data_->_tmp8_ = _g_object_ref0 ((GFileInfo*) _data_->file_info_it->data);
				_data_->file_info = _data_->_tmp8_;
				{
					_data_->_tmp10_ = _data_->file_info;
					_data_->_tmp9_ = _data_->file_info_test (_data_->_tmp10_, _data_->file_info_test_target, &_data_->_inner_error0_);
					if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
						g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
						_g_object_unref0 (_data_->file_info);
						(_data_->file_infos == NULL) ? NULL : (_data_->file_infos = (_g_list_free__g_object_unref0_ (_data_->file_infos), NULL));
						_g_object_unref0 (_data_->enumerator);
						g_object_unref (_data_->_async_result);
						return FALSE;
					}
					if (_data_->_tmp9_) {
						_g_object_unref0 (_data_->file_info);
						(_data_->file_infos == NULL) ? NULL : (_data_->file_infos = (_g_list_free__g_object_unref0_ (_data_->file_infos), NULL));
						_g_object_unref0 (_data_->enumerator);
						g_task_return_pointer (_data_->_async_result, _data_, NULL);
						if (_data_->_state_ != 0) {
							while (!g_task_get_completed (_data_->_async_result)) {
								g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
							}
						}
						g_object_unref (_data_->_async_result);
						return FALSE;
					}
					_g_object_unref0 (_data_->file_info);
				}
			}
		}
		(_data_->file_infos == NULL) ? NULL : (_data_->file_infos = (_g_list_free__g_object_unref0_ (_data_->file_infos), NULL));
	}
	_g_object_unref0 (_data_->enumerator);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
games_directory_class_init (GamesDirectoryClass * klass,
                            gpointer klass_data)
{
	games_directory_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GamesDirectory_private_offset);
	G_OBJECT_CLASS (klass)->finalize = games_directory_finalize;
}

static void
games_directory_instance_init (GamesDirectory * self,
                               gpointer klass)
{
	self->priv = games_directory_get_instance_private (self);
}

static void
games_directory_finalize (GObject * obj)
{
	GamesDirectory * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_DIRECTORY, GamesDirectory);
	_g_object_unref0 (self->priv->file);
	G_OBJECT_CLASS (games_directory_parent_class)->finalize (obj);
}

static GType
games_directory_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GamesDirectoryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_directory_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesDirectory), 0, (GInstanceInitFunc) games_directory_instance_init, NULL };
	GType games_directory_type_id;
	games_directory_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesDirectory", &g_define_type_info, 0);
	GamesDirectory_private_offset = g_type_add_instance_private (games_directory_type_id, sizeof (GamesDirectoryPrivate));
	return games_directory_type_id;
}

GType
games_directory_get_type (void)
{
	static volatile gsize games_directory_type_id__once = 0;
	if (g_once_init_enter (&games_directory_type_id__once)) {
		GType games_directory_type_id;
		games_directory_type_id = games_directory_get_type_once ();
		g_once_init_leave (&games_directory_type_id__once, games_directory_type_id);
	}
	return games_directory_type_id__once;
}

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

