MCPcopy Create free account
hub / github.com/clechasseur/pathcopycopy / GetPath

Method GetPath

PathCopyCopy/plugins/src/WSLPathPlugin.cpp:69–96  ·  view source on GitHub ↗

Returns the WSL path of the specified file. @param p_File File path. @return File path in WSL format (/mnt/c/...)

Source from the content-addressed store, hash-verified

67 // @return File path in WSL format (/mnt/c/...)
68 //
69 std::wstring WSLPathPlugin::GetPath(const std::wstring& p_File) const
70 {
71 // Call parent to get Unix path.
72 std::wstring path = UnixPathPlugin::GetPath(p_File);
73
74 // Get WSL path prefix, from settings if possible.
75 std::wstring wslPathPrefix = DEFAULT_MNT_PREFIX;
76 if (m_pSettings != nullptr) {
77 wslPathPrefix = m_pSettings->GetWSLPathPrefix();
78 }
79
80 // Check if the file begins with a drive letter. If so,
81 // remove the drive letter and replace it with /mnt/letter.
82 [[gsl::suppress(type.4)]] // Compiler considers foo{bar} to be a C-style cast
83 if (path.size() >= 3 && path.at(1) == L':') {
84 std::wstringstream newPathSS;
85 newPathSS << wslPathPrefix << L'/' // The WSL path prefix
86 << wchar_t{::towlower(path.front())} // Drive letter
87 << path.substr(2); // Rest of the path, including the slash after that : we had.
88 path = newPathSS.str();
89 }
90
91 // Escape spaces bash-style. This works without quotes.
92 StringUtils::ReplaceAll(path, L" ", L"\\ ");
93
94 // Return modified path.
95 return path;
96 }
97
98 } // namespace Plugins
99

Callers

nothing calls this directly

Calls 2

GetWSLPathPrefixMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected