From e7e56eb1e397a528df91f9ce99f738c49bde363c Mon Sep 17 00:00:00 2001 From: Marcelo Hernandez Date: Sat, 22 Oct 2022 14:50:32 -0400 Subject: [PATCH 1/8] 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 From 15593b5c0912b4fe5ad77d6a27e336e9b68ed861 Mon Sep 17 00:00:00 2001 From: Marcelo Hernandez Date: Sat, 22 Oct 2022 23:04:36 -0400 Subject: [PATCH 2/8] Add "Select all" checkbox + ui revamp + code cleanup Signed-off-by: Marcelo Hernandez --- launcher/CMakeLists.txt | 1 + launcher/InstanceCopyPrefs.cpp | 15 +++ launcher/InstanceCopyPrefs.h | 3 + launcher/InstanceCopyTask.cpp | 4 +- launcher/InstanceCopyTask.h | 2 +- launcher/ui/MainWindow.cpp | 12 +- launcher/ui/dialogs/CopyInstanceDialog.cpp | 102 ++++++++-------- launcher/ui/dialogs/CopyInstanceDialog.h | 22 ++-- launcher/ui/dialogs/CopyInstanceDialog.ui | 136 +++++++++++---------- 9 files changed, 153 insertions(+), 144 deletions(-) create mode 100644 launcher/InstanceCopyPrefs.cpp diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 77440cca..7dc060fb 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -32,6 +32,7 @@ set(CORE_SOURCES InstanceCreationTask.h InstanceCreationTask.cpp InstanceCopyPrefs.h + InstanceCopyPrefs.cpp InstanceCopyTask.h InstanceCopyTask.cpp InstanceImportTask.h diff --git a/launcher/InstanceCopyPrefs.cpp b/launcher/InstanceCopyPrefs.cpp new file mode 100644 index 00000000..56b43a03 --- /dev/null +++ b/launcher/InstanceCopyPrefs.cpp @@ -0,0 +1,15 @@ +// +// Created by marcelohdez on 10/22/22. +// + +#include "InstanceCopyPrefs.h" + +InstanceCopyPrefs::InstanceCopyPrefs(bool setAll) + : copySaves(setAll), + keepPlaytime(setAll), + copyGameOptions(setAll), + copyResourcePacks(setAll), + copyShaderPacks(setAll), + copyServers(setAll), + copyMods(setAll) +{} diff --git a/launcher/InstanceCopyPrefs.h b/launcher/InstanceCopyPrefs.h index ac2feab8..d360a8a7 100644 --- a/launcher/InstanceCopyPrefs.h +++ b/launcher/InstanceCopyPrefs.h @@ -6,6 +6,9 @@ #define LAUNCHER_INSTANCECOPYPREFS_H struct InstanceCopyPrefs { + explicit InstanceCopyPrefs(bool setAll); + ~InstanceCopyPrefs() = default; + bool copySaves; bool keepPlaytime; bool copyGameOptions; diff --git a/launcher/InstanceCopyTask.cpp b/launcher/InstanceCopyTask.cpp index 360f6cfa..e0f68224 100644 --- a/launcher/InstanceCopyTask.cpp +++ b/launcher/InstanceCopyTask.cpp @@ -5,7 +5,7 @@ #include "pathmatcher/RegexpMatcher.h" #include -InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, InstanceCopyPrefs prefs) +InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, const InstanceCopyPrefs& prefs) { m_origInstance = origInstance; m_keepPlaytime = prefs.keepPlaytime; @@ -51,7 +51,7 @@ InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, InstanceCopyPrefs p } } -void InstanceCopyTask::appendToFilter(QString& filter, const QString &append) +void InstanceCopyTask::appendToFilter(QString& filter, const QString& append) { if (!filter.isEmpty()) filter.append('|'); // OR regex diff --git a/launcher/InstanceCopyTask.h b/launcher/InstanceCopyTask.h index d66bec55..4abbf6e6 100644 --- a/launcher/InstanceCopyTask.h +++ b/launcher/InstanceCopyTask.h @@ -15,7 +15,7 @@ class InstanceCopyTask : public InstanceTask { Q_OBJECT public: - explicit InstanceCopyTask(InstancePtr origInstance, InstanceCopyPrefs prefs); + explicit InstanceCopyTask(InstancePtr origInstance, const InstanceCopyPrefs& prefs); protected: //! Entry point for tasks. diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index d51f799c..08005b86 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -1616,17 +1616,7 @@ void MainWindow::on_actionCopyInstance_triggered() if (!copyInstDlg.exec()) return; - auto copyTask = new InstanceCopyTask( - m_selectedInstance, - InstanceCopyPrefs { - copyInstDlg.shouldCopySaves(), - copyInstDlg.shouldKeepPlaytime(), - copyInstDlg.shouldCopyGameOptions(), - copyInstDlg.shouldCopyResourcePacks(), - copyInstDlg.shouldCopyShaderPacks(), - copyInstDlg.shouldCopyServers(), - copyInstDlg.shouldCopyMods() - }); + auto copyTask = new InstanceCopyTask(m_selectedInstance, copyInstDlg.getChosenOptions()); 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 d19888ed..0a23cd34 100644 --- a/launcher/ui/dialogs/CopyInstanceDialog.cpp +++ b/launcher/ui/dialogs/CopyInstanceDialog.cpp @@ -78,13 +78,13 @@ CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget *parent) } ui->groupBox->setCurrentIndex(index); 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); + ui->copySavesCheckbox->setChecked(m_selectedOptions.copySaves); + ui->keepPlaytimeCheckbox->setChecked(m_selectedOptions.keepPlaytime); + ui->copyGameOptionsCheckbox->setChecked(m_selectedOptions.copyGameOptions); + ui->copyResPacksCheckbox->setChecked(m_selectedOptions.copyResourcePacks); + ui->copyShaderPacksCheckbox->setChecked(m_selectedOptions.copyShaderPacks); + ui->copyServersCheckbox->setChecked(m_selectedOptions.copyServers); + ui->copyModsCheckbox->setChecked(m_selectedOptions.copyMods); } CopyInstanceDialog::~CopyInstanceDialog() @@ -139,122 +139,118 @@ void CopyInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1) updateDialogState(); } -bool CopyInstanceDialog::shouldCopySaves() const +const InstanceCopyPrefs& CopyInstanceDialog::getChosenOptions() const { - return m_copySaves; + return m_selectedOptions; +} + +void CopyInstanceDialog::on_selectAllCheckbox_stateChanged(int state) +{ + bool checked; + if(state == Qt::Unchecked) + { + checked = false; + } + else if(state == Qt::Checked) + { + checked = true; + } + + checkAllCheckboxes(checked); +} + +void CopyInstanceDialog::checkAllCheckboxes(bool b) +{ + ui->keepPlaytimeCheckbox->setChecked(b); + ui->copySavesCheckbox->setChecked(b); + ui->copyGameOptionsCheckbox->setChecked(b); + ui->copyResPacksCheckbox->setChecked(b); + ui->copyShaderPacksCheckbox->setChecked(b); + ui->copyServersCheckbox->setChecked(b); + ui->copyModsCheckbox->setChecked(b); } void CopyInstanceDialog::on_copySavesCheckbox_stateChanged(int state) { if(state == Qt::Unchecked) { - m_copySaves = false; + m_selectedOptions.copySaves = false; } else if(state == Qt::Checked) { - m_copySaves = true; + m_selectedOptions.copySaves = true; } } -bool CopyInstanceDialog::shouldKeepPlaytime() const -{ - return m_keepPlaytime; -} - void CopyInstanceDialog::on_keepPlaytimeCheckbox_stateChanged(int state) { if(state == Qt::Unchecked) { - m_keepPlaytime = false; + m_selectedOptions.keepPlaytime = false; } else if(state == Qt::Checked) { - m_keepPlaytime = true; + m_selectedOptions.keepPlaytime = true; } } -bool CopyInstanceDialog::shouldCopyGameOptions() const -{ - return m_copyGameOptions; -} - void CopyInstanceDialog::on_copyGameOptionsCheckbox_stateChanged(int state) { if(state == Qt::Unchecked) { - m_copyGameOptions = false; + m_selectedOptions.copyGameOptions = false; } else if(state == Qt::Checked) { - m_copyGameOptions = true; + m_selectedOptions.copyGameOptions = true; } } -bool CopyInstanceDialog::shouldCopyResourcePacks() const -{ - return m_copyResourcePacks; -} - void CopyInstanceDialog::on_copyResPacksCheckbox_stateChanged(int state) { if(state == Qt::Unchecked) { - m_copyResourcePacks = false; + m_selectedOptions.copyResourcePacks = false; } else if(state == Qt::Checked) { - m_copyResourcePacks = true; + m_selectedOptions.copyResourcePacks = true; } } -bool CopyInstanceDialog::shouldCopyShaderPacks() const -{ - return m_copyShaderPacks; -} - void CopyInstanceDialog::on_copyShaderPacksCheckbox_stateChanged(int state) { if(state == Qt::Unchecked) { - m_copyShaderPacks = false; + m_selectedOptions.copyShaderPacks = false; } else if(state == Qt::Checked) { - m_copyShaderPacks = true; + m_selectedOptions.copyShaderPacks = true; } } -bool CopyInstanceDialog::shouldCopyServers() const -{ - return m_copyServers; -} - void CopyInstanceDialog::on_copyServersCheckbox_stateChanged(int state) { if(state == Qt::Unchecked) { - m_copyServers = false; + m_selectedOptions.copyServers = false; } else if(state == Qt::Checked) { - m_copyServers = true; + m_selectedOptions.copyServers = true; } } -bool CopyInstanceDialog::shouldCopyMods() const -{ - return m_copyMods; -} - void CopyInstanceDialog::on_copyModsCheckbox_stateChanged(int state) { if(state == Qt::Unchecked) { - m_copyMods = false; + m_selectedOptions.copyMods = false; } else if(state == Qt::Checked) { - m_copyMods = true; + m_selectedOptions.copyMods = true; } } diff --git a/launcher/ui/dialogs/CopyInstanceDialog.h b/launcher/ui/dialogs/CopyInstanceDialog.h index e4c70494..e57de0a1 100644 --- a/launcher/ui/dialogs/CopyInstanceDialog.h +++ b/launcher/ui/dialogs/CopyInstanceDialog.h @@ -17,7 +17,7 @@ #include #include "BaseVersion.h" -#include +#include "InstanceCopyPrefs.h" class BaseInstance; @@ -39,18 +39,16 @@ public: QString instName() const; QString instGroup() const; QString iconKey() const; - bool shouldCopySaves() const; - bool shouldKeepPlaytime() const; - bool shouldCopyGameOptions() const; - bool shouldCopyResourcePacks() const; - bool shouldCopyShaderPacks() const; - bool shouldCopyServers() const; - bool shouldCopyMods() const; + const InstanceCopyPrefs& getChosenOptions() const; private slots: void on_iconButton_clicked(); void on_instNameTextBox_textChanged(const QString &arg1); + + // Checkbox options: + void checkAllCheckboxes(bool b); + void on_selectAllCheckbox_stateChanged(int state); void on_copySavesCheckbox_stateChanged(int state); void on_keepPlaytimeCheckbox_stateChanged(int state); void on_copyGameOptionsCheckbox_stateChanged(int state); @@ -63,11 +61,5 @@ private: Ui::CopyInstanceDialog *ui; QString InstIconKey; 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; + InstanceCopyPrefs m_selectedOptions = InstanceCopyPrefs(true); // Default to all options as true }; diff --git a/launcher/ui/dialogs/CopyInstanceDialog.ui b/launcher/ui/dialogs/CopyInstanceDialog.ui index e89439e6..822ed797 100644 --- a/launcher/ui/dialogs/CopyInstanceDialog.ui +++ b/launcher/ui/dialogs/CopyInstanceDialog.ui @@ -9,8 +9,8 @@ 0 0 - 265 - 425 + 341 + 385 @@ -60,7 +60,7 @@ - 40 + 60 20 @@ -83,7 +83,10 @@ - + + + 6 + @@ -110,62 +113,73 @@ - - - Copy saves - - - - - - - Keep play time - - - - - - - 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 - - + + + + + Copy saves + + + + + + + true + + + Copy resource packs + + + + + + + Disabling this will still keep the mod loader (ex: Fabric, Quilt, etc.) but erase the mods folder and their configs. + + + Copy mods + + + + + + + Copy the in-game options like FOV, max framerate, etc. + + + Copy game options + + + + + + + Copy servers + + + + + + + Keep play time + + + + + + + Copy shader packs + + + + + + + Select all + + + + @@ -183,8 +197,6 @@ iconButton instNameTextBox groupBox - copySavesCheckbox - keepPlaytimeCheckbox From 4caf06bc99dfe34f10fae943374c98b88ad8814d Mon Sep 17 00:00:00 2001 From: Marcelo Hernandez Date: Sun, 23 Oct 2022 00:25:38 -0400 Subject: [PATCH 3/8] Check "Select all" checkbox if all options are already selected + code cleanup Signed-off-by: Marcelo Hernandez --- launcher/InstanceCopyPrefs.cpp | 19 ++-- launcher/InstanceCopyPrefs.h | 17 ++- launcher/ui/dialogs/CopyInstanceDialog.cpp | 124 +++++++-------------- launcher/ui/dialogs/CopyInstanceDialog.h | 6 +- 4 files changed, 65 insertions(+), 101 deletions(-) diff --git a/launcher/InstanceCopyPrefs.cpp b/launcher/InstanceCopyPrefs.cpp index 56b43a03..fad55d1e 100644 --- a/launcher/InstanceCopyPrefs.cpp +++ b/launcher/InstanceCopyPrefs.cpp @@ -4,12 +4,13 @@ #include "InstanceCopyPrefs.h" -InstanceCopyPrefs::InstanceCopyPrefs(bool setAll) - : copySaves(setAll), - keepPlaytime(setAll), - copyGameOptions(setAll), - copyResourcePacks(setAll), - copyShaderPacks(setAll), - copyServers(setAll), - copyMods(setAll) -{} +bool InstanceCopyPrefs::allTrue() const +{ + return copySaves && + keepPlaytime && + copyGameOptions && + copyResourcePacks && + copyShaderPacks && + copyServers && + copyMods; +} diff --git a/launcher/InstanceCopyPrefs.h b/launcher/InstanceCopyPrefs.h index d360a8a7..c5c1a7ae 100644 --- a/launcher/InstanceCopyPrefs.h +++ b/launcher/InstanceCopyPrefs.h @@ -6,16 +6,15 @@ #define LAUNCHER_INSTANCECOPYPREFS_H struct InstanceCopyPrefs { - explicit InstanceCopyPrefs(bool setAll); - ~InstanceCopyPrefs() = default; + bool copySaves = true; + bool keepPlaytime = true; + bool copyGameOptions = true; + bool copyResourcePacks = true; + bool copyShaderPacks = true; + bool copyServers = true; + bool copyMods = true; - bool copySaves; - bool keepPlaytime; - bool copyGameOptions; - bool copyResourcePacks; - bool copyShaderPacks; - bool copyServers; - bool copyMods; + bool allTrue() const; }; #endif // LAUNCHER_INSTANCECOPYPREFS_H diff --git a/launcher/ui/dialogs/CopyInstanceDialog.cpp b/launcher/ui/dialogs/CopyInstanceDialog.cpp index 0a23cd34..44e70012 100644 --- a/launcher/ui/dialogs/CopyInstanceDialog.cpp +++ b/launcher/ui/dialogs/CopyInstanceDialog.cpp @@ -122,6 +122,40 @@ QString CopyInstanceDialog::instGroup() const return ui->groupBox->currentText(); } +const InstanceCopyPrefs& CopyInstanceDialog::getChosenOptions() const +{ + return m_selectedOptions; +} + +void CopyInstanceDialog::checkAllCheckboxes(const bool& b) +{ + ui->keepPlaytimeCheckbox->setChecked(b); + ui->copySavesCheckbox->setChecked(b); + ui->copyGameOptionsCheckbox->setChecked(b); + ui->copyResPacksCheckbox->setChecked(b); + ui->copyShaderPacksCheckbox->setChecked(b); + ui->copyServersCheckbox->setChecked(b); + ui->copyModsCheckbox->setChecked(b); +} + +// Sets b to true if state is a checked checkbox +void CopyInstanceDialog::checkBool(bool& b, const int& state) +{ + if(state == Qt::Unchecked) + { + b = false; + } + else if(state == Qt::Checked) + { + b = true; + } + + // Have "Select all" checkbox checked if all options are already checked: + ui->selectAllCheckbox->blockSignals(true); + ui->selectAllCheckbox->setChecked(m_selectedOptions.allTrue()); + ui->selectAllCheckbox->blockSignals(false); +} + void CopyInstanceDialog::on_iconButton_clicked() { IconPickerDialog dlg(this); @@ -134,123 +168,51 @@ void CopyInstanceDialog::on_iconButton_clicked() } } + void CopyInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1) { updateDialogState(); } -const InstanceCopyPrefs& CopyInstanceDialog::getChosenOptions() const -{ - return m_selectedOptions; -} - void CopyInstanceDialog::on_selectAllCheckbox_stateChanged(int state) { bool checked; - if(state == Qt::Unchecked) - { - checked = false; - } - else if(state == Qt::Checked) - { - checked = true; - } - + checkBool(checked, state); checkAllCheckboxes(checked); } -void CopyInstanceDialog::checkAllCheckboxes(bool b) -{ - ui->keepPlaytimeCheckbox->setChecked(b); - ui->copySavesCheckbox->setChecked(b); - ui->copyGameOptionsCheckbox->setChecked(b); - ui->copyResPacksCheckbox->setChecked(b); - ui->copyShaderPacksCheckbox->setChecked(b); - ui->copyServersCheckbox->setChecked(b); - ui->copyModsCheckbox->setChecked(b); -} - void CopyInstanceDialog::on_copySavesCheckbox_stateChanged(int state) { - if(state == Qt::Unchecked) - { - m_selectedOptions.copySaves = false; - } - else if(state == Qt::Checked) - { - m_selectedOptions.copySaves = true; - } + checkBool(m_selectedOptions.copySaves, state); } void CopyInstanceDialog::on_keepPlaytimeCheckbox_stateChanged(int state) { - if(state == Qt::Unchecked) - { - m_selectedOptions.keepPlaytime = false; - } - else if(state == Qt::Checked) - { - m_selectedOptions.keepPlaytime = true; - } + checkBool(m_selectedOptions.keepPlaytime, state); } void CopyInstanceDialog::on_copyGameOptionsCheckbox_stateChanged(int state) { - if(state == Qt::Unchecked) - { - m_selectedOptions.copyGameOptions = false; - } - else if(state == Qt::Checked) - { - m_selectedOptions.copyGameOptions = true; - } + checkBool(m_selectedOptions.copyGameOptions, state); } void CopyInstanceDialog::on_copyResPacksCheckbox_stateChanged(int state) { - if(state == Qt::Unchecked) - { - m_selectedOptions.copyResourcePacks = false; - } - else if(state == Qt::Checked) - { - m_selectedOptions.copyResourcePacks = true; - } + checkBool(m_selectedOptions.copyResourcePacks, state); } void CopyInstanceDialog::on_copyShaderPacksCheckbox_stateChanged(int state) { - if(state == Qt::Unchecked) - { - m_selectedOptions.copyShaderPacks = false; - } - else if(state == Qt::Checked) - { - m_selectedOptions.copyShaderPacks = true; - } + checkBool(m_selectedOptions.copyShaderPacks, state); } void CopyInstanceDialog::on_copyServersCheckbox_stateChanged(int state) { - if(state == Qt::Unchecked) - { - m_selectedOptions.copyServers = false; - } - else if(state == Qt::Checked) - { - m_selectedOptions.copyServers = true; - } + checkBool(m_selectedOptions.copyServers, state); } void CopyInstanceDialog::on_copyModsCheckbox_stateChanged(int state) { - if(state == Qt::Unchecked) - { - m_selectedOptions.copyMods = false; - } - else if(state == Qt::Checked) - { - m_selectedOptions.copyMods = true; - } + checkBool(m_selectedOptions.copyMods, state); } diff --git a/launcher/ui/dialogs/CopyInstanceDialog.h b/launcher/ui/dialogs/CopyInstanceDialog.h index e57de0a1..4171c440 100644 --- a/launcher/ui/dialogs/CopyInstanceDialog.h +++ b/launcher/ui/dialogs/CopyInstanceDialog.h @@ -47,7 +47,9 @@ slots: void on_instNameTextBox_textChanged(const QString &arg1); // Checkbox options: - void checkAllCheckboxes(bool b); + void checkAllCheckboxes(const bool& b); + void checkBool(bool& b, const int& state); + void on_selectAllCheckbox_stateChanged(int state); void on_copySavesCheckbox_stateChanged(int state); void on_keepPlaytimeCheckbox_stateChanged(int state); @@ -61,5 +63,5 @@ private: Ui::CopyInstanceDialog *ui; QString InstIconKey; InstancePtr m_original; - InstanceCopyPrefs m_selectedOptions = InstanceCopyPrefs(true); // Default to all options as true + InstanceCopyPrefs m_selectedOptions; }; From a89df42561cc3089c4878c0c44353fcd1359bf53 Mon Sep 17 00:00:00 2001 From: Marcelo Hernandez <76508651+marcelohdez@users.noreply.github.com> Date: Mon, 24 Oct 2022 19:27:21 -0400 Subject: [PATCH 4/8] Simplify bool check in CopyInstanceDialog.cpp Signed-off-by: Marcelo Hernandez --- launcher/ui/dialogs/CopyInstanceDialog.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/launcher/ui/dialogs/CopyInstanceDialog.cpp b/launcher/ui/dialogs/CopyInstanceDialog.cpp index 44e70012..1b8e2aa0 100644 --- a/launcher/ui/dialogs/CopyInstanceDialog.cpp +++ b/launcher/ui/dialogs/CopyInstanceDialog.cpp @@ -141,14 +141,7 @@ void CopyInstanceDialog::checkAllCheckboxes(const bool& b) // Sets b to true if state is a checked checkbox void CopyInstanceDialog::checkBool(bool& b, const int& state) { - if(state == Qt::Unchecked) - { - b = false; - } - else if(state == Qt::Checked) - { - b = true; - } + b = (state == Qt::Checked); // Have "Select all" checkbox checked if all options are already checked: ui->selectAllCheckbox->blockSignals(true); From 385c452ddffa2f40b21d7decede9f255e2b24d45 Mon Sep 17 00:00:00 2001 From: Marcelo Hernandez Date: Mon, 24 Oct 2022 20:49:40 -0400 Subject: [PATCH 5/8] remove checkBool function, add updateSelectAllCheckbox function Signed-off-by: Marcelo Hernandez --- launcher/ui/dialogs/CopyInstanceDialog.cpp | 30 ++++++++++++---------- launcher/ui/dialogs/CopyInstanceDialog.h | 9 +++---- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/launcher/ui/dialogs/CopyInstanceDialog.cpp b/launcher/ui/dialogs/CopyInstanceDialog.cpp index 1b8e2aa0..8445f0a9 100644 --- a/launcher/ui/dialogs/CopyInstanceDialog.cpp +++ b/launcher/ui/dialogs/CopyInstanceDialog.cpp @@ -138,12 +138,9 @@ void CopyInstanceDialog::checkAllCheckboxes(const bool& b) ui->copyModsCheckbox->setChecked(b); } -// Sets b to true if state is a checked checkbox -void CopyInstanceDialog::checkBool(bool& b, const int& state) +// Check the "Select all" checkbox checked if all options are already checked: +void CopyInstanceDialog::updateSelectAllCheckbox() { - b = (state == Qt::Checked); - - // Have "Select all" checkbox checked if all options are already checked: ui->selectAllCheckbox->blockSignals(true); ui->selectAllCheckbox->setChecked(m_selectedOptions.allTrue()); ui->selectAllCheckbox->blockSignals(false); @@ -170,42 +167,49 @@ void CopyInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1) void CopyInstanceDialog::on_selectAllCheckbox_stateChanged(int state) { bool checked; - checkBool(checked, state); + checked = (state == Qt::Checked); checkAllCheckboxes(checked); } void CopyInstanceDialog::on_copySavesCheckbox_stateChanged(int state) { - checkBool(m_selectedOptions.copySaves, state); + m_selectedOptions.copySaves = (state == Qt::Checked); + updateSelectAllCheckbox(); } void CopyInstanceDialog::on_keepPlaytimeCheckbox_stateChanged(int state) { - checkBool(m_selectedOptions.keepPlaytime, state); + m_selectedOptions.keepPlaytime = (state == Qt::Checked); + updateSelectAllCheckbox(); } void CopyInstanceDialog::on_copyGameOptionsCheckbox_stateChanged(int state) { - checkBool(m_selectedOptions.copyGameOptions, state); + m_selectedOptions.copyGameOptions = (state == Qt::Checked); + updateSelectAllCheckbox(); } void CopyInstanceDialog::on_copyResPacksCheckbox_stateChanged(int state) { - checkBool(m_selectedOptions.copyResourcePacks, state); + m_selectedOptions.copyResourcePacks = (state == Qt::Checked); + updateSelectAllCheckbox(); } void CopyInstanceDialog::on_copyShaderPacksCheckbox_stateChanged(int state) { - checkBool(m_selectedOptions.copyShaderPacks, state); + m_selectedOptions.copyShaderPacks = (state == Qt::Checked); + updateSelectAllCheckbox(); } void CopyInstanceDialog::on_copyServersCheckbox_stateChanged(int state) { - checkBool(m_selectedOptions.copyServers, state); + m_selectedOptions.copyServers = (state == Qt::Checked); + updateSelectAllCheckbox(); } void CopyInstanceDialog::on_copyModsCheckbox_stateChanged(int state) { - checkBool(m_selectedOptions.copyMods, state); + m_selectedOptions.copyMods = (state == Qt::Checked); + updateSelectAllCheckbox(); } diff --git a/launcher/ui/dialogs/CopyInstanceDialog.h b/launcher/ui/dialogs/CopyInstanceDialog.h index 4171c440..94015334 100644 --- a/launcher/ui/dialogs/CopyInstanceDialog.h +++ b/launcher/ui/dialogs/CopyInstanceDialog.h @@ -45,11 +45,7 @@ private slots: void on_iconButton_clicked(); void on_instNameTextBox_textChanged(const QString &arg1); - - // Checkbox options: - void checkAllCheckboxes(const bool& b); - void checkBool(bool& b, const int& state); - + // Checkboxes void on_selectAllCheckbox_stateChanged(int state); void on_copySavesCheckbox_stateChanged(int state); void on_keepPlaytimeCheckbox_stateChanged(int state); @@ -60,6 +56,9 @@ slots: void on_copyModsCheckbox_stateChanged(int state); private: + void checkAllCheckboxes(const bool& b); + void updateSelectAllCheckbox(); + /* data */ Ui::CopyInstanceDialog *ui; QString InstIconKey; InstancePtr m_original; From 63b6c6685ce53e3fac1902e0ee7a6998c5d341d0 Mon Sep 17 00:00:00 2001 From: Marcelo Hernandez Date: Wed, 26 Oct 2022 00:20:36 -0400 Subject: [PATCH 6/8] Abstract away InstanceCopyPrefs' internals through new getSelectedFiltersAsRegex() function + fix typo in comment + remove unused import + add [[nodiscard]] to methods Signed-off-by: Marcelo Hernandez --- launcher/InstanceCopyPrefs.cpp | 33 ++++++++++++ launcher/InstanceCopyPrefs.h | 5 +- launcher/InstanceCopyTask.cpp | 60 +++------------------- launcher/InstanceCopyTask.h | 4 -- launcher/ui/dialogs/CopyInstanceDialog.cpp | 3 +- 5 files changed, 45 insertions(+), 60 deletions(-) diff --git a/launcher/InstanceCopyPrefs.cpp b/launcher/InstanceCopyPrefs.cpp index fad55d1e..6432a535 100644 --- a/launcher/InstanceCopyPrefs.cpp +++ b/launcher/InstanceCopyPrefs.cpp @@ -14,3 +14,36 @@ bool InstanceCopyPrefs::allTrue() const copyServers && copyMods; } + +// Returns a single RegEx string of the selected folders/files to filter out (ex: ".minecraft/saves|.minecraft/server.dat") +QString InstanceCopyPrefs::getSelectedFiltersAsRegex() const +{ + QStringList filters; + + if(!copySaves) + filters << "saves"; + + if(!copyGameOptions) + filters << "options.txt"; + + if(!copyResourcePacks) + filters << "resourcepacks" << "texturepacks"; + + if(!copyShaderPacks) + filters << "shaderpacks"; + + if(!copyServers) + filters << "servers.dat" << "servers.dat_old" << "server-resource-packs"; + + if(!copyMods) + filters << "coremods" << "mods" << "config"; + + // If we have any filters to add, join them as a single regex string to return: + if (!filters.isEmpty()) { + const QString MC_ROOT = "[.]?minecraft/"; + // Ensure first filter starts with root, then join other filters with OR regex before root (ex: ".minecraft/saves|.minecraft/mods"): + return MC_ROOT + filters.join("|" + MC_ROOT); + } + + return {}; +} diff --git a/launcher/InstanceCopyPrefs.h b/launcher/InstanceCopyPrefs.h index c5c1a7ae..432d67c4 100644 --- a/launcher/InstanceCopyPrefs.h +++ b/launcher/InstanceCopyPrefs.h @@ -5,6 +5,8 @@ #ifndef LAUNCHER_INSTANCECOPYPREFS_H #define LAUNCHER_INSTANCECOPYPREFS_H +#include + struct InstanceCopyPrefs { bool copySaves = true; bool keepPlaytime = true; @@ -14,7 +16,8 @@ struct InstanceCopyPrefs { bool copyServers = true; bool copyMods = true; - bool allTrue() const; + [[nodiscard]] bool allTrue() const; + [[nodiscard]] QString getSelectedFiltersAsRegex() const; }; #endif // LAUNCHER_INSTANCECOPYPREFS_H diff --git a/launcher/InstanceCopyTask.cpp b/launcher/InstanceCopyTask.cpp index e0f68224..7fbf8636 100644 --- a/launcher/InstanceCopyTask.cpp +++ b/launcher/InstanceCopyTask.cpp @@ -9,62 +9,16 @@ InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, const InstanceCopyP { m_origInstance = origInstance; m_keepPlaytime = prefs.keepPlaytime; - QString filter; - if(!prefs.copySaves) + QString filters = prefs.getSelectedFiltersAsRegex(); + if (!filters.isEmpty()) { - appendToFilter(filter, "saves"); + // Set regex filter: + // FIXME: get this from the original instance type... + auto matcherReal = new RegexpMatcher(filters); + matcherReal->caseSensitive(false); + m_matcher.reset(matcherReal); } - - 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 4abbf6e6..1f29b854 100644 --- a/launcher/InstanceCopyTask.h +++ b/launcher/InstanceCopyTask.h @@ -24,10 +24,6 @@ protected: void copyAborted(); 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; diff --git a/launcher/ui/dialogs/CopyInstanceDialog.cpp b/launcher/ui/dialogs/CopyInstanceDialog.cpp index 8445f0a9..e658f26d 100644 --- a/launcher/ui/dialogs/CopyInstanceDialog.cpp +++ b/launcher/ui/dialogs/CopyInstanceDialog.cpp @@ -44,7 +44,6 @@ #include "BaseVersion.h" #include "icons/IconList.h" -#include "tasks/Task.h" #include "BaseInstance.h" #include "InstanceList.h" @@ -138,7 +137,7 @@ void CopyInstanceDialog::checkAllCheckboxes(const bool& b) ui->copyModsCheckbox->setChecked(b); } -// Check the "Select all" checkbox checked if all options are already checked: +// Check the "Select all" checkbox if all options are already selected: void CopyInstanceDialog::updateSelectAllCheckbox() { ui->selectAllCheckbox->blockSignals(true); From c00f96c7ca49a624ea8e9c4774ea11e954bbdc4b Mon Sep 17 00:00:00 2001 From: Marcelo Hernandez Date: Sat, 29 Oct 2022 00:55:33 -0400 Subject: [PATCH 7/8] create getters and setters for InstanceCopyPrefs + use pragma once like other .h files in this directory Signed-off-by: Marcelo Hernandez --- launcher/InstanceCopyPrefs.cpp | 72 ++++++++++++++++++++++ launcher/InstanceCopyPrefs.h | 29 ++++++--- launcher/InstanceCopyTask.cpp | 2 +- launcher/ui/dialogs/CopyInstanceDialog.cpp | 28 ++++----- 4 files changed, 109 insertions(+), 22 deletions(-) diff --git a/launcher/InstanceCopyPrefs.cpp b/launcher/InstanceCopyPrefs.cpp index 6432a535..ae30bb82 100644 --- a/launcher/InstanceCopyPrefs.cpp +++ b/launcher/InstanceCopyPrefs.cpp @@ -47,3 +47,75 @@ QString InstanceCopyPrefs::getSelectedFiltersAsRegex() const return {}; } + +// ======= Getters ======= +bool InstanceCopyPrefs::isCopySavesEnabled() const +{ + return copySaves; +} + +bool InstanceCopyPrefs::isKeepPlaytimeEnabled() const +{ + return keepPlaytime; +} + +bool InstanceCopyPrefs::isCopyGameOptionsEnabled() const +{ + return copyGameOptions; +} + +bool InstanceCopyPrefs::isCopyResourcePacksEnabled() const +{ + return copyResourcePacks; +} + +bool InstanceCopyPrefs::isCopyShaderPacksEnabled() const +{ + return copyShaderPacks; +} + +bool InstanceCopyPrefs::isCopyServersEnabled() const +{ + return copyServers; +} + +bool InstanceCopyPrefs::isCopyModsEnabled() const +{ + return copyMods; +} + +// ======= Setters ======= +void InstanceCopyPrefs::enableCopySaves(bool b) +{ + copySaves = b; +} + +void InstanceCopyPrefs::enableKeepPlaytime(bool b) +{ + keepPlaytime = b; +} + +void InstanceCopyPrefs::enableCopyGameOptions(bool b) +{ + copyGameOptions = b; +} + +void InstanceCopyPrefs::enableCopyResourcePacks(bool b) +{ + copyResourcePacks = b; +} + +void InstanceCopyPrefs::enableCopyShaderPacks(bool b) +{ + copyShaderPacks = b; +} + +void InstanceCopyPrefs::enableCopyServers(bool b) +{ + copyServers = b; +} + +void InstanceCopyPrefs::enableCopyMods(bool b) +{ + copyMods = b; +} diff --git a/launcher/InstanceCopyPrefs.h b/launcher/InstanceCopyPrefs.h index 432d67c4..3855965d 100644 --- a/launcher/InstanceCopyPrefs.h +++ b/launcher/InstanceCopyPrefs.h @@ -2,12 +2,32 @@ // Created by marcelohdez on 10/22/22. // -#ifndef LAUNCHER_INSTANCECOPYPREFS_H -#define LAUNCHER_INSTANCECOPYPREFS_H +#pragma once #include struct InstanceCopyPrefs { + public: + [[nodiscard]] bool allTrue() const; + [[nodiscard]] QString getSelectedFiltersAsRegex() const; + // Getters + [[nodiscard]] bool isCopySavesEnabled() const; + [[nodiscard]] bool isKeepPlaytimeEnabled() const; + [[nodiscard]] bool isCopyGameOptionsEnabled() const; + [[nodiscard]] bool isCopyResourcePacksEnabled() const; + [[nodiscard]] bool isCopyShaderPacksEnabled() const; + [[nodiscard]] bool isCopyServersEnabled() const; + [[nodiscard]] bool isCopyModsEnabled() const; + // Setters + void enableCopySaves(bool b); + void enableKeepPlaytime(bool b); + void enableCopyGameOptions(bool b); + void enableCopyResourcePacks(bool b); + void enableCopyShaderPacks(bool b); + void enableCopyServers(bool b); + void enableCopyMods(bool b); + + protected: // data bool copySaves = true; bool keepPlaytime = true; bool copyGameOptions = true; @@ -15,9 +35,4 @@ struct InstanceCopyPrefs { bool copyShaderPacks = true; bool copyServers = true; bool copyMods = true; - - [[nodiscard]] bool allTrue() const; - [[nodiscard]] QString getSelectedFiltersAsRegex() const; }; - -#endif // LAUNCHER_INSTANCECOPYPREFS_H diff --git a/launcher/InstanceCopyTask.cpp b/launcher/InstanceCopyTask.cpp index 7fbf8636..a4ea947d 100644 --- a/launcher/InstanceCopyTask.cpp +++ b/launcher/InstanceCopyTask.cpp @@ -8,7 +8,7 @@ InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, const InstanceCopyPrefs& prefs) { m_origInstance = origInstance; - m_keepPlaytime = prefs.keepPlaytime; + m_keepPlaytime = prefs.isKeepPlaytimeEnabled(); QString filters = prefs.getSelectedFiltersAsRegex(); if (!filters.isEmpty()) diff --git a/launcher/ui/dialogs/CopyInstanceDialog.cpp b/launcher/ui/dialogs/CopyInstanceDialog.cpp index e658f26d..f76b509e 100644 --- a/launcher/ui/dialogs/CopyInstanceDialog.cpp +++ b/launcher/ui/dialogs/CopyInstanceDialog.cpp @@ -77,13 +77,13 @@ CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget *parent) } ui->groupBox->setCurrentIndex(index); ui->groupBox->lineEdit()->setPlaceholderText(tr("No group")); - ui->copySavesCheckbox->setChecked(m_selectedOptions.copySaves); - ui->keepPlaytimeCheckbox->setChecked(m_selectedOptions.keepPlaytime); - ui->copyGameOptionsCheckbox->setChecked(m_selectedOptions.copyGameOptions); - ui->copyResPacksCheckbox->setChecked(m_selectedOptions.copyResourcePacks); - ui->copyShaderPacksCheckbox->setChecked(m_selectedOptions.copyShaderPacks); - ui->copyServersCheckbox->setChecked(m_selectedOptions.copyServers); - ui->copyModsCheckbox->setChecked(m_selectedOptions.copyMods); + ui->copySavesCheckbox->setChecked(m_selectedOptions.isCopySavesEnabled()); + ui->keepPlaytimeCheckbox->setChecked(m_selectedOptions.isKeepPlaytimeEnabled()); + ui->copyGameOptionsCheckbox->setChecked(m_selectedOptions.isCopyGameOptionsEnabled()); + ui->copyResPacksCheckbox->setChecked(m_selectedOptions.isCopyResourcePacksEnabled()); + ui->copyShaderPacksCheckbox->setChecked(m_selectedOptions.isCopyShaderPacksEnabled()); + ui->copyServersCheckbox->setChecked(m_selectedOptions.isCopyServersEnabled()); + ui->copyModsCheckbox->setChecked(m_selectedOptions.isCopyModsEnabled()); } CopyInstanceDialog::~CopyInstanceDialog() @@ -172,43 +172,43 @@ void CopyInstanceDialog::on_selectAllCheckbox_stateChanged(int state) void CopyInstanceDialog::on_copySavesCheckbox_stateChanged(int state) { - m_selectedOptions.copySaves = (state == Qt::Checked); + m_selectedOptions.enableCopySaves(state == Qt::Checked); updateSelectAllCheckbox(); } void CopyInstanceDialog::on_keepPlaytimeCheckbox_stateChanged(int state) { - m_selectedOptions.keepPlaytime = (state == Qt::Checked); + m_selectedOptions.enableKeepPlaytime(state == Qt::Checked); updateSelectAllCheckbox(); } void CopyInstanceDialog::on_copyGameOptionsCheckbox_stateChanged(int state) { - m_selectedOptions.copyGameOptions = (state == Qt::Checked); + m_selectedOptions.enableCopyGameOptions(state == Qt::Checked); updateSelectAllCheckbox(); } void CopyInstanceDialog::on_copyResPacksCheckbox_stateChanged(int state) { - m_selectedOptions.copyResourcePacks = (state == Qt::Checked); + m_selectedOptions.enableCopyResourcePacks(state == Qt::Checked); updateSelectAllCheckbox(); } void CopyInstanceDialog::on_copyShaderPacksCheckbox_stateChanged(int state) { - m_selectedOptions.copyShaderPacks = (state == Qt::Checked); + m_selectedOptions.enableCopyShaderPacks(state == Qt::Checked); updateSelectAllCheckbox(); } void CopyInstanceDialog::on_copyServersCheckbox_stateChanged(int state) { - m_selectedOptions.copyServers = (state == Qt::Checked); + m_selectedOptions.enableCopyServers(state == Qt::Checked); updateSelectAllCheckbox(); } void CopyInstanceDialog::on_copyModsCheckbox_stateChanged(int state) { - m_selectedOptions.copyMods = (state == Qt::Checked); + m_selectedOptions.enableCopyMods(state == Qt::Checked); updateSelectAllCheckbox(); } From 5d1aac3c53904f7c843dc5cfdbdd33086eb4b6d6 Mon Sep 17 00:00:00 2001 From: Marcelo Hernandez Date: Sat, 29 Oct 2022 22:27:31 -0400 Subject: [PATCH 8/8] added option to not copy screenshots + moved select all checkbox to top row, centered. Signed-off-by: Marcelo Hernandez --- launcher/InstanceCopyPrefs.cpp | 16 +++- launcher/InstanceCopyPrefs.h | 3 + launcher/ui/dialogs/CopyInstanceDialog.cpp | 8 ++ launcher/ui/dialogs/CopyInstanceDialog.h | 1 + launcher/ui/dialogs/CopyInstanceDialog.ui | 85 ++++++++++++++-------- 5 files changed, 81 insertions(+), 32 deletions(-) diff --git a/launcher/InstanceCopyPrefs.cpp b/launcher/InstanceCopyPrefs.cpp index ae30bb82..7b93a516 100644 --- a/launcher/InstanceCopyPrefs.cpp +++ b/launcher/InstanceCopyPrefs.cpp @@ -12,7 +12,8 @@ bool InstanceCopyPrefs::allTrue() const copyResourcePacks && copyShaderPacks && copyServers && - copyMods; + copyMods && + copyScreenshots; } // Returns a single RegEx string of the selected folders/files to filter out (ex: ".minecraft/saves|.minecraft/server.dat") @@ -38,6 +39,9 @@ QString InstanceCopyPrefs::getSelectedFiltersAsRegex() const if(!copyMods) filters << "coremods" << "mods" << "config"; + if(!copyScreenshots) + filters << "screenshots"; + // If we have any filters to add, join them as a single regex string to return: if (!filters.isEmpty()) { const QString MC_ROOT = "[.]?minecraft/"; @@ -84,6 +88,11 @@ bool InstanceCopyPrefs::isCopyModsEnabled() const return copyMods; } +bool InstanceCopyPrefs::isCopyScreenshotsEnabled() const +{ + return copyScreenshots; +} + // ======= Setters ======= void InstanceCopyPrefs::enableCopySaves(bool b) { @@ -119,3 +128,8 @@ void InstanceCopyPrefs::enableCopyMods(bool b) { copyMods = b; } + +void InstanceCopyPrefs::enableCopyScreenshots(bool b) +{ + copyScreenshots = b; +} diff --git a/launcher/InstanceCopyPrefs.h b/launcher/InstanceCopyPrefs.h index 3855965d..6988b2df 100644 --- a/launcher/InstanceCopyPrefs.h +++ b/launcher/InstanceCopyPrefs.h @@ -18,6 +18,7 @@ struct InstanceCopyPrefs { [[nodiscard]] bool isCopyShaderPacksEnabled() const; [[nodiscard]] bool isCopyServersEnabled() const; [[nodiscard]] bool isCopyModsEnabled() const; + [[nodiscard]] bool isCopyScreenshotsEnabled() const; // Setters void enableCopySaves(bool b); void enableKeepPlaytime(bool b); @@ -26,6 +27,7 @@ struct InstanceCopyPrefs { void enableCopyShaderPacks(bool b); void enableCopyServers(bool b); void enableCopyMods(bool b); + void enableCopyScreenshots(bool b); protected: // data bool copySaves = true; @@ -35,4 +37,5 @@ struct InstanceCopyPrefs { bool copyShaderPacks = true; bool copyServers = true; bool copyMods = true; + bool copyScreenshots = true; }; diff --git a/launcher/ui/dialogs/CopyInstanceDialog.cpp b/launcher/ui/dialogs/CopyInstanceDialog.cpp index f76b509e..3f5122f6 100644 --- a/launcher/ui/dialogs/CopyInstanceDialog.cpp +++ b/launcher/ui/dialogs/CopyInstanceDialog.cpp @@ -84,6 +84,7 @@ CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget *parent) ui->copyShaderPacksCheckbox->setChecked(m_selectedOptions.isCopyShaderPacksEnabled()); ui->copyServersCheckbox->setChecked(m_selectedOptions.isCopyServersEnabled()); ui->copyModsCheckbox->setChecked(m_selectedOptions.isCopyModsEnabled()); + ui->copyScreenshotsCheckbox->setChecked(m_selectedOptions.isCopyScreenshotsEnabled()); } CopyInstanceDialog::~CopyInstanceDialog() @@ -135,6 +136,7 @@ void CopyInstanceDialog::checkAllCheckboxes(const bool& b) ui->copyShaderPacksCheckbox->setChecked(b); ui->copyServersCheckbox->setChecked(b); ui->copyModsCheckbox->setChecked(b); + ui->copyScreenshotsCheckbox->setChecked(b); } // Check the "Select all" checkbox if all options are already selected: @@ -212,3 +214,9 @@ void CopyInstanceDialog::on_copyModsCheckbox_stateChanged(int state) m_selectedOptions.enableCopyMods(state == Qt::Checked); updateSelectAllCheckbox(); } + +void CopyInstanceDialog::on_copyScreenshotsCheckbox_stateChanged(int state) +{ + m_selectedOptions.enableCopyScreenshots(state == Qt::Checked); + updateSelectAllCheckbox(); +} diff --git a/launcher/ui/dialogs/CopyInstanceDialog.h b/launcher/ui/dialogs/CopyInstanceDialog.h index 94015334..884501d1 100644 --- a/launcher/ui/dialogs/CopyInstanceDialog.h +++ b/launcher/ui/dialogs/CopyInstanceDialog.h @@ -54,6 +54,7 @@ slots: void on_copyShaderPacksCheckbox_stateChanged(int state); void on_copyServersCheckbox_stateChanged(int state); void on_copyModsCheckbox_stateChanged(int state); + void on_copyScreenshotsCheckbox_stateChanged(int state); private: void checkAllCheckboxes(const bool& b); diff --git a/launcher/ui/dialogs/CopyInstanceDialog.ui b/launcher/ui/dialogs/CopyInstanceDialog.ui index 822ed797..b7828fe3 100644 --- a/launcher/ui/dialogs/CopyInstanceDialog.ui +++ b/launcher/ui/dialogs/CopyInstanceDialog.ui @@ -10,7 +10,7 @@ 0 0 341 - 385 + 399 @@ -112,25 +112,31 @@ + + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + Select all + + + false + + + + + - - - - Copy saves - - - - - - - true - - - Copy resource packs - - - @@ -151,17 +157,10 @@ - - + + - Copy servers - - - - - - - Keep play time + Copy saves @@ -172,10 +171,34 @@ - - + + - Select all + Copy servers + + + + + + + true + + + Copy resource packs + + + + + + + Keep play time + + + + + + + Copy screenshots