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:
parent
3623b3fe29
commit
ecfe13cade
2 changed files with 64 additions and 2 deletions
|
@ -4,6 +4,7 @@
|
||||||
#include "hashdatabase.h"
|
#include "hashdatabase.h"
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QSqlDriver>
|
||||||
#include <QSqlError>
|
#include <QSqlError>
|
||||||
#include <physis.hpp>
|
#include <physis.hpp>
|
||||||
|
|
||||||
|
@ -99,10 +100,53 @@ void HashDatabase::importFileList(const QString &path)
|
||||||
QFile file(path);
|
QFile file(path);
|
||||||
file.open(QIODevice::ReadOnly);
|
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);
|
QTextStream stream(&file);
|
||||||
|
stream.readLine(); // skip header
|
||||||
while (!stream.atEnd()) {
|
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"
|
#include "moc_hashdatabase.cpp"
|
|
@ -9,6 +9,7 @@
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "cmppart.h"
|
#include "cmppart.h"
|
||||||
#include "exdpart.h"
|
#include "exdpart.h"
|
||||||
|
@ -119,11 +120,28 @@ void MainWindow::refreshParts(const QString &path)
|
||||||
|
|
||||||
void MainWindow::setupFileMenu(QMenu *menu)
|
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")));
|
openList->setIcon(QIcon::fromTheme(QStringLiteral("document-open")));
|
||||||
connect(openList, &QAction::triggered, [this] {
|
connect(openList, &QAction::triggered, [this] {
|
||||||
auto fileName = QFileDialog::getOpenFileName(nullptr, QStringLiteral("Open Path List"), QStringLiteral("~"));
|
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);
|
m_database.importFileList(fileName);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue