[geany/geany] e1ce9c: Change the working directory on Windows properly

Enrico Tröger git-noreply at xxxxx
Thu Apr 10 20:24:15 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:        Thu, 10 Apr 2014 20:24:15 UTC
Commit:      e1ce9cfbecf432f8033ecf15322c2b273d377c34
             https://github.com/geany/geany/commit/e1ce9cfbecf432f8033ecf15322c2b273d377c34

Log Message:
-----------
Change the working directory on Windows properly

On Windows we need to change the working directory on startup to not
lock the directory Geany was started from (bug #2626124).
However we can't change the directory to late in the startup process
otherwise plugins maybe unable to load resources from the installation
directory.

Though we also can't change it too early otherwise opening files given
with relative paths in Geany from the command line won't work anymore
(bug #3613096).

This change should fix both issues by changing the working directory after
command line file handling happened and before plugins will be loaded.


Modified Paths:
--------------
    src/main.c

Modified: src/main.c
14 files changed, 11 insertions(+), 3 deletions(-)
===================================================================
@@ -380,13 +380,17 @@ static void get_line_and_column_from_filename(gchar *filename, gint *line, gint
 
 
 #ifdef G_OS_WIN32
-static void change_working_directory_on_windows(const gchar *install_dir)
+static void change_working_directory_on_windows()
 {
+	gchar *install_dir = win32_get_installation_dir();
+
 	/* On Windows, change the working directory to the Geany installation path to not lock
 	 * the directory of a file passed as command line argument (see bug #2626124).
 	 * This also helps if plugins or other code uses relative paths to load
 	 * any additional resources (e.g. share/geany-plugins/...). */
 	win32_set_working_directory(install_dir);
+
+	g_free(install_dir);
 }
 #endif
 
@@ -405,8 +409,6 @@ static void setup_paths(void)
 	data_dir = g_build_filename(install_dir, "data", NULL); /* e.g. C:\Program Files\geany\data */
 	doc_dir = g_build_filename(install_dir, "doc", NULL);
 
-	change_working_directory_on_windows(install_dir);
-
 	g_free(install_dir);
 #else
 	data_dir = g_build_filename(GEANY_DATADIR, "geany", NULL); /* e.g. /usr/share/geany */
@@ -1099,6 +1101,12 @@ gint main(gint argc, gchar **argv)
 	}
 #endif
 
+#ifdef G_OS_WIN32
+	/* after we initialized the socket code and handled command line args,
+	 * let's change the working directory on Windows to not lock it */
+	change_working_directory_on_windows();
+#endif
+
 	locale = get_locale();
 	geany_debug("Geany %s, %s",
 		main_get_version_string(),



--------------
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