/* sticker_store.c generated by valac 0.56.19, the Vala compiler
 * generated from sticker_store.vala, do not modify */

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <gio/gio.h>

#define DC_STICKER_STORE_SEP "__"
#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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define DC_TYPE_STICKER (dc_sticker_get_type ())
#define DC_STICKER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_STICKER, DcSticker))
#define DC_STICKER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_STICKER, DcStickerClass))
#define DC_IS_STICKER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_STICKER))
#define DC_IS_STICKER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_STICKER))
#define DC_STICKER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_STICKER, DcStickerClass))

typedef struct _DcSticker DcSticker;
typedef struct _DcStickerClass DcStickerClass;
typedef struct _DcStickerPrivate DcStickerPrivate;
enum  {
	DC_STICKER_0_PROPERTY,
	DC_STICKER_NUM_PROPERTIES
};
static GParamSpec* dc_sticker_properties[DC_STICKER_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))

#define DC_TYPE_STICKER_STORE (dc_sticker_store_get_type ())
#define DC_STICKER_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_STICKER_STORE, DcStickerStore))
#define DC_STICKER_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_STICKER_STORE, DcStickerStoreClass))
#define DC_IS_STICKER_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_STICKER_STORE))
#define DC_IS_STICKER_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_STICKER_STORE))
#define DC_STICKER_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_STICKER_STORE, DcStickerStoreClass))

typedef struct _DcStickerStore DcStickerStore;
typedef struct _DcStickerStoreClass DcStickerStoreClass;
typedef struct _DcStickerStorePrivate DcStickerStorePrivate;
enum  {
	DC_STICKER_STORE_0_PROPERTY,
	DC_STICKER_STORE_NUM_PROPERTIES
};
static GParamSpec* dc_sticker_store_properties[DC_STICKER_STORE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_ptr_array_unref0(var) ((var == NULL) ? NULL : (var = (g_ptr_array_unref (var), NULL)))
typedef struct _Block21Data Block21Data;
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _g_dir_close0(var) ((var == NULL) ? NULL : (var = (g_dir_close (var), NULL)))

struct _DcSticker {
	GObject parent_instance;
	DcStickerPrivate * priv;
	gchar* file_name;
	gchar* pack;
	gchar* emoji;
	gchar* display_name;
};

struct _DcStickerClass {
	GObjectClass parent_class;
};

struct _DcStickerStore {
	GObject parent_instance;
	DcStickerStorePrivate * priv;
};

struct _DcStickerStoreClass {
	GObjectClass parent_class;
};

struct _Block21Data {
	int _ref_count_;
	GPtrArray* self;
	GCompareFunc compare_func;
};

static gpointer dc_sticker_parent_class = NULL;
static gpointer dc_sticker_store_parent_class = NULL;

VALA_EXTERN GType dc_sticker_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcSticker, g_object_unref)
VALA_EXTERN DcSticker* dc_sticker_new (const gchar* file_name,
                           const gchar* pack,
                           const gchar* emoji,
                           const gchar* display_name);
VALA_EXTERN DcSticker* dc_sticker_construct (GType object_type,
                                 const gchar* file_name,
                                 const gchar* pack,
                                 const gchar* emoji,
                                 const gchar* display_name);
static void dc_sticker_finalize (GObject * obj);
static GType dc_sticker_get_type_once (void);
VALA_EXTERN GType dc_sticker_store_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcStickerStore, g_object_unref)
VALA_EXTERN gchar* dc_sticker_store_get_stickers_dir (void);
VALA_EXTERN gchar* dc_account_finder_get_parla_data_dir (void);
VALA_EXTERN gchar* dc_sticker_store_sticker_path (const gchar* file_name);
VALA_EXTERN gboolean dc_sticker_store_is_sticker_filename (const gchar* name);
VALA_EXTERN DcSticker* dc_sticker_store_parse (const gchar* file_name);
VALA_EXTERN gchar** dc_sticker_store_list_packs (gint* result_length1);
static void _g_free0_ (gpointer var);
static GPtrArray* dc_sticker_store_list_all (void);
static gboolean dc_sticker_store_contains (GPtrArray* items,
                                    const gchar* value);
static Block21Data* block21_data_ref (Block21Data* _data21_);
static void block21_data_unref (void * _userdata_);
static gint ___lambda0__gcompare_data_func (gconstpointer a,
                                     gconstpointer b,
                                     gpointer self);
static gint __lambda30_ (const gchar* a,
                  const gchar* b);
static gint ___lambda30__gcompare_func (gconstpointer a,
                                 gconstpointer b);
static void _vala_array_add42 (gchar** * array,
                        gint* length,
                        gint* size,
                        gchar* value);
VALA_EXTERN DcSticker** dc_sticker_store_list_stickers (const gchar* pack,
                                            gint* result_length1);
static void _vala_array_add43 (DcSticker** * array,
                        gint* length,
                        gint* size,
                        DcSticker* value);
VALA_EXTERN gchar* dc_sticker_store_sanitize_pack_name (const gchar* name);
VALA_EXTERN void dc_sticker_store_rename_pack (const gchar* pack,
                                   const gchar* new_pack,
                                   GError** error);
VALA_EXTERN gboolean dc_sticker_store_move_sticker (DcSticker* sticker,
                                        const gchar* dest_pack,
                                        GError** error);
VALA_EXTERN void dc_sticker_store_delete_sticker (DcSticker* sticker);
VALA_EXTERN void dc_sticker_store_delete_pack (const gchar* pack);
VALA_EXTERN gboolean dc_sticker_store_add_sticker (const gchar* pack,
                                       const gchar* source_path,
                                       GError** error);
static gboolean dc_sticker_store_has_display_name (const gchar* pack,
                                            const gchar* display);
static gchar* dc_sticker_store_build_file_name (const gchar* pack,
                                         const gchar* emoji,
                                         const gchar* display);
static void dc_sticker_store_rename (const gchar* from,
                              const gchar* to,
                              GError** error);
VALA_EXTERN void dc_sticker_store_set_emoji (DcSticker* sticker,
                                 const gchar* emoji,
                                 GError** error);
static void _g_object_unref0_ (gpointer var);
static gint __lambda29_ (DcSticker* a,
                  DcSticker* b);
static gint ___lambda29__gcompare_func (gconstpointer a,
                                 gconstpointer b);
VALA_EXTERN DcStickerStore* dc_sticker_store_new (void);
VALA_EXTERN DcStickerStore* dc_sticker_store_construct (GType object_type);
static GType dc_sticker_store_get_type_once (void);
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 gssize _vala_array_length (gpointer array);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static const gchar* DC_STICKER_STORE_STICKER_SUFFIXES[3] = {".gif", ".webp", ".webm"};

DcSticker*
dc_sticker_construct (GType object_type,
                      const gchar* file_name,
                      const gchar* pack,
                      const gchar* emoji,
                      const gchar* display_name)
{
	DcSticker * self = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	g_return_val_if_fail (file_name != NULL, NULL);
	g_return_val_if_fail (pack != NULL, NULL);
	g_return_val_if_fail (emoji != NULL, NULL);
	g_return_val_if_fail (display_name != NULL, NULL);
	self = (DcSticker*) g_object_new (object_type, NULL);
	_tmp0_ = g_strdup (file_name);
	_g_free0 (self->file_name);
	self->file_name = _tmp0_;
	_tmp1_ = g_strdup (pack);
	_g_free0 (self->pack);
	self->pack = _tmp1_;
	_tmp2_ = g_strdup (emoji);
	_g_free0 (self->emoji);
	self->emoji = _tmp2_;
	_tmp3_ = g_strdup (display_name);
	_g_free0 (self->display_name);
	self->display_name = _tmp3_;
	return self;
}

DcSticker*
dc_sticker_new (const gchar* file_name,
                const gchar* pack,
                const gchar* emoji,
                const gchar* display_name)
{
	return dc_sticker_construct (DC_TYPE_STICKER, file_name, pack, emoji, display_name);
}

static void
dc_sticker_class_init (DcStickerClass * klass,
                       gpointer klass_data)
{
	dc_sticker_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = dc_sticker_finalize;
}

static void
dc_sticker_instance_init (DcSticker * self,
                          gpointer klass)
{
}

static void
dc_sticker_finalize (GObject * obj)
{
	DcSticker * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_TYPE_STICKER, DcSticker);
	_g_free0 (self->file_name);
	_g_free0 (self->pack);
	_g_free0 (self->emoji);
	_g_free0 (self->display_name);
	G_OBJECT_CLASS (dc_sticker_parent_class)->finalize (obj);
}

/** One sticker file in the store, decoded from its file name. */
static GType
dc_sticker_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DcStickerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_sticker_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcSticker), 0, (GInstanceInitFunc) dc_sticker_instance_init, NULL };
	GType dc_sticker_type_id;
	dc_sticker_type_id = g_type_register_static (G_TYPE_OBJECT, "DcSticker", &g_define_type_info, 0);
	return dc_sticker_type_id;
}

GType
dc_sticker_get_type (void)
{
	static volatile gsize dc_sticker_type_id__once = 0;
	if (g_once_init_enter (&dc_sticker_type_id__once)) {
		GType dc_sticker_type_id;
		dc_sticker_type_id = dc_sticker_get_type_once ();
		g_once_init_leave (&dc_sticker_type_id__once, dc_sticker_type_id);
	}
	return dc_sticker_type_id__once;
}

gchar*
dc_sticker_store_get_stickers_dir (void)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	_tmp0_ = dc_account_finder_get_parla_data_dir ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_build_filename (_tmp1_, "stickers", NULL);
	_tmp3_ = _tmp2_;
	_g_free0 (_tmp1_);
	result = _tmp3_;
	return result;
}

gchar*
dc_sticker_store_sticker_path (const gchar* file_name)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (file_name != NULL, NULL);
	_tmp0_ = dc_sticker_store_get_stickers_dir ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_build_filename (_tmp1_, file_name, NULL);
	_tmp3_ = _tmp2_;
	_g_free0 (_tmp1_);
	result = _tmp3_;
	return result;
}

gboolean
dc_sticker_store_is_sticker_filename (const gchar* name)
{
	gchar* lower = NULL;
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (name != NULL, FALSE);
	_tmp0_ = g_utf8_strdown (name, (gssize) -1);
	lower = _tmp0_;
	{
		const gchar** suffix_collection = NULL;
		gint suffix_collection_length1 = 0;
		gint _suffix_collection_size_ = 0;
		gint suffix_it = 0;
		suffix_collection = DC_STICKER_STORE_STICKER_SUFFIXES;
		suffix_collection_length1 = G_N_ELEMENTS (DC_STICKER_STORE_STICKER_SUFFIXES);
		for (suffix_it = 0; suffix_it < suffix_collection_length1; suffix_it = suffix_it + 1) {
			gchar* _tmp1_;
			gchar* suffix = NULL;
			_tmp1_ = g_strdup (suffix_collection[suffix_it]);
			suffix = _tmp1_;
			{
				const gchar* _tmp2_;
				const gchar* _tmp3_;
				_tmp2_ = lower;
				_tmp3_ = suffix;
				if (g_str_has_suffix (_tmp2_, _tmp3_)) {
					result = TRUE;
					_g_free0 (suffix);
					_g_free0 (lower);
					return result;
				}
				_g_free0 (suffix);
			}
		}
	}
	result = FALSE;
	_g_free0 (lower);
	return result;
}

/** Decode "<pack>__<emoji>__<name>"; null for foreign files. */
DcSticker*
dc_sticker_store_parse (const gchar* file_name)
{
	gchar** parts = NULL;
	gchar** _tmp0_;
	gchar** _tmp1_;
	gint parts_length1;
	gint _parts_size_;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gchar** _tmp4_;
	gint _tmp4__length1;
	gchar** _tmp13_;
	gint _tmp13__length1;
	const gchar* _tmp14_;
	gchar** _tmp15_;
	gint _tmp15__length1;
	const gchar* _tmp16_;
	gchar** _tmp17_;
	gint _tmp17__length1;
	const gchar* _tmp18_;
	DcSticker* _tmp19_;
	DcSticker* result;
	g_return_val_if_fail (file_name != NULL, NULL);
	if (!dc_sticker_store_is_sticker_filename (file_name)) {
		result = NULL;
		return result;
	}
	_tmp1_ = _tmp0_ = g_strsplit (file_name, DC_STICKER_STORE_SEP, 3);
	parts = _tmp1_;
	parts_length1 = _vala_array_length (_tmp0_);
	_parts_size_ = parts_length1;
	_tmp4_ = parts;
	_tmp4__length1 = parts_length1;
	if (_tmp4__length1 != 3) {
		_tmp3_ = TRUE;
	} else {
		gchar** _tmp5_;
		gint _tmp5__length1;
		const gchar* _tmp6_;
		gint _tmp7_;
		gint _tmp8_;
		_tmp5_ = parts;
		_tmp5__length1 = parts_length1;
		_tmp6_ = _tmp5_[0];
		_tmp7_ = strlen (_tmp6_);
		_tmp8_ = _tmp7_;
		_tmp3_ = _tmp8_ == 0;
	}
	if (_tmp3_) {
		_tmp2_ = TRUE;
	} else {
		gchar** _tmp9_;
		gint _tmp9__length1;
		const gchar* _tmp10_;
		gint _tmp11_;
		gint _tmp12_;
		_tmp9_ = parts;
		_tmp9__length1 = parts_length1;
		_tmp10_ = _tmp9_[2];
		_tmp11_ = strlen (_tmp10_);
		_tmp12_ = _tmp11_;
		_tmp2_ = _tmp12_ == 0;
	}
	if (_tmp2_) {
		result = NULL;
		parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
		return result;
	}
	_tmp13_ = parts;
	_tmp13__length1 = parts_length1;
	_tmp14_ = _tmp13_[0];
	_tmp15_ = parts;
	_tmp15__length1 = parts_length1;
	_tmp16_ = _tmp15_[1];
	_tmp17_ = parts;
	_tmp17__length1 = parts_length1;
	_tmp18_ = _tmp17_[2];
	_tmp19_ = dc_sticker_new (file_name, _tmp14_, _tmp16_, _tmp18_);
	result = _tmp19_;
	parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
	return result;
}

/** Alphabetical list of the packs named by the sticker files. */
static void
_g_free0_ (gpointer var)
{
	var = (g_free (var), NULL);
}

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

static Block21Data*
block21_data_ref (Block21Data* _data21_)
{
	g_atomic_int_inc (&_data21_->_ref_count_);
	return _data21_;
}

static void
block21_data_unref (void * _userdata_)
{
	Block21Data* _data21_;
	_data21_ = (Block21Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data21_->_ref_count_)) {
		GPtrArray* self;
		self = _data21_->self;
		_g_ptr_array_unref0 (self);
		g_slice_free (Block21Data, _data21_);
	}
}

static gint
__lambda0_ (Block21Data* _data21_,
            gconstpointer** a,
            gconstpointer** b)
{
	GPtrArray* self;
	gint result;
	self = _data21_->self;
	result = _data21_->compare_func ((gconstpointer**) (*a), (gconstpointer**) (*b));
	return result;
}

static gint
___lambda0__gcompare_data_func (gconstpointer a,
                                gconstpointer b,
                                gpointer self)
{
	gint result;
	result = __lambda0_ (self, a, b);
	return result;
}

static void
vala_g_ptr_array_sort (GPtrArray* self,
                       GCompareFunc compare_func)
{
	Block21Data* _data21_;
	g_return_if_fail (self != NULL);
	_data21_ = g_slice_new0 (Block21Data);
	_data21_->_ref_count_ = 1;
	_data21_->self = g_ptr_array_ref (self);
	_data21_->compare_func = compare_func;
	g_ptr_array_sort_with_data (self, ___lambda0__gcompare_data_func, _data21_);
	block21_data_unref (_data21_);
	_data21_ = NULL;
}

static gint
__lambda30_ (const gchar* a,
             const gchar* b)
{
	GCompareFunc _tmp0_;
	gint result;
	g_return_val_if_fail (a != NULL, -1);
	g_return_val_if_fail (b != NULL, -1);
	_tmp0_ = ((GCompareFunc) g_strcmp0);
	result = _tmp0_ (a, b);
	return result;
}

static gint
___lambda30__gcompare_func (gconstpointer a,
                            gconstpointer b)
{
	gint result;
	result = __lambda30_ ((const gchar*) a, (const gchar*) b);
	return result;
}

static void
_vala_array_add42 (gchar** * array,
                   gint* length,
                   gint* size,
                   gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

gchar**
dc_sticker_store_list_packs (gint* result_length1)
{
	GPtrArray* found = NULL;
	GPtrArray* _tmp0_;
	GPtrArray* _tmp1_;
	GPtrArray* _tmp10_;
	gchar** _result_ = NULL;
	gchar** _tmp11_;
	gint _result__length1;
	gint __result__size_;
	GPtrArray* _tmp12_;
	gchar** _tmp16_;
	gint _tmp16__length1;
	gchar** result;
	_tmp0_ = g_ptr_array_new_full ((guint) 0, _g_free0_);
	found = _tmp0_;
	_tmp1_ = dc_sticker_store_list_all ();
	{
		GPtrArray* sticker_collection = NULL;
		guint sticker_index = 0U;
		sticker_collection = _tmp1_;
		for (sticker_index = 0; sticker_index < sticker_collection->len; sticker_index = sticker_index + 1) {
			DcSticker* _tmp2_;
			DcSticker* sticker = NULL;
			_tmp2_ = _g_object_ref0 ((DcSticker*) g_ptr_array_index (sticker_collection, sticker_index));
			sticker = _tmp2_;
			{
				GPtrArray* _tmp3_;
				DcSticker* _tmp4_;
				const gchar* _tmp5_;
				_tmp3_ = found;
				_tmp4_ = sticker;
				_tmp5_ = _tmp4_->pack;
				if (!dc_sticker_store_contains (_tmp3_, _tmp5_)) {
					GPtrArray* _tmp6_;
					DcSticker* _tmp7_;
					const gchar* _tmp8_;
					gchar* _tmp9_;
					_tmp6_ = found;
					_tmp7_ = sticker;
					_tmp8_ = _tmp7_->pack;
					_tmp9_ = g_strdup (_tmp8_);
					g_ptr_array_add (_tmp6_, _tmp9_);
				}
				_g_object_unref0 (sticker);
			}
		}
		_g_ptr_array_unref0 (sticker_collection);
	}
	_tmp10_ = found;
	vala_g_ptr_array_sort (_tmp10_, ___lambda30__gcompare_func);
	_tmp11_ = g_new0 (gchar*, 0 + 1);
	_result_ = _tmp11_;
	_result__length1 = 0;
	__result__size_ = _result__length1;
	_tmp12_ = found;
	{
		GPtrArray* pack_collection = NULL;
		guint pack_index = 0U;
		pack_collection = _tmp12_;
		for (pack_index = 0; pack_index < pack_collection->len; pack_index = pack_index + 1) {
			gchar* _tmp13_;
			gchar* pack = NULL;
			_tmp13_ = g_strdup ((gchar*) g_ptr_array_index (pack_collection, pack_index));
			pack = _tmp13_;
			{
				const gchar* _tmp14_;
				gchar* _tmp15_;
				_tmp14_ = pack;
				_tmp15_ = g_strdup (_tmp14_);
				_vala_array_add42 (&_result_, &_result__length1, &__result__size_, _tmp15_);
				_g_free0 (pack);
			}
		}
	}
	_tmp16_ = _result_;
	_tmp16__length1 = _result__length1;
	if (result_length1) {
		*result_length1 = _tmp16__length1;
	}
	result = _tmp16_;
	_g_ptr_array_unref0 (found);
	return result;
}

/** Stickers of one pack, sorted by display name. */
static void
_vala_array_add43 (DcSticker** * array,
                   gint* length,
                   gint* size,
                   DcSticker* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (DcSticker*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

DcSticker**
dc_sticker_store_list_stickers (const gchar* pack,
                                gint* result_length1)
{
	DcSticker** _result_ = NULL;
	DcSticker** _tmp0_;
	gint _result__length1;
	gint __result__size_;
	GPtrArray* _tmp1_;
	DcSticker** _tmp7_;
	gint _tmp7__length1;
	DcSticker** result;
	g_return_val_if_fail (pack != NULL, NULL);
	_tmp0_ = g_new0 (DcSticker*, 0 + 1);
	_result_ = _tmp0_;
	_result__length1 = 0;
	__result__size_ = _result__length1;
	_tmp1_ = dc_sticker_store_list_all ();
	{
		GPtrArray* sticker_collection = NULL;
		guint sticker_index = 0U;
		sticker_collection = _tmp1_;
		for (sticker_index = 0; sticker_index < sticker_collection->len; sticker_index = sticker_index + 1) {
			DcSticker* _tmp2_;
			DcSticker* sticker = NULL;
			_tmp2_ = _g_object_ref0 ((DcSticker*) g_ptr_array_index (sticker_collection, sticker_index));
			sticker = _tmp2_;
			{
				DcSticker* _tmp3_;
				const gchar* _tmp4_;
				_tmp3_ = sticker;
				_tmp4_ = _tmp3_->pack;
				if (g_strcmp0 (_tmp4_, pack) == 0) {
					DcSticker* _tmp5_;
					DcSticker* _tmp6_;
					_tmp5_ = sticker;
					_tmp6_ = _g_object_ref0 (_tmp5_);
					_vala_array_add43 (&_result_, &_result__length1, &__result__size_, _tmp6_);
				}
				_g_object_unref0 (sticker);
			}
		}
		_g_ptr_array_unref0 (sticker_collection);
	}
	_tmp7_ = _result_;
	_tmp7__length1 = _result__length1;
	if (result_length1) {
		*result_length1 = _tmp7__length1;
	}
	result = _tmp7_;
	return result;
}

/** Pack name stripped and made safe for the file-name encoding
            (no path separators, no "__"); null when nothing remains. */
static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

static gchar*
string_replace (const gchar* self,
                const gchar* old,
                const gchar* replacement)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	if ((*((gchar*) self)) == '\0') {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = (*((gchar*) old)) == '\0';
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_strcmp0 (old, replacement) == 0;
	}
	if (_tmp0_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (self);
		result = _tmp2_;
		return result;
	}
	{
		GRegex* regex = NULL;
		gchar* _tmp3_;
		gchar* _tmp4_;
		GRegex* _tmp5_;
		GRegex* _tmp6_;
		gchar* _tmp7_ = NULL;
		GRegex* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp3_ = g_regex_escape_string (old, -1);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_regex_new (_tmp4_, 0, 0, &_inner_error0_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		regex = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected 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 NULL;
		}
		_tmp8_ = regex;
		_tmp9_ = g_regex_replace_literal (_tmp8_, self, (gssize) -1, 0, replacement, 0, &_inner_error0_);
		_tmp7_ = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected 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 NULL;
		}
		_tmp10_ = _tmp7_;
		_tmp7_ = NULL;
		result = _tmp10_;
		_g_free0 (_tmp7_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		g_assert_not_reached ();
	}
	__finally0:
	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 NULL;
}

gchar*
dc_sticker_store_sanitize_pack_name (const gchar* name)
{
	gchar* clean = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	const gchar* _tmp8_ = NULL;
	gboolean _tmp9_ = FALSE;
	gboolean _tmp10_ = FALSE;
	const gchar* _tmp11_;
	gint _tmp12_;
	gint _tmp13_;
	gchar* _tmp17_;
	gchar* result;
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = string_strip (name);
	_tmp1_ = _tmp0_;
	_tmp2_ = string_replace (_tmp1_, "/", "-");
	_tmp3_ = _tmp2_;
	_tmp4_ = string_replace (_tmp3_, "\\", "-");
	_tmp5_ = _tmp4_;
	_tmp6_ = string_replace (_tmp5_, "_", "-");
	_tmp7_ = _tmp6_;
	_g_free0 (_tmp5_);
	_g_free0 (_tmp3_);
	_g_free0 (_tmp1_);
	clean = _tmp7_;
	_tmp11_ = clean;
	_tmp12_ = strlen (_tmp11_);
	_tmp13_ = _tmp12_;
	if (_tmp13_ > 0) {
		const gchar* _tmp14_;
		_tmp14_ = clean;
		_tmp10_ = g_strcmp0 (_tmp14_, ".") != 0;
	} else {
		_tmp10_ = FALSE;
	}
	if (_tmp10_) {
		const gchar* _tmp15_;
		_tmp15_ = clean;
		_tmp9_ = g_strcmp0 (_tmp15_, "..") != 0;
	} else {
		_tmp9_ = FALSE;
	}
	if (_tmp9_) {
		const gchar* _tmp16_;
		_tmp16_ = clean;
		_tmp8_ = _tmp16_;
	} else {
		_tmp8_ = NULL;
	}
	_tmp17_ = g_strdup (_tmp8_);
	result = _tmp17_;
	_g_free0 (clean);
	return result;
}

/** Rename a pack by moving every sticker into the new name. When
            the destination pack already holds a same-named sticker it is
            the same content (names are checksums), so the source duplicate
            is dropped and the packs merge. */
void
dc_sticker_store_rename_pack (const gchar* pack,
                              const gchar* new_pack,
                              GError** error)
{
	gint _tmp0_ = 0;
	DcSticker** _tmp1_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (pack != NULL);
	g_return_if_fail (new_pack != NULL);
	if (g_strcmp0 (pack, new_pack) == 0) {
		return;
	}
	_tmp1_ = dc_sticker_store_list_stickers (pack, &_tmp0_);
	{
		DcSticker** sticker_collection = NULL;
		gint sticker_collection_length1 = 0;
		gint _sticker_collection_size_ = 0;
		gint sticker_it = 0;
		sticker_collection = _tmp1_;
		sticker_collection_length1 = _tmp0_;
		for (sticker_it = 0; sticker_it < sticker_collection_length1; sticker_it = sticker_it + 1) {
			DcSticker* _tmp2_;
			DcSticker* sticker = NULL;
			_tmp2_ = _g_object_ref0 (sticker_collection[sticker_it]);
			sticker = _tmp2_;
			{
				gboolean _tmp3_ = FALSE;
				DcSticker* _tmp4_;
				_tmp4_ = sticker;
				_tmp3_ = dc_sticker_store_move_sticker (_tmp4_, new_pack, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					g_propagate_error (error, _inner_error0_);
					_g_object_unref0 (sticker);
					sticker_collection = (_vala_array_free (sticker_collection, sticker_collection_length1, (GDestroyNotify) g_object_unref), NULL);
					return;
				}
				if (!_tmp3_) {
					DcSticker* _tmp5_;
					_tmp5_ = sticker;
					dc_sticker_store_delete_sticker (_tmp5_);
				}
				_g_object_unref0 (sticker);
			}
		}
		sticker_collection = (_vala_array_free (sticker_collection, sticker_collection_length1, (GDestroyNotify) g_object_unref), NULL);
	}
}

/** Deleting every sticker of a pack deletes the pack itself. */
void
dc_sticker_store_delete_pack (const gchar* pack)
{
	gint _tmp0_ = 0;
	DcSticker** _tmp1_;
	g_return_if_fail (pack != NULL);
	_tmp1_ = dc_sticker_store_list_stickers (pack, &_tmp0_);
	{
		DcSticker** sticker_collection = NULL;
		gint sticker_collection_length1 = 0;
		gint _sticker_collection_size_ = 0;
		gint sticker_it = 0;
		sticker_collection = _tmp1_;
		sticker_collection_length1 = _tmp0_;
		for (sticker_it = 0; sticker_it < sticker_collection_length1; sticker_it = sticker_it + 1) {
			DcSticker* _tmp2_;
			DcSticker* sticker = NULL;
			_tmp2_ = _g_object_ref0 (sticker_collection[sticker_it]);
			sticker = _tmp2_;
			{
				DcSticker* _tmp3_;
				_tmp3_ = sticker;
				dc_sticker_store_delete_sticker (_tmp3_);
				_g_object_unref0 (sticker);
			}
		}
		sticker_collection = (_vala_array_free (sticker_collection, sticker_collection_length1, (GDestroyNotify) g_object_unref), NULL);
	}
}

/** Copy a file into a pack. The file names are content checksums,
            so a same-named sticker already in the pack is the same sticker:
            returns false and copies nothing. */
gboolean
dc_sticker_store_add_sticker (const gchar* pack,
                              const gchar* source_path,
                              GError** error)
{
	gchar* display = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	GFile* src = NULL;
	GFile* _tmp4_;
	GFile* dst = NULL;
	const gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	GFile* _tmp10_;
	GFile* _tmp11_;
	GFile* _tmp12_;
	GFile* _tmp13_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (pack != NULL, FALSE);
	g_return_val_if_fail (source_path != NULL, FALSE);
	_tmp0_ = g_path_get_basename (source_path);
	display = _tmp0_;
	_tmp1_ = display;
	if (dc_sticker_store_has_display_name (pack, _tmp1_)) {
		result = FALSE;
		_g_free0 (display);
		return result;
	}
	_tmp2_ = dc_sticker_store_get_stickers_dir ();
	_tmp3_ = _tmp2_;
	g_mkdir_with_parents (_tmp3_, 0755);
	_g_free0 (_tmp3_);
	_tmp4_ = g_file_new_for_path (source_path);
	src = _tmp4_;
	_tmp5_ = display;
	_tmp6_ = dc_sticker_store_build_file_name (pack, "", _tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = dc_sticker_store_sticker_path (_tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = g_file_new_for_path (_tmp9_);
	_tmp11_ = _tmp10_;
	_g_free0 (_tmp9_);
	_g_free0 (_tmp7_);
	dst = _tmp11_;
	_tmp12_ = src;
	_tmp13_ = dst;
	g_file_copy (_tmp12_, _tmp13_, G_FILE_COPY_NONE, NULL, NULL, NULL, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp14_ = FALSE;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (dst);
		_g_object_unref0 (src);
		_g_free0 (display);
		return _tmp14_;
	}
	result = TRUE;
	_g_object_unref0 (dst);
	_g_object_unref0 (src);
	_g_free0 (display);
	return result;
}

/** Rename a sticker into another pack, keeping its emoji. Returns
            false when the destination already holds this sticker. */
gboolean
dc_sticker_store_move_sticker (DcSticker* sticker,
                               const gchar* dest_pack,
                               GError** error)
{
	const gchar* _tmp0_;
	gchar* new_name = NULL;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	gchar* _tmp7_;
	const gchar* _tmp8_;
	gchar* _tmp9_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (sticker != NULL, FALSE);
	g_return_val_if_fail (dest_pack != NULL, FALSE);
	_tmp0_ = sticker->display_name;
	if (dc_sticker_store_has_display_name (dest_pack, _tmp0_)) {
		result = FALSE;
		return result;
	}
	_tmp1_ = sticker->emoji;
	_tmp2_ = sticker->display_name;
	_tmp3_ = dc_sticker_store_build_file_name (dest_pack, _tmp1_, _tmp2_);
	new_name = _tmp3_;
	_tmp4_ = sticker->file_name;
	_tmp5_ = new_name;
	dc_sticker_store_rename (_tmp4_, _tmp5_, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp6_ = FALSE;
		g_propagate_error (error, _inner_error0_);
		_g_free0 (new_name);
		return _tmp6_;
	}
	_tmp7_ = g_strdup (dest_pack);
	_g_free0 (sticker->pack);
	sticker->pack = _tmp7_;
	_tmp8_ = new_name;
	_tmp9_ = g_strdup (_tmp8_);
	_g_free0 (sticker->file_name);
	sticker->file_name = _tmp9_;
	result = TRUE;
	_g_free0 (new_name);
	return result;
}

/** Re-encode the sticker file name with a new emoji. */
void
dc_sticker_store_set_emoji (DcSticker* sticker,
                            const gchar* emoji,
                            GError** error)
{
	gchar* new_name = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (sticker != NULL);
	g_return_if_fail (emoji != NULL);
	_tmp0_ = sticker->pack;
	_tmp1_ = sticker->display_name;
	_tmp2_ = dc_sticker_store_build_file_name (_tmp0_, emoji, _tmp1_);
	new_name = _tmp2_;
	_tmp3_ = sticker->file_name;
	dc_sticker_store_rename (_tmp3_, new_name, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_free0 (new_name);
		return;
	}
	_tmp4_ = g_strdup (emoji);
	_g_free0 (sticker->emoji);
	sticker->emoji = _tmp4_;
	_tmp5_ = g_strdup (new_name);
	_g_free0 (sticker->file_name);
	sticker->file_name = _tmp5_;
	_g_free0 (new_name);
}

void
dc_sticker_store_delete_sticker (DcSticker* sticker)
{
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	g_return_if_fail (sticker != NULL);
	_tmp0_ = sticker->file_name;
	_tmp1_ = dc_sticker_store_sticker_path (_tmp0_);
	_tmp2_ = _tmp1_;
	g_unlink (_tmp2_);
	_g_free0 (_tmp2_);
}

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

static gint
__lambda29_ (DcSticker* a,
             DcSticker* b)
{
	GCompareFunc _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gint result;
	g_return_val_if_fail (a != NULL, -1);
	g_return_val_if_fail (b != NULL, -1);
	_tmp0_ = ((GCompareFunc) g_strcmp0);
	_tmp1_ = a->display_name;
	_tmp2_ = b->display_name;
	result = _tmp0_ (_tmp1_, _tmp2_);
	return result;
}

static gint
___lambda29__gcompare_func (gconstpointer a,
                            gconstpointer b)
{
	gint result;
	result = __lambda29_ ((DcSticker*) a, (DcSticker*) b);
	return result;
}

static GPtrArray*
dc_sticker_store_list_all (void)
{
	GPtrArray* found = NULL;
	GPtrArray* _tmp0_;
	GPtrArray* _tmp15_;
	GError* _inner_error0_ = NULL;
	GPtrArray* result;
	_tmp0_ = g_ptr_array_new_full ((guint) 0, _g_object_unref0_);
	found = _tmp0_;
	{
		GDir* dir = NULL;
		gchar* _tmp1_;
		gchar* _tmp2_;
		GDir* _tmp3_;
		GDir* _tmp4_;
		gchar* name = NULL;
		_tmp1_ = dc_sticker_store_get_stickers_dir ();
		_tmp2_ = _tmp1_;
		_tmp3_ = g_dir_open (_tmp2_, (guint) 0, &_inner_error0_);
		_tmp4_ = _tmp3_;
		_g_free0 (_tmp2_);
		dir = _tmp4_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		while (TRUE) {
			GDir* _tmp5_;
			const gchar* _tmp6_;
			gchar* _tmp7_;
			const gchar* _tmp8_;
			DcSticker* sticker = NULL;
			const gchar* _tmp9_;
			DcSticker* _tmp10_;
			DcSticker* _tmp11_;
			_tmp5_ = dir;
			_tmp6_ = g_dir_read_name (_tmp5_);
			_tmp7_ = g_strdup (_tmp6_);
			_g_free0 (name);
			name = _tmp7_;
			_tmp8_ = name;
			if (!(_tmp8_ != NULL)) {
				break;
			}
			_tmp9_ = name;
			_tmp10_ = dc_sticker_store_parse (_tmp9_);
			sticker = _tmp10_;
			_tmp11_ = sticker;
			if (_tmp11_ != NULL) {
				GPtrArray* _tmp12_;
				DcSticker* _tmp13_;
				DcSticker* _tmp14_;
				_tmp12_ = found;
				_tmp13_ = sticker;
				_tmp14_ = _g_object_ref0 (_tmp13_);
				g_ptr_array_add (_tmp12_, _tmp14_);
			}
			_g_object_unref0 (sticker);
		}
		_g_free0 (name);
		_g_dir_close0 (dir);
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_inner_error0_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_ptr_array_unref0 (found);
		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 NULL;
	}
	_tmp15_ = found;
	vala_g_ptr_array_sort (_tmp15_, ___lambda29__gcompare_func);
	result = found;
	return result;
}

static gchar*
dc_sticker_store_build_file_name (const gchar* pack,
                                  const gchar* emoji,
                                  const gchar* display)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* result;
	g_return_val_if_fail (pack != NULL, NULL);
	g_return_val_if_fail (emoji != NULL, NULL);
	g_return_val_if_fail (display != NULL, NULL);
	_tmp0_ = g_strconcat (pack, DC_STICKER_STORE_SEP, NULL);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strconcat (_tmp1_, emoji, NULL);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strconcat (_tmp3_, DC_STICKER_STORE_SEP, NULL);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_strconcat (_tmp5_, display, NULL);
	_tmp7_ = _tmp6_;
	_g_free0 (_tmp5_);
	_g_free0 (_tmp3_);
	_g_free0 (_tmp1_);
	result = _tmp7_;
	return result;
}

static void
dc_sticker_store_rename (const gchar* from,
                         const gchar* to,
                         GError** error)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gboolean _tmp4_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (from != NULL);
	g_return_if_fail (to != NULL);
	if (g_strcmp0 (from, to) == 0) {
		return;
	}
	_tmp0_ = dc_sticker_store_sticker_path (from);
	_tmp1_ = _tmp0_;
	_tmp2_ = dc_sticker_store_sticker_path (to);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_rename (_tmp1_, _tmp3_) != 0;
	_g_free0 (_tmp3_);
	_g_free0 (_tmp1_);
	if (_tmp4_) {
		gchar* _tmp5_;
		gchar* _tmp6_;
		GError* _tmp7_;
		GError* _tmp8_;
		_tmp5_ = g_strdup_printf ("Could not rename %s", from);
		_tmp6_ = _tmp5_;
		_tmp7_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, _tmp6_);
		_tmp8_ = _tmp7_;
		_g_free0 (_tmp6_);
		_inner_error0_ = _tmp8_;
		g_propagate_error (error, _inner_error0_);
		return;
	}
}

static gboolean
dc_sticker_store_has_display_name (const gchar* pack,
                                   const gchar* display)
{
	gint _tmp0_ = 0;
	DcSticker** _tmp1_;
	gboolean result;
	g_return_val_if_fail (pack != NULL, FALSE);
	g_return_val_if_fail (display != NULL, FALSE);
	_tmp1_ = dc_sticker_store_list_stickers (pack, &_tmp0_);
	{
		DcSticker** sticker_collection = NULL;
		gint sticker_collection_length1 = 0;
		gint _sticker_collection_size_ = 0;
		gint sticker_it = 0;
		sticker_collection = _tmp1_;
		sticker_collection_length1 = _tmp0_;
		for (sticker_it = 0; sticker_it < sticker_collection_length1; sticker_it = sticker_it + 1) {
			DcSticker* _tmp2_;
			DcSticker* sticker = NULL;
			_tmp2_ = _g_object_ref0 (sticker_collection[sticker_it]);
			sticker = _tmp2_;
			{
				DcSticker* _tmp3_;
				const gchar* _tmp4_;
				_tmp3_ = sticker;
				_tmp4_ = _tmp3_->display_name;
				if (g_strcmp0 (_tmp4_, display) == 0) {
					result = TRUE;
					_g_object_unref0 (sticker);
					sticker_collection = (_vala_array_free (sticker_collection, sticker_collection_length1, (GDestroyNotify) g_object_unref), NULL);
					return result;
				}
				_g_object_unref0 (sticker);
			}
		}
		sticker_collection = (_vala_array_free (sticker_collection, sticker_collection_length1, (GDestroyNotify) g_object_unref), NULL);
	}
	result = FALSE;
	return result;
}

static gboolean
dc_sticker_store_contains (GPtrArray* items,
                           const gchar* value)
{
	gboolean result;
	g_return_val_if_fail (items != NULL, FALSE);
	g_return_val_if_fail (value != NULL, FALSE);
	{
		GPtrArray* item_collection = NULL;
		guint item_index = 0U;
		item_collection = items;
		for (item_index = 0; item_index < item_collection->len; item_index = item_index + 1) {
			gchar* _tmp0_;
			gchar* item = NULL;
			_tmp0_ = g_strdup ((gchar*) g_ptr_array_index (item_collection, item_index));
			item = _tmp0_;
			{
				const gchar* _tmp1_;
				_tmp1_ = item;
				if (g_strcmp0 (_tmp1_, value) == 0) {
					result = TRUE;
					_g_free0 (item);
					return result;
				}
				_g_free0 (item);
			}
		}
	}
	result = FALSE;
	return result;
}

DcStickerStore*
dc_sticker_store_construct (GType object_type)
{
	DcStickerStore * self = NULL;
	self = (DcStickerStore*) g_object_new (object_type, NULL);
	return self;
}

DcStickerStore*
dc_sticker_store_new (void)
{
	return dc_sticker_store_construct (DC_TYPE_STICKER_STORE);
}

static void
dc_sticker_store_class_init (DcStickerStoreClass * klass,
                             gpointer klass_data)
{
	dc_sticker_store_parent_class = g_type_class_peek_parent (klass);
}

static void
dc_sticker_store_instance_init (DcStickerStore * self,
                                gpointer klass)
{
}

/**
     * Flat on-disk sticker storage: a single <parla data dir>/stickers
     * directory where each gif/webp/webm file is named
     * "<pack>__<emoji>__<original name>", so the pack and the associated
     * emoji live in the file name and changing either is a rename. A pack
     * exists exactly while at least one file carries its prefix.
     */
static GType
dc_sticker_store_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DcStickerStoreClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_sticker_store_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcStickerStore), 0, (GInstanceInitFunc) dc_sticker_store_instance_init, NULL };
	GType dc_sticker_store_type_id;
	dc_sticker_store_type_id = g_type_register_static (G_TYPE_OBJECT, "DcStickerStore", &g_define_type_info, 0);
	return dc_sticker_store_type_id;
}

GType
dc_sticker_store_get_type (void)
{
	static volatile gsize dc_sticker_store_type_id__once = 0;
	if (g_once_init_enter (&dc_sticker_store_type_id__once)) {
		GType dc_sticker_store_type_id;
		dc_sticker_store_type_id = dc_sticker_store_get_type_once ();
		g_once_init_leave (&dc_sticker_store_type_id__once, dc_sticker_store_type_id);
	}
	return dc_sticker_store_type_id__once;
}

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 gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

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

