From a1991c4d379cc76917dd8f85e68fcc9b0b3aa301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Sun, 29 Oct 2017 16:16:17 +0100 Subject: [PATCH 1/2] Use utility function to get a file URI prefix On Windows, we need "file:///" for local file URIs while on all other platforms the prefix is "file://" for absolute filenames. The utility function saves us from replicating the platform specific logic. --- src/utils.c | 22 +++++++++++++++------- src/utils.h | 1 + 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/utils.c b/src/utils.c index 9fb69bb1..0a03a68f 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1688,6 +1688,17 @@ gboolean utils_spawn_async(const gchar *dir, gchar **argv, gchar **env, GSpawnFl } +/* Returns "file:///" on Windows, "file://" everywhere else */ +const gchar *utils_get_uri_file_prefix(void) +{ +#ifdef G_OS_WIN32 + return "file:///"; +#else + return "file://"; +#endif +} + + /* Retrieves the path for the given URI. * It returns: * - the path which was determined by g_filename_from_uri() or GIO @@ -1893,16 +1904,13 @@ GSList *utils_get_config_files(const gchar *subdir) * an anchor link, e.g. "#some_anchor". */ gchar *utils_get_help_url(const gchar *suffix) { - gint skip; gchar *uri; + const gchar *uri_file_prefix = utils_get_uri_file_prefix(); + gint skip = strlen(uri_file_prefix); + uri = g_strconcat(uri_file_prefix, app->docdir, "/index.html", NULL); #ifdef G_OS_WIN32 - skip = 8; - uri = g_strconcat("file:///", app->docdir, "/index.html", NULL); g_strdelimit(uri, "\\", '/'); /* replace '\\' by '/' */ -#else - skip = 7; - uri = g_strconcat("file://", app->docdir, "/index.html", NULL); #endif if (! g_file_test(uri + skip, G_FILE_TEST_IS_REGULAR)) @@ -2115,7 +2123,7 @@ const gchar *utils_resource_dir(GeanyResourceDirType type) { # ifdef MAC_INTEGRATION gchar *prefix = gtkosx_application_get_resource_path(); - + resdirs[RESOURCE_DIR_DATA] = g_build_filename(prefix, "share", "geany", NULL); resdirs[RESOURCE_DIR_ICON] = g_build_filename(prefix, "share", "icons", NULL); resdirs[RESOURCE_DIR_DOC] = g_build_filename(prefix, "share", "doc", "geany", "html", NULL); diff --git a/src/utils.h b/src/utils.h index da14b43b..d2596d87 100644 --- a/src/utils.h +++ b/src/utils.h @@ -309,6 +309,7 @@ gboolean utils_str_has_upper(const gchar *str); gint utils_is_file_writable(const gchar *locale_filename); +const gchar *utils_get_uri_file_prefix(void); gchar *utils_get_path_from_uri(const gchar *uri); From cb669e2a019eb5cb9a62e39c886ce928350ba699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Sun, 29 Oct 2017 16:20:53 +0100 Subject: [PATCH 2/2] Use utils_get_uri_file_prefix() as file URI prefix utils_get_uri_file_prefix() gives "file:///" for Windows and "file://" for all other platforms. So we don't need "g_path_skip_root()" any longer. Using "g_path_skip_root()" removed the drive letter from the URI which worked only as long as the file to be opened was on drive C: (or whatever drive Windows considers as the default). But since local file URIs including the drive letter are supported on Windows, we should use it, so opening files on other drives works as well. Fixes #1018. --- src/build.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/build.c b/src/build.c index 55bce141..f68e7b70 100644 --- a/src/build.c +++ b/src/build.c @@ -1237,13 +1237,14 @@ static void on_build_menu_item(GtkWidget *w, gpointer user_data) bc = get_build_cmd(doc, grp, cmd, NULL); if (bc != NULL && strcmp(bc->command, "builtin") == 0) { + const gchar *uri_file_prefix; gchar *uri; if (doc == NULL) return; - uri = g_strconcat("file:///", g_path_skip_root(doc->file_name), NULL); + uri_file_prefix = utils_get_uri_file_prefix(); + uri = g_strconcat(uri_file_prefix, doc->file_name, NULL); utils_open_browser(uri); g_free(uri); - } else build_run_cmd(doc, cmd);