From 89421ac32343b8e73cd02218cc0b7092db9eff0f Mon Sep 17 00:00:00 2001 From: aarondill Date: Wed, 21 Feb 2024 14:32:25 -0600 Subject: [PATCH 1/5] tilp: Use g_get_user_config_dir() to get the config directory This allows the XDG base specification to be followed, defaulting to LocalAppData on windows --- tilp/trunk/src/tilp_config.c | 116 ++++++++++++++--------------------- tilp/trunk/src/tilp_paths.h | 7 --- 2 files changed, 47 insertions(+), 76 deletions(-) diff --git a/tilp/trunk/src/tilp_config.c b/tilp/trunk/src/tilp_config.c index 8d167e9c..80529a90 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); + deprecated_config_path(old_ini_file, ini_file); + free(old_ini_file); + ini_file = get_config_path(); +#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 } 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" From eef728a9225a6d553fb89e8919423a8a5bdf6ed8 Mon Sep 17 00:00:00 2001 From: aarondill Date: Thu, 22 Feb 2024 08:25:33 -0600 Subject: [PATCH 2/5] fix: don't use ini_file until it's been initialized! --- tilp/trunk/src/tilp_config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tilp/trunk/src/tilp_config.c b/tilp/trunk/src/tilp_config.c index 80529a90..66964afe 100644 --- a/tilp/trunk/src/tilp_config.c +++ b/tilp/trunk/src/tilp_config.c @@ -149,10 +149,10 @@ int tilp_config_exist(void) char * ini_file; char* old_ini_file; 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); - ini_file = get_config_path(); #if defined(__WIN32__) // On Windows, there can be two config files: // * per-user config files (which the *nix versions have been using for ages). From c375937db7161b18b7cc7cc97d8350d33e333f4f Mon Sep 17 00:00:00 2001 From: aarondill Date: Thu, 22 Feb 2024 08:39:54 -0600 Subject: [PATCH 3/5] docs: Update docs and translations to indicate new config directory --- tilp/trunk/help/chapter07.html | 18 +++++++++--------- tilp/trunk/man/tilp.1 | 2 +- tilp/trunk/po/de.po | 4 ++-- tilp/trunk/po/fr.po | 6 +++--- tilp/trunk/src/tilp_config.c | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tilp/trunk/help/chapter07.html b/tilp/trunk/help/chapter07.html index f874704c..b2648a4f 100644 --- a/tilp/trunk/help/chapter07.html +++ b/tilp/trunk/help/chapter07.html @@ -138,15 +138,15 @@

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). 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 66964afe..571a1230 100644 --- a/tilp/trunk/src/tilp_config.c +++ b/tilp/trunk/src/tilp_config.c @@ -357,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; } From 0b06ebccb952f26a2665a5ea57704b01503c7918 Mon Sep 17 00:00:00 2001 From: aarondill Date: Mon, 11 Mar 2024 22:05:28 -0500 Subject: [PATCH 4/5] docs: Update docs to describe deprecated config migration (also fixes 'windows' -> 'Windows') --- tilp/trunk/help/chapter07.html | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tilp/trunk/help/chapter07.html b/tilp/trunk/help/chapter07.html index b2648a4f..61392476 100644 --- a/tilp/trunk/help/chapter07.html +++ b/tilp/trunk/help/chapter07.html @@ -138,14 +138,16 @@

7. Command line

CONFIG FILE FORMAT - 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). - 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 + 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 From dbff5735796f3ec9d7190eb1f3010939c192b4cc Mon Sep 17 00:00:00 2001 From: Aaron Dill <117116764+aarondill@users.noreply.github.com> Date: Sat, 18 May 2024 12:03:53 -0500 Subject: [PATCH 5/5] fix: restore detection of deprecated config path on non-windows the dot was accidentally removed while copying. The leading dot has been re-added now --- tilp/trunk/src/tilp_config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tilp/trunk/src/tilp_config.c b/tilp/trunk/src/tilp_config.c index 571a1230..eca9627f 100644 --- a/tilp/trunk/src/tilp_config.c +++ b/tilp/trunk/src/tilp_config.c @@ -137,7 +137,7 @@ static char * get_config_path(void) } #if defined(__LINUX__) || defined(__BSD__) || defined(__MACOSX__) -# define OLD_INI_FILE "tilp" +# define OLD_INI_FILE ".tilp" #elif defined(__WIN32__) # define OLD_INI_FILE "tilp.ini" #endif