From 31613d15ef0f4052829bd2d161c2d80acfa5e1d6 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 13 Jun 2023 14:36:55 +1000 Subject: [PATCH] ImBuf: WIN32 UNC support for path to URI conversion Correct the drive letter check & support UNC paths. --- source/blender/imbuf/intern/thumbs.cc | 28 +++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/source/blender/imbuf/intern/thumbs.cc b/source/blender/imbuf/intern/thumbs.cc index d599a4a9fb7..88db853f943 100644 --- a/source/blender/imbuf/intern/thumbs.cc +++ b/source/blender/imbuf/intern/thumbs.cc @@ -218,13 +218,29 @@ static bool uri_from_filename(const char *path, char *uri) char orig_uri[URI_MAX]; #ifdef WIN32 - if (strlen(path) < 2 && path[1] != ':') { - /* Not a correct absolute path. */ - return 0; + bool path_is_unc = BLI_path_is_unc(path); + char path_unc_normalized[FILE_MAX]; + if (path_is_unc) { + STRNCPY(path_unc_normalized, path); + BLI_path_normalize_unc(path_unc_normalized, sizeof(path_unc_normalized)); + path = path_unc_normalized; + /* Assign again because a normalized UNC path may resolve to a drive letter. */ + path_is_unc = BLI_path_is_unc(path); + } + + if (path_is_unc) { + /* Skip over the `\\` prefix, it's not needed for a URI. */ + SNPRINTF(orig_uri, "file://%s", BLI_path_slash_skip(path)); + } + else if (BLI_path_is_win32_drive(path)) { + SNPRINTF(orig_uri, "file:///%s", path); + /* Always use an uppercase drive/volume letter in the URI. */ + orig_uri[8] = char(toupper(orig_uri[8])); + } + else { + /* Not a correct absolute path with a drive letter or UNC prefix. */ + return false; } - SNPRINTF(orig_uri, "file:///%s", path); - /* Always use an uppercase drive/volume letter in the URI. */ - orig_uri[8] = char(toupper(orig_uri[8])); BLI_str_replace_char(orig_uri, '\\', '/'); #else SNPRINTF(orig_uri, "file://%s", path);