Moving files around

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2024-02-02 15:51:32 +02:00
parent 6c5bb3817b
commit 3c58fb0677
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
25 changed files with 254 additions and 224 deletions

View File

@ -110,7 +110,7 @@ QHash<int, QByteArray> BaseVersionList::roleNames() const
roles.insert(TypeRole, "type");
roles.insert(BranchRole, "branch");
roles.insert(PathRole, "path");
roles.insert(AliasRole, "alias");
roles.insert(ArchitectureRole, "architecture");
roles.insert(JavaNameRole, "javaName");
roles.insert(CPUArchitectureRole, "architecture");
return roles;
}

View File

@ -48,8 +48,8 @@ class BaseVersionList : public QAbstractListModel {
TypeRole,
BranchRole,
PathRole,
AliasRole,
ArchitectureRole,
JavaNameRole,
CPUArchitectureRole,
SortRole
};
using RoleList = QList<int>;

View File

@ -431,17 +431,17 @@ set(JAVA_SOURCES
java/JavaVersion.h
java/JavaVersion.cpp
java/JavaRuntime.h
java/JavaRuntime.cpp
java/download/ArchiveJavaDownloader.cpp
java/download/ArchiveJavaDownloader.h
java/download/ManifestJavaDownloader.cpp
java/download/ManifestJavaDownloader.h
java/JavaMetadata.h
java/JavaMetadata.cpp
java/download/ArchiveDownloadTask.cpp
java/download/ArchiveDownloadTask.h
java/download/ManifestDownloadTask.cpp
java/download/ManifestDownloadTask.h
ui/java/JavaDownload.h
ui/java/JavaDownload.cpp
ui/java/ListModel.h
ui/java/ListModel.cpp
ui/java/JavaDownloader.h
ui/java/JavaDownloader.cpp
ui/java/VersionList.h
ui/java/VersionList.cpp
)
set(TRANSLATIONS_SOURCES
@ -1192,7 +1192,7 @@ qt_wrap_ui(LAUNCHER_UI
ui/dialogs/ScrollMessageBox.ui
ui/dialogs/BlockedModsDialog.ui
ui/dialogs/ChooseProviderDialog.ui
ui/java/JavaDownload.ui
ui/java/JavaDownloader.ui
)
qt_wrap_ui(PRISM_UPDATE_UI

View File

@ -114,12 +114,12 @@ QVariant VersionProxyModel::headerData(int section, Qt::Orientation orientation,
return tr("Branch");
case Type:
return tr("Type");
case Architecture:
case CPUArchitecture:
return tr("Architecture");
case Path:
return tr("Path");
case Alias:
return tr("Alias");
case JavaName:
return tr("Java Name");
case Time:
return tr("Released");
}
@ -133,11 +133,11 @@ QVariant VersionProxyModel::headerData(int section, Qt::Orientation orientation,
return tr("The version's branch");
case Type:
return tr("The version's type");
case Architecture:
case CPUArchitecture:
return tr("CPU Architecture");
case Path:
return tr("Filesystem path to this version");
case Alias:
case JavaName:
return tr("The alternative name of the java version");
case Time:
return tr("Release date of this version");
@ -169,12 +169,12 @@ QVariant VersionProxyModel::data(const QModelIndex& index, int role) const
return sourceModel()->data(parentIndex, BaseVersionList::BranchRole);
case Type:
return sourceModel()->data(parentIndex, BaseVersionList::TypeRole);
case Architecture:
return sourceModel()->data(parentIndex, BaseVersionList::ArchitectureRole);
case CPUArchitecture:
return sourceModel()->data(parentIndex, BaseVersionList::CPUArchitectureRole);
case Path:
return sourceModel()->data(parentIndex, BaseVersionList::PathRole);
case Alias:
return sourceModel()->data(parentIndex, BaseVersionList::AliasRole);
case JavaName:
return sourceModel()->data(parentIndex, BaseVersionList::JavaNameRole);
case Time:
return sourceModel()->data(parentIndex, Meta::VersionList::TimeRole).toDate();
default:
@ -314,14 +314,14 @@ void VersionProxyModel::setSourceModel(QAbstractItemModel* replacingRaw)
m_columns.push_back(ParentVersion);
}
*/
if (roles.contains(BaseVersionList::ArchitectureRole)) {
m_columns.push_back(Architecture);
if (roles.contains(BaseVersionList::CPUArchitectureRole)) {
m_columns.push_back(CPUArchitecture);
}
if (roles.contains(BaseVersionList::PathRole)) {
m_columns.push_back(Path);
}
if (roles.contains(BaseVersionList::AliasRole)) {
m_columns.push_back(Alias);
if (roles.contains(BaseVersionList::JavaNameRole)) {
m_columns.push_back(JavaName);
}
if (roles.contains(Meta::VersionList::TimeRole)) {
m_columns.push_back(Time);

View File

@ -9,7 +9,7 @@ class VersionFilterModel;
class VersionProxyModel : public QAbstractProxyModel {
Q_OBJECT
public:
enum Column { Name, ParentVersion, Branch, Type, Architecture, Path, Time, Alias };
enum Column { Name, ParentVersion, Branch, Type, CPUArchitecture, Path, Time, JavaName };
using FilterMap = QHash<BaseVersionList::ModelRoles, std::shared_ptr<Filter>>;
public:

View File

@ -108,7 +108,7 @@ QVariant JavaInstallList::data(const QModelIndex& index, int role) const
return version->recommended;
case PathRole:
return version->path;
case ArchitectureRole:
case CPUArchitectureRole:
return version->arch;
default:
return QVariant();
@ -117,7 +117,7 @@ QVariant JavaInstallList::data(const QModelIndex& index, int role) const
BaseVersionList::RoleList JavaInstallList::providesRoles() const
{
return { VersionPointerRole, VersionIdRole, VersionRole, RecommendedRole, PathRole, ArchitectureRole };
return { VersionPointerRole, VersionIdRole, VersionRole, RecommendedRole, PathRole, CPUArchitectureRole };
}
void JavaInstallList::updateListData(QList<BaseVersion::Ptr> versions)

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "java/JavaRuntime.h"
#include "java/JavaMetadata.h"
#include <memory>
@ -25,7 +25,7 @@
#include "java/JavaVersion.h"
#include "minecraft/ParseUtils.h"
namespace JavaRuntime {
namespace Java {
DownloadType parseDownloadType(QString javaDownload)
{
@ -44,9 +44,9 @@ QString downloadTypeToString(DownloadType javaDownload)
}
return "";
}
MetaPtr parseJavaMeta(const QJsonObject& in)
MetadataPtr parseJavaMeta(const QJsonObject& in)
{
auto meta = std::make_shared<Meta>();
auto meta = std::make_shared<Metadata>();
meta->m_name = Json::ensureString(in, "name", "");
meta->vendor = Json::ensureString(in, "vendor", "");
@ -74,7 +74,7 @@ MetaPtr parseJavaMeta(const QJsonObject& in)
return meta;
}
bool Meta::operator<(const Meta& rhs)
bool Metadata::operator<(const Metadata& rhs)
{
auto id = version;
if (id < rhs.version) {
@ -86,32 +86,32 @@ bool Meta::operator<(const Meta& rhs)
return StringUtils::naturalCompare(m_name, rhs.m_name, Qt::CaseInsensitive) < 0;
}
bool Meta::operator==(const Meta& rhs)
bool Metadata::operator==(const Metadata& rhs)
{
return version == rhs.version && m_name == rhs.m_name;
}
bool Meta::operator>(const Meta& rhs)
bool Metadata::operator>(const Metadata& rhs)
{
return (!operator<(rhs)) && (!operator==(rhs));
}
bool Meta::operator<(BaseVersion& a)
bool Metadata::operator<(BaseVersion& a)
{
try {
return operator<(dynamic_cast<Meta&>(a));
return operator<(dynamic_cast<Metadata&>(a));
} catch (const std::bad_cast& e) {
return BaseVersion::operator<(a);
}
}
bool Meta::operator>(BaseVersion& a)
bool Metadata::operator>(BaseVersion& a)
{
try {
return operator>(dynamic_cast<Meta&>(a));
return operator>(dynamic_cast<Metadata&>(a));
} catch (const std::bad_cast& e) {
return BaseVersion::operator>(a);
}
}
} // namespace JavaRuntime
} // namespace Java

View File

@ -26,11 +26,11 @@
#include "BaseVersion.h"
#include "java/JavaVersion.h"
namespace JavaRuntime {
namespace Java {
enum class DownloadType { Manifest, Archive };
class Meta : public BaseVersion {
class Metadata : public BaseVersion {
public:
virtual QString descriptor() override { return version.toString(); }
@ -40,9 +40,9 @@ class Meta : public BaseVersion {
virtual bool operator<(BaseVersion& a) override;
virtual bool operator>(BaseVersion& a) override;
bool operator<(const Meta& rhs);
bool operator==(const Meta& rhs);
bool operator>(const Meta& rhs);
bool operator<(const Metadata& rhs);
bool operator==(const Metadata& rhs);
bool operator>(const Metadata& rhs);
QString m_name;
QString vendor;
@ -55,10 +55,10 @@ class Meta : public BaseVersion {
QString packageType;
JavaVersion version;
};
using MetaPtr = std::shared_ptr<Meta>;
using MetadataPtr = std::shared_ptr<Metadata>;
DownloadType parseDownloadType(QString javaDownload);
QString downloadTypeToString(DownloadType javaDownload);
MetaPtr parseJavaMeta(const QJsonObject& libObj);
MetadataPtr parseJavaMeta(const QJsonObject& libObj);
} // namespace JavaRuntime
} // namespace Java

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "java/download/ArchiveJavaDownloader.h"
#include "java/download/ArchiveDownloadTask.h"
#include <quazip.h>
#include <memory>
#include "MMCZip.h"
@ -25,11 +25,12 @@
#include "net/NetJob.h"
#include "tasks/Task.h"
ArchiveJavaDownloader::ArchiveJavaDownloader(QUrl url, QString final_path, QString checksumType, QString checksumHash)
namespace Java {
ArchiveDownloadTask::ArchiveDownloadTask(QUrl url, QString final_path, QString checksumType, QString checksumHash)
: m_url(url), m_final_path(final_path), m_checksum_type(checksumType), m_checksum_hash(checksumHash)
{}
void ArchiveJavaDownloader::executeTask()
void ArchiveDownloadTask::executeTask()
{
// JRE found ! download the zip
setStatus(tr("Downloading Java"));
@ -49,8 +50,8 @@ void ArchiveJavaDownloader::executeTask()
auto fullPath = entry->getFullPath();
connect(download.get(), &NetJob::finished, [download, this] { disconnect(this, &Task::aborted, download.get(), &NetJob::abort); });
connect(download.get(), &NetJob::progress, this, &ArchiveJavaDownloader::progress);
connect(download.get(), &NetJob::failed, this, &ArchiveJavaDownloader::emitFailed);
connect(download.get(), &NetJob::progress, this, &ArchiveDownloadTask::progress);
connect(download.get(), &NetJob::failed, this, &ArchiveDownloadTask::emitFailed);
connect(this, &Task::aborted, download.get(), &NetJob::abort);
connect(download.get(), &NetJob::succeeded, [this, fullPath] {
// This should do all of the extracting and creating folders
@ -59,7 +60,7 @@ void ArchiveJavaDownloader::executeTask()
download->start();
}
void ArchiveJavaDownloader::extractJava(QString input)
void ArchiveDownloadTask::extractJava(QString input)
{
setStatus(tr("Extracting java"));
auto zip = std::make_shared<QuaZip>(input);
@ -79,14 +80,14 @@ void ArchiveJavaDownloader::extractJava(QString input)
connect(this, &Task::aborted, zipTask.get(), &Task::abort);
connect(zipTask.get(), &Task::finished, [zipTask, this] { disconnect(this, &Task::aborted, zipTask.get(), &Task::abort); });
connect(zipTask.get(), &Task::succeeded, this, &ArchiveJavaDownloader::emitSucceeded);
connect(zipTask.get(), &Task::aborted, this, &ArchiveJavaDownloader::emitAborted);
connect(zipTask.get(), &Task::succeeded, this, &ArchiveDownloadTask::emitSucceeded);
connect(zipTask.get(), &Task::aborted, this, &ArchiveDownloadTask::emitAborted);
connect(zipTask.get(), &Task::failed, this, [this, progressStep](QString reason) {
progressStep->state = TaskStepState::Failed;
stepProgress(*progressStep);
emitFailed(reason);
});
connect(zipTask.get(), &Task::stepProgress, this, &ArchiveJavaDownloader::propagateStepProgress);
connect(zipTask.get(), &Task::stepProgress, this, &ArchiveDownloadTask::propagateStepProgress);
connect(zipTask.get(), &Task::progress, this, [this, progressStep](qint64 current, qint64 total) {
progressStep->update(current, total);
@ -97,4 +98,5 @@ void ArchiveJavaDownloader::extractJava(QString input)
stepProgress(*progressStep);
});
zipTask->start();
}
}
} // namespace Java

View File

@ -21,11 +21,12 @@
#include <QUrl>
#include "tasks/Task.h"
class ArchiveJavaDownloader : public Task {
namespace Java {
class ArchiveDownloadTask : public Task {
Q_OBJECT
public:
ArchiveJavaDownloader(QUrl url, QString final_path, QString checksumType = "", QString checksumHash = "");
virtual ~ArchiveJavaDownloader() = default;
ArchiveDownloadTask(QUrl url, QString final_path, QString checksumType = "", QString checksumHash = "");
virtual ~ArchiveDownloadTask() = default;
[[nodiscard]] bool canAbort() const override { return true; }
void executeTask() override;
@ -38,6 +39,5 @@ class ArchiveJavaDownloader : public Task {
QString m_final_path;
QString m_checksum_type;
QString m_checksum_hash;
Task::Ptr m_current_task;
};
};
} // namespace Java

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "java/download/ManifestJavaDownloader.h"
#include "java/download/ManifestDownloadTask.h"
#include "Application.h"
#include "FileSystem.h"
@ -30,11 +30,12 @@ struct File {
bool isExec;
};
ManifestJavaDownloader::ManifestJavaDownloader(QUrl url, QString final_path, QString checksumType, QString checksumHash)
namespace Java {
ManifestDownloadTask::ManifestDownloadTask(QUrl url, QString final_path, QString checksumType, QString checksumHash)
: m_url(url), m_final_path(final_path), m_checksum_type(checksumType), m_checksum_hash(checksumHash)
{}
void ManifestJavaDownloader::executeTask()
void ManifestDownloadTask::executeTask()
{
setStatus(tr("Downloading Java"));
auto download = makeShared<NetJob>(QString("JRE::DownloadJava"), APPLICATION->network());
@ -51,8 +52,8 @@ void ManifestJavaDownloader::executeTask()
download->addNetAction(action);
connect(download.get(), &NetJob::finished, [download, this] { disconnect(this, &Task::aborted, download.get(), &NetJob::abort); });
connect(download.get(), &NetJob::progress, this, &ManifestJavaDownloader::progress);
connect(download.get(), &NetJob::failed, this, &ManifestJavaDownloader::emitFailed);
connect(download.get(), &NetJob::progress, this, &ManifestDownloadTask::progress);
connect(download.get(), &NetJob::failed, this, &ManifestDownloadTask::emitFailed);
connect(this, &Task::aborted, download.get(), &NetJob::abort);
connect(download.get(), &NetJob::succeeded, [files, this] {
@ -69,7 +70,7 @@ void ManifestJavaDownloader::executeTask()
download->start();
}
void ManifestJavaDownloader::downloadJava(const QJsonDocument& doc)
void ManifestDownloadTask::downloadJava(const QJsonDocument& doc)
{
// valid json doc, begin making jre spot
FS::ensureFolderPathExists(m_final_path);
@ -116,10 +117,11 @@ void ManifestJavaDownloader::downloadJava(const QJsonDocument& doc)
disconnect(this, &Task::aborted, elementDownload, &NetJob::abort);
elementDownload->deleteLater();
});
connect(elementDownload, &NetJob::progress, this, &ManifestJavaDownloader::progress);
connect(elementDownload, &NetJob::failed, this, &ManifestJavaDownloader::emitFailed);
connect(elementDownload, &NetJob::progress, this, &ManifestDownloadTask::progress);
connect(elementDownload, &NetJob::failed, this, &ManifestDownloadTask::emitFailed);
connect(this, &Task::aborted, elementDownload, &NetJob::abort);
connect(elementDownload, &NetJob::succeeded, [this] { emitSucceeded(); });
elementDownload->start();
}
}
} // namespace Java

View File

@ -21,11 +21,13 @@
#include <QUrl>
#include "tasks/Task.h"
class ManifestJavaDownloader : public Task {
namespace Java {
class ManifestDownloadTask : public Task {
Q_OBJECT
public:
ManifestJavaDownloader(QUrl url, QString final_path, QString checksumType = "", QString checksumHash = "");
virtual ~ManifestJavaDownloader() = default;
ManifestDownloadTask(QUrl url, QString final_path, QString checksumType = "", QString checksumHash = "");
virtual ~ManifestDownloadTask() = default;
[[nodiscard]] bool canAbort() const override { return true; }
void executeTask() override;
@ -38,6 +40,5 @@ class ManifestJavaDownloader : public Task {
QString m_final_path;
QString m_checksum_type;
QString m_checksum_hash;
Task::Ptr m_current_task;
};
};
} // namespace Java

View File

@ -101,10 +101,14 @@ QVariant VersionList::data(const QModelIndex& index, int role) const
BaseVersionList::RoleList VersionList::providesRoles() const
{
return { VersionPointerRole, VersionRole, VersionIdRole, ParentVersionRole, TypeRole, UidRole,
TimeRole, RequiresRole, SortRole, RecommendedRole, LatestRole, VersionPtrRole };
return m_provided_roles;
}
void VersionList::setProvidedRoles(RoleList roles)
{
m_provided_roles = roles;
};
QHash<int, QByteArray> VersionList::roleNames() const
{
QHash<int, QByteArray> roles = BaseVersionList::roleNames();

View File

@ -47,6 +47,8 @@ class VersionList : public BaseVersionList, public BaseEntity {
RoleList providesRoles() const override;
QHash<int, QByteArray> roleNames() const override;
void setProvidedRoles(RoleList roles);
QString localFilename() const override;
QString uid() const { return m_uid; }
@ -79,6 +81,9 @@ class VersionList : public BaseVersionList, public BaseEntity {
Version::Ptr m_recommended;
RoleList m_provided_roles = { VersionPointerRole, VersionRole, VersionIdRole, ParentVersionRole, TypeRole, UidRole,
TimeRole, RequiresRole, SortRole, RecommendedRole, LatestRole, VersionPtrRole };
void setupAddedVersion(int row, const Version::Ptr& version);
};
} // namespace Meta

View File

@ -37,7 +37,7 @@
#include <Json.h>
#include <minecraft/MojangVersionFormat.h>
#include <QList>
#include "java/JavaRuntime.h"
#include "java/JavaMetadata.h"
#include "minecraft/Agent.h"
#include "minecraft/ParseUtils.h"
@ -261,9 +261,9 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument& doc
auto runtimes = requireObject(root, "runtimes");
out->runtimes = {};
for (auto key : runtimes.keys()) {
QList<JavaRuntime::MetaPtr> list;
QList<Java::MetadataPtr> list;
for (auto runtime : ensureArray(runtimes, key)) {
list.append(JavaRuntime::parseJavaMeta(ensureObject(runtime)));
list.append(Java::parseJavaMeta(ensureObject(runtime)));
}
out->runtimes[key] = list;
}

View File

@ -47,7 +47,7 @@
#include "Agent.h"
#include "Library.h"
#include "ProblemProvider.h"
#include "java/JavaRuntime.h"
#include "java/JavaMetadata.h"
#include "minecraft/Rule.h"
class PackProfile;
@ -155,7 +155,7 @@ class VersionFile : public ProblemContainer {
/// is volatile -- may be removed as soon as it is no longer needed by something else
bool m_volatile = false;
QHash<QString, QList<JavaRuntime::MetaPtr>> runtimes;
QHash<QString, QList<Java::MetadataPtr>> runtimes;
public:
// Mojang: DEPRECATED list of 'downloads' - client jar, server jar, windows server exe, maybe more.

View File

@ -1,90 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (c) 2024 Trial97 <alexandru.tripon97@gmail.com>
*
* 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.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "JavaDownload.h"
#include <QPushButton>
#include <memory>
#include "Application.h"
#include "FileSystem.h"
#include "QObjectPtr.h"
#include "SysInfo.h"
#include "java/JavaRuntime.h"
#include "java/download/ArchiveJavaDownloader.h"
#include "java/download/ManifestJavaDownloader.h"
#include "meta/Index.h"
#include "meta/Version.h"
#include "ui/dialogs/ProgressDialog.h"
#include "ui/java/ListModel.h"
#include "ui_JavaDownload.h"
JavaDownload::JavaDownload(QWidget* parent) : QDialog(parent), ui(new Ui::JavaDownload)
{
ui->setupUi(this);
ui->widget->initialize(new Java::JavaBaseVersionList("net.minecraft.java"));
ui->widget->selectCurrent();
connect(ui->widget, &VersionSelectWidget::selectedVersionChanged, this, &JavaDownload::setSelectedVersion);
auto reset = ui->buttonBox->button(QDialogButtonBox::Reset);
connect(reset, &QPushButton::clicked, this, &JavaDownload::refresh);
}
JavaDownload::~JavaDownload()
{
delete ui;
}
void JavaDownload::setSelectedVersion(BaseVersion::Ptr version)
{
auto dcast = std::dynamic_pointer_cast<Meta::Version>(version);
if (!dcast) {
return;
}
ui->widget_2->initialize(new Java::InstallList(dcast, this));
ui->widget_2->selectCurrent();
}
void JavaDownload::accept()
{
auto meta = std::dynamic_pointer_cast<JavaRuntime::Meta>(ui->widget_2->selectedVersion());
if (!meta) {
return;
}
Task::Ptr task;
auto final_path = FS::PathCombine(APPLICATION->dataRoot(), "java", meta->m_name);
switch (meta->downloadType) {
case JavaRuntime::DownloadType::Manifest:
task = makeShared<ManifestJavaDownloader>(meta->url, final_path, meta->checksumType, meta->checksumHash);
break;
case JavaRuntime::DownloadType::Archive:
task = makeShared<ArchiveJavaDownloader>(meta->url, final_path, meta->checksumType, meta->checksumHash);
break;
}
ProgressDialog pg(this);
pg.execWithTask(task.get());
QDialog::accept();
}
void JavaDownload::refresh()
{
ui->widget->loadList();
}

View File

@ -0,0 +1,109 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (c) 2024 Trial97 <alexandru.tripon97@gmail.com>
*
* 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.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "JavaDownloader.h"
#include <QPushButton>
#include <memory>
#include "Application.h"
#include "BaseVersionList.h"
#include "FileSystem.h"
#include "QObjectPtr.h"
#include "SysInfo.h"
#include "java/JavaMetadata.h"
#include "java/download/ArchiveDownloadTask.h"
#include "java/download/ManifestDownloadTask.h"
#include "meta/Index.h"
#include "meta/Version.h"
#include "meta/VersionList.h"
#include "ui/dialogs/ProgressDialog.h"
#include "ui/java/VersionList.h"
#include "ui_JavaDownloader.h"
namespace Java {
Downloader::Downloader(QWidget* parent) : QDialog(parent), ui(new Ui::JavaDownloader)
{
ui->setupUi(this);
auto versionList = new Meta::VersionList("net.minecraft.java", this);
versionList->setProvidedRoles({ BaseVersionList::VersionRole, BaseVersionList::RecommendedRole, BaseVersionList::VersionPointerRole });
ui->majorVersionSelect->initialize(versionList);
ui->majorVersionSelect->selectCurrent();
ui->majorVersionSelect->setEmptyString(tr("No java versions are currently available in the meta"));
ui->majorVersionSelect->setEmptyErrorString(tr("Couldn't load or download the java version lists!"));
ui->javaVersionSelect->setEmptyString(tr("No java versions are currently available for your OS."));
ui->javaVersionSelect->setEmptyErrorString(tr("Couldn't load or download the java version lists!"));
ui->buttonBox->button(QDialogButtonBox::Retry)->setText(tr("Refresh"));
ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Download"));
connect(ui->majorVersionSelect, &VersionSelectWidget::selectedVersionChanged, this, &Downloader::setSelectedVersion);
auto reset = ui->buttonBox->button(QDialogButtonBox::Reset);
connect(reset, &QPushButton::clicked, this, &Downloader::refresh);
}
Downloader::~Downloader()
{
delete ui;
}
void Downloader::setSelectedVersion(BaseVersion::Ptr version)
{
auto dcast = std::dynamic_pointer_cast<Meta::Version>(version);
if (!dcast) {
return;
}
ui->javaVersionSelect->initialize(new Java::VersionList(dcast, this));
ui->javaVersionSelect->selectCurrent();
}
void Downloader::accept()
{
auto meta = std::dynamic_pointer_cast<Java::Metadata>(ui->javaVersionSelect->selectedVersion());
if (!meta) {
return;
}
Task::Ptr task;
auto final_path = FS::PathCombine(APPLICATION->dataRoot(), "java", meta->m_name);
switch (meta->downloadType) {
case Java::DownloadType::Manifest:
task = makeShared<ManifestDownloadTask>(meta->url, final_path, meta->checksumType, meta->checksumHash);
break;
case Java::DownloadType::Archive:
task = makeShared<ArchiveDownloadTask>(meta->url, final_path, meta->checksumType, meta->checksumHash);
break;
}
auto deletePath = [final_path] { FS::deletePath(final_path); };
connect(task.get(), &Task::failed, this, deletePath);
connect(task.get(), &Task::aborted, this, deletePath);
ProgressDialog pg(this);
pg.execWithTask(task.get());
QDialog::accept();
}
void Downloader::refresh()
{
ui->majorVersionSelect->loadList();
}
} // namespace Java

View File

@ -22,15 +22,17 @@
#include "BaseVersion.h"
namespace Ui {
class JavaDownload;
class JavaDownloader;
}
class JavaDownload : public QDialog {
namespace Java {
class Downloader : public QDialog {
Q_OBJECT
public:
explicit JavaDownload(QWidget* parent = 0);
~JavaDownload();
explicit Downloader(QWidget* parent = 0);
~Downloader();
void accept();
@ -41,5 +43,6 @@ class JavaDownload : public QDialog {
void setSelectedVersion(BaseVersion::Ptr version);
private:
Ui::JavaDownload* ui;
Ui::JavaDownloader* ui;
};
} // namespace Java

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>JavaDownload</class>
<widget class="QDialog" name="JavaDownload">
<class>JavaDownloader</class>
<widget class="QDialog" name="JavaDownloader">
<property name="geometry">
<rect>
<x>0</x>
@ -23,7 +23,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="VersionSelectWidget" name="widget" native="true"/>
<widget class="VersionSelectWidget" name="majorVersionSelect" native="true"/>
</item>
</layout>
</widget>
@ -35,7 +35,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="VersionSelectWidget" name="widget_2" native="true"/>
<widget class="VersionSelectWidget" name="javaVersionSelect" native="true"/>
</item>
</layout>
</widget>
@ -67,7 +67,7 @@
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>JavaDownload</receiver>
<receiver>JavaDownloader</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
@ -83,7 +83,7 @@
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>JavaDownload</receiver>
<receiver>JavaDownloader</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">

View File

@ -16,46 +16,46 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "ListModel.h"
#include "VersionList.h"
#include <memory>
#include "BaseVersionList.h"
#include "SysInfo.h"
#include "java/JavaRuntime.h"
#include "java/JavaMetadata.h"
namespace Java {
InstallList::InstallList(Meta::Version::Ptr version, QObject* parent) : BaseVersionList(parent), m_version(version)
VersionList::VersionList(Meta::Version::Ptr version, QObject* parent) : BaseVersionList(parent), m_version(version)
{
if (version->isLoaded())
sortVersions();
}
Task::Ptr InstallList::getLoadTask()
Task::Ptr VersionList::getLoadTask()
{
m_version->load(Net::Mode::Online);
auto task = m_version->getCurrentTask();
connect(task.get(), &Task::finished, this, &InstallList::sortVersions);
connect(task.get(), &Task::finished, this, &VersionList::sortVersions);
return task;
}
const BaseVersion::Ptr InstallList::at(int i) const
const BaseVersion::Ptr VersionList::at(int i) const
{
return m_vlist.at(i);
}
bool InstallList::isLoaded()
bool VersionList::isLoaded()
{
return m_version->isLoaded();
}
int InstallList::count() const
int VersionList::count() const
{
return m_vlist.count();
}
QVariant InstallList::data(const QModelIndex& index, int role) const
QVariant VersionList::data(const QModelIndex& index, int role) const
{
if (!index.isValid())
return QVariant();
@ -75,28 +75,28 @@ QVariant InstallList::data(const QModelIndex& index, int role) const
return version->version.toString();
case RecommendedRole:
return version->recommended;
case AliasRole:
case JavaNameRole:
return version->name();
case ArchitectureRole:
case CPUArchitectureRole:
return version->vendor;
default:
return QVariant();
}
}
BaseVersionList::RoleList InstallList::providesRoles() const
BaseVersionList::RoleList VersionList::providesRoles() const
{
return { VersionPointerRole, VersionIdRole, VersionRole, RecommendedRole, AliasRole, ArchitectureRole };
return { VersionPointerRole, VersionIdRole, VersionRole, RecommendedRole, JavaNameRole, CPUArchitectureRole };
}
bool sortJavas(BaseVersion::Ptr left, BaseVersion::Ptr right)
{
auto rleft = std::dynamic_pointer_cast<JavaRuntime::Meta>(right);
auto rright = std::dynamic_pointer_cast<JavaRuntime::Meta>(left);
auto rleft = std::dynamic_pointer_cast<Java::Metadata>(right);
auto rright = std::dynamic_pointer_cast<Java::Metadata>(left);
return (*rleft) > (*rright);
}
void InstallList::sortVersions()
void VersionList::sortVersions()
{
QString versionStr = SysInfo::getSupportedJavaArchitecture();
beginResetModel();

View File

@ -18,23 +18,17 @@
#pragma once
#include "java/JavaRuntime.h"
#include "meta/VersionList.h"
#include "BaseVersionList.h"
#include "java/JavaMetadata.h"
#include "meta/Version.h"
namespace Java {
class JavaBaseVersionList : public Meta::VersionList {
Q_OBJECT
public:
explicit JavaBaseVersionList(const QString& uid, QObject* parent = nullptr) : VersionList(uid, parent) {}
BaseVersionList::RoleList providesRoles() const { return { VersionRole, RecommendedRole, VersionPointerRole }; }
};
class InstallList : public BaseVersionList {
class VersionList : public BaseVersionList {
Q_OBJECT
public:
explicit InstallList(Meta::Version::Ptr m_version, QObject* parent = 0);
explicit VersionList(Meta::Version::Ptr m_version, QObject* parent = 0);
Task::Ptr getLoadTask() override;
bool isLoaded() override;
@ -50,7 +44,7 @@ class InstallList : public BaseVersionList {
protected:
Meta::Version::Ptr m_version;
QList<JavaRuntime::MetaPtr> m_vlist;
QList<Java::MetadataPtr> m_vlist;
};
} // namespace Java

View File

@ -36,7 +36,7 @@
#include "JavaPage.h"
#include "JavaCommon.h"
#include "ui/java/JavaDownload.h"
#include "ui/java/JavaDownloader.h"
#include "ui_JavaPage.h"
#include <QDir>
@ -169,7 +169,7 @@ void JavaPage::on_javaTestBtn_clicked()
void JavaPage::on_javaDownloadBtn_clicked()
{
auto jdialog = new JavaDownload(this);
auto jdialog = new Java::Downloader(this);
jdialog->exec();
}

View File

@ -36,7 +36,7 @@
*/
#include "InstanceSettingsPage.h"
#include "ui/java/JavaDownload.h"
#include "ui/java/JavaDownloader.h"
#include "ui_InstanceSettingsPage.h"
#include <QDialog>
@ -387,7 +387,7 @@ void InstanceSettingsPage::loadSettings()
void InstanceSettingsPage::on_javaDownloadBtn_clicked()
{
auto jdialog = new JavaDownload(this);
auto jdialog = new Java::Downloader(this);
jdialog->exec();
}

View File

@ -19,7 +19,7 @@
#include "java/JavaUtils.h"
#include "ui/dialogs/CustomMessageBox.h"
#include "ui/java/JavaDownload.h"
#include "ui/java/JavaDownloader.h"
#include "ui/widgets/VersionSelectWidget.h"
#include "Application.h"
@ -274,7 +274,7 @@ void JavaSettingsWidget::on_javaBrowseBtn_clicked()
}
void JavaSettingsWidget::on_javaDownloadBtn_clicked()
{
auto jdialog = new JavaDownload(this);
auto jdialog = new Java::Downloader(this);
jdialog->exec();
}
void JavaSettingsWidget::on_javaStatusBtn_clicked()