Fix handling of network path (UNC path) in CustomFileDialog
Use STL algorithms for path transformation. Fix #9527, close #9551
This commit is contained in:
parent
26dad277c9
commit
064d844a41
|
@ -382,18 +382,25 @@ private:
|
||||||
if (fileName.empty())
|
if (fileName.empty())
|
||||||
return false;
|
return false;
|
||||||
bool transformed = false;
|
bool transformed = false;
|
||||||
// Transform to a Windows path.
|
// Replace a forward-slash with a backslash.
|
||||||
size_t pos = 0;
|
std::replace_if(fileName.begin(), fileName.end(),
|
||||||
while ((pos = fileName.find('/', pos)) != generic_string::npos)
|
[&transformed](generic_string::value_type c)
|
||||||
{
|
{
|
||||||
fileName[pos] = '\\';
|
const bool eq = (c == '/');
|
||||||
++pos;
|
transformed |= eq;
|
||||||
transformed = true;
|
return eq;
|
||||||
}
|
},
|
||||||
|
'\\');
|
||||||
// If there are two or more double backslash, then change it to single.
|
// If there are two or more double backslash, then change it to single.
|
||||||
while (fileName.find(_T("\\\\")) != generic_string::npos)
|
// Start from 2nd element to keep a path that starts from "\\".
|
||||||
|
auto last = std::unique(fileName.begin() + 1, fileName.end(),
|
||||||
|
[](generic_string::value_type a, generic_string::value_type b)
|
||||||
|
{
|
||||||
|
return a == b && a == '\\';
|
||||||
|
});
|
||||||
|
if (last != fileName.end())
|
||||||
{
|
{
|
||||||
fileName.replace(fileName.find(_T("\\\\")), 2, _T("\\"));
|
fileName.erase(last, fileName.end());
|
||||||
transformed = true;
|
transformed = true;
|
||||||
}
|
}
|
||||||
return transformed;
|
return transformed;
|
||||||
|
|
Loading…
Reference in New Issue