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

#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "protonplus_core.h"
#include <libnotify/notify.h>
#include "config.h"
#include <glib-object.h>
#include <gio/gio.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

typedef struct _Block1Data Block1Data;
#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL)))
#define _proton_plus_cli_handler_unref0(var) ((var == NULL) ? NULL : (var = (proton_plus_cli_handler_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _Block1Data {
	int _ref_count_;
	ProtonPlusCLIHandler* cli;
	GMainLoop* loop;
	gint _result_;
};

static gint proton_plus_main (gchar** args,
                       gint args_length1);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void ___lambda4_ (Block1Data* _data1_,
                  GObject* obj,
                  GAsyncResult* res);
static void ____lambda4__gasync_ready_callback (GObject* source_object,
                                         GAsyncResult* res,
                                         gpointer self);

static Block1Data*
block1_data_ref (Block1Data* _data1_)
{
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}

static void
block1_data_unref (void * _userdata_)
{
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		_g_main_loop_unref0 (_data1_->loop);
		_proton_plus_cli_handler_unref0 (_data1_->cli);
		g_slice_free (Block1Data, _data1_);
	}
}

static void
___lambda4_ (Block1Data* _data1_,
             GObject* obj,
             GAsyncResult* res)
{
	ProtonPlusCLIHandler* _tmp0_;
	GMainLoop* _tmp1_;
	g_return_if_fail (res != NULL);
	_tmp0_ = _data1_->cli;
	_data1_->_result_ = proton_plus_cli_handler_run_finish (_tmp0_, res);
	_tmp1_ = _data1_->loop;
	g_main_loop_quit (_tmp1_);
}

static void
____lambda4__gasync_ready_callback (GObject* source_object,
                                    GAsyncResult* res,
                                    gpointer self)
{
	___lambda4_ (self, source_object, res);
	block1_data_unref (self);
}

static gint
proton_plus_main (gchar** args,
                  gint args_length1)
{
	ProtonPlusWidgetsApplication* application = NULL;
	ProtonPlusWidgetsApplication* _tmp36_;
	gint status = 0;
	ProtonPlusWidgetsApplication* _tmp37_;
	gint result;
	if (args_length1 > 1) {
		Block1Data* _data1_;
		ProtonPlusServicesInstallationService* _tmp0_;
		ProtonPlusServicesInstallationService* _tmp1_;
		ProtonPlusServicesCompatibilityProcessGuard* _tmp2_;
		ProtonPlusServicesCompatibilityProcessGuard* _tmp3_;
		ProtonPlusServicesMigrationsManager* migration_manager = NULL;
		ProtonPlusServicesMigrationsManager* _tmp4_;
		ProtonPlusServicesMigrationsManager* _tmp5_;
		ProtonPlusServicesSteamRestartManager* steam_restart_manager = NULL;
		gchar* command = NULL;
		const gchar* _tmp6_;
		gchar* _tmp7_;
		gboolean _tmp8_ = FALSE;
		gboolean _tmp9_ = FALSE;
		const gchar* _tmp10_;
		ProtonPlusCLIHandler* _tmp28_;
		GMainLoop* _tmp29_;
		ProtonPlusCLIHandler* _tmp30_;
		GMainLoop* _tmp31_;
		ProtonPlusServicesSteamRestartManager* _tmp32_;
		ProtonPlusServicesInstallationService* _tmp34_;
		ProtonPlusServicesInstallationService* _tmp35_;
		_data1_ = g_slice_new0 (Block1Data);
		_data1_->_ref_count_ = 1;
		proton_plus_globals_load ();
		proton_plus_globals_setupLanguage ();
		notify_init (APP_NAME);
		_tmp0_ = proton_plus_services_installation_service_get_instance ();
		_tmp1_ = _tmp0_;
		_tmp2_ = proton_plus_services_compatibility_process_guard_new_for_package (proton_plus_globals_IS_FLATPAK);
		_tmp3_ = _tmp2_;
		proton_plus_services_installation_service_configure_compatibility_process_guard (_tmp1_, _tmp3_);
		_g_object_unref0 (_tmp3_);
		_tmp4_ = proton_plus_services_migrations_manager_new ();
		migration_manager = _tmp4_;
		_tmp5_ = migration_manager;
		proton_plus_services_migrations_manager_check_and_migrate_sync (_tmp5_, APP_VERSION);
		steam_restart_manager = NULL;
		_tmp6_ = args[1];
		_tmp7_ = g_strdup (_tmp6_);
		command = _tmp7_;
		_tmp10_ = command;
		if (g_strcmp0 (_tmp10_, "install") == 0) {
			_tmp9_ = TRUE;
		} else {
			const gchar* _tmp11_;
			_tmp11_ = command;
			_tmp9_ = g_strcmp0 (_tmp11_, "uninstall") == 0;
		}
		if (_tmp9_) {
			_tmp8_ = TRUE;
		} else {
			const gchar* _tmp12_;
			_tmp12_ = command;
			_tmp8_ = g_strcmp0 (_tmp12_, "update") == 0;
		}
		if (_tmp8_) {
			ProtonPlusServicesSteamSessionService* session_service = NULL;
			ProtonPlusServicesSteamSessionService* _tmp13_;
			ProtonPlusServicesSteamSessionService* _tmp14_;
			ProtonPlusServicesSteamRestartStateStore* _tmp15_;
			ProtonPlusServicesSteamRestartStateStore* _tmp16_;
			ProtonPlusServicesSteamRestartManager* _tmp17_;
			ProtonPlusServicesSteamConfigurationService* configuration_service = NULL;
			ProtonPlusServicesSteamSessionService* _tmp18_;
			ProtonPlusServicesSteamRestartManager* _tmp19_;
			ProtonPlusServicesSteamConfigurationService* _tmp20_;
			ProtonPlusServicesSteamRestartManager* _tmp21_;
			ProtonPlusServicesSteamConfigurationService* _tmp22_;
			ProtonPlusServicesSteamConfigurationService* _tmp23_;
			ProtonPlusServicesInstallationService* _tmp24_;
			ProtonPlusServicesInstallationService* _tmp25_;
			ProtonPlusServicesSteamRestartManager* _tmp26_;
			ProtonPlusServicesSteamRestartManager* _tmp27_;
			_tmp13_ = proton_plus_services_steam_session_service_new (NULL);
			session_service = _tmp13_;
			_tmp14_ = session_service;
			_tmp15_ = proton_plus_services_steam_restart_state_store_new (NULL);
			_tmp16_ = _tmp15_;
			_tmp17_ = proton_plus_services_steam_restart_manager_new (_tmp14_, _tmp16_, NULL);
			_g_object_unref0 (steam_restart_manager);
			steam_restart_manager = _tmp17_;
			_g_object_unref0 (_tmp16_);
			_tmp18_ = session_service;
			_tmp19_ = steam_restart_manager;
			_tmp20_ = proton_plus_services_steam_configuration_service_new (_tmp18_, G_TYPE_CHECK_INSTANCE_CAST (_tmp19_, PROTON_PLUS_SERVICES_TYPE_STEAM_RESTART_MANAGER, ProtonPlusServicesSteamRestartManager), NULL);
			configuration_service = _tmp20_;
			_tmp21_ = steam_restart_manager;
			_tmp22_ = configuration_service;
			proton_plus_services_steam_restart_manager_configure_configuration_reconciler (G_TYPE_CHECK_INSTANCE_CAST (_tmp21_, PROTON_PLUS_SERVICES_TYPE_STEAM_RESTART_MANAGER, ProtonPlusServicesSteamRestartManager), (ProtonPlusServicesSteamConfigurationReconciler*) _tmp22_);
			_tmp23_ = configuration_service;
			proton_plus_services_steam_configuration_service_configure (_tmp23_);
			_tmp24_ = proton_plus_services_installation_service_get_instance ();
			_tmp25_ = _tmp24_;
			_tmp26_ = steam_restart_manager;
			proton_plus_services_installation_service_configure_steam_change_recorder (_tmp25_, (ProtonPlusServicesSteamChangeRecorder*) G_TYPE_CHECK_INSTANCE_CAST (_tmp26_, PROTON_PLUS_SERVICES_TYPE_STEAM_RESTART_MANAGER, ProtonPlusServicesSteamRestartManager));
			_tmp27_ = steam_restart_manager;
			proton_plus_services_steam_restart_manager_start_observation (_tmp27_);
			_g_object_unref0 (configuration_service);
			_g_object_unref0 (session_service);
		}
		_tmp28_ = proton_plus_cli_handler_new (NULL, NULL);
		_data1_->cli = _tmp28_;
		_tmp29_ = g_main_loop_new (NULL, FALSE);
		_data1_->loop = _tmp29_;
		_data1_->_result_ = 0;
		_tmp30_ = _data1_->cli;
		proton_plus_cli_handler_run (_tmp30_, args, (gint) args_length1, ____lambda4__gasync_ready_callback, block1_data_ref (_data1_));
		_tmp31_ = _data1_->loop;
		g_main_loop_run (_tmp31_);
		_tmp32_ = steam_restart_manager;
		if (_tmp32_ != NULL) {
			ProtonPlusServicesSteamRestartManager* _tmp33_;
			_tmp33_ = steam_restart_manager;
			proton_plus_services_steam_restart_manager_stop_observation (_tmp33_);
		}
		_tmp34_ = proton_plus_services_installation_service_get_instance ();
		_tmp35_ = _tmp34_;
		proton_plus_services_installation_service_reset_lifecycle_configuration (_tmp35_);
		proton_plus_services_steam_configuration_service_reset_configuration ();
		notify_uninit ();
		result = _data1_->_result_;
		_g_free0 (command);
		_g_object_unref0 (steam_restart_manager);
		_g_object_unref0 (migration_manager);
		block1_data_unref (_data1_);
		_data1_ = NULL;
		return result;
	}
	_tmp36_ = proton_plus_widgets_application_new ();
	application = _tmp36_;
	_tmp37_ = application;
	status = g_application_run ((GApplication*) _tmp37_, (gint) args_length1, args);
	result = status;
	_g_object_unref0 (application);
	return result;
}

int
main (int argc,
      char ** argv)
{
	return proton_plus_main (argv, argc);
}

