On 14-08-22 11:23 AM, Enrico Tröger wrote:
Hi,

lately, I started building a new Windows installer which includes a
recent GTK 2.24 runtime for Windows which need for future releases.

While most things went fine I noticed one problem:

GTK, in detail Glib, changed the way g_get_user_data_dir() works on Windows:
in older releases, something GLib 2.28 or 2.26 and older,
g_get_user_data_dir() returned c:\users\<username>\AppData\Roaming, in
newer GLib versions it returns c:\users\<username>\AppData\Local.

This affects users who already have a config directory located in
<...>\Roaming and Geany would look in <...>\Local now.

This is the change I'm talking about:
https://git.gnome.org/browse/glib/commit/glib/gutils.c?id=9d80c361418f94c609840ec9f83741aede7e482c


How do we want to handle this?

- continue using the <...>\Roaming directory (and so not using
g_get_user_data_dir() anymore)


If we went this route we could use something like the attached patch[0]. Maybe it's what the linked commit is referring to about proper Windows programs probably not using those GLib functions?

- leave the code as it is, resulting in a new complete config for users

- add some code to check if a config in <...>\Roaming exists and if so,
move it to <...>\Local


I was thinking about it a bit and it might be good to keep using the "Roaming" one (ie. whatever Win32 API gives as correct dir) since IIUC it allows users on a domain to sync their config between machines on login/logout. As mentioned in the linked commit, the function we use (g_get_user_config_dir()) only changed to match g_get_user_data_dir(), not because it's the actually a better or more appropriate directory.

Anyway, I don't actually care much either way since I rarely use Windows, so any fix is fine to me :)

Cheers,
Matthew Brush

[0]: Untested since my win32 geany build environment is once again broken, it might need tweaking win32 version macros before including windows.h or using SHGetFolderPath depending on which versions of Windows we are supporting. Also, the encoding stuff could probably be handled nicer, without going through UTF-8 step.
diff --git a/src/main.c b/src/main.c
index 279ecdf..cc92906 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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)
diff --git a/src/utils.c b/src/utils.c
index e4c5448..574ca8b 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -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
+}
diff --git a/src/utils.h b/src/utils.h
index c4df0bd..7e14099 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -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 */
diff --git a/src/win32.c b/src/win32.c
index eaf5afb..3fe44e6 100644
--- a/src/win32.c
+++ b/src/win32.c
@@ -1497,4 +1497,34 @@ gchar *win32_get_installation_dir(void)
 }
 
 
+gchar *win32_get_user_config_dir(void)
+{
+	wchar_t wdata_dir[MAX_PATH] = {0};
+
+	if (SHGetSpecialFolderPath(NULL, CSIDL_APPDATA, TRUE))
+	{
+		/* FIXME: should probably pre-flight the WideCharToMultiByte() call
+		 * to get the proper length since this UTF-8 encoded bytes which will
+		 * probably be more than when encoded as UTF-16/wchar */
+		gchar u8data_dir[MAX_PATH+1] = {0};
+
+		if (WideCharToMultiByte(CP_UTF8, 0, wdata_dir, -1, u8data_dir, MAX_PATH, NULL, NULL))
+		{
+			gchar *locale_data_dir;
+
+			locale_data_dir = g_win32_locale_filename_from_utf8(u8data_dir);
+
+			if (locale_data_dir)
+			{
+				gchar *full_path;
+				full_path = g_build_filename(locale_data_dir, "geany", NULL);
+				g_free(locale_data_dir);
+				return full_path;
+			}
+		}
+	}
+
+	return g_build_filename(g_get_user_config_dir(), "geany", NULL);
+}
+
 #endif
diff --git a/src/win32.h b/src/win32.h
index 72de162c..ad1af90 100644
--- a/src/win32.h
+++ b/src/win32.h
@@ -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 */
_______________________________________________
Devel mailing list
Devel@lists.geany.org
https://lists.geany.org/cgi-bin/mailman/listinfo/devel

Reply via email to