Exemple #1
0
static void _track_write_image_to_file(sp_image* img, gpointer data) {
    GError* err = NULL;
    const guchar* img_data = NULL;
    gsize len;
    gchar* filename = (gchar*) data;

    img_data = sp_image_data(img, &len);
    if (!img_data)
        g_error("Can't read image data");
    g_debug("Saving image to %s", filename);
    if (!g_file_set_contents(filename, (gchar*) img_data, len, &err))
        g_error("Can't save image to file: %s", err->message);
    g_free(filename);
    sp_image_release(img);
}
Exemple #2
0
void write_installer_conf(const char* path)
{
    g_assert(path != NULL);

    normalization();
    char* content = installer_conf_to_string();
    GError* error = NULL;
    g_file_set_contents(path, content, -1, &error);
    g_free(content);

    if (error != NULL) {
	g_warning("write deepin-installer.conf(to %s) failed:%s\n", path, error->message);
	g_error_free(error);
    }
}
void
gss_config_save_config_file (void)
{
  GError *error = NULL;
  GString *s = g_string_new ("");
  gboolean ret;

  gss_config_append_config_file (s);

  ret = g_file_set_contents (CONFIG_FILE, s->str, s->len, &error);
  g_string_free (s, TRUE);
  if (!ret) {
    g_error_free (error);
  }
}
Exemple #4
0
/**
 * Writes the key store file to disk.
 */
static bool save_keystore(GKeyFile *keyfile) {
    char *filename;
    bool ok;
    // Serialize
    gsize file_length;
    gchar *file_data = g_key_file_to_data(keyfile, &file_length, NULL);
    if (!file_data) return false;
    
    // Write to file
    filename = get_config_filename();
    ok = g_file_set_contents(filename, file_data, file_length, NULL);
    g_free(filename);
    g_free(file_data);
    return ok;
}
Exemple #5
0
static void
_save_prefs(void)
{
    gsize g_data_size;
    gchar *g_prefs_data = g_key_file_to_data(prefs, &g_data_size, NULL);
    gchar *base = g_path_get_basename(prefs_loc);
    gchar *true_loc = get_file_or_linked(prefs_loc, base);

    g_file_set_contents(true_loc, g_prefs_data, g_data_size, NULL);
    g_chmod(prefs_loc, S_IRUSR | S_IWUSR);

    g_free(base);
    free(true_loc);
    g_free(g_prefs_data);
}
void write_setting_file()
{
    gchar * file = g_strjoin("/",g_get_home_dir(),".emerald/settings.ini",NULL);
    gchar * path = g_strjoin("/",g_get_home_dir(),".emerald/",NULL);
    gchar * at;
    g_mkdir_with_parents(path,00755);
    at = g_key_file_to_data(global_settings_file,NULL,NULL);
    if (at)
    {
        g_file_set_contents(file,at,-1,NULL);
        g_free(at);
    }
    g_free(file);
    g_free(path);
}
void
test_patterndb_tags_outside_of_rule()
{
  patterndb = pattern_db_new();
  messages = NULL;

  g_file_open_tmp("patterndbXXXXXX.xml", &filename, NULL);
  g_file_set_contents(filename, tag_outside_of_rule_skeleton,
                      strlen(tag_outside_of_rule_skeleton), NULL);

  if (pattern_db_reload_ruleset(patterndb, configuration, filename))
    fail = TRUE;

  clean_pattern_db();
}
/* create basic conffile with sensible defaults */
static void create_conf_file(void)
{
  GKeyFile *settingsfile;
  gchar *keyfile;

  mkdir(CONFIG_FILE_DIR, 0755);

  settingsfile = g_key_file_new();

  g_key_file_set_string(settingsfile, MODE_SETTING_ENTRY, MODE_SETTING_KEY, MODE_DEVELOPER );
  keyfile = g_key_file_to_data (settingsfile, NULL, NULL);
  if(g_file_set_contents(FS_MOUNT_CONFIG_FILE, keyfile, -1, NULL) == 0)
	log_debug("Conffile creation failed. Continuing without configuration!\n");
  g_key_file_free(settingsfile);
}
Exemple #9
0
static void
replace_in_file (const gchar *filename,
                 const gchar *find,
                 const gchar *replace)
{
	gchar *content = NULL;
	GError *error = NULL;
	GString *filenamestr = NULL;

	g_return_if_fail (filename != NULL);
	g_return_if_fail (find != NULL);
	g_return_if_fail (*find);
	g_return_if_fail (replace != NULL);

	if (strstr (filename, "$")) {
		filenamestr = replace_variables (filename);

		if (!filenamestr) {
			g_warning ("%s: Replace variables in '%s' failed!", G_STRFUNC, filename);
			return;
		}

		filename = filenamestr->str;
	}

	if (g_file_get_contents (filename, &content, NULL, &error)) {
		GString *str = replace_string (content, find, replace);

		if (str) {
			if (!g_file_set_contents (filename, str->str, -1, &error) && error) {
				g_warning ("%s: cannot write file content, error: %s", G_STRFUNC, error->message);
				g_error_free (error);
			}

			g_string_free (str, TRUE);
		} else {
			g_warning ("%s: Replace of '%s' to '%s' failed!", G_STRFUNC, find, replace);
		}

		g_free (content);
	} else if (error) {
		g_warning ("%s: Cannot read file content, error: %s", G_STRFUNC, error->message);
		g_error_free (error);
	}

	if (filenamestr)
		g_string_free (filenamestr, TRUE);
}
void FiltersDialog::on_button_try()
{
  // Iterators.
  GtkTextIter startiter, enditer;

  // Input text.
  GtkTextBuffer *inputbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview_input));
  gtk_text_buffer_get_start_iter(inputbuffer, &startiter);
  gtk_text_buffer_get_end_iter(inputbuffer, &enditer);
  ustring inputfile = script_temporal_input_file();
  gchar *txt = gtk_text_buffer_get_text(inputbuffer, &startiter, &enditer, false);
  g_file_set_contents(inputfile.c_str(), txt, -1, NULL);
  g_free(txt); // Postiff: plug memory leak

  // Filter.
  ustring scriptname = combobox_get_active_string(combobox_filters);
  bool straightthrough = scriptname == scripts_straight_through();

  // Output file.
  ustring outputfile = script_temporal_output_file();

  // Run filter.
  ustring error = script_filter(scriptname, straightthrough, inputfile, outputfile);

  // Show output in textview.  
  gchar *outputtext;
  g_file_get_contents(outputfile.c_str(), &outputtext, NULL, NULL);
  GtkTextBuffer *outputbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview_output));
  if (outputtext) {
    gtk_text_buffer_set_text(outputbuffer, outputtext, -1);
    g_free(outputtext);
  } else {
    gtk_text_buffer_set_text(outputbuffer, "", -1);
  }

  // If script failed, give the error for debugging purposes.
  if (!error.empty()) {
    gtk_text_buffer_set_text(outputbuffer, error.c_str(), -1);
  }
  // If there were compile errors before, show these.
  if (!compile_errors.empty()) {
    gtk_text_buffer_set_text(outputbuffer, "", -1);
    for (unsigned int i = 0; i < compile_errors.size(); i++) {
      gtk_text_buffer_insert_at_cursor(outputbuffer, compile_errors[i].c_str(), -1);
      gtk_text_buffer_insert_at_cursor(outputbuffer, "\n", -1);
    }
  }
}
Exemple #11
0
static gboolean
mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path, GError ** error)
{
    gchar *data, *written_data;
    gsize len, total_written;
    gboolean ret;
    int fd;
    ssize_t cur_written;
    vfs_path_t *ini_vpath;

    ini_vpath = vfs_path_from_str (ini_path);
    data = g_key_file_to_data (mc_config->handle, &len, NULL);
    if (!exist_file (ini_path))
    {
        ret = g_file_set_contents (ini_path, data, len, error);
        g_free (data);
        vfs_path_free (ini_vpath);
        return ret;
    }
    mc_util_make_backup_if_possible (ini_path, "~");

    fd = mc_open (ini_vpath, O_WRONLY | O_TRUNC, 0);
    if (fd == -1)
    {
        g_propagate_error (error, g_error_new (MC_ERROR, 0, "%s", unix_error_string (errno)));
        g_free (data);
        vfs_path_free (ini_vpath);
        return FALSE;
    }

    for (written_data = data, total_written = len;
         (cur_written = mc_write (fd, (const void *) written_data, total_written)) > 0;
         written_data += cur_written, total_written -= cur_written);
    mc_close (fd);
    g_free (data);

    if (cur_written == -1)
    {
        mc_util_restore_from_backup_if_possible (ini_path, "~");
        g_propagate_error (error, g_error_new (MC_ERROR, 0, "%s", unix_error_string (errno)));
        vfs_path_free (ini_vpath);
        return FALSE;
    }

    mc_util_unlink_backup_if_possible (ini_path, "~");
    vfs_path_free (ini_vpath);
    return TRUE;
}
static void
hlfs_find_inode_by_name_setup(Fixture *fixture, const void *data) {
    const char *test_dir = (const char *)data;
    g_print("test env dir is %s\n", test_dir);
    char *fs_dir = g_build_filename(test_dir, "testfs", NULL);
//	g_assert(g_mkdir(fs_dir, 0700) == 0);
    char *uri = g_malloc0(128);
    g_assert(uri != NULL);
    snprintf(uri, 128, "%s%s", "local://", fs_dir);
//	char *uri = g_build_path(tmp, fs_dir, NULL);
    g_print("uri is %s\n", uri);
    pid_t status;
    const char cmd[256];
    memset((char *) cmd, 0, 256);
    sprintf((char *) cmd, "%s %s %s %s %d %s %d %s %d", "../mkfs.hlfs",
            "-u", uri,
            "-b", 8192,
            "-s", 67108864,
            "-m", 1024);
    g_message("cmd is [%s]", cmd);
    status = system(cmd);
#if 0
    GKeyFile *sb_keyfile = g_key_file_new();
    g_key_file_set_string(sb_keyfile, "METADATA", "uri", uri);
    g_key_file_set_integer(sb_keyfile, "METADATA", "block_size", 8196);
    g_key_file_set_integer(sb_keyfile, "METADATA", "segment_size", 67108864);
    g_key_file_set_integer(sb_keyfile, "METADATA", "max_fs_size", 671088640);
    gchar *content = g_key_file_to_data(sb_keyfile, NULL, NULL);
    char *sb_file_path = g_build_filename(fs_dir, "superblock", NULL);
    g_print("sb file path is %s\n", sb_file_path);
    GError *error = NULL;
    if (TRUE != g_file_set_contents(sb_file_path, content, strlen(content) + 1, &error)) {
        g_print("error msg is %s", error->message);
        error = NULL;
    }
#endif
    fixture->uri = uri;
    g_print("fixture->uri is %s\n", fixture->uri);
    fixture->ctrl = init_hlfs(fixture->uri);
    g_assert(fixture->ctrl != NULL);
    int ret = hlfs_open(fixture->ctrl, 1);
    g_assert(ret == 0);
    take_snapshot(fixture, data);
//	g_key_file_free(sb_keyfile);
//	g_free(sb_file_path);
    g_free(fs_dir);
    return ;
}
Exemple #13
0
void convert_txt(const gchar *dirname, const gchar *txtfilename, const gchar *locale_sutra_name)
{
	std::string fullfilename;
	fullfilename = dirname;
	fullfilename += "/txt/";
	fullfilename += txtfilename;

	std::string file_contents;
	file_contents = "<HTML><HEAD>\r\n<META http-equiv=Content-Type content=\"text/html; charset=GBK\">\r\n<TITLE>";
	file_contents += locale_sutra_name;
	file_contents += "</TITLE>\r\n</HEAD>\r\n<BODY>";

	gchar *contents;
	g_file_get_contents(fullfilename.c_str(), &contents, NULL, NULL);
	
	std::string html_contents;
	html_contents = contents;
	string_replace(html_contents, "\r\n", "<BR>\r\n");

	g_free(contents);

	file_contents += html_contents;

	file_contents += "</BODY>\r\n</HTML>";

	g_file_set_contents(fullfilename.c_str(), file_contents.c_str(), -1, NULL);

	std::string oldpath;
	oldpath = dirname;
	oldpath += "/txt/";
	oldpath += txtfilename;

	gchar tmpfilename1[256];
	strcpy(tmpfilename1, txtfilename);
	gchar *p;
	p = strrchr(tmpfilename1, '.');
	if (p) {
		*p = '\0';
	}

	std::string newpath;
	newpath = dirname;
	newpath += "/html/";
	newpath += tmpfilename1;
	newpath += ".html";

	rename(oldpath.c_str(), newpath.c_str());
}
Exemple #14
0
void destroy( GtkWidget *widget,
	      gpointer   data )
{
    gsize length;
    gchar *inidata = g_key_file_to_data (keyfile,
                                         &length,
                                         NULL);

    print_stat();

    g_file_set_contents(conffile, inidata, length, NULL);
    g_free(inidata);
    g_key_file_free(keyfile);

    gtk_main_quit ();
}
Exemple #15
0
static gboolean set_etag_file(const char *fn, CurlDownloadOptions *cdo)
{
  gboolean result = FALSE;
  gchar *etag_filename;

  etag_filename = g_strdup_printf("%s.etag", fn);
  if (etag_filename) {
    result = g_file_set_contents(etag_filename, cdo->new_etag, -1, NULL);
    g_free(etag_filename);
  }

  if (result)
    g_debug("%s: Set etag (file) on %s: %s", __FUNCTION__, fn, cdo->new_etag);

  return result;
}
Exemple #16
0
static void policy_save(GKeyFile *keyfile, char *pathname)
{
	gchar *data = NULL;
	gsize length = 0;
	GError *error = NULL;

	data = g_key_file_to_data(keyfile, &length, NULL);

	if (!g_file_set_contents(pathname, data, length, &error)) {
		DBG("Failed to store information: %s", error->message);
		g_error_free(error);
		g_assert(0);
	}

	g_free(data);
}
Exemple #17
0
static void
write_or_die (const gchar *filename,
	      const gchar *contents,
	      gssize       length)
{
  GError *error = NULL;
  gchar *displayname;    

  if (!g_file_set_contents (filename, contents, length, &error)) 
    {
      displayname = g_filename_display_name (childname);
      g_print ("failed to write '%s': %s\n", 
	       displayname, error->message);
      exit (1);
    }
}
Exemple #18
0
void
remmina_pref_set_value (const gchar *key, const gchar *value)
{
    GKeyFile *gkeyfile;
    gchar *content;
    gsize length;

    gkeyfile = g_key_file_new ();
    g_key_file_load_from_file (gkeyfile, remmina_pref_file, G_KEY_FILE_NONE, NULL);
    g_key_file_set_string (gkeyfile, "remmina_pref", key, value);
    content = g_key_file_to_data (gkeyfile, &length, NULL);
    g_file_set_contents (remmina_pref_file, content, length, NULL);

    g_key_file_free (gkeyfile);
    g_free (content);
}
Exemple #19
0
gboolean json_gobject_to_file(GObject * object, const gchar *filename)
{
	gchar *data;
	gsize length;
	data = json_gobject_to_data(object, &length);
	if (!data)
		return FALSE;

	GError *error = NULL;
	gboolean ret = g_file_set_contents(filename, data, length, &error);
	g_free(data);
	if (!ret)
		return FALSE;

	return ret;
}
Exemple #20
0
static void
_load_pattern_db_from_string(const gchar *pdb)
{
  patterndb = pattern_db_new();
  messages = g_ptr_array_new();

  pattern_db_set_emit_func(patterndb, _emit_func, NULL);

  g_file_open_tmp("patterndbXXXXXX.xml", &filename, NULL);
  g_file_set_contents(filename, pdb, strlen(pdb), NULL);
  
  assert_pdb_file_valid(filename, pdb);

  assert_true(pattern_db_reload_ruleset(patterndb, configuration, filename), "Error loading ruleset [[[%s]]]", pdb);
  assert_string(pattern_db_get_ruleset_pub_date(patterndb), "2010-02-22", "Invalid pubdate");
}
static void
store_default (GkdSecretService *self)
{
	GError *error = NULL;
	const gchar *identifier;
	gchar *path;

	identifier = g_hash_table_lookup (self->aliases, "default");
	if (!identifier)
		return;

	path = default_path (self);
	if (!g_file_set_contents (path, identifier, -1, &error))
		g_message ("couldn't store default keyring: %s", egg_error_message (error));
	g_free (path);
}
Exemple #22
0
static gint create_pid_file ()
{
        gchar *pid;
        GError *err = NULL;

        pid = g_strdup_printf ("%d", getpid ());
        if (!g_file_set_contents (PID_FILE, pid, strlen (pid), &err)) {
                GST_ERROR ("write pid %s failure: %s\n", PID_FILE, err->message);
                g_error_free (err);
                g_free (pid);
                return 1;
        }
        g_free (pid);

        return 0;
}
Exemple #23
0
static void
_save_settings(void)
{
    gsize g_data_size;
    gchar *g_data = g_key_file_to_data(settings, &g_data_size, NULL);

    char *fileloc = files_get_data_path(FILE_PLUGIN_SETTINGS);
    gchar *base = g_path_get_basename(fileloc);
    gchar *true_loc = get_file_or_linked(fileloc, base);
    g_free(base);
    g_file_set_contents(true_loc, g_data, g_data_size, NULL);
    free(true_loc);
    g_free(g_data);
    g_chmod(fileloc, S_IRUSR | S_IWUSR);
    free(fileloc);
}
Exemple #24
0
static void
_save_accounts(void)
{
    gsize g_data_size;
    gchar *g_accounts_data = g_key_file_to_data(accounts, &g_data_size, NULL);
    gchar *xdg_data = xdg_get_data_home();
    GString *base_str = g_string_new(xdg_data);
    g_string_append(base_str, "/profanity/");
    gchar *true_loc = get_file_or_linked(accounts_loc, base_str->str);
    g_file_set_contents(true_loc, g_accounts_data, g_data_size, NULL);
    g_chmod(accounts_loc, S_IRUSR | S_IWUSR);
    g_free(xdg_data);
    free(true_loc);
    g_free(g_accounts_data);
    g_string_free(base_str, TRUE);
}
Exemple #25
0
static void
save_key_file (const char *filename, GKeyFile *key_file)
{
  char *contents;
  gsize length;

  /* NULL GError */
  contents = g_key_file_to_data (key_file, &length, NULL);
  if (!contents)
    return;

  /* NULL GError */
  g_file_set_contents (filename, contents, length, NULL);

  g_free (contents);
}
Exemple #26
0
void template_create_file (GuTemplate* t, gchar* filename, gchar* text) {
    const char* filepath = g_build_filename (g_get_user_config_dir (),
            "gummi", "templates", filename, NULL);

    if (g_file_test (filepath, G_FILE_TEST_EXISTS)) {
        gtk_label_set_text (t->template_label, "filename already exists");
        template_remove_entry (t);
    }
    else {
        g_file_set_contents (filepath, text, strlen (text), NULL);
    }
    g_object_set (t->template_render, "editable", FALSE, NULL);
    gtk_widget_set_sensitive (t->template_add, TRUE);
    gtk_widget_set_sensitive (t->template_remove, TRUE);
    gtk_widget_set_sensitive (t->template_open, TRUE);
}
static gboolean
save_event(struct namespace_data_s *ns_data, gridcluster_event_t *e, GError **error)
{
	time_t old_timestamp = 0L;
	gchar *path, *ueid;
	gboolean rc;
	GByteArray *encoded = NULL;

	encoded = gridcluster_encode_event(e, error);
	if (!encoded) {
		GSETERROR(error, "Serialisation error");
		return FALSE;
	}
	
	if (0 != g_mkdir_with_parents(ns_data->queues.dir_incoming, event_directory_mode)) {
		GSETERROR(error, "mkdir(%s) error", ns_data->queues.dir_incoming);
		g_byte_array_free(encoded, TRUE);
		return FALSE;
	}

	path = path_get_from_event_aggrname(e, ns_data->queues.dir_incoming);
	ueid = ueid_get_from_event(e);

	/* get the previous timestamp and unlink the previous file */
	old_timestamp = event_get_timestamp(path, NULL);
	if (0 == unlink(path))
		DEBUG("Unlinked a previous event at [%s]", path);

	if (!(rc = g_file_set_contents(path, (gchar*)encoded->data, encoded->len, error)))
		GSETERROR(error,"Failed to write the serialized event UEID[%s] at [%s]", ueid, path);
	else {
		gboolean xattr_rc;

		xattr_rc = event_set_timestamp(path, old_timestamp ? old_timestamp : time(0));
		g_chmod(path, event_file_mode);

		INFO("Incoming event UEID[%s] saved at [%s] (%s : %s)", ueid, path,
			(xattr_rc ? "xattr timestamp set" : "xattr timestamp not set"),
			strerror(errno));
	}

	g_byte_array_free(encoded, TRUE);
	g_free(path);
	g_free(ueid);
	return rc;
	
}
/*
 * @param config : the key to be set
 * @param setting : The value to be set
 */
set_config_result_t set_network_setting(const char *config, const char *setting)
{
  GKeyFile *settingsfile;
  gboolean test = FALSE;
  gchar *keyfile;

  if(!strcmp(config, NETWORK_IP_KEY) || !strcmp(config, NETWORK_GATEWAY_KEY))
	if(validate_ip(setting) != 0)
		return SET_CONFIG_ERROR;

  settingsfile = g_key_file_new();
  test = g_key_file_load_from_file(settingsfile, FS_MOUNT_CONFIG_FILE, G_KEY_FILE_NONE, NULL);

  if(!strcmp(config, NETWORK_IP_KEY) || !strcmp(config, NETWORK_INTERFACE_KEY) || !strcmp(config, NETWORK_GATEWAY_KEY))
  {
	set_config_result_t ret = SET_CONFIG_ERROR;
	if (test)
	{
		if(config_value_changed(settingsfile, NETWORK_ENTRY, config, setting))
		{
			g_key_file_free(settingsfile);
			return SET_CONFIG_UNCHANGED;
		}
	}
	else
	{
		log_debug("No conffile. Creating.\n");
		create_conf_file();
	}

	g_key_file_set_string(settingsfile, NETWORK_ENTRY, config, setting);
  	keyfile = g_key_file_to_data (settingsfile, NULL, NULL); 
  	/* free the settingsfile before writing things out to be sure 
     	the contents will be correctly written to file afterwards.
     	Just a precaution. */
  	g_key_file_free(settingsfile);
	if (g_file_set_contents(FS_MOUNT_CONFIG_FILE, keyfile, -1, NULL))
		ret = SET_CONFIG_UPDATED;
	free(keyfile);
	return ret;
  }
  else
  {
	g_key_file_free(settingsfile);
	return SET_CONFIG_ERROR;
  }
}
DLLIMPORT bool stardict_misc_plugin_init(void)
{
	std::string res = get_cfg_filename();
	if (!g_file_test(res.c_str(), G_FILE_TEST_EXISTS)) {
		g_file_set_contents(res.c_str(), "[update]\nlatest_version_num=0\nlast_prompt_num=0\nversion_msg_title=\nversion_msg_content=\nlatest_news=\n[misc]\nshow_ads=true\n", -1, NULL);
	}
	GKeyFile *keyfile = g_key_file_new();
	g_key_file_load_from_file(keyfile, res.c_str(), G_KEY_FILE_NONE, NULL);
	GError *err;
	err = NULL;
	latest_version_num = g_key_file_get_integer(keyfile, "update", "latest_version_num", &err);
	if (err) {
		g_error_free (err);
		latest_version_num = 0;
	}
	err = NULL;
	last_prompt_num = g_key_file_get_integer(keyfile, "update", "last_prompt_num", &err);
	if (err) {
		g_error_free (err);
		last_prompt_num = 0;
	}
	char *str;
	str = g_key_file_get_string(keyfile, "update", "version_msg_title", NULL);
	if (str) {
		version_msg_title = str;
		g_free(str);
	}
	str = g_key_file_get_string(keyfile, "update", "version_msg_content", NULL);
	if (str) {
		version_msg_content = str;
		g_free(str);
	}
	str = g_key_file_get_string(keyfile, "update", "latest_news", NULL);
	if (str) {
		latest_news = str;
		g_free(str);
	}
	err = NULL;
	show_ads = g_key_file_get_boolean(keyfile, "misc", "show_ads", &err);
	if (err) {
		g_error_free (err);
		show_ads = true;
	}
	g_key_file_free(keyfile);
	g_print(_("Update info plug-in loaded.\n"));
	return false;
}
Exemple #30
0
void save_settings(Preferences *pref)
{
	gchar *path;
	gchar *dir;
	GKeyFile* key;
	GError *err = NULL;
	gchar *data;
	gsize data_len = 0;
	GtkWidget *dialog;

	path = get_config_path();
	dir = g_dirname(path);
	
	key = g_key_file_new();
	g_key_file_load_from_file(key, path, G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS, NULL);
	
	g_key_file_set_integer(key, "core", "backend", pref->backend);
	g_key_file_set_string(key, "core", "download_dir", pref->download_dir);
	g_key_file_set_integer(key, "core", "max_concurrent_downloads", pref->max_concurrent_downloads);
	g_key_file_set_boolean(key, "core", "use_schedule", pref->use_schedule);
	g_key_file_set_integer(key, "core", "start_time_hour", pref->start_time_hour);
	g_key_file_set_integer(key, "core", "start_time_minute", pref->start_time_minute);
	g_key_file_set_integer(key, "core", "end_time_hour", pref->end_time_hour);
	g_key_file_set_integer(key, "core", "end_time_minute", pref->end_time_minute);
	
	data = g_key_file_to_data(key, &data_len, &err);
	if (err) {
		dialog = gtk_message_dialog_new (GTK_WINDOW(g_GAria2),
                                  GTK_DIALOG_DESTROY_WITH_PARENT,
                                  GTK_MESSAGE_ERROR,
                                  GTK_BUTTONS_CLOSE,
                                  "Error: %s", err->message);
 		gtk_dialog_run (GTK_DIALOG (dialog));
 		gtk_widget_destroy (dialog);
		g_error_free(err);
	}
	
	if (!g_file_test(dir, G_FILE_TEST_EXISTS)) {
		g_mkdir_with_parents(dir, 0700);
	}
	g_file_set_contents(path, data, data_len, NULL);
	
	g_free(data);
	g_free(path);
	g_free(dir);
	g_key_file_free(key);
}