/* installer-media.c generated by valac 0.17.1.6-d284, the Vala compiler
 * generated from installer-media.vala, do not modify */

/* This file is part of GNOME Boxes. License: LGPLv2+*/

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


#define BOXES_TYPE_INSTALLER_MEDIA (boxes_installer_media_get_type ())
#define BOXES_INSTALLER_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_INSTALLER_MEDIA, BoxesInstallerMedia))
#define BOXES_INSTALLER_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_INSTALLER_MEDIA, BoxesInstallerMediaClass))
#define BOXES_IS_INSTALLER_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_INSTALLER_MEDIA))
#define BOXES_IS_INSTALLER_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_INSTALLER_MEDIA))
#define BOXES_INSTALLER_MEDIA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_INSTALLER_MEDIA, BoxesInstallerMediaClass))

typedef struct _BoxesInstallerMedia BoxesInstallerMedia;
typedef struct _BoxesInstallerMediaClass BoxesInstallerMediaClass;
typedef struct _BoxesInstallerMediaPrivate BoxesInstallerMediaPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

#define BOXES_TYPE_MEDIA_MANAGER (boxes_media_manager_get_type ())
#define BOXES_MEDIA_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_MEDIA_MANAGER, BoxesMediaManager))
#define BOXES_MEDIA_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_MEDIA_MANAGER, BoxesMediaManagerClass))
#define BOXES_IS_MEDIA_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_MEDIA_MANAGER))
#define BOXES_IS_MEDIA_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_MEDIA_MANAGER))
#define BOXES_MEDIA_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_MEDIA_MANAGER, BoxesMediaManagerClass))

typedef struct _BoxesMediaManager BoxesMediaManager;
typedef struct _BoxesMediaManagerClass BoxesMediaManagerClass;
typedef struct _BoxesInstallerMediaCreateForPathData BoxesInstallerMediaCreateForPathData;

#define BOXES_TYPE_OS_DATABASE (boxes_os_database_get_type ())
#define BOXES_OS_DATABASE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_OS_DATABASE, BoxesOSDatabase))
#define BOXES_OS_DATABASE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_OS_DATABASE, BoxesOSDatabaseClass))
#define BOXES_IS_OS_DATABASE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_OS_DATABASE))
#define BOXES_IS_OS_DATABASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_OS_DATABASE))
#define BOXES_OS_DATABASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_OS_DATABASE, BoxesOSDatabaseClass))

typedef struct _BoxesOSDatabase BoxesOSDatabase;
typedef struct _BoxesOSDatabaseClass BoxesOSDatabaseClass;
typedef struct _BoxesInstallerMediaSetupForPathData BoxesInstallerMediaSetupForPathData;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _BoxesInstallerMediaGetDeviceFromPathData BoxesInstallerMediaGetDeviceFromPathData;

struct _BoxesInstallerMedia {
	GObject parent_instance;
	BoxesInstallerMediaPrivate * priv;
	OsinfoOs* os;
	OsinfoResources* resources;
	OsinfoMedia* os_media;
	gchar* label;
	gchar* device_file;
	gchar* mount_point;
	gboolean from_image;
};

struct _BoxesInstallerMediaClass {
	GObjectClass parent_class;
};

struct _BoxesInstallerMediaCreateForPathData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	gchar* path;
	BoxesMediaManager* media_manager;
	GCancellable* cancellable;
	BoxesInstallerMedia* result;
	BoxesInstallerMedia* _tmp0_;
	BoxesInstallerMedia* media;
	const gchar* _tmp1_;
	BoxesMediaManager* _tmp2_;
	GCancellable* _tmp3_;
	GError * _inner_error_;
};

typedef enum  {
	BOXES_OS_DATABASE_ERROR_NON_BOOTABLE,
	BOXES_OS_DATABASE_ERROR_UNKNOWN_OS_ID,
	BOXES_OS_DATABASE_ERROR_UNKNOWN_MEDIA_ID
} BoxesOSDatabaseError;
#define BOXES_OS_DATABASE_ERROR boxes_os_database_error_quark ()
struct _BoxesInstallerMediaSetupForPathData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	BoxesInstallerMedia* self;
	gchar* path;
	BoxesMediaManager* media_manager;
	GCancellable* cancellable;
	const gchar* _tmp0_;
	BoxesMediaManager* _tmp1_;
	GUdevClient* _tmp2_;
	GUdevClient* _tmp3_;
	GCancellable* _tmp4_;
	GUdevDevice* _tmp5_;
	GUdevDevice* device;
	GUdevDevice* _tmp6_;
	GUdevDevice* _tmp7_;
	BoxesMediaManager* _tmp8_;
	BoxesOSDatabase* _tmp9_;
	BoxesOSDatabase* _tmp10_;
	BoxesMediaManager* _tmp11_;
	BoxesOSDatabase* _tmp12_;
	BoxesOSDatabase* _tmp13_;
	const gchar* _tmp14_;
	GCancellable* _tmp15_;
	OsinfoMedia* _tmp16_;
	OsinfoOs* _tmp17_;
	OsinfoOs* _tmp18_;
	OsinfoOs* _tmp19_;
	OsinfoOs* _tmp20_;
	const gchar* _tmp21_;
	gchar* _tmp22_;
	const gchar* _tmp23_;
	const gchar* _tmp24_;
	gchar* _tmp25_;
	gchar* _tmp26_;
	OsinfoMedia* _tmp27_;
	OsinfoMedia* _tmp28_;
	gchar* _tmp29_;
	gchar* _tmp30_;
	gchar* _tmp31_;
	const gchar* _tmp32_;
	gchar* _tmp33_;
	gchar* architecture;
	BoxesMediaManager* _tmp34_;
	BoxesOSDatabase* _tmp35_;
	BoxesOSDatabase* _tmp36_;
	OsinfoOs* _tmp37_;
	const gchar* _tmp38_;
	OsinfoResources* _tmp39_;
	GError * _inner_error_;
};

struct _BoxesInstallerMediaGetDeviceFromPathData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	BoxesInstallerMedia* self;
	gchar* path;
	GUdevClient* client;
	GCancellable* cancellable;
	GUdevDevice* result;
	const gchar* _tmp0_;
	GFile* _tmp1_;
	GFile* mount_dir;
	GCancellable* _tmp2_;
	GMount* _tmp3_;
	GMount* mount;
	GFile* _tmp4_;
	GFile* _tmp5_;
	GFile* root_dir;
	GFile* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gboolean _tmp11_;
	GVolume* _tmp12_;
	GVolume* _tmp13_;
	GVolume* volume;
	GVolume* _tmp14_;
	const gchar* _tmp15_;
	gchar* _tmp16_;
	const gchar* _tmp17_;
	gchar* _tmp18_;
	const gchar* _tmp19_;
	gchar* _tmp20_;
	GError* _error_;
	const gchar* _tmp21_;
	gchar* _tmp22_;
	GUdevClient* _tmp23_;
	const gchar* _tmp24_;
	GUdevDevice* _tmp25_;
	GError * _inner_error_;
};


static gpointer boxes_installer_media_parent_class = NULL;

GType boxes_installer_media_get_type (void) G_GNUC_CONST;
enum  {
	BOXES_INSTALLER_MEDIA_DUMMY_PROPERTY,
	BOXES_INSTALLER_MEDIA_LIVE
};
BoxesInstallerMedia* boxes_installer_media_new_from_iso_info (const gchar* path, const gchar* label, OsinfoOs* os, OsinfoMedia* media, OsinfoResources* resources);
BoxesInstallerMedia* boxes_installer_media_construct_from_iso_info (GType object_type, const gchar* path, const gchar* label, OsinfoOs* os, OsinfoMedia* media, OsinfoResources* resources);
static void boxes_installer_media_create_for_path_data_free (gpointer _data);
GType boxes_media_manager_get_type (void) G_GNUC_CONST;
void boxes_installer_media_create_for_path (const gchar* path, BoxesMediaManager* media_manager, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
BoxesInstallerMedia* boxes_installer_media_create_for_path_finish (GAsyncResult* _res_, GError** error);
static gboolean boxes_installer_media_create_for_path_co (BoxesInstallerMediaCreateForPathData* _data_);
BoxesInstallerMedia* boxes_installer_media_new (void);
BoxesInstallerMedia* boxes_installer_media_construct (GType object_type);
static void boxes_installer_media_setup_for_path (BoxesInstallerMedia* self, const gchar* path, BoxesMediaManager* media_manager, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
static void boxes_installer_media_setup_for_path_finish (BoxesInstallerMedia* self, GAsyncResult* _res_, GError** error);
static void boxes_installer_media_create_for_path_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static void boxes_installer_media_setup_for_path_data_free (gpointer _data);
static gboolean boxes_installer_media_setup_for_path_co (BoxesInstallerMediaSetupForPathData* _data_);
static void boxes_installer_media_get_device_from_path (BoxesInstallerMedia* self, const gchar* path, GUdevClient* client, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
static GUdevDevice* boxes_installer_media_get_device_from_path_finish (BoxesInstallerMedia* self, GAsyncResult* _res_);
GUdevClient* boxes_media_manager_get_client (BoxesMediaManager* self);
static void boxes_installer_media_setup_for_path_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
gpointer boxes_os_database_ref (gpointer instance);
void boxes_os_database_unref (gpointer instance);
GParamSpec* boxes_param_spec_os_database (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void boxes_value_set_os_database (GValue* value, gpointer v_object);
void boxes_value_take_os_database (GValue* value, gpointer v_object);
gpointer boxes_value_get_os_database (const GValue* value);
GType boxes_os_database_get_type (void) G_GNUC_CONST;
GQuark boxes_os_database_error_quark (void);
static void boxes_installer_media_get_media_info_from_device (BoxesInstallerMedia* self, GUdevDevice* device, BoxesOSDatabase* os_db, GError** error);
BoxesOSDatabase* boxes_media_manager_get_os_db (BoxesMediaManager* self);
void boxes_os_database_guess_os_from_install_media (BoxesOSDatabase* self, const gchar* media_path, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
OsinfoOs* boxes_os_database_guess_os_from_install_media_finish (BoxesOSDatabase* self, GAsyncResult* _res_, OsinfoMedia** os_media, GError** error);
OsinfoResources* boxes_os_database_get_resources_for_os (BoxesOSDatabase* self, OsinfoOs* os, const gchar* architecture);
static void boxes_installer_media_get_device_from_path_data_free (gpointer _data);
static gboolean boxes_installer_media_get_device_from_path_co (BoxesInstallerMediaGetDeviceFromPathData* _data_);
static void boxes_installer_media_get_device_from_path_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
OsinfoOs* boxes_os_database_get_os_by_id (BoxesOSDatabase* self, const gchar* id, GError** error);
OsinfoMedia* boxes_os_database_get_media_by_id (BoxesOSDatabase* self, OsinfoOs* os, const gchar* id, GError** error);
gboolean boxes_installer_media_get_live (BoxesInstallerMedia* self);
static void boxes_installer_media_finalize (GObject* obj);
static void _vala_boxes_installer_media_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);


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


BoxesInstallerMedia* boxes_installer_media_construct_from_iso_info (GType object_type, const gchar* path, const gchar* label, OsinfoOs* os, OsinfoMedia* media, OsinfoResources* resources) {
	BoxesInstallerMedia * self = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	OsinfoOs* _tmp4_;
	OsinfoOs* _tmp5_;
	OsinfoMedia* _tmp6_;
	OsinfoMedia* _tmp7_;
	OsinfoResources* _tmp8_;
	OsinfoResources* _tmp9_;
	g_return_val_if_fail (path != NULL, NULL);
	g_return_val_if_fail (label != NULL, NULL);
	g_return_val_if_fail (os != NULL, NULL);
	g_return_val_if_fail (media != NULL, NULL);
	self = (BoxesInstallerMedia*) g_object_new (object_type, NULL);
	_tmp0_ = path;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 (self->device_file);
	self->device_file = _tmp1_;
	_tmp2_ = label;
	_tmp3_ = g_strdup (_tmp2_);
	_g_free0 (self->label);
	self->label = _tmp3_;
	_tmp4_ = os;
	_tmp5_ = _g_object_ref0 (_tmp4_);
	_g_object_unref0 (self->os);
	self->os = _tmp5_;
	_tmp6_ = media;
	_tmp7_ = _g_object_ref0 (_tmp6_);
	_g_object_unref0 (self->os_media);
	self->os_media = _tmp7_;
	_tmp8_ = resources;
	_tmp9_ = _g_object_ref0 (_tmp8_);
	_g_object_unref0 (self->resources);
	self->resources = _tmp9_;
	self->from_image = TRUE;
	return self;
}


BoxesInstallerMedia* boxes_installer_media_new_from_iso_info (const gchar* path, const gchar* label, OsinfoOs* os, OsinfoMedia* media, OsinfoResources* resources) {
	return boxes_installer_media_construct_from_iso_info (BOXES_TYPE_INSTALLER_MEDIA, path, label, os, media, resources);
}


static void boxes_installer_media_create_for_path_data_free (gpointer _data) {
	BoxesInstallerMediaCreateForPathData* _data_;
	_data_ = _data;
	_g_free0 (_data_->path);
	_g_object_unref0 (_data_->media_manager);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	g_slice_free (BoxesInstallerMediaCreateForPathData, _data_);
}


void boxes_installer_media_create_for_path (const gchar* path, BoxesMediaManager* media_manager, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	BoxesInstallerMediaCreateForPathData* _data_;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	BoxesMediaManager* _tmp2_;
	BoxesMediaManager* _tmp3_;
	GCancellable* _tmp4_;
	GCancellable* _tmp5_;
	_data_ = g_slice_new0 (BoxesInstallerMediaCreateForPathData);
	_data_->_async_result = g_simple_async_result_new (g_object_newv (G_TYPE_OBJECT, 0, NULL), _callback_, _user_data_, boxes_installer_media_create_for_path);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, boxes_installer_media_create_for_path_data_free);
	_tmp0_ = path;
	_tmp1_ = g_strdup (_tmp0_);
	_data_->path = _tmp1_;
	_tmp2_ = media_manager;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	_data_->media_manager = _tmp3_;
	_tmp4_ = cancellable;
	_tmp5_ = _g_object_ref0 (_tmp4_);
	_data_->cancellable = _tmp5_;
	boxes_installer_media_create_for_path_co (_data_);
}


BoxesInstallerMedia* boxes_installer_media_create_for_path_finish (GAsyncResult* _res_, GError** error) {
	BoxesInstallerMedia* result;
	BoxesInstallerMediaCreateForPathData* _data_;
	if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (_res_), error)) {
		return NULL;
	}
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
	result = _data_->result;
	_data_->result = NULL;
	return result;
}


static void boxes_installer_media_create_for_path_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	BoxesInstallerMediaCreateForPathData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	boxes_installer_media_create_for_path_co (_data_);
}


static gboolean boxes_installer_media_create_for_path_co (BoxesInstallerMediaCreateForPathData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = boxes_installer_media_new ();
	_data_->media = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->path;
	_data_->_tmp2_ = _data_->media_manager;
	_data_->_tmp3_ = _data_->cancellable;
	_data_->_state_ = 1;
	boxes_installer_media_setup_for_path (_data_->media, _data_->_tmp1_, _data_->_tmp2_, _data_->_tmp3_, boxes_installer_media_create_for_path_ready, _data_);
	return FALSE;
	_state_1:
	boxes_installer_media_setup_for_path_finish (_data_->media, _data_->_res_, &_data_->_inner_error_);
	if (_data_->_inner_error_ != NULL) {
		g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
		g_error_free (_data_->_inner_error_);
		_g_object_unref0 (_data_->media);
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->result = _data_->media;
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
	_g_object_unref0 (_data_->media);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static void boxes_installer_media_setup_for_path_data_free (gpointer _data) {
	BoxesInstallerMediaSetupForPathData* _data_;
	_data_ = _data;
	_g_free0 (_data_->path);
	_g_object_unref0 (_data_->media_manager);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (BoxesInstallerMediaSetupForPathData, _data_);
}


static void boxes_installer_media_setup_for_path (BoxesInstallerMedia* self, const gchar* path, BoxesMediaManager* media_manager, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	BoxesInstallerMediaSetupForPathData* _data_;
	BoxesInstallerMedia* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	BoxesMediaManager* _tmp3_;
	BoxesMediaManager* _tmp4_;
	GCancellable* _tmp5_;
	GCancellable* _tmp6_;
	_data_ = g_slice_new0 (BoxesInstallerMediaSetupForPathData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, boxes_installer_media_setup_for_path);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, boxes_installer_media_setup_for_path_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = path;
	_tmp2_ = g_strdup (_tmp1_);
	_data_->path = _tmp2_;
	_tmp3_ = media_manager;
	_tmp4_ = _g_object_ref0 (_tmp3_);
	_data_->media_manager = _tmp4_;
	_tmp5_ = cancellable;
	_tmp6_ = _g_object_ref0 (_tmp5_);
	_data_->cancellable = _tmp6_;
	boxes_installer_media_setup_for_path_co (_data_);
}


static void boxes_installer_media_setup_for_path_finish (BoxesInstallerMedia* self, GAsyncResult* _res_, GError** error) {
	BoxesInstallerMediaSetupForPathData* _data_;
	if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (_res_), error)) {
		return;
	}
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static void boxes_installer_media_setup_for_path_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	BoxesInstallerMediaSetupForPathData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	boxes_installer_media_setup_for_path_co (_data_);
}


static gboolean boxes_installer_media_setup_for_path_co (BoxesInstallerMediaSetupForPathData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->path;
	_data_->_tmp1_ = _data_->media_manager;
	_data_->_tmp2_ = boxes_media_manager_get_client (_data_->_tmp1_);
	_data_->_tmp3_ = _data_->_tmp2_;
	_data_->_tmp4_ = _data_->cancellable;
	_data_->_state_ = 1;
	boxes_installer_media_get_device_from_path (_data_->self, _data_->_tmp0_, _data_->_tmp3_, _data_->_tmp4_, boxes_installer_media_setup_for_path_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp5_ = NULL;
	_data_->_tmp5_ = boxes_installer_media_get_device_from_path_finish (_data_->self, _data_->_res_);
	_data_->device = _data_->_tmp5_;
	_data_->_tmp6_ = _data_->device;
	if (_data_->_tmp6_ != NULL) {
		_data_->_tmp7_ = _data_->device;
		_data_->_tmp8_ = _data_->media_manager;
		_data_->_tmp9_ = boxes_media_manager_get_os_db (_data_->_tmp8_);
		_data_->_tmp10_ = _data_->_tmp9_;
		boxes_installer_media_get_media_info_from_device (_data_->self, _data_->_tmp7_, _data_->_tmp10_, &_data_->_inner_error_);
		if (_data_->_inner_error_ != NULL) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			_g_object_unref0 (_data_->device);
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	} else {
		_data_->self->from_image = TRUE;
		_data_->_tmp11_ = _data_->media_manager;
		_data_->_tmp12_ = boxes_media_manager_get_os_db (_data_->_tmp11_);
		_data_->_tmp13_ = _data_->_tmp12_;
		_data_->_tmp14_ = _data_->self->device_file;
		_data_->_tmp15_ = _data_->cancellable;
		_data_->_tmp16_ = NULL;
		_data_->_state_ = 2;
		boxes_os_database_guess_os_from_install_media (_data_->_tmp13_, _data_->_tmp14_, _data_->_tmp15_, boxes_installer_media_setup_for_path_ready, _data_);
		return FALSE;
		_state_2:
		_data_->_tmp17_ = NULL;
		_data_->_tmp17_ = boxes_os_database_guess_os_from_install_media_finish (_data_->_tmp13_, _data_->_res_, &_data_->_tmp16_, &_data_->_inner_error_);
		_g_object_unref0 (_data_->self->os_media);
		_data_->self->os_media = _data_->_tmp16_;
		_data_->_tmp18_ = _data_->_tmp17_;
		if (_data_->_inner_error_ != NULL) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			_g_object_unref0 (_data_->device);
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_g_object_unref0 (_data_->self->os);
		_data_->self->os = _data_->_tmp18_;
	}
	_data_->_tmp19_ = _data_->self->os;
	if (_data_->_tmp19_ != NULL) {
		_data_->_tmp20_ = _data_->self->os;
		_data_->_tmp21_ = NULL;
		_data_->_tmp21_ = osinfo_product_get_name ((OsinfoProduct*) _data_->_tmp20_);
		_data_->_tmp22_ = g_strdup (_data_->_tmp21_);
		_g_free0 (_data_->self->label);
		_data_->self->label = _data_->_tmp22_;
	}
	_data_->_tmp23_ = _data_->self->label;
	if (_data_->_tmp23_ == NULL) {
		_data_->_tmp24_ = _data_->self->device_file;
		_data_->_tmp25_ = NULL;
		_data_->_tmp25_ = g_path_get_basename (_data_->_tmp24_);
		_g_free0 (_data_->self->label);
		_data_->self->label = _data_->_tmp25_;
	}
	_data_->_tmp27_ = _data_->self->os_media;
	if (_data_->_tmp27_ != NULL) {
		_data_->_tmp28_ = _data_->self->os_media;
		_data_->_tmp29_ = NULL;
		g_object_get (_data_->_tmp28_, "architecture", &_data_->_tmp29_, NULL);
		_data_->_tmp30_ = _data_->_tmp29_;
		_g_free0 (_data_->_tmp26_);
		_data_->_tmp26_ = _data_->_tmp30_;
	} else {
		_data_->_tmp31_ = g_strdup ("i686");
		_g_free0 (_data_->_tmp26_);
		_data_->_tmp26_ = _data_->_tmp31_;
	}
	_data_->_tmp32_ = _data_->_tmp26_;
	_data_->_tmp33_ = g_strdup (_data_->_tmp32_);
	_data_->architecture = _data_->_tmp33_;
	_data_->_tmp34_ = _data_->media_manager;
	_data_->_tmp35_ = boxes_media_manager_get_os_db (_data_->_tmp34_);
	_data_->_tmp36_ = _data_->_tmp35_;
	_data_->_tmp37_ = _data_->self->os;
	_data_->_tmp38_ = _data_->architecture;
	_data_->_tmp39_ = NULL;
	_data_->_tmp39_ = boxes_os_database_get_resources_for_os (_data_->_tmp36_, _data_->_tmp37_, _data_->_tmp38_);
	_g_object_unref0 (_data_->self->resources);
	_data_->self->resources = _data_->_tmp39_;
	_g_free0 (_data_->architecture);
	_g_free0 (_data_->_tmp26_);
	_g_object_unref0 (_data_->device);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static void boxes_installer_media_get_device_from_path_data_free (gpointer _data) {
	BoxesInstallerMediaGetDeviceFromPathData* _data_;
	_data_ = _data;
	_g_free0 (_data_->path);
	_g_object_unref0 (_data_->client);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (BoxesInstallerMediaGetDeviceFromPathData, _data_);
}


static void boxes_installer_media_get_device_from_path (BoxesInstallerMedia* self, const gchar* path, GUdevClient* client, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	BoxesInstallerMediaGetDeviceFromPathData* _data_;
	BoxesInstallerMedia* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	GUdevClient* _tmp3_;
	GUdevClient* _tmp4_;
	GCancellable* _tmp5_;
	GCancellable* _tmp6_;
	_data_ = g_slice_new0 (BoxesInstallerMediaGetDeviceFromPathData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, boxes_installer_media_get_device_from_path);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, boxes_installer_media_get_device_from_path_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = path;
	_tmp2_ = g_strdup (_tmp1_);
	_data_->path = _tmp2_;
	_tmp3_ = client;
	_tmp4_ = _g_object_ref0 (_tmp3_);
	_data_->client = _tmp4_;
	_tmp5_ = cancellable;
	_tmp6_ = _g_object_ref0 (_tmp5_);
	_data_->cancellable = _tmp6_;
	boxes_installer_media_get_device_from_path_co (_data_);
}


static GUdevDevice* boxes_installer_media_get_device_from_path_finish (BoxesInstallerMedia* self, GAsyncResult* _res_) {
	GUdevDevice* result;
	BoxesInstallerMediaGetDeviceFromPathData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
	result = _data_->result;
	_data_->result = NULL;
	return result;
}


static void boxes_installer_media_get_device_from_path_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	BoxesInstallerMediaGetDeviceFromPathData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	boxes_installer_media_get_device_from_path_co (_data_);
}


static gboolean boxes_installer_media_get_device_from_path_co (BoxesInstallerMediaGetDeviceFromPathData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	{
		_data_->_tmp0_ = _data_->path;
		_data_->_tmp1_ = NULL;
		_data_->_tmp1_ = g_file_new_for_commandline_arg (_data_->_tmp0_);
		_data_->mount_dir = _data_->_tmp1_;
		_data_->_tmp2_ = _data_->cancellable;
		_data_->_state_ = 1;
		g_file_find_enclosing_mount_async (_data_->mount_dir, G_PRIORITY_DEFAULT, _data_->_tmp2_, boxes_installer_media_get_device_from_path_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp3_ = NULL;
		_data_->_tmp3_ = g_file_find_enclosing_mount_finish (_data_->mount_dir, _data_->_res_, &_data_->_inner_error_);
		_data_->mount = _data_->_tmp3_;
		if (_data_->_inner_error_ != NULL) {
			_g_object_unref0 (_data_->mount_dir);
			goto __catch13_g_error;
		}
		_data_->_tmp4_ = NULL;
		_data_->_tmp4_ = g_mount_get_root (_data_->mount);
		_data_->_tmp5_ = _g_object_ref0 (_data_->_tmp4_);
		_data_->root_dir = _data_->_tmp5_;
		_data_->_tmp6_ = _data_->root_dir;
		_data_->_tmp7_ = NULL;
		_data_->_tmp7_ = g_file_get_path (_data_->_tmp6_);
		_data_->_tmp8_ = _data_->_tmp7_;
		_data_->_tmp9_ = NULL;
		_data_->_tmp9_ = g_file_get_path (_data_->mount_dir);
		_data_->_tmp10_ = _data_->_tmp9_;
		_data_->_tmp11_ = g_strcmp0 (_data_->_tmp8_, _data_->_tmp10_) == 0;
		_g_free0 (_data_->_tmp10_);
		_g_free0 (_data_->_tmp8_);
		if (_data_->_tmp11_) {
			_data_->_tmp12_ = NULL;
			_data_->_tmp12_ = g_mount_get_volume (_data_->mount);
			_data_->_tmp13_ = _g_object_ref0 (_data_->_tmp12_);
			_data_->volume = _data_->_tmp13_;
			_data_->_tmp14_ = _data_->volume;
			_data_->_tmp15_ = NULL;
			_data_->_tmp15_ = g_volume_get_identifier (_data_->_tmp14_, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
			_data_->_tmp16_ = g_strdup (_data_->_tmp15_);
			_g_free0 (_data_->self->device_file);
			_data_->self->device_file = _data_->_tmp16_;
			_data_->_tmp17_ = _data_->path;
			_data_->_tmp18_ = g_strdup (_data_->_tmp17_);
			_g_free0 (_data_->self->mount_point);
			_data_->self->mount_point = _data_->_tmp18_;
			_g_object_unref0 (_data_->volume);
		} else {
			_data_->_tmp19_ = _data_->path;
			_data_->_tmp20_ = g_strdup (_data_->_tmp19_);
			_g_free0 (_data_->self->device_file);
			_data_->self->device_file = _data_->_tmp20_;
		}
		_g_object_unref0 (_data_->root_dir);
		_g_object_unref0 (_data_->mount);
		_g_object_unref0 (_data_->mount_dir);
	}
	goto __finally13;
	__catch13_g_error:
	{
		_data_->_error_ = _data_->_inner_error_;
		_data_->_inner_error_ = NULL;
		_data_->_tmp21_ = _data_->path;
		_data_->_tmp22_ = g_strdup (_data_->_tmp21_);
		_g_free0 (_data_->self->device_file);
		_data_->self->device_file = _data_->_tmp22_;
		_g_error_free0 (_data_->_error_);
	}
	__finally13:
	if (_data_->_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
		g_clear_error (&_data_->_inner_error_);
		return FALSE;
	}
	_data_->_tmp23_ = _data_->client;
	_data_->_tmp24_ = _data_->self->device_file;
	_data_->_tmp25_ = NULL;
	_data_->_tmp25_ = g_udev_client_query_by_device_file (_data_->_tmp23_, _data_->_tmp24_);
	_data_->result = _data_->_tmp25_;
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static void boxes_installer_media_get_media_info_from_device (BoxesInstallerMedia* self, GUdevDevice* device, BoxesOSDatabase* os_db, GError** error) {
	GUdevDevice* _tmp0_;
	gboolean _tmp1_ = FALSE;
	GUdevDevice* _tmp4_;
	const gchar* _tmp5_ = NULL;
	gchar* _tmp6_;
	GUdevDevice* _tmp7_;
	const gchar* _tmp8_ = NULL;
	gchar* _tmp9_;
	gchar* _tmp10_;
	const gchar* _tmp11_;
	const gchar* _tmp15_;
	gchar* _tmp16_;
	gchar* os_id;
	const gchar* _tmp17_;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (device != NULL);
	g_return_if_fail (os_db != NULL);
	_tmp0_ = device;
	_tmp1_ = g_udev_device_get_property_as_boolean (_tmp0_, "OSINFO_BOOTABLE");
	if (!_tmp1_) {
		const gchar* _tmp2_;
		GError* _tmp3_;
		_tmp2_ = self->device_file;
		_tmp3_ = g_error_new (BOXES_OS_DATABASE_ERROR, BOXES_OS_DATABASE_ERROR_NON_BOOTABLE, "Media %s is not bootable.", _tmp2_);
		_inner_error_ = _tmp3_;
		if (_inner_error_->domain == BOXES_OS_DATABASE_ERROR) {
			g_propagate_error (error, _inner_error_);
			return;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
	}
	_tmp4_ = device;
	_tmp5_ = g_udev_device_get_property (_tmp4_, "ID_FS_LABEL");
	_tmp6_ = g_strdup (_tmp5_);
	_g_free0 (self->label);
	self->label = _tmp6_;
	_tmp7_ = device;
	_tmp8_ = g_udev_device_get_property (_tmp7_, "OSINFO_INSTALLER");
	_tmp9_ = g_strdup (_tmp8_);
	_tmp10_ = _tmp9_;
	_tmp11_ = _tmp10_;
	if (_tmp11_ == NULL) {
		GUdevDevice* _tmp12_;
		const gchar* _tmp13_ = NULL;
		gchar* _tmp14_;
		_tmp12_ = device;
		_tmp13_ = g_udev_device_get_property (_tmp12_, "OSINFO_LIVE");
		_tmp14_ = g_strdup (_tmp13_);
		_g_free0 (_tmp10_);
		_tmp10_ = _tmp14_;
	}
	_tmp15_ = _tmp10_;
	_tmp16_ = g_strdup (_tmp15_);
	os_id = _tmp16_;
	_tmp17_ = os_id;
	if (_tmp17_ != NULL) {
		BoxesOSDatabase* _tmp18_;
		const gchar* _tmp19_;
		OsinfoOs* _tmp20_ = NULL;
		OsinfoOs* _tmp21_;
		GUdevDevice* _tmp22_;
		const gchar* _tmp23_ = NULL;
		gchar* _tmp24_;
		gchar* media_id;
		const gchar* _tmp25_;
		_tmp18_ = os_db;
		_tmp19_ = os_id;
		_tmp20_ = boxes_os_database_get_os_by_id (_tmp18_, _tmp19_, &_inner_error_);
		_tmp21_ = _tmp20_;
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == BOXES_OS_DATABASE_ERROR) {
				g_propagate_error (error, _inner_error_);
				_g_free0 (os_id);
				_g_free0 (_tmp10_);
				return;
			} else {
				_g_free0 (os_id);
				_g_free0 (_tmp10_);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return;
			}
		}
		_g_object_unref0 (self->os);
		self->os = _tmp21_;
		_tmp22_ = device;
		_tmp23_ = g_udev_device_get_property (_tmp22_, "OSINFO_MEDIA");
		_tmp24_ = g_strdup (_tmp23_);
		media_id = _tmp24_;
		_tmp25_ = media_id;
		if (_tmp25_ != NULL) {
			BoxesOSDatabase* _tmp26_;
			OsinfoOs* _tmp27_;
			const gchar* _tmp28_;
			OsinfoMedia* _tmp29_ = NULL;
			OsinfoMedia* _tmp30_;
			_tmp26_ = os_db;
			_tmp27_ = self->os;
			_tmp28_ = media_id;
			_tmp29_ = boxes_os_database_get_media_by_id (_tmp26_, _tmp27_, _tmp28_, &_inner_error_);
			_tmp30_ = _tmp29_;
			if (_inner_error_ != NULL) {
				if (_inner_error_->domain == BOXES_OS_DATABASE_ERROR) {
					g_propagate_error (error, _inner_error_);
					_g_free0 (media_id);
					_g_free0 (os_id);
					_g_free0 (_tmp10_);
					return;
				} else {
					_g_free0 (media_id);
					_g_free0 (os_id);
					_g_free0 (_tmp10_);
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
					g_clear_error (&_inner_error_);
					return;
				}
			}
			_g_object_unref0 (self->os_media);
			self->os_media = _tmp30_;
		}
		_g_free0 (media_id);
	}
	_g_free0 (os_id);
	_g_free0 (_tmp10_);
}


BoxesInstallerMedia* boxes_installer_media_construct (GType object_type) {
	BoxesInstallerMedia * self = NULL;
	self = (BoxesInstallerMedia*) g_object_new (object_type, NULL);
	return self;
}


BoxesInstallerMedia* boxes_installer_media_new (void) {
	return boxes_installer_media_construct (BOXES_TYPE_INSTALLER_MEDIA);
}


gboolean boxes_installer_media_get_live (BoxesInstallerMedia* self) {
	gboolean result;
	gboolean _tmp0_ = FALSE;
	OsinfoMedia* _tmp1_;
	gboolean _tmp5_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp1_ = self->os_media;
	if (_tmp1_ == NULL) {
		_tmp0_ = TRUE;
	} else {
		OsinfoMedia* _tmp2_;
		gboolean _tmp3_ = FALSE;
		gboolean _tmp4_;
		_tmp2_ = self->os_media;
		g_object_get (_tmp2_, "live", &_tmp3_, NULL);
		_tmp4_ = _tmp3_;
		_tmp0_ = _tmp4_;
	}
	_tmp5_ = _tmp0_;
	result = _tmp5_;
	return result;
}


static void boxes_installer_media_class_init (BoxesInstallerMediaClass * klass) {
	boxes_installer_media_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->get_property = _vala_boxes_installer_media_get_property;
	G_OBJECT_CLASS (klass)->finalize = boxes_installer_media_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), BOXES_INSTALLER_MEDIA_LIVE, g_param_spec_boolean ("live", "live", "live", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
}


static void boxes_installer_media_instance_init (BoxesInstallerMedia * self) {
}


static void boxes_installer_media_finalize (GObject* obj) {
	BoxesInstallerMedia * self;
	self = BOXES_INSTALLER_MEDIA (obj);
	_g_object_unref0 (self->os);
	_g_object_unref0 (self->resources);
	_g_object_unref0 (self->os_media);
	_g_free0 (self->label);
	_g_free0 (self->device_file);
	_g_free0 (self->mount_point);
	G_OBJECT_CLASS (boxes_installer_media_parent_class)->finalize (obj);
}


GType boxes_installer_media_get_type (void) {
	static volatile gsize boxes_installer_media_type_id__volatile = 0;
	if (g_once_init_enter (&boxes_installer_media_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (BoxesInstallerMediaClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) boxes_installer_media_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BoxesInstallerMedia), 0, (GInstanceInitFunc) boxes_installer_media_instance_init, NULL };
		GType boxes_installer_media_type_id;
		boxes_installer_media_type_id = g_type_register_static (G_TYPE_OBJECT, "BoxesInstallerMedia", &g_define_type_info, 0);
		g_once_init_leave (&boxes_installer_media_type_id__volatile, boxes_installer_media_type_id);
	}
	return boxes_installer_media_type_id__volatile;
}


static void _vala_boxes_installer_media_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	BoxesInstallerMedia * self;
	self = BOXES_INSTALLER_MEDIA (object);
	switch (property_id) {
		case BOXES_INSTALLER_MEDIA_LIVE:
		g_value_set_boolean (value, boxes_installer_media_get_live (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



