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

#include "protonplus_core.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include "config.h"
#include <glib/gstdio.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_MODELS_LAUNCHERS_FAUGUS_LAUNCHER_0_PROPERTY,
	PROTON_PLUS_MODELS_LAUNCHERS_FAUGUS_LAUNCHER_NUM_PROPERTIES
};
static GParamSpec* proton_plus_models_launchers_faugus_launcher_properties[PROTON_PLUS_MODELS_LAUNCHERS_FAUGUS_LAUNCHER_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))

static gpointer proton_plus_models_launchers_faugus_launcher_parent_class = NULL;

static ProtonPlusModelsSteamRestartTarget* proton_plus_models_launchers_faugus_launcher_real_get_steam_restart_target (ProtonPlusModelsLauncher* base);
static gchar* proton_plus_models_launchers_faugus_launcher_real_get_install_target_error (ProtonPlusModelsLauncher* base,
                                                                                   const gchar* target_directory);
static gboolean proton_plus_models_launchers_faugus_launcher_real_supports_provider_definition (ProtonPlusModelsLauncher* base,
                                                                                         ProtonPlusModelsProvidersProviderDefinition* definition);
static GType proton_plus_models_launchers_faugus_launcher_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);

ProtonPlusModelsLaunchersFaugusLauncher*
proton_plus_models_launchers_faugus_launcher_construct (GType object_type,
                                                        ProtonPlusModelsLauncherInstallationTypes installation_type,
                                                        const gchar* home_directory_override,
                                                        const gchar* host_data_home_override,
                                                        const gchar* config_home_override,
                                                        const gchar* data_home_override,
                                                        const gchar* state_home_override)
{
	ProtonPlusModelsLaunchersFaugusLauncher * self = NULL;
	const gchar* _tmp0_ = NULL;
	gchar* home_directory = NULL;
	gchar* _tmp2_;
	const gchar* _tmp3_ = NULL;
	gchar* config_home = NULL;
	gchar* _tmp5_;
	const gchar* _tmp6_ = NULL;
	gchar* data_home = NULL;
	gchar* _tmp8_;
	const gchar* _tmp9_ = NULL;
	gchar* state_home = NULL;
	gchar* _tmp11_;
	gboolean _tmp12_ = FALSE;
	const gchar* _tmp13_;
	const gchar* _tmp17_ = NULL;
	gchar* host_data_home = NULL;
	gchar* _tmp19_;
	gboolean _tmp20_ = FALSE;
	const gchar* _tmp21_;
	gchar** detection_markers = NULL;
	gint detection_markers_length1 = 0;
	gint _detection_markers_size_ = 0;
	gchar* _tmp44_;
	gchar* _tmp45_;
	gchar** _tmp46_;
	gchar** _tmp47_;
	gint _tmp47__length1;
	gchar** _tmp48_;
	gint _tmp48__length1;
	const gchar* _tmp49_;
	gchar* _tmp50_;
	gchar* _tmp51_;
	gboolean _tmp52_ = FALSE;
	_tmp0_ = home_directory_override;
	if (_tmp0_ == NULL) {
		const gchar* _tmp1_;
		_tmp1_ = g_get_home_dir ();
		_tmp0_ = _tmp1_;
	}
	_tmp2_ = g_strdup (_tmp0_);
	home_directory = _tmp2_;
	_tmp3_ = config_home_override;
	if (_tmp3_ == NULL) {
		const gchar* _tmp4_;
		_tmp4_ = g_get_user_config_dir ();
		_tmp3_ = _tmp4_;
	}
	_tmp5_ = g_strdup (_tmp3_);
	config_home = _tmp5_;
	_tmp6_ = data_home_override;
	if (_tmp6_ == NULL) {
		const gchar* _tmp7_;
		_tmp7_ = g_get_user_data_dir ();
		_tmp6_ = _tmp7_;
	}
	_tmp8_ = g_strdup (_tmp6_);
	data_home = _tmp8_;
	_tmp9_ = state_home_override;
	if (_tmp9_ == NULL) {
		const gchar* _tmp10_;
		_tmp10_ = g_getenv ("XDG_STATE_HOME");
		_tmp9_ = _tmp10_;
	}
	_tmp11_ = g_strdup (_tmp9_);
	state_home = _tmp11_;
	_tmp13_ = state_home;
	if (_tmp13_ == NULL) {
		_tmp12_ = TRUE;
	} else {
		const gchar* _tmp14_;
		_tmp14_ = state_home;
		_tmp12_ = g_strcmp0 (_tmp14_, "") == 0;
	}
	if (_tmp12_) {
		const gchar* _tmp15_;
		gchar* _tmp16_;
		_tmp15_ = home_directory;
		_tmp16_ = g_build_filename (_tmp15_, ".local", "state", NULL);
		_g_free0 (state_home);
		state_home = _tmp16_;
	}
	_tmp17_ = host_data_home_override;
	if (_tmp17_ == NULL) {
		const gchar* _tmp18_;
		_tmp18_ = g_getenv ("HOST_XDG_DATA_HOME");
		_tmp17_ = _tmp18_;
	}
	_tmp19_ = g_strdup (_tmp17_);
	host_data_home = _tmp19_;
	_tmp21_ = host_data_home;
	if (_tmp21_ == NULL) {
		_tmp20_ = TRUE;
	} else {
		const gchar* _tmp22_;
		_tmp22_ = host_data_home;
		_tmp20_ = g_strcmp0 (_tmp22_, "") == 0;
	}
	if (_tmp20_) {
		const gchar* _tmp23_;
		gchar* _tmp24_;
		_tmp23_ = home_directory;
		_tmp24_ = g_build_filename (_tmp23_, ".local", "share", NULL);
		_g_free0 (host_data_home);
		host_data_home = _tmp24_;
	}
	switch (installation_type) {
		case PROTON_PLUS_MODELS_LAUNCHER_INSTALLATION_TYPES_SYSTEM:
		{
			const gchar* _tmp25_;
			gchar* _tmp26_;
			const gchar* _tmp27_;
			gchar* _tmp28_;
			const gchar* _tmp29_;
			gchar* _tmp30_;
			const gchar* _tmp31_;
			gchar* _tmp32_;
			const gchar* _tmp33_;
			gchar* _tmp34_;
			gchar** _tmp35_;
			_tmp25_ = config_home;
			_tmp26_ = g_build_filename (_tmp25_, "faugus-launcher", NULL);
			_tmp27_ = data_home;
			_tmp28_ = g_build_filename (_tmp27_, "faugus-launcher", NULL);
			_tmp29_ = state_home;
			_tmp30_ = g_build_filename ((const gchar*) _tmp29_, "faugus-launcher", NULL);
			_tmp31_ = home_directory;
			_tmp32_ = g_build_filename (_tmp31_, ".config", "faugus-launcher", NULL);
			_tmp33_ = home_directory;
			_tmp34_ = g_build_filename (_tmp33_, ".local", "share", "faugus-launcher", NULL);
			_tmp35_ = g_new0 (gchar*, 5 + 1);
			_tmp35_[0] = _tmp26_;
			_tmp35_[1] = _tmp28_;
			_tmp35_[2] = _tmp30_;
			_tmp35_[3] = _tmp32_;
			_tmp35_[4] = _tmp34_;
			detection_markers = (_vala_array_free (detection_markers, detection_markers_length1, (GDestroyNotify) g_free), NULL);
			detection_markers = _tmp35_;
			detection_markers_length1 = 5;
			_detection_markers_size_ = detection_markers_length1;
			break;
		}
		case PROTON_PLUS_MODELS_LAUNCHER_INSTALLATION_TYPES_FLATPAK:
		{
			const gchar* _tmp36_;
			gchar* _tmp37_;
			const gchar* _tmp38_;
			gchar* _tmp39_;
			const gchar* _tmp40_;
			gchar* _tmp41_;
			gchar** _tmp42_;
			_tmp36_ = home_directory;
			_tmp37_ = g_build_filename (_tmp36_, ".var", "app", PROTON_PLUS_MODELS_LAUNCHERS_FAUGUS_LAUNCHER_FLATPAK_ID, "config", "faugus-launcher", NULL);
			_tmp38_ = home_directory;
			_tmp39_ = g_build_filename (_tmp38_, ".var", "app", PROTON_PLUS_MODELS_LAUNCHERS_FAUGUS_LAUNCHER_FLATPAK_ID, "data", "faugus-launcher", NULL);
			_tmp40_ = home_directory;
			_tmp41_ = g_build_filename (_tmp40_, ".var", "app", PROTON_PLUS_MODELS_LAUNCHERS_FAUGUS_LAUNCHER_FLATPAK_ID, ".local", "state", "faugus-launcher", NULL);
			_tmp42_ = g_new0 (gchar*, 3 + 1);
			_tmp42_[0] = _tmp37_;
			_tmp42_[1] = _tmp39_;
			_tmp42_[2] = _tmp41_;
			detection_markers = (_vala_array_free (detection_markers, detection_markers_length1, (GDestroyNotify) g_free), NULL);
			detection_markers = _tmp42_;
			detection_markers_length1 = 3;
			_detection_markers_size_ = detection_markers_length1;
			break;
		}
		default:
		{
			gchar** _tmp43_;
			_tmp43_ = g_new0 (gchar*, 0 + 1);
			detection_markers = (_vala_array_free (detection_markers, detection_markers_length1, (GDestroyNotify) g_free), NULL);
			detection_markers = _tmp43_;
			detection_markers_length1 = 0;
			_detection_markers_size_ = detection_markers_length1;
			break;
		}
	}
	_tmp44_ = g_strdup_printf ("%s/faugus-launcher.svg", RESOURCE_BASE);
	_tmp45_ = _tmp44_;
	_tmp46_ = g_new0 (gchar*, 0 + 1);
	_tmp47_ = _tmp46_;
	_tmp47__length1 = 0;
	_tmp48_ = detection_markers;
	_tmp48__length1 = detection_markers_length1;
	_tmp49_ = host_data_home;
	_tmp50_ = g_build_filename ((const gchar*) _tmp49_, "Steam", NULL);
	_tmp51_ = _tmp50_;
	self = (ProtonPlusModelsLaunchersFaugusLauncher*) proton_plus_models_launcher_construct (object_type, "Faugus Launcher", installation_type, _tmp45_, _tmp47_, (gint) 0, PROTON_PLUS_MODELS_LAUNCHERS_FAUGUS_LAUNCHER_FAMILY_ID, _tmp48_, (gint) _tmp48__length1, _tmp51_, PROTON_PLUS_MODELS_LAUNCHERS_STEAM_FAMILY_ID, "steam-system");
	_g_free0 (_tmp51_);
	_tmp47_ = (_vala_array_free (_tmp47_, _tmp47__length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (_tmp45_);
	if (installation_type == PROTON_PLUS_MODELS_LAUNCHER_INSTALLATION_TYPES_FLATPAK) {
		_tmp52_ = proton_plus_globals_IS_FLATPAK;
	} else {
		_tmp52_ = FALSE;
	}
	if (_tmp52_) {
		((ProtonPlusModelsLauncher*) self)->installed = proton_plus_globals_FAUGUS_FLATPAK_INSTALLED;
	}
	detection_markers = (_vala_array_free (detection_markers, detection_markers_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (host_data_home);
	_g_free0 (state_home);
	_g_free0 (data_home);
	_g_free0 (config_home);
	_g_free0 (home_directory);
	return self;
}

ProtonPlusModelsLaunchersFaugusLauncher*
proton_plus_models_launchers_faugus_launcher_new (ProtonPlusModelsLauncherInstallationTypes installation_type,
                                                  const gchar* home_directory_override,
                                                  const gchar* host_data_home_override,
                                                  const gchar* config_home_override,
                                                  const gchar* data_home_override,
                                                  const gchar* state_home_override)
{
	return proton_plus_models_launchers_faugus_launcher_construct (PROTON_PLUS_MODELS_LAUNCHERS_TYPE_FAUGUS_LAUNCHER, installation_type, home_directory_override, host_data_home_override, config_home_override, data_home_override, state_home_override);
}

static ProtonPlusModelsSteamRestartTarget*
proton_plus_models_launchers_faugus_launcher_real_get_steam_restart_target (ProtonPlusModelsLauncher* base)
{
	ProtonPlusModelsLaunchersFaugusLauncher * self;
	const gchar* _tmp0_;
	ProtonPlusModelsSteamRestartTarget* _tmp1_;
	ProtonPlusModelsSteamRestartTarget* result;
	self = (ProtonPlusModelsLaunchersFaugusLauncher*) base;
	_tmp0_ = ((ProtonPlusModelsLauncher*) self)->directory;
	_tmp1_ = proton_plus_models_steam_restart_target_for_native (_tmp0_, "Steam", "steam.desktop");
	result = _tmp1_;
	return result;
}

static gchar*
proton_plus_models_launchers_faugus_launcher_real_get_install_target_error (ProtonPlusModelsLauncher* base,
                                                                            const gchar* target_directory)
{
	ProtonPlusModelsLaunchersFaugusLauncher * self;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gchar* command = NULL;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* result;
	self = (ProtonPlusModelsLaunchersFaugusLauncher*) base;
	g_return_val_if_fail (target_directory != NULL, NULL);
	if (!proton_plus_globals_IS_FLATPAK) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = !g_file_test (target_directory, G_FILE_TEST_IS_SYMLINK);
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_file_test (target_directory, G_FILE_TEST_IS_DIR);
	}
	if (_tmp0_) {
		result = NULL;
		return result;
	}
	_tmp2_ = g_strdup_printf ("flatpak override --user --filesystem=\"$HOME/.local/share/Steam/compat" \
"ibilitytools.d\" %s", APP_ID);
	command = _tmp2_;
	_tmp3_ = command;
	_tmp4_ = g_strdup_printf ("%s\n%s\n\n%s\n%s", _ ("Faugus Launcher uses this folder for Proton installations, but ProtonP" \
"lus cannot access its symlink target:"), target_directory, _ ("Grant ProtonPlus access, restart it, and try the installation again:"), _tmp3_);
	result = _tmp4_;
	_g_free0 (command);
	return result;
}

static gboolean
proton_plus_models_launchers_faugus_launcher_real_supports_provider_definition (ProtonPlusModelsLauncher* base,
                                                                                ProtonPlusModelsProvidersProviderDefinition* definition)
{
	ProtonPlusModelsLaunchersFaugusLauncher * self;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	GQuark _tmp4_ = 0U;
	static GQuark _tmp3_label0 = 0;
	static GQuark _tmp3_label1 = 0;
	static GQuark _tmp3_label2 = 0;
	static GQuark _tmp3_label3 = 0;
	gboolean result;
	self = (ProtonPlusModelsLaunchersFaugusLauncher*) base;
	g_return_val_if_fail (definition != NULL, FALSE);
	_tmp0_ = proton_plus_models_providers_provider_definition_get_provider_id (definition);
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_;
	_tmp4_ = (NULL == _tmp2_) ? 0 : g_quark_from_string (_tmp2_);
	if ((((_tmp4_ == ((0 != _tmp3_label0) ? _tmp3_label0 : (_tmp3_label0 = g_quark_from_static_string ("proton-ge")))) || (_tmp4_ == ((0 != _tmp3_label1) ? _tmp3_label1 : (_tmp3_label1 = g_quark_from_static_string ("proton-em"))))) || (_tmp4_ == ((0 != _tmp3_label2) ? _tmp3_label2 : (_tmp3_label2 = g_quark_from_static_string ("proton-cachyos"))))) || (_tmp4_ == ((0 != _tmp3_label3) ? _tmp3_label3 : (_tmp3_label3 = g_quark_from_static_string ("dw-proton"))))) {
		switch (0) {
			default:
			{
				result = TRUE;
				return result;
			}
		}
	} else {
		switch (0) {
			default:
			{
				result = FALSE;
				return result;
			}
		}
	}
}

static void
proton_plus_models_launchers_faugus_launcher_class_init (ProtonPlusModelsLaunchersFaugusLauncherClass * klass,
                                                         gpointer klass_data)
{
	proton_plus_models_launchers_faugus_launcher_parent_class = g_type_class_peek_parent (klass);
	((ProtonPlusModelsLauncherClass *) klass)->get_steam_restart_target = (ProtonPlusModelsSteamRestartTarget* (*) (ProtonPlusModelsLauncher*)) proton_plus_models_launchers_faugus_launcher_real_get_steam_restart_target;
	((ProtonPlusModelsLauncherClass *) klass)->get_install_target_error = (gchar* (*) (ProtonPlusModelsLauncher*, const gchar*)) proton_plus_models_launchers_faugus_launcher_real_get_install_target_error;
	((ProtonPlusModelsLauncherClass *) klass)->supports_provider_definition = (gboolean (*) (ProtonPlusModelsLauncher*, ProtonPlusModelsProvidersProviderDefinition*)) proton_plus_models_launchers_faugus_launcher_real_supports_provider_definition;
}

static void
proton_plus_models_launchers_faugus_launcher_instance_init (ProtonPlusModelsLaunchersFaugusLauncher * self,
                                                            gpointer klass)
{
}

static GType
proton_plus_models_launchers_faugus_launcher_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ProtonPlusModelsLaunchersFaugusLauncherClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) proton_plus_models_launchers_faugus_launcher_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ProtonPlusModelsLaunchersFaugusLauncher), 0, (GInstanceInitFunc) proton_plus_models_launchers_faugus_launcher_instance_init, NULL };
	GType proton_plus_models_launchers_faugus_launcher_type_id;
	proton_plus_models_launchers_faugus_launcher_type_id = g_type_register_static (PROTON_PLUS_MODELS_TYPE_LAUNCHER, "ProtonPlusModelsLaunchersFaugusLauncher", &g_define_type_info, 0);
	return proton_plus_models_launchers_faugus_launcher_type_id;
}

GType
proton_plus_models_launchers_faugus_launcher_get_type (void)
{
	static volatile gsize proton_plus_models_launchers_faugus_launcher_type_id__once = 0;
	if (g_once_init_enter (&proton_plus_models_launchers_faugus_launcher_type_id__once)) {
		GType proton_plus_models_launchers_faugus_launcher_type_id;
		proton_plus_models_launchers_faugus_launcher_type_id = proton_plus_models_launchers_faugus_launcher_get_type_once ();
		g_once_init_leave (&proton_plus_models_launchers_faugus_launcher_type_id__once, proton_plus_models_launchers_faugus_launcher_type_id);
	}
	return proton_plus_models_launchers_faugus_launcher_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;
}

