summaryrefslogtreecommitdiffstats
path: root/application/pages/VersionPage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'application/pages/VersionPage.cpp')
-rw-r--r--application/pages/VersionPage.cpp203
1 files changed, 104 insertions, 99 deletions
diff --git a/application/pages/VersionPage.cpp b/application/pages/VersionPage.cpp
index 8c14818f..00ae0a7e 100644
--- a/application/pages/VersionPage.cpp
+++ b/application/pages/VersionPage.cpp
@@ -1,4 +1,4 @@
-/* Copyright 2013-2017 MultiMC Contributors
+/* Copyright 2013-2018 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
#include "dialogs/CustomMessageBox.h"
#include "dialogs/VersionSelectDialog.h"
+#include "dialogs/NewComponentDialog.h"
#include "dialogs/ModEditDialogCommon.h"
#include "dialogs/ProgressDialog.h"
@@ -35,7 +36,7 @@
#include <QString>
#include <QUrl>
-#include "minecraft/MinecraftProfile.h"
+#include "minecraft/ComponentList.h"
#include "minecraft/auth/MojangAccountList.h"
#include "minecraft/Mod.h"
#include "icons/IconList.h"
@@ -50,13 +51,13 @@ class IconProxy : public QIdentityProxyModel
{
Q_OBJECT
public:
-
+
IconProxy(QWidget *parentWidget) : QIdentityProxyModel(parentWidget)
{
connect(parentWidget, &QObject::destroyed, this, &IconProxy::widgetGone);
m_parentWidget = parentWidget;
}
-
+
virtual QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const override
{
QVariant var = QIdentityProxyModel::data(mapToSource(proxyIndex), role);
@@ -98,20 +99,15 @@ bool VersionPage::shouldDisplay() const
return !m_inst->isRunning();
}
-void VersionPage::setParentContainer(BasePageContainer * container)
-{
- m_container = container;
-}
-
-VersionPage::VersionPage(OneSixInstance *inst, QWidget *parent)
+VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent)
: QWidget(parent), ui(new Ui::VersionPage), m_inst(inst)
{
ui->setupUi(this);
ui->tabWidget->tabBar()->hide();
+ m_profile = m_inst->getComponentList();
- reloadMinecraftProfile();
+ reloadComponentList();
- m_profile = m_inst->getMinecraftProfile();
if (m_profile)
{
auto proxy = new IconProxy(ui->packageView);
@@ -119,10 +115,9 @@ VersionPage::VersionPage(OneSixInstance *inst, QWidget *parent)
ui->packageView->setModel(proxy);
ui->packageView->installEventFilter(this);
ui->packageView->setSelectionMode(QAbstractItemView::SingleSelection);
- connect(ui->packageView->selectionModel(), &QItemSelectionModel::currentChanged,
- this, &VersionPage::versionCurrent);
+ connect(ui->packageView->selectionModel(), &QItemSelectionModel::currentChanged, this, &VersionPage::versionCurrent);
auto smodel = ui->packageView->selectionModel();
- connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), SLOT(packageCurrent(QModelIndex, QModelIndex)));
+ connect(smodel, &QItemSelectionModel::currentChanged, this, &VersionPage::packageCurrent);
updateVersionControls();
// select first item.
preselect(0);
@@ -131,7 +126,7 @@ VersionPage::VersionPage(OneSixInstance *inst, QWidget *parent)
{
disableVersionControls();
}
- connect(m_inst, &OneSixInstance::versionReloaded, this,
+ connect(m_inst, &MinecraftInstance::versionReloaded, this,
&VersionPage::updateVersionControls);
}
@@ -148,7 +143,7 @@ void VersionPage::packageCurrent(const QModelIndex &current, const QModelIndex &
return;
}
int row = current.row();
- auto patch = m_profile->versionPatch(row);
+ auto patch = m_profile->getComponent(row);
auto severity = patch->getProblemSeverity();
switch(severity)
{
@@ -168,15 +163,15 @@ void VersionPage::packageCurrent(const QModelIndex &current, const QModelIndex &
QString problemOut;
for (auto &problem: problems)
{
- if(problem.getSeverity() == ProblemSeverity::Error)
+ if(problem.m_severity == ProblemSeverity::Error)
{
problemOut += tr("Error: ");
}
- else if(problem.getSeverity() == ProblemSeverity::Warning)
+ else if(problem.m_severity == ProblemSeverity::Warning)
{
problemOut += tr("Warning: ");
}
- problemOut += problem.getDescription();
+ problemOut += problem.m_description;
problemOut += "\n";
}
ui->frame->setModDescription(problemOut);
@@ -198,11 +193,11 @@ void VersionPage::disableVersionControls()
updateButtons();
}
-bool VersionPage::reloadMinecraftProfile()
+bool VersionPage::reloadComponentList()
{
try
{
- m_inst->reloadProfile();
+ m_profile->reload(Net::Mode::Online);
return true;
}
catch (Exception &e)
@@ -221,7 +216,7 @@ bool VersionPage::reloadMinecraftProfile()
void VersionPage::on_reloadBtn_clicked()
{
- reloadMinecraftProfile();
+ reloadComponentList();
m_container->refreshContainer();
}
@@ -236,7 +231,7 @@ void VersionPage::on_removeBtn_clicked()
}
}
updateButtons();
- reloadMinecraftProfile();
+ reloadComponentList();
m_container->refreshContainer();
}
@@ -250,47 +245,20 @@ void VersionPage::on_modBtn_clicked()
void VersionPage::on_jarmodBtn_clicked()
{
- bool nagShown = false;
- if (!m_profile->hasTrait("legacyLaunch") && !m_profile->hasTrait("alphaLaunch"))
- {
- // not legacy launch... nag
- auto seenNag = MMC->settings()->get("JarModNagSeen").toBool();
- if(!seenNag)
- {
- auto result = QMessageBox::question(this,
- tr("Are you sure?"),
- tr("This will add mods directly to the Minecraft jar.\n"
- "Unless you KNOW that this is what NEEDS to be done, you should just use the mods folder (Loader mods).\n"
- "\n"
- "Do you want to continue?"),
- tr("I understand, continue."), tr("Cancel"), QString(), 1, 1
- );
- if(result != 0)
- return;
- nagShown = true;
- }
- }
auto list = GuiUtil::BrowseForFiles("jarmod", tr("Select jar mods"), tr("Minecraft.jar mods (*.zip *.jar)"), MMC->settings()->get("CentralModsDir").toString(), this->parentWidget());
if(!list.empty())
{
m_profile->installJarMods(list);
- if(nagShown)
- {
- MMC->settings()->set("JarModNagSeen", QVariant(true));
- }
}
updateButtons();
}
-void VersionPage::on_resetOrderBtn_clicked()
+void VersionPage::on_jarBtn_clicked()
{
- try
- {
- m_profile->resetOrder();
- }
- catch (Exception &e)
+ auto jarPath = GuiUtil::BrowseForFile("jar", tr("Select jar"), tr("Minecraft.jar replacement (*.jar)"), MMC->settings()->get("CentralModsDir").toString(), this->parentWidget());
+ if(!jarPath.isEmpty())
{
- QMessageBox::critical(this, tr("Error"), e.cause());
+ m_profile->installCustomJar(jarPath);
}
updateButtons();
}
@@ -299,7 +267,7 @@ void VersionPage::on_moveUpBtn_clicked()
{
try
{
- m_profile->move(currentRow(), MinecraftProfile::MoveUp);
+ m_profile->move(currentRow(), ComponentList::MoveUp);
}
catch (Exception &e)
{
@@ -312,7 +280,7 @@ void VersionPage::on_moveDownBtn_clicked()
{
try
{
- m_profile->move(currentRow(), MinecraftProfile::MoveDown);
+ m_profile->move(currentRow(), ComponentList::MoveDown);
}
catch (Exception &e)
{
@@ -328,7 +296,7 @@ void VersionPage::on_changeVersionBtn_clicked()
{
return;
}
- auto patch = m_profile->versionPatch(versionRow);
+ auto patch = m_profile->getComponent(versionRow);
auto name = patch->getName();
auto list = patch->getVersionList();
if(!list)
@@ -336,10 +304,39 @@ void VersionPage::on_changeVersionBtn_clicked()
return;
}
auto uid = list->uid();
+ // FIXME: this is a horrible HACK. Get version filtering information from the actual metadata...
+ if(uid == "net.minecraftforge")
+ {
+ on_forgeBtn_clicked();
+ return;
+ }
+ else if (uid == "com.mumfrey.liteloader")
+ {
+ on_liteloaderBtn_clicked();
+ return;
+ }
VersionSelectDialog vselect(list.get(), tr("Change %1 version").arg(name), this);
+ auto currentVersion = patch->getVersion();
+ if(!currentVersion.isEmpty())
+ {
+ vselect.setCurrentVersion(currentVersion);
+ }
if (!vselect.exec() || !vselect.selectedVersion())
return;
+ qDebug() << "Change" << uid << "to" << vselect.selectedVersion()->descriptor();
+ bool important = false;
+ if(uid == "net.minecraft")
+ {
+ important = true;
+ }
+ m_profile->setComponentVersion(uid, vselect.selectedVersion()->descriptor(), important);
+ m_profile->resolve(Net::Mode::Online);
+ m_container->refreshContainer();
+}
+
+void VersionPage::on_downloadBtn_clicked()
+{
if (!MMC->accounts()->anyAccountIsValid())
{
CustomMessageBox::selectable(
@@ -350,42 +347,17 @@ void VersionPage::on_changeVersionBtn_clicked()
return;
}
- qDebug() << "Change" << uid << "to" << vselect.selectedVersion()->descriptor();
- if(uid == "net.minecraft")
- {
- if (!m_profile->isVanilla())
- {
- auto result = CustomMessageBox::selectable(
- this, tr("Are you sure?"),
- tr("This will remove any library/version customization you did previously. "
- "This includes things like Forge install and similar."),
- QMessageBox::Warning, QMessageBox::Ok | QMessageBox::Abort,
- QMessageBox::Abort)->exec();
-
- if (result != QMessageBox::Ok)
- return;
- m_profile->revertToVanilla();
- reloadMinecraftProfile();
- }
- }
- m_inst->setComponentVersion(uid, vselect.selectedVersion()->descriptor());
- doUpdate();
- m_container->refreshContainer();
-}
-
-int VersionPage::doUpdate()
-{
- auto updateTask = m_inst->createUpdateTask();
+ auto updateTask = m_inst->createUpdateTask(Net::Mode::Online);
if (!updateTask)
{
- return 1;
+ return;
}
ProgressDialog tDialog(this);
connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString)));
- int ret = tDialog.execWithTask(updateTask.get());
+ // FIXME: unused return value
+ tDialog.execWithTask(updateTask.get());
updateButtons();
m_container->refreshContainer();
- return ret;
}
void VersionPage::on_forgeBtn_clicked()
@@ -396,20 +368,45 @@ void VersionPage::on_forgeBtn_clicked()
return;
}
VersionSelectDialog vselect(vlist.get(), tr("Select Forge version"), this);
- vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_inst->currentVersionId());
- vselect.setEmptyString(tr("No Forge versions are currently available for Minecraft ") + m_inst->currentVersionId());
+ vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft"));
+ vselect.setEmptyString(tr("No Forge versions are currently available for Minecraft ") + m_profile->getComponentVersion("net.minecraft"));
vselect.setEmptyErrorString(tr("Couldn't load or download the Forge version lists!"));
+
+ auto currentVersion = m_profile->getComponentVersion("net.minecraftforge");
+ if(!currentVersion.isEmpty())
+ {
+ vselect.setCurrentVersion(currentVersion);
+ }
+
if (vselect.exec() && vselect.selectedVersion())
{
auto vsn = vselect.selectedVersion();
- m_inst->setComponentVersion("net.minecraftforge", vsn->descriptor());
- m_profile->reload();
+ m_profile->setComponentVersion("net.minecraftforge", vsn->descriptor());
+ m_profile->resolve(Net::Mode::Online);
// m_profile->installVersion();
preselect(m_profile->rowCount(QModelIndex())-1);
m_container->refreshContainer();
}
}
+void VersionPage::on_addEmptyBtn_clicked()
+{
+ NewComponentDialog compdialog(QString(), QString(), this);
+ QStringList blacklist;
+ for(int i = 0; i < m_profile->rowCount(); i++)
+ {
+ auto comp = m_profile->getComponent(i);
+ blacklist.push_back(comp->getID());
+ }
+ compdialog.setBlacklist(blacklist);
+ if (compdialog.exec())
+ {
+ qDebug() << "name:" << compdialog.name();
+ qDebug() << "uid:" << compdialog.uid();
+ m_profile->installEmpty(compdialog.uid(), compdialog.name());
+ }
+}
+
void VersionPage::on_liteloaderBtn_clicked()
{
auto vlist = ENV.metadataIndex()->get("com.mumfrey.liteloader");
@@ -418,14 +415,21 @@ void VersionPage::on_liteloaderBtn_clicked()
return;
}
VersionSelectDialog vselect(vlist.get(), tr("Select LiteLoader version"), this);
- vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_inst->currentVersionId());
- vselect.setEmptyString(tr("No LiteLoader versions are currently available for Minecraft ") + m_inst->currentVersionId());
+ vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft"));
+ vselect.setEmptyString(tr("No LiteLoader versions are currently available for Minecraft ") + m_profile->getComponentVersion("net.minecraft"));
vselect.setEmptyErrorString(tr("Couldn't load or download the LiteLoader version lists!"));
+
+ auto currentVersion = m_profile->getComponentVersion("com.mumfrey.liteloader");
+ if(!currentVersion.isEmpty())
+ {
+ vselect.setCurrentVersion(currentVersion);
+ }
+
if (vselect.exec() && vselect.selectedVersion())
{
auto vsn = vselect.selectedVersion();
- m_inst->setComponentVersion("com.mumfrey.liteloader", vsn->descriptor());
- m_profile->reload();
+ m_profile->setComponentVersion("com.mumfrey.liteloader", vsn->descriptor());
+ m_profile->resolve(Net::Mode::Online);
// m_profile->installVersion(vselect.selectedVersion());
preselect(m_profile->rowCount(QModelIndex())-1);
m_container->refreshContainer();
@@ -461,7 +465,7 @@ void VersionPage::updateButtons(int row)
{
if(row == -1)
row = currentRow();
- auto patch = m_profile->versionPatch(row);
+ auto patch = m_profile->getComponent(row);
if (!patch)
{
ui->removeBtn->setDisabled(true);
@@ -490,14 +494,14 @@ void VersionPage::onGameUpdateError(QString error)
QMessageBox::Warning)->show();
}
-ProfilePatchPtr VersionPage::current()
+Component * VersionPage::current()
{
auto row = currentRow();
if(row < 0)
{
return nullptr;
}
- return m_profile->versionPatch(row);
+ return m_profile->getComponent(row);
}
int VersionPage::currentRow()
@@ -516,7 +520,7 @@ void VersionPage::on_customizeBtn_clicked()
{
return;
}
- auto patch = m_profile->versionPatch(version);
+ auto patch = m_profile->getComponent(version);
if(!patch->getVersionFile())
{
// TODO: wait for the update task to finish here...
@@ -563,3 +567,4 @@ void VersionPage::on_revertBtn_clicked()
}
#include "VersionPage.moc"
+