MCPcopy Create free account
hub / github.com/amule-project/amule / GetPublicSharedDirName

Method GetPublicSharedDirName

src/SharedFileList.cpp:1322–1395  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1320
1321
1322wxString CSharedFileList::GetPublicSharedDirName(const CPath& dir)
1323{
1324 // safety check: is the directory supposed to be shared after all?
1325 if (!IsShared(dir)) {
1326 wxFAIL;
1327 return "";
1328 }
1329 // check if the public name for the directory is cached in our Map
1330 StringPathMap::const_iterator it;
1331 for (it = m_PublicSharedDirNames.begin(); it != m_PublicSharedDirNames.end(); ++it) {
1332 if (it->second.IsSameDir(dir)) {
1333 // public name for directory was determined earlier
1334 return it->first;
1335 }
1336 }
1337
1338 // we store the path separator (forward or back slash) for quick access
1339 wxChar cPathSeparator = wxFileName::GetPathSeparator();
1340
1341 // determine and cache the public name for "dir" ...
1342 // We need to use the 'raw' filename, so the receiving client can recognize it.
1343 wxString strDirectoryTmp = dir.GetRaw();
1344 if (strDirectoryTmp.EndsWith(&cPathSeparator)) {
1345 strDirectoryTmp.RemoveLast();
1346 }
1347
1348 wxString strPublicName;
1349 int iPos;
1350 // check all the subdirectories in the path for being shared
1351 // the public name will consist of these concatenated
1352 while ((iPos = strDirectoryTmp.Find( cPathSeparator, true )) != wxNOT_FOUND) {
1353 strPublicName = strDirectoryTmp.Right(strDirectoryTmp.Length() - iPos) + strPublicName;
1354 strDirectoryTmp.Truncate(iPos);
1355 if (!IsShared(CPath(strDirectoryTmp)))
1356 break;
1357 }
1358 if (!strPublicName.IsEmpty()) {
1359 // remove first path separator ???
1360 wxASSERT( strPublicName.GetChar(0) == cPathSeparator );
1361 strPublicName = strPublicName.Right(strPublicName.Length() - 1);
1362 } else {
1363 // must be a rootdirectory on Windows
1364 wxASSERT( strDirectoryTmp.Length() == 2 );
1365 strPublicName = strDirectoryTmp;
1366 }
1367 // we have the name, make sure it is unique by appending an index if necessary
1368 if (m_PublicSharedDirNames.find(strPublicName) != m_PublicSharedDirNames.end()) {
1369 wxString strUniquePublicName;
1370 for (iPos = 2; ; ++iPos) {
1371 strUniquePublicName = CFormat("%s_%i") % strPublicName % iPos;
1372
1373 if (m_PublicSharedDirNames.find(strUniquePublicName) == m_PublicSharedDirNames.end()) {
1374 AddDebugLogLineN(logClient, CFormat("Using public name '%s' for directory '%s'")
1375 % strUniquePublicName
1376 % dir.GetPrintable());
1377 m_PublicSharedDirNames.insert(std::pair<wxString, CPath> (strUniquePublicName, dir));
1378 return strUniquePublicName;
1379 }

Callers 1

SendSharedDirectoriesMethod · 0.80

Calls 10

CFormatClass · 0.85
IsSameDirMethod · 0.80
GetRawMethod · 0.80
LengthMethod · 0.80
GetPrintableMethod · 0.80
insertMethod · 0.80
CPathClass · 0.70
beginMethod · 0.45
endMethod · 0.45
IsEmptyMethod · 0.45

Tested by

no test coverage detected