2015-02-02 22:25:30 +00:00
|
|
|
/* Copyright 2013-2015 MultiMC Contributors
|
2014-06-01 23:49:53 +01: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 <pathutils.h>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QEvent>
|
|
|
|
#include <QKeyEvent>
|
|
|
|
|
|
|
|
#include "VersionPage.h"
|
|
|
|
#include "ui_VersionPage.h"
|
|
|
|
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "Platform.h"
|
|
|
|
#include "dialogs/CustomMessageBox.h"
|
|
|
|
#include "dialogs/VersionSelectDialog.h"
|
|
|
|
#include "dialogs/ModEditDialogCommon.h"
|
2014-06-01 23:49:53 +01:00
|
|
|
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "dialogs/ProgressDialog.h"
|
2015-05-04 23:42:04 +01:00
|
|
|
#include <GuiUtil.h>
|
2014-06-01 23:49:53 +01:00
|
|
|
|
2014-07-12 22:02:52 +01:00
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QListView>
|
|
|
|
#include <QString>
|
|
|
|
#include <QUrl>
|
|
|
|
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "minecraft/MinecraftProfile.h"
|
|
|
|
#include "forge/ForgeVersionList.h"
|
|
|
|
#include "forge/ForgeInstaller.h"
|
|
|
|
#include "liteloader/LiteLoaderVersionList.h"
|
|
|
|
#include "liteloader/LiteLoaderInstaller.h"
|
|
|
|
#include "auth/MojangAccountList.h"
|
|
|
|
#include "minecraft/Mod.h"
|
|
|
|
#include "icons/IconList.h"
|
2014-06-01 23:49:53 +01:00
|
|
|
|
|
|
|
|
2014-07-12 16:58:23 +01:00
|
|
|
QIcon VersionPage::icon() const
|
2014-06-01 23:49:53 +01:00
|
|
|
{
|
2015-02-01 10:44:47 +00:00
|
|
|
return ENV.icons()->getIcon(m_inst->iconKey());
|
2014-06-01 23:49:53 +01:00
|
|
|
}
|
2014-07-12 16:58:23 +01:00
|
|
|
bool VersionPage::shouldDisplay() const
|
2014-06-30 01:02:57 +01:00
|
|
|
{
|
|
|
|
return !m_inst->isRunning();
|
|
|
|
}
|
|
|
|
|
2014-06-01 23:49:53 +01:00
|
|
|
VersionPage::VersionPage(OneSixInstance *inst, QWidget *parent)
|
|
|
|
: QWidget(parent), ui(new Ui::VersionPage), m_inst(inst)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2014-07-20 23:10:13 +01:00
|
|
|
ui->tabWidget->tabBar()->hide();
|
2014-06-01 23:49:53 +01:00
|
|
|
|
2015-04-15 02:12:57 +01:00
|
|
|
reloadMinecraftProfile();
|
|
|
|
|
2015-01-27 21:31:07 +00:00
|
|
|
m_version = m_inst->getMinecraftProfile();
|
2014-06-01 23:49:53 +01:00
|
|
|
if (m_version)
|
|
|
|
{
|
2015-05-17 22:38:28 +01:00
|
|
|
ui->packageView->setModel(m_version.get());
|
|
|
|
ui->packageView->installEventFilter(this);
|
|
|
|
ui->packageView->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
connect(ui->packageView->selectionModel(), &QItemSelectionModel::currentChanged,
|
2014-06-01 23:49:53 +01:00
|
|
|
this, &VersionPage::versionCurrent);
|
|
|
|
updateVersionControls();
|
2014-06-10 07:39:11 +01:00
|
|
|
// select first item.
|
2015-05-17 22:38:28 +01:00
|
|
|
preselect(0);
|
2014-06-01 23:49:53 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
disableVersionControls();
|
|
|
|
}
|
|
|
|
connect(m_inst, &OneSixInstance::versionReloaded, this,
|
|
|
|
&VersionPage::updateVersionControls);
|
|
|
|
}
|
|
|
|
|
|
|
|
VersionPage::~VersionPage()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::updateVersionControls()
|
|
|
|
{
|
|
|
|
ui->forgeBtn->setEnabled(true);
|
|
|
|
ui->liteloaderBtn->setEnabled(true);
|
2015-05-17 22:38:28 +01:00
|
|
|
updateButtons();
|
2014-06-01 23:49:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::disableVersionControls()
|
|
|
|
{
|
|
|
|
ui->forgeBtn->setEnabled(false);
|
|
|
|
ui->liteloaderBtn->setEnabled(false);
|
2015-05-17 22:38:28 +01:00
|
|
|
ui->reloadBtn->setEnabled(false);
|
|
|
|
updateButtons();
|
2014-06-01 23:49:53 +01:00
|
|
|
}
|
|
|
|
|
2015-01-27 21:31:07 +00:00
|
|
|
bool VersionPage::reloadMinecraftProfile()
|
2014-06-01 23:49:53 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-01-27 21:31:07 +00:00
|
|
|
m_inst->reloadProfile();
|
2014-06-01 23:49:53 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (MMCError &e)
|
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error"), e.cause());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
QMessageBox::critical(
|
|
|
|
this, tr("Error"),
|
2015-04-15 02:12:57 +01:00
|
|
|
tr("Couldn't load the instance profile."));
|
2014-06-01 23:49:53 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-17 22:38:28 +01:00
|
|
|
void VersionPage::on_reloadBtn_clicked()
|
2014-06-01 23:49:53 +01:00
|
|
|
{
|
2015-01-27 21:31:07 +00:00
|
|
|
reloadMinecraftProfile();
|
2014-06-01 23:49:53 +01:00
|
|
|
}
|
|
|
|
|
2015-05-17 22:38:28 +01:00
|
|
|
void VersionPage::on_removeBtn_clicked()
|
2014-06-01 23:49:53 +01:00
|
|
|
{
|
2015-05-17 22:38:28 +01:00
|
|
|
if (ui->packageView->currentIndex().isValid())
|
2014-06-01 23:49:53 +01:00
|
|
|
{
|
|
|
|
// FIXME: use actual model, not reloading.
|
2015-05-17 22:38:28 +01:00
|
|
|
if (!m_version->remove(ui->packageView->currentIndex().row()))
|
2014-06-01 23:49:53 +01:00
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error"), tr("Couldn't remove file"));
|
|
|
|
}
|
|
|
|
}
|
2015-05-17 22:38:28 +01:00
|
|
|
updateButtons();
|
2014-06-01 23:49:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::on_jarmodBtn_clicked()
|
|
|
|
{
|
2015-05-04 23:42:04 +01:00
|
|
|
auto list = GuiUtil::BrowseForMods("jarmod", tr("Select jar mods"), tr("Minecraft.jar mods (*.zip *.jar)"), this->parentWidget());
|
|
|
|
if(!list.empty())
|
2014-06-01 23:49:53 +01:00
|
|
|
{
|
2015-05-04 23:42:04 +01:00
|
|
|
m_version->installJarMods(list);
|
2014-06-01 23:49:53 +01:00
|
|
|
}
|
2015-05-17 22:38:28 +01:00
|
|
|
updateButtons();
|
2014-06-01 23:49:53 +01:00
|
|
|
}
|
|
|
|
|
2015-05-17 22:38:28 +01:00
|
|
|
void VersionPage::on_resetOrderBtn_clicked()
|
2014-06-01 23:49:53 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
m_version->resetOrder();
|
|
|
|
}
|
|
|
|
catch (MMCError &e)
|
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error"), e.cause());
|
|
|
|
}
|
2015-05-17 22:38:28 +01:00
|
|
|
updateButtons();
|
2014-06-01 23:49:53 +01:00
|
|
|
}
|
|
|
|
|
2015-05-17 22:38:28 +01:00
|
|
|
void VersionPage::on_moveUpBtn_clicked()
|
2014-06-01 23:49:53 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-05-17 22:38:28 +01:00
|
|
|
m_version->move(currentRow(), MinecraftProfile::MoveUp);
|
2014-06-01 23:49:53 +01:00
|
|
|
}
|
|
|
|
catch (MMCError &e)
|
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error"), e.cause());
|
|
|
|
}
|
2015-05-17 22:38:28 +01:00
|
|
|
updateButtons();
|
2014-06-01 23:49:53 +01:00
|
|
|
}
|
|
|
|
|
2015-05-17 22:38:28 +01:00
|
|
|
void VersionPage::on_moveDownBtn_clicked()
|
2014-06-01 23:49:53 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-05-17 22:38:28 +01:00
|
|
|
m_version->move(currentRow(), MinecraftProfile::MoveDown);
|
2014-06-01 23:49:53 +01:00
|
|
|
}
|
|
|
|
catch (MMCError &e)
|
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error"), e.cause());
|
|
|
|
}
|
2015-05-17 22:38:28 +01:00
|
|
|
updateButtons();
|
2014-06-01 23:49:53 +01:00
|
|
|
}
|
|
|
|
|
2015-05-17 22:38:28 +01:00
|
|
|
void VersionPage::on_changeVersionBtn_clicked()
|
2014-06-01 23:49:53 +01:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-01-27 21:31:07 +00:00
|
|
|
if (!m_version->isVanilla())
|
2014-06-01 23:49:53 +01:00
|
|
|
{
|
|
|
|
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_version->revertToVanilla();
|
2015-01-27 21:31:07 +00:00
|
|
|
reloadMinecraftProfile();
|
2014-06-01 23:49:53 +01:00
|
|
|
}
|
|
|
|
m_inst->setIntendedVersionId(vselect.selectedVersion()->descriptor());
|
|
|
|
|
|
|
|
auto updateTask = m_inst->doUpdate();
|
|
|
|
if (!updateTask)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ProgressDialog tDialog(this);
|
|
|
|
connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString)));
|
|
|
|
tDialog.exec(updateTask.get());
|
2015-05-17 22:38:28 +01:00
|
|
|
updateButtons();
|
2014-06-01 23:49:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::on_forgeBtn_clicked()
|
|
|
|
{
|
|
|
|
VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this);
|
2015-04-28 08:01:37 +01:00
|
|
|
vselect.setExactFilter(BaseVersionList::ParentGameVersionRole, m_inst->currentVersionId());
|
2014-06-01 23:49:53 +01:00
|
|
|
vselect.setEmptyString(tr("No Forge versions are currently available for Minecraft ") +
|
|
|
|
m_inst->currentVersionId());
|
2015-05-02 22:42:33 +01:00
|
|
|
vselect.setEmptyErrorString(tr("Couldn't load or download the Forge version lists!"));
|
2014-06-01 23:49:53 +01:00
|
|
|
if (vselect.exec() && vselect.selectedVersion())
|
|
|
|
{
|
|
|
|
ProgressDialog dialog(this);
|
|
|
|
dialog.exec(
|
|
|
|
ForgeInstaller().createInstallTask(m_inst, vselect.selectedVersion(), this));
|
2015-05-17 22:38:28 +01:00
|
|
|
preselect(m_version->rowCount(QModelIndex())-1);
|
2014-06-01 23:49:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::on_liteloaderBtn_clicked()
|
|
|
|
{
|
|
|
|
VersionSelectDialog vselect(MMC->liteloaderlist().get(), tr("Select LiteLoader version"),
|
|
|
|
this);
|
2015-04-28 08:01:37 +01:00
|
|
|
vselect.setExactFilter(BaseVersionList::ParentGameVersionRole, m_inst->currentVersionId());
|
2014-06-01 23:49:53 +01:00
|
|
|
vselect.setEmptyString(tr("No LiteLoader versions are currently available for Minecraft ") +
|
|
|
|
m_inst->currentVersionId());
|
2015-05-02 22:42:33 +01:00
|
|
|
vselect.setEmptyErrorString(tr("Couldn't load or download the LiteLoader version lists!"));
|
2014-06-01 23:49:53 +01:00
|
|
|
if (vselect.exec() && vselect.selectedVersion())
|
|
|
|
{
|
|
|
|
ProgressDialog dialog(this);
|
|
|
|
dialog.exec(
|
|
|
|
LiteLoaderInstaller().createInstallTask(m_inst, vselect.selectedVersion(), this));
|
2015-05-17 22:38:28 +01:00
|
|
|
preselect(m_version->rowCount(QModelIndex())-1);
|
2014-06-01 23:49:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::versionCurrent(const QModelIndex ¤t, const QModelIndex &previous)
|
|
|
|
{
|
2015-05-17 22:38:28 +01:00
|
|
|
currentIdx = current.row();
|
|
|
|
updateButtons(currentIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::preselect(int row)
|
|
|
|
{
|
|
|
|
if(row < 0)
|
2014-06-01 23:49:53 +01:00
|
|
|
{
|
2015-05-17 22:38:28 +01:00
|
|
|
row = 0;
|
2014-06-01 23:49:53 +01:00
|
|
|
}
|
2015-05-17 22:38:28 +01:00
|
|
|
if(row >= m_version->rowCount(QModelIndex()))
|
2014-06-01 23:49:53 +01:00
|
|
|
{
|
2015-05-17 22:38:28 +01:00
|
|
|
row = m_version->rowCount(QModelIndex()) - 1;
|
|
|
|
}
|
|
|
|
if(row < 0)
|
|
|
|
{
|
|
|
|
return;
|
2014-06-01 23:49:53 +01:00
|
|
|
}
|
2015-05-17 22:38:28 +01:00
|
|
|
auto model_index = m_version->index(row);
|
|
|
|
ui->packageView->selectionModel()->select(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
|
|
|
|
updateButtons(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::updateButtons(int row)
|
|
|
|
{
|
|
|
|
if(row == -1)
|
|
|
|
row = currentRow();
|
|
|
|
auto patch = m_version->versionPatch(row);
|
|
|
|
if (!patch)
|
2014-06-08 18:01:19 +01:00
|
|
|
{
|
2015-05-17 22:38:28 +01: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 18:01:19 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-17 22:38:28 +01:00
|
|
|
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 18:01:19 +01:00
|
|
|
}
|
2014-06-01 23:49:53 +01:00
|
|
|
}
|
2015-04-08 12:50:21 +01:00
|
|
|
|
|
|
|
void VersionPage::onGameUpdateError(QString error)
|
|
|
|
{
|
|
|
|
CustomMessageBox::selectable(this, tr("Error updating instance"), error,
|
|
|
|
QMessageBox::Warning)->show();
|
|
|
|
}
|
2015-05-17 22:38:28 +01:00
|
|
|
|
|
|
|
ProfilePatchPtr VersionPage::current()
|
|
|
|
{
|
|
|
|
auto row = currentRow();
|
|
|
|
if(row < 0)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return m_version->versionPatch(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
if(!m_version->customize(version))
|
|
|
|
{
|
|
|
|
// TODO: some error box here
|
|
|
|
}
|
|
|
|
updateButtons();
|
|
|
|
preselect(currentIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::on_editBtn_clicked()
|
|
|
|
{
|
|
|
|
auto version = current();
|
|
|
|
if(!version)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto filename = version->getPatchFilename();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
if(!m_version->revert(version))
|
|
|
|
{
|
|
|
|
// TODO: some error box here
|
|
|
|
}
|
|
|
|
updateButtons();
|
|
|
|
preselect(currentIdx);
|
|
|
|
}
|