follow XDG Base Directory Specification for user configuration directory and migrate previously created directory

This commit is contained in:
Thomas Debesse 2013-11-11 01:36:47 +01:00 committed by Thomas Debesse
parent 9ddb9db9bb
commit d577634cec
7 changed files with 74 additions and 5 deletions

View File

@ -1,3 +1,7 @@
Nov 11, 2013: Thomas Debesse <xqf@illwieckz.net>
- follow XDG Base Directory Specification for user configuration directory
and migrate previously created directory
Nov 10, 2013: Thomas Debesse <xqf@illwieckz.net>
- add World of Padman game

View File

@ -13,6 +13,7 @@ Changes since 1.0.5:
* Enhance Steam applaunch support
* Enable GTK+2 build by default, GTK+1 build is no longer guaranteed
* Add scalable SVG icon
* Follow XDG Base Directory Specification for user configuration directory and migrate previously created directory
* Add x11 libs to pkg_modules
* Fix build with newer linker versions
* Fix autotools, intltool

View File

@ -5068,11 +5068,11 @@ int fix_qw_player_color (int color) {
int init_user_info (void) {
if (!g_get_user_name () || !g_get_home_dir () || !g_get_tmp_dir ()) {
xqf_error(_("Unable to get user name/home/tmpdir"));
if (!g_get_user_name () || !g_get_home_dir () || !g_get_tmp_dir () || !g_get_user_config_dir ()) {
xqf_error(_("Unable to get user name/home directory/XDG config directory/tmp directory"));
return FALSE;
}
user_rcdir = file_in_dir (g_get_home_dir (), RC_DIR);
user_rcdir = file_in_dir (g_get_user_config_dir (), XDG_RC_DIR);
return TRUE;
}

View File

@ -23,6 +23,7 @@
#include <unistd.h> /* stat, mkdir, unlink */
#include <sys/types.h> /* mkdir */
#include <fcntl.h> /* mkdir */
#include <stdlib.h> /* free */
#include "xqf.h"
#include "game.h"
@ -474,6 +475,58 @@ int rc_save (void) {
}
int rc_migrate_dir (void) {
int res;
struct stat st_buf;
char* legacy_user_rcdir = NULL;
char* xdg_user_rcdir = NULL;
char* xdg_user_dir = NULL;
if (!g_get_user_name () || !g_get_home_dir () || !g_get_user_config_dir ()) {
fprintf(stderr, "Unable to get user name/home directory/XDG config directory\n");
return FALSE;
}
xdg_user_dir = g_get_user_config_dir ();
legacy_user_rcdir = file_in_dir (g_get_home_dir (), RC_DIR);
xdg_user_rcdir = file_in_dir (xdg_user_dir, XDG_RC_DIR);
/* if ~/.qf exists and ~/.config/xqf does not exists */
if (stat (legacy_user_rcdir, &st_buf) != -1 && stat (xdg_user_rcdir, &st_buf) == -1)
{
/* if ~/.config does not exists, create it */
if (stat (xdg_user_dir, &st_buf) == -1) {
res = mkdir (xdg_user_dir, 0755);
if (res != 0) {
fprintf(stderr, "Can't create XDG user config directory %s\n", xdg_user_dir);
free(legacy_user_rcdir);
free(xdg_user_rcdir);
return res;
}
}
else {
/* move ~/.qf ~/.config/qf */
fprintf(stdout, "Moving legacy config directory %s to XDG user config directory %s\n", legacy_user_rcdir, xdg_user_rcdir);
res = rename(legacy_user_rcdir, xdg_user_rcdir);
if (res == 0) {
fprintf(stdout, "Legacy config directory %s succesfully moved to XDG user config directory %s\n", legacy_user_rcdir, xdg_user_rcdir);
}
else {
fprintf(stderr, "Error when moving legacy config directory %s to XDG user config directory %s\n", legacy_user_rcdir, xdg_user_rcdir);
free(legacy_user_rcdir);
free(xdg_user_rcdir);
return res;
}
}
}
else if (stat (legacy_user_rcdir, &st_buf) != -1 && stat (xdg_user_rcdir, &st_buf) != -1) {
fprintf(stderr, "Warning, there is an old legacy config directory %s, but XDG user config directory %s will be used\n", legacy_user_rcdir, xdg_user_rcdir);
}
free(legacy_user_rcdir);
free(xdg_user_rcdir);
return TRUE;
}
int rc_check_dir (void) {
struct stat st_buf;

View File

@ -54,6 +54,7 @@ struct keyword {
extern int rc_parse (void);
extern int rc_save (void);
extern int rc_migrate_dir (void);
extern int rc_check_dir (void);

View File

@ -3981,6 +3981,15 @@ int main (int argc, char *argv[]) {
set_debug_level (DEFAULT_DEBUG_LEVEL);
debug (5, "main() -- Debug Level Default Set at %d", DEFAULT_DEBUG_LEVEL);
/* migrate config directory to follow XDG Base Directory Specification
* http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
* https://developer.gnome.org/basedir-spec/
* https://developer.gnome.org/glib/2.37/glib-Miscellaneous-Utility-Functions.html#g-get-user-config-dir
*/
if (!rc_migrate_dir()) {
return 1;
}
if (!init_user_info ()) {
return 1;
}

View File

@ -22,14 +22,15 @@
#include "gnuconfig.h" /* GNU autoconf */
#include <sys/types.h>
#include <netinet/in.h> /* struct in_addr */
#include <netinet/in.h> /* struct in_addr */
#include <arpa/inet.h> /* struct in_addr */
#include <time.h> /* time_t */
#include <gtk/gtk.h>
#include <glib.h>
#define RC_DIR ".qf"
#define RC_DIR ".qf" /* legacy config dir, before 1.0.6 */
#define XDG_RC_DIR "qf" /* new config dir, since 1.0.6 */
#define RC_FILE "qfrc"
#define CONFIG_FILE "config"
#define SERVERS_FILE "servers"