ShatteredPrism/launcher/ui/dialogs/SkinUploadDialog.cpp
Evan Goode 9d442a0348 authlib-injector
* 'Custom Yggdrasil' AccountType

Signed-off-by: Evan Goode <mail@evangoo.de>

* Allow multiple accounts with the same player UUID

Signed-off-by: Evan Goode <mail@evangoo.de>

* Use correct services server URL for SkinDelete

Signed-off-by: Evan Goode <mail@evangoo.de>

* Correctly use CustomYggdrasilRefresh, add warning message

Signed-off-by: Evan Goode <mail@evangoo.de>

* Custom Yggdrasil: Readability fixes

Also made the MinecraftEntitlement for Custom Yggdrasil accounts work
just like offline accounts---instead of checking the reply from the auth
server, Custom Yggdrasil accounts are granted canPlayMinecraft and
ownsMinecraft when they are created, in MinecraftAccount.cpp.

Signed-off-by: Evan Goode <mail@evangoo.de>

* Custom Yggdrasil: Add extra confirmation dialog

Signed-off-by: Evan Goode <mail@evangoo.de>

* Add install authlib-injector button

Signed-off-by: Evan Goode <mail@evangoo.de>

* authlib-injector accounts

Signed-off-by: Evan Goode <mail@evangoo.de>

* Suggest installing authlib-injector when needed

Signed-off-by: Evan Goode <mail@evangoo.de>

* Use Unmojang metadata

Signed-off-by: Evan Goode <mail@evangoo.de>

* Use std::string for MANAGED_AGENTS, not QString

---------

Signed-off-by: Evan Goode <mail@evangoo.de>

Resolve X-Authlib-Injector-API-Location

Signed-off-by: Evan Goode <mail@evangoo.de>

Prefetch authlib-injector metadata

Resolves https://github.com/unmojang/PrismLauncher/issues/4

See https://github-com.translate.goog/yushijinhun/authlib-injector/wiki/%E5%90%AF%E5%8A%A8%E5%99%A8%E6%8A%80%E6%9C%AF%E8%A7%84%E8%8C%83?_x_tr_sl=auto&_x_tr_tl=en&_x_tr_hl=en-US#%E9%85%8D%E7%BD%AE%E9%A2%84%E8%8E%B7%E5%8F%96

Signed-off-by: Evan Goode <mail@evangoo.de>

drag-and-drop authlib-injector URL, clang-format

Resolves https://github.com/unmojang/PrismLauncher/issues/2

Signed-off-by: Evan Goode <mail@evangoo.de>
2023-09-04 19:00:18 +01:00

165 lines
6.2 KiB
C++

// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
*
* 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/>.
*
* 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.
*/
#include <QFileDialog>
#include <QFileInfo>
#include <QPainter>
#include <FileSystem.h>
#include <minecraft/services/CapeChange.h>
#include <minecraft/services/SkinUpload.h>
#include <tasks/SequentialTask.h>
#include "CustomMessageBox.h"
#include "ProgressDialog.h"
#include "SkinUploadDialog.h"
#include "ui_SkinUploadDialog.h"
void SkinUploadDialog::on_buttonBox_rejected()
{
close();
}
void SkinUploadDialog::on_buttonBox_accepted()
{
QString fileName;
QString input = ui->skinPathTextBox->text();
ProgressDialog prog(this);
SequentialTask skinUpload;
if (!input.isEmpty()) {
QRegularExpression urlPrefixMatcher(QRegularExpression::anchoredPattern("^([a-z]+)://.+$"));
bool isLocalFile = false;
// it has an URL prefix -> it is an URL
if (urlPrefixMatcher.match(input).hasMatch()) {
QUrl fileURL = input;
if (fileURL.isValid()) {
// local?
if (fileURL.isLocalFile()) {
isLocalFile = true;
fileName = fileURL.toLocalFile();
} else {
CustomMessageBox::selectable(this, tr("Skin Upload"), tr("Using remote URLs for setting skins is not implemented yet."),
QMessageBox::Warning)
->exec();
close();
return;
}
} else {
CustomMessageBox::selectable(this, tr("Skin Upload"), tr("You cannot use an invalid URL for uploading skins."),
QMessageBox::Warning)
->exec();
close();
return;
}
} else {
// just assume it's a path then
isLocalFile = true;
fileName = ui->skinPathTextBox->text();
}
if (isLocalFile && !QFile::exists(fileName)) {
CustomMessageBox::selectable(this, tr("Skin Upload"), tr("Skin file does not exist!"), QMessageBox::Warning)->exec();
close();
return;
}
SkinUpload::Model model = SkinUpload::STEVE;
if (ui->steveBtn->isChecked()) {
model = SkinUpload::STEVE;
} else if (ui->alexBtn->isChecked()) {
model = SkinUpload::ALEX;
}
skinUpload.addTask(shared_qobject_ptr<SkinUpload>(new SkinUpload(this, m_account, FS::read(fileName), model)));
}
auto selectedCape = ui->capeCombo->currentData().toString();
if (selectedCape != m_account->accountData()->minecraftProfile.currentCape) {
skinUpload.addTask(shared_qobject_ptr<CapeChange>(new CapeChange(this, m_account, selectedCape)));
}
if (prog.execWithTask(&skinUpload) != QDialog::Accepted) {
CustomMessageBox::selectable(this, tr("Skin Upload"), tr("Failed to upload skin!"), QMessageBox::Warning)->exec();
close();
return;
}
CustomMessageBox::selectable(this, tr("Skin Upload"), tr("Success"), QMessageBox::Information)->exec();
close();
}
void SkinUploadDialog::on_skinBrowseBtn_clicked()
{
auto filter = QMimeDatabase().mimeTypeForName("image/png").filterString();
QString raw_path = QFileDialog::getOpenFileName(this, tr("Select Skin Texture"), QString(), filter);
if (raw_path.isEmpty() || !QFileInfo::exists(raw_path)) {
return;
}
QString cooked_path = FS::NormalizePath(raw_path);
ui->skinPathTextBox->setText(cooked_path);
}
SkinUploadDialog::SkinUploadDialog(MinecraftAccountPtr account, QWidget* parent) : QDialog(parent), m_account(account), ui(new Ui::SkinUploadDialog)
{
ui->setupUi(this);
// FIXME: add a model for this, download/refresh the capes on demand
auto& accountData = *account->accountData();
int index = 0;
ui->capeCombo->addItem(tr("No Cape"), QVariant());
auto currentCape = accountData.minecraftProfile.currentCape;
if (currentCape.isEmpty()) {
ui->capeCombo->setCurrentIndex(index);
}
for (auto& cape : accountData.minecraftProfile.capes) {
index++;
if (cape.data.size()) {
QPixmap capeImage;
if (capeImage.loadFromData(cape.data, "PNG")) {
QPixmap preview = QPixmap(10, 16);
QPainter painter(&preview);
painter.drawPixmap(0, 0, capeImage.copy(1, 1, 10, 16));
ui->capeCombo->addItem(capeImage, cape.alias, cape.id);
if (currentCape == cape.id) {
ui->capeCombo->setCurrentIndex(index);
}
continue;
}
}
ui->capeCombo->addItem(cape.alias, cape.id);
if (currentCape == cape.id) {
ui->capeCombo->setCurrentIndex(index);
}
}
}