ATLauncher: Add modes to install task and display appropriate message

This will display the update/reinstall message for the installation
method currently in use..
This commit is contained in:
Jamie Mansfield 2022-05-23 17:22:21 +01:00
parent 3b187b5246
commit e0ae631d59
No known key found for this signature in database
GPG Key ID: 36F61598F39F67B0
2 changed files with 31 additions and 5 deletions

View File

@ -60,12 +60,13 @@ namespace ATLauncher {
static Meta::VersionPtr getComponentVersion(const QString& uid, const QString& version);
PackInstallTask::PackInstallTask(UserInteractionSupport *support, QString packName, QString version)
PackInstallTask::PackInstallTask(UserInteractionSupport *support, QString packName, QString version, InstallMode installMode)
{
m_support = support;
m_pack_name = packName;
m_pack_safe_name = packName.replace(QRegularExpression("[^A-Za-z0-9]"), "");
m_version_name = version;
m_install_mode = installMode;
}
bool PackInstallTask::abort()
@ -117,9 +118,27 @@ void PackInstallTask::onDownloadSucceeded()
}
m_version = version;
// Display install message if one exists
if (!m_version.messages.install.isEmpty())
m_support->displayMessage(m_version.messages.install);
// Derived from the installation mode
QString message;
switch (m_install_mode) {
case InstallMode::Reinstall:
case InstallMode::Update:
message = m_version.messages.update;
break;
case InstallMode::Install:
message = m_version.messages.install;
break;
default:
emitFailed(tr("Unsupported installation mode"));
break;
}
// Display message if one exists
if (!message.isEmpty())
m_support->displayMessage(message);
auto ver = getComponentVersion("net.minecraft", m_version.minecraft);
if (!ver) {

View File

@ -50,6 +50,12 @@
namespace ATLauncher {
enum class InstallMode {
Install,
Reinstall,
Update,
};
class UserInteractionSupport {
public:
@ -75,7 +81,7 @@ class PackInstallTask : public InstanceTask
Q_OBJECT
public:
explicit PackInstallTask(UserInteractionSupport *support, QString packName, QString version);
explicit PackInstallTask(UserInteractionSupport *support, QString packName, QString version, InstallMode installMode = InstallMode::Install);
virtual ~PackInstallTask(){}
bool canAbort() const override { return true; }
@ -117,6 +123,7 @@ private:
NetJob::Ptr jobPtr;
QByteArray response;
InstallMode m_install_mode;
QString m_pack_name;
QString m_pack_safe_name;
QString m_version_name;