From e1ce9cfbecf432f8033ecf15322c2b273d377c34 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Enrico=20Tr=C3=B6ger?= Date: Thu, 10 Apr 2014 22:24:15 +0200 Subject: [PATCH] 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. --- src/main.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 07f569181..18fb1a90a 100644 --- a/src/main.c +++ b/src/main.c @@ -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(), -- 2.11.4.GIT