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

Method AddFilesFromDirectory

src/SharedFileList.cpp:428–491  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

426
427
428unsigned CSharedFileList::AddFilesFromDirectory(const CPath& directory, TaskList & hashTasks,
429 const ReloadYieldCb & yieldCb, size_t & scanned, bool & aborted)
430{
431 // Do not allow these folders to be shared:
432 // - The .aMule folder
433 // - The Temp folder
434 // - The users home-dir
435 if (CheckDirectory(wxGetHomeDir(), directory)) {
436 return 0;
437 } else if (CheckDirectory(thePrefs::GetConfigDir(), directory)) {
438 return 0;
439 } else if (CheckDirectory(thePrefs::GetTempDir().GetRaw(), directory)) {
440 return 0;
441 }
442
443 if (!directory.DirExists()) {
444 AddLogLineNS(CFormat(_("Shared directory not found, skipping: %s"))
445 % directory.GetPrintable());
446
447 return 0;
448 }
449
450 CDirIterator::FileType searchFor = CDirIterator::FileNoHidden;
451 if (thePrefs::ShareHiddenFiles()) {
452 searchFor = CDirIterator::File;
453 }
454
455 const int extraFlags = thePrefs::FollowSymlinksInShares() ? 0 : wxDIR_NO_FOLLOW;
456
457 unsigned knownFiles = 0;
458 unsigned addedFiles = 0;
459
460 // Yield to the caller every kYieldEvery files so the UI can stay
461 // responsive on big shared trees. 256 strikes a balance between
462 // progress-bar responsiveness (~4 updates/s on a 1 ms-per-file
463 // machine) and the overhead of the callback itself.
464 constexpr size_t kYieldEvery = 256;
465
466 CDirIterator SharedDir(directory);
467
468 for (CPath fname = SharedDir.GetFirstFile(searchFor, wxEmptyString, extraFlags); fname.IsOk(); fname = SharedDir.GetNextFile()) {
469 if (yieldCb && ++scanned % kYieldEvery == 0) {
470 if (!yieldCb(scanned)) {
471 aborted = true;
472 return addedFiles;
473 }
474 } else if (!yieldCb) {
475 ++scanned;
476 }
477
478 switch (AddPathToShares(directory, fname, hashTasks)) {
479 case kAddPathQueued: addedFiles++; break;
480 case kAddPathKnown: knownFiles++; break;
481 case kAddPathSkipped: break;
482 }
483 }
484
485 if ((addedFiles == 0) && (knownFiles == 0)) {

Callers

nothing calls this directly

Calls 9

CheckDirectoryFunction · 0.85
GetConfigDirFunction · 0.85
CFormatClass · 0.85
GetRawMethod · 0.80
DirExistsMethod · 0.80
GetPrintableMethod · 0.80
GetFirstFileMethod · 0.80
GetNextFileMethod · 0.80
IsOkMethod · 0.45

Tested by

no test coverage detected