X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/29c93cc57d2f7715c58b4e577440bc580a47bd8a..e8bab170981ff0e1cd572107ca4de122d4aafe8c:/src/dir.c diff --git a/src/dir.c b/src/dir.c index a6b6049c..0c14b427 100644 --- a/src/dir.c +++ b/src/dir.c @@ -32,37 +32,45 @@ #include #include -const gchar *a_get_viking_dir() +/** + * For external use, free the result + * Made externally available primarily to detect when Viking is first run + */ +gchar *a_get_viking_dir_no_create() { - static gchar *viking_dir = NULL; - // TODO: use g_get_user_config_dir ? - if (!viking_dir) { - const gchar *home = g_getenv("HOME"); - if (!home || g_access(home, W_OK)) - home = g_get_home_dir (); + const gchar *home = g_getenv("HOME"); + if (!home || g_access(home, W_OK)) + home = g_get_home_dir (); #ifdef HAVE_MKDTEMP - if (!home || g_access(home, W_OK)) + if (!home || g_access(home, W_OK)) { static gchar temp[] = {"/tmp/vikXXXXXX"}; home = mkdtemp(temp); } #endif - if (!home || g_access(home, W_OK)) - /* Fatal error */ - g_critical("Unable to find a base directory"); + if (!home || g_access(home, W_OK)) + /* Fatal error */ + g_critical("Unable to find a base directory"); /* Build the name of the directory */ #ifdef __APPLE__ - viking_dir = g_build_filename(home, "/Library/Application Support/Viking", NULL); + return g_build_filename(home, "/Library/Application Support/Viking", NULL); #else - viking_dir = g_build_filename(home, ".viking", NULL); + return g_build_filename(home, ".viking", NULL); #endif +} + +static gchar *viking_dir = NULL; + +const gchar *a_get_viking_dir() +{ + if (!viking_dir) { + viking_dir = a_get_viking_dir_no_create (); if (g_file_test(viking_dir, G_FILE_TEST_EXISTS) == FALSE) g_mkdir(viking_dir, 0755); } - return viking_dir; } @@ -97,7 +105,13 @@ a_get_viking_data_home() gchar ** a_get_viking_data_path() { +#ifdef WINDOWS + // Try to use from the install directory - normally the working directory of Viking is where ever it's install location is + const gchar *xdg_data_dirs = "./data"; + //const gchar *xdg_data_dirs = g_strdup ( "%s/%s/data", g_getenv("ProgramFiles"), PACKAGE ); +#else const gchar *xdg_data_dirs = g_getenv("XDG_DATA_DIRS"); +#endif if (xdg_data_dirs == NULL) { /* Default value specified in @@ -105,7 +119,10 @@ a_get_viking_data_path() */ xdg_data_dirs = "/usr/local/share/:/usr/share/"; } - gchar **data_path = g_strsplit(xdg_data_dirs, ":", 0); + + gchar **data_path = g_strsplit(xdg_data_dirs, G_SEARCHPATH_SEPARATOR_S, 0); + +#ifndef WINDOWS /* Append the viking dir */ gchar **path; for (path = data_path ; *path != NULL ; path++) @@ -114,5 +131,6 @@ a_get_viking_data_path() *path = g_build_filename(dir, PACKAGE, NULL); g_free(dir); } +#endif return data_path; }