2015-02-03 03:55:30 +05:30
|
|
|
/* Copyright 2013-2015 MultiMC Contributors
|
2014-06-02 04:19:53 +05:30
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "MultiMC.h"
|
|
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QEvent>
|
|
|
|
#include <QKeyEvent>
|
|
|
|
|
|
|
|
#include "VersionPage.h"
|
|
|
|
#include "ui_VersionPage.h"
|
|
|
|
|
2015-02-09 06:21:14 +05:30
|
|
|
#include "dialogs/CustomMessageBox.h"
|
|
|
|
#include "dialogs/VersionSelectDialog.h"
|
|
|
|
#include "dialogs/ModEditDialogCommon.h"
|
2014-06-02 04:19:53 +05:30
|
|
|
|
2015-02-09 06:21:14 +05:30
|
|
|
#include "dialogs/ProgressDialog.h"
|
2015-05-05 04:12:04 +05:30
|
|
|
#include <GuiUtil.h>
|
2014-06-02 04:19:53 +05:30
|
|
|
|
2014-07-13 02:32:52 +05:30
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QListView>
|
|
|
|
#include <QString>
|
|
|
|
#include <QUrl>
|
|
|
|
|
2015-02-09 06:21:14 +05:30
|
|
|
#include "minecraft/MinecraftProfile.h"
|
2016-02-28 00:28:40 +05:30
|
|
|
#include "minecraft/forge/ForgeVersionList.h"
|
|
|
|
#include "minecraft/forge/ForgeInstaller.h"
|
|
|
|
#include "minecraft/liteloader/LiteLoaderVersionList.h"
|
|
|
|
#include "minecraft/liteloader/LiteLoaderInstaller.h"
|
|
|
|
#include "minecraft/auth/MojangAccountList.h"
|
2015-02-09 06:21:14 +05:30
|
|
|
#include "minecraft/Mod.h"
|
2016-02-28 00:28:40 +05:30
|
|
|
#include "minecraft/MinecraftVersion.h"
|
|
|
|
#include "minecraft/MinecraftVersionList.h"
|
2015-02-09 06:21:14 +05:30
|
|
|
#include "icons/IconList.h"
|
2015-05-28 23:08:29 +05:30
|
|
|
#include "Exception.h"
|
2014-06-02 04:19:53 +05:30
|
|
|
|
2016-02-21 06:14:27 +05:30
|
|
|
#include "MultiMC.h"
|
|
|
|
|
|
|
|
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);
|
|
|
|
int column = proxyIndex.column();
|
|
|
|
if(column == 0 && role == Qt::DecorationRole && m_parentWidget)
|
|
|
|
{
|
|
|
|
if(!var.isNull())
|
|
|
|
{
|
|
|
|
auto string = var.toString();
|
|
|
|
if(string == "warning")
|
|
|
|
{
|
|
|
|
return MMC->getThemedIcon("status-yellow");
|
|
|
|
}
|
|
|
|
else if(string == "error")
|
|
|
|
{
|
|
|
|
return MMC->getThemedIcon("status-bad");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return MMC->getThemedIcon("status-good");
|
|
|
|
}
|
|
|
|
return var;
|
|
|
|
}
|
|
|
|
private slots:
|
|
|
|
void widgetGone()
|
|
|
|
{
|
|
|
|
m_parentWidget = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QWidget *m_parentWidget = nullptr;
|
|
|
|
};
|
|
|
|
|
2014-07-12 21:28:23 +05:30
|
|
|
QIcon VersionPage::icon() const
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
2016-04-10 07:59:29 +05:30
|
|
|
return MMC->icons()->getIcon(m_inst->iconKey());
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
2014-07-12 21:28:23 +05:30
|
|
|
bool VersionPage::shouldDisplay() const
|
2014-06-30 05:32:57 +05:30
|
|
|
{
|
|
|
|
return !m_inst->isRunning();
|
|
|
|
}
|
|
|
|
|
2015-05-29 05:52:02 +05:30
|
|
|
void VersionPage::setParentContainer(BasePageContainer * container)
|
|
|
|
{
|
|
|
|
m_container = container;
|
|
|
|
}
|
|
|
|
|
2014-06-02 04:19:53 +05:30
|
|
|
VersionPage::VersionPage(OneSixInstance *inst, QWidget *parent)
|
|
|
|
: QWidget(parent), ui(new Ui::VersionPage), m_inst(inst)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2014-07-21 03:40:13 +05:30
|
|
|
ui->tabWidget->tabBar()->hide();
|
2014-06-02 04:19:53 +05:30
|
|
|
|
2015-04-15 06:42:57 +05:30
|
|
|
reloadMinecraftProfile();
|
|
|
|
|
2016-03-14 01:27:01 +05:30
|
|
|
m_profile = m_inst->getMinecraftProfile();
|
|
|
|
if (m_profile)
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
2016-02-21 06:14:27 +05:30
|
|
|
auto proxy = new IconProxy(ui->packageView);
|
2016-03-14 01:27:01 +05:30
|
|
|
proxy->setSourceModel(m_profile.get());
|
2016-02-21 06:14:27 +05:30
|
|
|
ui->packageView->setModel(proxy);
|
2015-05-18 03:08:28 +05:30
|
|
|
ui->packageView->installEventFilter(this);
|
|
|
|
ui->packageView->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
connect(ui->packageView->selectionModel(), &QItemSelectionModel::currentChanged,
|
2014-06-02 04:19:53 +05:30
|
|
|
this, &VersionPage::versionCurrent);
|
2016-02-21 06:14:27 +05:30
|
|
|
auto smodel = ui->packageView->selectionModel();
|
|
|
|
connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), SLOT(packageCurrent(QModelIndex, QModelIndex)));
|
2014-06-02 04:19:53 +05:30
|
|
|
updateVersionControls();
|
2014-06-10 12:09:11 +05:30
|
|
|
// select first item.
|
2015-05-18 03:08:28 +05:30
|
|
|
preselect(0);
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
disableVersionControls();
|
|
|
|
}
|
|
|
|
connect(m_inst, &OneSixInstance::versionReloaded, this,
|
|
|
|
&VersionPage::updateVersionControls);
|
|
|
|
}
|
|
|
|
|
|
|
|
VersionPage::~VersionPage()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2016-02-21 06:14:27 +05:30
|
|
|
void VersionPage::packageCurrent(const QModelIndex ¤t, const QModelIndex &previous)
|
|
|
|
{
|
|
|
|
if (!current.isValid())
|
|
|
|
{
|
|
|
|
ui->frame->clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int row = current.row();
|
2016-03-14 01:27:01 +05:30
|
|
|
auto patch = m_profile->versionPatch(row);
|
2016-02-21 06:14:27 +05:30
|
|
|
auto severity = patch->getProblemSeverity();
|
|
|
|
switch(severity)
|
|
|
|
{
|
|
|
|
case PROBLEM_WARNING:
|
2016-03-13 04:53:45 +05:30
|
|
|
ui->frame->setModText(tr("%1 possibly has issues.").arg(patch->getName()));
|
2016-02-21 06:14:27 +05:30
|
|
|
break;
|
|
|
|
case PROBLEM_ERROR:
|
2016-03-13 04:53:45 +05:30
|
|
|
ui->frame->setModText(tr("%1 has issues!").arg(patch->getName()));
|
2016-02-21 06:14:27 +05:30
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case PROBLEM_NONE:
|
|
|
|
ui->frame->clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &problems = patch->getProblems();
|
|
|
|
QString problemOut;
|
|
|
|
for (auto &problem: problems)
|
|
|
|
{
|
|
|
|
if(problem.getSeverity() == PROBLEM_ERROR)
|
|
|
|
{
|
|
|
|
problemOut += tr("Error: ");
|
|
|
|
}
|
|
|
|
else if(problem.getSeverity() == PROBLEM_WARNING)
|
|
|
|
{
|
|
|
|
problemOut += tr("Warning: ");
|
|
|
|
}
|
|
|
|
problemOut += problem.getDescription();
|
|
|
|
problemOut += "\n";
|
|
|
|
}
|
|
|
|
ui->frame->setModDescription(problemOut);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-02 04:19:53 +05:30
|
|
|
void VersionPage::updateVersionControls()
|
|
|
|
{
|
|
|
|
ui->forgeBtn->setEnabled(true);
|
|
|
|
ui->liteloaderBtn->setEnabled(true);
|
2015-05-18 03:08:28 +05:30
|
|
|
updateButtons();
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::disableVersionControls()
|
|
|
|
{
|
|
|
|
ui->forgeBtn->setEnabled(false);
|
|
|
|
ui->liteloaderBtn->setEnabled(false);
|
2015-05-18 03:08:28 +05:30
|
|
|
ui->reloadBtn->setEnabled(false);
|
|
|
|
updateButtons();
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
|
2015-01-28 03:01:07 +05:30
|
|
|
bool VersionPage::reloadMinecraftProfile()
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-01-28 03:01:07 +05:30
|
|
|
m_inst->reloadProfile();
|
2014-06-02 04:19:53 +05:30
|
|
|
return true;
|
|
|
|
}
|
2015-05-28 23:08:29 +05:30
|
|
|
catch (Exception &e)
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error"), e.cause());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
QMessageBox::critical(
|
|
|
|
this, tr("Error"),
|
2015-04-15 06:42:57 +05:30
|
|
|
tr("Couldn't load the instance profile."));
|
2014-06-02 04:19:53 +05:30
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-18 03:08:28 +05:30
|
|
|
void VersionPage::on_reloadBtn_clicked()
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
2015-01-28 03:01:07 +05:30
|
|
|
reloadMinecraftProfile();
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
|
2015-05-18 03:08:28 +05:30
|
|
|
void VersionPage::on_removeBtn_clicked()
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
2015-05-18 03:08:28 +05:30
|
|
|
if (ui->packageView->currentIndex().isValid())
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
|
|
|
// FIXME: use actual model, not reloading.
|
2016-03-14 01:27:01 +05:30
|
|
|
if (!m_profile->remove(ui->packageView->currentIndex().row()))
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error"), tr("Couldn't remove file"));
|
|
|
|
}
|
|
|
|
}
|
2015-05-18 03:08:28 +05:30
|
|
|
updateButtons();
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
|
2015-05-29 05:52:02 +05:30
|
|
|
void VersionPage::on_modBtn_clicked()
|
|
|
|
{
|
|
|
|
if(m_container)
|
|
|
|
{
|
|
|
|
m_container->selectPage("mods");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-02 04:19:53 +05:30
|
|
|
void VersionPage::on_jarmodBtn_clicked()
|
|
|
|
{
|
2015-05-29 05:52:02 +05:30
|
|
|
bool nagShown = false;
|
2016-03-14 01:27:01 +05:30
|
|
|
if (!m_profile->hasTrait("legacyLaunch") && !m_profile->hasTrait("alphaLaunch"))
|
2015-05-29 05:52:02 +05:30
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
2015-09-10 03:23:33 +05:30
|
|
|
auto list = GuiUtil::BrowseForFiles("jarmod", tr("Select jar mods"), tr("Minecraft.jar mods (*.zip *.jar)"), MMC->settings()->get("CentralModsDir").toString(), this->parentWidget());
|
2015-05-05 04:12:04 +05:30
|
|
|
if(!list.empty())
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
2016-03-14 01:27:01 +05:30
|
|
|
m_profile->installJarMods(list);
|
2015-05-29 05:52:02 +05:30
|
|
|
if(nagShown)
|
|
|
|
{
|
|
|
|
MMC->settings()->set("JarModNagSeen", QVariant(true));
|
|
|
|
}
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
2015-05-18 03:08:28 +05:30
|
|
|
updateButtons();
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
|
2015-05-18 03:08:28 +05:30
|
|
|
void VersionPage::on_resetOrderBtn_clicked()
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2016-03-14 01:27:01 +05:30
|
|
|
m_profile->resetOrder();
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
2015-05-28 23:08:29 +05:30
|
|
|
catch (Exception &e)
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error"), e.cause());
|
|
|
|
}
|
2015-05-18 03:08:28 +05:30
|
|
|
updateButtons();
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
|
2015-05-18 03:08:28 +05:30
|
|
|
void VersionPage::on_moveUpBtn_clicked()
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2016-03-14 01:27:01 +05:30
|
|
|
m_profile->move(currentRow(), MinecraftProfile::MoveUp);
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
2015-05-28 23:08:29 +05:30
|
|
|
catch (Exception &e)
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error"), e.cause());
|
|
|
|
}
|
2015-05-18 03:08:28 +05:30
|
|
|
updateButtons();
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
|
2015-05-18 03:08:28 +05:30
|
|
|
void VersionPage::on_moveDownBtn_clicked()
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2016-03-14 01:27:01 +05:30
|
|
|
m_profile->move(currentRow(), MinecraftProfile::MoveDown);
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
2015-05-28 23:08:29 +05:30
|
|
|
catch (Exception &e)
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error"), e.cause());
|
|
|
|
}
|
2015-05-18 03:08:28 +05:30
|
|
|
updateButtons();
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
|
2015-05-18 03:08:28 +05:30
|
|
|
void VersionPage::on_changeVersionBtn_clicked()
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
|
|
|
VersionSelectDialog vselect(m_inst->versionList().get(), tr("Change Minecraft version"),
|
|
|
|
this);
|
|
|
|
if (!vselect.exec() || !vselect.selectedVersion())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!MMC->accounts()->anyAccountIsValid())
|
|
|
|
{
|
|
|
|
CustomMessageBox::selectable(
|
|
|
|
this, tr("Error"),
|
|
|
|
tr("MultiMC cannot download Minecraft or update instances unless you have at least "
|
|
|
|
"one account added.\nPlease add your Mojang or Minecraft account."),
|
|
|
|
QMessageBox::Warning)->show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-14 01:27:01 +05:30
|
|
|
if (!m_profile->isVanilla())
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
|
|
|
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;
|
2016-03-14 01:27:01 +05:30
|
|
|
m_profile->revertToVanilla();
|
2015-01-28 03:01:07 +05:30
|
|
|
reloadMinecraftProfile();
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
m_inst->setIntendedVersionId(vselect.selectedVersion()->descriptor());
|
2015-05-28 13:06:58 +05:30
|
|
|
doUpdate();
|
|
|
|
}
|
2014-06-02 04:19:53 +05:30
|
|
|
|
2015-05-28 13:06:58 +05:30
|
|
|
int VersionPage::doUpdate()
|
|
|
|
{
|
2015-07-10 03:36:05 +05:30
|
|
|
auto updateTask = m_inst->createUpdateTask();
|
2014-06-02 04:19:53 +05:30
|
|
|
if (!updateTask)
|
|
|
|
{
|
2015-05-28 13:06:58 +05:30
|
|
|
return 1;
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
ProgressDialog tDialog(this);
|
|
|
|
connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString)));
|
2015-09-26 07:34:09 +05:30
|
|
|
int ret = tDialog.execWithTask(updateTask.get());
|
2015-05-18 03:08:28 +05:30
|
|
|
updateButtons();
|
2015-05-28 13:06:58 +05:30
|
|
|
return ret;
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::on_forgeBtn_clicked()
|
|
|
|
{
|
|
|
|
VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this);
|
2015-04-28 12:31:37 +05:30
|
|
|
vselect.setExactFilter(BaseVersionList::ParentGameVersionRole, m_inst->currentVersionId());
|
2014-06-02 04:19:53 +05:30
|
|
|
vselect.setEmptyString(tr("No Forge versions are currently available for Minecraft ") +
|
|
|
|
m_inst->currentVersionId());
|
2015-05-03 03:12:33 +05:30
|
|
|
vselect.setEmptyErrorString(tr("Couldn't load or download the Forge version lists!"));
|
2014-06-02 04:19:53 +05:30
|
|
|
if (vselect.exec() && vselect.selectedVersion())
|
|
|
|
{
|
|
|
|
ProgressDialog dialog(this);
|
2015-09-26 07:34:09 +05:30
|
|
|
dialog.execWithTask(
|
2014-06-02 04:19:53 +05:30
|
|
|
ForgeInstaller().createInstallTask(m_inst, vselect.selectedVersion(), this));
|
2016-03-14 01:27:01 +05:30
|
|
|
preselect(m_profile->rowCount(QModelIndex())-1);
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::on_liteloaderBtn_clicked()
|
|
|
|
{
|
|
|
|
VersionSelectDialog vselect(MMC->liteloaderlist().get(), tr("Select LiteLoader version"),
|
|
|
|
this);
|
2015-04-28 12:31:37 +05:30
|
|
|
vselect.setExactFilter(BaseVersionList::ParentGameVersionRole, m_inst->currentVersionId());
|
2014-06-02 04:19:53 +05:30
|
|
|
vselect.setEmptyString(tr("No LiteLoader versions are currently available for Minecraft ") +
|
|
|
|
m_inst->currentVersionId());
|
2015-05-03 03:12:33 +05:30
|
|
|
vselect.setEmptyErrorString(tr("Couldn't load or download the LiteLoader version lists!"));
|
2014-06-02 04:19:53 +05:30
|
|
|
if (vselect.exec() && vselect.selectedVersion())
|
|
|
|
{
|
|
|
|
ProgressDialog dialog(this);
|
2015-09-26 07:34:09 +05:30
|
|
|
dialog.execWithTask(
|
2014-06-02 04:19:53 +05:30
|
|
|
LiteLoaderInstaller().createInstallTask(m_inst, vselect.selectedVersion(), this));
|
2016-03-14 01:27:01 +05:30
|
|
|
preselect(m_profile->rowCount(QModelIndex())-1);
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::versionCurrent(const QModelIndex ¤t, const QModelIndex &previous)
|
|
|
|
{
|
2015-05-18 03:08:28 +05:30
|
|
|
currentIdx = current.row();
|
|
|
|
updateButtons(currentIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::preselect(int row)
|
|
|
|
{
|
|
|
|
if(row < 0)
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
2015-05-18 03:08:28 +05:30
|
|
|
row = 0;
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
2016-03-14 01:27:01 +05:30
|
|
|
if(row >= m_profile->rowCount(QModelIndex()))
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
2016-03-14 01:27:01 +05:30
|
|
|
row = m_profile->rowCount(QModelIndex()) - 1;
|
2015-05-18 03:08:28 +05:30
|
|
|
}
|
|
|
|
if(row < 0)
|
|
|
|
{
|
|
|
|
return;
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
2016-03-14 01:27:01 +05:30
|
|
|
auto model_index = m_profile->index(row);
|
2015-05-18 03:08:28 +05:30
|
|
|
ui->packageView->selectionModel()->select(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
|
|
|
|
updateButtons(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::updateButtons(int row)
|
|
|
|
{
|
|
|
|
if(row == -1)
|
|
|
|
row = currentRow();
|
2016-03-14 01:27:01 +05:30
|
|
|
auto patch = m_profile->versionPatch(row);
|
2015-05-18 03:08:28 +05:30
|
|
|
if (!patch)
|
2014-06-08 22:31:19 +05:30
|
|
|
{
|
2015-05-18 03:08:28 +05:30
|
|
|
ui->removeBtn->setDisabled(true);
|
|
|
|
ui->moveDownBtn->setDisabled(true);
|
|
|
|
ui->moveUpBtn->setDisabled(true);
|
|
|
|
ui->changeVersionBtn->setDisabled(true);
|
|
|
|
ui->editBtn->setDisabled(true);
|
|
|
|
ui->customizeBtn->setDisabled(true);
|
|
|
|
ui->revertBtn->setDisabled(true);
|
2014-06-08 22:31:19 +05:30
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-18 03:08:28 +05:30
|
|
|
ui->removeBtn->setEnabled(patch->isRemovable());
|
|
|
|
ui->moveDownBtn->setEnabled(patch->isMoveable());
|
|
|
|
ui->moveUpBtn->setEnabled(patch->isMoveable());
|
|
|
|
ui->changeVersionBtn->setEnabled(patch->isVersionChangeable());
|
|
|
|
ui->editBtn->setEnabled(patch->isEditable());
|
|
|
|
ui->customizeBtn->setEnabled(patch->isCustomizable());
|
|
|
|
ui->revertBtn->setEnabled(patch->isRevertible());
|
2014-06-08 22:31:19 +05:30
|
|
|
}
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
2015-04-08 17:20:21 +05:30
|
|
|
|
|
|
|
void VersionPage::onGameUpdateError(QString error)
|
|
|
|
{
|
|
|
|
CustomMessageBox::selectable(this, tr("Error updating instance"), error,
|
|
|
|
QMessageBox::Warning)->show();
|
|
|
|
}
|
2015-05-18 03:08:28 +05:30
|
|
|
|
|
|
|
ProfilePatchPtr VersionPage::current()
|
|
|
|
{
|
|
|
|
auto row = currentRow();
|
|
|
|
if(row < 0)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-03-14 01:27:01 +05:30
|
|
|
return m_profile->versionPatch(row);
|
2015-05-18 03:08:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
int VersionPage::currentRow()
|
|
|
|
{
|
|
|
|
if (ui->packageView->selectionModel()->selectedRows().isEmpty())
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return ui->packageView->selectionModel()->selectedRows().first().row();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::on_customizeBtn_clicked()
|
|
|
|
{
|
|
|
|
auto version = currentRow();
|
|
|
|
if(version == -1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-05-28 13:06:58 +05:30
|
|
|
//HACK HACK remove, this is dumb
|
2016-03-14 01:27:01 +05:30
|
|
|
auto patch = m_profile->versionPatch(version);
|
2015-05-28 13:06:58 +05:30
|
|
|
auto mc = std::dynamic_pointer_cast<MinecraftVersion>(patch);
|
|
|
|
if(mc && mc->needsUpdate())
|
|
|
|
{
|
|
|
|
if(!doUpdate())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-03-14 01:27:01 +05:30
|
|
|
if(!m_profile->customize(version))
|
2015-05-18 03:08:28 +05:30
|
|
|
{
|
|
|
|
// TODO: some error box here
|
|
|
|
}
|
|
|
|
updateButtons();
|
|
|
|
preselect(currentIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::on_editBtn_clicked()
|
|
|
|
{
|
|
|
|
auto version = current();
|
|
|
|
if(!version)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-03-13 04:53:45 +05:30
|
|
|
auto filename = version->getFilename();
|
2015-05-18 03:08:28 +05:30
|
|
|
if(!QFileInfo::exists(filename))
|
|
|
|
{
|
|
|
|
qWarning() << "file" << filename << "can't be opened for editing, doesn't exist!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MMC->openJsonEditor(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::on_revertBtn_clicked()
|
|
|
|
{
|
|
|
|
auto version = currentRow();
|
|
|
|
if(version == -1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-05-28 13:06:58 +05:30
|
|
|
auto mcraw = MMC->minecraftlist()->findVersion(m_inst->intendedVersionId());
|
|
|
|
auto mc = std::dynamic_pointer_cast<MinecraftVersion>(mcraw);
|
|
|
|
if(mc && mc->needsUpdate())
|
|
|
|
{
|
|
|
|
if(!doUpdate())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-03-14 01:27:01 +05:30
|
|
|
if(!m_profile->revertToBase(version))
|
2015-05-18 03:08:28 +05:30
|
|
|
{
|
|
|
|
// TODO: some error box here
|
|
|
|
}
|
|
|
|
updateButtons();
|
|
|
|
preselect(currentIdx);
|
|
|
|
}
|
2016-02-21 06:14:27 +05:30
|
|
|
|
|
|
|
#include "VersionPage.moc"
|