Skip to content

Commit

Permalink
Make VICE respect XDG basedir spec when loading/saving config files
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.code.sf.net/p/vice-emu/code/trunk@35704 379a1393-f5fb-40a0-bcee-ef074d9b53f7
  • Loading branch information
compyx committed Oct 28, 2018
1 parent 1dd0fef commit d54f94b
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 6 deletions.
29 changes: 29 additions & 0 deletions vice/src/arch/gtk3/archdep.c
Expand Up @@ -49,6 +49,8 @@
#include "uiapi.h"

/* Will get fixed once the code in this file gets moved to its proper location */
#include "../shared/archdep_xdg.h"
#include "../shared/archdep_defs.h"
#include "../shared/archdep_create_user_config_dir.h"
#include "../shared/archdep_join_paths.h"

Expand Down Expand Up @@ -176,6 +178,11 @@ int archdep_init(int *argc, char **argv)
char *vice_ini;
char *datadir;
char *docsdir;
# if defined(ARCHDEP_OS_LINUX) || defined(ARCHDEP_OS_BSD)
char *xdg_cache;
char *xdg_config;
char *xdg_data;
# endif
#endif
argv0 = lib_stralloc(argv[0]);

Expand All @@ -193,6 +200,12 @@ int archdep_init(int *argc, char **argv)
datadir = archdep_get_vice_datadir();
docsdir = archdep_get_vice_docsdir();

# if defined(ARCHDEP_OS_LINUX) && defined(ARCHDEP_OS_BSD)
xdg_cache = archdep_xdg_cache_home();
xdg_config = archdep_xdg_config_home();
xdg_data = archdep_xdg_data_home()l
# endif

debug_gtk3("program name = \"%s\"", prg_name);
debug_gtk3("user home dir = \"%s\"", archdep_home_path());
debug_gtk3("user config dir = \"%s\"", cfg_path);
Expand All @@ -202,6 +215,22 @@ int archdep_init(int *argc, char **argv)
debug_gtk3("VICE docs path = \"%s\"", docsdir);
debug_gtk3("vice.ini path = \"%s\"", vice_ini);

# if defined(ARCHDEP_OS_LINUX) || defined(ARCHDEP_OS_BSD)
xdg_cache = archdep_xdg_cache_home();
xdg_config = archdep_xdg_config_home();
xdg_data = archdep_xdg_data_home();

debug_gtk3("XDG_CACHE_HOME = '%s'.", xdg_cache);
debug_gtk3("XDG_CONFIG_HOME = '%s'.", xdg_config);
debug_gtk3("XDG_DATA_HOME = '%s'.", xdg_data);

lib_free(xdg_cache);
lib_free(xdg_config);
lib_free(xdg_data);
# endif



lib_free(searchpath);
lib_free(vice_ini);
# if 0
Expand Down
6 changes: 4 additions & 2 deletions vice/src/arch/shared/Makefile.am
Expand Up @@ -40,7 +40,8 @@ libarchdep_a_SOURCES = \
archdep_sanitize_filename.c \
archdep_startup_log_error.c \
archdep_stat.c \
archdep_user_config_path.c
archdep_user_config_path.c \
archdep_xdg.c

EXTRA_DIST = \
archdep_defs.h \
Expand Down Expand Up @@ -71,4 +72,5 @@ EXTRA_DIST = \
archdep_sanitize_filename.h \
archdep_startup_log_error.h \
archdep_stat.h \
archdep_user_config_path.h
archdep_user_config_path.h \
archdep_xdg.h
9 changes: 6 additions & 3 deletions vice/src/arch/shared/archdep_user_config_path.c
Expand Up @@ -49,6 +49,7 @@
#include "archdep_boot_path.h"
#include "archdep_home_path.h"
#include "archdep_join_paths.h"
#include "archdep_xdg.h"

#include "archdep_user_config_path.h"

Expand All @@ -67,7 +68,7 @@ static char *user_config_dir = NULL;
* the home directory, depending on OS:
*
* - Windows: $HOME\\AppData\\Roaming\\vice
* - Unix: $HOME/.config/vice
* - Unix: $HOME/.config/vice (rather: XDG_CONFIG_HOME)
* - BeOS: $HOME/config/settings/vice
* (Haiku sets $XDG_CONFIG_HOME to '/boot/home/config/settings')
*
Expand All @@ -84,8 +85,10 @@ char *archdep_user_config_path(void)
}

#if defined(ARCHDEP_OS_UNIX)
user_config_dir = archdep_join_paths(archdep_home_path(),
".config", "vice", NULL);
char *xdg_config = archdep_xdg_config_home();
user_config_dir = archdep_join_paths(xdg_config, "vice", NULL);
lib_free(xdg_config);

#elif defined(ARCHDEP_OS_WINDOWS)
user_config_dir = archdep_join_paths(archdep_home_path(),
"AppData", "Roaming", "vice", NULL);
Expand Down
91 changes: 91 additions & 0 deletions vice/src/arch/shared/archdep_xdg.c
@@ -0,0 +1,91 @@
/** \file archdep_xdg.c
* \brief XDG base dir specification support
* \author Bas Wassink <b.wassink@ziggo.nl>
*/

/*
* This file is part of VICE, the Versatile Commodore Emulator.
* See README for copyright notice.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA.
*
*/

#include "vice.h"
#include <stdio.h>
#include <stdlib.h>
#include "lib.h"

#include "archdep_defs.h"
#include "archdep_home_path.h"
#include "archdep_join_paths.h"

#include "archdep_xdg.h"


/** \brief Get XDG_DATA_HOME
*
* Either returns the value of $XDG_DATA_HOME or the default $HOME/.local/share
*
* \return heap-allocated string, free with lib_free()
*/
char *archdep_xdg_data_home(void)
{
const char *path = getenv("XDG_DATA_HOME");

if (path != NULL) {
/* got env var, heap-allocate since the archdep_join_paths() function
* also returns a heap-allocated string.
*/
return lib_stralloc(path);
}
return archdep_join_paths(archdep_home_path(), ".local", "share", NULL);
}


/** \brief Get XDG_CONFIG_HOME
*
* Either returns the value of $XDG_CONFIG_HOME or the default $HOME/.config
*
* \return heap-allocated string, free with lib_free()
*/
char *archdep_xdg_config_home(void)
{
const char *path = getenv("XDG_CONFIG_HOME");

if (path != NULL) {
return lib_stralloc(path);
}
return archdep_join_paths(archdep_home_path(), ".config", NULL);
}


/** \brief Get XDG_CACHE_HOME
*
* Either returns the value of $XDG_CACHE_HOME or the default $HOME/.cache
*
* \return heap-allocated string, free with lib_free()
*/
char *archdep_xdg_cache_home(void)
{
const char *path = getenv("XDG_CACHE_HOME");

if (path != NULL) {
return lib_stralloc(path);
}
return archdep_join_paths(archdep_home_path(), ".cache", NULL);
}

34 changes: 34 additions & 0 deletions vice/src/arch/shared/archdep_xdg.h
@@ -0,0 +1,34 @@
/** \file archdep_xdg.g
* \brief XDG base dir specification support - header
* \author Bas Wassink <b.wassink@ziggo.nl>
*/

/*
* This file is part of VICE, the Versatile Commodore Emulator.
* See README for copyright notice.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA.
*
*/

#ifndef VICE_ARCHDEP_XDG_H
#define VICE_ARCHDEP_XDG_H

char *archdep_xdg_data_home(void);
char *archdep_xdg_config_home(void);
char *archdep_xdg_cache_home(void);

#endif
1 change: 0 additions & 1 deletion vice/src/archapi.h
Expand Up @@ -135,5 +135,4 @@ extern char *archdep_extra_title_text(void);
int archdep_vice_atexit(void (*function)(void));
void archdep_vice_exit(int excode);


#endif

0 comments on commit d54f94b

Please sign in to comment.