Fixed some and simplified Indexer with code related to rescanning

sources. Also fixed GmeIndexerSource -- it seems to be working now
This commit is contained in:
Casey Langen 2019-01-03 21:32:18 -08:00
parent 31dd2a5f79
commit 681e6c27bc
4 changed files with 28 additions and 59 deletions

View File

@ -258,46 +258,31 @@ void Indexer::Synchronize(const SyncContext& context, boost::asio::io_service* i
} }
} }
/* process ALL IIndexerSource plugins, if applicable */ /* refresh sources */
if (type == SyncType::All || (type == SyncType::Sources && sourceId == 0)) {
for (auto it : this->sources) { for (auto it : this->sources) {
if (this->Bail()) { if (this->Bail()) {
break; break;
} }
if (sourceId != 0 && sourceId != it->SourceId()) {
continue; /* asked to scan a specific source, and this isn't it. */
}
this->currentSource = it; this->currentSource = it;
if (this->SyncSource(it.get(), paths) == ScanRollback) { if (this->SyncSource(it.get(), paths) == ScanRollback) {
this->trackTransaction->Cancel(); this->trackTransaction->Cancel();
} }
this->trackTransaction->CommitAndRestart(); this->trackTransaction->CommitAndRestart();
break; if (sourceId != 0) {
} break; /* done with the one we were asked to scan */
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();
} }
} }
this->currentSource.reset(); this->currentSource.reset();
}
/* process local files */ /* process local files */
if (type == SyncType::All || type == SyncType::Local) { if (type != SyncType::Sources) {
if (logFile) { if (logFile) {
fprintf(logFile, "\n\nSYNCING LOCAL FILES:\n"); fprintf(logFile, "\n\nSYNCING LOCAL FILES:\n");
} }
@ -386,25 +371,6 @@ void Indexer::ReadMetadataFromFile(
it++; 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 */ /* write it to the db, if read successfully */
if (saveToDb) { if (saveToDb) {
track.SetValue("path_id", pathId.c_str()); track.SetValue("path_id", pathId.c_str());

View File

@ -53,11 +53,10 @@ static const std::set<std::string> FORMATS = {
".nsf", ".ay", ".gbs", ".hes", ".kss" ".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) { for (auto& ext : FORMATS) {
std::string lowerFn; if (fn.rfind(ext) == fn.size() - ext.size()) {
std::transform(fn.begin(), fn.end(), lowerFn.begin(), ::tolower);
if (lowerFn.rfind(ext) == lowerFn.size() - ext.size()) {
return true; return true;
} }
} }

View File

@ -65,7 +65,11 @@ static bool exists(const std::string& externalId) {
return access(fn.c_str(), R_OK) != -1; 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_t* data = nullptr;
gme_err_t err = gme_open_file(fn.c_str(), &data, 44100); gme_err_t err = gme_open_file(fn.c_str(), &data, 44100);
if (err) { if (err) {
@ -144,7 +148,8 @@ static void scanDirectory(const std::string& path, IIndexerSource* source, IInde
else { else {
std::string fn = entry->d_name; std::string fn = entry->d_name;
if (canHandle(fn)) { if (canHandle(fn)) {
updateMetadata(source, fn, indexer); std::string fullFn = path + "/" + fn;
updateMetadata(fullFn, source, indexer);
} }
} }
} }

View File

@ -39,8 +39,7 @@
#include <functional> #include <functional>
#include <set> #include <set>
class GmeIndexerSource: class GmeIndexerSource: public musik::core::sdk::IIndexerSource {
public musik::core::sdk::IIndexerSource {
public: public:
GmeIndexerSource(); GmeIndexerSource();
~GmeIndexerSource(); ~GmeIndexerSource();