feat: add dialog to ask whether to chaneg instance's name
This prevents custom names from being lost when updating, by only changing the name if the old instance name constains the old version, so that we can update it if the user whishes to. Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
ddde885084
commit
06019f01e3
@ -908,11 +908,6 @@ bool InstanceList::commitStagedInstance(QString path, InstanceName const& instan
|
|||||||
qWarning() << "Failed to override" << path << "to" << destination;
|
qWarning() << "Failed to override" << path << "to" << destination;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inst)
|
|
||||||
inst = getInstanceById(instID);
|
|
||||||
if (inst)
|
|
||||||
inst->setName(instanceName.name());
|
|
||||||
} else {
|
} else {
|
||||||
if (!dir.rename(path, destination)) {
|
if (!dir.rename(path, destination)) {
|
||||||
qWarning() << "Failed to move" << path << "to" << destination;
|
qWarning() << "Failed to move" << path << "to" << destination;
|
||||||
|
@ -1,5 +1,23 @@
|
|||||||
#include "InstanceTask.h"
|
#include "InstanceTask.h"
|
||||||
|
|
||||||
|
#include "ui/dialogs/CustomMessageBox.h"
|
||||||
|
|
||||||
|
InstanceNameChange askForChangingInstanceName(QWidget* parent, QString old_name, QString new_name)
|
||||||
|
{
|
||||||
|
auto dialog =
|
||||||
|
CustomMessageBox::selectable(parent, QObject::tr("Change instance name"),
|
||||||
|
QObject::tr("The instance's name seems to include the old version. Would you like to update it?\n\n"
|
||||||
|
"Old name: %1\n"
|
||||||
|
"New name: %2")
|
||||||
|
.arg(old_name, new_name),
|
||||||
|
QMessageBox::Question, QMessageBox::No | QMessageBox::Yes);
|
||||||
|
auto result = dialog->exec();
|
||||||
|
|
||||||
|
if (result == QMessageBox::Yes)
|
||||||
|
return InstanceNameChange::ShouldChange;
|
||||||
|
return InstanceNameChange::ShouldKeep;
|
||||||
|
}
|
||||||
|
|
||||||
QString InstanceName::name() const
|
QString InstanceName::name() const
|
||||||
{
|
{
|
||||||
if (!m_modified_name.isEmpty())
|
if (!m_modified_name.isEmpty())
|
||||||
@ -26,9 +44,9 @@ QString InstanceName::version() const
|
|||||||
|
|
||||||
void InstanceName::setName(InstanceName& other)
|
void InstanceName::setName(InstanceName& other)
|
||||||
{
|
{
|
||||||
m_original_name = other.m_original_name;
|
m_original_name = other.m_original_name;
|
||||||
m_original_version = other.m_original_version;
|
m_original_version = other.m_original_version;
|
||||||
m_modified_name = other.m_modified_name;
|
m_modified_name = other.m_modified_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
InstanceTask::InstanceTask() : Task(), InstanceName() {}
|
InstanceTask::InstanceTask() : Task(), InstanceName() {}
|
||||||
|
@ -3,6 +3,10 @@
|
|||||||
#include "settings/SettingsObject.h"
|
#include "settings/SettingsObject.h"
|
||||||
#include "tasks/Task.h"
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
|
/* Helpers */
|
||||||
|
enum class InstanceNameChange { ShouldChange, ShouldKeep };
|
||||||
|
[[nodiscard]] InstanceNameChange askForChangingInstanceName(QWidget* parent, QString old_name, QString new_name);
|
||||||
|
|
||||||
struct InstanceName {
|
struct InstanceName {
|
||||||
public:
|
public:
|
||||||
InstanceName() = default;
|
InstanceName() = default;
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
|
|
||||||
#include "settings/INISettingsObject.h"
|
#include "settings/INISettingsObject.h"
|
||||||
|
|
||||||
#include "ui/dialogs/CustomMessageBox.h"
|
|
||||||
#include "ui/dialogs/BlockedModsDialog.h"
|
#include "ui/dialogs/BlockedModsDialog.h"
|
||||||
|
#include "ui/dialogs/CustomMessageBox.h"
|
||||||
|
|
||||||
const static QMap<QString, QString> forgemap = { { "1.2.5", "3.4.9.171" },
|
const static QMap<QString, QString> forgemap = { { "1.2.5", "3.4.9.171" },
|
||||||
{ "1.4.2", "6.0.1.355" },
|
{ "1.4.2", "6.0.1.355" },
|
||||||
@ -348,12 +348,20 @@ bool FlameCreationTask::createInstance()
|
|||||||
|
|
||||||
bool did_succeed = getError().isEmpty();
|
bool did_succeed = getError().isEmpty();
|
||||||
|
|
||||||
|
// Update information of the already installed instance, if any.
|
||||||
if (m_instance && did_succeed) {
|
if (m_instance && did_succeed) {
|
||||||
setAbortable(false);
|
setAbortable(false);
|
||||||
auto inst = m_instance.value();
|
auto inst = m_instance.value();
|
||||||
|
|
||||||
|
// Only change the name if it didn't use a custom name, so that the previous custom name
|
||||||
|
// is preserved, but if we're using the original one, we update the version string.
|
||||||
|
// NOTE: This needs to come before the copyManagedPack call!
|
||||||
|
if (inst->name().contains(inst->getManagedPackVersionName())) {
|
||||||
|
if (askForChangingInstanceName(m_parent, inst->name(), instance.name()) == InstanceNameChange::ShouldChange)
|
||||||
|
inst->setName(instance.name());
|
||||||
|
}
|
||||||
|
|
||||||
inst->copyManagedPack(instance);
|
inst->copyManagedPack(instance);
|
||||||
inst->setName(instance.name());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return did_succeed;
|
return did_succeed;
|
||||||
|
@ -262,12 +262,20 @@ bool ModrinthCreationTask::createInstance()
|
|||||||
|
|
||||||
loop.exec();
|
loop.exec();
|
||||||
|
|
||||||
|
// Update information of the already installed instance, if any.
|
||||||
if (m_instance && ended_well) {
|
if (m_instance && ended_well) {
|
||||||
setAbortable(false);
|
setAbortable(false);
|
||||||
auto inst = m_instance.value();
|
auto inst = m_instance.value();
|
||||||
|
|
||||||
|
// Only change the name if it didn't use a custom name, so that the previous custom name
|
||||||
|
// is preserved, but if we're using the original one, we update the version string.
|
||||||
|
// NOTE: This needs to come before the copyManagedPack call!
|
||||||
|
if (inst->name().contains(inst->getManagedPackVersionName())) {
|
||||||
|
if (askForChangingInstanceName(m_parent, inst->name(), instance.name()) == InstanceNameChange::ShouldChange)
|
||||||
|
inst->setName(instance.name());
|
||||||
|
}
|
||||||
|
|
||||||
inst->copyManagedPack(instance);
|
inst->copyManagedPack(instance);
|
||||||
inst->setName(instance.name());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ended_well;
|
return ended_well;
|
||||||
|
Loading…
Reference in New Issue
Block a user