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

/*  This file is part of corebird, a Gtk+ linux Twitter client.
 *  Copyright (C) 2013 Timm Bäder
 *
 *  corebird 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.
 *
 *  corebird 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 corebird.  If not, see <http://www.gnu.org/licenses/>.
 */

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

#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))


extern gchar* dirs_config_dir;
gchar* dirs_config_dir = NULL;
extern gchar* dirs_cache_dir;
gchar* dirs_cache_dir = NULL;
extern gchar* dirs_data_dir;
gchar* dirs_data_dir = NULL;

void dirs_create_dirs (void);
void dirs_create_folder (const gchar* path);
gchar* dirs_cache (const gchar* path);
gchar* dirs_config (const gchar* path);
gchar* dirs_data (const gchar* path);


void dirs_create_dirs (void) {
	gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	gchar* _tmp6_ = NULL;
	gchar* _tmp7_ = NULL;
	gchar* _tmp8_ = NULL;
	gchar* _tmp9_ = NULL;
	gchar* _tmp10_ = NULL;
	gchar* _tmp11_ = NULL;
	gchar* _tmp12_ = NULL;
	gchar* _tmp13_ = NULL;
	gchar* _tmp14_ = NULL;
	gchar* _tmp15_ = NULL;
	gchar* _tmp16_ = NULL;
	gchar* _tmp17_ = NULL;
	gchar* _tmp18_ = NULL;
	gchar* _tmp19_ = NULL;
	gchar* _tmp20_ = NULL;
	gchar* _tmp21_ = NULL;
	_tmp0_ = dirs_cache ("");
	_tmp1_ = _tmp0_;
	dirs_create_folder (_tmp1_);
	_g_free0 (_tmp1_);
	_tmp2_ = dirs_cache ("assets");
	_tmp3_ = _tmp2_;
	dirs_create_folder (_tmp3_);
	_g_free0 (_tmp3_);
	_tmp4_ = dirs_cache ("assets/banners/");
	_tmp5_ = _tmp4_;
	dirs_create_folder (_tmp5_);
	_g_free0 (_tmp5_);
	_tmp6_ = dirs_cache ("assets/avatars/");
	_tmp7_ = _tmp6_;
	dirs_create_folder (_tmp7_);
	_g_free0 (_tmp7_);
	_tmp8_ = dirs_cache ("assets/user/");
	_tmp9_ = _tmp8_;
	dirs_create_folder (_tmp9_);
	_g_free0 (_tmp9_);
	_tmp10_ = dirs_cache ("assets/media/");
	_tmp11_ = _tmp10_;
	dirs_create_folder (_tmp11_);
	_g_free0 (_tmp11_);
	_tmp12_ = dirs_cache ("assets/media/thumbs/");
	_tmp13_ = _tmp12_;
	dirs_create_folder (_tmp13_);
	_g_free0 (_tmp13_);
	_tmp14_ = dirs_config ("");
	_tmp15_ = _tmp14_;
	dirs_create_folder (_tmp15_);
	_g_free0 (_tmp15_);
	_tmp16_ = dirs_config ("accounts/");
	_tmp17_ = _tmp16_;
	dirs_create_folder (_tmp17_);
	_g_free0 (_tmp17_);
	_tmp18_ = dirs_data ("");
	_tmp19_ = _tmp18_;
	dirs_create_folder (_tmp19_);
	_g_free0 (_tmp19_);
	_tmp20_ = dirs_data ("logs/");
	_tmp21_ = _tmp20_;
	dirs_create_folder (_tmp21_);
	_g_free0 (_tmp21_);
}


gchar* dirs_cache (const gchar* path) {
	gchar* result = NULL;
	const gchar* _tmp0_ = NULL;
	const gchar* _tmp3_ = NULL;
	const gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	g_return_val_if_fail (path != NULL, NULL);
	_tmp0_ = dirs_cache_dir;
	if (_tmp0_ == NULL) {
		const gchar* _tmp1_ = NULL;
		gchar* _tmp2_ = NULL;
		_tmp1_ = g_get_user_cache_dir ();
		_tmp2_ = g_strconcat (_tmp1_, "/corebird/", NULL);
		_g_free0 (dirs_cache_dir);
		dirs_cache_dir = _tmp2_;
	}
	_tmp3_ = dirs_cache_dir;
	_tmp4_ = path;
	_tmp5_ = g_strconcat (_tmp3_, _tmp4_, NULL);
	result = _tmp5_;
	return result;
}


gchar* dirs_data (const gchar* path) {
	gchar* result = NULL;
	const gchar* _tmp0_ = NULL;
	const gchar* _tmp3_ = NULL;
	const gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	g_return_val_if_fail (path != NULL, NULL);
	_tmp0_ = dirs_data_dir;
	if (_tmp0_ == NULL) {
		const gchar* _tmp1_ = NULL;
		gchar* _tmp2_ = NULL;
		_tmp1_ = g_get_user_data_dir ();
		_tmp2_ = g_strconcat (_tmp1_, "/corebird/", NULL);
		_g_free0 (dirs_data_dir);
		dirs_data_dir = _tmp2_;
	}
	_tmp3_ = dirs_data_dir;
	_tmp4_ = path;
	_tmp5_ = g_strconcat (_tmp3_, _tmp4_, NULL);
	result = _tmp5_;
	return result;
}


gchar* dirs_config (const gchar* path) {
	gchar* result = NULL;
	const gchar* _tmp0_ = NULL;
	const gchar* _tmp7_ = NULL;
	const gchar* _tmp8_ = NULL;
	gchar* _tmp9_ = NULL;
	g_return_val_if_fail (path != NULL, NULL);
	_tmp0_ = dirs_config_dir;
	if (_tmp0_ == NULL) {
		const gchar* _tmp1_ = NULL;
		gchar* _tmp2_ = NULL;
		const gchar* _tmp3_ = NULL;
		gboolean _tmp4_ = FALSE;
		_tmp1_ = g_get_home_dir ();
		_tmp2_ = g_strconcat (_tmp1_, "/.corebird/", NULL);
		_g_free0 (dirs_config_dir);
		dirs_config_dir = _tmp2_;
		_tmp3_ = dirs_config_dir;
		_tmp4_ = g_file_test (_tmp3_, G_FILE_TEST_EXISTS);
		if (!_tmp4_) {
			const gchar* _tmp5_ = NULL;
			gchar* _tmp6_ = NULL;
			_tmp5_ = g_get_user_config_dir ();
			_tmp6_ = g_strconcat (_tmp5_, "/corebird/", NULL);
			_g_free0 (dirs_config_dir);
			dirs_config_dir = _tmp6_;
		}
	}
	_tmp7_ = dirs_config_dir;
	_tmp8_ = path;
	_tmp9_ = g_strconcat (_tmp7_, _tmp8_, NULL);
	result = _tmp9_;
	return result;
}


void dirs_create_folder (const gchar* path) {
	const gchar* _tmp0_ = NULL;
	gboolean _tmp1_ = FALSE;
	GError * _inner_error_ = NULL;
	g_return_if_fail (path != NULL);
	_tmp0_ = path;
	_tmp1_ = g_file_test (_tmp0_, G_FILE_TEST_EXISTS);
	if (_tmp1_) {
		return;
	}
	{
		gboolean success = FALSE;
		const gchar* _tmp2_ = NULL;
		GFile* _tmp3_ = NULL;
		GFile* _tmp4_ = NULL;
		gboolean _tmp5_ = FALSE;
		gboolean _tmp6_ = FALSE;
		gboolean _tmp7_ = FALSE;
		_tmp2_ = path;
		_tmp3_ = g_file_new_for_path (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_file_make_directory (_tmp4_, NULL, &_inner_error_);
		_tmp6_ = _tmp5_;
		_g_object_unref0 (_tmp4_);
		success = _tmp6_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch74_g_error;
		}
		_tmp7_ = success;
		if (!_tmp7_) {
			const gchar* _tmp8_ = NULL;
			_tmp8_ = path;
			g_critical ("Dirs.vala:71: Couldn't create user folder %s", _tmp8_);
		}
	}
	goto __finally74;
	__catch74_g_error:
	{
		GError* e = NULL;
		GError* _tmp9_ = NULL;
		const gchar* _tmp10_ = NULL;
		const gchar* _tmp11_ = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp9_ = e;
		_tmp10_ = _tmp9_->message;
		_tmp11_ = path;
		g_critical ("Dirs.vala:74: %s(%s)", _tmp10_, _tmp11_);
		_g_error_free0 (e);
	}
	__finally74:
	if (G_UNLIKELY (_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;
	}
}



