summaryrefslogtreecommitdiffstats
path: root/logic
diff options
context:
space:
mode:
authorJan Dalheimer <jan@dalheimer.de>2014-07-12 17:58:23 +0200
committerPetr Mrázek <peterix@gmail.com>2014-07-12 23:31:05 +0200
commit5c4384235989b16d6931cc0cfa26dd192af68b96 (patch)
tree90e9fa1b758c97302726e01882e9c7c914426182 /logic
parentaba1f89e2abfd596eb01c674d1b2deee3bdc1047 (diff)
downloadMultiMC-5c4384235989b16d6931cc0cfa26dd192af68b96.tar
MultiMC-5c4384235989b16d6931cc0cfa26dd192af68b96.tar.gz
MultiMC-5c4384235989b16d6931cc0cfa26dd192af68b96.tar.lz
MultiMC-5c4384235989b16d6931cc0cfa26dd192af68b96.tar.xz
MultiMC-5c4384235989b16d6931cc0cfa26dd192af68b96.zip
Add a new page that can show all sorts of logs
Diffstat (limited to 'logic')
-rw-r--r--logic/OneSixInstance.cpp14
-rw-r--r--logic/RecursiveFileSystemWatcher.cpp97
-rw-r--r--logic/RecursiveFileSystemWatcher.h51
3 files changed, 156 insertions, 6 deletions
diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp
index 3eb817a5..82d4e480 100644
--- a/logic/OneSixInstance.cpp
+++ b/logic/OneSixInstance.cpp
@@ -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;
}
diff --git a/logic/RecursiveFileSystemWatcher.cpp b/logic/RecursiveFileSystemWatcher.cpp
new file mode 100644
index 00000000..5cfa7e4e
--- /dev/null
+++ b/logic/RecursiveFileSystemWatcher.cpp
@@ -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));
+}
diff --git a/logic/RecursiveFileSystemWatcher.h b/logic/RecursiveFileSystemWatcher.h
new file mode 100644
index 00000000..54fc1d12
--- /dev/null
+++ b/logic/RecursiveFileSystemWatcher.h
@@ -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);
+};