From 681e6c27bcf2f536a88fb6bc5ca26cdb66bf22dd Mon Sep 17 00:00:00 2001 From: Casey Langen Date: Thu, 3 Jan 2019 21:32:18 -0800 Subject: [PATCH] Fixed some and simplified Indexer with code related to rescanning sources. Also fixed GmeIndexerSource -- it seems to be working now --- src/core/library/Indexer.cpp | 68 ++++++--------------- src/plugins/gmedecoder/Constants.h | 7 +-- src/plugins/gmedecoder/GmeIndexerSource.cpp | 9 ++- src/plugins/gmedecoder/GmeIndexerSource.h | 3 +- 4 files changed, 28 insertions(+), 59 deletions(-) diff --git a/src/core/library/Indexer.cpp b/src/core/library/Indexer.cpp index 4ebf15762..88f2fc1f0 100644 --- a/src/core/library/Indexer.cpp +++ b/src/core/library/Indexer.cpp @@ -258,46 +258,31 @@ void Indexer::Synchronize(const SyncContext& context, boost::asio::io_service* i } } - /* process ALL IIndexerSource plugins, if applicable */ - if (type == SyncType::All || (type == SyncType::Sources && sourceId == 0)) { - for (auto it : this->sources) { - if (this->Bail()) { - break; - } - - this->currentSource = it; - if (this->SyncSource(it.get(), paths) == ScanRollback) { - this->trackTransaction->Cancel(); - } - this->trackTransaction->CommitAndRestart(); - + /* refresh sources */ + for (auto it : this->sources) { + if (this->Bail()) { break; } - this->currentSource.reset(); - } - - /* otherwise, we may have just been asked to index a single one... */ - else if (type == SyncType::Sources && sourceId != 0) { - for (auto it : this->sources) { - if (this->Bail()) { - break; - } - - if (it->SourceId() == sourceId) { - this->currentSource = it; - if (this->SyncSource(it.get(), paths) == ScanRollback) { - this->trackTransaction->Cancel(); - } - this->trackTransaction->CommitAndRestart(); - } + if (sourceId != 0 && sourceId != it->SourceId()) { + continue; /* asked to scan a specific source, and this isn't it. */ } - this->currentSource.reset(); + this->currentSource = it; + if (this->SyncSource(it.get(), paths) == ScanRollback) { + this->trackTransaction->Cancel(); + } + this->trackTransaction->CommitAndRestart(); + + if (sourceId != 0) { + break; /* done with the one we were asked to scan */ + } } + this->currentSource.reset(); + /* process local files */ - if (type == SyncType::All || type == SyncType::Local) { + if (type != SyncType::Sources) { if (logFile) { fprintf(logFile, "\n\nSYNCING LOCAL FILES:\n"); } @@ -386,25 +371,6 @@ void Indexer::ReadMetadataFromFile( it++; } - /* no tag? well... if a decoder can play it, add it to the database - with the file as the name. */ - if (!saveToDb) { - std::string fullPath = file.string(); - auto it = this->audioDecoders.begin(); - while (it != this->audioDecoders.end()) { - if ((*it)->CanHandle(fullPath.c_str())) { - if (logFile) { - fprintf(logFile, " - %s\n", file.string().c_str()); - } - - saveToDb = true; - track.SetValue("title", file.leaf().string().c_str()); - break; - } - ++it; - } - } - /* write it to the db, if read successfully */ if (saveToDb) { track.SetValue("path_id", pathId.c_str()); diff --git a/src/plugins/gmedecoder/Constants.h b/src/plugins/gmedecoder/Constants.h index 7f5bb6056..aaa58947c 100644 --- a/src/plugins/gmedecoder/Constants.h +++ b/src/plugins/gmedecoder/Constants.h @@ -53,11 +53,10 @@ static const std::set FORMATS = { ".nsf", ".ay", ".gbs", ".hes", ".kss" }; -static inline bool canHandle(const std::string& fn) { +static inline bool canHandle(std::string fn) { + std::transform(fn.begin(), fn.end(), fn.begin(), ::tolower); for (auto& ext : FORMATS) { - std::string lowerFn; - std::transform(fn.begin(), fn.end(), lowerFn.begin(), ::tolower); - if (lowerFn.rfind(ext) == lowerFn.size() - ext.size()) { + if (fn.rfind(ext) == fn.size() - ext.size()) { return true; } } diff --git a/src/plugins/gmedecoder/GmeIndexerSource.cpp b/src/plugins/gmedecoder/GmeIndexerSource.cpp index d52f3b9b1..ce201f030 100644 --- a/src/plugins/gmedecoder/GmeIndexerSource.cpp +++ b/src/plugins/gmedecoder/GmeIndexerSource.cpp @@ -65,7 +65,11 @@ static bool exists(const std::string& externalId) { return access(fn.c_str(), R_OK) != -1; } -static void updateMetadata(IIndexerSource* source, const std::string& fn, IIndexerWriter* indexer) { +static void updateMetadata( + const std::string& fn, + IIndexerSource* source, + IIndexerWriter* indexer) +{ gme_t* data = nullptr; gme_err_t err = gme_open_file(fn.c_str(), &data, 44100); if (err) { @@ -144,7 +148,8 @@ static void scanDirectory(const std::string& path, IIndexerSource* source, IInde else { std::string fn = entry->d_name; if (canHandle(fn)) { - updateMetadata(source, fn, indexer); + std::string fullFn = path + "/" + fn; + updateMetadata(fullFn, source, indexer); } } } diff --git a/src/plugins/gmedecoder/GmeIndexerSource.h b/src/plugins/gmedecoder/GmeIndexerSource.h index 27312e1fa..df0598bff 100644 --- a/src/plugins/gmedecoder/GmeIndexerSource.h +++ b/src/plugins/gmedecoder/GmeIndexerSource.h @@ -39,8 +39,7 @@ #include #include -class GmeIndexerSource: - public musik::core::sdk::IIndexerSource { +class GmeIndexerSource: public musik::core::sdk::IIndexerSource { public: GmeIndexerSource(); ~GmeIndexerSource();