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

#include <gio/gio.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gstdio.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
#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 _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_settings_schema_unref0(var) ((var == NULL) ? NULL : (var = (g_settings_schema_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_settings_schema_source_unref0(var) ((var == NULL) ? NULL : (var = (g_settings_schema_source_unref (var), NULL)))
typedef struct _ProtonPlusGlobalsLoadData ProtonPlusGlobalsLoadData;

struct _ProtonPlusGlobalsLoadData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GSettingsSchemaSource* schema_source;
	GSettingsSchemaSource* _tmp0_;
	GSettingsSchemaSource* _tmp1_;
	GSettingsSchemaSource* _tmp2_;
	GSettingsSchema* schema;
	GSettingsSchemaSource* _tmp3_;
	GSettingsSchema* _tmp4_;
	GSettingsSchema* _tmp5_;
	GSettingsSchema* _tmp6_;
	GSettings* _tmp7_;
	const gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	GList* _tmp13_;
	gchar* _tmp14_;
	const gchar* _tmp15_;
	gchar* _tmp16_;
	const gchar* _tmp17_;
	const gchar* _tmp18_;
	const gchar* _tmp19_;
	gchar* _tmp20_;
	const gchar* _tmp21_;
	const gchar* _tmp22_;
};

VALA_EXTERN GSettings* proton_plus_globals_SETTINGS;
GSettings* proton_plus_globals_SETTINGS = NULL;
VALA_EXTERN gboolean proton_plus_globals_IS_STEAM_OS;
gboolean proton_plus_globals_IS_STEAM_OS = FALSE;
VALA_EXTERN gboolean proton_plus_globals_IS_GAMESCOPE;
gboolean proton_plus_globals_IS_GAMESCOPE = FALSE;
VALA_EXTERN gboolean proton_plus_globals_IS_FLATPAK;
gboolean proton_plus_globals_IS_FLATPAK = FALSE;
VALA_EXTERN GList* proton_plus_globals_HWCAPS;
GList* proton_plus_globals_HWCAPS = NULL;
VALA_EXTERN gchar* proton_plus_globals_CACHE_PATH;
gchar* proton_plus_globals_CACHE_PATH = NULL;
VALA_EXTERN gchar* proton_plus_globals_PROTONTRICKS_EXEC;
gchar* proton_plus_globals_PROTONTRICKS_EXEC = NULL;
VALA_EXTERN gchar* proton_plus_globals_CONFIG_PATH;
gchar* proton_plus_globals_CONFIG_PATH = NULL;

static void proton_plus_globals_load_data_free (gpointer _data);
VALA_EXTERN void proton_plus_globals_load (GAsyncReadyCallback _callback_,
                               gpointer _user_data_);
VALA_EXTERN void proton_plus_globals_load_finish (GAsyncResult* _res_);
static gboolean proton_plus_globals_load_co (ProtonPlusGlobalsLoadData* _data_);
VALA_EXTERN void proton_plus_utils_system_get_distribution_name (GAsyncReadyCallback _callback_,
                                                     gpointer _user_data_);
VALA_EXTERN gchar* proton_plus_utils_system_get_distribution_name_finish (GAsyncResult* _res_);
static void proton_plus_globals_load_ready (GObject* source_object,
                                     GAsyncResult* _res_,
                                     gpointer _user_data_);
VALA_EXTERN GList* proton_plus_utils_system_get_hwcaps (void);
static void _g_free0_ (gpointer var);
static inline void _g_list_free__g_free0_ (GList* self);
VALA_EXTERN void proton_plus_utils_system_get_protontricks_exec (GAsyncReadyCallback _callback_,
                                                     gpointer _user_data_);
VALA_EXTERN gchar* proton_plus_utils_system_get_protontricks_exec_finish (GAsyncResult* _res_);
VALA_EXTERN void proton_plus_utils_filesystem_create_directory (const gchar* path,
                                                    GAsyncReadyCallback _callback_,
                                                    gpointer _user_data_);
VALA_EXTERN gboolean proton_plus_utils_filesystem_create_directory_finish (GAsyncResult* _res_);

static void
proton_plus_globals_load_data_free (gpointer _data)
{
	ProtonPlusGlobalsLoadData* _data_;
	_data_ = _data;
	g_slice_free (ProtonPlusGlobalsLoadData, _data_);
}

void
proton_plus_globals_load (GAsyncReadyCallback _callback_,
                          gpointer _user_data_)
{
	ProtonPlusGlobalsLoadData* _data_;
	_data_ = g_slice_new0 (ProtonPlusGlobalsLoadData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, proton_plus_globals_load_data_free);
	proton_plus_globals_load_co (_data_);
}

void
proton_plus_globals_load_finish (GAsyncResult* _res_)
{
	ProtonPlusGlobalsLoadData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static gpointer
_g_settings_schema_source_ref0 (gpointer self)
{
	return self ? g_settings_schema_source_ref (self) : NULL;
}

static void
proton_plus_globals_load_ready (GObject* source_object,
                                GAsyncResult* _res_,
                                gpointer _user_data_)
{
	ProtonPlusGlobalsLoadData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	proton_plus_globals_load_co (_data_);
}

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

static inline void
_g_list_free__g_free0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_free0_);
}

static gboolean
proton_plus_globals_load_co (ProtonPlusGlobalsLoadData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		case 4:
		goto _state_4;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = g_settings_schema_source_get_default ();
	_data_->_tmp1_ = _g_settings_schema_source_ref0 (_data_->_tmp0_);
	_data_->schema_source = _data_->_tmp1_;
	_data_->_tmp2_ = _data_->schema_source;
	if (_data_->_tmp2_ != NULL) {
		_data_->_tmp3_ = _data_->schema_source;
		_data_->_tmp4_ = g_settings_schema_source_lookup (_data_->_tmp3_, "com.vysp3r.ProtonPlus.State", TRUE);
		_data_->schema = _data_->_tmp4_;
		_data_->_tmp5_ = _data_->schema;
		if (_data_->_tmp5_ != NULL) {
			_data_->_tmp6_ = _data_->schema;
			_data_->_tmp7_ = g_settings_new_full (_data_->_tmp6_, NULL, NULL);
			_g_object_unref0 (proton_plus_globals_SETTINGS);
			proton_plus_globals_SETTINGS = _data_->_tmp7_;
		}
		_g_settings_schema_unref0 (_data_->schema);
	}
	proton_plus_globals_IS_FLATPAK = g_file_test ("/.flatpak-info", G_FILE_TEST_IS_REGULAR);
	_data_->_tmp8_ = g_getenv ("DESKTOP_SESSION");
	proton_plus_globals_IS_GAMESCOPE = g_strcmp0 (_data_->_tmp8_, "gamescope-wayland") == 0;
	_data_->_state_ = 1;
	proton_plus_utils_system_get_distribution_name (proton_plus_globals_load_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp9_ = proton_plus_utils_system_get_distribution_name_finish (_data_->_res_);
	_data_->_tmp10_ = _data_->_tmp9_;
	_data_->_tmp11_ = g_ascii_strdown (_data_->_tmp10_, (gssize) -1);
	_data_->_tmp12_ = _data_->_tmp11_;
	proton_plus_globals_IS_STEAM_OS = g_strcmp0 (_data_->_tmp12_, "steamos") == 0;
	_g_free0 (_data_->_tmp12_);
	_g_free0 (_data_->_tmp10_);
	_data_->_tmp13_ = proton_plus_utils_system_get_hwcaps ();
	(proton_plus_globals_HWCAPS == NULL) ? NULL : (proton_plus_globals_HWCAPS = (_g_list_free__g_free0_ (proton_plus_globals_HWCAPS), NULL));
	proton_plus_globals_HWCAPS = _data_->_tmp13_;
	_data_->_state_ = 2;
	proton_plus_utils_system_get_protontricks_exec (proton_plus_globals_load_ready, _data_);
	return FALSE;
	_state_2:
	_data_->_tmp14_ = proton_plus_utils_system_get_protontricks_exec_finish (_data_->_res_);
	_g_free0 (proton_plus_globals_PROTONTRICKS_EXEC);
	proton_plus_globals_PROTONTRICKS_EXEC = _data_->_tmp14_;
	_data_->_tmp15_ = g_get_user_cache_dir ();
	_data_->_tmp16_ = g_strdup_printf ("%s/ProtonPlus", _data_->_tmp15_);
	_g_free0 (proton_plus_globals_CACHE_PATH);
	proton_plus_globals_CACHE_PATH = _data_->_tmp16_;
	_data_->_tmp17_ = proton_plus_globals_CACHE_PATH;
	if (!g_file_test (_data_->_tmp17_, G_FILE_TEST_IS_DIR)) {
		_data_->_tmp18_ = proton_plus_globals_CACHE_PATH;
		_data_->_state_ = 3;
		proton_plus_utils_filesystem_create_directory (_data_->_tmp18_, proton_plus_globals_load_ready, _data_);
		return FALSE;
		_state_3:
		proton_plus_utils_filesystem_create_directory_finish (_data_->_res_);
	}
	_data_->_tmp19_ = g_get_user_config_dir ();
	_data_->_tmp20_ = g_strdup_printf ("%s/ProtonPlus", _data_->_tmp19_);
	_g_free0 (proton_plus_globals_CONFIG_PATH);
	proton_plus_globals_CONFIG_PATH = _data_->_tmp20_;
	_data_->_tmp21_ = proton_plus_globals_CONFIG_PATH;
	if (!g_file_test (_data_->_tmp21_, G_FILE_TEST_IS_DIR)) {
		_data_->_tmp22_ = proton_plus_globals_CONFIG_PATH;
		_data_->_state_ = 4;
		proton_plus_utils_filesystem_create_directory (_data_->_tmp22_, proton_plus_globals_load_ready, _data_);
		return FALSE;
		_state_4:
		proton_plus_utils_filesystem_create_directory_finish (_data_->_res_);
	}
	_g_settings_schema_source_unref0 (_data_->schema_source);
	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;
}

