From a56aee27f687ea292bb85661e95b07141e2af90b Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Wed, 25 Aug 2004 00:39:13 +0000 Subject: [PATCH] Win32 equivalences of the XDG folders 2004-08-25 Tor Lillqvist Win32 equivalences of the XDG folders * glib/gutils.c (get_special_folder): New function, calls SHGetSpecialFolderLocation() to get path to places like the My Documents folder. (g_get_any_init): Use CSIDL_PROFILE as HOME if not overridden by env vars. (g_get_user_data_dir): Use CSIDL_PERSONAL. (g_get_user_config_dir): Use CSIDL_APPDATA. (g_get_user_cache_dir): Use CSIDL_INTERNET_CACHE. Debatable... (g_get_system_data_dirs): Use CSIDL_COMMON_APPDATA and CSIDL_COMMON_DOCUMENTS. (g_get_system_config_dirs): Use CSIDL_COMMON_APPDATA. * configure.in: Add -lole32 to G_LIBS_EXTRA for mingw. * glib/glib.def: Add the new functions. --- ChangeLog | 20 ++++++++++ ChangeLog.pre-2-10 | 20 ++++++++++ ChangeLog.pre-2-12 | 20 ++++++++++ ChangeLog.pre-2-6 | 20 ++++++++++ ChangeLog.pre-2-8 | 20 ++++++++++ configure.in | 2 +- glib/glib.def | 5 +++ glib/gutils.c | 98 +++++++++++++++++++++++++++++++++++++--------- 8 files changed, 186 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index d421a3c77..68d20d611 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2004-08-25 Tor Lillqvist + + Win32 equivalences of the XDG folders + + * glib/gutils.c (get_special_folder): New function, calls + SHGetSpecialFolderLocation() to get path to places like the My + Documents folder. + (g_get_any_init): Use CSIDL_PROFILE as HOME if not + overridden by env vars. + (g_get_user_data_dir): Use CSIDL_PERSONAL. + (g_get_user_config_dir): Use CSIDL_APPDATA. + (g_get_user_cache_dir): Use CSIDL_INTERNET_CACHE. Debatable... + (g_get_system_data_dirs): Use CSIDL_COMMON_APPDATA and + CSIDL_COMMON_DOCUMENTS. + (g_get_system_config_dirs): Use CSIDL_COMMON_APPDATA. + + * configure.in: Add -lole32 to G_LIBS_EXTRA for mingw. + + * glib/glib.def: Add the new functions. + Mon Aug 23 16:16:35 2004 Manish Singh * glib/goption.c (g_option_group_add_entries): remove unused diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index d421a3c77..68d20d611 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,23 @@ +2004-08-25 Tor Lillqvist + + Win32 equivalences of the XDG folders + + * glib/gutils.c (get_special_folder): New function, calls + SHGetSpecialFolderLocation() to get path to places like the My + Documents folder. + (g_get_any_init): Use CSIDL_PROFILE as HOME if not + overridden by env vars. + (g_get_user_data_dir): Use CSIDL_PERSONAL. + (g_get_user_config_dir): Use CSIDL_APPDATA. + (g_get_user_cache_dir): Use CSIDL_INTERNET_CACHE. Debatable... + (g_get_system_data_dirs): Use CSIDL_COMMON_APPDATA and + CSIDL_COMMON_DOCUMENTS. + (g_get_system_config_dirs): Use CSIDL_COMMON_APPDATA. + + * configure.in: Add -lole32 to G_LIBS_EXTRA for mingw. + + * glib/glib.def: Add the new functions. + Mon Aug 23 16:16:35 2004 Manish Singh * glib/goption.c (g_option_group_add_entries): remove unused diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index d421a3c77..68d20d611 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,23 @@ +2004-08-25 Tor Lillqvist + + Win32 equivalences of the XDG folders + + * glib/gutils.c (get_special_folder): New function, calls + SHGetSpecialFolderLocation() to get path to places like the My + Documents folder. + (g_get_any_init): Use CSIDL_PROFILE as HOME if not + overridden by env vars. + (g_get_user_data_dir): Use CSIDL_PERSONAL. + (g_get_user_config_dir): Use CSIDL_APPDATA. + (g_get_user_cache_dir): Use CSIDL_INTERNET_CACHE. Debatable... + (g_get_system_data_dirs): Use CSIDL_COMMON_APPDATA and + CSIDL_COMMON_DOCUMENTS. + (g_get_system_config_dirs): Use CSIDL_COMMON_APPDATA. + + * configure.in: Add -lole32 to G_LIBS_EXTRA for mingw. + + * glib/glib.def: Add the new functions. + Mon Aug 23 16:16:35 2004 Manish Singh * glib/goption.c (g_option_group_add_entries): remove unused diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index d421a3c77..68d20d611 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,23 @@ +2004-08-25 Tor Lillqvist + + Win32 equivalences of the XDG folders + + * glib/gutils.c (get_special_folder): New function, calls + SHGetSpecialFolderLocation() to get path to places like the My + Documents folder. + (g_get_any_init): Use CSIDL_PROFILE as HOME if not + overridden by env vars. + (g_get_user_data_dir): Use CSIDL_PERSONAL. + (g_get_user_config_dir): Use CSIDL_APPDATA. + (g_get_user_cache_dir): Use CSIDL_INTERNET_CACHE. Debatable... + (g_get_system_data_dirs): Use CSIDL_COMMON_APPDATA and + CSIDL_COMMON_DOCUMENTS. + (g_get_system_config_dirs): Use CSIDL_COMMON_APPDATA. + + * configure.in: Add -lole32 to G_LIBS_EXTRA for mingw. + + * glib/glib.def: Add the new functions. + Mon Aug 23 16:16:35 2004 Manish Singh * glib/goption.c (g_option_group_add_entries): remove unused diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index d421a3c77..68d20d611 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,23 @@ +2004-08-25 Tor Lillqvist + + Win32 equivalences of the XDG folders + + * glib/gutils.c (get_special_folder): New function, calls + SHGetSpecialFolderLocation() to get path to places like the My + Documents folder. + (g_get_any_init): Use CSIDL_PROFILE as HOME if not + overridden by env vars. + (g_get_user_data_dir): Use CSIDL_PERSONAL. + (g_get_user_config_dir): Use CSIDL_APPDATA. + (g_get_user_cache_dir): Use CSIDL_INTERNET_CACHE. Debatable... + (g_get_system_data_dirs): Use CSIDL_COMMON_APPDATA and + CSIDL_COMMON_DOCUMENTS. + (g_get_system_config_dirs): Use CSIDL_COMMON_APPDATA. + + * configure.in: Add -lole32 to G_LIBS_EXTRA for mingw. + + * glib/glib.def: Add the new functions. + Mon Aug 23 16:16:35 2004 Manish Singh * glib/goption.c (g_option_group_add_entries): remove unused diff --git a/configure.in b/configure.in index b024157ae..b865d0e0e 100644 --- a/configure.in +++ b/configure.in @@ -1970,7 +1970,7 @@ case $host in G_LIBS_EXTRA="-luser32 -lkernel32" ;; *-*-mingw*) - G_LIBS_EXTRA="-lwsock32" + G_LIBS_EXTRA="-lwsock32 -lole32" ;; *) G_LIBS_EXTRA="" diff --git a/glib/glib.def b/glib/glib.def index 733b0c8bb..20d0e25d4 100644 --- a/glib/glib.def +++ b/glib/glib.def @@ -178,7 +178,12 @@ EXPORTS g_get_home_dir g_get_prgname g_get_real_name + g_get_system_config_dirs + g_get_system_data_dirs g_get_tmp_dir + g_get_user_cache_dir + g_get_user_config_dir + g_get_user_data_dir g_get_user_name g_getenv g_hash_table_destroy diff --git a/glib/gutils.c b/glib/gutils.c index e46c04819..398dc75f0 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -75,6 +75,7 @@ #ifdef G_OS_WIN32 # include +# include #endif #ifdef HAVE_CODESET @@ -892,6 +893,45 @@ static gchar *g_user_cache_dir = NULL; static gchar *g_user_config_dir = NULL; static gchar **g_system_config_dirs = NULL; +#ifdef G_OS_WIN32 + +static gchar * +get_special_folder (int csidl) +{ + union { + char c[MAX_PATH+1]; + wchar_t wc[MAX_PATH+1]; + } path; + HRESULT hr; + LPITEMIDLIST pidl = NULL; + BOOL b; + gchar *retval = NULL; + + hr = SHGetSpecialFolderLocation (NULL, csidl, &pidl); + if (hr == S_OK) + { + if (G_WIN32_HAVE_WIDECHAR_API ()) + { + b = SHGetPathFromIDListW (pidl, path.wc); + if (b) + retval = g_utf16_to_utf8 (path.wc, -1, NULL, NULL, NULL); + } + else + { + b = SHGetPathFromIDListA (pidl, path.c); + if (b) + retval = g_locale_to_utf8 (path.c, -1, NULL, NULL, NULL); + } + CoTaskMemFree (pidl); + } + if (retval == NULL) + return "C:\\"; + else + return retval; +} + +#endif + /* HOLDS: g_utils_global_lock */ static void g_get_any_init (void) @@ -953,6 +993,9 @@ g_get_any_init (void) g_home_dir = g_strdup (g_getenv ("USERPROFILE")); } + if (!g_home_dir) + g_home_dir = get_special_folder (CSIDL_PROFILE); + if (!g_home_dir) { /* At least at some time, HOMEDRIVE and HOMEPATH were used @@ -1269,6 +1312,9 @@ g_get_user_data_dir (void) if (!g_user_data_dir) { +#ifdef G_OS_WIN32 + data_dir = get_special_folder (CSIDL_PERSONAL); +#else data_dir = (gchar *) g_getenv ("XDG_DATA_HOME"); if (data_dir && data_dir[0]) @@ -1281,7 +1327,7 @@ g_get_user_data_dir (void) data_dir = g_build_filename (g_home_dir, ".local", "share", NULL); } - +#endif g_user_data_dir = data_dir; } else @@ -1315,19 +1361,22 @@ g_get_user_config_dir (void) if (!g_user_config_dir) { - config_dir = (gchar *) g_getenv ("XDG_CONFIG_HOME"); - - if (config_dir && config_dir[0]) - config_dir = g_strdup (config_dir); - else - { - if (!g_tmp_dir) - g_get_any_init (); - - config_dir = g_build_filename (g_home_dir, ".config", NULL); - } - - g_user_config_dir = config_dir; +#ifdef G_OS_WIN32 + config_dir = get_special_folder (CSIDL_APPDATA); +#else + config_dir = (gchar *) g_getenv ("XDG_CONFIG_HOME"); + + if (config_dir && config_dir[0]) + config_dir = g_strdup (config_dir); + else + { + if (!g_tmp_dir) + g_get_any_init (); + + config_dir = g_build_filename (g_home_dir, ".config", NULL); + } +#endif + g_user_config_dir = config_dir; } else config_dir = g_user_config_dir; @@ -1360,6 +1409,9 @@ g_get_user_cache_dir (void) if (!g_user_cache_dir) { +#ifdef G_OS_WIN32 + cache_dir = get_special_folder (CSIDL_INTERNET_CACHE); /* XXX correct? */ +#else cache_dir = (gchar *) g_getenv ("XDG_CACHE_HOME"); if (cache_dir && cache_dir[0]) @@ -1371,6 +1423,7 @@ g_get_user_cache_dir (void) cache_dir = g_build_filename (g_home_dir, ".cache", NULL); } +#endif g_user_cache_dir = cache_dir; } else @@ -1404,12 +1457,18 @@ g_get_system_data_dirs (void) if (!g_system_data_dirs) { +#ifdef G_OS_WIN32 + data_dirs = g_strconcat (get_special_folder (CSIDL_COMMON_APPDATA), + G_SEARCHPATH_SEPARATOR_S, + get_special_folder (CSIDL_COMMON_DOCUMENTS), + NULL); +#else data_dirs = (gchar *) g_getenv ("XDG_DATA_DIRS"); if (!data_dirs || !data_dirs[0]) data_dirs = "/usr/local/share/:/usr/share/"; - - data_dir_vector = g_strsplit (data_dirs, ":", 0); +#endif + data_dir_vector = g_strsplit (data_dirs, G_SEARCHPATH_SEPARATOR_S, 0); g_system_data_dirs = data_dir_vector; } @@ -1444,12 +1503,15 @@ g_get_system_config_dirs (void) if (!g_system_config_dirs) { +#ifdef G_OS_WIN32 + conf_dirs = get_special_folder (CSIDL_COMMON_APPDATA); +#else conf_dirs = (gchar *) g_getenv ("XDG_CONFIG_DIRS"); if (!conf_dirs || !conf_dirs[0]) conf_dirs = "/etc/xdg"; - - conf_dir_vector = g_strsplit (conf_dirs, ":", 0); +#endif + conf_dir_vector = g_strsplit (conf_dirs, G_SEARCHPATH_SEPARATOR_S, 0); } else conf_dir_vector = g_system_config_dirs;