feat(ui): improve info dialog before updating an instance
Adds a 'Cancel' option, and add a note about doing a backup before updating. Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
68facd6b93
commit
eda6cf11ef
@ -11,6 +11,12 @@ void InstanceCreationTask::executeTask()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When the user aborted in the update stage.
|
||||||
|
if (m_abort) {
|
||||||
|
emitAborted();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If this is set, it means we're updating an instance. Since the previous step likely
|
// If this is set, it means we're updating an instance. Since the previous step likely
|
||||||
// removed some old files, we'd better not let the user abort the next task, since it'd
|
// removed some old files, we'd better not let the user abort the next task, since it'd
|
||||||
// put the instance in an invalid state.
|
// put the instance in an invalid state.
|
||||||
|
@ -36,6 +36,9 @@ class InstanceCreationTask : public InstanceTask {
|
|||||||
protected:
|
protected:
|
||||||
void setError(QString message) { m_error_message = message; };
|
void setError(QString message) { m_error_message = message; };
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool m_abort = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_error_message;
|
QString m_error_message;
|
||||||
};
|
};
|
||||||
|
@ -279,6 +279,7 @@ void InstanceImportTask::processFlame()
|
|||||||
connect(inst_creation_task, &Task::finished, inst_creation_task, &InstanceCreationTask::deleteLater);
|
connect(inst_creation_task, &Task::finished, inst_creation_task, &InstanceCreationTask::deleteLater);
|
||||||
|
|
||||||
connect(this, &Task::aborted, inst_creation_task, &InstanceCreationTask::abort);
|
connect(this, &Task::aborted, inst_creation_task, &InstanceCreationTask::abort);
|
||||||
|
connect(inst_creation_task, &Task::aborted, this, &Task::abort);
|
||||||
connect(inst_creation_task, &Task::abortStatusChanged, this, &Task::setAbortStatus);
|
connect(inst_creation_task, &Task::abortStatusChanged, this, &Task::setAbortStatus);
|
||||||
|
|
||||||
inst_creation_task->start();
|
inst_creation_task->start();
|
||||||
@ -342,6 +343,7 @@ void InstanceImportTask::processModrinth()
|
|||||||
connect(inst_creation_task, &Task::finished, inst_creation_task, &InstanceCreationTask::deleteLater);
|
connect(inst_creation_task, &Task::finished, inst_creation_task, &InstanceCreationTask::deleteLater);
|
||||||
|
|
||||||
connect(this, &Task::aborted, inst_creation_task, &InstanceCreationTask::abort);
|
connect(this, &Task::aborted, inst_creation_task, &InstanceCreationTask::abort);
|
||||||
|
connect(inst_creation_task, &Task::aborted, this, &Task::abort);
|
||||||
connect(inst_creation_task, &Task::abortStatusChanged, this, &Task::setAbortStatus);
|
connect(inst_creation_task, &Task::abortStatusChanged, this, &Task::setAbortStatus);
|
||||||
|
|
||||||
inst_creation_task->start();
|
inst_creation_task->start();
|
||||||
|
@ -66,17 +66,26 @@ bool FlameCreationTask::updateInstance()
|
|||||||
auto version_id = inst->getManagedPackVersionName();
|
auto version_id = inst->getManagedPackVersionName();
|
||||||
auto version_str = !version_id.isEmpty() ? tr(" (version %1)").arg(version_id) : "";
|
auto version_str = !version_id.isEmpty() ? tr(" (version %1)").arg(version_id) : "";
|
||||||
|
|
||||||
auto info = CustomMessageBox::selectable(m_parent, tr("Similar modpack was found!"),
|
auto info = CustomMessageBox::selectable(
|
||||||
tr("One or more of your instances are from this same modpack%1. Do you want to create a "
|
m_parent, tr("Similar modpack was found!"),
|
||||||
"separate instance, or update the existing one?")
|
tr("One or more of your instances are from this same modpack%1. Do you want to create a "
|
||||||
.arg(version_str),
|
"separate instance, or update the existing one?\n\nNOTE: Make sure you made a backup of your important instance data before "
|
||||||
QMessageBox::Information, QMessageBox::Ok | QMessageBox::Abort);
|
"updating, as worlds can be corrupted and some configuration may be lost (due to pack overrides).")
|
||||||
|
.arg(version_str), QMessageBox::Information, QMessageBox::Ok | QMessageBox::Reset | QMessageBox::Abort);
|
||||||
info->setButtonText(QMessageBox::Ok, tr("Update existing instance"));
|
info->setButtonText(QMessageBox::Ok, tr("Update existing instance"));
|
||||||
info->setButtonText(QMessageBox::Abort, tr("Create new instance"));
|
info->setButtonText(QMessageBox::Abort, tr("Create new instance"));
|
||||||
|
info->setButtonText(QMessageBox::Reset, tr("Cancel"));
|
||||||
|
|
||||||
if (info->exec() && info->clickedButton() == info->button(QMessageBox::Abort))
|
info->exec();
|
||||||
|
|
||||||
|
if (info->clickedButton() == info->button(QMessageBox::Abort))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (info->clickedButton() == info->button(QMessageBox::Reset)) {
|
||||||
|
m_abort = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QDir old_inst_dir(inst->instanceRoot());
|
QDir old_inst_dir(inst->instanceRoot());
|
||||||
|
|
||||||
QString old_index_folder(FS::PathCombine(old_inst_dir.absolutePath(), "flame"));
|
QString old_index_folder(FS::PathCombine(old_inst_dir.absolutePath(), "flame"));
|
||||||
|
@ -42,23 +42,33 @@ bool ModrinthCreationTask::updateInstance()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString index_path = FS::PathCombine(m_stagingPath, "modrinth.index.json");
|
QString index_path = FS::PathCombine(m_stagingPath, "modrinth.index.json");
|
||||||
if (!parseManifest(index_path, m_files))
|
if (!parseManifest(index_path, m_files, true, false))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto version_name = inst->getManagedPackVersionName();
|
auto version_name = inst->getManagedPackVersionName();
|
||||||
auto version_str = !version_name.isEmpty() ? tr(" (version %1)").arg(version_name) : "";
|
auto version_str = !version_name.isEmpty() ? tr(" (version %1)").arg(version_name) : "";
|
||||||
|
|
||||||
auto info = CustomMessageBox::selectable(m_parent, tr("Similar modpack was found!"),
|
auto info = CustomMessageBox::selectable(
|
||||||
tr("One or more of your instances are from this same modpack%1. Do you want to create a "
|
m_parent, tr("Similar modpack was found!"),
|
||||||
"separate instance, or update the existing one?")
|
tr("One or more of your instances are from this same modpack%1. Do you want to create a "
|
||||||
.arg(version_str),
|
"separate instance, or update the existing one?\n\nNOTE: Make sure you made a backup of your important instance data before "
|
||||||
QMessageBox::Information, QMessageBox::Ok | QMessageBox::Abort);
|
"updating, as worlds can be corrupted and some configuration may be lost (due to pack overrides).")
|
||||||
info->setButtonText(QMessageBox::Ok, tr("Update existing instance"));
|
.arg(version_str),
|
||||||
info->setButtonText(QMessageBox::Abort, tr("Create new instance"));
|
QMessageBox::Information, QMessageBox::Ok | QMessageBox::Reset | QMessageBox::Abort);
|
||||||
|
info->setButtonText(QMessageBox::Ok, tr("Create new instance"));
|
||||||
|
info->setButtonText(QMessageBox::Abort, tr("Update existing instance"));
|
||||||
|
info->setButtonText(QMessageBox::Reset, tr("Cancel"));
|
||||||
|
|
||||||
if (info->exec() && info->clickedButton() == info->button(QMessageBox::Abort))
|
info->exec();
|
||||||
|
|
||||||
|
if (info->clickedButton() == info->button(QMessageBox::Ok))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (info->clickedButton() == info->button(QMessageBox::Reset)) {
|
||||||
|
m_abort = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Remove repeated files, we don't need to download them!
|
// Remove repeated files, we don't need to download them!
|
||||||
QDir old_inst_dir(inst->instanceRoot());
|
QDir old_inst_dir(inst->instanceRoot());
|
||||||
|
|
||||||
@ -68,7 +78,7 @@ bool ModrinthCreationTask::updateInstance()
|
|||||||
QFileInfo old_index_file(old_index_path);
|
QFileInfo old_index_file(old_index_path);
|
||||||
if (old_index_file.exists()) {
|
if (old_index_file.exists()) {
|
||||||
std::vector<Modrinth::File> old_files;
|
std::vector<Modrinth::File> old_files;
|
||||||
parseManifest(old_index_path, old_files, false);
|
parseManifest(old_index_path, old_files, false, false);
|
||||||
|
|
||||||
// Let's remove all duplicated, identical resources!
|
// Let's remove all duplicated, identical resources!
|
||||||
auto files_iterator = m_files.begin();
|
auto files_iterator = m_files.begin();
|
||||||
@ -137,7 +147,7 @@ bool ModrinthCreationTask::createInstance()
|
|||||||
QString parent_folder(FS::PathCombine(m_stagingPath, "mrpack"));
|
QString parent_folder(FS::PathCombine(m_stagingPath, "mrpack"));
|
||||||
|
|
||||||
QString index_path = FS::PathCombine(m_stagingPath, "modrinth.index.json");
|
QString index_path = FS::PathCombine(m_stagingPath, "modrinth.index.json");
|
||||||
if (m_files.empty() && !parseManifest(index_path, m_files))
|
if (m_files.empty() && !parseManifest(index_path, m_files, true, true))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Keep index file in case we need it some other time (like when changing versions)
|
// Keep index file in case we need it some other time (like when changing versions)
|
||||||
@ -243,7 +253,7 @@ bool ModrinthCreationTask::createInstance()
|
|||||||
return ended_well;
|
return ended_well;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModrinthCreationTask::parseManifest(QString index_path, std::vector<Modrinth::File>& files, bool set_managed_info)
|
bool ModrinthCreationTask::parseManifest(QString index_path, std::vector<Modrinth::File>& files, bool set_managed_info, bool show_optional_dialog)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
auto doc = Json::requireDocument(index_path);
|
auto doc = Json::requireDocument(index_path);
|
||||||
@ -274,7 +284,7 @@ bool ModrinthCreationTask::parseManifest(QString index_path, std::vector<Modrint
|
|||||||
continue;
|
continue;
|
||||||
} else if (support == "optional") {
|
} else if (support == "optional") {
|
||||||
// TODO: Make a review dialog for choosing which ones the user wants!
|
// TODO: Make a review dialog for choosing which ones the user wants!
|
||||||
if (!had_optional) {
|
if (!had_optional && show_optional_dialog) {
|
||||||
had_optional = true;
|
had_optional = true;
|
||||||
auto info = CustomMessageBox::selectable(
|
auto info = CustomMessageBox::selectable(
|
||||||
m_parent, tr("Optional mod detected!"),
|
m_parent, tr("Optional mod detected!"),
|
||||||
|
@ -27,7 +27,7 @@ class ModrinthCreationTask final : public InstanceCreationTask {
|
|||||||
bool createInstance() override;
|
bool createInstance() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool parseManifest(QString, std::vector<Modrinth::File>&, bool set_managed_info = true);
|
bool parseManifest(QString, std::vector<Modrinth::File>&, bool set_managed_info = true, bool show_optional_dialog = true);
|
||||||
QString getManagedPackID() const;
|
QString getManagedPackID() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user