mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-12 05:07:46 +02:00
Shallow search and lazy loading for Other Logs page
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
@ -43,16 +43,18 @@
|
||||
|
||||
#include <FileSystem.h>
|
||||
#include <GZip.h>
|
||||
#include <qdir.h>
|
||||
#include <qdiriterator.h>
|
||||
#include <qfilesystemwatcher.h>
|
||||
#include <qurl.h>
|
||||
#include <QShortcut>
|
||||
#include "RecursiveFileSystemWatcher.h"
|
||||
|
||||
OtherLogsPage::OtherLogsPage(InstancePtr instance, IPathMatcher::Ptr fileFilter, QWidget* parent)
|
||||
OtherLogsPage::OtherLogsPage(InstancePtr instance, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::OtherLogsPage)
|
||||
, m_instance(instance)
|
||||
, m_path(instance->getLogFileRoot())
|
||||
, m_fileFilter(fileFilter)
|
||||
, m_watcher(new RecursiveFileSystemWatcher(this))
|
||||
, m_basePath(instance->gameRoot())
|
||||
, m_logSearchPaths(instance->getLogFileSearchPaths())
|
||||
, m_model(new LogModel(this))
|
||||
{
|
||||
ui->setupUi(this);
|
||||
@ -78,11 +80,7 @@ OtherLogsPage::OtherLogsPage(InstancePtr instance, IPathMatcher::Ptr fileFilter,
|
||||
m_model->setOverflowMessage(tr("Cannot display this log since the log length surpassed %1 lines.").arg(m_model->getMaxLines()));
|
||||
m_proxy->setSourceModel(m_model.get());
|
||||
|
||||
m_watcher->setMatcher(fileFilter);
|
||||
m_watcher->setRootDir(QDir::current().absoluteFilePath(m_path));
|
||||
|
||||
connect(m_watcher, &RecursiveFileSystemWatcher::filesChanged, this, &OtherLogsPage::populateSelectLogBox);
|
||||
populateSelectLogBox();
|
||||
connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &OtherLogsPage::populateSelectLogBox);
|
||||
|
||||
auto findShortcut = new QShortcut(QKeySequence(QKeySequence::Find), this);
|
||||
connect(findShortcut, &QShortcut::activated, this, &OtherLogsPage::findActivated);
|
||||
@ -108,22 +106,39 @@ void OtherLogsPage::retranslate()
|
||||
|
||||
void OtherLogsPage::openedImpl()
|
||||
{
|
||||
m_watcher->enable();
|
||||
const QStringList failedPaths = m_watcher.addPaths(m_logSearchPaths);
|
||||
|
||||
for (const QString& path : m_logSearchPaths) {
|
||||
if (failedPaths.contains(path))
|
||||
qDebug() << "Failed to start watching" << path;
|
||||
else
|
||||
qDebug() << "Started watching" << path;
|
||||
}
|
||||
|
||||
populateSelectLogBox();
|
||||
}
|
||||
|
||||
void OtherLogsPage::closedImpl()
|
||||
{
|
||||
m_watcher->disable();
|
||||
const QStringList failedPaths = m_watcher.removePaths(m_logSearchPaths);
|
||||
|
||||
for (const QString& path : m_logSearchPaths) {
|
||||
if (failedPaths.contains(path))
|
||||
qDebug() << "Failed to stop watching" << path;
|
||||
else
|
||||
qDebug() << "Stopped watching" << path;
|
||||
}
|
||||
}
|
||||
|
||||
void OtherLogsPage::populateSelectLogBox()
|
||||
{
|
||||
QString prevCurrentFile = m_currentFile;
|
||||
|
||||
ui->selectLogBox->clear();
|
||||
ui->selectLogBox->addItems(m_watcher->files());
|
||||
if (m_currentFile.isEmpty()) {
|
||||
setControlsEnabled(false);
|
||||
ui->selectLogBox->setCurrentIndex(-1);
|
||||
} else {
|
||||
const int index = ui->selectLogBox->findText(m_currentFile);
|
||||
ui->selectLogBox->addItems(getPaths());
|
||||
|
||||
if (!prevCurrentFile.isEmpty()) {
|
||||
const int index = ui->selectLogBox->findText(prevCurrentFile);
|
||||
if (index != -1) {
|
||||
ui->selectLogBox->setCurrentIndex(index);
|
||||
setControlsEnabled(true);
|
||||
@ -140,7 +155,7 @@ void OtherLogsPage::on_selectLogBox_currentIndexChanged(const int index)
|
||||
file = ui->selectLogBox->itemText(index);
|
||||
}
|
||||
|
||||
if (file.isEmpty() || !QFile::exists(FS::PathCombine(m_path, file))) {
|
||||
if (file.isEmpty() || !QFile::exists(FS::PathCombine(m_basePath, file))) {
|
||||
m_currentFile = QString();
|
||||
ui->text->clear();
|
||||
setControlsEnabled(false);
|
||||
@ -199,7 +214,7 @@ void OtherLogsPage::on_btnReload_clicked()
|
||||
setControlsEnabled(false);
|
||||
return;
|
||||
}
|
||||
QFile file(FS::PathCombine(m_path, m_currentFile));
|
||||
QFile file(FS::PathCombine(m_basePath, m_currentFile));
|
||||
if (!file.open(QFile::ReadOnly)) {
|
||||
setControlsEnabled(false);
|
||||
ui->btnReload->setEnabled(true); // allow reload
|
||||
@ -284,7 +299,7 @@ void OtherLogsPage::on_btnDelete_clicked()
|
||||
QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) {
|
||||
return;
|
||||
}
|
||||
QFile file(FS::PathCombine(m_path, m_currentFile));
|
||||
QFile file(FS::PathCombine(m_basePath, m_currentFile));
|
||||
|
||||
if (FS::trash(file.fileName())) {
|
||||
return;
|
||||
@ -297,7 +312,7 @@ void OtherLogsPage::on_btnDelete_clicked()
|
||||
|
||||
void OtherLogsPage::on_btnClean_clicked()
|
||||
{
|
||||
auto toDelete = m_watcher->files();
|
||||
auto toDelete = getPaths();
|
||||
if (toDelete.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@ -320,7 +335,9 @@ void OtherLogsPage::on_btnClean_clicked()
|
||||
}
|
||||
QStringList failed;
|
||||
for (auto item : toDelete) {
|
||||
QFile file(FS::PathCombine(m_path, item));
|
||||
QString absolutePath = FS::PathCombine(m_basePath, item);
|
||||
QFile file(absolutePath);
|
||||
qDebug() << "Deleting log" << absolutePath;
|
||||
if (FS::trash(file.fileName())) {
|
||||
continue;
|
||||
}
|
||||
@ -374,6 +391,28 @@ void OtherLogsPage::setControlsEnabled(const bool enabled)
|
||||
ui->btnClean->setEnabled(enabled);
|
||||
}
|
||||
|
||||
QStringList OtherLogsPage::getPaths()
|
||||
{
|
||||
QDir baseDir(m_basePath);
|
||||
|
||||
QStringList result;
|
||||
|
||||
for (QString searchPath : m_logSearchPaths) {
|
||||
QDirIterator iterator(searchPath, QDir::Files | QDir::Readable);
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
const QString name = iterator.next();
|
||||
|
||||
if (!name.endsWith(".log") && !name.endsWith(".log.gz"))
|
||||
continue;
|
||||
|
||||
result.append(baseDir.relativeFilePath(name));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void OtherLogsPage::on_findButton_clicked()
|
||||
{
|
||||
auto modifiers = QApplication::keyboardModifiers();
|
||||
|
Reference in New Issue
Block a user