mirror of
https://github.com/clangen/musikcube.git
synced 2024-10-02 04:52:32 +00:00
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:
parent
31dd2a5f79
commit
681e6c27bc
@ -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)) {
|
||||
/* refresh sources */
|
||||
for (auto it : this->sources) {
|
||||
if (this->Bail()) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (sourceId != 0 && sourceId != it->SourceId()) {
|
||||
continue; /* asked to scan a specific source, and this isn't it. */
|
||||
}
|
||||
|
||||
this->currentSource = it;
|
||||
if (this->SyncSource(it.get(), paths) == ScanRollback) {
|
||||
this->trackTransaction->Cancel();
|
||||
}
|
||||
this->trackTransaction->CommitAndRestart();
|
||||
|
||||
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) {
|
||||
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());
|
||||
|
@ -53,11 +53,10 @@ static const std::set<std::string> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,8 +39,7 @@
|
||||
#include <functional>
|
||||
#include <set>
|
||||
|
||||
class GmeIndexerSource:
|
||||
public musik::core::sdk::IIndexerSource {
|
||||
class GmeIndexerSource: public musik::core::sdk::IIndexerSource {
|
||||
public:
|
||||
GmeIndexerSource();
|
||||
~GmeIndexerSource();
|
||||
|
Loading…
Reference in New Issue
Block a user