2018-02-10 23:40:01 +00:00
|
|
|
/* Copyright 2013-2018 MultiMC Contributors
|
2014-06-01 22:49:53 +00:00
|
|
|
*
|
|
|
|
* 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 00:51:14 +00:00
|
|
|
#include "dialogs/CustomMessageBox.h"
|
|
|
|
#include "dialogs/VersionSelectDialog.h"
|
2017-12-31 00:37:50 +00:00
|
|
|
#include "dialogs/NewComponentDialog.h"
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "dialogs/ModEditDialogCommon.h"
|
2014-06-01 22:49:53 +00:00
|
|
|
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "dialogs/ProgressDialog.h"
|
2015-05-04 22:42:04 +00:00
|
|
|
#include <GuiUtil.h>
|
2014-06-01 22:49:53 +00:00
|
|
|
|
2014-07-12 21:02:52 +00:00
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QListView>
|
|
|
|
#include <QString>
|
|
|
|
#include <QUrl>
|
|
|
|
|
2017-10-11 21:04:24 +00:00
|
|
|
#include "minecraft/ComponentList.h"
|
2016-02-27 18:58:40 +00:00
|
|
|
#include "minecraft/auth/MojangAccountList.h"
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "minecraft/Mod.h"
|
|
|
|
#include "icons/IconList.h"
|
2015-05-28 17:38:29 +00:00
|
|
|
#include "Exception.h"
|
2014-06-01 22:49:53 +00:00
|
|
|
|
2016-02-21 00:44:27 +00:00
|
|
|
#include "MultiMC.h"
|
|
|
|
|
2017-03-24 01:26:06 +00:00
|
|
|
#include <meta/Index.h>
|
|
|
|
#include <meta/VersionList.h>
|
|
|
|
|
2016-02-21 00:44:27 +00:00
|
|
|
class IconProxy : public QIdentityProxyModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2017-07-24 07:01:37 +00:00
|
|
|
|
2016-02-21 00:44:27 +00:00
|
|
|
IconProxy(QWidget *parentWidget) : QIdentityProxyModel(parentWidget)
|
|
|
|
{
|
|
|
|
connect(parentWidget, &QObject::destroyed, this, &IconProxy::widgetGone);
|
|
|
|
m_parentWidget = parentWidget;
|
|
|
|
}
|
2017-07-24 07:01:37 +00:00
|
|
|
|
2016-02-21 00:44:27 +00:00
|
|
|
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 15:58:23 +00:00
|
|
|
QIcon VersionPage::icon() const
|
2014-06-01 22:49:53 +00:00
|
|
|
{
|
2016-04-10 02:29:29 +00:00
|
|
|
return MMC->icons()->getIcon(m_inst->iconKey());
|
2014-06-01 22:49:53 +00:00
|
|
|
}
|
2014-07-12 15:58:23 +00:00
|
|
|
bool VersionPage::shouldDisplay() const
|
2014-06-30 00:02:57 +00:00
|
|
|
{
|
|
|
|
return !m_inst->isRunning();
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:01:37 +00:00
|
|
|
VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent)
|
2014-06-01 22:49:53 +00:00
|
|
|
: QWidget(parent), ui(new Ui::VersionPage), m_inst(inst)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2014-07-20 22:10:13 +00:00
|
|
|
ui->tabWidget->tabBar()->hide();
|
2017-11-11 00:38:31 +00:00
|
|
|
m_profile = m_inst->getComponentList();
|
2014-06-01 22:49:53 +00:00
|
|
|
|
2017-10-11 21:04:24 +00:00
|
|
|
reloadComponentList();
|
2015-04-15 01:12:57 +00:00
|
|
|
|
2016-03-13 19:57:01 +00:00
|
|
|
if (m_profile)
|
2014-06-01 22:49:53 +00:00
|
|
|
{
|
2016-02-21 00:44:27 +00:00
|
|
|
auto proxy = new IconProxy(ui->packageView);
|
2016-03-13 19:57:01 +00:00
|
|
|
proxy->setSourceModel(m_profile.get());
|
2016-02-21 00:44:27 +00:00
|
|
|
ui->packageView->setModel(proxy);
|
2015-05-17 21:38:28 +00:00
|
|
|
ui->packageView->installEventFilter(this);
|
|
|
|
ui->packageView->setSelectionMode(QAbstractItemView::SingleSelection);
|
2017-07-29 06:43:34 +00:00
|
|
|
connect(ui->packageView->selectionModel(), &QItemSelectionModel::currentChanged, this, &VersionPage::versionCurrent);
|
2016-02-21 00:44:27 +00:00
|
|
|
auto smodel = ui->packageView->selectionModel();
|
2017-07-29 06:43:34 +00:00
|
|
|
connect(smodel, &QItemSelectionModel::currentChanged, this, &VersionPage::packageCurrent);
|
2014-06-01 22:49:53 +00:00
|
|
|
updateVersionControls();
|
2014-06-10 06:39:11 +00:00
|
|
|
// select first item.
|
2015-05-17 21:38:28 +00:00
|
|
|
preselect(0);
|
2014-06-01 22:49:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
disableVersionControls();
|
|
|
|
}
|
2017-07-24 07:01:37 +00:00
|
|
|
connect(m_inst, &MinecraftInstance::versionReloaded, this,
|
2014-06-01 22:49:53 +00:00
|
|
|
&VersionPage::updateVersionControls);
|
|
|
|
}
|
|
|
|
|
|
|
|
VersionPage::~VersionPage()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2016-02-21 00:44:27 +00:00
|
|
|
void VersionPage::packageCurrent(const QModelIndex ¤t, const QModelIndex &previous)
|
|
|
|
{
|
|
|
|
if (!current.isValid())
|
|
|
|
{
|
|
|
|
ui->frame->clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int row = current.row();
|
2017-11-11 00:38:31 +00:00
|
|
|
auto patch = m_profile->getComponent(row);
|
2016-02-21 00:44:27 +00:00
|
|
|
auto severity = patch->getProblemSeverity();
|
|
|
|
switch(severity)
|
|
|
|
{
|
2017-03-27 01:34:39 +00:00
|
|
|
case ProblemSeverity::Warning:
|
2016-03-12 23:23:45 +00:00
|
|
|
ui->frame->setModText(tr("%1 possibly has issues.").arg(patch->getName()));
|
2016-02-21 00:44:27 +00:00
|
|
|
break;
|
2017-03-27 01:34:39 +00:00
|
|
|
case ProblemSeverity::Error:
|
2016-03-12 23:23:45 +00:00
|
|
|
ui->frame->setModText(tr("%1 has issues!").arg(patch->getName()));
|
2016-02-21 00:44:27 +00:00
|
|
|
break;
|
|
|
|
default:
|
2017-03-27 01:34:39 +00:00
|
|
|
case ProblemSeverity::None:
|
2016-02-21 00:44:27 +00:00
|
|
|
ui->frame->clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &problems = patch->getProblems();
|
|
|
|
QString problemOut;
|
|
|
|
for (auto &problem: problems)
|
|
|
|
{
|
2017-07-29 06:43:34 +00:00
|
|
|
if(problem.m_severity == ProblemSeverity::Error)
|
2016-02-21 00:44:27 +00:00
|
|
|
{
|
|
|
|
problemOut += tr("Error: ");
|
|
|
|
}
|
2017-07-29 06:43:34 +00:00
|
|
|
else if(problem.m_severity == ProblemSeverity::Warning)
|
2016-02-21 00:44:27 +00:00
|
|
|
{
|
|
|
|
problemOut += tr("Warning: ");
|
|
|
|
}
|
2017-07-29 06:43:34 +00:00
|
|
|
problemOut += problem.m_description;
|
2016-02-21 00:44:27 +00:00
|
|
|
problemOut += "\n";
|
|
|
|
}
|
|
|
|
ui->frame->setModDescription(problemOut);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-01 22:49:53 +00:00
|
|
|
void VersionPage::updateVersionControls()
|
|
|
|
{
|
|
|
|
ui->forgeBtn->setEnabled(true);
|
|
|
|
ui->liteloaderBtn->setEnabled(true);
|
2015-05-17 21:38:28 +00:00
|
|
|
updateButtons();
|
2014-06-01 22:49:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::disableVersionControls()
|
|
|
|
{
|
|
|
|
ui->forgeBtn->setEnabled(false);
|
|
|
|
ui->liteloaderBtn->setEnabled(false);
|
2015-05-17 21:38:28 +00:00
|
|
|
ui->reloadBtn->setEnabled(false);
|
|
|
|
updateButtons();
|
2014-06-01 22:49:53 +00:00
|
|
|
}
|
|
|
|
|
2017-10-11 21:04:24 +00:00
|
|
|
bool VersionPage::reloadComponentList()
|
2014-06-01 22:49:53 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2017-11-11 00:38:31 +00:00
|
|
|
m_profile->reload(Net::Mode::Online);
|
2014-06-01 22:49:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-05-28 17:38:29 +00:00
|
|
|
catch (Exception &e)
|
2014-06-01 22:49:53 +00:00
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error"), e.cause());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
QMessageBox::critical(
|
|
|
|
this, tr("Error"),
|
2015-04-15 01:12:57 +00:00
|
|
|
tr("Couldn't load the instance profile."));
|
2014-06-01 22:49:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-17 21:38:28 +00:00
|
|
|
void VersionPage::on_reloadBtn_clicked()
|
2014-06-01 22:49:53 +00:00
|
|
|
{
|
2017-10-11 21:04:24 +00:00
|
|
|
reloadComponentList();
|
2016-11-06 23:18:27 +00:00
|
|
|
m_container->refreshContainer();
|
2014-06-01 22:49:53 +00:00
|
|
|
}
|
|
|
|
|
2015-05-17 21:38:28 +00:00
|
|
|
void VersionPage::on_removeBtn_clicked()
|
2014-06-01 22:49:53 +00:00
|
|
|
{
|
2015-05-17 21:38:28 +00:00
|
|
|
if (ui->packageView->currentIndex().isValid())
|
2014-06-01 22:49:53 +00:00
|
|
|
{
|
|
|
|
// FIXME: use actual model, not reloading.
|
2016-03-13 19:57:01 +00:00
|
|
|
if (!m_profile->remove(ui->packageView->currentIndex().row()))
|
2014-06-01 22:49:53 +00:00
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error"), tr("Couldn't remove file"));
|
|
|
|
}
|
|
|
|
}
|
2015-05-17 21:38:28 +00:00
|
|
|
updateButtons();
|
2017-10-11 21:04:24 +00:00
|
|
|
reloadComponentList();
|
2016-11-06 23:18:27 +00:00
|
|
|
m_container->refreshContainer();
|
2014-06-01 22:49:53 +00:00
|
|
|
}
|
|
|
|
|
2015-05-29 00:22:02 +00:00
|
|
|
void VersionPage::on_modBtn_clicked()
|
|
|
|
{
|
|
|
|
if(m_container)
|
|
|
|
{
|
|
|
|
m_container->selectPage("mods");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-01 22:49:53 +00:00
|
|
|
void VersionPage::on_jarmodBtn_clicked()
|
|
|
|
{
|
2015-09-09 21:53:33 +00:00
|
|
|
auto list = GuiUtil::BrowseForFiles("jarmod", tr("Select jar mods"), tr("Minecraft.jar mods (*.zip *.jar)"), MMC->settings()->get("CentralModsDir").toString(), this->parentWidget());
|
2015-05-04 22:42:04 +00:00
|
|
|
if(!list.empty())
|
2014-06-01 22:49:53 +00:00
|
|
|
{
|
2016-03-13 19:57:01 +00:00
|
|
|
m_profile->installJarMods(list);
|
2017-08-06 22:46:29 +00:00
|
|
|
}
|
|
|
|
updateButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::on_jarBtn_clicked()
|
|
|
|
{
|
|
|
|
auto jarPath = GuiUtil::BrowseForFile("jar", tr("Select jar"), tr("Minecraft.jar replacement (*.jar)"), MMC->settings()->get("CentralModsDir").toString(), this->parentWidget());
|
|
|
|
if(!jarPath.isEmpty())
|
|
|
|
{
|
|
|
|
m_profile->installCustomJar(jarPath);
|
2014-06-01 22:49:53 +00:00
|
|
|
}
|
2015-05-17 21:38:28 +00:00
|
|
|
updateButtons();
|
2014-06-01 22:49:53 +00:00
|
|
|
}
|
|
|
|
|
2015-05-17 21:38:28 +00:00
|
|
|
void VersionPage::on_moveUpBtn_clicked()
|
2014-06-01 22:49:53 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2017-10-11 21:04:24 +00:00
|
|
|
m_profile->move(currentRow(), ComponentList::MoveUp);
|
2014-06-01 22:49:53 +00:00
|
|
|
}
|
2015-05-28 17:38:29 +00:00
|
|
|
catch (Exception &e)
|
2014-06-01 22:49:53 +00:00
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error"), e.cause());
|
|
|
|
}
|
2015-05-17 21:38:28 +00:00
|
|
|
updateButtons();
|
2014-06-01 22:49:53 +00:00
|
|
|
}
|
|
|
|
|
2015-05-17 21:38:28 +00:00
|
|
|
void VersionPage::on_moveDownBtn_clicked()
|
2014-06-01 22:49:53 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2017-10-11 21:04:24 +00:00
|
|
|
m_profile->move(currentRow(), ComponentList::MoveDown);
|
2014-06-01 22:49:53 +00:00
|
|
|
}
|
2015-05-28 17:38:29 +00:00
|
|
|
catch (Exception &e)
|
2014-06-01 22:49:53 +00:00
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error"), e.cause());
|
|
|
|
}
|
2015-05-17 21:38:28 +00:00
|
|
|
updateButtons();
|
2014-06-01 22:49:53 +00:00
|
|
|
}
|
|
|
|
|
2015-05-17 21:38:28 +00:00
|
|
|
void VersionPage::on_changeVersionBtn_clicked()
|
2014-06-01 22:49:53 +00:00
|
|
|
{
|
2017-03-29 23:05:58 +00:00
|
|
|
auto versionRow = currentRow();
|
|
|
|
if(versionRow == -1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-11-11 00:38:31 +00:00
|
|
|
auto patch = m_profile->getComponent(versionRow);
|
2017-03-29 23:05:58 +00:00
|
|
|
auto name = patch->getName();
|
|
|
|
auto list = patch->getVersionList();
|
|
|
|
if(!list)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto uid = list->uid();
|
2017-12-04 23:40:45 +00:00
|
|
|
// 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;
|
|
|
|
}
|
2017-03-29 23:05:58 +00:00
|
|
|
VersionSelectDialog vselect(list.get(), tr("Change %1 version").arg(name), this);
|
2017-12-09 00:30:23 +00:00
|
|
|
auto currentVersion = patch->getVersion();
|
|
|
|
if(!currentVersion.isEmpty())
|
|
|
|
{
|
|
|
|
vselect.setCurrentVersion(currentVersion);
|
|
|
|
}
|
2014-06-01 22:49:53 +00:00
|
|
|
if (!vselect.exec() || !vselect.selectedVersion())
|
|
|
|
return;
|
|
|
|
|
2017-03-29 23:05:58 +00:00
|
|
|
qDebug() << "Change" << uid << "to" << vselect.selectedVersion()->descriptor();
|
2017-11-11 00:38:31 +00:00
|
|
|
bool important = false;
|
2017-03-29 23:05:58 +00:00
|
|
|
if(uid == "net.minecraft")
|
2014-06-01 22:49:53 +00:00
|
|
|
{
|
2017-11-11 00:38:31 +00:00
|
|
|
important = true;
|
2014-06-01 22:49:53 +00:00
|
|
|
}
|
2017-11-11 00:38:31 +00:00
|
|
|
m_profile->setComponentVersion(uid, vselect.selectedVersion()->descriptor(), important);
|
2018-01-05 03:26:46 +00:00
|
|
|
m_profile->resolve(Net::Mode::Online);
|
2016-11-06 23:18:27 +00:00
|
|
|
m_container->refreshContainer();
|
2015-05-28 07:36:58 +00:00
|
|
|
}
|
2014-06-01 22:49:53 +00:00
|
|
|
|
2018-01-05 03:26:46 +00:00
|
|
|
void VersionPage::on_downloadBtn_clicked()
|
2015-05-28 07:36:58 +00:00
|
|
|
{
|
2018-01-05 03:26:46 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-11-11 00:38:31 +00:00
|
|
|
auto updateTask = m_inst->createUpdateTask(Net::Mode::Online);
|
2014-06-01 22:49:53 +00:00
|
|
|
if (!updateTask)
|
|
|
|
{
|
2018-01-05 03:26:46 +00:00
|
|
|
return;
|
2014-06-01 22:49:53 +00:00
|
|
|
}
|
|
|
|
ProgressDialog tDialog(this);
|
|
|
|
connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString)));
|
2018-02-11 00:21:32 +00:00
|
|
|
// FIXME: unused return value
|
|
|
|
tDialog.execWithTask(updateTask.get());
|
2015-05-17 21:38:28 +00:00
|
|
|
updateButtons();
|
2016-11-06 23:18:27 +00:00
|
|
|
m_container->refreshContainer();
|
2014-06-01 22:49:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::on_forgeBtn_clicked()
|
|
|
|
{
|
2017-03-24 01:26:06 +00:00
|
|
|
auto vlist = ENV.metadataIndex()->get("net.minecraftforge");
|
2017-03-12 22:19:45 +00:00
|
|
|
if(!vlist)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
VersionSelectDialog vselect(vlist.get(), tr("Select Forge version"), this);
|
2017-11-11 00:38:31 +00:00
|
|
|
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"));
|
2015-05-02 21:42:33 +00:00
|
|
|
vselect.setEmptyErrorString(tr("Couldn't load or download the Forge version lists!"));
|
2017-12-09 00:30:23 +00:00
|
|
|
|
|
|
|
auto currentVersion = m_profile->getComponentVersion("net.minecraftforge");
|
|
|
|
if(!currentVersion.isEmpty())
|
|
|
|
{
|
|
|
|
vselect.setCurrentVersion(currentVersion);
|
|
|
|
}
|
|
|
|
|
2014-06-01 22:49:53 +00:00
|
|
|
if (vselect.exec() && vselect.selectedVersion())
|
|
|
|
{
|
2017-03-31 21:47:56 +00:00
|
|
|
auto vsn = vselect.selectedVersion();
|
2017-11-11 00:38:31 +00:00
|
|
|
m_profile->setComponentVersion("net.minecraftforge", vsn->descriptor());
|
|
|
|
m_profile->resolve(Net::Mode::Online);
|
2017-03-31 21:47:56 +00:00
|
|
|
// m_profile->installVersion();
|
2016-03-13 19:57:01 +00:00
|
|
|
preselect(m_profile->rowCount(QModelIndex())-1);
|
2016-11-06 23:18:27 +00:00
|
|
|
m_container->refreshContainer();
|
2014-06-01 22:49:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-31 00:37:50 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-01 22:49:53 +00:00
|
|
|
void VersionPage::on_liteloaderBtn_clicked()
|
|
|
|
{
|
2017-04-06 21:32:20 +00:00
|
|
|
auto vlist = ENV.metadataIndex()->get("com.mumfrey.liteloader");
|
2017-03-12 22:19:45 +00:00
|
|
|
if(!vlist)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
VersionSelectDialog vselect(vlist.get(), tr("Select LiteLoader version"), this);
|
2017-11-11 00:38:31 +00:00
|
|
|
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"));
|
2015-05-02 21:42:33 +00:00
|
|
|
vselect.setEmptyErrorString(tr("Couldn't load or download the LiteLoader version lists!"));
|
2017-12-09 00:30:23 +00:00
|
|
|
|
|
|
|
auto currentVersion = m_profile->getComponentVersion("com.mumfrey.liteloader");
|
|
|
|
if(!currentVersion.isEmpty())
|
|
|
|
{
|
|
|
|
vselect.setCurrentVersion(currentVersion);
|
|
|
|
}
|
|
|
|
|
2014-06-01 22:49:53 +00:00
|
|
|
if (vselect.exec() && vselect.selectedVersion())
|
|
|
|
{
|
2017-03-31 21:47:56 +00:00
|
|
|
auto vsn = vselect.selectedVersion();
|
2017-11-11 00:38:31 +00:00
|
|
|
m_profile->setComponentVersion("com.mumfrey.liteloader", vsn->descriptor());
|
|
|
|
m_profile->resolve(Net::Mode::Online);
|
2017-03-31 21:47:56 +00:00
|
|
|
// m_profile->installVersion(vselect.selectedVersion());
|
2016-03-13 19:57:01 +00:00
|
|
|
preselect(m_profile->rowCount(QModelIndex())-1);
|
2016-11-06 23:18:27 +00:00
|
|
|
m_container->refreshContainer();
|
2014-06-01 22:49:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::versionCurrent(const QModelIndex ¤t, const QModelIndex &previous)
|
|
|
|
{
|
2015-05-17 21:38:28 +00:00
|
|
|
currentIdx = current.row();
|
|
|
|
updateButtons(currentIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::preselect(int row)
|
|
|
|
{
|
|
|
|
if(row < 0)
|
2014-06-01 22:49:53 +00:00
|
|
|
{
|
2015-05-17 21:38:28 +00:00
|
|
|
row = 0;
|
2014-06-01 22:49:53 +00:00
|
|
|
}
|
2016-03-13 19:57:01 +00:00
|
|
|
if(row >= m_profile->rowCount(QModelIndex()))
|
2014-06-01 22:49:53 +00:00
|
|
|
{
|
2016-03-13 19:57:01 +00:00
|
|
|
row = m_profile->rowCount(QModelIndex()) - 1;
|
2015-05-17 21:38:28 +00:00
|
|
|
}
|
|
|
|
if(row < 0)
|
|
|
|
{
|
|
|
|
return;
|
2014-06-01 22:49:53 +00:00
|
|
|
}
|
2016-03-13 19:57:01 +00:00
|
|
|
auto model_index = m_profile->index(row);
|
2015-05-17 21:38:28 +00:00
|
|
|
ui->packageView->selectionModel()->select(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
|
|
|
|
updateButtons(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::updateButtons(int row)
|
|
|
|
{
|
|
|
|
if(row == -1)
|
|
|
|
row = currentRow();
|
2017-11-11 00:38:31 +00:00
|
|
|
auto patch = m_profile->getComponent(row);
|
2015-05-17 21:38:28 +00:00
|
|
|
if (!patch)
|
2014-06-08 17:01:19 +00:00
|
|
|
{
|
2015-05-17 21:38:28 +00:00
|
|
|
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 17:01:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-17 21:38:28 +00:00
|
|
|
ui->removeBtn->setEnabled(patch->isRemovable());
|
|
|
|
ui->moveDownBtn->setEnabled(patch->isMoveable());
|
|
|
|
ui->moveUpBtn->setEnabled(patch->isMoveable());
|
|
|
|
ui->changeVersionBtn->setEnabled(patch->isVersionChangeable());
|
2017-03-27 01:34:39 +00:00
|
|
|
ui->editBtn->setEnabled(patch->isCustom());
|
2017-04-08 20:04:07 +00:00
|
|
|
ui->customizeBtn->setEnabled(patch->isCustomizable());
|
2015-05-17 21:38:28 +00:00
|
|
|
ui->revertBtn->setEnabled(patch->isRevertible());
|
2014-06-08 17:01:19 +00:00
|
|
|
}
|
2014-06-01 22:49:53 +00:00
|
|
|
}
|
2015-04-08 11:50:21 +00:00
|
|
|
|
|
|
|
void VersionPage::onGameUpdateError(QString error)
|
|
|
|
{
|
|
|
|
CustomMessageBox::selectable(this, tr("Error updating instance"), error,
|
|
|
|
QMessageBox::Warning)->show();
|
|
|
|
}
|
2015-05-17 21:38:28 +00:00
|
|
|
|
2017-12-28 23:35:10 +00:00
|
|
|
Component * VersionPage::current()
|
2015-05-17 21:38:28 +00:00
|
|
|
{
|
|
|
|
auto row = currentRow();
|
|
|
|
if(row < 0)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-11-11 00:38:31 +00:00
|
|
|
return m_profile->getComponent(row);
|
2015-05-17 21:38:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2017-11-11 00:38:31 +00:00
|
|
|
auto patch = m_profile->getComponent(version);
|
2017-03-19 22:58:54 +00:00
|
|
|
if(!patch->getVersionFile())
|
2015-05-28 07:36:58 +00:00
|
|
|
{
|
2017-03-19 22:58:54 +00:00
|
|
|
// TODO: wait for the update task to finish here...
|
|
|
|
return;
|
2015-05-28 07:36:58 +00:00
|
|
|
}
|
2016-03-13 19:57:01 +00:00
|
|
|
if(!m_profile->customize(version))
|
2015-05-17 21:38:28 +00:00
|
|
|
{
|
|
|
|
// TODO: some error box here
|
|
|
|
}
|
|
|
|
updateButtons();
|
|
|
|
preselect(currentIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::on_editBtn_clicked()
|
|
|
|
{
|
|
|
|
auto version = current();
|
|
|
|
if(!version)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-03-12 23:23:45 +00:00
|
|
|
auto filename = version->getFilename();
|
2015-05-17 21:38:28 +00:00
|
|
|
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;
|
|
|
|
}
|
2016-03-13 19:57:01 +00:00
|
|
|
if(!m_profile->revertToBase(version))
|
2015-05-17 21:38:28 +00:00
|
|
|
{
|
|
|
|
// TODO: some error box here
|
|
|
|
}
|
|
|
|
updateButtons();
|
|
|
|
preselect(currentIdx);
|
2016-11-06 23:18:27 +00:00
|
|
|
m_container->refreshContainer();
|
2015-05-17 21:38:28 +00:00
|
|
|
}
|
2016-02-21 00:44:27 +00:00
|
|
|
|
|
|
|
#include "VersionPage.moc"
|
2017-07-24 07:01:37 +00:00
|
|
|
|