mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
Detect modified files and update them
The old file is delete, the modified file is inserted and the existing metadata is copied over. The added date is updated to avoid new matches during the update process.
This commit is contained in:
parent
68ece533e1
commit
8520a29a05
@ -285,18 +285,23 @@ bool LibraryCreator::checkCover(const QString &hash)
|
|||||||
return QFile::exists(_target + "/covers/" + hash + ".jpg");
|
return QFile::exists(_target + "/covers/" + hash + ".jpg");
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibraryCreator::insertComic(const QString &relativePath, const QFileInfo &fileInfo)
|
QString pseudoHash(const QFileInfo &fileInfo)
|
||||||
{
|
{
|
||||||
auto _database = QSqlDatabase::database(_databaseConnection);
|
|
||||||
// Se calcula el hash del cómic
|
|
||||||
|
|
||||||
QCryptographicHash crypto(QCryptographicHash::Sha1);
|
QCryptographicHash crypto(QCryptographicHash::Sha1);
|
||||||
QFile file(fileInfo.absoluteFilePath());
|
QFile file(fileInfo.absoluteFilePath());
|
||||||
file.open(QFile::ReadOnly);
|
file.open(QFile::ReadOnly);
|
||||||
crypto.addData(file.read(524288));
|
crypto.addData(file.read(524288));
|
||||||
file.close();
|
file.close();
|
||||||
// hash Sha1 del primer 0.5MB + filesize
|
// hash Sha1 del primer 0.5MB + filesize
|
||||||
QString hash = QString(crypto.result().toHex().constData()) + QString::number(fileInfo.size());
|
return QString(crypto.result().toHex().constData()) + QString::number(fileInfo.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void LibraryCreator::insertComic(const QString &relativePath, const QFileInfo &fileInfo)
|
||||||
|
{
|
||||||
|
auto _database = QSqlDatabase::database(_databaseConnection);
|
||||||
|
|
||||||
|
QString hash = pseudoHash(fileInfo);
|
||||||
|
|
||||||
ComicDB comic = DBHelper::loadComic(fileInfo.fileName(), relativePath, hash, _database);
|
ComicDB comic = DBHelper::loadComic(fileInfo.fileName(), relativePath, hash, _database);
|
||||||
int numPages = 0;
|
int numPages = 0;
|
||||||
QPair<int, int> originalCoverSize = { 0, 0 };
|
QPair<int, int> originalCoverSize = { 0, 0 };
|
||||||
@ -333,6 +338,37 @@ void LibraryCreator::insertComic(const QString &relativePath, const QFileInfo &f
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LibraryCreator::replaceComic(const QString &relativePath, const QFileInfo &fileInfo, ComicDB *comic)
|
||||||
|
{
|
||||||
|
QLOG_INFO() << "Replacing comic" << relativePath;
|
||||||
|
|
||||||
|
auto _database = QSqlDatabase::database(_databaseConnection);
|
||||||
|
|
||||||
|
DBHelper::removeFromDB(comic, _database);
|
||||||
|
insertComic(relativePath, fileInfo);
|
||||||
|
|
||||||
|
QString hash = pseudoHash(fileInfo);
|
||||||
|
|
||||||
|
ComicDB insertedComic = DBHelper::loadComic(fileInfo.fileName(), relativePath, hash, _database);
|
||||||
|
|
||||||
|
auto numPages = insertedComic.info.numPages;
|
||||||
|
auto coverSize = insertedComic.info.originalCoverSize;
|
||||||
|
auto coverRatio = insertedComic.info.coverSizeRatio;
|
||||||
|
auto id = insertedComic.info.id;
|
||||||
|
auto added = insertedComic.info.added;
|
||||||
|
|
||||||
|
insertedComic.info = comic->info;
|
||||||
|
|
||||||
|
insertedComic.info.numPages = numPages;
|
||||||
|
insertedComic.info.originalCoverSize = coverSize;
|
||||||
|
insertedComic.info.coverSizeRatio = coverRatio;
|
||||||
|
insertedComic.info.id = id;
|
||||||
|
insertedComic.info.coverPage = 0;
|
||||||
|
insertedComic.info.added = QDateTime::currentSecsSinceEpoch(); // when replacing a comic, added needs to be later than modified to avoid tagging this file as modified
|
||||||
|
|
||||||
|
DBHelper::update(&(insertedComic.info), _database);
|
||||||
|
}
|
||||||
|
|
||||||
void LibraryCreator::update(QDir dirS)
|
void LibraryCreator::update(QDir dirS)
|
||||||
{
|
{
|
||||||
auto _database = QSqlDatabase::database(_databaseConnection);
|
auto _database = QSqlDatabase::database(_databaseConnection);
|
||||||
@ -541,24 +577,24 @@ void LibraryCreator::update(QDir dirS)
|
|||||||
} else // same file
|
} else // same file
|
||||||
{
|
{
|
||||||
if (fileInfoS.isFile() && !fileInfoD->isDir()) {
|
if (fileInfoS.isFile() && !fileInfoD->isDir()) {
|
||||||
// TODO_METADATA use added,
|
auto comicDB = static_cast<ComicDB *>(fileInfoD);
|
||||||
// if added < modified, do something
|
auto lastModified = fileInfoS.lastModified().toSecsSinceEpoch();
|
||||||
|
auto added = comicDB->info.added.toULongLong();
|
||||||
|
|
||||||
// copy metadata to avoid loosing it if the imported comics doesn't have it.
|
if (added > 0 && added < lastModified) {
|
||||||
|
#ifdef Q_OS_MACOS
|
||||||
// DBHelper::removeFromDB(fileInfoD, _database);
|
QStringList src = _source.split("/");
|
||||||
// #ifdef Q_OS_MACOS
|
QString filePath = fileInfoS.absoluteFilePath();
|
||||||
// QStringList src = _source.split("/");
|
QStringList fp = filePath.split("/");
|
||||||
// QString filePath = fileInfoS.absoluteFilePath();
|
for (int i = 0; i < src.count(); i++) {
|
||||||
// QStringList fp = filePath.split("/");
|
fp.removeFirst();
|
||||||
// for (int i = 0; i < src.count(); i++) {
|
}
|
||||||
// fp.removeFirst();
|
QString path = "/" + fp.join("/");
|
||||||
// }
|
#else
|
||||||
// QString path = "/" + fp.join("/");
|
QString path = QDir::cleanPath(fileInfoS.absoluteFilePath()).remove(_source);
|
||||||
// #else
|
#endif
|
||||||
// QString path = QDir::cleanPath(fileInfoS.absoluteFilePath()).remove(_source);
|
replaceComic(path, fileInfoS, comicDB);
|
||||||
// #endif
|
}
|
||||||
// insertComic(path, fileInfoS);
|
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
j++;
|
j++;
|
||||||
|
@ -47,6 +47,7 @@ private:
|
|||||||
qulonglong insertFolders(); // devuelve el id del último folder añadido (último en la ruta)
|
qulonglong insertFolders(); // devuelve el id del último folder añadido (último en la ruta)
|
||||||
bool checkCover(const QString &hash);
|
bool checkCover(const QString &hash);
|
||||||
void insertComic(const QString &relativePath, const QFileInfo &fileInfo);
|
void insertComic(const QString &relativePath, const QFileInfo &fileInfo);
|
||||||
|
void replaceComic(const QString &relativePath, const QFileInfo &fileInfo, ComicDB *comic);
|
||||||
// qulonglong insertFolder(qulonglong parentId,const Folder & folder);
|
// qulonglong insertFolder(qulonglong parentId,const Folder & folder);
|
||||||
// qulonglong insertComic(const Comic & comic);
|
// qulonglong insertComic(const Comic & comic);
|
||||||
bool stopRunning;
|
bool stopRunning;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user