diff --git a/tilp/trunk/help/chapter07.html b/tilp/trunk/help/chapter07.html
index f874704c..61392476 100644
--- a/tilp/trunk/help/chapter07.html
+++ b/tilp/trunk/help/chapter07.html
@@ -138,15 +138,17 @@
7. Command line
CONFIG FILE FORMAT
- This section describes the format of the .tilp config file which is in
- the home directory of the user (Linux) or the tilp.ini file (Win32).
- The file is separated into several sections (hardware, gui, calc,
- external programs, fonts, screen, misc). But, there is no order, you
- can write lines as you want. A line preceded by the '#' symbol is a
- comment. Each line has the following format: option=something. Every
- line can be put in any order. Beware: any comment added to the file
- will be overwritten ! Below is described each option and the possible
- values:
+ This section describes the format of the tilp.ini config file which is
+ in the configuration directory of the user ($XDG_CONFIG_HOME or
+ LocalAppData on Windows). Note that the configuration used to be
+ located in the user's home directory. This file will be automatically
+ migrated to the new location. The file is separated into several
+ sections (hardware, gui, calc, external programs, fonts, screen, misc).
+ But, there is no order, you can write lines as you want. A line
+ preceded by the '#' symbol is a comment. Each line has the following
+ format: option=something. Every line can be put in any order. Beware:
+ any comment added to the file will be overwritten! Below is described
+ each option and the possible values:
version= Which version of TiLP has written the config file. Used to
display the Release the file and to keep compatibility.
diff --git a/tilp/trunk/man/tilp.1 b/tilp/trunk/man/tilp.1
index 30fc843e..a0754113 100644
--- a/tilp/trunk/man/tilp.1
+++ b/tilp/trunk/man/tilp.1
@@ -73,7 +73,7 @@ Starting at version 1.13, a new and shorter syntax can be used:
tilp ti89 blacklink \-p2 \-t20 \-n group.89g
.SH CONFIG FILE FORMAT
-This section describes the format of the .tilp config file which is in the home directory of the user (*nix, Win32), or the old tilp.ini file formerly stored alongside the program (Win32). The file is separated into several sections (hardware, gui, calc, external programs, fonts, screen, misc).
+This section describes the format of the tilp.ini config file which is in the configuration directory of the user ($XDG_CONFIG_HOME or LocalAppData on windows). The file is separated into several sections (hardware, gui, calc, external programs, fonts, screen, misc).
A line preceded by the '#' symbol is a comment. Each line has the following format: option=something.
Every line can be put in any order. Beware: any comment added to the file will be overwritten!
Here's a description of the options and their possible values:
diff --git a/tilp/trunk/po/de.po b/tilp/trunk/po/de.po
index b5118d6b..4f9b6c1a 100644
--- a/tilp/trunk/po/de.po
+++ b/tilp/trunk/po/de.po
@@ -640,9 +640,9 @@ msgid "The file <%s> does not exist."
msgstr "Die Datei <%s> existiert nich."
#: ../src/tilp_config.c:382
-msgid "Unable to write the config file (~/.tilp or ~/tilp.ini).\n"
+msgid "Unable to write the config file ($XDG_CONFIG_HOME/tilp.ini).\n"
msgstr ""
-"Die Konfigurationsdatei (~/.tilp or tilp.ini) kann nicht geschrieben "
+"Die Konfigurationsdatei ($XDG_CONFIG_HOME/tilp.ini) kann nicht geschrieben "
"werden.\n"
#: ../src/tilp_config.c:544
diff --git a/tilp/trunk/po/fr.po b/tilp/trunk/po/fr.po
index c9888041..30038514 100644
--- a/tilp/trunk/po/fr.po
+++ b/tilp/trunk/po/fr.po
@@ -634,10 +634,10 @@ msgid "The file <%s> does not exist."
msgstr "Le fichier <%s> n'existe pas."
#: ../src/tilp_config.c:382
-msgid "Unable to write the config file (~/.tilp or ~/tilp.ini).\n"
+msgid "Unable to write the config file ($XDG_CONFIG_HOME/tilp.ini).\n"
msgstr ""
-"Impossible d'enregistrer le fichier de configuration (~/.tilp ou ~/tilp."
-"ini).\n"
+"Impossible d'enregistrer le fichier de configuration ($XDG_CONFIG_HOME/"
+"tilp.ini).\n"
#: ../src/tilp_config.c:544
msgid "Configuration file saved."
diff --git a/tilp/trunk/src/tilp_config.c b/tilp/trunk/src/tilp_config.c
index 8d167e9c..eca9627f 100644
--- a/tilp/trunk/src/tilp_config.c
+++ b/tilp/trunk/src/tilp_config.c
@@ -102,90 +102,68 @@ int tilp_config_default(void)
return 0;
}
+static void deprecated_config_path(char* old_ini_file, char* ini_file)
+{
+ int old_exists, new_exists;
+ old_exists = !access(old_ini_file, F_OK);
+ new_exists = !access(ini_file, F_OK);
+
+ if (old_exists && !new_exists)
+ {
+ FILE *in;
+ FILE *out;
+
+ in = fopen(old_ini_file, "rb");
+ out = fopen(ini_file, "wb");
+ if (in && out)
+ {
+ int c;
+ while ((c = fgetc(in)) != EOF)
+ {
+ fputc(c, out);
+ }
+ fclose(out);
+ fclose(in);
+ // A config file now exists at the new location.
+ // Delete the old file.
+ unlink(old_ini_file);
+ }
+ }
+}
+
static char * get_config_path(void)
{
- return g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S, INI_FILE, NULL);
+ return g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), "tilp.ini", NULL);
}
+#if defined(__LINUX__) || defined(__BSD__) || defined(__MACOSX__)
+# define OLD_INI_FILE ".tilp"
+#elif defined(__WIN32__)
+# define OLD_INI_FILE "tilp.ini"
+#endif
+
/* Chech whether a RC file exists */
int tilp_config_exist(void)
{
-#if defined(__LINUX__) || defined(__BSD__) || defined(__MACOSX__)
- char * ini_file;
int retval;
-
- ini_file = get_config_path();
-
- retval = !access(ini_file, F_OK);
- g_free(ini_file);
- return retval;
-#elif defined(__WIN32__)
+ char * ini_file;
char* old_ini_file;
- char* ini_file;
- int result1, result2, retval;
+ old_ini_file = g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S, OLD_INI_FILE, NULL);
+ ini_file = get_config_path();
+ deprecated_config_path(old_ini_file, ini_file);
+ free(old_ini_file);
+#if defined(__WIN32__)
// On Windows, there can be two config files:
- // * in the install dir (deprecated, as it does not work well with the UAC);
- old_ini_file = g_strconcat(inst_paths.base_dir, G_DIR_SEPARATOR_S, INI_FILE, NULL);
- result1 = !access(old_ini_file, F_OK);
// * per-user config files (which the *nix versions have been using for ages).
- ini_file = get_config_path();
- result2 = !access(ini_file, F_OK);
-
- if (result1)
- {
- // A config file exists at the old location
- if (!result2)
- {
- // No config file exists at the new location, bad.
- // Create it.
- FILE *in;
- FILE *out;
-
- in = fopen(old_ini_file, "rb");
- out = fopen(ini_file, "wb");
- if (in && out)
- {
- int c;
-
- while ((c = fgetc(in)) != EOF)
- {
- fputc(c, out);
- }
- fclose(out);
- fclose(in);
- // A config file now exists at the new location.
- // Delete the old file.
- unlink(old_ini_file);
- retval = 1;
- }
- else
- {
- // There's a problem...
- // Trigger failure in the callers.
- retval = 0;
- }
- }
- else
- {
- // A config file exists at the new location (even if a config file exists at the old location), good.
- retval = 1;
- }
- }
- else if (result2)
- {
- // A config file exists at the new location, good.
- retval = 1;
- }
- else
- {
- // No config file at either location.
- retval = 0;
- }
+ // * in the install dir (deprecated, as it does not work well with the UAC);
+ old_ini_file = g_strconcat(inst_paths.base_dir, G_DIR_SEPARATOR_S, OLD_INI_FILE, NULL);
+ deprecated_config_path(old_ini_file, ini_file);
g_free(old_ini_file);
+#endif
+ retval = !access(ini_file, F_OK);
g_free(ini_file);
return retval;
-#endif
}
@@ -379,7 +357,7 @@ int tilp_config_write(void)
f = fopen(ini_file, "wt");
if (f == NULL)
{
- gif->msg_box1(_("Error"), _("Unable to write the config file (~/.tilp or ~/tilp.ini).\n"));
+ gif->msg_box1(_("Error"), _("Unable to write the config file ($XDG_CONFIG_HOME/tilp.ini).\n"));
ret = -1;
goto exit;
}
diff --git a/tilp/trunk/src/tilp_paths.h b/tilp/trunk/src/tilp_paths.h
index 9c07905c..fe413f2f 100644
--- a/tilp/trunk/src/tilp_paths.h
+++ b/tilp/trunk/src/tilp_paths.h
@@ -28,13 +28,6 @@
#include
-/* Paths */
-#if defined(__LINUX__) || defined(__BSD__) || defined(__MACOSX__)
-# define INI_FILE "/.tilp"
-#elif defined(__WIN32__)
-# define INI_FILE "tilp.ini"
-#endif
-
/* Temporary filenames (used by cb_calc.c) */
#define TMPFILE_BACKUP "tilp.backup"
#define TMPFILE_ROMDUMP "tilp.romdump"