1
Fork 0
mirror of https://github.com/redstrate/Novus.git synced 2025-04-25 05:17:44 +00:00

sagasu: Fix import path list function

It can now quickly import path lists from ResLogger (or another source
that fits such format)
This commit is contained in:
Joshua Goins 2024-02-03 10:04:25 -05:00
parent 3623b3fe29
commit ecfe13cade
2 changed files with 64 additions and 2 deletions

View file

@ -4,6 +4,7 @@
#include "hashdatabase.h"
#include <QFile>
#include <QSqlDriver>
#include <QSqlError>
#include <physis.hpp>
@ -99,10 +100,53 @@ void HashDatabase::importFileList(const QString &path)
QFile file(path);
file.open(QIODevice::ReadOnly);
QVariantList folderNames, folderHashes;
QVariantList fileNames, fileHashes;
m_db.transaction();
QSqlQuery folderQuery;
folderQuery.prepare(
QStringLiteral("REPLACE INTO folder_hashes (hash, name) "
"VALUES (?, ?)"));
QSqlQuery fileQuery;
fileQuery.prepare(
QStringLiteral("REPLACE INTO file_hashes (hash, name) "
"VALUES (?, ?)"));
QTextStream stream(&file);
stream.readLine(); // skip header
while (!stream.atEnd()) {
addFile(stream.readLine());
const QStringList parts = stream.readLine().split(QLatin1Char(','));
const QString &folderHash = parts[1];
const QString &fileHash = parts[2];
const QString &path = parts[4];
QString filename;
QString foldername;
if (path.contains(QStringLiteral("/"))) {
int lastSlash = path.lastIndexOf(QStringLiteral("/"));
filename = path.sliced(lastSlash + 1, path.length() - lastSlash - 1);
foldername = path.left(lastSlash);
} else {
filename = path;
}
// execBatch is too slow as the QSQLITE doesn't support batch operations
if (!foldername.isEmpty()) {
folderQuery.bindValue(0, folderHash.toUInt());
folderQuery.bindValue(1, foldername);
folderQuery.exec();
}
fileQuery.bindValue(0, fileHash.toUInt());
fileQuery.bindValue(1, filename);
fileQuery.exec();
}
m_db.commit();
}
#include "moc_hashdatabase.cpp"

View file

@ -9,6 +9,7 @@
#include <QHBoxLayout>
#include <QLabel>
#include <QMenuBar>
#include <QMessageBox>
#include "cmppart.h"
#include "exdpart.h"
@ -119,11 +120,28 @@ void MainWindow::refreshParts(const QString &path)
void MainWindow::setupFileMenu(QMenu *menu)
{
auto openList = menu->addAction(QStringLiteral("Import path list..."));
auto openList = menu->addAction(QStringLiteral("Import Path List..."));
openList->setIcon(QIcon::fromTheme(QStringLiteral("document-open")));
connect(openList, &QAction::triggered, [this] {
auto fileName = QFileDialog::getOpenFileName(nullptr, QStringLiteral("Open Path List"), QStringLiteral("~"));
QMessageBox::warning(this,
QStringLiteral("Import Warning"),
QStringLiteral("Depending on the size of the import, this process usually takes a few minutes. The program may freeze. Please "
"keep it open until the operation is finished."),
QMessageBox::Ok,
QMessageBox::Ok);
m_database.importFileList(fileName);
QMessageBox::information(this, QStringLiteral("Import Complete"), QStringLiteral("Successfully imported path list!"), QMessageBox::Ok, QMessageBox::Ok);
});
auto downloadList = menu->addAction(QStringLiteral("Download Path List..."));
downloadList->setIcon(QIcon::fromTheme(QStringLiteral("document-open")));
connect(downloadList, &QAction::triggered, [this] {
auto fileName = QFileDialog::getOpenFileName(nullptr, QStringLiteral("Open Path List"), QStringLiteral("~"));
m_database.importFileList(fileName);
});
}