Merge pull request #242 from marcelohdez/more-copy-options

This commit is contained in:
Sefa Eyeoglu 2022-11-06 01:10:24 +01:00 committed by GitHub
commit 9fb80a2687
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 386 additions and 64 deletions

View File

@ -31,6 +31,8 @@ set(CORE_SOURCES
# Basic instance manipulation tasks (derived from InstanceTask) # Basic instance manipulation tasks (derived from InstanceTask)
InstanceCreationTask.h InstanceCreationTask.h
InstanceCreationTask.cpp InstanceCreationTask.cpp
InstanceCopyPrefs.h
InstanceCopyPrefs.cpp
InstanceCopyTask.h InstanceCopyTask.h
InstanceCopyTask.cpp InstanceCopyTask.cpp
InstanceImportTask.h InstanceImportTask.h

View File

@ -0,0 +1,135 @@
//
// Created by marcelohdez on 10/22/22.
//
#include "InstanceCopyPrefs.h"
bool InstanceCopyPrefs::allTrue() const
{
return copySaves &&
keepPlaytime &&
copyGameOptions &&
copyResourcePacks &&
copyShaderPacks &&
copyServers &&
copyMods &&
copyScreenshots;
}
// 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(!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/";
// 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 {};
}
// ======= 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;
}
bool InstanceCopyPrefs::isCopyScreenshotsEnabled() const
{
return copyScreenshots;
}
// ======= 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;
}
void InstanceCopyPrefs::enableCopyScreenshots(bool b)
{
copyScreenshots = b;
}

View File

@ -0,0 +1,41 @@
//
// Created by marcelohdez on 10/22/22.
//
#pragma once
#include <QStringList>
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;
[[nodiscard]] bool isCopyScreenshotsEnabled() 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);
void enableCopyScreenshots(bool b);
protected: // data
bool copySaves = true;
bool keepPlaytime = true;
bool copyGameOptions = true;
bool copyResourcePacks = true;
bool copyShaderPacks = true;
bool copyServers = true;
bool copyMods = true;
bool copyScreenshots = true;
};

View File

@ -5,15 +5,17 @@
#include "pathmatcher/RegexpMatcher.h" #include "pathmatcher/RegexpMatcher.h"
#include <QtConcurrentRun> #include <QtConcurrentRun>
InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, bool copySaves, bool keepPlaytime) InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, const InstanceCopyPrefs& prefs)
{ {
m_origInstance = origInstance; m_origInstance = origInstance;
m_keepPlaytime = keepPlaytime; m_keepPlaytime = prefs.isKeepPlaytimeEnabled();
if(!copySaves) QString filters = prefs.getSelectedFiltersAsRegex();
if (!filters.isEmpty())
{ {
// Set regex filter:
// FIXME: get this from the original instance type... // FIXME: get this from the original instance type...
auto matcherReal = new RegexpMatcher("[.]?minecraft/saves"); auto matcherReal = new RegexpMatcher(filters);
matcherReal->caseSensitive(false); matcherReal->caseSensitive(false);
m_matcher.reset(matcherReal); m_matcher.reset(matcherReal);
} }

View File

@ -1,20 +1,21 @@
#pragma once #pragma once
#include "tasks/Task.h"
#include "net/NetJob.h"
#include <QUrl>
#include <QFuture> #include <QFuture>
#include <QFutureWatcher> #include <QFutureWatcher>
#include "settings/SettingsObject.h" #include <QUrl>
#include "BaseVersion.h"
#include "BaseInstance.h" #include "BaseInstance.h"
#include "BaseVersion.h"
#include "InstanceCopyPrefs.h"
#include "InstanceTask.h" #include "InstanceTask.h"
#include "net/NetJob.h"
#include "settings/SettingsObject.h"
#include "tasks/Task.h"
class InstanceCopyTask : public InstanceTask class InstanceCopyTask : public InstanceTask
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit InstanceCopyTask(InstancePtr origInstance, bool copySaves, bool keepPlaytime); explicit InstanceCopyTask(InstancePtr origInstance, const InstanceCopyPrefs& prefs);
protected: protected:
//! Entry point for tasks. //! Entry point for tasks.
@ -22,7 +23,8 @@ protected:
void copyFinished(); void copyFinished();
void copyAborted(); void copyAborted();
private: /* data */ private:
/* data */
InstancePtr m_origInstance; InstancePtr m_origInstance;
QFuture<bool> m_copyFuture; QFuture<bool> m_copyFuture;
QFutureWatcher<bool> m_copyFutureWatcher; QFutureWatcher<bool> m_copyFutureWatcher;

View File

@ -1651,7 +1651,7 @@ void MainWindow::on_actionCopyInstance_triggered()
if (!copyInstDlg.exec()) if (!copyInstDlg.exec())
return; return;
auto copyTask = new InstanceCopyTask(m_selectedInstance, copyInstDlg.shouldCopySaves(), copyInstDlg.shouldKeepPlaytime()); auto copyTask = new InstanceCopyTask(m_selectedInstance, copyInstDlg.getChosenOptions());
copyTask->setName(copyInstDlg.instName()); copyTask->setName(copyInstDlg.instName());
copyTask->setGroup(copyInstDlg.instGroup()); copyTask->setGroup(copyInstDlg.instGroup());
copyTask->setIcon(copyInstDlg.iconKey()); copyTask->setIcon(copyInstDlg.iconKey());

View File

@ -44,7 +44,6 @@
#include "BaseVersion.h" #include "BaseVersion.h"
#include "icons/IconList.h" #include "icons/IconList.h"
#include "tasks/Task.h"
#include "BaseInstance.h" #include "BaseInstance.h"
#include "InstanceList.h" #include "InstanceList.h"
@ -78,8 +77,14 @@ CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget *parent)
} }
ui->groupBox->setCurrentIndex(index); ui->groupBox->setCurrentIndex(index);
ui->groupBox->lineEdit()->setPlaceholderText(tr("No group")); ui->groupBox->lineEdit()->setPlaceholderText(tr("No group"));
ui->copySavesCheckbox->setChecked(m_copySaves); ui->copySavesCheckbox->setChecked(m_selectedOptions.isCopySavesEnabled());
ui->keepPlaytimeCheckbox->setChecked(m_keepPlaytime); 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());
ui->copyScreenshotsCheckbox->setChecked(m_selectedOptions.isCopyScreenshotsEnabled());
} }
CopyInstanceDialog::~CopyInstanceDialog() CopyInstanceDialog::~CopyInstanceDialog()
@ -117,6 +122,31 @@ QString CopyInstanceDialog::instGroup() const
return ui->groupBox->currentText(); 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);
ui->copyScreenshotsCheckbox->setChecked(b);
}
// Check the "Select all" checkbox if all options are already selected:
void CopyInstanceDialog::updateSelectAllCheckbox()
{
ui->selectAllCheckbox->blockSignals(true);
ui->selectAllCheckbox->setChecked(m_selectedOptions.allTrue());
ui->selectAllCheckbox->blockSignals(false);
}
void CopyInstanceDialog::on_iconButton_clicked() void CopyInstanceDialog::on_iconButton_clicked()
{ {
IconPickerDialog dlg(this); IconPickerDialog dlg(this);
@ -129,42 +159,64 @@ void CopyInstanceDialog::on_iconButton_clicked()
} }
} }
void CopyInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1) void CopyInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1)
{ {
updateDialogState(); updateDialogState();
} }
bool CopyInstanceDialog::shouldCopySaves() const void CopyInstanceDialog::on_selectAllCheckbox_stateChanged(int state)
{ {
return m_copySaves; bool checked;
checked = (state == Qt::Checked);
checkAllCheckboxes(checked);
} }
void CopyInstanceDialog::on_copySavesCheckbox_stateChanged(int state) void CopyInstanceDialog::on_copySavesCheckbox_stateChanged(int state)
{ {
if(state == Qt::Unchecked) m_selectedOptions.enableCopySaves(state == Qt::Checked);
{ updateSelectAllCheckbox();
m_copySaves = false;
}
else if(state == Qt::Checked)
{
m_copySaves = true;
}
}
bool CopyInstanceDialog::shouldKeepPlaytime() const
{
return m_keepPlaytime;
} }
void CopyInstanceDialog::on_keepPlaytimeCheckbox_stateChanged(int state) void CopyInstanceDialog::on_keepPlaytimeCheckbox_stateChanged(int state)
{ {
if(state == Qt::Unchecked) m_selectedOptions.enableKeepPlaytime(state == Qt::Checked);
updateSelectAllCheckbox();
}
void CopyInstanceDialog::on_copyGameOptionsCheckbox_stateChanged(int state)
{ {
m_keepPlaytime = false; m_selectedOptions.enableCopyGameOptions(state == Qt::Checked);
updateSelectAllCheckbox();
} }
else if(state == Qt::Checked)
void CopyInstanceDialog::on_copyResPacksCheckbox_stateChanged(int state)
{ {
m_keepPlaytime = true; m_selectedOptions.enableCopyResourcePacks(state == Qt::Checked);
updateSelectAllCheckbox();
} }
void CopyInstanceDialog::on_copyShaderPacksCheckbox_stateChanged(int state)
{
m_selectedOptions.enableCopyShaderPacks(state == Qt::Checked);
updateSelectAllCheckbox();
}
void CopyInstanceDialog::on_copyServersCheckbox_stateChanged(int state)
{
m_selectedOptions.enableCopyServers(state == Qt::Checked);
updateSelectAllCheckbox();
}
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();
} }

View File

@ -17,7 +17,7 @@
#include <QDialog> #include <QDialog>
#include "BaseVersion.h" #include "BaseVersion.h"
#include <BaseInstance.h> #include "InstanceCopyPrefs.h"
class BaseInstance; class BaseInstance;
@ -39,20 +39,29 @@ public:
QString instName() const; QString instName() const;
QString instGroup() const; QString instGroup() const;
QString iconKey() const; QString iconKey() const;
bool shouldCopySaves() const; const InstanceCopyPrefs& getChosenOptions() const;
bool shouldKeepPlaytime() const;
private private
slots: slots:
void on_iconButton_clicked(); void on_iconButton_clicked();
void on_instNameTextBox_textChanged(const QString &arg1); void on_instNameTextBox_textChanged(const QString &arg1);
// Checkboxes
void on_selectAllCheckbox_stateChanged(int state);
void on_copySavesCheckbox_stateChanged(int state); void on_copySavesCheckbox_stateChanged(int state);
void on_keepPlaytimeCheckbox_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);
void on_copyScreenshotsCheckbox_stateChanged(int state);
private: private:
void checkAllCheckboxes(const bool& b);
void updateSelectAllCheckbox();
/* data */
Ui::CopyInstanceDialog *ui; Ui::CopyInstanceDialog *ui;
QString InstIconKey; QString InstIconKey;
InstancePtr m_original; InstancePtr m_original;
bool m_copySaves = true; InstanceCopyPrefs m_selectedOptions;
bool m_keepPlaytime = true;
}; };

View File

@ -9,8 +9,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>345</width> <width>341</width>
<height>323</height> <height>399</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -33,7 +33,7 @@
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>60</width>
<height>20</height> <height>20</height>
</size> </size>
</property> </property>
@ -60,7 +60,7 @@
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>60</width>
<height>20</height> <height>20</height>
</size> </size>
</property> </property>
@ -83,7 +83,10 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="groupDropdownLayout">
<property name="verticalSpacing">
<number>6</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="labelVersion_3"> <widget class="QLabel" name="labelVersion_3">
<property name="text"> <property name="text">
@ -110,19 +113,97 @@
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="selectAllButtonLayout">
<item>
<widget class="QCheckBox" name="selectAllCheckbox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Select all</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" name="copyOptionsLayout">
<item row="6" column="1">
<widget class="QCheckBox" name="copyModsCheckbox">
<property name="toolTip">
<string>Disabling this will still keep the mod loader (ex: Fabric, Quilt, etc.) but erase the mods folder and their configs.</string>
</property>
<property name="text">
<string>Copy mods</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="copyGameOptionsCheckbox">
<property name="toolTip">
<string>Copy the in-game options like FOV, max framerate, etc.</string>
</property>
<property name="text">
<string>Copy game options</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="copySavesCheckbox"> <widget class="QCheckBox" name="copySavesCheckbox">
<property name="text"> <property name="text">
<string>Copy saves</string> <string>Copy saves</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="3" column="1">
<widget class="QCheckBox" name="copyShaderPacksCheckbox">
<property name="text">
<string>Copy shader packs</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QCheckBox" name="copyServersCheckbox">
<property name="text">
<string>Copy servers</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="copyResPacksCheckbox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Copy resource packs</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="keepPlaytimeCheckbox"> <widget class="QCheckBox" name="keepPlaytimeCheckbox">
<property name="text"> <property name="text">
<string>Keep play time</string> <string>Keep play time</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1">
<widget class="QCheckBox" name="copyScreenshotsCheckbox">
<property name="text">
<string>Copy screenshots</string>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation"> <property name="orientation">
@ -139,8 +220,6 @@
<tabstop>iconButton</tabstop> <tabstop>iconButton</tabstop>
<tabstop>instNameTextBox</tabstop> <tabstop>instNameTextBox</tabstop>
<tabstop>groupBox</tabstop> <tabstop>groupBox</tabstop>
<tabstop>copySavesCheckbox</tabstop>
<tabstop>keepPlaytimeCheckbox</tabstop>
</tabstops> </tabstops>
<resources> <resources>
<include location="../../graphics.qrc"/> <include location="../../graphics.qrc"/>
@ -153,8 +232,8 @@
<slot>accept()</slot> <slot>accept()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>248</x> <x>254</x>
<y>254</y> <y>316</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>157</x> <x>157</x>
@ -169,8 +248,8 @@
<slot>reject()</slot> <slot>reject()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>316</x> <x>322</x>
<y>260</y> <y>316</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>286</x> <x>286</x>