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

Method GetMappedDriveFilePath

PathCopyCopy/plugins/src/UNCPathPlugin.cpp:117–138  ·  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. @returns true if the file was on a mapped network drive and we fetched its network path.

Source from the content-addressed store, hash-verified

115 // @returns true if the file was on a mapped network drive and we fetched its network path.
116 //
117 bool UNCPathPlugin::GetMappedDriveFilePath(std::wstring& p_rFilePath) const
118 {
119 // WNetGetUniversalName allows us to get the network path
120 // if file is on a mapped drive.
121 bool converted = false;
122 DWORD bufferSize = INITIAL_BUFFER_SIZE;
123 ArrayAutoPtr<char> apBuffer;
124 DWORD ret = ERROR_MORE_DATA;
125 while (ret == ERROR_MORE_DATA) {
126 apBuffer = new char[bufferSize];
127 ret = ::WNetGetUniversalNameW(p_rFilePath.c_str(),
128 UNIVERSAL_NAME_INFO_LEVEL,
129 apBuffer.Get(),
130 &bufferSize);
131 }
132 if (ret == NO_ERROR) {
133 // Got UNC path, return it.
134 p_rFilePath.assign(reinterpret_cast<UNIVERSAL_NAME_INFO*>(apBuffer.Get())->lpUniversalName);
135 converted = true;
136 }
137 return converted;
138 }
139
140 //
141 // Checks if the given file resides in a directory in a public network share.

Callers

nothing calls this directly

Calls 1

GetMethod · 0.45

Tested by

no test coverage detected