Returns the path of the specified file in file URI format @param p_File File path. @return Internet (e.g., URI) path.
| 85 | // @return Internet (e.g., URI) path. |
| 86 | // |
| 87 | std::wstring InternetPathPlugin::GetPath(const std::wstring& p_File) const |
| 88 | { |
| 89 | // First call inherited version to get the path. |
| 90 | std::wstring path = LongUNCPathPlugin::GetPath(p_File); |
| 91 | |
| 92 | // There are two possible formats we use. For local files, we use |
| 93 | // C:\path\to\file -> file:///C:/path/to/file |
| 94 | // For network shares, we use |
| 95 | // \\computer\share\path\to\file -> file://computer/share/path/to/file |
| 96 | if (path.find(NETWORK_SHARE_PREFIX) == 0) { |
| 97 | path = NETWORK_FILE_URI_PREFIX + path.replace(0, ::wcslen(NETWORK_SHARE_PREFIX), L""); |
| 98 | } else { |
| 99 | path = FILE_URI_PREFIX + path; |
| 100 | } |
| 101 | |
| 102 | // Now switch backslashes to slashes. |
| 103 | std::replace(path.begin(), path.end(), L'\\', L'/'); |
| 104 | |
| 105 | // Switch whitespace for %20. |
| 106 | std::wstringstream newPathSS; |
| 107 | std::wstring::size_type oldPos = 0, whitespacePos = path.find_first_of(WHITESPACE_TO_ESCAPE); |
| 108 | while (whitespacePos != std::wstring::npos) { |
| 109 | newPathSS << path.substr(oldPos, whitespacePos - oldPos) << WHITESPACE_ESCAPE_SEQ; |
| 110 | oldPos = whitespacePos + 1; |
| 111 | whitespacePos = path.find_first_of(WHITESPACE_TO_ESCAPE, oldPos); |
| 112 | } |
| 113 | if (oldPos < path.size()) { |
| 114 | newPathSS << path.substr(oldPos, path.size() - oldPos); |
| 115 | } |
| 116 | path = newPathSS.str(); |
| 117 | |
| 118 | return path; |
| 119 | } |
| 120 | |
| 121 | // |
| 122 | // Protected constructor with custom description and help text resources. |