2022-03-21 00:31:08 +05:30
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
|
|
|
* PolyMC - Minecraft Launcher
|
|
|
|
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
2022-03-27 16:43:32 +05:30
|
|
|
* Copyright (c) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
2014-06-02 04:19:53 +05:30
|
|
|
*
|
2022-03-21 00:31:08 +05:30
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 3.
|
2014-06-02 04:19:53 +05:30
|
|
|
*
|
2022-03-21 00:31:08 +05:30
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2014-06-02 04:19:53 +05:30
|
|
|
*
|
2022-03-21 00:31:08 +05:30
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following copyright and
|
|
|
|
* permission notice:
|
|
|
|
*
|
|
|
|
* Copyright 2013-2021 MultiMC Contributors
|
|
|
|
*
|
|
|
|
* 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.
|
2014-06-02 04:19:53 +05:30
|
|
|
*/
|
|
|
|
|
2021-11-20 20:52:22 +05:30
|
|
|
#include "Application.h"
|
2014-06-02 04:19:53 +05:30
|
|
|
|
|
|
|
#include <QMessageBox>
|
2019-07-14 09:07:10 +05:30
|
|
|
#include <QLabel>
|
2014-06-02 04:19:53 +05:30
|
|
|
#include <QEvent>
|
|
|
|
#include <QKeyEvent>
|
2019-07-14 09:07:10 +05:30
|
|
|
#include <QMenu>
|
2014-07-13 02:32:52 +05:30
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QListView>
|
|
|
|
#include <QString>
|
|
|
|
#include <QUrl>
|
|
|
|
|
2021-11-22 08:25:16 +05:30
|
|
|
#include "VersionPage.h"
|
|
|
|
#include "ui_VersionPage.h"
|
|
|
|
|
|
|
|
#include "ui/dialogs/CustomMessageBox.h"
|
|
|
|
#include "ui/dialogs/VersionSelectDialog.h"
|
|
|
|
#include "ui/dialogs/NewComponentDialog.h"
|
|
|
|
#include "ui/dialogs/ProgressDialog.h"
|
|
|
|
|
|
|
|
#include "ui/GuiUtil.h"
|
|
|
|
|
2020-06-27 15:32:31 +05:30
|
|
|
#include "minecraft/PackProfile.h"
|
2021-07-27 01:14:11 +05:30
|
|
|
#include "minecraft/auth/AccountList.h"
|
2019-08-04 06:57:53 +05:30
|
|
|
#include "minecraft/mod/Mod.h"
|
2015-02-09 06:21:14 +05:30
|
|
|
#include "icons/IconList.h"
|
2015-05-28 23:08:29 +05:30
|
|
|
#include "Exception.h"
|
2019-07-11 02:00:42 +05:30
|
|
|
#include "Version.h"
|
2020-01-09 18:15:46 +05:30
|
|
|
#include "DesktopServices.h"
|
2014-06-02 04:19:53 +05:30
|
|
|
|
2021-11-22 08:25:16 +05:30
|
|
|
#include "meta/Index.h"
|
|
|
|
#include "meta/VersionList.h"
|
2017-03-24 06:56:06 +05:30
|
|
|
|
2016-02-21 06:14:27 +05:30
|
|
|
class IconProxy : public QIdentityProxyModel
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
Q_OBJECT
|
2016-02-21 06:14:27 +05:30
|
|
|
public:
|
2017-07-24 12:31:37 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
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
|
|
|
|
{
|
2020-05-17 23:26:59 +05:30
|
|
|
QVariant var = QIdentityProxyModel::data(proxyIndex, role);
|
2018-07-15 18:21:05 +05:30
|
|
|
int column = proxyIndex.column();
|
|
|
|
if(column == 0 && role == Qt::DecorationRole && m_parentWidget)
|
|
|
|
{
|
|
|
|
if(!var.isNull())
|
|
|
|
{
|
|
|
|
auto string = var.toString();
|
|
|
|
if(string == "warning")
|
|
|
|
{
|
2021-11-20 20:52:22 +05:30
|
|
|
return APPLICATION->getThemedIcon("status-yellow");
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
|
|
|
else if(string == "error")
|
|
|
|
{
|
2021-11-20 20:52:22 +05:30
|
|
|
return APPLICATION->getThemedIcon("status-bad");
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
|
|
|
}
|
2021-11-20 20:52:22 +05:30
|
|
|
return APPLICATION->getThemedIcon("status-good");
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
|
|
|
return var;
|
|
|
|
}
|
2016-02-21 06:14:27 +05:30
|
|
|
private slots:
|
2018-07-15 18:21:05 +05:30
|
|
|
void widgetGone()
|
|
|
|
{
|
|
|
|
m_parentWidget = nullptr;
|
|
|
|
}
|
2016-02-21 06:14:27 +05:30
|
|
|
|
|
|
|
private:
|
2018-07-15 18:21:05 +05:30
|
|
|
QWidget *m_parentWidget = nullptr;
|
2016-02-21 06:14:27 +05:30
|
|
|
};
|
|
|
|
|
2014-07-12 21:28:23 +05:30
|
|
|
QIcon VersionPage::icon() const
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
2021-11-20 20:52:22 +05:30
|
|
|
return APPLICATION->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
|
|
|
{
|
2019-07-16 02:46:34 +05:30
|
|
|
return true;
|
2014-06-30 05:32:57 +05:30
|
|
|
}
|
|
|
|
|
2022-02-22 23:53:53 +05:30
|
|
|
void VersionPage::retranslate()
|
|
|
|
{
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
}
|
|
|
|
|
2019-07-14 09:07:10 +05:30
|
|
|
QMenu * VersionPage::createPopupMenu()
|
|
|
|
{
|
|
|
|
QMenu* filteredMenu = QMainWindow::createPopupMenu();
|
|
|
|
filteredMenu->removeAction( ui->toolBar->toggleViewAction() );
|
|
|
|
return filteredMenu;
|
|
|
|
}
|
|
|
|
|
2017-07-24 12:31:37 +05:30
|
|
|
VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent)
|
2019-07-14 09:07:10 +05:30
|
|
|
: QMainWindow(parent), ui(new Ui::VersionPage), m_inst(inst)
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
ui->setupUi(this);
|
2019-07-17 05:31:29 +05:30
|
|
|
|
2019-07-23 04:18:14 +05:30
|
|
|
ui->toolBar->insertSpacer(ui->actionReload);
|
2019-07-14 09:07:10 +05:30
|
|
|
|
2020-06-27 15:32:31 +05:30
|
|
|
m_profile = m_inst->getPackProfile();
|
2018-07-15 18:21:05 +05:30
|
|
|
|
2020-06-27 15:32:31 +05:30
|
|
|
reloadPackProfile();
|
2018-07-15 18:21:05 +05:30
|
|
|
|
2019-07-11 04:31:47 +05:30
|
|
|
auto proxy = new IconProxy(ui->packageView);
|
|
|
|
proxy->setSourceModel(m_profile.get());
|
2021-06-19 03:51:12 +05:30
|
|
|
|
|
|
|
m_filterModel = new QSortFilterProxyModel();
|
|
|
|
m_filterModel->setDynamicSortFilter(true);
|
|
|
|
m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
m_filterModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
m_filterModel->setSourceModel(proxy);
|
|
|
|
m_filterModel->setFilterKeyColumn(-1);
|
|
|
|
|
|
|
|
ui->packageView->setModel(m_filterModel);
|
2019-07-11 04:31:47 +05:30
|
|
|
ui->packageView->installEventFilter(this);
|
|
|
|
ui->packageView->setSelectionMode(QAbstractItemView::SingleSelection);
|
2019-07-25 04:32:30 +05:30
|
|
|
ui->packageView->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
2019-07-11 04:31:47 +05:30
|
|
|
connect(ui->packageView->selectionModel(), &QItemSelectionModel::currentChanged, this, &VersionPage::versionCurrent);
|
|
|
|
auto smodel = ui->packageView->selectionModel();
|
|
|
|
connect(smodel, &QItemSelectionModel::currentChanged, this, &VersionPage::packageCurrent);
|
|
|
|
|
2020-06-27 15:32:31 +05:30
|
|
|
connect(m_profile.get(), &PackProfile::minecraftChanged, this, &VersionPage::updateVersionControls);
|
2019-07-16 02:46:34 +05:30
|
|
|
controlsEnabled = !m_inst->isRunning();
|
2019-07-11 04:31:47 +05:30
|
|
|
updateVersionControls();
|
|
|
|
preselect(0);
|
2019-07-16 02:46:34 +05:30
|
|
|
connect(m_inst, &BaseInstance::runningStatusChanged, this, &VersionPage::updateRunningStatus);
|
2021-06-19 03:51:12 +05:30
|
|
|
connect(ui->packageView, &ModListView::customContextMenuRequested, this, &VersionPage::showContextMenu);
|
|
|
|
connect(ui->filterEdit, &QLineEdit::textChanged, this, &VersionPage::onFilterTextChanged);
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
VersionPage::~VersionPage()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
delete ui;
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
|
2021-06-19 03:51:12 +05:30
|
|
|
void VersionPage::showContextMenu(const QPoint& pos)
|
2019-07-25 04:32:30 +05:30
|
|
|
{
|
|
|
|
auto menu = ui->toolBar->createContextMenu(this, tr("Context menu"));
|
|
|
|
menu->exec(ui->packageView->mapToGlobal(pos));
|
|
|
|
delete menu;
|
|
|
|
}
|
|
|
|
|
2016-02-21 06:14:27 +05:30
|
|
|
void VersionPage::packageCurrent(const QModelIndex ¤t, const QModelIndex &previous)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if (!current.isValid())
|
|
|
|
{
|
|
|
|
ui->frame->clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int row = current.row();
|
|
|
|
auto patch = m_profile->getComponent(row);
|
|
|
|
auto severity = patch->getProblemSeverity();
|
|
|
|
switch(severity)
|
|
|
|
{
|
|
|
|
case ProblemSeverity::Warning:
|
|
|
|
ui->frame->setModText(tr("%1 possibly has issues.").arg(patch->getName()));
|
|
|
|
break;
|
|
|
|
case ProblemSeverity::Error:
|
|
|
|
ui->frame->setModText(tr("%1 has issues!").arg(patch->getName()));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case ProblemSeverity::None:
|
|
|
|
ui->frame->clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &problems = patch->getProblems();
|
|
|
|
QString problemOut;
|
|
|
|
for (auto &problem: problems)
|
|
|
|
{
|
|
|
|
if(problem.m_severity == ProblemSeverity::Error)
|
|
|
|
{
|
|
|
|
problemOut += tr("Error: ");
|
|
|
|
}
|
|
|
|
else if(problem.m_severity == ProblemSeverity::Warning)
|
|
|
|
{
|
|
|
|
problemOut += tr("Warning: ");
|
|
|
|
}
|
|
|
|
problemOut += problem.m_description;
|
|
|
|
problemOut += "\n";
|
|
|
|
}
|
|
|
|
ui->frame->setModDescription(problemOut);
|
2016-02-21 06:14:27 +05:30
|
|
|
}
|
|
|
|
|
2019-07-16 02:46:34 +05:30
|
|
|
void VersionPage::updateRunningStatus(bool running)
|
|
|
|
{
|
|
|
|
if(controlsEnabled == running) {
|
|
|
|
controlsEnabled = !running;
|
|
|
|
updateVersionControls();
|
|
|
|
}
|
|
|
|
}
|
2016-02-21 06:14:27 +05:30
|
|
|
|
2014-06-02 04:19:53 +05:30
|
|
|
void VersionPage::updateVersionControls()
|
|
|
|
{
|
2019-07-11 02:00:42 +05:30
|
|
|
// FIXME: this is a dirty hack
|
2019-07-16 02:46:34 +05:30
|
|
|
auto minecraftVersion = Version(m_profile->getComponentVersion("net.minecraft"));
|
2021-06-30 19:22:00 +05:30
|
|
|
|
2022-03-20 20:05:35 +05:30
|
|
|
ui->actionInstall_Forge->setEnabled(controlsEnabled);
|
|
|
|
|
2021-06-30 19:22:00 +05:30
|
|
|
bool supportsFabric = minecraftVersion >= Version("1.14");
|
|
|
|
ui->actionInstall_Fabric->setEnabled(controlsEnabled && supportsFabric);
|
|
|
|
|
|
|
|
bool supportsLiteLoader = minecraftVersion <= Version("1.12.2");
|
|
|
|
ui->actionInstall_LiteLoader->setEnabled(controlsEnabled && supportsLiteLoader);
|
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
updateButtons();
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
|
2019-07-16 02:46:34 +05:30
|
|
|
void VersionPage::updateButtons(int row)
|
|
|
|
{
|
|
|
|
if(row == -1)
|
|
|
|
row = currentRow();
|
|
|
|
auto patch = m_profile->getComponent(row);
|
|
|
|
ui->actionRemove->setEnabled(controlsEnabled && patch && patch->isRemovable());
|
|
|
|
ui->actionMove_down->setEnabled(controlsEnabled && patch && patch->isMoveable());
|
|
|
|
ui->actionMove_up->setEnabled(controlsEnabled && patch && patch->isMoveable());
|
|
|
|
ui->actionChange_version->setEnabled(controlsEnabled && patch && patch->isVersionChangeable());
|
|
|
|
ui->actionEdit->setEnabled(controlsEnabled && patch && patch->isCustom());
|
|
|
|
ui->actionCustomize->setEnabled(controlsEnabled && patch && patch->isCustomizable());
|
|
|
|
ui->actionRevert->setEnabled(controlsEnabled && patch && patch->isRevertible());
|
|
|
|
ui->actionDownload_All->setEnabled(controlsEnabled);
|
|
|
|
ui->actionAdd_Empty->setEnabled(controlsEnabled);
|
|
|
|
ui->actionReload->setEnabled(controlsEnabled);
|
|
|
|
ui->actionInstall_mods->setEnabled(controlsEnabled);
|
|
|
|
ui->actionReplace_Minecraft_jar->setEnabled(controlsEnabled);
|
|
|
|
ui->actionAdd_to_Minecraft_jar->setEnabled(controlsEnabled);
|
|
|
|
}
|
|
|
|
|
2020-06-27 15:32:31 +05:30
|
|
|
bool VersionPage::reloadPackProfile()
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
try
|
|
|
|
{
|
|
|
|
m_profile->reload(Net::Mode::Online);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (const Exception &e)
|
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error"), e.cause());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
QMessageBox::critical(
|
|
|
|
this, tr("Error"),
|
|
|
|
tr("Couldn't load the instance profile."));
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
|
2019-07-14 09:07:10 +05:30
|
|
|
void VersionPage::on_actionReload_triggered()
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
2020-06-27 15:32:31 +05:30
|
|
|
reloadPackProfile();
|
2018-07-15 18:21:05 +05:30
|
|
|
m_container->refreshContainer();
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
|
2019-07-14 09:07:10 +05:30
|
|
|
void VersionPage::on_actionRemove_triggered()
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if (ui->packageView->currentIndex().isValid())
|
|
|
|
{
|
|
|
|
// FIXME: use actual model, not reloading.
|
|
|
|
if (!m_profile->remove(ui->packageView->currentIndex().row()))
|
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error"), tr("Couldn't remove file"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateButtons();
|
2020-06-27 15:32:31 +05:30
|
|
|
reloadPackProfile();
|
2018-07-15 18:21:05 +05:30
|
|
|
m_container->refreshContainer();
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
|
2019-07-14 09:07:10 +05:30
|
|
|
void VersionPage::on_actionInstall_mods_triggered()
|
2015-05-29 05:52:02 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if(m_container)
|
|
|
|
{
|
|
|
|
m_container->selectPage("mods");
|
|
|
|
}
|
2015-05-29 05:52:02 +05:30
|
|
|
}
|
|
|
|
|
2019-07-14 09:07:10 +05:30
|
|
|
void VersionPage::on_actionAdd_to_Minecraft_jar_triggered()
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
2021-11-20 20:52:22 +05:30
|
|
|
auto list = GuiUtil::BrowseForFiles("jarmod", tr("Select jar mods"), tr("Minecraft.jar mods (*.zip *.jar)"), APPLICATION->settings()->get("CentralModsDir").toString(), this->parentWidget());
|
2018-07-15 18:21:05 +05:30
|
|
|
if(!list.empty())
|
|
|
|
{
|
|
|
|
m_profile->installJarMods(list);
|
|
|
|
}
|
|
|
|
updateButtons();
|
2017-08-07 04:16:29 +05:30
|
|
|
}
|
|
|
|
|
2019-07-14 09:07:10 +05:30
|
|
|
void VersionPage::on_actionReplace_Minecraft_jar_triggered()
|
2017-08-07 04:16:29 +05:30
|
|
|
{
|
2021-11-20 20:52:22 +05:30
|
|
|
auto jarPath = GuiUtil::BrowseForFile("jar", tr("Select jar"), tr("Minecraft.jar replacement (*.jar)"), APPLICATION->settings()->get("CentralModsDir").toString(), this->parentWidget());
|
2018-07-15 18:21:05 +05:30
|
|
|
if(!jarPath.isEmpty())
|
|
|
|
{
|
|
|
|
m_profile->installCustomJar(jarPath);
|
|
|
|
}
|
|
|
|
updateButtons();
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
|
2019-07-14 09:07:10 +05:30
|
|
|
void VersionPage::on_actionMove_up_triggered()
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
try
|
|
|
|
{
|
2020-06-27 15:32:31 +05:30
|
|
|
m_profile->move(currentRow(), PackProfile::MoveUp);
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
|
|
|
catch (const Exception &e)
|
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error"), e.cause());
|
|
|
|
}
|
|
|
|
updateButtons();
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
|
2019-07-14 09:07:10 +05:30
|
|
|
void VersionPage::on_actionMove_down_triggered()
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
try
|
|
|
|
{
|
2020-06-27 15:32:31 +05:30
|
|
|
m_profile->move(currentRow(), PackProfile::MoveDown);
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
|
|
|
catch (const Exception &e)
|
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error"), e.cause());
|
|
|
|
}
|
|
|
|
updateButtons();
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
|
2019-07-14 09:07:10 +05:30
|
|
|
void VersionPage::on_actionChange_version_triggered()
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
auto versionRow = currentRow();
|
|
|
|
if(versionRow == -1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto patch = m_profile->getComponent(versionRow);
|
|
|
|
auto name = patch->getName();
|
|
|
|
auto list = patch->getVersionList();
|
|
|
|
if(!list)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto uid = list->uid();
|
|
|
|
// FIXME: this is a horrible HACK. Get version filtering information from the actual metadata...
|
|
|
|
if(uid == "net.minecraftforge")
|
|
|
|
{
|
2019-07-14 09:07:10 +05:30
|
|
|
on_actionInstall_Forge_triggered();
|
2018-07-15 18:21:05 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (uid == "com.mumfrey.liteloader")
|
|
|
|
{
|
2019-07-14 09:07:10 +05:30
|
|
|
on_actionInstall_LiteLoader_triggered();
|
2018-07-15 18:21:05 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
VersionSelectDialog vselect(list.get(), tr("Change %1 version").arg(name), this);
|
2019-06-16 02:15:56 +05:30
|
|
|
if (uid == "net.fabricmc.intermediary")
|
|
|
|
{
|
2020-07-09 21:47:59 +05:30
|
|
|
vselect.setEmptyString(tr("No intermediary mappings versions are currently available."));
|
|
|
|
vselect.setEmptyErrorString(tr("Couldn't load or download the intermediary mappings version lists!"));
|
2019-06-16 02:15:56 +05:30
|
|
|
vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft"));
|
|
|
|
}
|
2018-07-15 18:21:05 +05:30
|
|
|
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();
|
2015-05-28 13:06:58 +05:30
|
|
|
}
|
2014-06-02 04:19:53 +05:30
|
|
|
|
2019-08-09 03:41:42 +05:30
|
|
|
void VersionPage::on_actionDownload_All_triggered()
|
2015-05-28 13:06:58 +05:30
|
|
|
{
|
2021-11-20 20:52:22 +05:30
|
|
|
if (!APPLICATION->accounts()->anyAccountIsValid())
|
2018-07-15 18:21:05 +05:30
|
|
|
{
|
|
|
|
CustomMessageBox::selectable(
|
|
|
|
this, tr("Error"),
|
2022-03-27 02:51:08 +05:30
|
|
|
tr("Cannot download Minecraft or update instances unless you have at least "
|
2018-07-15 18:21:05 +05:30
|
|
|
"one account added.\nPlease add your Mojang or Minecraft account."),
|
|
|
|
QMessageBox::Warning)->show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto updateTask = m_inst->createUpdateTask(Net::Mode::Online);
|
|
|
|
if (!updateTask)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ProgressDialog tDialog(this);
|
|
|
|
connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString)));
|
|
|
|
// FIXME: unused return value
|
|
|
|
tDialog.execWithTask(updateTask.get());
|
|
|
|
updateButtons();
|
|
|
|
m_container->refreshContainer();
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
|
2019-07-14 09:07:10 +05:30
|
|
|
void VersionPage::on_actionInstall_Forge_triggered()
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
2021-11-22 03:51:12 +05:30
|
|
|
auto vlist = APPLICATION->metadataIndex()->get("net.minecraftforge");
|
2018-07-15 18:21:05 +05:30
|
|
|
if(!vlist)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
VersionSelectDialog vselect(vlist.get(), tr("Select Forge version"), this);
|
|
|
|
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_profile->setComponentVersion("net.minecraftforge", vsn->descriptor());
|
|
|
|
m_profile->resolve(Net::Mode::Online);
|
|
|
|
// m_profile->installVersion();
|
|
|
|
preselect(m_profile->rowCount(QModelIndex())-1);
|
|
|
|
m_container->refreshContainer();
|
|
|
|
}
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
|
2019-07-14 09:07:10 +05:30
|
|
|
void VersionPage::on_actionInstall_Fabric_triggered()
|
2019-06-16 00:55:23 +05:30
|
|
|
{
|
2021-11-22 03:51:12 +05:30
|
|
|
auto vlist = APPLICATION->metadataIndex()->get("net.fabricmc.fabric-loader");
|
2019-06-16 00:55:23 +05:30
|
|
|
if(!vlist)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
VersionSelectDialog vselect(vlist.get(), tr("Select Fabric Loader version"), this);
|
|
|
|
vselect.setEmptyString(tr("No Fabric Loader versions are currently available."));
|
|
|
|
vselect.setEmptyErrorString(tr("Couldn't load or download the Fabric Loader version lists!"));
|
|
|
|
|
|
|
|
auto currentVersion = m_profile->getComponentVersion("net.fabricmc.fabric-loader");
|
|
|
|
if(!currentVersion.isEmpty())
|
|
|
|
{
|
|
|
|
vselect.setCurrentVersion(currentVersion);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vselect.exec() && vselect.selectedVersion())
|
|
|
|
{
|
|
|
|
auto vsn = vselect.selectedVersion();
|
|
|
|
m_profile->setComponentVersion("net.fabricmc.fabric-loader", vsn->descriptor());
|
|
|
|
m_profile->resolve(Net::Mode::Online);
|
|
|
|
preselect(m_profile->rowCount(QModelIndex())-1);
|
|
|
|
m_container->refreshContainer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-14 09:07:10 +05:30
|
|
|
void VersionPage::on_actionAdd_Empty_triggered()
|
2017-12-31 06:07:50 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
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());
|
|
|
|
}
|
2017-12-31 06:07:50 +05:30
|
|
|
}
|
|
|
|
|
2019-07-14 09:07:10 +05:30
|
|
|
void VersionPage::on_actionInstall_LiteLoader_triggered()
|
2014-06-02 04:19:53 +05:30
|
|
|
{
|
2021-11-22 03:51:12 +05:30
|
|
|
auto vlist = APPLICATION->metadataIndex()->get("com.mumfrey.liteloader");
|
2018-07-15 18:21:05 +05:30
|
|
|
if(!vlist)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
VersionSelectDialog vselect(vlist.get(), tr("Select LiteLoader version"), this);
|
|
|
|
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_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();
|
|
|
|
}
|
2014-06-02 04:19:53 +05:30
|
|
|
}
|
|
|
|
|
2020-01-09 18:15:46 +05:30
|
|
|
void VersionPage::on_actionLibrariesFolder_triggered()
|
|
|
|
{
|
|
|
|
DesktopServices::openDirectory(m_inst->getLocalLibraryPath(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::on_actionMinecraftFolder_triggered()
|
|
|
|
{
|
|
|
|
DesktopServices::openDirectory(m_inst->gameRoot(), true);
|
|
|
|
}
|
|
|
|
|
2014-06-02 04:19:53 +05:30
|
|
|
void VersionPage::versionCurrent(const QModelIndex ¤t, const QModelIndex &previous)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
currentIdx = current.row();
|
|
|
|
updateButtons(currentIdx);
|
2015-05-18 03:08:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void VersionPage::preselect(int row)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if(row < 0)
|
|
|
|
{
|
|
|
|
row = 0;
|
|
|
|
}
|
|
|
|
if(row >= m_profile->rowCount(QModelIndex()))
|
|
|
|
{
|
|
|
|
row = m_profile->rowCount(QModelIndex()) - 1;
|
|
|
|
}
|
|
|
|
if(row < 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto model_index = m_profile->index(row);
|
|
|
|
ui->packageView->selectionModel()->select(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
|
|
|
|
updateButtons(row);
|
2015-05-18 03:08:28 +05:30
|
|
|
}
|
|
|
|
|
2015-04-08 17:20:21 +05:30
|
|
|
void VersionPage::onGameUpdateError(QString error)
|
|
|
|
{
|
2019-07-16 02:46:34 +05:30
|
|
|
CustomMessageBox::selectable(this, tr("Error updating instance"), error, QMessageBox::Warning)->show();
|
2015-04-08 17:20:21 +05:30
|
|
|
}
|
2015-05-18 03:08:28 +05:30
|
|
|
|
2017-12-29 05:05:10 +05:30
|
|
|
Component * VersionPage::current()
|
2015-05-18 03:08:28 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
auto row = currentRow();
|
|
|
|
if(row < 0)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return m_profile->getComponent(row);
|
2015-05-18 03:08:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
int VersionPage::currentRow()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if (ui->packageView->selectionModel()->selectedRows().isEmpty())
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return ui->packageView->selectionModel()->selectedRows().first().row();
|
2015-05-18 03:08:28 +05:30
|
|
|
}
|
|
|
|
|
2019-07-14 09:07:10 +05:30
|
|
|
void VersionPage::on_actionCustomize_triggered()
|
2015-05-18 03:08:28 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
auto version = currentRow();
|
|
|
|
if(version == -1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto patch = m_profile->getComponent(version);
|
|
|
|
if(!patch->getVersionFile())
|
|
|
|
{
|
|
|
|
// TODO: wait for the update task to finish here...
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(!m_profile->customize(version))
|
|
|
|
{
|
|
|
|
// TODO: some error box here
|
|
|
|
}
|
|
|
|
updateButtons();
|
|
|
|
preselect(currentIdx);
|
2015-05-18 03:08:28 +05:30
|
|
|
}
|
|
|
|
|
2019-07-14 09:07:10 +05:30
|
|
|
void VersionPage::on_actionEdit_triggered()
|
2015-05-18 03:08:28 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
auto version = current();
|
|
|
|
if(!version)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto filename = version->getFilename();
|
|
|
|
if(!QFileInfo::exists(filename))
|
|
|
|
{
|
|
|
|
qWarning() << "file" << filename << "can't be opened for editing, doesn't exist!";
|
|
|
|
return;
|
|
|
|
}
|
2021-11-20 20:52:22 +05:30
|
|
|
APPLICATION->openJsonEditor(filename);
|
2015-05-18 03:08:28 +05:30
|
|
|
}
|
|
|
|
|
2019-07-14 09:07:10 +05:30
|
|
|
void VersionPage::on_actionRevert_triggered()
|
2015-05-18 03:08:28 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
auto version = currentRow();
|
|
|
|
if(version == -1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(!m_profile->revertToBase(version))
|
|
|
|
{
|
|
|
|
// TODO: some error box here
|
|
|
|
}
|
|
|
|
updateButtons();
|
|
|
|
preselect(currentIdx);
|
|
|
|
m_container->refreshContainer();
|
2015-05-18 03:08:28 +05:30
|
|
|
}
|
2016-02-21 06:14:27 +05:30
|
|
|
|
2021-06-19 03:51:12 +05:30
|
|
|
void VersionPage::onFilterTextChanged(const QString &newContents)
|
|
|
|
{
|
|
|
|
m_filterModel->setFilterFixedString(newContents);
|
|
|
|
}
|
|
|
|
|
2016-02-21 06:14:27 +05:30
|
|
|
#include "VersionPage.moc"
|