From 2df3e2db0b44b81f627c926062cb76661b03f1ab Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Wed, 31 Jul 2024 17:47:18 +0400 Subject: [PATCH] ContentManager::handleZimFileInMonitoredDir() Indentation is intentionally not fixed (to keep the diff minimal). --- src/contentmanager.cpp | 15 +++++++++++---- src/contentmanager.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/contentmanager.cpp b/src/contentmanager.cpp index 5fd32ea..0755e98 100644 --- a/src/contentmanager.cpp +++ b/src/contentmanager.cpp @@ -905,10 +905,18 @@ void ContentManager::handleDisappearedZimFiles(const QString& dirPath, const QSt size_t ContentManager::handleNewZimFiles(const QString& dirPath, const QStringSet& fileNames) { size_t countOfSuccessfullyAddedZims = 0; + for (const auto& file : fileNames) { + const bool addedToLib = handleZimFileInMonitoredDir(dirPath, file); + countOfSuccessfullyAddedZims += addedToLib; + } + return countOfSuccessfullyAddedZims; +} + +int ContentManager::handleZimFileInMonitoredDir(QString dirPath, QString file) +{ const auto kiwixLib = mp_library->getKiwixLibrary(); kiwix::Manager manager(kiwixLib); auto& zimsInDir = m_knownZimsInDir[dirPath]; - for (const auto& file : fileNames) { const auto bookPath = QDir::toNativeSeparators(dirPath + "/" + file); DBGOUT("directory monitoring: file appeared: " << bookPath); if ( mp_library->isBeingDownloadedByUs(bookPath) ) { @@ -916,12 +924,11 @@ size_t ContentManager::handleNewZimFiles(const QString& dirPath, const QStringSe } else if ( manager.addBookFromPath(bookPath.toStdString()) ) { DBGOUT(" and was added to the library"); zimsInDir.insert(file); - ++countOfSuccessfullyAddedZims; + return 1; } else { DBGOUT(" but could not be added to the library"); } - } - return countOfSuccessfullyAddedZims; + return 0; } void ContentManager::updateLibraryFromDir(QString dirPath) diff --git a/src/contentmanager.h b/src/contentmanager.h index 343eebd..f692adb 100644 --- a/src/contentmanager.h +++ b/src/contentmanager.h @@ -120,6 +120,7 @@ private: // functions void updateLibraryFromDir(QString dir); void handleDisappearedZimFiles(const QString& dirPath, const QStringSet& fileNames); size_t handleNewZimFiles(const QString& dirPath, const QStringSet& fileNames); + int handleZimFileInMonitoredDir(QString dirPath, QString fileName); bool handleDisappearedBook(QString bookId); // Get the book with the specified id from