[geany/geany] 3e089e: Reading the config directory from the Windows API instead of GLib

Enrico Tröger git-noreply at xxxxx
Sun Oct 5 10:55:33 UTC 2014


Branch:      refs/heads/master
Author:      Enrico Tröger <enrico.troeger at uvena.de>
Committer:   Enrico Tröger <enrico.troeger at uvena.de>
Date:        Sun, 05 Oct 2014 10:55:33 UTC
Commit:      3e089e4c2c914a4b8885daa65e784a227bd2d6b0
             https://github.com/geany/geany/commit/3e089e4c2c914a4b8885daa65e784a227bd2d6b0

Log Message:
-----------
Reading the config directory from the Windows API instead of GLib

Before we used g_get_user_config_dir() but GLib changed the returned
location in newer versions, so use the Windows API directly
to get the old location, at least for now.
Also add utils_get_user_config_dir() wrapper.

Code is based almost completely on a patch from Matthew.


Modified Paths:
--------------
    src/main.c
    src/utils.c
    src/utils.h
    src/win32.c
    src/win32.h

Modified: src/main.c
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -608,7 +608,7 @@ static void parse_command_line_options(gint *argc, gchar ***argv)
 	}
 	else
 	{
-		app->configdir = g_build_filename(g_get_user_config_dir(), "geany", NULL);
+		app->configdir = utils_get_user_config_dir();
 	}
 
 	if (generate_tags)


Modified: src/utils.c
10 lines changed, 10 insertions(+), 0 deletions(-)
===================================================================
@@ -2078,3 +2078,13 @@ gchar *utils_parse_and_format_build_date(const gchar *input)
 
 	return g_strdup(input);
 }
+
+
+gchar *utils_get_user_config_dir(void)
+{
+#ifdef G_OS_WIN32
+	return win32_get_user_config_dir();
+#else
+	return g_build_filename(g_get_user_data_dir(), "geany", NULL);
+#endif
+}


Modified: src/utils.h
2 lines changed, 2 insertions(+), 0 deletions(-)
===================================================================
@@ -289,6 +289,8 @@ GDate *utils_parse_date(const gchar *input);
 
 gchar *utils_parse_and_format_build_date(const gchar *input);
 
+gchar *utils_get_user_config_dir(void);
+
 G_END_DECLS
 
 #endif /* GEANY_UTILS_H */


Modified: src/win32.c
27 lines changed, 27 insertions(+), 0 deletions(-)
===================================================================
@@ -1497,4 +1497,31 @@ gchar *win32_get_installation_dir(void)
 }
 
 
+gchar *win32_get_user_config_dir(void)
+{
+	HRESULT hr;
+	wchar_t path[MAX_PATH];
+	LPSTR w_title[512];
+
+	hr = SHGetFolderPathAndSubDirW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, L"geany", path);
+	if (SUCCEEDED(hr))
+	{
+		// GLib always uses UTF-8 for filename encoding on Windows
+		int u8_size = WideCharToMultiByte(CP_UTF8, 0, path, -1, NULL, 0, NULL, NULL);
+		if (u8_size > 0)
+		{
+			gchar *u8_path = g_malloc0(u8_size + 1);
+			if (u8_path != NULL &&
+				WideCharToMultiByte(CP_UTF8, 0, path, -1, u8_path, u8_size, NULL, NULL))
+			{
+				return u8_path;
+			}
+		}
+	}
+
+	// glib fallback
+	g_warning("Failed to retrieve Windows config dir, falling back to default");
+	return g_build_filename(g_get_user_config_dir(), "geany", NULL);
+}
+
 #endif


Modified: src/win32.h
2 lines changed, 2 insertions(+), 0 deletions(-)
===================================================================
@@ -71,6 +71,8 @@ gchar *win32_get_installation_dir(void);
 
 gchar *win32_expand_environment_variables(const gchar *str);
 
+gchar *win32_get_user_config_dir(void);
+
 G_END_DECLS
 
 #endif /* G_OS_WIN32 */



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list