Add a new page that can show all sorts of logs
This commit is contained in:

committed by
Petr Mrázek

parent
aba1f89e2a
commit
5c43842359
@ -31,12 +31,13 @@
|
||||
#include "logic/MinecraftProcess.h"
|
||||
#include "gui/pagedialog/PageDialog.h"
|
||||
#include "gui/pages/VersionPage.h"
|
||||
#include <gui/pages/ModFolderPage.h>
|
||||
#include <gui/pages/ResourcePackPage.h>
|
||||
#include <gui/pages/TexturePackPage.h>
|
||||
#include <gui/pages/InstanceSettingsPage.h>
|
||||
#include <gui/pages/NotesPage.h>
|
||||
#include <gui/pages/ScreenshotsPage.h>
|
||||
#include "gui/pages/ModFolderPage.h"
|
||||
#include "gui/pages/ResourcePackPage.h"
|
||||
#include "gui/pages/TexturePackPage.h"
|
||||
#include "gui/pages/InstanceSettingsPage.h"
|
||||
#include "gui/pages/NotesPage.h"
|
||||
#include "gui/pages/ScreenshotsPage.h"
|
||||
#include "gui/pages/OtherLogsPage.h"
|
||||
|
||||
OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *settings,
|
||||
QObject *parent)
|
||||
@ -72,6 +73,7 @@ QList<BasePage *> OneSixInstance::getPages()
|
||||
values.append(new NotesPage(this));
|
||||
values.append(new ScreenshotsPage(this));
|
||||
values.append(new InstanceSettingsPage(this));
|
||||
values.append(new OtherLogsPage(this));
|
||||
return values;
|
||||
}
|
||||
|
||||
|
97
logic/RecursiveFileSystemWatcher.cpp
Normal file
97
logic/RecursiveFileSystemWatcher.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
#include "RecursiveFileSystemWatcher.h"
|
||||
|
||||
#include <QRegularExpression>
|
||||
|
||||
RecursiveFileSystemWatcher::RecursiveFileSystemWatcher(QObject *parent)
|
||||
: QObject(parent),
|
||||
m_watcher(new QFileSystemWatcher(this))
|
||||
{
|
||||
connect(m_watcher, &QFileSystemWatcher::fileChanged, this, &RecursiveFileSystemWatcher::fileChange);
|
||||
connect(m_watcher, &QFileSystemWatcher::directoryChanged, this, &RecursiveFileSystemWatcher::directoryChange);
|
||||
}
|
||||
|
||||
void RecursiveFileSystemWatcher::setRootDir(const QDir &root)
|
||||
{
|
||||
bool wasEnabled = m_isEnabled;
|
||||
disable();
|
||||
m_root = root;
|
||||
setFiles(scanRecursive(m_root));
|
||||
if (wasEnabled)
|
||||
{
|
||||
enable();
|
||||
}
|
||||
}
|
||||
void RecursiveFileSystemWatcher::setWatchFiles(const bool watchFiles)
|
||||
{
|
||||
bool wasEnabled = m_isEnabled;
|
||||
disable();
|
||||
m_watchFiles = watchFiles;
|
||||
if (wasEnabled)
|
||||
{
|
||||
enable();
|
||||
}
|
||||
}
|
||||
|
||||
void RecursiveFileSystemWatcher::enable()
|
||||
{
|
||||
Q_ASSERT(m_root != QDir::root());
|
||||
addFilesToWatcherRecursive(m_root);
|
||||
m_isEnabled = true;
|
||||
}
|
||||
void RecursiveFileSystemWatcher::disable()
|
||||
{
|
||||
m_isEnabled = false;
|
||||
m_watcher->removePaths(m_watcher->files());
|
||||
m_watcher->removePaths(m_watcher->directories());
|
||||
}
|
||||
|
||||
void RecursiveFileSystemWatcher::setFiles(const QStringList &files)
|
||||
{
|
||||
if (files != m_files)
|
||||
{
|
||||
m_files = files;
|
||||
emit filesChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void RecursiveFileSystemWatcher::addFilesToWatcherRecursive(const QDir &dir)
|
||||
{
|
||||
m_watcher->addPath(dir.absolutePath());
|
||||
for (const QFileInfo &info : dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot))
|
||||
{
|
||||
addFilesToWatcherRecursive(info.absoluteDir());
|
||||
}
|
||||
if (m_watchFiles)
|
||||
{
|
||||
for (const QFileInfo &info : dir.entryInfoList(QDir::Files))
|
||||
{
|
||||
m_watcher->addPath(info.absoluteFilePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
QStringList RecursiveFileSystemWatcher::scanRecursive(const QDir &dir)
|
||||
{
|
||||
QStringList ret;
|
||||
QRegularExpression exp(m_exp);
|
||||
for (const QFileInfo &info : dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files))
|
||||
{
|
||||
if (info.isFile() && exp.match(info.absoluteFilePath()).hasMatch())
|
||||
{
|
||||
ret.append(info.absoluteFilePath());
|
||||
}
|
||||
else if (info.isDir())
|
||||
{
|
||||
ret.append(scanRecursive(info.absoluteDir()));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void RecursiveFileSystemWatcher::fileChange(const QString &path)
|
||||
{
|
||||
emit fileChanged(path);
|
||||
}
|
||||
void RecursiveFileSystemWatcher::directoryChange(const QString &path)
|
||||
{
|
||||
setFiles(scanRecursive(m_root));
|
||||
}
|
51
logic/RecursiveFileSystemWatcher.h
Normal file
51
logic/RecursiveFileSystemWatcher.h
Normal file
@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include <QFileSystemWatcher>
|
||||
#include <QDir>
|
||||
|
||||
class RecursiveFileSystemWatcher : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RecursiveFileSystemWatcher(QObject *parent);
|
||||
|
||||
void setRootDir(const QDir &root);
|
||||
QDir rootDir() const { return m_root; }
|
||||
|
||||
// WARNING: setting this to true may be bad for performance
|
||||
void setWatchFiles(const bool watchFiles);
|
||||
bool watchFiles() const { return m_watchFiles; }
|
||||
|
||||
void setFileExpression(const QString &exp) { m_exp = exp; }
|
||||
QString fileExpression() const { return m_exp; }
|
||||
|
||||
QStringList files() const { return m_files; }
|
||||
|
||||
signals:
|
||||
void filesChanged();
|
||||
void fileChanged(const QString &path);
|
||||
|
||||
public
|
||||
slots:
|
||||
void enable();
|
||||
void disable();
|
||||
|
||||
private:
|
||||
QDir m_root;
|
||||
bool m_watchFiles = false;
|
||||
bool m_isEnabled = false;
|
||||
QString m_exp;
|
||||
|
||||
QFileSystemWatcher *m_watcher;
|
||||
|
||||
QStringList m_files;
|
||||
void setFiles(const QStringList &scanRecursive);
|
||||
|
||||
void addFilesToWatcherRecursive(const QDir &dir);
|
||||
QStringList scanRecursive(const QDir &dir);
|
||||
|
||||
private
|
||||
slots:
|
||||
void fileChange(const QString &path);
|
||||
void directoryChange(const QString &path);
|
||||
};
|
Reference in New Issue
Block a user