@ -44,32 +44,24 @@
|
||||
|
||||
#include "InstanceImportTask.h"
|
||||
|
||||
|
||||
class UrlValidator : public QValidator
|
||||
{
|
||||
public:
|
||||
class UrlValidator : public QValidator {
|
||||
public:
|
||||
using QValidator::QValidator;
|
||||
|
||||
State validate(QString &in, [[maybe_unused]] int &pos) const
|
||||
State validate(QString& in, [[maybe_unused]] int& pos) const
|
||||
{
|
||||
const QUrl url(in);
|
||||
if (url.isValid() && !url.isRelative() && !url.isEmpty())
|
||||
{
|
||||
if (url.isValid() && !url.isRelative() && !url.isEmpty()) {
|
||||
return Acceptable;
|
||||
}
|
||||
else if (QFile::exists(in))
|
||||
{
|
||||
} else if (QFile::exists(in)) {
|
||||
return Acceptable;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return Intermediate;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ImportPage::ImportPage(NewInstanceDialog* dialog, QWidget *parent)
|
||||
: QWidget(parent), ui(new Ui::ImportPage), dialog(dialog)
|
||||
ImportPage::ImportPage(NewInstanceDialog* dialog, QWidget* parent) : QWidget(parent), ui(new Ui::ImportPage), dialog(dialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->modpackEdit->setValidator(new UrlValidator(ui->modpackEdit));
|
||||
@ -98,16 +90,13 @@ void ImportPage::openedImpl()
|
||||
|
||||
void ImportPage::updateState()
|
||||
{
|
||||
if(!isOpened)
|
||||
{
|
||||
if (!isOpened) {
|
||||
return;
|
||||
}
|
||||
if(ui->modpackEdit->hasAcceptableInput())
|
||||
{
|
||||
if (ui->modpackEdit->hasAcceptableInput()) {
|
||||
QString input = ui->modpackEdit->text();
|
||||
auto url = QUrl::fromUserInput(input);
|
||||
if(url.isLocalFile())
|
||||
{
|
||||
if (url.isLocalFile()) {
|
||||
// FIXME: actually do some validation of what's inside here... this is fake AF
|
||||
QFileInfo fi(input);
|
||||
|
||||
@ -116,28 +105,23 @@ void ImportPage::updateState()
|
||||
// mrpack is a modrinth pack
|
||||
bool isMRPack = fi.suffix() == "mrpack";
|
||||
|
||||
if(fi.exists() && (isZip || isMRPack))
|
||||
{
|
||||
if (fi.exists() && (isZip || isMRPack)) {
|
||||
QFileInfo file_info(url.fileName());
|
||||
dialog->setSuggestedPack(file_info.completeBaseName(), new InstanceImportTask(url,this));
|
||||
dialog->setSuggestedPack(file_info.completeBaseName(), new InstanceImportTask(url, this));
|
||||
dialog->setSuggestedIcon("default");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(input.endsWith("?client=y")) {
|
||||
} else {
|
||||
if (input.endsWith("?client=y")) {
|
||||
input.chop(9);
|
||||
input.append("/file");
|
||||
url = QUrl::fromUserInput(input);
|
||||
}
|
||||
// hook, line and sinker.
|
||||
QFileInfo fi(url.fileName());
|
||||
dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url,this));
|
||||
dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url, this));
|
||||
dialog->setSuggestedIcon("default");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dialog->setSuggestedPack();
|
||||
}
|
||||
}
|
||||
@ -154,29 +138,21 @@ void ImportPage::on_modpackBtn_clicked()
|
||||
//: Option for filtering for *.mrpack files when importing
|
||||
filter += ";;" + tr("Modrinth pack") + " (*.mrpack)";
|
||||
const QUrl url = QFileDialog::getOpenFileUrl(this, tr("Choose modpack"), modpackUrl(), filter);
|
||||
if (url.isValid())
|
||||
{
|
||||
if (url.isLocalFile())
|
||||
{
|
||||
if (url.isValid()) {
|
||||
if (url.isLocalFile()) {
|
||||
ui->modpackEdit->setText(url.toLocalFile());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ui->modpackEdit->setText(url.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QUrl ImportPage::modpackUrl() const
|
||||
{
|
||||
const QUrl url(ui->modpackEdit->text());
|
||||
if (url.isValid() && !url.isRelative() && !url.host().isEmpty())
|
||||
{
|
||||
if (url.isValid() && !url.isRelative() && !url.host().isEmpty()) {
|
||||
return url;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return QUrl::fromLocalFile(ui->modpackEdit->text());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user