From e7e56eb1e397a528df91f9ce99f738c49bde363c Mon Sep 17 00:00:00 2001 From: Marcelo Hernandez Date: Sat, 22 Oct 2022 14:50:32 -0400 Subject: [PATCH] add more options to copy instance dialog - Copy game options, copy resource packs, copy shaders, copy servers, and copy mods - Also made a new InstanceCopyPrefs struct to store those options rather than passing 7 different booleans into InstanceCopyTask's constructor Signed-off-by: Marcelo Hernandez --- launcher/CMakeLists.txt | 1 + launcher/InstanceCopyPrefs.h | 18 +++++ launcher/InstanceCopyTask.cpp | 62 +++++++++++++-- launcher/InstanceCopyTask.h | 20 +++-- launcher/ui/MainWindow.cpp | 12 ++- launcher/ui/dialogs/CopyInstanceDialog.cpp | 90 ++++++++++++++++++++++ launcher/ui/dialogs/CopyInstanceDialog.h | 15 ++++ launcher/ui/dialogs/CopyInstanceDialog.ui | 58 ++++++++++++-- 8 files changed, 254 insertions(+), 22 deletions(-) create mode 100644 launcher/InstanceCopyPrefs.h diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 79ac49c7..77440cca 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -31,6 +31,7 @@ set(CORE_SOURCES # Basic instance manipulation tasks (derived from InstanceTask) InstanceCreationTask.h InstanceCreationTask.cpp + InstanceCopyPrefs.h InstanceCopyTask.h InstanceCopyTask.cpp InstanceImportTask.h diff --git a/launcher/InstanceCopyPrefs.h b/launcher/InstanceCopyPrefs.h new file mode 100644 index 00000000..ac2feab8 --- /dev/null +++ b/launcher/InstanceCopyPrefs.h @@ -0,0 +1,18 @@ +// +// Created by marcelohdez on 10/22/22. +// + +#ifndef LAUNCHER_INSTANCECOPYPREFS_H +#define LAUNCHER_INSTANCECOPYPREFS_H + +struct InstanceCopyPrefs { + bool copySaves; + bool keepPlaytime; + bool copyGameOptions; + bool copyResourcePacks; + bool copyShaderPacks; + bool copyServers; + bool copyMods; +}; + +#endif // LAUNCHER_INSTANCECOPYPREFS_H diff --git a/launcher/InstanceCopyTask.cpp b/launcher/InstanceCopyTask.cpp index b1e33884..360f6cfa 100644 --- a/launcher/InstanceCopyTask.cpp +++ b/launcher/InstanceCopyTask.cpp @@ -5,18 +5,66 @@ #include "pathmatcher/RegexpMatcher.h" #include -InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, bool copySaves, bool keepPlaytime) +InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, InstanceCopyPrefs prefs) { m_origInstance = origInstance; - m_keepPlaytime = keepPlaytime; + m_keepPlaytime = prefs.keepPlaytime; + QString filter; - if(!copySaves) + if(!prefs.copySaves) { - // FIXME: get this from the original instance type... - auto matcherReal = new RegexpMatcher("[.]?minecraft/saves"); - matcherReal->caseSensitive(false); - m_matcher.reset(matcherReal); + appendToFilter(filter, "saves"); } + + if(!prefs.copyGameOptions) { + appendToFilter(filter, "options.txt"); + } + + if(!prefs.copyResourcePacks) + { + appendToFilter(filter, "resourcepacks"); + appendToFilter(filter, "texturepacks"); + } + + if(!prefs.copyShaderPacks) + { + appendToFilter(filter, "shaderpacks"); + } + + if(!prefs.copyServers) + { + appendToFilter(filter, "servers.dat"); + appendToFilter(filter, "servers.dat_old"); + appendToFilter(filter, "server-resource-packs"); + } + + if(!prefs.copyMods) + { + appendToFilter(filter, "coremods"); + appendToFilter(filter, "mods"); + appendToFilter(filter, "config"); + } + + if (!filter.isEmpty()) + { + resetFromMatcher(filter); + } +} + +void InstanceCopyTask::appendToFilter(QString& filter, const QString &append) +{ + if (!filter.isEmpty()) + filter.append('|'); // OR regex + + filter.append("[.]?minecraft/" + append); +} + +void InstanceCopyTask::resetFromMatcher(const QString& regexp) +{ + // FIXME: get this from the original instance type... + auto matcherReal = new RegexpMatcher(regexp); + matcherReal->caseSensitive(false); + m_matcher.reset(matcherReal); } void InstanceCopyTask::executeTask() diff --git a/launcher/InstanceCopyTask.h b/launcher/InstanceCopyTask.h index 82901732..d66bec55 100644 --- a/launcher/InstanceCopyTask.h +++ b/launcher/InstanceCopyTask.h @@ -1,20 +1,21 @@ #pragma once -#include "tasks/Task.h" -#include "net/NetJob.h" -#include #include #include -#include "settings/SettingsObject.h" -#include "BaseVersion.h" +#include #include "BaseInstance.h" +#include "BaseVersion.h" +#include "InstanceCopyPrefs.h" #include "InstanceTask.h" +#include "net/NetJob.h" +#include "settings/SettingsObject.h" +#include "tasks/Task.h" class InstanceCopyTask : public InstanceTask { Q_OBJECT public: - explicit InstanceCopyTask(InstancePtr origInstance, bool copySaves, bool keepPlaytime); + explicit InstanceCopyTask(InstancePtr origInstance, InstanceCopyPrefs prefs); protected: //! Entry point for tasks. @@ -22,7 +23,12 @@ protected: void copyFinished(); void copyAborted(); -private: /* data */ +private: + // Helper functions to avoid repeating code + static void appendToFilter(QString &filter, const QString &append); + void resetFromMatcher(const QString ®exp); + + /* data */ InstancePtr m_origInstance; QFuture m_copyFuture; QFutureWatcher m_copyFutureWatcher; diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 97152a48..d51f799c 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -1616,7 +1616,17 @@ void MainWindow::on_actionCopyInstance_triggered() if (!copyInstDlg.exec()) return; - auto copyTask = new InstanceCopyTask(m_selectedInstance, copyInstDlg.shouldCopySaves(), copyInstDlg.shouldKeepPlaytime()); + auto copyTask = new InstanceCopyTask( + m_selectedInstance, + InstanceCopyPrefs { + copyInstDlg.shouldCopySaves(), + copyInstDlg.shouldKeepPlaytime(), + copyInstDlg.shouldCopyGameOptions(), + copyInstDlg.shouldCopyResourcePacks(), + copyInstDlg.shouldCopyShaderPacks(), + copyInstDlg.shouldCopyServers(), + copyInstDlg.shouldCopyMods() + }); copyTask->setName(copyInstDlg.instName()); copyTask->setGroup(copyInstDlg.instGroup()); copyTask->setIcon(copyInstDlg.iconKey()); diff --git a/launcher/ui/dialogs/CopyInstanceDialog.cpp b/launcher/ui/dialogs/CopyInstanceDialog.cpp index 9ec341bc..d19888ed 100644 --- a/launcher/ui/dialogs/CopyInstanceDialog.cpp +++ b/launcher/ui/dialogs/CopyInstanceDialog.cpp @@ -80,6 +80,11 @@ CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget *parent) ui->groupBox->lineEdit()->setPlaceholderText(tr("No group")); ui->copySavesCheckbox->setChecked(m_copySaves); ui->keepPlaytimeCheckbox->setChecked(m_keepPlaytime); + ui->copyGameOptionsCheckbox->setChecked(m_copyGameOptions); + ui->copyResPacksCheckbox->setChecked(m_copyResourcePacks); + ui->copyShaderPacksCheckbox->setChecked(m_copyShaderPacks); + ui->copyServersCheckbox->setChecked(m_copyServers); + ui->copyModsCheckbox->setChecked(m_copyMods); } CopyInstanceDialog::~CopyInstanceDialog() @@ -168,3 +173,88 @@ void CopyInstanceDialog::on_keepPlaytimeCheckbox_stateChanged(int state) m_keepPlaytime = true; } } + +bool CopyInstanceDialog::shouldCopyGameOptions() const +{ + return m_copyGameOptions; +} + +void CopyInstanceDialog::on_copyGameOptionsCheckbox_stateChanged(int state) +{ + if(state == Qt::Unchecked) + { + m_copyGameOptions = false; + } + else if(state == Qt::Checked) + { + m_copyGameOptions = true; + } +} + +bool CopyInstanceDialog::shouldCopyResourcePacks() const +{ + return m_copyResourcePacks; +} + +void CopyInstanceDialog::on_copyResPacksCheckbox_stateChanged(int state) +{ + if(state == Qt::Unchecked) + { + m_copyResourcePacks = false; + } + else if(state == Qt::Checked) + { + m_copyResourcePacks = true; + } +} + +bool CopyInstanceDialog::shouldCopyShaderPacks() const +{ + return m_copyShaderPacks; +} + +void CopyInstanceDialog::on_copyShaderPacksCheckbox_stateChanged(int state) +{ + if(state == Qt::Unchecked) + { + m_copyShaderPacks = false; + } + else if(state == Qt::Checked) + { + m_copyShaderPacks = true; + } +} + +bool CopyInstanceDialog::shouldCopyServers() const +{ + return m_copyServers; +} + +void CopyInstanceDialog::on_copyServersCheckbox_stateChanged(int state) +{ + if(state == Qt::Unchecked) + { + m_copyServers = false; + } + else if(state == Qt::Checked) + { + m_copyServers = true; + } +} + +bool CopyInstanceDialog::shouldCopyMods() const +{ + return m_copyMods; +} + +void CopyInstanceDialog::on_copyModsCheckbox_stateChanged(int state) +{ + if(state == Qt::Unchecked) + { + m_copyMods = false; + } + else if(state == Qt::Checked) + { + m_copyMods = true; + } +} diff --git a/launcher/ui/dialogs/CopyInstanceDialog.h b/launcher/ui/dialogs/CopyInstanceDialog.h index bf3cd920..e4c70494 100644 --- a/launcher/ui/dialogs/CopyInstanceDialog.h +++ b/launcher/ui/dialogs/CopyInstanceDialog.h @@ -41,6 +41,11 @@ public: QString iconKey() const; bool shouldCopySaves() const; bool shouldKeepPlaytime() const; + bool shouldCopyGameOptions() const; + bool shouldCopyResourcePacks() const; + bool shouldCopyShaderPacks() const; + bool shouldCopyServers() const; + bool shouldCopyMods() const; private slots: @@ -48,6 +53,11 @@ slots: void on_instNameTextBox_textChanged(const QString &arg1); void on_copySavesCheckbox_stateChanged(int state); void on_keepPlaytimeCheckbox_stateChanged(int state); + void on_copyGameOptionsCheckbox_stateChanged(int state); + void on_copyResPacksCheckbox_stateChanged(int state); + void on_copyShaderPacksCheckbox_stateChanged(int state); + void on_copyServersCheckbox_stateChanged(int state); + void on_copyModsCheckbox_stateChanged(int state); private: Ui::CopyInstanceDialog *ui; @@ -55,4 +65,9 @@ private: InstancePtr m_original; bool m_copySaves = true; bool m_keepPlaytime = true; + bool m_copyGameOptions = true; + bool m_copyResourcePacks = true; + bool m_copyShaderPacks = true; + bool m_copyServers = true; + bool m_copyMods = true; }; diff --git a/launcher/ui/dialogs/CopyInstanceDialog.ui b/launcher/ui/dialogs/CopyInstanceDialog.ui index f4b191e2..e89439e6 100644 --- a/launcher/ui/dialogs/CopyInstanceDialog.ui +++ b/launcher/ui/dialogs/CopyInstanceDialog.ui @@ -9,8 +9,8 @@ 0 0 - 345 - 323 + 265 + 425 @@ -33,7 +33,7 @@ - 40 + 60 20 @@ -123,6 +123,50 @@ + + + + Copy the in-game options like FOV, max framerate, etc. + + + Copy game options + + + + + + + true + + + Copy resource packs + + + + + + + Copy shader packs + + + + + + + Copy servers + + + + + + + Disabling this will still keep the mod loader (ex: Fabric, Quilt, etc.) but erase the mods folder and their configs. + + + Copy mods + + + @@ -153,8 +197,8 @@ accept() - 248 - 254 + 254 + 316 157 @@ -169,8 +213,8 @@ reject() - 316 - 260 + 322 + 316 286