Win32 equivalences of the XDG folders
authorTor Lillqvist <tml@iki.fi>
Wed, 25 Aug 2004 00:39:13 +0000 (00:39 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Wed, 25 Aug 2004 00:39:13 +0000 (00:39 +0000)
2004-08-25  Tor Lillqvist  <tml@iki.fi>

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
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-6
ChangeLog.pre-2-8
configure.in
glib/glib.def
glib/gutils.c

index d421a3c..68d20d6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2004-08-25  Tor Lillqvist  <tml@iki.fi>
+
+       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  <yosh@gimp.org>
 
        * glib/goption.c (g_option_group_add_entries): remove unused
index d421a3c..68d20d6 100644 (file)
@@ -1,3 +1,23 @@
+2004-08-25  Tor Lillqvist  <tml@iki.fi>
+
+       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  <yosh@gimp.org>
 
        * glib/goption.c (g_option_group_add_entries): remove unused
index d421a3c..68d20d6 100644 (file)
@@ -1,3 +1,23 @@
+2004-08-25  Tor Lillqvist  <tml@iki.fi>
+
+       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  <yosh@gimp.org>
 
        * glib/goption.c (g_option_group_add_entries): remove unused
index d421a3c..68d20d6 100644 (file)
@@ -1,3 +1,23 @@
+2004-08-25  Tor Lillqvist  <tml@iki.fi>
+
+       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  <yosh@gimp.org>
 
        * glib/goption.c (g_option_group_add_entries): remove unused
index d421a3c..68d20d6 100644 (file)
@@ -1,3 +1,23 @@
+2004-08-25  Tor Lillqvist  <tml@iki.fi>
+
+       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  <yosh@gimp.org>
 
        * glib/goption.c (g_option_group_add_entries): remove unused
index b024157..b865d0e 100644 (file)
@@ -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=""
index 733b0c8..20d0e25 100644 (file)
@@ -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
index e46c048..398dc75 100644 (file)
@@ -75,6 +75,7 @@
 
 #ifdef G_OS_WIN32
 #  include <direct.h>
+#  include <shlobj.h>
 #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)
@@ -954,6 +994,9 @@ g_get_any_init (void)
        }
 
       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
           * to point to the home directory, I think. But on Windows
@@ -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;