Make possible to cancel updates/creations

This commit is contained in:
Luis Ángel San Martín
2023-08-20 12:36:40 +02:00
parent a6caf98af9
commit 45043cf36e
2 changed files with 24 additions and 8 deletions

View File

@ -110,6 +110,7 @@ void LibraryCreator::processLibrary(const QString &source, const QString &target
void LibraryCreator::run()
{
stopRunning = false;
canceled = false;
#if !defined use_unarr && !defined use_libarchive
// check for 7z lib
#if defined Q_OS_UNIX && !defined Q_OS_MACOS
@ -187,13 +188,15 @@ void LibraryCreator::run()
update(QDir(_source));
}
if (partialUpdate) {
auto folder = DBHelper::updateChildrenInfo(folderDestinationModelIndex.data(FolderModel::IdRole).toULongLong(), _database);
DBHelper::propagateFolderUpdatesToParent(folder, _database);
} else
DBHelper::updateChildrenInfo(_database);
if (!canceled) {
if (partialUpdate) {
auto folder = DBHelper::updateChildrenInfo(folderDestinationModelIndex.data(FolderModel::IdRole).toULongLong(), _database);
DBHelper::propagateFolderUpdatesToParent(folder, _database);
} else
DBHelper::updateChildrenInfo(_database);
_database.commit();
_database.commit();
}
_database.close();
}
@ -224,6 +227,13 @@ void LibraryCreator::stop()
stopRunning = true;
}
void LibraryCreator::cancel()
{
QSqlDatabase::database(_databaseConnection).rollback();
canceled = true;
stopRunning = true;
}
// retorna el id del ultimo de los folders
qulonglong LibraryCreator::insertFolders()
{
@ -291,7 +301,7 @@ QString pseudoHash(const QFileInfo &fileInfo)
QCryptographicHash crypto(QCryptographicHash::Sha1);
QFile file(fileInfo.absoluteFilePath());
file.open(QFile::ReadOnly);
crypto.addData(file.read(524288));
crypto.addData(file.read(52428));
file.close();
// hash Sha1 del primer 0.5MB + filesize
return QString(crypto.result().toHex().constData()) + QString::number(fileInfo.size());
@ -376,6 +386,10 @@ void LibraryCreator::replaceComic(const QString &relativePath, const QFileInfo &
void LibraryCreator::update(QDir dirS)
{
if (stopRunning) {
return;
}
auto _database = QSqlDatabase::database(_databaseConnection);
// QLOG_TRACE() << "Updating" << dirS.absolutePath();
// QLOG_TRACE() << "Getting info from dir" << dirS.absolutePath();