/* launch-options-editor-amd-icd.c generated by valac 0.56.19, the Vala compiler
 * generated from launch-options-editor-amd-icd.vala, do not modify */

#include "protonplus_core.h"
#include <gee.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib/gi18n-lib.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  {
	PROTON_PLUS_WIDGETS_GAMES_LAUNCH_OPTIONS_EDITOR_LAUNCH_OPTION_AMD_ICD_0_PROPERTY,
	PROTON_PLUS_WIDGETS_GAMES_LAUNCH_OPTIONS_EDITOR_LAUNCH_OPTION_AMD_ICD_NUM_PROPERTIES
};
static GParamSpec* proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_properties[PROTON_PLUS_WIDGETS_GAMES_LAUNCH_OPTIONS_EDITOR_LAUNCH_OPTION_AMD_ICD_NUM_PROPERTIES];
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))

static gpointer proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_parent_class = NULL;

static void _g_free0_ (gpointer var);
static void proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_real_append_command_segments (ProtonPlusWidgetsGamesLaunchOptionsEditorLaunchOptionCustomPairs* base,
                                                                                                         GeeLinkedList* segments);
static GType proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_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 inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static void
_g_free0_ (gpointer var)
{
	var = (g_free (var), NULL);
}

ProtonPlusWidgetsGamesLaunchOptionsEditorLaunchOptionAmdIcd*
proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_construct (GType object_type)
{
	ProtonPlusWidgetsGamesLaunchOptionsEditorLaunchOptionAmdIcd * self = NULL;
	gchar** keys = NULL;
	gchar* _tmp0_;
	gchar** _tmp1_;
	gint keys_length1;
	gint _keys_size_;
	gchar** display_opts = NULL;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar** _tmp5_;
	gint display_opts_length1;
	gint _display_opts_size_;
	gchar** value_opts = NULL;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar** _tmp9_;
	gint value_opts_length1;
	gint _value_opts_size_;
	GHashTable* tooltips = NULL;
	GHashFunc _tmp10_;
	GEqualFunc _tmp11_;
	GHashTable* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	_tmp0_ = g_strdup ("driver");
	_tmp1_ = g_new0 (gchar*, 1 + 1);
	_tmp1_[0] = _tmp0_;
	keys = _tmp1_;
	keys_length1 = 1;
	_keys_size_ = keys_length1;
	_tmp2_ = g_strdup (_ ("System Default"));
	_tmp3_ = g_strdup ("Mesa RADV (RADV)");
	_tmp4_ = g_strdup ("AMD Proprietary (AMDVLK)");
	_tmp5_ = g_new0 (gchar*, 3 + 1);
	_tmp5_[0] = _tmp2_;
	_tmp5_[1] = _tmp3_;
	_tmp5_[2] = _tmp4_;
	display_opts = _tmp5_;
	display_opts_length1 = 3;
	_display_opts_size_ = display_opts_length1;
	_tmp6_ = g_strdup ("");
	_tmp7_ = g_strdup ("RADV");
	_tmp8_ = g_strdup ("AMDVLK");
	_tmp9_ = g_new0 (gchar*, 3 + 1);
	_tmp9_[0] = _tmp6_;
	_tmp9_[1] = _tmp7_;
	_tmp9_[2] = _tmp8_;
	value_opts = _tmp9_;
	value_opts_length1 = 3;
	_value_opts_size_ = value_opts_length1;
	_tmp10_ = g_str_hash;
	_tmp11_ = g_str_equal;
	_tmp12_ = g_hash_table_new_full (_tmp10_, _tmp11_, _g_free0_, _g_free0_);
	tooltips = _tmp12_;
	_tmp13_ = g_strdup ("driver");
	_tmp14_ = g_strdup (_ ("Switch between open-source Mesa driver and official AMDVLK driver."));
	g_hash_table_insert (tooltips, _tmp13_, _tmp14_);
	self = (ProtonPlusWidgetsGamesLaunchOptionsEditorLaunchOptionAmdIcd*) proton_plus_widgets_games_launch_options_editor_launch_option_custom_pairs_construct (object_type, _ ("AMD Vulkan ICD Driver"), _ ("Select preferred Vulkan driver implementation"), _ ("Force Vulkan Driver"), _ ("Override system-wide Vulkan driver preference for this game"), keys, (gint) keys_length1, display_opts, (gint) display_opts_length1, value_opts, (gint) value_opts_length1, tooltips, ",", "AMD_ICD");
	_g_hash_table_unref0 (tooltips);
	value_opts = (_vala_array_free (value_opts, value_opts_length1, (GDestroyNotify) g_free), NULL);
	display_opts = (_vala_array_free (display_opts, display_opts_length1, (GDestroyNotify) g_free), NULL);
	keys = (_vala_array_free (keys, keys_length1, (GDestroyNotify) g_free), NULL);
	return self;
}

ProtonPlusWidgetsGamesLaunchOptionsEditorLaunchOptionAmdIcd*
proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_new (void)
{
	return proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_construct (PROTON_PLUS_WIDGETS_GAMES_LAUNCH_OPTIONS_EDITOR_TYPE_LAUNCH_OPTION_AMD_ICD);
}

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

static void
proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_real_append_command_segments (ProtonPlusWidgetsGamesLaunchOptionsEditorLaunchOptionCustomPairs* base,
                                                                                                    GeeLinkedList* segments)
{
	ProtonPlusWidgetsGamesLaunchOptionsEditorLaunchOptionAmdIcd * self;
	gchar* val = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	self = (ProtonPlusWidgetsGamesLaunchOptionsEditorLaunchOptionAmdIcd*) base;
	g_return_if_fail (segments != NULL);
	_tmp0_ = proton_plus_widgets_games_launch_options_editor_launch_option_custom_pairs_get_value ((ProtonPlusWidgetsGamesLaunchOptionsEditorLaunchOptionCustomPairs*) self);
	_tmp1_ = _tmp0_;
	val = _tmp1_;
	_tmp2_ = val;
	if (g_strcmp0 (_tmp2_, "") != 0) {
		gchar* driver_name = NULL;
		const gchar* _tmp3_;
		gchar* _tmp4_;
		const gchar* _tmp5_;
		const gchar* _tmp6_;
		const gchar* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		_tmp3_ = val;
		_tmp4_ = string_replace (_tmp3_, "driver=", "");
		driver_name = _tmp4_;
		_tmp5_ = proton_plus_widgets_games_launch_options_editor_launch_option_custom_pairs_get_environment_variable_prefix ((ProtonPlusWidgetsGamesLaunchOptionsEditorLaunchOptionCustomPairs*) self);
		_tmp6_ = _tmp5_;
		_tmp7_ = driver_name;
		_tmp8_ = g_strconcat (_tmp6_, _tmp7_, NULL);
		_tmp9_ = _tmp8_;
		gee_abstract_collection_add ((GeeAbstractCollection*) segments, _tmp9_);
		_g_free0 (_tmp9_);
		_g_free0 (driver_name);
	}
	_g_free0 (val);
}

static void
proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_class_init (ProtonPlusWidgetsGamesLaunchOptionsEditorLaunchOptionAmdIcdClass * klass,
                                                                                  gpointer klass_data)
{
	proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_parent_class = g_type_class_peek_parent (klass);
	((ProtonPlusWidgetsGamesLaunchOptionsEditorLaunchOptionCustomPairsClass *) klass)->append_command_segments = (void (*) (ProtonPlusWidgetsGamesLaunchOptionsEditorLaunchOptionCustomPairs*, GeeLinkedList*)) proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_real_append_command_segments;
}

static void
proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_instance_init (ProtonPlusWidgetsGamesLaunchOptionsEditorLaunchOptionAmdIcd * self,
                                                                                     gpointer klass)
{
}

static GType
proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ProtonPlusWidgetsGamesLaunchOptionsEditorLaunchOptionAmdIcdClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ProtonPlusWidgetsGamesLaunchOptionsEditorLaunchOptionAmdIcd), 0, (GInstanceInitFunc) proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_instance_init, NULL };
	GType proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_type_id;
	proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_type_id = g_type_register_static (PROTON_PLUS_WIDGETS_GAMES_LAUNCH_OPTIONS_EDITOR_TYPE_LAUNCH_OPTION_CUSTOM_PAIRS, "ProtonPlusWidgetsGamesLaunchOptionsEditorLaunchOptionAmdIcd", &g_define_type_info, 0);
	return proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_type_id;
}

GType
proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_get_type (void)
{
	static volatile gsize proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_type_id__once = 0;
	if (g_once_init_enter (&proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_type_id__once)) {
		GType proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_type_id;
		proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_type_id = proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_get_type_once ();
		g_once_init_leave (&proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_type_id__once, proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_type_id);
	}
	return proton_plus_widgets_games_launch_options_editor_launch_option_amd_icd_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 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;
}

