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

Method GetMappedDriveFilePath

PathCopyCopy/src/PluginUtils.cpp:213–235  ·  view source on GitHub ↗

Checks if the given file resides on a mapped network drive. If it does, returns its corresponding network path. Ex: N:\Data\File.txt -> \\server\share\Data\File.txt @param p_rFilePath Local file path. Upon exit, will contain network path. @return true if the file was on a mapped network drive and we fetched its network path.

Source from the content-addressed store, hash-verified

211 // @return true if the file was on a mapped network drive and we fetched its network path.
212 //
213 bool PluginUtils::GetMappedDriveFilePath(std::wstring& p_rFilePath)
214 {
215 // WNetGetUniversalName allows us to get the network path
216 // if file is on a mapped drive.
217 bool converted = false;
218 DWORD bufferSize = INITIAL_BUFFER_SIZE;
219 std::vector<char> vBuffer;
220 DWORD ret = ERROR_MORE_DATA;
221 while (ret == ERROR_MORE_DATA) {
222 vBuffer.resize(bufferSize, '\0');
223 ret = ::WNetGetUniversalNameW(p_rFilePath.c_str(),
224 UNIVERSAL_NAME_INFO_LEVEL,
225 vBuffer.data(),
226 &bufferSize);
227 }
228 if (ret == NO_ERROR) {
229 // Got UNC path, return it.
230#pragma warning(suppress: 26490) // No choice but to use reinterpret_cast here, can't change the Win32 API
231 p_rFilePath.assign(reinterpret_cast<UNIVERSAL_NAME_INFOW*>(vBuffer.data())->lpUniversalName);
232 converted = true;
233 }
234 return converted;
235 }
236
237 //
238 // Checks if the given file resides in a directory in a network share.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected