aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/General
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2020-12-20 17:31:11 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2020-12-20 17:31:11 +0000
commitc7f763c3f63802b0a05394e358b3496aa89ea2ba (patch)
treeb3ec129811b354d297ac06cd7d15551125d0f1d9 /src/plugins/General
parentc23917a408e6a7baa4e54686ae3d481980c43eec (diff)
downloadqmmp-c7f763c3f63802b0a05394e358b3496aa89ea2ba.tar.gz
qmmp-c7f763c3f63802b0a05394e358b3496aa89ea2ba.tar.bz2
qmmp-c7f763c3f63802b0a05394e358b3496aa89ea2ba.zip
library: remove invalid files after directory scan
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9597 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/General')
-rw-r--r--src/plugins/General/library/library.cpp48
-rw-r--r--src/plugins/General/library/library.h2
2 files changed, 48 insertions, 2 deletions
diff --git a/src/plugins/General/library/library.cpp b/src/plugins/General/library/library.cpp
index 5b10b600c..14ff9ac7a 100644
--- a/src/plugins/General/library/library.cpp
+++ b/src/plugins/General/library/library.cpp
@@ -123,6 +123,8 @@ bool Library::createTables()
if(!ok)
qWarning("Library: unable to create table, error: %s", qPrintable(query.lastError().text()));
+ removeInvalid();
+
return ok;
}
@@ -133,8 +135,9 @@ void Library::addTrack(TrackInfo *track, const QString &filePath)
return;
QSqlQuery query(db);
- query.prepare("INSERT INTO track_library VALUES("
- "NULL, :timestamp, "
+ query.prepare("INSERT OR REPLACE INTO track_library VALUES("
+ "(SELECT ID FROM track_library WHERE URL = :url), "
+ ":timestamp, "
":title, :artist, :albumartist, :album, :comment, :genre, :composer, "
":year, :track, :discnumber, :duration, "
":audioinfo, :url, :filepath)");
@@ -218,6 +221,9 @@ bool Library::scanDirectories(const QStringList &paths)
return false;
}
+ removeInvalid();
+ qDebug("Library: directory scan finished");
+
return true;
}
@@ -279,6 +285,44 @@ void Library::addDirectory(const QString &s)
}
}
+void Library::removeInvalid()
+{
+ QSqlDatabase db = QSqlDatabase::database(CONNECTION_NAME);
+ if(!db.isOpen())
+ return;
+
+ QSqlQuery query(db);
+ if(!query.exec("SELECT FilePath FROM track_library"))
+ {
+ qWarning("Library: exec error: %s", qPrintable(query.lastError().text()));
+ return;
+ }
+
+ QString previousPath;
+
+ while (query.next())
+ {
+ QString path = query.value(0).toString();
+ if(previousPath == path)
+ continue;
+
+ previousPath = path;
+
+ if(!QFile::exists(path))
+ {
+ qDebug("Library: removing '%s' from library", qPrintable(path));
+ QSqlQuery rmQuery(db);
+ rmQuery.prepare("DELETE FROM track_library WHERE FilePath = :filepath");
+ rmQuery.bindValue(":filepath", path);
+ if(!rmQuery.exec())
+ {
+ qWarning("Library: exec error: %s", qPrintable(query.lastError().text()));
+ return;
+ }
+ }
+ }
+}
+
bool Library::checkFile(const QFileInfo &info)
{
QSqlDatabase db = QSqlDatabase::database(CONNECTION_NAME);
diff --git a/src/plugins/General/library/library.h b/src/plugins/General/library/library.h
index b1adace09..95525d779 100644
--- a/src/plugins/General/library/library.h
+++ b/src/plugins/General/library/library.h
@@ -53,9 +53,11 @@ private:
QByteArray serializeAudioInfo(const QMap<Qmmp::TrackProperty, QString> &properties);
bool scanDirectories(const QStringList &paths);
void addDirectory(const QString &s);
+ void removeInvalid();
bool checkFile(const QFileInfo &info);
void removeIgnoredTracks(QList<TrackInfo *> *tracks, const QStringList &ignoredPaths);
+
QFuture<bool> m_future;
QStringList m_filters, m_dirs;
bool m_stopped = false;