2010-12-29 18:12:59 +03:00
|
|
|
/*
|
|
|
|
paths to configuration files
|
|
|
|
|
2018-01-01 09:54:11 +03:00
|
|
|
Copyright (C) 2010-2018
|
2014-02-12 10:33:10 +04:00
|
|
|
Free Software Foundation, Inc.
|
2010-12-29 18:12:59 +03:00
|
|
|
|
|
|
|
Written by:
|
|
|
|
Slava Zanko <slavazanko@gmail.com>, 2010.
|
|
|
|
|
|
|
|
This file is part of the Midnight Commander.
|
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander is free software: you can redistribute it
|
2010-12-29 18:12:59 +03:00
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
2011-10-15 14:56:47 +04:00
|
|
|
published by the Free Software Foundation, either version 3 of the License,
|
|
|
|
or (at your option) any later version.
|
2010-12-29 18:12:59 +03:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander 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.
|
2010-12-29 18:12:59 +03:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2011-10-15 14:56:47 +04:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-12-29 18:12:59 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2011-12-05 18:52:46 +04:00
|
|
|
#include <stdlib.h>
|
2010-12-29 18:12:59 +03:00
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "lib/global.h"
|
|
|
|
#include "lib/fileloc.h"
|
2011-02-15 16:44:17 +03:00
|
|
|
#include "lib/vfs/vfs.h"
|
2011-10-15 14:56:47 +04:00
|
|
|
#include "lib/util.h" /* unix_error_string() */
|
2011-07-07 10:36:56 +04:00
|
|
|
|
|
|
|
#include "lib/mcconfig.h"
|
2010-12-29 18:12:59 +03:00
|
|
|
|
|
|
|
/*** global variables ****************************************************************************/
|
|
|
|
|
|
|
|
/*** file scope macro definitions ****************************************************************/
|
|
|
|
|
2011-11-07 18:24:23 +04:00
|
|
|
#define MC_OLD_USERCONF_DIR ".mc"
|
|
|
|
|
2010-12-29 18:12:59 +03:00
|
|
|
/*** file scope type declarations ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
|
|
|
static gboolean xdg_vars_initialized = FALSE;
|
2011-11-07 18:24:23 +04:00
|
|
|
static char *mc_config_str = NULL;
|
|
|
|
static char *mc_cache_str = NULL;
|
|
|
|
static char *mc_data_str = NULL;
|
2010-12-29 18:12:59 +03:00
|
|
|
|
|
|
|
static gboolean config_dir_present = FALSE;
|
|
|
|
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const char *old_filename;
|
|
|
|
|
|
|
|
char **new_basedir;
|
|
|
|
const char *new_filename;
|
2011-11-24 02:28:07 +04:00
|
|
|
} mc_config_files_reference[] =
|
2010-12-29 18:12:59 +03:00
|
|
|
{
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
/* config */
|
2011-11-07 18:24:23 +04:00
|
|
|
{ "ini", &mc_config_str, MC_CONFIG_FILE},
|
|
|
|
{ "filehighlight.ini", &mc_config_str, MC_FHL_INI_FILE},
|
2017-02-24 23:32:01 +03:00
|
|
|
{ "hotlist", &mc_config_str, MC_HOTLIST_FILE},
|
2011-11-07 18:24:23 +04:00
|
|
|
{ "mc.keymap", &mc_config_str, GLOBAL_KEYMAP_FILE},
|
2011-11-07 19:01:42 +04:00
|
|
|
{ "menu", &mc_config_str, MC_USERMENU_FILE},
|
|
|
|
{ "cedit" PATH_SEP_STR "Syntax", &mc_config_str, EDIT_SYNTAX_FILE},
|
|
|
|
{ "cedit" PATH_SEP_STR "menu", &mc_config_str, EDIT_HOME_MENU},
|
|
|
|
{ "cedit" PATH_SEP_STR "edit.indent.rc", &mc_config_str, EDIT_DIR PATH_SEP_STR "edit.indent.rc"},
|
|
|
|
{ "cedit" PATH_SEP_STR "edit.spell.rc", &mc_config_str, EDIT_DIR PATH_SEP_STR "edit.spell.rc"},
|
|
|
|
{ "panels.ini", &mc_config_str, MC_PANELS_FILE},
|
2011-11-24 02:28:07 +04:00
|
|
|
|
2011-11-07 19:01:42 +04:00
|
|
|
/* User should move this file with applying some changes in file */
|
2011-11-24 02:28:07 +04:00
|
|
|
{ "", &mc_config_str, MC_FILEBIND_FILE},
|
2010-12-29 18:12:59 +03:00
|
|
|
|
|
|
|
/* data */
|
2011-11-07 18:24:23 +04:00
|
|
|
{ "skins", &mc_data_str, MC_SKINS_SUBDIR},
|
|
|
|
{ "fish", &mc_data_str, FISH_PREFIX},
|
2013-09-02 20:00:53 +04:00
|
|
|
{ "ashrc", &mc_data_str, "ashrc"},
|
2011-11-07 18:24:23 +04:00
|
|
|
{ "bashrc", &mc_data_str, "bashrc"},
|
|
|
|
{ "inputrc", &mc_data_str, "inputrc"},
|
|
|
|
{ "extfs.d", &mc_data_str, MC_EXTFS_DIR},
|
2011-11-07 19:01:42 +04:00
|
|
|
{ "history", &mc_data_str, MC_HISTORY_FILE},
|
|
|
|
{ "filepos", &mc_data_str, MC_FILEPOS_FILE},
|
|
|
|
{ "cedit" PATH_SEP_STR "cooledit.clip", &mc_data_str, EDIT_CLIP_FILE},
|
2011-11-24 02:28:07 +04:00
|
|
|
{ "", &mc_data_str, MC_MACRO_FILE},
|
2010-12-29 18:12:59 +03:00
|
|
|
|
|
|
|
/* cache */
|
2011-11-07 18:24:23 +04:00
|
|
|
{ "log", &mc_cache_str, "mc.log"},
|
|
|
|
{ "Tree", &mc_cache_str, MC_TREESTORE_FILE},
|
|
|
|
{ "cedit" PATH_SEP_STR "cooledit.temp", &mc_cache_str, EDIT_TEMP_FILE},
|
|
|
|
{ "cedit" PATH_SEP_STR "cooledit.block", &mc_cache_str, EDIT_BLOCK_FILE},
|
2010-12-29 18:12:59 +03:00
|
|
|
|
|
|
|
{NULL, NULL, NULL}
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
};
|
|
|
|
|
2015-04-05 08:50:45 +03:00
|
|
|
#if MC_HOMEDIR_XDG
|
2011-11-07 19:01:42 +04:00
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
char **old_basedir;
|
2011-12-02 14:25:30 +04:00
|
|
|
const char *filename;
|
2011-11-07 19:01:42 +04:00
|
|
|
|
|
|
|
char **new_basedir;
|
|
|
|
} mc_config_migrate_rules_fix[] =
|
|
|
|
{
|
|
|
|
/* *INDENT-OFF* */
|
2011-12-02 14:25:30 +04:00
|
|
|
{ &mc_data_str, MC_USERMENU_FILE, &mc_config_str},
|
|
|
|
{ &mc_data_str, EDIT_SYNTAX_FILE, &mc_config_str},
|
|
|
|
{ &mc_data_str, EDIT_HOME_MENU, &mc_config_str},
|
|
|
|
{ &mc_data_str, EDIT_DIR PATH_SEP_STR "edit.indent.rc", &mc_config_str},
|
|
|
|
{ &mc_data_str, EDIT_DIR PATH_SEP_STR "edit.spell.rc", &mc_config_str},
|
|
|
|
{ &mc_data_str, MC_FILEBIND_FILE, &mc_config_str},
|
2011-11-07 19:01:42 +04:00
|
|
|
|
2011-12-02 14:25:30 +04:00
|
|
|
{ &mc_cache_str, MC_HISTORY_FILE, &mc_data_str},
|
|
|
|
{ &mc_cache_str, MC_FILEPOS_FILE, &mc_data_str},
|
|
|
|
{ &mc_cache_str, EDIT_CLIP_FILE, &mc_data_str},
|
2011-11-07 19:01:42 +04:00
|
|
|
|
2011-12-02 14:25:30 +04:00
|
|
|
{ &mc_cache_str, MC_PANELS_FILE, &mc_config_str},
|
2011-11-07 19:01:42 +04:00
|
|
|
|
2011-12-02 14:25:30 +04:00
|
|
|
{NULL, NULL, NULL}
|
2011-11-07 19:01:42 +04:00
|
|
|
/* *INDENT-ON* */
|
|
|
|
};
|
2011-12-02 14:25:30 +04:00
|
|
|
#endif /* MC_HOMEDIR_XDG */
|
2011-11-07 19:01:42 +04:00
|
|
|
|
2010-12-29 18:12:59 +03:00
|
|
|
/*** file scope functions *********************************************************************** */
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_config_mkdir (const char *directory_name, GError ** mcerror)
|
2010-12-29 18:12:59 +03:00
|
|
|
{
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_return_if_error (mcerror);
|
|
|
|
|
2010-12-29 18:12:59 +03:00
|
|
|
if ((!g_file_test (directory_name, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) &&
|
|
|
|
(g_mkdir_with_parents (directory_name, 0700) != 0))
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_propagate_error (mcerror, 0, _("Cannot create %s directory"), directory_name);
|
2010-12-29 18:12:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static char *
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_config_init_one_config_path (const char *path_base, const char *subdir, GError ** mcerror)
|
2010-12-29 18:12:59 +03:00
|
|
|
{
|
|
|
|
char *full_path;
|
|
|
|
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_return_val_if_error (mcerror, FALSE);
|
2010-12-29 18:12:59 +03:00
|
|
|
|
2016-03-25 21:33:44 +03:00
|
|
|
full_path = g_build_filename (path_base, subdir, (char *) NULL);
|
2011-12-05 18:52:46 +04:00
|
|
|
if (g_file_test (full_path, G_FILE_TEST_EXISTS))
|
|
|
|
{
|
|
|
|
if (g_file_test (full_path, G_FILE_TEST_IS_DIR))
|
|
|
|
{
|
|
|
|
config_dir_present = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf (stderr, "%s %s\n", _("FATAL: not a directory:"), full_path);
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
2010-12-29 18:12:59 +03:00
|
|
|
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_config_mkdir (full_path, mcerror);
|
|
|
|
if (mcerror != NULL && *mcerror != NULL)
|
2014-08-05 11:18:30 +04:00
|
|
|
MC_PTR_FREE (full_path);
|
|
|
|
|
2010-12-29 18:12:59 +03:00
|
|
|
return full_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static char *
|
|
|
|
mc_config_get_deprecated_path (void)
|
|
|
|
{
|
2016-03-25 21:33:44 +03:00
|
|
|
return g_build_filename (mc_config_get_home_dir (), MC_OLD_USERCONF_DIR, (char *) NULL);
|
2010-12-29 18:12:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_config_copy (const char *old_name, const char *new_name, GError ** mcerror)
|
2010-12-29 18:12:59 +03:00
|
|
|
{
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_return_if_error (mcerror);
|
|
|
|
|
2011-07-06 18:07:18 +04:00
|
|
|
if (g_file_test (old_name, G_FILE_TEST_IS_REGULAR))
|
2010-12-29 18:12:59 +03:00
|
|
|
{
|
|
|
|
char *contents = NULL;
|
|
|
|
size_t length;
|
|
|
|
|
2014-07-15 16:53:06 +04:00
|
|
|
if (g_file_get_contents (old_name, &contents, &length, mcerror))
|
|
|
|
g_file_set_contents (new_name, contents, length, mcerror);
|
2010-12-29 18:12:59 +03:00
|
|
|
|
|
|
|
g_free (contents);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-06 18:07:18 +04:00
|
|
|
if (g_file_test (old_name, G_FILE_TEST_IS_DIR))
|
2010-12-29 18:12:59 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
GDir *dir;
|
|
|
|
const char *dir_name;
|
|
|
|
|
2014-07-15 16:53:06 +04:00
|
|
|
dir = g_dir_open (old_name, 0, mcerror);
|
2010-12-29 18:12:59 +03:00
|
|
|
if (dir == NULL)
|
|
|
|
return;
|
|
|
|
|
2011-07-06 18:07:18 +04:00
|
|
|
if (g_mkdir_with_parents (new_name, 0700) == -1)
|
2010-12-29 18:12:59 +03:00
|
|
|
{
|
|
|
|
g_dir_close (dir);
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_propagate_error (mcerror, 0,
|
|
|
|
_("An error occurred while migrating user settings: %s"),
|
|
|
|
unix_error_string (errno));
|
2010-12-29 18:12:59 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((dir_name = g_dir_read_name (dir)) != NULL)
|
|
|
|
{
|
|
|
|
char *old_name2, *new_name2;
|
2011-07-07 10:36:56 +04:00
|
|
|
|
2016-03-25 21:33:44 +03:00
|
|
|
old_name2 = g_build_filename (old_name, dir_name, (char *) NULL);
|
|
|
|
new_name2 = g_build_filename (new_name, dir_name, (char *) NULL);
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_config_copy (old_name2, new_name2, mcerror);
|
2010-12-29 18:12:59 +03:00
|
|
|
g_free (new_name2);
|
|
|
|
g_free (old_name2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-07 19:01:42 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2011-12-02 00:04:05 +04:00
|
|
|
#if MC_HOMEDIR_XDG
|
2011-11-07 19:01:42 +04:00
|
|
|
static void
|
|
|
|
mc_config_fix_migrated_rules (void)
|
|
|
|
{
|
|
|
|
size_t rule_index;
|
|
|
|
|
|
|
|
for (rule_index = 0; mc_config_migrate_rules_fix[rule_index].old_basedir != NULL; rule_index++)
|
|
|
|
{
|
|
|
|
char *old_name;
|
|
|
|
|
|
|
|
old_name =
|
|
|
|
g_build_filename (*mc_config_migrate_rules_fix[rule_index].old_basedir,
|
2016-03-25 21:33:44 +03:00
|
|
|
mc_config_migrate_rules_fix[rule_index].filename, (char *) NULL);
|
2011-11-07 19:01:42 +04:00
|
|
|
|
|
|
|
if (g_file_test (old_name, G_FILE_TEST_EXISTS))
|
|
|
|
{
|
|
|
|
char *new_name;
|
2011-12-02 14:25:30 +04:00
|
|
|
const char *basedir = *mc_config_migrate_rules_fix[rule_index].new_basedir;
|
|
|
|
const char *filename = mc_config_migrate_rules_fix[rule_index].filename;
|
2011-11-07 19:01:42 +04:00
|
|
|
|
2016-03-25 21:33:44 +03:00
|
|
|
new_name = g_build_filename (basedir, filename, (char *) NULL);
|
2011-11-07 19:01:42 +04:00
|
|
|
rename (old_name, new_name);
|
|
|
|
g_free (new_name);
|
|
|
|
}
|
|
|
|
g_free (old_name);
|
|
|
|
}
|
|
|
|
}
|
2011-12-02 00:04:05 +04:00
|
|
|
#endif /* MC_HOMEDIR_XDG */
|
2011-11-07 19:01:42 +04:00
|
|
|
|
2012-10-30 16:15:33 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
mc_config_deprecated_dir_present (void)
|
|
|
|
{
|
|
|
|
char *old_dir;
|
|
|
|
gboolean is_present;
|
|
|
|
|
|
|
|
old_dir = mc_config_get_deprecated_path ();
|
|
|
|
is_present = g_file_test (old_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR);
|
|
|
|
g_free (old_dir);
|
|
|
|
|
|
|
|
return is_present && !config_dir_present;
|
|
|
|
}
|
|
|
|
|
2010-12-29 18:12:59 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_config_init_config_paths (GError ** mcerror)
|
2010-12-29 18:12:59 +03:00
|
|
|
{
|
2016-12-01 12:00:33 +03:00
|
|
|
const char *profile_root;
|
2012-03-16 14:53:34 +04:00
|
|
|
char *dir;
|
2015-04-05 08:50:45 +03:00
|
|
|
#if MC_HOMEDIR_XDG == 0
|
2015-03-31 20:27:07 +03:00
|
|
|
char *defined_userconf_dir;
|
|
|
|
#endif
|
2010-12-29 18:12:59 +03:00
|
|
|
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_return_if_error (mcerror);
|
|
|
|
|
2010-12-29 18:12:59 +03:00
|
|
|
if (xdg_vars_initialized)
|
|
|
|
return;
|
|
|
|
|
2016-12-01 12:00:33 +03:00
|
|
|
profile_root = mc_get_profile_root ();
|
|
|
|
|
2015-04-05 08:50:45 +03:00
|
|
|
#if MC_HOMEDIR_XDG
|
2016-12-01 12:00:33 +03:00
|
|
|
if (strcmp (profile_root, mc_config_get_home_dir ()) != 0)
|
2012-03-29 13:50:45 +04:00
|
|
|
{
|
2016-09-08 17:02:43 +03:00
|
|
|
/*
|
|
|
|
* The user overrode the default profile root.
|
|
|
|
*
|
|
|
|
* In this case we can't use GLib's g_get_user_{config,cache,data}_dir()
|
|
|
|
* as these functions use the user's home dir as the root.
|
|
|
|
*/
|
|
|
|
|
|
|
|
dir = g_build_filename (profile_root, ".config", (char *) NULL);
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_config_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror);
|
2012-03-29 13:50:45 +04:00
|
|
|
g_free (dir);
|
2010-12-29 18:12:59 +03:00
|
|
|
|
2016-09-08 17:02:43 +03:00
|
|
|
dir = g_build_filename (profile_root, ".cache", (char *) NULL);
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_cache_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror);
|
2012-03-29 13:50:45 +04:00
|
|
|
g_free (dir);
|
2010-12-29 18:12:59 +03:00
|
|
|
|
2016-09-08 17:02:43 +03:00
|
|
|
dir = g_build_filename (profile_root, ".local", "share", (char *) NULL);
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_data_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror);
|
2012-03-29 13:50:45 +04:00
|
|
|
g_free (dir);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-08 00:51:20 +03:00
|
|
|
mc_config_str =
|
|
|
|
mc_config_init_one_config_path (g_get_user_config_dir (), MC_USERCONF_DIR, mcerror);
|
|
|
|
mc_cache_str =
|
|
|
|
mc_config_init_one_config_path (g_get_user_cache_dir (), MC_USERCONF_DIR, mcerror);
|
|
|
|
mc_data_str =
|
|
|
|
mc_config_init_one_config_path (g_get_user_data_dir (), MC_USERCONF_DIR, mcerror);
|
2012-03-29 13:50:45 +04:00
|
|
|
}
|
2011-02-16 15:23:29 +03:00
|
|
|
|
2011-11-07 19:01:42 +04:00
|
|
|
mc_config_fix_migrated_rules ();
|
2011-11-07 18:24:23 +04:00
|
|
|
#else /* MC_HOMEDIR_XDG */
|
2011-12-10 00:19:37 +04:00
|
|
|
defined_userconf_dir = tilde_expand (MC_USERCONF_DIR);
|
2012-03-16 14:53:34 +04:00
|
|
|
if (g_path_is_absolute (defined_userconf_dir))
|
|
|
|
dir = defined_userconf_dir;
|
|
|
|
else
|
2011-12-10 00:19:37 +04:00
|
|
|
{
|
|
|
|
g_free (defined_userconf_dir);
|
2016-12-01 12:00:33 +03:00
|
|
|
dir = g_build_filename (profile_root, MC_USERCONF_DIR, (char *) NULL);
|
2011-12-10 00:19:37 +04:00
|
|
|
}
|
2011-11-07 18:24:23 +04:00
|
|
|
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_data_str = mc_cache_str = mc_config_str = mc_config_init_one_config_path (dir, "", mcerror);
|
2011-11-07 18:24:23 +04:00
|
|
|
|
2012-03-16 14:53:34 +04:00
|
|
|
g_free (dir);
|
2011-11-07 18:24:23 +04:00
|
|
|
#endif /* MC_HOMEDIR_XDG */
|
|
|
|
|
2010-12-29 18:12:59 +03:00
|
|
|
xdg_vars_initialized = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void
|
|
|
|
mc_config_deinit_config_paths (void)
|
|
|
|
{
|
|
|
|
if (!xdg_vars_initialized)
|
|
|
|
return;
|
|
|
|
|
2011-11-07 18:24:23 +04:00
|
|
|
g_free (mc_config_str);
|
2015-04-05 08:50:45 +03:00
|
|
|
#if MC_HOMEDIR_XDG
|
2011-11-07 18:24:23 +04:00
|
|
|
g_free (mc_cache_str);
|
|
|
|
g_free (mc_data_str);
|
|
|
|
#endif /* MC_HOMEDIR_XDG */
|
2010-12-29 18:12:59 +03:00
|
|
|
|
2011-02-16 15:23:29 +03:00
|
|
|
g_free (mc_global.share_data_dir);
|
|
|
|
g_free (mc_global.sysconfig_dir);
|
|
|
|
|
2010-12-29 18:12:59 +03:00
|
|
|
xdg_vars_initialized = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
const char *
|
|
|
|
mc_config_get_data_path (void)
|
|
|
|
{
|
|
|
|
if (!xdg_vars_initialized)
|
|
|
|
mc_config_init_config_paths (NULL);
|
|
|
|
|
2011-11-07 18:24:23 +04:00
|
|
|
return (const char *) mc_data_str;
|
2010-12-29 18:12:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
const char *
|
|
|
|
mc_config_get_cache_path (void)
|
|
|
|
{
|
|
|
|
if (!xdg_vars_initialized)
|
|
|
|
mc_config_init_config_paths (NULL);
|
|
|
|
|
2011-11-07 18:24:23 +04:00
|
|
|
return (const char *) mc_cache_str;
|
2010-12-29 18:12:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
const char *
|
|
|
|
mc_config_get_home_dir (void)
|
|
|
|
{
|
2016-09-08 17:07:27 +03:00
|
|
|
static const char *homedir = NULL;
|
|
|
|
|
2010-12-29 18:12:59 +03:00
|
|
|
if (homedir == NULL)
|
|
|
|
{
|
2016-09-08 00:51:20 +03:00
|
|
|
/* Prior to GLib 2.36, g_get_home_dir() ignores $HOME, which is why
|
|
|
|
* we read it ourselves. As that function's documentation explains,
|
|
|
|
* using $HOME is good for compatibility with other programs and
|
|
|
|
* for running from test frameworks. */
|
2016-09-08 17:02:43 +03:00
|
|
|
homedir = g_getenv ("HOME");
|
2012-03-16 14:53:34 +04:00
|
|
|
if (homedir == NULL || *homedir == '\0')
|
2010-12-29 18:12:59 +03:00
|
|
|
homedir = g_get_home_dir ();
|
|
|
|
}
|
|
|
|
return homedir;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
const char *
|
|
|
|
mc_config_get_path (void)
|
|
|
|
{
|
|
|
|
if (!xdg_vars_initialized)
|
|
|
|
mc_config_init_config_paths (NULL);
|
|
|
|
|
2011-11-07 18:24:23 +04:00
|
|
|
return (const char *) mc_config_str;
|
2010-12-29 18:12:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2012-10-30 16:15:33 +04:00
|
|
|
gboolean
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_config_migrate_from_old_place (GError ** mcerror, char **msg)
|
2010-12-29 18:12:59 +03:00
|
|
|
{
|
2011-07-07 10:36:56 +04:00
|
|
|
char *old_dir;
|
2010-12-29 18:12:59 +03:00
|
|
|
size_t rule_index;
|
|
|
|
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_return_val_if_error (mcerror, FALSE);
|
|
|
|
|
2012-10-30 16:15:33 +04:00
|
|
|
if (!mc_config_deprecated_dir_present ())
|
|
|
|
return FALSE;
|
|
|
|
|
2010-12-29 18:12:59 +03:00
|
|
|
old_dir = mc_config_get_deprecated_path ();
|
|
|
|
|
2014-07-15 16:53:06 +04:00
|
|
|
g_free (mc_config_init_one_config_path (mc_config_str, EDIT_DIR, mcerror));
|
2015-04-05 08:50:45 +03:00
|
|
|
#if MC_HOMEDIR_XDG
|
2014-07-15 16:53:06 +04:00
|
|
|
g_free (mc_config_init_one_config_path (mc_cache_str, EDIT_DIR, mcerror));
|
|
|
|
g_free (mc_config_init_one_config_path (mc_data_str, EDIT_DIR, mcerror));
|
2011-11-07 18:24:23 +04:00
|
|
|
#endif /* MC_HOMEDIR_XDG */
|
2010-12-29 18:12:59 +03:00
|
|
|
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_return_val_if_error (mcerror, FALSE);
|
2012-10-30 16:15:33 +04:00
|
|
|
|
2011-11-24 02:28:07 +04:00
|
|
|
for (rule_index = 0; mc_config_files_reference[rule_index].old_filename != NULL; rule_index++)
|
2010-12-29 18:12:59 +03:00
|
|
|
{
|
2011-07-07 10:36:56 +04:00
|
|
|
char *old_name;
|
2011-11-24 02:28:07 +04:00
|
|
|
if (*mc_config_files_reference[rule_index].old_filename == '\0')
|
|
|
|
continue;
|
2010-12-29 18:12:59 +03:00
|
|
|
|
|
|
|
old_name =
|
2016-03-25 21:33:44 +03:00
|
|
|
g_build_filename (old_dir, mc_config_files_reference[rule_index].old_filename,
|
|
|
|
(char *) NULL);
|
2010-12-29 18:12:59 +03:00
|
|
|
|
2011-07-07 10:36:56 +04:00
|
|
|
if (g_file_test (old_name, G_FILE_TEST_EXISTS))
|
2010-12-29 18:12:59 +03:00
|
|
|
{
|
2011-07-07 10:36:56 +04:00
|
|
|
char *new_name;
|
2011-12-02 14:25:30 +04:00
|
|
|
const char *basedir = *mc_config_files_reference[rule_index].new_basedir;
|
|
|
|
const char *filename = mc_config_files_reference[rule_index].new_filename;
|
2010-12-29 18:12:59 +03:00
|
|
|
|
2016-03-25 21:33:44 +03:00
|
|
|
new_name = g_build_filename (basedir, filename, (char *) NULL);
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_config_copy (old_name, new_name, mcerror);
|
2011-07-07 10:36:56 +04:00
|
|
|
g_free (new_name);
|
|
|
|
}
|
2010-12-29 18:12:59 +03:00
|
|
|
g_free (old_name);
|
|
|
|
}
|
2011-07-07 10:36:56 +04:00
|
|
|
|
2015-04-05 08:50:45 +03:00
|
|
|
#if MC_HOMEDIR_XDG
|
2012-10-30 16:15:33 +04:00
|
|
|
*msg = g_strdup_printf (_("Your old settings were migrated from %s\n"
|
|
|
|
"to Freedesktop recommended dirs.\n"
|
|
|
|
"To get more info, please visit\n"
|
|
|
|
"http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html"),
|
2012-11-09 10:35:46 +04:00
|
|
|
old_dir);
|
2011-11-07 18:24:23 +04:00
|
|
|
#else /* MC_HOMEDIR_XDG */
|
2012-10-30 16:15:33 +04:00
|
|
|
*msg = g_strdup_printf (_("Your old settings were migrated from %s\n"
|
|
|
|
"to %s\n"), old_dir, mc_config_str);
|
2011-11-07 18:24:23 +04:00
|
|
|
#endif /* MC_HOMEDIR_XDG */
|
2010-12-29 18:12:59 +03:00
|
|
|
|
|
|
|
g_free (old_dir);
|
2011-07-07 10:36:56 +04:00
|
|
|
|
2012-10-30 16:15:33 +04:00
|
|
|
return TRUE;
|
2010-12-29 18:12:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2011-11-24 02:28:07 +04:00
|
|
|
/**
|
|
|
|
* Get full path to config file by short name.
|
|
|
|
*
|
|
|
|
* @param config_name short name
|
|
|
|
* @return full path to config file
|
|
|
|
*/
|
|
|
|
|
|
|
|
char *
|
|
|
|
mc_config_get_full_path (const char *config_name)
|
|
|
|
{
|
|
|
|
size_t rule_index;
|
|
|
|
|
|
|
|
if (config_name == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2011-12-02 00:04:05 +04:00
|
|
|
if (!xdg_vars_initialized)
|
|
|
|
mc_config_init_config_paths (NULL);
|
|
|
|
|
2011-11-24 02:28:07 +04:00
|
|
|
for (rule_index = 0; mc_config_files_reference[rule_index].old_filename != NULL; rule_index++)
|
|
|
|
{
|
|
|
|
if (strcmp (config_name, mc_config_files_reference[rule_index].new_filename) == 0)
|
|
|
|
{
|
|
|
|
return g_build_filename (*mc_config_files_reference[rule_index].new_basedir,
|
2016-03-25 21:33:44 +03:00
|
|
|
mc_config_files_reference[rule_index].new_filename,
|
|
|
|
(char *) NULL);
|
2011-11-24 02:28:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2011-07-18 01:30:58 +04:00
|
|
|
/**
|
|
|
|
* Get full path to config file by short name.
|
|
|
|
*
|
|
|
|
* @param config_name short name
|
|
|
|
* @return object with full path to config file
|
|
|
|
*/
|
|
|
|
|
|
|
|
vfs_path_t *
|
|
|
|
mc_config_get_full_vpath (const char *config_name)
|
|
|
|
{
|
|
|
|
vfs_path_t *ret_vpath;
|
|
|
|
char *str_path;
|
|
|
|
|
|
|
|
str_path = mc_config_get_full_path (config_name);
|
|
|
|
|
2012-03-29 13:50:45 +04:00
|
|
|
ret_vpath = vfs_path_from_str (str_path);
|
2011-07-18 01:30:58 +04:00
|
|
|
g_free (str_path);
|
|
|
|
return ret_vpath;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|