Store config and save*s in user specific config directory
Apply patch #2936906 from Jan Steffens to save config, saves and savestates in a common dir instead of having them in the current dir. The config file is moved automagically but you need to move the saves and savestates inside ~/.config/desmume/ by hand.
This commit is contained in:
parent
9b1d5c4ef2
commit
269d1940c4
|
@ -19,20 +19,35 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#include <glib/gstdio.h>
|
||||||
|
|
||||||
#include "ctrlssdl.h"
|
#include "ctrlssdl.h"
|
||||||
#include "desmume_config.h"
|
#include "desmume_config.h"
|
||||||
|
|
||||||
static const gchar *desmume_config_file = ".desmume.ini";
|
static const gchar *desmume_old_config_file = ".desmume.ini";
|
||||||
|
static const gchar *desmume_config_dir = "desmume";
|
||||||
|
static const gchar *desmume_config_file = "config";
|
||||||
|
|
||||||
GKeyFile *desmume_config_read_file(const u16 *kb_cfg)
|
GKeyFile *desmume_config_read_file(const u16 *kb_cfg)
|
||||||
{
|
{
|
||||||
gchar *config_file;
|
gchar *config_file, *config_dir, *old_config_file;
|
||||||
GKeyFile *keyfile;
|
GKeyFile *keyfile;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
|
|
||||||
config_file = g_build_filename(g_get_home_dir(), desmume_config_file, NULL);
|
old_config_file = g_build_filename(g_get_home_dir(), desmume_old_config_file, NULL);
|
||||||
|
config_file = g_build_filename(g_get_user_config_dir(), desmume_config_dir, desmume_config_file, NULL);
|
||||||
|
|
||||||
|
config_dir = g_build_filename(g_get_user_config_dir(), desmume_config_dir, NULL);
|
||||||
|
g_mkdir_with_parents(config_dir, 0755);
|
||||||
|
|
||||||
|
if (!g_file_test(config_file, G_FILE_TEST_IS_REGULAR) && g_file_test(old_config_file, G_FILE_TEST_IS_REGULAR)) {
|
||||||
|
ret = g_rename(old_config_file, config_file);
|
||||||
|
if (ret) {
|
||||||
|
g_printerr("Failed to move old config file %s to new location %s \n", old_config_file, config_file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
keyfile = g_key_file_new();
|
keyfile = g_key_file_new();
|
||||||
ret = g_key_file_load_from_file(keyfile, config_file, G_KEY_FILE_NONE, &error);
|
ret = g_key_file_load_from_file(keyfile, config_file, G_KEY_FILE_NONE, &error);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
|
@ -40,6 +55,8 @@ GKeyFile *desmume_config_read_file(const u16 *kb_cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(config_file);
|
g_free(config_file);
|
||||||
|
g_free(config_dir);
|
||||||
|
g_free(old_config_file);
|
||||||
|
|
||||||
load_default_config(kb_cfg);
|
load_default_config(kb_cfg);
|
||||||
desmume_config_read_keys(keyfile);
|
desmume_config_read_keys(keyfile);
|
||||||
|
@ -56,12 +73,15 @@ void desmume_config_dispose(GKeyFile *keyfile)
|
||||||
static gboolean desmume_config_write_file(GKeyFile *keyfile)
|
static gboolean desmume_config_write_file(GKeyFile *keyfile)
|
||||||
{
|
{
|
||||||
gchar *config_file;
|
gchar *config_file;
|
||||||
|
gchar *config_dir;
|
||||||
gchar *data;
|
gchar *data;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gsize length;
|
gsize length;
|
||||||
gboolean ret = TRUE;
|
gboolean ret = TRUE;
|
||||||
|
|
||||||
config_file = g_build_filename(g_get_home_dir(), desmume_config_file, NULL);
|
config_dir = g_build_filename(g_get_user_config_dir(), desmume_config_dir, NULL);
|
||||||
|
g_mkdir_with_parents(config_dir, 0755);
|
||||||
|
config_file = g_build_filename(g_get_user_config_dir(), desmume_config_dir, desmume_config_file, NULL);
|
||||||
data = g_key_file_to_data(keyfile, &length, NULL);
|
data = g_key_file_to_data(keyfile, &length, NULL);
|
||||||
ret = g_file_set_contents(config_file, data, length, &error);
|
ret = g_file_set_contents(config_file, data, length, &error);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
|
@ -69,6 +89,7 @@ static gboolean desmume_config_write_file(GKeyFile *keyfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(config_file);
|
g_free(config_file);
|
||||||
|
g_free(config_dir);
|
||||||
g_free(data);
|
g_free(data);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -84,7 +84,8 @@ public:
|
||||||
while (p >= pathToModule && *p != '\\') p--;
|
while (p >= pathToModule && *p != '\\') p--;
|
||||||
if (++p >= pathToModule) *p = 0;
|
if (++p >= pathToModule) *p = 0;
|
||||||
#else
|
#else
|
||||||
char *cwd = g_get_current_dir();
|
char *cwd = g_build_filename(g_get_user_config_dir(), "desmume", NULL);
|
||||||
|
g_mkdir_with_parents(cwd, 0755);
|
||||||
strncpy(pathToModule, cwd, MAX_PATH);
|
strncpy(pathToModule, cwd, MAX_PATH);
|
||||||
g_free(cwd);
|
g_free(cwd);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue