mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-13 05:37:42 +02:00
Moving files around
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
@ -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();
|
||||
}
|
109
launcher/ui/java/JavaDownloader.cpp
Normal file
109
launcher/ui/java/JavaDownloader.cpp
Normal 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
|
@ -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
|
@ -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">
|
@ -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();
|
@ -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
|
Reference in New Issue
Block a user