diff options
author | Vincent Torri <vincent.torri@gmail.com> | 2021-02-06 14:49:54 +0000 |
---|---|---|
committer | Carsten Haitzler (Rasterman) <raster@rasterman.com> | 2021-02-06 14:49:54 +0000 |
commit | ec4ef6911591b0ce47616438dfd34626d9302537 (patch) | |
tree | bed0d387b7a2346040cc0b3d73acf64c0f758839 /src/lib | |
parent | d8d52861a619e7a6e1e7244ffb70a9a8b4819c07 (diff) | |
download | efl-ec4ef6911591b0ce47616438dfd34626d9302537.tar.gz |
Efreet: fix file:// scheme on Windows
Summary: On Windows, file:///c:/path/to/file is correct and not managed. Use a Win API for manage it correctly
Test Plan: test case
Reviewers: raster, cedric
Reviewed By: raster
Subscribers: #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12244
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/efreet/efreet_uri.c | 70 | ||||
-rw-r--r-- | src/lib/efreet/meson.build | 5 |
2 files changed, 75 insertions, 0 deletions
diff --git a/src/lib/efreet/efreet_uri.c b/src/lib/efreet/efreet_uri.c index 44fe54a35f..2b64556159 100644 --- a/src/lib/efreet/efreet_uri.c +++ b/src/lib/efreet/efreet_uri.c @@ -2,8 +2,15 @@ # include <config.h> #endif +#include <stdlib.h> +#include <string.h> #include <ctype.h> +#ifdef _WIN32 +# include <windows.h> +# include <shlwapi.h> +#endif + #ifndef _POSIX_HOST_NAME_MAX #define _POSIX_HOST_NAME_MAX 255 #endif @@ -28,6 +35,64 @@ efreet_uri_decode(const char *full_uri) EINA_SAFETY_ON_NULL_RETURN_VAL(full_uri, NULL); /* An uri should be in the form <scheme>:[<authority>][<path>][<query>][<fragment>] */ + + /* + * Specific code for Windows when the scheme part of full_uri is 'file', + * for local Windows file path. + * see https://docs.microsoft.com/en-us/archive/blogs/ie/file-uris-in-windows + * + * Correct syntax : + * file:///c:/path/to/file + * + * The returned path must be c:\path\to\file + */ +#ifdef _WIN32 + + *scheme = 0; + *authority = 0; + *path = 0; + + if (strncasecmp(full_uri, "file://", strlen("file://")) == 0) + { + HRESULT res; + DWORD len; +# ifdef UNICODE + wchar_t buf[MAX_PATH]; + wchar_t *w_full_uri; + char *uri; + + w_full_uri = evil_utf8_to_utf16(full_uri); + if (!w_full_uri) + return NULL; + + if (wcslen(w_full_uri) > 2048) + { + free(w_full_uri); + return NULL; + } + + len = sizeof(buf); + res = PathCreateFromUrl(w_full_uri, buf, &len, 0UL); + free(w_full_uri); + if (res != S_OK) + return NULL; + uri = evil_utf16_to_utf8(buf); + if (uri) + { + strncpy(path, uri, sizeof(path)); + path[sizeof(path)-1] = 0; + goto win32_file_scheme; + } +#else + len = sizeof(path); + res = PathCreateFromUrl(full_uri, path, &len, 0UL); + if (res == S_OK) + goto win32_file_scheme; +#endif + return NULL; + } +#endif + sep = strchr(full_uri, ':'); if (!sep) return NULL; /* check if we have a Windows PATH, that is a letter follow by a colon */ @@ -77,6 +142,11 @@ efreet_uri_decode(const char *full_uri) path[i] = *p; } +#ifdef _WIN32 + win32_file_scheme: + strcpy(scheme, "file"); +#endif + uri = NEW(Efreet_Uri, 1); if (!uri) return NULL; diff --git a/src/lib/efreet/meson.build b/src/lib/efreet/meson.build index 41d3113566..1d02f3db1f 100644 --- a/src/lib/efreet/meson.build +++ b/src/lib/efreet/meson.build @@ -36,6 +36,11 @@ efreet_ext_deps = [buildsystem_simple, intl, m] package_c_args += ['-DDATA_DIR="'+dir_data+'"'] +if sys_windows + shlwapi = cc.find_library('shlwapi') + efreet_ext_deps += [shlwapi] +endif + efreet_lib = library('efreet', efreet_src, dependencies: efreet_pub_deps + efreet_ext_deps + efreet_deps, |