Extract library paths methods to it's own struct in yacreader_global.h and use it everywhere

This commit is contained in:
Luis Ángel San Martín
2025-03-29 11:31:53 +01:00
parent 5aa637fdbe
commit d4b7c6dd8a
15 changed files with 133 additions and 90 deletions

View File

@ -33,7 +33,7 @@ void ConsoleUILibraryCreator::createLibrary(const QString &name, const QString &
return;
}
libraryCreator->createLibrary(cleanPath, YACReaderLibrary::libraryDataPath(cleanPath));
libraryCreator->createLibrary(cleanPath, LibraryPaths::libraryDataPath(cleanPath));
connect(libraryCreator, &LibraryCreator::finished, this, &ConsoleUILibraryCreator::done);
connect(libraryCreator, &LibraryCreator::comicAdded, this, &ConsoleUILibraryCreator::newComic);
@ -62,7 +62,7 @@ void ConsoleUILibraryCreator::updateLibrary(const QString &path)
LibraryCreator *libraryCreator = new LibraryCreator(settings);
QString cleanPath = QDir::cleanPath(pathDir.absolutePath());
libraryCreator->updateLibrary(cleanPath, YACReaderLibrary::libraryDataPath(cleanPath));
libraryCreator->updateLibrary(cleanPath, LibraryPaths::libraryDataPath(cleanPath));
connect(libraryCreator, &LibraryCreator::finished, this, &ConsoleUILibraryCreator::done);
connect(libraryCreator, &LibraryCreator::comicAdded, this, &ConsoleUILibraryCreator::newComic);
@ -85,7 +85,7 @@ void ConsoleUILibraryCreator::addExistingLibrary(const QString &name, const QStr
}
QString cleanPath = QDir::cleanPath(pathDir.absolutePath());
if (!QDir(YACReaderLibrary::libraryDataPath(cleanPath)).exists()) {
if (!QDir(LibraryPaths::libraryDataPath(cleanPath)).exists()) {
std::cout << "No data folder found in path: " << cleanPath.toStdString() << std::endl;
return;
}
@ -135,7 +135,7 @@ void ConsoleUILibraryCreator::rescanXMLInfoLibrary(const QString &path)
connect(scanner, &XMLInfoLibraryScanner::finished, &eventLoop, &QEventLoop::quit);
std::cout << "Scanning comics";
scanner->scanLibrary(cleanPath, YACReaderLibrary::libraryDataPath(cleanPath));
scanner->scanLibrary(cleanPath, LibraryPaths::libraryDataPath(cleanPath));
eventLoop.exec();
}

View File

@ -14,16 +14,18 @@ void LibrariesUpdater::updateIfNeeded()
libraries.load();
foreach (QString name, libraries.getNames()) {
QString path = libraries.getPath(name) + "/.yacreaderlibrary";
QString root = libraries.getPath(name);
QString libraryDataPath = YACReader::LibraryPaths::libraryDataPath(root);
QString databasePath = YACReader::LibraryPaths::libraryDatabasePath(root);
QDir d;
QString dbVersion;
if (d.exists(path) && d.exists(path + "/library.ydb") && (dbVersion = DataBaseManagement::checkValidDB(path + "/library.ydb")) != "") {
if (d.exists(libraryDataPath) && d.exists(databasePath) && (dbVersion = DataBaseManagement::checkValidDB(databasePath)) != "") {
int comparation = DataBaseManagement::compareVersions(dbVersion, DB_VERSION);
if (comparation < 0) {
bool updated = DataBaseManagement::updateToCurrentVersion(path);
bool updated = DataBaseManagement::updateToCurrentVersion(libraryDataPath);
if (!updated) {
// TODO log error
}