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

/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 2 -*- */
/*
    This file is part of Déjà Dup.
    © 2008,2009 Michael Terry <mike@mterry.name>

    Déjà Dup is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Déjà Dup is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Déjà Dup.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <config.h>
#include <glib/gi18n-lib.h>


#define DEJA_DUP_TYPE_SIMPLE_SETTINGS (deja_dup_simple_settings_get_type ())
#define DEJA_DUP_SIMPLE_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_SIMPLE_SETTINGS, DejaDupSimpleSettings))
#define DEJA_DUP_SIMPLE_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_SIMPLE_SETTINGS, DejaDupSimpleSettingsClass))
#define DEJA_DUP_IS_SIMPLE_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_SIMPLE_SETTINGS))
#define DEJA_DUP_IS_SIMPLE_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_SIMPLE_SETTINGS))
#define DEJA_DUP_SIMPLE_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_SIMPLE_SETTINGS, DejaDupSimpleSettingsClass))

typedef struct _DejaDupSimpleSettings DejaDupSimpleSettings;
typedef struct _DejaDupSimpleSettingsClass DejaDupSimpleSettingsClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_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)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

#define DEJA_DUP_TYPE_BACKEND (deja_dup_backend_get_type ())
#define DEJA_DUP_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_BACKEND, DejaDupBackend))
#define DEJA_DUP_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_BACKEND, DejaDupBackendClass))
#define DEJA_DUP_IS_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_BACKEND))
#define DEJA_DUP_IS_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_BACKEND))
#define DEJA_DUP_BACKEND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_BACKEND, DejaDupBackendClass))

typedef struct _DejaDupBackend DejaDupBackend;
typedef struct _DejaDupBackendClass DejaDupBackendClass;

typedef enum  {
	DEJA_DUP_BACKUP_ERROR_BAD_CONFIG,
	DEJA_DUP_BACKUP_ERROR_ALREADY_RUNNING
} DejaDupBackupError;
#define DEJA_DUP_BACKUP_ERROR deja_dup_backup_error_quark ()


#define DEJA_DUP_INCLUDE_LIST_KEY "include-list"
#define DEJA_DUP_EXCLUDE_LIST_KEY "exclude-list"
#define DEJA_DUP_BACKEND_KEY "backend"
#define DEJA_DUP_ROOT_PROMPT_KEY "root-prompt"
#define DEJA_DUP_ENCRYPT_KEY "encrypt"
#define DEJA_DUP_LAST_RUN_KEY "last-run"
#define DEJA_DUP_PERIODIC_KEY "periodic"
#define DEJA_DUP_PERIODIC_PERIOD_KEY "periodic-period"
#define DEJA_DUP_DELETE_AFTER_KEY "delete-after"
GQuark deja_dup_backup_error_quark (void);
void deja_dup_update_last_run_timestamp (GError** error);
GType deja_dup_simple_settings_get_type (void) G_GNUC_CONST;
DejaDupSimpleSettings* deja_dup_get_settings (const gchar* subdir);
void deja_dup_simple_settings_set_string (DejaDupSimpleSettings* self, const gchar* k, const gchar* v);
gchar* deja_dup_get_trash_path (void);
gchar* deja_dup_get_folder_key (DejaDupSimpleSettings* settings, const gchar* key);
GFile* deja_dup_parse_dir (const gchar* dir);
GFile** deja_dup_parse_dir_list (const gchar** dirs, int dirs_length1, int* result_length1);
static void _vala_array_add1 (GFile*** array, int* length, int* size, GFile* value);
DejaDupSimpleSettings* deja_dup_simple_settings_new (const gchar* schema);
DejaDupSimpleSettings* deja_dup_simple_settings_construct (GType object_type, const gchar* schema);
#define DEJA_DUP_SSH_USERNAME_KEY "username"
#define DEJA_DUP_SSH_SERVER_KEY "server"
#define DEJA_DUP_SSH_PORT_KEY "port"
#define DEJA_DUP_SSH_DIRECTORY_KEY "directory"
void deja_dup_convert_ssh_to_file (void);
#define DEJA_DUP_FILE_ROOT "File"
#define DEJA_DUP_FILE_PATH_KEY "path"
void deja_dup_convert_s3_folder_to_hostname (void);
#define DEJA_DUP_S3_ROOT "S3"
#define DEJA_DUP_S3_FOLDER_KEY "folder"
gchar* deja_dup_backend_get_default_type (void);
void deja_dup_initialize (void);
void deja_dup_i18n_setup (void);
gchar* deja_dup_get_file_desc (GFile* file);
gchar* deja_dup_get_location_desc (void);
GType deja_dup_backend_get_type (void) G_GNUC_CONST;
DejaDupBackend* deja_dup_backend_get_default (GError** error);
gchar* deja_dup_backend_get_location_pretty (DejaDupBackend* self, GError** error);
gint deja_dup_get_full_backup_threshold (void);
void deja_dup_get_full_backup_threshold_date (GDate* result);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


GQuark deja_dup_backup_error_quark (void) {
	return g_quark_from_static_string ("deja_dup_backup_error-quark");
}


void deja_dup_update_last_run_timestamp (GError** error) {
	GTimeVal cur_time = {0};
	gchar* _tmp0_ = NULL;
	gchar* cur_time_str;
	DejaDupSimpleSettings* _tmp1_ = NULL;
	DejaDupSimpleSettings* settings;
	g_get_current_time (&cur_time);
	g_get_current_time (&cur_time);
	_tmp0_ = g_time_val_to_iso8601 (&cur_time);
	cur_time_str = _tmp0_;
	_tmp1_ = deja_dup_get_settings (NULL);
	settings = _tmp1_;
	deja_dup_simple_settings_set_string (settings, DEJA_DUP_LAST_RUN_KEY, cur_time_str);
	_g_object_unref0 (settings);
	_g_free0 (cur_time_str);
}


gchar* deja_dup_get_trash_path (void) {
	gchar* result = NULL;
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	_tmp0_ = g_get_user_data_dir ();
	_tmp1_ = g_build_filename (_tmp0_, "Trash", NULL);
	result = _tmp1_;
	return result;
}


static gboolean string_contains (const gchar* self, const gchar* needle) {
	gboolean result = FALSE;
	gchar* _tmp0_ = NULL;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = strstr ((gchar*) self, (gchar*) needle);
	result = _tmp0_ != NULL;
	return result;
}


static gchar* string_replace (const gchar* self, const gchar* old, const gchar* replacement) {
	gchar* result = NULL;
	gchar* _tmp0_ = NULL;
	gchar* _tmp1_;
	GRegex* _tmp2_ = NULL;
	GRegex* _tmp3_;
	GRegex* regex;
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	_tmp0_ = g_regex_escape_string (old, -1);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_regex_new (_tmp1_, 0, 0, &_inner_error_);
	regex = (_tmp3_ = _tmp2_, _g_free0 (_tmp1_), _tmp3_);
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == G_REGEX_ERROR) {
			goto __catch14_g_regex_error;
		}
		g_critical ("file %s: line %d: unexpected 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 NULL;
	}
	_tmp4_ = g_regex_replace_literal (regex, self, (gssize) (-1), 0, replacement, 0, &_inner_error_);
	_tmp5_ = _tmp4_;
	if (_inner_error_ != NULL) {
		_g_regex_unref0 (regex);
		if (_inner_error_->domain == G_REGEX_ERROR) {
			goto __catch14_g_regex_error;
		}
		_g_regex_unref0 (regex);
		g_critical ("file %s: line %d: unexpected 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 NULL;
	}
	result = _tmp5_;
	_g_regex_unref0 (regex);
	return result;
	_g_regex_unref0 (regex);
	goto __finally14;
	__catch14_g_regex_error:
	{
		GError * e;
		e = _inner_error_;
		_inner_error_ = NULL;
		g_assert_not_reached ();
		_g_error_free0 (e);
	}
	__finally14:
	if (_inner_error_ != NULL) {
		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 NULL;
	}
}


static gchar* string_substring (const gchar* self, glong offset, glong len) {
	gchar* result = NULL;
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= 0) {
		_tmp0_ = len >= 0;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		glong _tmp1_;
		_tmp1_ = strnlen ((gchar*) self, (gsize) (offset + len));
		string_length = _tmp1_;
	} else {
		gint _tmp2_;
		_tmp2_ = strlen (self);
		string_length = (glong) _tmp2_;
	}
	if (offset < 0) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= 0, NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < 0) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}


gchar* deja_dup_get_folder_key (DejaDupSimpleSettings* settings, const gchar* key) {
	gchar* result = NULL;
	gchar* _tmp0_ = NULL;
	gchar* folder;
	gboolean _tmp1_;
	gboolean _tmp5_;
	g_return_val_if_fail (settings != NULL, NULL);
	g_return_val_if_fail (key != NULL, NULL);
	_tmp0_ = g_settings_get_string ((GSettings*) settings, key);
	folder = _tmp0_;
	_tmp1_ = string_contains (folder, "$HOSTNAME");
	if (_tmp1_) {
		const gchar* _tmp2_ = NULL;
		gchar* _tmp3_ = NULL;
		gchar* _tmp4_;
		_tmp2_ = g_get_host_name ();
		_tmp3_ = string_replace (folder, "$HOSTNAME", _tmp2_);
		_tmp4_ = _tmp3_;
		_g_free0 (folder);
		folder = _tmp4_;
		deja_dup_simple_settings_set_string (settings, key, folder);
	}
	_tmp5_ = g_str_has_prefix (folder, "/");
	if (_tmp5_) {
		gchar* _tmp6_ = NULL;
		gchar* _tmp7_;
		_tmp6_ = string_substring (folder, (glong) 1, (glong) (-1));
		_tmp7_ = _tmp6_;
		_g_free0 (folder);
		folder = _tmp7_;
	}
	result = folder;
	return result;
}


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


GFile* deja_dup_parse_dir (const gchar* dir) {
	GFile* result = NULL;
	gchar* _tmp0_;
	gchar* s;
	g_return_val_if_fail (dir != NULL, NULL);
	_tmp0_ = g_strdup (dir);
	s = _tmp0_;
	if (g_strcmp0 (s, "$HOME") == 0) {
		const gchar* _tmp1_ = NULL;
		gchar* _tmp2_;
		gchar* _tmp3_;
		_tmp1_ = g_get_home_dir ();
		_tmp2_ = g_strdup (_tmp1_);
		_tmp3_ = _tmp2_;
		_g_free0 (s);
		s = _tmp3_;
	} else {
		if (g_strcmp0 (s, "$DESKTOP") == 0) {
			const gchar* _tmp4_ = NULL;
			gchar* _tmp5_;
			gchar* _tmp6_;
			_tmp4_ = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
			_tmp5_ = g_strdup (_tmp4_);
			_tmp6_ = _tmp5_;
			_g_free0 (s);
			s = _tmp6_;
		} else {
			if (g_strcmp0 (s, "$DOCUMENTS") == 0) {
				const gchar* _tmp7_ = NULL;
				gchar* _tmp8_;
				gchar* _tmp9_;
				_tmp7_ = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
				_tmp8_ = g_strdup (_tmp7_);
				_tmp9_ = _tmp8_;
				_g_free0 (s);
				s = _tmp9_;
			} else {
				if (g_strcmp0 (s, "$DOWNLOAD") == 0) {
					const gchar* _tmp10_ = NULL;
					gchar* _tmp11_;
					gchar* _tmp12_;
					_tmp10_ = g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD);
					_tmp11_ = g_strdup (_tmp10_);
					_tmp12_ = _tmp11_;
					_g_free0 (s);
					s = _tmp12_;
				} else {
					if (g_strcmp0 (s, "$MUSIC") == 0) {
						const gchar* _tmp13_ = NULL;
						gchar* _tmp14_;
						gchar* _tmp15_;
						_tmp13_ = g_get_user_special_dir (G_USER_DIRECTORY_MUSIC);
						_tmp14_ = g_strdup (_tmp13_);
						_tmp15_ = _tmp14_;
						_g_free0 (s);
						s = _tmp15_;
					} else {
						if (g_strcmp0 (s, "$PICTURES") == 0) {
							const gchar* _tmp16_ = NULL;
							gchar* _tmp17_;
							gchar* _tmp18_;
							_tmp16_ = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
							_tmp17_ = g_strdup (_tmp16_);
							_tmp18_ = _tmp17_;
							_g_free0 (s);
							s = _tmp18_;
						} else {
							if (g_strcmp0 (s, "$PUBLIC_SHARE") == 0) {
								const gchar* _tmp19_ = NULL;
								gchar* _tmp20_;
								gchar* _tmp21_;
								_tmp19_ = g_get_user_special_dir (G_USER_DIRECTORY_PUBLIC_SHARE);
								_tmp20_ = g_strdup (_tmp19_);
								_tmp21_ = _tmp20_;
								_g_free0 (s);
								s = _tmp21_;
							} else {
								if (g_strcmp0 (s, "$TEMPLATES") == 0) {
									const gchar* _tmp22_ = NULL;
									gchar* _tmp23_;
									gchar* _tmp24_;
									_tmp22_ = g_get_user_special_dir (G_USER_DIRECTORY_TEMPLATES);
									_tmp23_ = g_strdup (_tmp22_);
									_tmp24_ = _tmp23_;
									_g_free0 (s);
									s = _tmp24_;
								} else {
									if (g_strcmp0 (s, "$TRASH") == 0) {
										gchar* _tmp25_ = NULL;
										gchar* _tmp26_;
										_tmp25_ = deja_dup_get_trash_path ();
										_tmp26_ = _tmp25_;
										_g_free0 (s);
										s = _tmp26_;
									} else {
										if (g_strcmp0 (s, "$VIDEOS") == 0) {
											const gchar* _tmp27_ = NULL;
											gchar* _tmp28_;
											gchar* _tmp29_;
											_tmp27_ = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
											_tmp28_ = g_strdup (_tmp27_);
											_tmp29_ = _tmp28_;
											_g_free0 (s);
											s = _tmp29_;
										} else {
											gboolean _tmp30_ = FALSE;
											gchar* _tmp31_ = NULL;
											gchar* _tmp32_;
											gboolean _tmp33_;
											_tmp31_ = g_uri_parse_scheme (s);
											_tmp32_ = _tmp31_;
											if ((_tmp33_ = _tmp32_ == NULL, _g_free0 (_tmp32_), _tmp33_)) {
												gboolean _tmp34_;
												_tmp34_ = g_path_is_absolute (s);
												_tmp30_ = !_tmp34_;
											} else {
												_tmp30_ = FALSE;
											}
											if (_tmp30_) {
												const gchar* _tmp35_ = NULL;
												gchar* _tmp36_ = NULL;
												gchar* _tmp37_;
												_tmp35_ = g_get_home_dir ();
												_tmp36_ = g_build_filename (_tmp35_, s, NULL);
												_tmp37_ = _tmp36_;
												_g_free0 (s);
												s = _tmp37_;
											} else {
												GFile* _tmp38_ = NULL;
												GFile* _tmp39_;
												_tmp38_ = g_file_parse_name (s);
												_tmp39_ = _g_object_ref0 (_tmp38_);
												result = _tmp39_;
												_g_free0 (s);
												return result;
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	if (s != NULL) {
		GFile* _tmp40_ = NULL;
		_tmp40_ = g_file_new_for_path (s);
		result = _tmp40_;
		_g_free0 (s);
		return result;
	} else {
		result = NULL;
		_g_free0 (s);
		return result;
	}
	_g_free0 (s);
}


static void _vala_array_add1 (GFile*** array, int* length, int* size, GFile* value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (GFile*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}


GFile** deja_dup_parse_dir_list (const gchar** dirs, int dirs_length1, int* result_length1) {
	GFile** result = NULL;
	GFile** _tmp0_ = NULL;
	GFile** rv;
	gint rv_length1;
	gint _rv_size_;
	GFile** _tmp4_;
	_tmp0_ = g_new0 (GFile*, 0 + 1);
	rv = _tmp0_;
	rv_length1 = 0;
	_rv_size_ = 0;
	{
		const gchar** s_collection;
		int s_collection_length1;
		int s_it;
		s_collection = dirs;
		s_collection_length1 = dirs_length1;
		for (s_it = 0; s_it < dirs_length1; s_it = s_it + 1) {
			gchar* _tmp1_;
			gchar* s;
			_tmp1_ = g_strdup ((gchar*) s_collection[s_it]);
			s = _tmp1_;
			{
				GFile* _tmp2_ = NULL;
				GFile* f;
				_tmp2_ = deja_dup_parse_dir (s);
				f = _tmp2_;
				if (f != NULL) {
					GFile* _tmp3_;
					_tmp3_ = _g_object_ref0 (f);
					_vala_array_add1 (&rv, &rv_length1, &_rv_size_, _tmp3_);
				}
				_g_object_unref0 (f);
				_g_free0 (s);
			}
		}
	}
	_tmp4_ = rv;
	*result_length1 = rv_length1;
	result = _tmp4_;
	return result;
}


DejaDupSimpleSettings* deja_dup_get_settings (const gchar* subdir) {
	DejaDupSimpleSettings* result = NULL;
	gchar* _tmp0_;
	gchar* schema;
	gboolean _tmp1_ = FALSE;
	DejaDupSimpleSettings* _tmp4_ = NULL;
	_tmp0_ = g_strdup ("org.gnome.DejaDup");
	schema = _tmp0_;
	if (subdir != NULL) {
		_tmp1_ = g_strcmp0 (subdir, "") != 0;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		gchar* _tmp2_;
		gchar* _tmp3_;
		_tmp2_ = g_strconcat (".", subdir, NULL);
		_tmp3_ = g_strconcat (schema, _tmp2_, NULL);
		_g_free0 (schema);
		schema = _tmp3_;
		_g_free0 (_tmp2_);
	}
	_tmp4_ = deja_dup_simple_settings_new (schema);
	result = _tmp4_;
	_g_free0 (schema);
	return result;
}


static gchar string_get (const gchar* self, glong index) {
	gchar result = '\0';
	g_return_val_if_fail (self != NULL, '\0');
	result = ((gchar*) self)[index];
	return result;
}


void deja_dup_convert_ssh_to_file (void) {
	DejaDupSimpleSettings* _tmp0_ = NULL;
	DejaDupSimpleSettings* settings;
	gchar* _tmp1_ = NULL;
	gchar* backend;
	_tmp0_ = deja_dup_get_settings (NULL);
	settings = _tmp0_;
	_tmp1_ = g_settings_get_string ((GSettings*) settings, DEJA_DUP_BACKEND_KEY);
	backend = _tmp1_;
	if (g_strcmp0 (backend, "ssh") == 0) {
		DejaDupSimpleSettings* _tmp2_ = NULL;
		DejaDupSimpleSettings* ssh_settings;
		gchar* _tmp3_ = NULL;
		gchar* server;
		gboolean _tmp4_ = FALSE;
		deja_dup_simple_settings_set_string (settings, DEJA_DUP_BACKEND_KEY, "file");
		_tmp2_ = deja_dup_get_settings ("SSH");
		ssh_settings = _tmp2_;
		_tmp3_ = g_settings_get_string ((GSettings*) ssh_settings, DEJA_DUP_SSH_SERVER_KEY);
		server = _tmp3_;
		if (server != NULL) {
			_tmp4_ = g_strcmp0 (server, "") != 0;
		} else {
			_tmp4_ = FALSE;
		}
		if (_tmp4_) {
			gchar* _tmp5_ = NULL;
			gchar* username;
			gint _tmp6_;
			gint port;
			gchar* _tmp7_ = NULL;
			gchar* directory;
			gchar* _tmp8_;
			gchar* gio_uri;
			gboolean _tmp9_ = FALSE;
			gchar* _tmp12_;
			gboolean _tmp13_ = FALSE;
			gboolean _tmp18_ = FALSE;
			DejaDupSimpleSettings* _tmp24_ = NULL;
			DejaDupSimpleSettings* file_settings;
			_tmp5_ = g_settings_get_string ((GSettings*) ssh_settings, DEJA_DUP_SSH_USERNAME_KEY);
			username = _tmp5_;
			_tmp6_ = g_settings_get_int ((GSettings*) ssh_settings, DEJA_DUP_SSH_PORT_KEY);
			port = _tmp6_;
			_tmp7_ = g_settings_get_string ((GSettings*) ssh_settings, DEJA_DUP_SSH_DIRECTORY_KEY);
			directory = _tmp7_;
			_tmp8_ = g_strdup ("ssh://");
			gio_uri = _tmp8_;
			if (username != NULL) {
				_tmp9_ = g_strcmp0 (username, "") != 0;
			} else {
				_tmp9_ = FALSE;
			}
			if (_tmp9_) {
				gchar* _tmp10_;
				gchar* _tmp11_;
				_tmp10_ = g_strconcat (username, "@", NULL);
				_tmp11_ = g_strconcat (gio_uri, _tmp10_, NULL);
				_g_free0 (gio_uri);
				gio_uri = _tmp11_;
				_g_free0 (_tmp10_);
			}
			_tmp12_ = g_strconcat (gio_uri, server, NULL);
			_g_free0 (gio_uri);
			gio_uri = _tmp12_;
			if (port > 0) {
				_tmp13_ = port != 22;
			} else {
				_tmp13_ = FALSE;
			}
			if (_tmp13_) {
				gchar* _tmp14_ = NULL;
				gchar* _tmp15_;
				gchar* _tmp16_;
				gchar* _tmp17_;
				_tmp14_ = g_strdup_printf ("%i", port);
				_tmp15_ = _tmp14_;
				_tmp16_ = g_strconcat (":", _tmp15_, NULL);
				_tmp17_ = g_strconcat (gio_uri, _tmp16_, NULL);
				_g_free0 (gio_uri);
				gio_uri = _tmp17_;
				_g_free0 (_tmp16_);
				_g_free0 (_tmp15_);
			}
			if (directory == NULL) {
				_tmp18_ = TRUE;
			} else {
				_tmp18_ = g_strcmp0 (directory, "") == 0;
			}
			if (_tmp18_) {
				gchar* _tmp19_;
				_tmp19_ = g_strconcat (gio_uri, "/", NULL);
				_g_free0 (gio_uri);
				gio_uri = _tmp19_;
			} else {
				gchar _tmp20_;
				_tmp20_ = string_get (directory, (glong) 0);
				if (_tmp20_ != '/') {
					gchar* _tmp21_;
					gchar* _tmp22_;
					_tmp21_ = g_strconcat ("/", directory, NULL);
					_tmp22_ = g_strconcat (gio_uri, _tmp21_, NULL);
					_g_free0 (gio_uri);
					gio_uri = _tmp22_;
					_g_free0 (_tmp21_);
				} else {
					gchar* _tmp23_;
					_tmp23_ = g_strconcat (gio_uri, directory, NULL);
					_g_free0 (gio_uri);
					gio_uri = _tmp23_;
				}
			}
			_tmp24_ = deja_dup_get_settings (DEJA_DUP_FILE_ROOT);
			file_settings = _tmp24_;
			deja_dup_simple_settings_set_string (file_settings, DEJA_DUP_FILE_PATH_KEY, gio_uri);
			_g_object_unref0 (file_settings);
			_g_free0 (gio_uri);
			_g_free0 (directory);
			_g_free0 (username);
		}
		_g_free0 (server);
		_g_object_unref0 (ssh_settings);
	}
	_g_free0 (backend);
	_g_object_unref0 (settings);
}


void deja_dup_convert_s3_folder_to_hostname (void) {
	DejaDupSimpleSettings* _tmp0_ = NULL;
	DejaDupSimpleSettings* settings;
	DejaDupSimpleSettings* _tmp1_ = NULL;
	DejaDupSimpleSettings* s3_settings;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_;
	gboolean _tmp6_;
	_tmp0_ = deja_dup_get_settings (NULL);
	settings = _tmp0_;
	_tmp1_ = deja_dup_get_settings (DEJA_DUP_S3_ROOT);
	s3_settings = _tmp1_;
	_tmp4_ = g_settings_get_string ((GSettings*) s3_settings, DEJA_DUP_S3_FOLDER_KEY);
	_tmp5_ = _tmp4_;
	if ((_tmp6_ = g_strcmp0 (_tmp5_, "") == 0, _g_free0 (_tmp5_), _tmp6_)) {
		_tmp3_ = TRUE;
	} else {
		gchar* _tmp7_ = NULL;
		gchar* _tmp8_;
		_tmp7_ = g_settings_get_string ((GSettings*) s3_settings, DEJA_DUP_S3_FOLDER_KEY);
		_tmp8_ = _tmp7_;
		_tmp3_ = g_strcmp0 (_tmp8_, "/") == 0;
		_g_free0 (_tmp8_);
	}
	if (_tmp3_) {
		gboolean _tmp9_ = FALSE;
		gchar* _tmp10_ = NULL;
		gchar* _tmp11_;
		gboolean _tmp12_;
		_tmp10_ = deja_dup_backend_get_default_type ();
		_tmp11_ = _tmp10_;
		if ((_tmp12_ = g_strcmp0 (_tmp11_, "s3") != 0, _g_free0 (_tmp11_), _tmp12_)) {
			_tmp9_ = TRUE;
		} else {
			gchar* _tmp13_ = NULL;
			gchar* _tmp14_;
			_tmp13_ = g_settings_get_string ((GSettings*) settings, DEJA_DUP_LAST_RUN_KEY);
			_tmp14_ = _tmp13_;
			_tmp9_ = g_strcmp0 (_tmp14_, "") == 0;
			_g_free0 (_tmp14_);
		}
		_tmp2_ = _tmp9_;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		deja_dup_simple_settings_set_string (s3_settings, DEJA_DUP_S3_FOLDER_KEY, "$HOSTNAME");
	}
	_g_object_unref0 (s3_settings);
	_g_object_unref0 (settings);
}


void deja_dup_initialize (void) {
	deja_dup_convert_ssh_to_file ();
	deja_dup_convert_s3_folder_to_hostname ();
}


void deja_dup_i18n_setup (void) {
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_;
	gchar* localedir;
	gboolean _tmp2_ = FALSE;
	const gchar* _tmp5_ = NULL;
	gchar* _tmp6_;
	gchar* language;
	gboolean _tmp7_ = FALSE;
	_tmp0_ = g_getenv ("DEJA_DUP_LOCALEDIR");
	_tmp1_ = g_strdup (_tmp0_);
	localedir = _tmp1_;
	if (localedir == NULL) {
		_tmp2_ = TRUE;
	} else {
		_tmp2_ = g_strcmp0 (localedir, "") == 0;
	}
	if (_tmp2_) {
		gchar* _tmp3_;
		gchar* _tmp4_;
		_tmp3_ = g_strdup (LOCALE_DIR);
		_tmp4_ = _tmp3_;
		_g_free0 (localedir);
		localedir = _tmp4_;
	}
	_tmp5_ = g_getenv ("DEJA_DUP_LANGUAGE");
	_tmp6_ = g_strdup (_tmp5_);
	language = _tmp6_;
	if (language != NULL) {
		_tmp7_ = g_strcmp0 (language, "") != 0;
	} else {
		_tmp7_ = FALSE;
	}
	if (_tmp7_) {
		g_setenv ("LANGUAGE", language, TRUE);
	}
	textdomain (GETTEXT_PACKAGE);
	bindtextdomain (GETTEXT_PACKAGE, localedir);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	_g_free0 (language);
	_g_free0 (localedir);
}


gchar* deja_dup_get_file_desc (GFile* file) {
	gchar* result = NULL;
	GFileInfo* _tmp0_ = NULL;
	GFileInfo* info;
	gboolean _tmp1_;
	gchar* _tmp7_ = NULL;
	gchar* _tmp8_;
	gchar* _tmp9_ = NULL;
	gchar* _tmp10_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (file != NULL, NULL);
	_tmp0_ = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," G_FILE_ATTRIBUTE_STANDARD_DESCRIPTION, G_FILE_QUERY_INFO_NONE, NULL, &_inner_error_);
	info = _tmp0_;
	if (_inner_error_ != NULL) {
		goto __catch15_g_error;
	}
	_tmp1_ = g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_DESCRIPTION);
	if (_tmp1_) {
		const gchar* _tmp2_ = NULL;
		gchar* _tmp3_;
		_tmp2_ = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_DESCRIPTION);
		_tmp3_ = g_strdup (_tmp2_);
		result = _tmp3_;
		_g_object_unref0 (info);
		return result;
	} else {
		gboolean _tmp4_;
		_tmp4_ = g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
		if (_tmp4_) {
			const gchar* _tmp5_ = NULL;
			gchar* _tmp6_;
			_tmp5_ = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
			_tmp6_ = g_strdup (_tmp5_);
			result = _tmp6_;
			_g_object_unref0 (info);
			return result;
		}
	}
	_g_object_unref0 (info);
	goto __finally15;
	__catch15_g_error:
	{
		GError * e;
		e = _inner_error_;
		_inner_error_ = NULL;
		_g_error_free0 (e);
	}
	__finally15:
	if (_inner_error_ != NULL) {
		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 NULL;
	}
	_tmp7_ = g_file_get_parse_name (file);
	_tmp8_ = _tmp7_;
	_tmp9_ = g_path_get_basename (_tmp8_);
	result = (_tmp10_ = _tmp9_, _g_free0 (_tmp8_), _tmp10_);
	return result;
}


gchar* deja_dup_get_location_desc (void) {
	gchar* result = NULL;
	DejaDupBackend* _tmp0_ = NULL;
	DejaDupBackend* _tmp1_;
	DejaDupBackend* _tmp2_;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_;
	gchar* desc;
	gboolean _tmp5_ = FALSE;
	const gchar* _tmp6_ = NULL;
	gchar* _tmp7_;
	GError * _inner_error_ = NULL;
	_tmp0_ = deja_dup_backend_get_default (&_inner_error_);
	_tmp1_ = _tmp0_;
	if (_inner_error_ != NULL) {
		goto __catch16_g_error;
	}
	_tmp2_ = _tmp1_;
	_tmp3_ = deja_dup_backend_get_location_pretty (_tmp2_, &_inner_error_);
	desc = (_tmp4_ = _tmp3_, _g_object_unref0 (_tmp2_), _tmp4_);
	if (_inner_error_ != NULL) {
		goto __catch16_g_error;
	}
	if (desc != NULL) {
		_tmp5_ = g_strcmp0 (desc, "") != 0;
	} else {
		_tmp5_ = FALSE;
	}
	if (_tmp5_) {
		result = desc;
		return result;
	}
	_g_free0 (desc);
	goto __finally16;
	__catch16_g_error:
	{
		GError * e;
		e = _inner_error_;
		_inner_error_ = NULL;
		_g_error_free0 (e);
	}
	__finally16:
	if (_inner_error_ != NULL) {
		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 NULL;
	}
	_tmp6_ = _ ("Unknown");
	_tmp7_ = g_strdup (_tmp6_);
	result = _tmp7_;
	return result;
}


gint deja_dup_get_full_backup_threshold (void) {
	gint result = 0;
	gint threshold;
	gint max;
	gint min;
	gint scale;
	gint min_fulls;
	DejaDupSimpleSettings* _tmp0_ = NULL;
	DejaDupSimpleSettings* settings;
	gint _tmp1_;
	gint delete_age;
	gboolean _tmp3_;
	gboolean periodic;
	threshold = 7 * 6;
	max = 24 * 7;
	min = 4 * 7;
	scale = 12;
	min_fulls = 2;
	_tmp0_ = deja_dup_get_settings (NULL);
	settings = _tmp0_;
	_tmp1_ = g_settings_get_int ((GSettings*) settings, DEJA_DUP_DELETE_AFTER_KEY);
	delete_age = _tmp1_;
	if (delete_age > 0) {
		gint _tmp2_;
		_tmp2_ = MIN (delete_age / min_fulls, max);
		max = _tmp2_;
	}
	_tmp3_ = g_settings_get_boolean ((GSettings*) settings, DEJA_DUP_PERIODIC_KEY);
	periodic = _tmp3_;
	if (periodic) {
		gint _tmp4_;
		gint period;
		_tmp4_ = g_settings_get_int ((GSettings*) settings, DEJA_DUP_PERIODIC_PERIOD_KEY);
		period = _tmp4_;
		threshold = period * scale;
		CLAMP (threshold, min, max);
	} else {
		threshold = max;
	}
	result = threshold;
	_g_object_unref0 (settings);
	return result;
}


void deja_dup_get_full_backup_threshold_date (GDate* result) {
	GTimeVal now = {0};
	GDate date = {0};
	gint _tmp0_;
	gint days;
	g_get_current_time (&now);
	g_get_current_time (&now);
	memset (&date, 0, sizeof (GDate));
	g_date_set_time_val (&date, &now);
	_tmp0_ = deja_dup_get_full_backup_threshold ();
	days = _tmp0_;
	g_date_subtract_days (&date, (guint) days);
	*result = date;
	return;
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int 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, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



