From 6dbb975c01e0bc355fc27397bb2f94fa5b733423 Mon Sep 17 00:00:00 2001 From: hogliux Date: Thu, 12 Apr 2018 10:29:13 +0100 Subject: [PATCH] Windows: Fixed an issue in the conversion from URL to Windows UNC file paths and vice versa --- modules/juce_core/network/juce_URL.cpp | 27 +++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/modules/juce_core/network/juce_URL.cpp b/modules/juce_core/network/juce_URL.cpp index c3322343cd..0bb25bff6b 100644 --- a/modules/juce_core/network/juce_URL.cpp +++ b/modules/juce_core/network/juce_URL.cpp @@ -148,6 +148,10 @@ URL::URL (File localFile) if (localFile == File()) return; + #if JUCE_WINDOWS + bool isUncPath = localFile.getFullPathName().startsWith ("\\\\"); + #endif + while (! localFile.isRoot()) { url = "/" + addEscapeChars (localFile.getFileName(), false) + url; @@ -156,8 +160,18 @@ URL::URL (File localFile) url = addEscapeChars (localFile.getFileName(), false) + url; - if (! url.startsWithChar (L'/')) - url = "/" + url; + #if JUCE_WINDOWS + if (isUncPath) + { + url = url.fromFirstOccurrenceOf ("/", false, false); + } + else + #endif + { + if (! url.startsWithChar (L'/')) + url = "/" + url; + } + url = "file://" + url; @@ -381,7 +395,9 @@ File URL::fileFromFileSchemeURL (const URL& fileURL) auto path = removeEscapeChars (fileURL.getDomain()).replace ("+", "%2B"); - #ifndef JUCE_WINDOWS + #ifdef JUCE_WINDOWS + bool isUncPath = (! fileURL.url.startsWith ("file:///")); + #else path = File::getSeparatorString() + path; #endif @@ -390,6 +406,11 @@ File URL::fileFromFileSchemeURL (const URL& fileURL) for (auto urlElement : urlElements) path += File::getSeparatorString() + removeEscapeChars (urlElement.replace ("+", "%2B")); + #ifdef JUCE_WINDOWS + if (isUncPath) + path = "\\\\" + path; + #endif + return path; }