aboutsummaryrefslogtreecommitdiff
path: root/launcher
diff options
context:
space:
mode:
Diffstat (limited to 'launcher')
-rw-r--r--launcher/Application.cpp35
-rw-r--r--launcher/CMakeLists.txt21
-rw-r--r--launcher/InstanceImportTask.cpp4
-rw-r--r--launcher/ResourceDownloadTask.cpp4
-rw-r--r--launcher/WindowsConsole.cpp132
-rw-r--r--launcher/WindowsConsole.h25
-rw-r--r--launcher/filelink/FileLink.cpp27
-rw-r--r--launcher/icons/IconList.cpp241
-rw-r--r--launcher/icons/IconList.h105
-rw-r--r--launcher/icons/IconUtils.cpp90
-rw-r--r--launcher/icons/IconUtils.h40
-rw-r--r--launcher/icons/MMCIcon.cpp50
-rw-r--r--launcher/icons/MMCIcon.h65
-rw-r--r--launcher/meta/BaseEntity.cpp4
-rw-r--r--launcher/minecraft/AssetsUtils.cpp4
-rw-r--r--launcher/minecraft/Library.cpp6
-rw-r--r--launcher/minecraft/mod/ModFolderModel.cpp1
-rw-r--r--launcher/minecraft/mod/ResourceFolderModel.cpp2
-rw-r--r--launcher/minecraft/mod/ResourceFolderModel.h1
-rw-r--r--launcher/minecraft/mod/ResourcePackFolderModel.cpp2
-rw-r--r--launcher/minecraft/mod/TexturePackFolderModel.cpp1
-rw-r--r--launcher/minecraft/update/AssetUpdateTask.cpp4
-rw-r--r--launcher/minecraft/update/FMLLibrariesTask.cpp4
-rw-r--r--launcher/modplatform/atlauncher/ATLPackInstallTask.cpp14
-rw-r--r--launcher/modplatform/flame/FileResolvingTask.cpp8
-rw-r--r--launcher/modplatform/flame/FlameAPI.cpp14
-rw-r--r--launcher/modplatform/flame/FlameCheckUpdate.cpp6
-rw-r--r--launcher/modplatform/flame/FlameInstanceCreationTask.cpp3
-rw-r--r--launcher/modplatform/helpers/NetworkResourceAPI.cpp8
-rw-r--r--launcher/modplatform/legacy_ftb/PackFetchTask.cpp6
-rw-r--r--launcher/modplatform/legacy_ftb/PackInstallTask.cpp4
-rw-r--r--launcher/modplatform/modrinth/ModrinthAPI.cpp13
-rw-r--r--launcher/modplatform/modrinth/ModrinthInstanceCreationTask.cpp5
-rw-r--r--launcher/modplatform/technic/SingleZipPackInstallTask.cpp4
-rw-r--r--launcher/modplatform/technic/SolderPackInstallTask.cpp5
-rw-r--r--launcher/net/ApiDownload.cpp66
-rw-r--r--launcher/net/ApiDownload.h38
-rw-r--r--launcher/net/ApiHeaderProxy.h49
-rw-r--r--launcher/net/ApiUpload.cpp43
-rw-r--r--launcher/net/ApiUpload.h36
-rw-r--r--launcher/net/ByteArraySink.h2
-rw-r--r--launcher/net/Download.cpp267
-rw-r--r--launcher/net/Download.h47
-rw-r--r--launcher/net/HeaderProxy.h49
-rw-r--r--launcher/net/NetAction.h10
-rw-r--r--launcher/net/NetRequest.cpp331
-rw-r--r--launcher/net/NetRequest.h99
-rw-r--r--launcher/net/RawHeaderProxy.h44
-rw-r--r--launcher/net/Upload.cpp209
-rw-r--r--launcher/net/Upload.h25
-rw-r--r--launcher/screenshots/ImgurAlbumCreation.h2
-rw-r--r--launcher/screenshots/ImgurUpload.h1
-rw-r--r--launcher/ui/dialogs/NewInstanceDialog.cpp11
-rw-r--r--launcher/ui/dialogs/SkinUploadDialog.ui2
-rw-r--r--launcher/ui/pages/global/ExternalToolsPage.ui8
-rw-r--r--launcher/ui/pages/global/JavaPage.ui150
-rw-r--r--launcher/ui/pages/global/LauncherPage.ui8
-rw-r--r--launcher/ui/pages/instance/InstanceSettingsPage.ui62
-rw-r--r--launcher/ui/pages/instance/ManagedPackPage.cpp6
-rw-r--r--launcher/ui/pages/modplatform/ResourceModel.cpp4
-rw-r--r--launcher/ui/pages/modplatform/atlauncher/AtlListModel.cpp11
-rw-r--r--launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.cpp4
-rw-r--r--launcher/ui/pages/modplatform/flame/FlameModel.cpp18
-rw-r--r--launcher/ui/pages/modplatform/flame/FlamePage.cpp15
-rw-r--r--launcher/ui/pages/modplatform/legacy_ftb/ListModel.cpp7
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp13
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp6
-rw-r--r--launcher/ui/pages/modplatform/technic/TechnicModel.cpp10
-rw-r--r--launcher/ui/pages/modplatform/technic/TechnicPage.cpp17
-rw-r--r--launcher/ui/widgets/PageContainer_p.h2
-rw-r--r--launcher/ui/widgets/VariableSizedImageObject.cpp3
-rw-r--r--launcher/ui/widgets/WideBar.cpp4
72 files changed, 1549 insertions, 1088 deletions
diff --git a/launcher/Application.cpp b/launcher/Application.cpp
index 7bfcce5f..e89b7659 100644
--- a/launcher/Application.cpp
+++ b/launcher/Application.cpp
@@ -135,13 +135,8 @@
#include "updater/MacSparkleUpdater.h"
#endif
-
#if defined Q_OS_WIN32
-#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN
-#endif
-#include <windows.h>
-#include <stdio.h>
+#include "WindowsConsole.h"
#endif
#define STRINGIFY(x) #x
@@ -168,31 +163,15 @@ void appDebugOutput(QtMsgType type, const QMessageLogContext &context, const QSt
fflush(stderr);
}
-}
+} // namespace
-Application::Application(int &argc, char **argv) : QApplication(argc, argv)
+
+
+Application::Application(int& argc, char** argv) : QApplication(argc, argv)
{
#if defined Q_OS_WIN32
- // attach the parent console
- if(AttachConsole(ATTACH_PARENT_PROCESS))
- {
- // if attach succeeds, reopen and sync all the i/o
- if(freopen("CON", "w", stdout))
- {
- std::cout.sync_with_stdio();
- }
- if(freopen("CON", "w", stderr))
- {
- std::cerr.sync_with_stdio();
- }
- if(freopen("CON", "r", stdin))
- {
- std::cin.sync_with_stdio();
- }
- auto out = GetStdHandle (STD_OUTPUT_HANDLE);
- DWORD written;
- const char * endline = "\n";
- WriteConsole(out, endline, strlen(endline), &written, NULL);
+ // attach the parent console if stdout not already captured
+ if (AttachWindowsConsole()) {
consoleAttached = true;
}
#endif
diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt
index 3ea88013..5255f9d3 100644
--- a/launcher/CMakeLists.txt
+++ b/launcher/CMakeLists.txt
@@ -136,6 +136,15 @@ set(NET_SOURCES
net/Validator.h
net/Upload.cpp
net/Upload.h
+ net/HeaderProxy.h
+ net/RawHeaderProxy.h
+ net/ApiHeaderProxy.h
+ net/ApiDownload.h
+ net/ApiDownload.cpp
+ net/ApiUpload.cpp
+ net/ApiUpload.h
+ net/NetRequest.cpp
+ net/NetRequest.h
)
# Game launch logic
@@ -566,6 +575,9 @@ set(ATLAUNCHER_SOURCES
)
set(LINKEXE_SOURCES
+ WindowsConsole.cpp
+ WindowsConsole.h
+
filelink/FileLink.h
filelink/FileLink.cpp
FileSystem.h
@@ -1028,6 +1040,14 @@ SET(LAUNCHER_SOURCES
ui/instanceview/VisualGroup.h
)
+if(WIN32)
+ set(LAUNCHER_SOURCES
+ WindowsConsole.cpp
+ WindowsConsole.h
+ ${LAUNCHER_SOURCES}
+ )
+endif()
+
qt_wrap_ui(LAUNCHER_UI
ui/MainWindow.ui
ui/setupwizard/PasteWizardPage.ui
@@ -1113,6 +1133,7 @@ endif()
# Add executable
add_library(Launcher_logic STATIC ${LOGIC_SOURCES} ${LAUNCHER_SOURCES} ${LAUNCHER_UI} ${LAUNCHER_RESOURCES})
+target_compile_definitions(Launcher_logic PUBLIC LAUNCHER_APPLICATION)
target_include_directories(Launcher_logic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(Launcher_logic
systeminfo
diff --git a/launcher/InstanceImportTask.cpp b/launcher/InstanceImportTask.cpp
index d6a96deb..98ed14b9 100644
--- a/launcher/InstanceImportTask.cpp
+++ b/launcher/InstanceImportTask.cpp
@@ -51,6 +51,8 @@
#include "settings/INISettingsObject.h"
+#include "net/ApiDownload.h"
+
#include <QtConcurrentRun>
#include <algorithm>
@@ -95,7 +97,7 @@ void InstanceImportTask::executeTask()
m_archivePath = entry->getFullPath();
m_filesNetJob.reset(new NetJob(tr("Modpack download"), APPLICATION->network()));
- m_filesNetJob->addNetAction(Net::Download::makeCached(m_sourceUrl, entry));
+ m_filesNetJob->addNetAction(Net::ApiDownload::makeCached(m_sourceUrl, entry));
connect(m_filesNetJob.get(), &NetJob::succeeded, this, &InstanceImportTask::downloadSucceeded);
connect(m_filesNetJob.get(), &NetJob::progress, this, &InstanceImportTask::downloadProgressChanged);
diff --git a/launcher/ResourceDownloadTask.cpp b/launcher/ResourceDownloadTask.cpp
index 8bb9b64e..a02151ca 100644
--- a/launcher/ResourceDownloadTask.cpp
+++ b/launcher/ResourceDownloadTask.cpp
@@ -24,6 +24,8 @@
#include "minecraft/mod/ModFolderModel.h"
#include "minecraft/mod/ResourceFolderModel.h"
+#include "net/ApiDownload.h"
+
ResourceDownloadTask::ResourceDownloadTask(ModPlatform::IndexedPack::Ptr pack,
ModPlatform::IndexedVersion version,
const std::shared_ptr<ResourceFolderModel> packs,
@@ -51,7 +53,7 @@ ResourceDownloadTask::ResourceDownloadTask(ModPlatform::IndexedPack::Ptr pack,
}
}
- m_filesNetJob->addNetAction(Net::Download::makeFile(m_pack_version.downloadUrl, dir.absoluteFilePath(getFilename())));
+ m_filesNetJob->addNetAction(Net::ApiDownload::makeFile(m_pack_version.downloadUrl, dir.absoluteFilePath(getFilename())));
connect(m_filesNetJob.get(), &NetJob::succeeded, this, &ResourceDownloadTask::downloadSucceeded);
connect(m_filesNetJob.get(), &NetJob::progress, this, &ResourceDownloadTask::downloadProgressChanged);
connect(m_filesNetJob.get(), &NetJob::stepProgress, this, &ResourceDownloadTask::propagateStepProgress);
diff --git a/launcher/WindowsConsole.cpp b/launcher/WindowsConsole.cpp
new file mode 100644
index 00000000..860af01f
--- /dev/null
+++ b/launcher/WindowsConsole.cpp
@@ -0,0 +1,132 @@
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2022 Rachel Powers <508861+Ryex@users.noreply.github.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/>.
+ *
+ */
+
+
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#include <fcntl.h>
+#include <io.h>
+#include <stdio.h>
+#include <windows.h>
+#include <iostream>
+
+void RedirectHandle(DWORD handle, FILE* stream, const char* mode ) {
+
+ HANDLE stdHandle = GetStdHandle(handle);
+ if (stdHandle != INVALID_HANDLE_VALUE) {
+ int fileDescriptor = _open_osfhandle((intptr_t)stdHandle, _O_TEXT);
+ if (fileDescriptor != -1) {
+ FILE* file = _fdopen(fileDescriptor, mode);
+ if (file != NULL) {
+ int dup2Result = _dup2(_fileno(file), _fileno(stream));
+ if (dup2Result == 0) {
+ setvbuf(stream, NULL, _IONBF, 0);
+ }
+ }
+ }
+ }
+
+}
+
+// taken from https://stackoverflow.com/a/25927081
+// getting a proper output to console with redirection support on windows is apparently hell
+void BindCrtHandlesToStdHandles(bool bindStdIn, bool bindStdOut, bool bindStdErr)
+{
+ // Re-initialize the C runtime "FILE" handles with clean handles bound to "nul". We do this because it has been
+ // observed that the file number of our standard handle file objects can be assigned internally to a value of -2
+ // when not bound to a valid target, which represents some kind of unknown internal invalid state. In this state our
+ // call to "_dup2" fails, as it specifically tests to ensure that the target file number isn't equal to this value
+ // before allowing the operation to continue. We can resolve this issue by first "re-opening" the target files to
+ // use the "nul" device, which will place them into a valid state, after which we can redirect them to our target
+ // using the "_dup2" function.
+ if (bindStdIn) {
+ FILE* dummyFile;
+ freopen_s(&dummyFile, "nul", "r", stdin);
+ }
+ if (bindStdOut) {
+ FILE* dummyFile;
+ freopen_s(&dummyFile, "nul", "w", stdout);
+ }
+ if (bindStdErr) {
+ FILE* dummyFile;
+ freopen_s(&dummyFile, "nul", "w", stderr);
+ }
+
+ // Redirect unbuffered stdin from the current standard input handle
+ if (bindStdIn) {
+ RedirectHandle(STD_INPUT_HANDLE, stdin, "r");
+ }
+
+ // Redirect unbuffered stdout to the current standard output handle
+ if (bindStdOut) {
+ RedirectHandle(STD_OUTPUT_HANDLE, stdout, "w");
+ }
+
+ // Redirect unbuffered stderr to the current standard error handle
+ if (bindStdErr) {
+ RedirectHandle(STD_ERROR_HANDLE, stderr, "w");
+ }
+
+ // Clear the error state for each of the C++ standard stream objects. We need to do this, as attempts to access the
+ // standard streams before they refer to a valid target will cause the iostream objects to enter an error state. In
+ // versions of Visual Studio after 2005, this seems to always occur during startup regardless of whether anything
+ // has been read from or written to the targets or not.
+ if (bindStdIn) {
+ std::wcin.clear();
+ std::cin.clear();
+ }
+ if (bindStdOut) {
+ std::wcout.clear();
+ std::cout.clear();
+ }
+ if (bindStdErr) {
+ std::wcerr.clear();
+ std::cerr.clear();
+ }
+}
+
+
+bool AttachWindowsConsole() {
+ auto stdinType = GetFileType(GetStdHandle(STD_INPUT_HANDLE));
+ auto stdoutType = GetFileType(GetStdHandle(STD_OUTPUT_HANDLE));
+ auto stderrType = GetFileType(GetStdHandle(STD_ERROR_HANDLE));
+
+ bool bindStdIn = false;
+ bool bindStdOut = false;
+ bool bindStdErr = false;
+
+ if (stdinType == FILE_TYPE_CHAR || stdinType == FILE_TYPE_UNKNOWN) {
+ bindStdIn = true;
+ }
+ if (stdoutType == FILE_TYPE_CHAR || stdoutType == FILE_TYPE_UNKNOWN) {
+ bindStdOut = true;
+ }
+ if (stderrType == FILE_TYPE_CHAR || stderrType == FILE_TYPE_UNKNOWN) {
+ bindStdErr = true;
+ }
+
+ if (AttachConsole(ATTACH_PARENT_PROCESS)) {
+ BindCrtHandlesToStdHandles(bindStdIn, bindStdOut, bindStdErr);
+ return true;
+ }
+
+ return false;
+}
+
+
diff --git a/launcher/WindowsConsole.h b/launcher/WindowsConsole.h
new file mode 100644
index 00000000..ab53864b
--- /dev/null
+++ b/launcher/WindowsConsole.h
@@ -0,0 +1,25 @@
+//
+// SPDX-License-Identifier: GPL-3.0-only
+
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2022 Rachel Powers <508861+Ryex@users.noreply.github.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/>.
+ *
+ */
+
+#pragma once
+
+void BindCrtHandlesToStdHandles(bool bindStdIn, bool bindStdOut, bool bindStdErr);
+bool AttachWindowsConsole();
diff --git a/launcher/filelink/FileLink.cpp b/launcher/filelink/FileLink.cpp
index c9599b82..fb0f5fcc 100644
--- a/launcher/filelink/FileLink.cpp
+++ b/launcher/filelink/FileLink.cpp
@@ -37,11 +37,7 @@
#include <sys.h>
#if defined Q_OS_WIN32
-#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN
-#endif
-#include <stdio.h>
-#include <windows.h>
+#include "WindowsConsole.h"
#endif
// Snippet from https://github.com/gulrak/filesystem#using-it-as-single-file-header
@@ -67,21 +63,7 @@ FileLinkApp::FileLinkApp(int& argc, char** argv) : QCoreApplication(argc, argv),
{
#if defined Q_OS_WIN32
// attach the parent console
- if (AttachConsole(ATTACH_PARENT_PROCESS)) {
- // if attach succeeds, reopen and sync all the i/o
- if (freopen("CON", "w", stdout)) {
- std::cout.sync_with_stdio();
- }
- if (freopen("CON", "w", stderr)) {
- std::cerr.sync_with_stdio();
- }
- if (freopen("CON", "r", stdin)) {
- std::cin.sync_with_stdio();
- }
- auto out = GetStdHandle(STD_OUTPUT_HANDLE);
- DWORD written;
- const char* endline = "\n";
- WriteConsole(out, endline, strlen(endline), &written, NULL);
+ if (AttachWindowsConsole()) {
consoleAttached = true;
}
#endif
@@ -188,7 +170,7 @@ void FileLinkApp::runLink()
FS::LinkResult result = { src_path, dst_path, QString::fromStdString(os_err.message()), os_err.value() };
m_path_results.append(result);
} else {
- FS::LinkResult result = { src_path, dst_path };
+ FS::LinkResult result = { src_path, dst_path, "", 0};
m_path_results.append(result);
}
}
@@ -248,7 +230,7 @@ void FileLinkApp::readPathPairs()
in >> numLinks;
qDebug() << "numLinks" << numLinks;
- for (int i = 0; i < numLinks; i++) {
+ for (unsigned int i = 0; i < numLinks; i++) {
FS::LinkPair pair;
in >> pair.src;
in >> pair.dst;
@@ -271,7 +253,6 @@ FileLinkApp::~FileLinkApp()
fclose(stdout);
fclose(stdin);
fclose(stderr);
- FreeConsole();
}
#endif
}
diff --git a/launcher/icons/IconList.cpp b/launcher/icons/IconList.cpp
index 13174f6e..5576b974 100644
--- a/launcher/icons/IconList.cpp
+++ b/launcher/icons/IconList.cpp
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
- * PolyMC - Minecraft Launcher
+ * Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
+ * Copyright (c) 2023 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
@@ -35,32 +36,30 @@
#include "IconList.h"
#include <FileSystem.h>
-#include <QMap>
+#include <QDebug>
#include <QEventLoop>
-#include <QMimeData>
-#include <QUrl>
#include <QFileSystemWatcher>
+#include <QMap>
+#include <QMimeData>
#include <QSet>
-#include <QDebug>
+#include <QUrl>
+#include "icons/IconUtils.h"
#define MAX_SIZE 1024
-IconList::IconList(const QStringList &builtinPaths, QString path, QObject *parent) : QAbstractListModel(parent)
+IconList::IconList(const QStringList& builtinPaths, QString path, QObject* parent) : QAbstractListModel(parent)
{
QSet<QString> builtinNames;
// add builtin icons
- for(auto & builtinPath: builtinPaths)
- {
+ for (auto& builtinPath : builtinPaths) {
QDir instance_icons(builtinPath);
auto file_info_list = instance_icons.entryInfoList(QDir::Files, QDir::Name);
- for (auto file_info : file_info_list)
- {
+ for (auto file_info : file_info_list) {
builtinNames.insert(file_info.completeBaseName());
}
}
- for(auto & builtinName : builtinNames)
- {
+ for (auto& builtinName : builtinNames) {
addThemeIcon(builtinName);
}
@@ -78,31 +77,27 @@ IconList::IconList(const QStringList &builtinPaths, QString path, QObject *paren
void IconList::sortIconList()
{
qDebug() << "Sorting icon list...";
- std::sort(icons.begin(), icons.end(), [](const MMCIcon& a, const MMCIcon& b) {
- return a.m_key.localeAwareCompare(b.m_key) < 0;
- });
+ std::sort(icons.begin(), icons.end(), [](const MMCIcon& a, const MMCIcon& b) { return a.m_key.localeAwareCompare(b.m_key) < 0; });
reindex();
}
-void IconList::directoryChanged(const QString &path)
+void IconList::directoryChanged(const QString& path)
{
- QDir new_dir (path);
- if(m_dir.absolutePath() != new_dir.absolutePath())
- {
+ QDir new_dir(path);
+ if (m_dir.absolutePath() != new_dir.absolutePath()) {
m_dir.setPath(path);
m_dir.refresh();
- if(is_watching)
+ if (is_watching)
stopWatching();
startWatching();
}
- if(!m_dir.exists())
- if(!FS::ensureFolderPathExists(m_dir.absolutePath()))
+ if (!m_dir.exists())
+ if (!FS::ensureFolderPathExists(m_dir.absolutePath()))
return;
m_dir.refresh();
auto new_list = m_dir.entryList(QDir::Files, QDir::Name);
- for (auto it = new_list.begin(); it != new_list.end(); it++)
- {
- QString &foo = (*it);
+ for (auto it = new_list.begin(); it != new_list.end(); it++) {
+ QString& foo = (*it);
foo = m_dir.filePath(foo);
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
@@ -111,8 +106,7 @@ void IconList::directoryChanged(const QString &path)
auto new_set = new_list.toSet();
#endif
QList<QString> current_list;
- for (auto &it : icons)
- {
+ for (auto& it : icons) {
if (!it.has(IconType::FileBased))
continue;
current_list.push_back(it.m_images[IconType::FileBased].filename);
@@ -129,38 +123,33 @@ void IconList::directoryChanged(const QString &path)
QSet<QString> to_add = new_set;
to_add -= current_set;
- for (auto remove : to_remove)
- {
+ for (auto remove : to_remove) {
qDebug() << "Removing " << remove;
QFileInfo rmfile(remove);
QString key = rmfile.completeBaseName();
QString suffix = rmfile.suffix();
// The icon doesnt have a suffix, but it can have other .s in the name, so we account for those as well
- if (suffix != "jpeg" && suffix != "png" && suffix != "jpg" && suffix != "ico" && suffix != "svg" && suffix != "gif")
+ if (!IconUtils::isIconSuffix(suffix))
key = rmfile.fileName();
int idx = getIconIndex(key);
if (idx == -1)
continue;
icons[idx].remove(IconType::FileBased);
- if (icons[idx].type() == IconType::ToBeDeleted)
- {
+ if (icons[idx].type() == IconType::ToBeDeleted) {
beginRemoveRows(QModelIndex(), idx, idx);
icons.remove(idx);
reindex();
endRemoveRows();
- }
- else
- {
+ } else {
dataChanged(index(idx), index(idx));
}
m_watcher->removePath(remove);
emit iconUpdated(key);
}
- for (auto add : to_add)
- {
+ for (auto add : to_add) {
qDebug() << "Adding " << add;
QFileInfo addfile(add);
@@ -168,11 +157,10 @@ void IconList::directoryChanged(const QString &path)
QString suffix = addfile.suffix();
// The icon doesnt have a suffix, but it can have other .s in the name, so we account for those as well
- if (suffix != "jpeg" && suffix != "png" && suffix != "jpg" && suffix != "ico" && suffix != "svg" && suffix != "gif")
+ if (!IconUtils::isIconSuffix(suffix))
key = addfile.fileName();
- if (addIcon(key, QString(), addfile.filePath(), IconType::FileBased))
- {
+ if (addIcon(key, QString(), addfile.filePath(), IconType::FileBased)) {
m_watcher->addPath(add);
emit iconUpdated(key);
}
@@ -181,7 +169,7 @@ void IconList::directoryChanged(const QString &path)
sortIconList();
}
-void IconList::fileChanged(const QString &path)
+void IconList::fileChanged(const QString& path)
{
qDebug() << "Checking " << path;
QFileInfo checkfile(path);
@@ -200,9 +188,9 @@ void IconList::fileChanged(const QString &path)
emit iconUpdated(key);
}
-void IconList::SettingChanged(const Setting &setting, QVariant value)
+void IconList::SettingChanged(const Setting& setting, QVariant value)
{
- if(setting.id() != "IconsDir")
+ if (setting.id() != "IconsDir")
return;
directoryChanged(value.toString());
@@ -213,12 +201,9 @@ void IconList::startWatching()
auto abs_path = m_dir.absolutePath();
FS::ensureFolderPathExists(abs_path);
is_watching = m_watcher->addPath(abs_path);
- if (is_watching)
- {
+ if (is_watching) {
qDebug() << "Started watching " << abs_path;
- }
- else
- {
+ } else {
qDebug() << "Failed to start watching " << abs_path;
}
}
@@ -241,7 +226,11 @@ Qt::DropActions IconList::supportedDropActions() const
return Qt::CopyAction;
}
-bool IconList::dropMimeData(const QMimeData *data, Qt::DropAction action, [[maybe_unused]] int row, [[maybe_unused]] int column, [[maybe_unused]] const QModelIndex &parent)
+bool IconList::dropMimeData(const QMimeData* data,
+ Qt::DropAction action,
+ [[maybe_unused]] int row,
+ [[maybe_unused]] int column,
+ [[maybe_unused]] const QModelIndex& parent)
{
if (action == Qt::IgnoreAction)
return true;
@@ -250,12 +239,10 @@ bool IconList::dropMimeData(const QMimeData *data, Qt::DropAction action, [[mayb
return false;
// files dropped from outside?
- if (data->hasUrls())
- {
+ if (data->hasUrls()) {
auto urls = data->urls();
QStringList iconFiles;
- for (auto url : urls)
- {
+ for (auto url : urls) {
// only local files may be dropped...
if (!url.isLocalFile())
continue;
@@ -267,16 +254,13 @@ bool IconList::dropMimeData(const QMimeData *data, Qt::DropAction action, [[mayb
return false;
}
-Qt::ItemFlags IconList::flags(const QModelIndex &index) const
+Qt::ItemFlags IconList::flags(const QModelIndex& index) const
{
Qt::ItemFlags defaultFlags = QAbstractListModel::flags(index);
- if (index.isValid())
- return Qt::ItemIsDropEnabled | defaultFlags;
- else
- return Qt::ItemIsDropEnabled | defaultFlags;
+ return Qt::ItemIsDropEnabled | defaultFlags;
}
-QVariant IconList::data(const QModelIndex &index, int role) const
+QVariant IconList::data(const QModelIndex& index, int role) const
{
if (!index.isValid())
return QVariant();
@@ -286,64 +270,49 @@ QVariant IconList::data(const QModelIndex &index, int role) const
if (row < 0 || row >= icons.size())
return QVariant();
- switch (role)
- {
- case Qt::DecorationRole:
- return icons[row].icon();
- case Qt::DisplayRole:
- return icons[row].name();
- case Qt::UserRole:
- return icons[row].m_key;
- default:
- return QVariant();
+ switch (role) {
+ case Qt::DecorationRole:
+ return icons[row].icon();
+ case Qt::DisplayRole:
+ return icons[row].name();
+ case Qt::UserRole:
+ return icons[row].m_key;
+ default:
+ return QVariant();
}
}
-int IconList::rowCount(const QModelIndex &parent) const
+int IconList::rowCount(const QModelIndex& parent) const
{
return parent.isValid() ? 0 : icons.size();
}
-void IconList::installIcons(const QStringList &iconFiles)
+void IconList::installIcons(const QStringList& iconFiles)
{
for (QString file : iconFiles)
- {
- QFileInfo fileinfo(file);
- if (!fileinfo.isReadable() || !fileinfo.isFile())
- continue;
- QString target = FS::PathCombine(getDirectory(), fileinfo.fileName());
-
- QString suffix = fileinfo.suffix();
- if (suffix != "jpeg" && suffix != "png" && suffix != "jpg" && suffix != "ico" && suffix != "svg" && suffix != "gif")
- continue;
-
- if (!QFile::copy(file, target))
- continue;
- }
+ installIcon(file, {});
}
-void IconList::installIcon(const QString &file, const QString &name)
+void IconList::installIcon(const QString& file, const QString& name)
{
QFileInfo fileinfo(file);
- if(!fileinfo.isReadable() || !fileinfo.isFile())
+ if (!fileinfo.isReadable() || !fileinfo.isFile())
return;
- QString target = FS::PathCombine(getDirectory(), name);
+ if (!IconUtils::isIconSuffix(fileinfo.suffix()))
+ return;
+ QString target = FS::PathCombine(getDirectory(), name.isEmpty() ? fileinfo.fileName() : name);
QFile::copy(file, target);
}
-bool IconList::iconFileExists(const QString &key) const
+bool IconList::iconFileExists(const QString& key) const
{
auto iconEntry = icon(key);
- if(!iconEntry)
- {
- return false;
- }
- return iconEntry->has(IconType::FileBased);
+ return iconEntry && iconEntry->has(IconType::FileBased);
}
-const MMCIcon *IconList::icon(const QString &key) const
+const MMCIcon* IconList::icon(const QString& key) const
{
int iconIdx = getIconIndex(key);
if (iconIdx == -1)
@@ -351,100 +320,84 @@ const MMCIcon *IconList::icon(const QString &key) const
return &icons[iconIdx];
}
-bool IconList::deleteIcon(const QString &key)
+bool IconList::deleteIcon(const QString& key)
{
- if (!iconFileExists(key))
- return false;
-
- return QFile::remove(icon(key)->getFilePath());
+ return iconFileExists(key) && QFile::remove(icon(key)->getFilePath());
}
-bool IconList::trashIcon(const QString &key)
+bool IconList::trashIcon(const QString& key)
{
- if (!iconFileExists(key))
- return false;
-
- return FS::trash(icon(key)->getFilePath(), nullptr);
+ return iconFileExists(key) && FS::trash(icon(key)->getFilePath(), nullptr);
}
bool IconList::addThemeIcon(const QString& key)
{
auto iter = name_index.find(key);
- if (iter != name_index.end())
- {
- auto &oldOne = icons[*iter];
+ if (iter != name_index.end()) {
+ auto& oldOne = icons[*iter];
oldOne.replace(Builtin, key);
dataChanged(index(*iter), index(*iter));
return true;
}
- else
+ // add a new icon
+ beginInsertRows(QModelIndex(), icons.size(), icons.size());
{
- // add a new icon
- beginInsertRows(QModelIndex(), icons.size(), icons.size());
- {
- MMCIcon mmc_icon;
- mmc_icon.m_name = key;
- mmc_icon.m_key = key;
- mmc_icon.replace(Builtin, key);
- icons.push_back(mmc_icon);
- name_index[key] = icons.size() - 1;
- }
- endInsertRows();
- return true;
+ MMCIcon mmc_icon;
+ mmc_icon.m_name = key;
+ mmc_icon.m_key = key;
+ mmc_icon.replace(Builtin, key);
+ icons.push_back(mmc_icon);
+ name_index[key] = icons.size() - 1;
}
+ endInsertRows();
+ return true;
}
-bool IconList::addIcon(const QString &key, const QString &name, const QString &path, const IconType type)
+bool IconList::addIcon(const QString& key, const QString& name, const QString& path, const IconType type)
{
// replace the icon even? is the input valid?
QIcon icon(path);
if (icon.isNull())
return false;
auto iter = name_index.find(key);
- if (iter != name_index.end())
- {
- auto &oldOne = icons[*iter];
+ if (iter != name_index.end()) {
+ auto& oldOne = icons[*iter];
oldOne.replace(type, icon, path);
dataChanged(index(*iter), index(*iter));
return true;
}
- else
+ // add a new icon
+ beginInsertRows(QModelIndex(), icons.size(), icons.size());
{
- // add a new icon
- beginInsertRows(QModelIndex(), icons.size(), icons.size());
- {
- MMCIcon mmc_icon;
- mmc_icon.m_name = name;
- mmc_icon.m_key = key;
- mmc_icon.replace(type, icon, path);
- icons.push_back(mmc_icon);
- name_index[key] = icons.size() - 1;
- }
- endInsertRows();
- return true;
+ MMCIcon mmc_icon;
+ mmc_icon.m_name = name;
+ mmc_icon.m_key = key;
+ mmc_icon.replace(type, icon, path);
+ icons.push_back(mmc_icon);
+ name_index[key] = icons.size() - 1;
}
+ endInsertRows();
+ return true;
}
-void IconList::saveIcon(const QString &key, const QString &path, const char * format) const
+void IconList::saveIcon(const QString& key, const QString& path, const char* format) const
{
auto icon = getIcon(key);
auto pixmap = icon.pixmap(128, 128);
pixmap.save(path, format);
}
-
void IconList::reindex()
{
name_index.clear();
int i = 0;
- for (auto &iter : icons)
- {
+ for (auto& iter : icons) {
name_index[iter.m_key] = i;
i++;
}
}
-QIcon IconList::getIcon(const QString &key) const
+QIcon IconList::getIcon(const QString& key) const
{
int icon_index = getIconIndex(key);
@@ -459,7 +412,7 @@ QIcon IconList::getIcon(const QString &key) const
return QIcon();
}
-int IconList::getIconIndex(const QString &key) const
+int IconList::getIconIndex(const QString& key) const
{
auto iter = name_index.find(key == "default" ? "grass" : key);
if (iter != name_index.end())
@@ -472,5 +425,3 @@ QString IconList::getDirectory() const
{
return m_dir.absolutePath();
}
-
-//#include "IconList.moc"
diff --git a/launcher/icons/IconList.h b/launcher/icons/IconList.h
index 97141e4a..8afd0557 100644
--- a/launcher/icons/IconList.h
+++ b/launcher/icons/IconList.h
@@ -1,24 +1,43 @@
-/* Copyright 2013-2021 MultiMC Contributors
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
*
- * 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
+ * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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.
*
- * 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.
+ * 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.
*/
-
#pragma once
-#include <QMutex>
#include <QAbstractListModel>
-#include <QFile>
#include <QDir>
+#include <QFile>
+#include <QMutex>
#include <QtGui/QIcon>
#include <memory>
@@ -29,58 +48,58 @@
class QFileSystemWatcher;
-class IconList : public QAbstractListModel
-{
+class IconList : public QAbstractListModel {
Q_OBJECT
-public:
- explicit IconList(const QStringList &builtinPaths, QString path, QObject *parent = 0);
- virtual ~IconList() {};
+ public:
+ explicit IconList(const QStringList& builtinPaths, QString path, QObject* parent = 0);
+ virtual ~IconList(){};
- QIcon getIcon(const QString &key) const;
- int getIconIndex(const QString &key) const;
+ QIcon getIcon(const QString& key) const;
+ int getIconIndex(const QString& key) const;
QString getDirectory() const;
- virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
- virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
+ virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
+ virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
virtual QStringList mimeTypes() const override;
virtual Qt::DropActions supportedDropActions() const override;
- virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
- virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
+ virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) override;
+ virtual Qt::ItemFlags flags(const QModelIndex& index) const override;
- bool addThemeIcon(const QString &key);
- bool addIcon(const QString &key, const QString &name, const QString &path, const IconType type);
- void saveIcon(const QString &key, const QString &path, const char * format) const;
- bool deleteIcon(const QString &key);
- bool trashIcon(const QString &key);
- bool iconFileExists(const QString &key) const;
+ bool addThemeIcon(const QString& key);
+ bool addIcon(const QString& key, const QString& name, const QString& path, const IconType type);
+ void saveIcon(const QString& key, const QString& path, const char* format) const;
+ bool deleteIcon(const QString& key);
+ bool trashIcon(const QString& key);
+ bool iconFileExists(const QString& key) const;
- void installIcons(const QStringList &iconFiles);
- void installIcon(const QString &file, const QString &name);
+ void installIcons(const QStringList& iconFiles);
+ void installIcon(const QString& file, const QString& name);
- const MMCIcon * icon(const QString &key) const;
+ const MMCIcon* icon(const QString& key) const;
void startWatching();
void stopWatching();
-signals:
+ signals:
void iconUpdated(QString key);
-private:
+ private:
// hide copy constructor
- IconList(const IconList &) = delete;
+ IconList(const IconList&) = delete;
// hide assign op
- IconList &operator=(const IconList &) = delete;
+ IconList& operator=(const IconList&) = delete;
void reindex();
void sortIconList();
-public slots:
- void directoryChanged(const QString &path);
+ public slots:
+ void directoryChanged(const QString& path);
+
+ protected slots:
+ void fileChanged(const QString& path);
+ void SettingChanged(const Setting& setting, QVariant value);
-protected slots:
- void fileChanged(const QString &path);
- void SettingChanged(const Setting & setting, QVariant value);
-private:
+ private:
shared_qobject_ptr<QFileSystemWatcher> m_watcher;
bool is_watching;
QMap<QString, int> name_index;
diff --git a/launcher/icons/IconUtils.cpp b/launcher/icons/IconUtils.cpp
index bf530c16..99c38f47 100644
--- a/launcher/icons/IconUtils.cpp
+++ b/launcher/icons/IconUtils.cpp
@@ -1,25 +1,51 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (c) 2023 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/>.
+ *
+ * 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 "IconUtils.h"
-#include "FileSystem.h"
#include <QDirIterator>
-
-#include <array>
+#include "FileSystem.h"
namespace {
-std::array<const char *, 6> validIconExtensions = {{
- "svg",
- "png",
- "ico",
- "gif",
- "jpg",
- "jpeg"
-}};
+static const QStringList validIconExtensions = { { "svg", "png", "ico", "gif", "jpg", "jpeg" } };
}
-namespace IconUtils{
+namespace IconUtils {
-QString findBestIconIn(const QString &folder, const QString & iconKey) {
- int best_found = validIconExtensions.size();
+QString findBestIconIn(const QString& folder, const QString& iconKey)
+{
QString best_filename;
QDirIterator it(folder, QDir::NoDotAndDotDot | QDir::Files, QDirIterator::NoIteratorFlags);
@@ -27,36 +53,20 @@ QString findBestIconIn(const QString &folder, const QString & iconKey) {
it.next();
auto fileInfo = it.fileInfo();
- if(fileInfo.completeBaseName() != iconKey)
- continue;
-
- auto extension = fileInfo.suffix();
-
- for(int i = 0; i < best_found; i++) {
- if(extension == validIconExtensions[i]) {
- best_found = i;
- qDebug() << i << " : " << fileInfo.fileName();
- best_filename = fileInfo.fileName();
- }
- }
+ if (fileInfo.completeBaseName() == iconKey && isIconSuffix(fileInfo.suffix()))
+ return fileInfo.absoluteFilePath();
}
- return FS::PathCombine(folder, best_filename);
+ return {};
}
-QString getIconFilter() {
- QString out;
- QTextStream stream(&out);
- stream << '(';
- for(size_t i = 0; i < validIconExtensions.size() - 1; i++) {
- if(i > 0) {
- stream << " ";
- }
- stream << "*." << validIconExtensions[i];
- }
- stream << " *." << validIconExtensions[validIconExtensions.size() - 1];
- stream << ')';
- return out;
+QString getIconFilter()
+{
+ return "(*." + validIconExtensions.join(" *.") + ")";
}
+bool isIconSuffix(QString suffix)
+{
+ return validIconExtensions.contains(suffix);
}
+} // namespace IconUtils
diff --git a/launcher/icons/IconUtils.h b/launcher/icons/IconUtils.h
index be93d914..90cdfe5a 100644
--- a/launcher/icons/IconUtils.h
+++ b/launcher/icons/IconUtils.h
@@ -1,3 +1,38 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (c) 2023 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/>.
+ *
+ * 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.
+ */
+
#pragma once
#include <QString>
@@ -5,9 +40,10 @@
namespace IconUtils {
// Given a folder and an icon key, find 'best' of the icons with the given key in there and return its path
-QString findBestIconIn(const QString &folder, const QString & iconKey);
+QString findBestIconIn(const QString& folder, const QString& iconKey);
// Get icon file type filter for file browser dialogs
QString getIconFilter();
-}
+bool isIconSuffix(QString suffix);
+} // namespace IconUtils
diff --git a/launcher/icons/MMCIcon.cpp b/launcher/icons/MMCIcon.cpp
index 436ef75f..991b470c 100644
--- a/launcher/icons/MMCIcon.cpp
+++ b/launcher/icons/MMCIcon.cpp
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
- * PolyMC - Minecraft Launcher
+ * Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
+ * Copyright (c) 2023 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
@@ -37,23 +38,21 @@
#include <QFileInfo>
#include <QIcon>
-IconType operator--(IconType &t, int)
+IconType operator--(IconType& t, int)
{
IconType temp = t;
- switch (t)
- {
- case IconType::Builtin:
- t = IconType::ToBeDeleted;
- break;
- case IconType::Transient:
- t = IconType::Builtin;
- break;
- case IconType::FileBased:
- t = IconType::Transient;
- break;
- default:
- {
- }
+ switch (t) {
+ case IconType::Builtin:
+ t = IconType::ToBeDeleted;
+ break;
+ case IconType::Transient:
+ t = IconType::Builtin;
+ break;
+ case IconType::FileBased:
+ t = IconType::Transient;
+ break;
+ default:
+ break;
}
return temp;
}
@@ -79,8 +78,8 @@ QIcon MMCIcon::icon() const
{
if (m_current_type == IconType::ToBeDeleted)
return QIcon();
- auto & icon = m_images[m_current_type].icon;
- if(!icon.isNull())
+ auto& icon = m_images[m_current_type].icon;
+ if (!icon.isNull())
return icon;
// FIXME: inject this.
return QIcon::fromTheme(m_images[m_current_type].key);
@@ -90,10 +89,8 @@ void MMCIcon::remove(IconType rm_type)
{
m_images[rm_type].filename = QString();
m_images[rm_type].icon = QIcon();
- for (auto iter = rm_type; iter != IconType::ToBeDeleted; iter--)
- {
- if (m_images[iter].present())
- {
+ for (auto iter = rm_type; iter != IconType::ToBeDeleted; iter--) {
+ if (m_images[iter].present()) {
m_current_type = iter;
return;
}
@@ -103,8 +100,7 @@ void MMCIcon::remove(IconType rm_type)
void MMCIcon::replace(IconType new_type, QIcon icon, QString path)
{
- if (new_type > m_current_type || m_current_type == IconType::ToBeDeleted)
- {
+ if (new_type > m_current_type || m_current_type == IconType::ToBeDeleted) {
m_current_type = new_type;
}
m_images[new_type].icon = icon;
@@ -114,8 +110,7 @@ void MMCIcon::replace(IconType new_type, QIcon icon, QString path)
void MMCIcon::replace(IconType new_type, const QString& key)
{
- if (new_type > m_current_type || m_current_type == IconType::ToBeDeleted)
- {
+ if (new_type > m_current_type || m_current_type == IconType::ToBeDeleted) {
m_current_type = new_type;
}
m_images[new_type].icon = QIcon();
@@ -125,13 +120,12 @@ void MMCIcon::replace(IconType new_type, const QString& key)
QString MMCIcon::getFilePath() const
{
- if(m_current_type == IconType::ToBeDeleted){
+ if (m_current_type == IconType::ToBeDeleted) {
return QString();
}
return m_images[m_current_type].filename;
}
-
bool MMCIcon::isBuiltIn() const
{
return m_current_type == IconType::Builtin;
diff --git a/launcher/icons/MMCIcon.h b/launcher/icons/MMCIcon.h
index 13d99318..a6e30566 100644
--- a/launcher/icons/MMCIcon.h
+++ b/launcher/icons/MMCIcon.h
@@ -1,45 +1,52 @@
-/* Copyright 2013-2021 MultiMC Contributors
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
*
- * 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
+ * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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.
*
- * 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.
+ * 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.
*/
-
#pragma once
-#include <QString>
#include <QDateTime>
#include <QIcon>
+#include <QString>
-enum IconType : unsigned
-{
- Builtin,
- Transient,
- FileBased,
- ICONS_TOTAL,
- ToBeDeleted
-};
+enum IconType : unsigned { Builtin, Transient, FileBased, ICONS_TOTAL, ToBeDeleted };
-struct MMCImage
-{
+struct MMCImage {
QIcon icon;
QString key;
QString filename;
- bool present() const
- {
- return !icon.isNull() || !key.isEmpty();
- }
+ bool present() const { return !icon.isNull() || !key.isEmpty(); }
};
-struct MMCIcon
-{
+struct MMCIcon {
QString m_key;
QString m_name;
MMCImage m_images[ICONS_TOTAL];
@@ -51,7 +58,7 @@ struct MMCIcon
QIcon icon() const;
void remove(IconType rm_type);
void replace(IconType new_type, QIcon icon, QString path = QString());
- void replace(IconType new_type, const QString &key);
+ void replace(IconType new_type, const QString& key);
bool isBuiltIn() const;
QString getFilePath() const;
};
diff --git a/launcher/meta/BaseEntity.cpp b/launcher/meta/BaseEntity.cpp
index 97815eba..fd810a91 100644
--- a/launcher/meta/BaseEntity.cpp
+++ b/launcher/meta/BaseEntity.cpp
@@ -15,7 +15,7 @@
#include "BaseEntity.h"
-#include "net/Download.h"
+#include "net/ApiDownload.h"
#include "net/HttpMetaCache.h"
#include "net/NetJob.h"
#include "Json.h"
@@ -130,7 +130,7 @@ void Meta::BaseEntity::load(Net::Mode loadType)
auto url = this->url();
auto entry = APPLICATION->metacache()->resolveEntry("meta", localFilename());
entry->setStale(true);
- auto dl = Net::Download::makeCached(url, entry);
+ auto dl = Net::ApiDownload::makeCached(url, entry);
/*
* The validator parses the file and loads it into the object.
* If that fails, the file is not written to storage.
diff --git a/launcher/minecraft/AssetsUtils.cpp b/launcher/minecraft/AssetsUtils.cpp
index 16fdfdb1..65ad6da6 100644
--- a/launcher/minecraft/AssetsUtils.cpp
+++ b/launcher/minecraft/AssetsUtils.cpp
@@ -45,7 +45,7 @@
#include "AssetsUtils.h"
#include "FileSystem.h"
-#include "net/Download.h"
+#include "net/ApiDownload.h"
#include "net/ChecksumValidator.h"
#include "BuildConfig.h"
@@ -311,7 +311,7 @@ NetAction::Ptr AssetObject::getDownloadAction()
QFileInfo objectFile(getLocalPath());
if ((!objectFile.isFile()) || (objectFile.size() != size))
{
- auto objectDL = Net::Download::makeFile(getUrl(), objectFile.filePath());
+ auto objectDL = Net::ApiDownload::makeFile(getUrl(), objectFile.filePath());
if(hash.size())
{
auto rawHash = QByteArray::fromHex(hash.toLatin1());
diff --git a/launcher/minecraft/Library.cpp b/launcher/minecraft/Library.cpp
index cb2b5254..e0318ef2 100644
--- a/launcher/minecraft/Library.cpp
+++ b/launcher/minecraft/Library.cpp
@@ -36,7 +36,7 @@
#include "Library.h"
#include "MinecraftInstance.h"
-#include <net/Download.h>
+#include <net/ApiDownload.h>
#include <net/ChecksumValidator.h>
#include <FileSystem.h>
#include <BuildConfig.h>
@@ -129,14 +129,14 @@ QList<NetAction::Ptr> Library::getDownloads(
if(sha1.size())
{
auto rawSha1 = QByteArray::fromHex(sha1.toLatin1());
- auto dl = Net::Download::makeCached(url, entry, options);
+ auto dl = Net::ApiDownload::makeCached(url, entry, options);
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1));
qDebug() << "Checksummed Download for:" << rawName().serialize() << "storage:" << storage << "url:" << url;
out.append(dl);
}
else
{
- out.append(Net::Download::makeCached(url, entry, options));
+ out.append(Net::ApiDownload::makeCached(url, entry, options));
qDebug() << "Download for:" << rawName().serialize() << "storage:" << storage << "url:" << url;
}
return true;
diff --git a/launcher/minecraft/mod/ModFolderModel.cpp b/launcher/minecraft/mod/ModFolderModel.cpp
index 51383edf..4300ce50 100644
--- a/launcher/minecraft/mod/ModFolderModel.cpp
+++ b/launcher/minecraft/mod/ModFolderModel.cpp
@@ -61,6 +61,7 @@ ModFolderModel::ModFolderModel(const QString& dir, BaseInstance* instance, bool
m_column_names_translated = QStringList({ tr("Enable"), tr("Image"), tr("Name"), tr("Version"), tr("Last Modified"), tr("Provider") });
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::NAME , SortType::VERSION, SortType::DATE, SortType::PROVIDER};
m_column_resize_modes = { QHeaderView::ResizeToContents, QHeaderView::Interactive, QHeaderView::Stretch, QHeaderView::ResizeToContents, QHeaderView::ResizeToContents, QHeaderView::ResizeToContents};
+ m_columnsHideable = { false, true, false, true, true, true };
}
QVariant ModFolderModel::data(const QModelIndex &index, int role) const
diff --git a/launcher/minecraft/mod/ResourceFolderModel.cpp b/launcher/minecraft/mod/ResourceFolderModel.cpp
index 39a61067..d834c359 100644
--- a/launcher/minecraft/mod/ResourceFolderModel.cpp
+++ b/launcher/minecraft/mod/ResourceFolderModel.cpp
@@ -552,6 +552,8 @@ QMenu* ResourceFolderModel::createHeaderContextMenu(QTreeView* tree)
menu->addSeparator()->setText(tr("Show / Hide Columns"));
for (int col = 0; col < columnCount(); ++col) {
+ // Skip creating actions for columns that should not be hidden
+ if (!m_columnsHideable.at(col)) continue;
auto act = new QAction(menu);
setupHeaderAction(act, col);
diff --git a/launcher/minecraft/mod/ResourceFolderModel.h b/launcher/minecraft/mod/ResourceFolderModel.h
index 454b84c3..ec334a08 100644
--- a/launcher/minecraft/mod/ResourceFolderModel.h
+++ b/launcher/minecraft/mod/ResourceFolderModel.h
@@ -202,6 +202,7 @@ class ResourceFolderModel : public QAbstractListModel {
QStringList m_column_names = {"Enable", "Name", "Last Modified"};
QStringList m_column_names_translated = {tr("Enable"), tr("Name"), tr("Last Modified")};
QList<QHeaderView::ResizeMode> m_column_resize_modes = { QHeaderView::ResizeToContents, QHeaderView::Stretch, QHeaderView::ResizeToContents };
+ QList<bool> m_columnsHideable = { false, false, true };
QDir m_dir;
BaseInstance* m_instance;
diff --git a/launcher/minecraft/mod/ResourcePackFolderModel.cpp b/launcher/minecraft/mod/ResourcePackFolderModel.cpp
index 41455599..c8770d54 100644
--- a/launcher/minecraft/mod/ResourcePackFolderModel.cpp
+++ b/launcher/minecraft/mod/ResourcePackFolderModel.cpp
@@ -54,7 +54,7 @@ ResourcePackFolderModel::ResourcePackFolderModel(const QString& dir, BaseInstanc
m_column_names_translated = QStringList({ tr("Enable"), tr("Image"), tr("Name"), tr("Pack Format"), tr("Last Modified") });
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::NAME, SortType::PACK_FORMAT, SortType::DATE};
m_column_resize_modes = { QHeaderView::ResizeToContents, QHeaderView::Interactive, QHeaderView::Stretch, QHeaderView::ResizeToContents, QHeaderView::ResizeToContents };
-
+ m_columnsHideable = { false, true, false, true, true };
}
QVariant ResourcePackFolderModel::data(const QModelIndex& index, int role) const
diff --git a/launcher/minecraft/mod/TexturePackFolderModel.cpp b/launcher/minecraft/mod/TexturePackFolderModel.cpp
index 531a7023..28fe0a46 100644
--- a/launcher/minecraft/mod/TexturePackFolderModel.cpp
+++ b/launcher/minecraft/mod/TexturePackFolderModel.cpp
@@ -49,6 +49,7 @@ TexturePackFolderModel::TexturePackFolderModel(const QString& dir, BaseInstance*
m_column_names_translated = QStringList({ tr("Enable"), tr("Image"), tr("Name"), tr("Last Modified") });
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::NAME, SortType::DATE };
m_column_resize_modes = { QHeaderView::ResizeToContents, QHeaderView::Interactive, QHeaderView::Stretch, QHeaderView::ResizeToContents};
+ m_columnsHideable = { false, true, false, true };
}
diff --git a/launcher/minecraft/update/AssetUpdateTask.cpp b/launcher/minecraft/update/AssetUpdateTask.cpp
index fda85ba8..ec0c90b7 100644
--- a/launcher/minecraft/update/AssetUpdateTask.cpp
+++ b/launcher/minecraft/update/AssetUpdateTask.cpp
@@ -7,6 +7,8 @@
#include "Application.h"
+#include "net/ApiDownload.h"
+
AssetUpdateTask::AssetUpdateTask(MinecraftInstance * inst)
{
m_inst = inst;
@@ -34,7 +36,7 @@ void AssetUpdateTask::executeTask()
entry->setStale(true);
auto hexSha1 = assets->sha1.toLatin1();
qDebug() << "Asset index SHA1:" << hexSha1;
- auto dl = Net::Download::makeCached(indexUrl, entry);
+ auto dl = Net::ApiDownload::makeCached(indexUrl, entry);
auto rawSha1 = QByteArray::fromHex(assets->sha1.toLatin1());
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1));
job->addNetAction(dl);
diff --git a/launcher/minecraft/update/FMLLibrariesTask.cpp b/launcher/minecraft/update/FMLLibrariesTask.cpp
index d9fa0595..51b6d74c 100644
--- a/launcher/minecraft/update/FMLLibrariesTask.cpp
+++ b/launcher/minecraft/update/FMLLibrariesTask.cpp
@@ -8,6 +8,8 @@
#include "BuildConfig.h"
#include "Application.h"
+#include "net/ApiDownload.h"
+
FMLLibrariesTask::FMLLibrariesTask(MinecraftInstance * inst)
{
m_inst = inst;
@@ -68,7 +70,7 @@ void FMLLibrariesTask::executeTask()
{
auto entry = metacache->resolveEntry("fmllibs", lib.filename);
QString urlString = BuildConfig.FMLLIBS_BASE_URL + lib.filename;
- dljob->addNetAction(Net::Download::makeCached(QUrl(urlString), entry, options));
+ dljob->addNetAction(Net::ApiDownload::makeCached(QUrl(urlString), entry, options));
}
connect(dljob.get(), &NetJob::succeeded, this, &FMLLibrariesTask::fmllibsFinished);
diff --git a/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp b/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp
index 82a51c27..8260a25c 100644
--- a/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp
+++ b/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp
@@ -53,6 +53,8 @@
#include "meta/Version.h"
#include "meta/VersionList.h"
+#include "net/ApiDownload.h"
+
#include "BuildConfig.h"
#include "Application.h"
@@ -82,9 +84,9 @@ void PackInstallTask::executeTask()
{
qDebug() << "PackInstallTask::executeTask: " << QThread::currentThreadId();
NetJob::Ptr netJob{ new NetJob("ATLauncher::VersionFetch", APPLICATION->network()) };
- auto searchUrl =
+ auto searchUrl =
QString(BuildConfig.ATL_DOWNLOAD_SERVER_URL + "packs/%1/versions/%2/Configs.json").arg(m_pack_safe_name).arg(m_version_name);
- netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), response));
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(QUrl(searchUrl), response));
QObject::connect(netJob.get(), &NetJob::succeeded, this, &PackInstallTask::onDownloadSucceeded);
QObject::connect(netJob.get(), &NetJob::failed, this, &PackInstallTask::onDownloadFailed);
@@ -659,7 +661,7 @@ void PackInstallTask::installConfigs()
auto entry = APPLICATION->metacache()->resolveEntry("ATLauncherPacks", path);
entry->setStale(true);
- auto dl = Net::Download::makeCached(url, entry);
+ auto dl = Net::ApiDownload::makeCached(url, entry);
if (!m_version.configs.sha1.isEmpty()) {
auto rawSha1 = QByteArray::fromHex(m_version.configs.sha1.toLatin1());
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1));
@@ -782,7 +784,7 @@ void PackInstallTask::downloadMods()
entry->setStale(true);
modsToExtract.insert(entry->getFullPath(), mod);
- auto dl = Net::Download::makeCached(url, entry);
+ auto dl = Net::ApiDownload::makeCached(url, entry);
if (!mod.md5.isEmpty()) {
auto rawMd5 = QByteArray::fromHex(mod.md5.toLatin1());
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, rawMd5));
@@ -794,7 +796,7 @@ void PackInstallTask::downloadMods()
entry->setStale(true);
modsToDecomp.insert(entry->getFullPath(), mod);
- auto dl = Net::Download::makeCached(url, entry);
+ auto dl = Net::ApiDownload::makeCached(url, entry);
if (!mod.md5.isEmpty()) {
auto rawMd5 = QByteArray::fromHex(mod.md5.toLatin1());
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, rawMd5));
@@ -808,7 +810,7 @@ void PackInstallTask::downloadMods()
auto entry = APPLICATION->metacache()->resolveEntry("ATLauncherPacks", cacheName);
entry->setStale(true);
- auto dl = Net::Download::makeCached(url, entry);
+ auto dl = Net::ApiDownload::makeCached(url, entry);
if (!mod.md5.isEmpty()) {
auto rawMd5 = QByteArray::fromHex(mod.md5.toLatin1());
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, rawMd5));
diff --git a/launcher/modplatform/flame/FileResolvingTask.cpp b/launcher/modplatform/flame/FileResolvingTask.cpp
index ae168bbd..fcf8517f 100644
--- a/launcher/modplatform/flame/FileResolvingTask.cpp
+++ b/launcher/modplatform/flame/FileResolvingTask.cpp
@@ -1,7 +1,9 @@
#include "FileResolvingTask.h"
#include "Json.h"
+#include "net/ApiUpload.h"
#include "net/Upload.h"
+#include "net/ApiDownload.h"
#include "modplatform/modrinth/ModrinthPackIndex.h"
@@ -38,7 +40,7 @@ void Flame::FileResolvingTask::executeTask()
return l;
}));
QByteArray data = Json::toText(object);
- auto dl = Net::Upload::makeByteArray(QUrl("https://api.curseforge.com/v1/mods/files"), result, data);
+ auto dl = Net::ApiUpload::makeByteArray(QUrl("https://api.curseforge.com/v1/mods/files"), result, data);
m_dljob->addNetAction(dl);
auto step_progress = std::make_shared<TaskStepProgress>();
@@ -99,7 +101,7 @@ void Flame::FileResolvingTask::netJobFinished()
if (!hash.isEmpty()) {
auto url = QString("https://api.modrinth.com/v2/version_file/%1?algorithm=sha1").arg(hash);
auto output = std::make_shared<QByteArray>();
- auto dl = Net::Download::makeByteArray(QUrl(url), output);
+ auto dl = Net::ApiDownload::makeByteArray(QUrl(url), output);
QObject::connect(dl.get(), &Net::Download::succeeded, [&out]() { out.resolved = true; });
m_checkJob->addNetAction(dl);
@@ -171,7 +173,7 @@ void Flame::FileResolvingTask::modrinthCheckFinished()
auto projectId = mod->projectId;
auto output = std::make_shared<QByteArray>();
auto url = QString("https://api.curseforge.com/v1/mods/%1").arg(projectId);
- auto dl = Net::Download::makeByteArray(url, output);
+ auto dl = Net::ApiDownload::makeByteArray(url, output);
qDebug() << "Fetching url slug for file:" << mod->fileName;
QObject::connect(dl.get(), &Net::Download::succeeded, [block, index, output]() {
auto mod = block->at(index); // use the shared_ptr so it is captured and only freed when we are done
diff --git a/launcher/modplatform/flame/FlameAPI.cpp b/launcher/modplatform/flame/FlameAPI.cpp
index 5b0b1d8b..7231b466 100644
--- a/launcher/modplatform/flame/FlameAPI.cpp
+++ b/launcher/modplatform/flame/FlameAPI.cpp
@@ -8,7 +8,9 @@
#include "Application.h"
#include "BuildConfig.h"
#include "Json.h"
+#include "net/ApiUpload.h"
#include "net/NetJob.h"
+#include "net/ApiDownload.h"
#include "net/Upload.h"
Task::Ptr FlameAPI::matchFingerprints(const QList<uint>& fingerprints, std::shared_ptr<QByteArray> response)
@@ -26,7 +28,7 @@ Task::Ptr FlameAPI::matchFingerprints(const QList<uint>& fingerprints, std::shar
QJsonDocument body(body_obj);
auto body_raw = body.toJson();
- netJob->addNetAction(Net::Upload::makeByteArray(QString("https://api.curseforge.com/v1/fingerprints"), response, body_raw));
+ netJob->addNetAction(Net::ApiUpload::makeByteArray(QString("https://api.curseforge.com/v1/fingerprints"), response, body_raw));
return netJob;
}
@@ -38,7 +40,7 @@ auto FlameAPI::getModFileChangelog(int modId, int fileId) -> QString
auto netJob = makeShared<NetJob>(QString("Flame::FileChangelog"), APPLICATION->network());
auto response = std::make_shared<QByteArray>();
- netJob->addNetAction(Net::Download::makeByteArray(
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(
QString("https://api.curseforge.com/v1/mods/%1/files/%2/changelog")
.arg(QString::fromStdString(std::to_string(modId)), QString::fromStdString(std::to_string(fileId))),
response));
@@ -74,7 +76,7 @@ auto FlameAPI::getModDescription(int modId) -> QString
auto netJob = makeShared<NetJob>(QString("Flame::ModDescription"), APPLICATION->network());
auto response = std::make_shared<QByteArray>();
netJob->addNetAction(
- Net::Download::makeByteArray(QString("https://api.curseforge.com/v1/mods/%1/description").arg(QString::number(modId)), response));
+ Net::ApiDownload::makeByteArray(QString("https://api.curseforge.com/v1/mods/%1/description").arg(QString::number(modId)), response));
QObject::connect(netJob.get(), &NetJob::succeeded, [&netJob, response, &description] {
QJsonParseError parse_error{};
@@ -113,7 +115,7 @@ auto FlameAPI::getLatestVersion(VersionSearchArgs&& args) -> ModPlatform::Indexe
auto response = std::make_shared<QByteArray>();
ModPlatform::IndexedVersion ver;
- netJob->addNetAction(Net::Download::makeByteArray(versions_url, response));
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(versions_url, response));
QObject::connect(netJob.get(), &NetJob::succeeded, [response, args, &ver] {
QJsonParseError parse_error{};
@@ -173,7 +175,7 @@ Task::Ptr FlameAPI::getProjects(QStringList addonIds, std::shared_ptr<QByteArray
QJsonDocument body(body_obj);
auto body_raw = body.toJson();
- netJob->addNetAction(Net::Upload::makeByteArray(QString("https://api.curseforge.com/v1/mods"), response, body_raw));
+ netJob->addNetAction(Net::ApiUpload::makeByteArray(QString("https://api.curseforge.com/v1/mods"), response, body_raw));
QObject::connect(netJob.get(), &NetJob::failed, [body_raw] { qDebug() << body_raw; });
@@ -195,7 +197,7 @@ Task::Ptr FlameAPI::getFiles(const QStringList& fileIds, std::shared_ptr<QByteAr
QJsonDocument body(body_obj);
auto body_raw = body.toJson();
- netJob->addNetAction(Net::Upload::makeByteArray(QString("https://api.curseforge.com/v1/mods/files"), response, body_raw));
+ netJob->addNetAction(Net::ApiUpload::makeByteArray(QString("https://api.curseforge.com/v1/mods/files"), response, body_raw));
QObject::connect(netJob.get(), &NetJob::failed, [body_raw] { qDebug() << body_raw; });
diff --git a/launcher/modplatform/flame/FlameCheckUpdate.cpp b/launcher/modplatform/flame/FlameCheckUpdate.cpp
index a2628e34..e10fedc3 100644
--- a/launcher/modplatform/flame/FlameCheckUpdate.cpp
+++ b/launcher/modplatform/flame/FlameCheckUpdate.cpp
@@ -13,6 +13,8 @@
#include "minecraft/mod/ModFolderModel.h"
#include "minecraft/mod/ResourceFolderModel.h"
+#include "net/ApiDownload.h"
+
static FlameAPI api;
bool FlameCheckUpdate::abort()
@@ -33,7 +35,7 @@ ModPlatform::IndexedPack getProjectInfo(ModPlatform::IndexedVersion& ver_info)
auto response = std::make_shared<QByteArray>();
auto url = QString("https://api.curseforge.com/v1/mods/%1").arg(ver_info.addonId.toString());
- auto dl = Net::Download::makeByteArray(url, response);
+ auto dl = Net::ApiDownload::makeByteArray(url, response);
get_project_job->addNetAction(dl);
QObject::connect(get_project_job, &NetJob::succeeded, [response, &pack]() {
@@ -77,7 +79,7 @@ ModPlatform::IndexedVersion getFileInfo(int addonId, int fileId)
auto response = std::make_shared<QByteArray>();
auto url = QString("https://api.curseforge.com/v1/mods/%1/files/%2").arg(QString::number(addonId), QString::number(fileId));
- auto dl = Net::Download::makeByteArray(url, response);
+ auto dl = Net::ApiDownload::makeByteArray(url, response);
get_file_info_job->addNetAction(dl);
QObject::connect(get_file_info_job, &NetJob::succeeded, [response, &ver]() {
diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp
index e17cf1c2..c170a4f5 100644
--- a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp
+++ b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp
@@ -61,6 +61,7 @@
#include "meta/VersionList.h"
#include "minecraft/World.h"
#include "minecraft/mod/tasks/LocalResourceParse.h"
+#include "net/ApiDownload.h"
static const FlameAPI api;
@@ -523,7 +524,7 @@ void FlameCreationTask::setupDownloadJob(QEventLoop& loop)
case Flame::File::Type::Mod: {
if (!result.url.isEmpty()) {
qDebug() << "Will download" << result.url << "to" << path;
- auto dl = Net::Download::makeFile(result.url, path);
+ auto dl = Net::ApiDownload::makeFile(result.url, path);
m_files_job->addNetAction(dl);
}
break;
diff --git a/launcher/modplatform/helpers/NetworkResourceAPI.cpp b/launcher/modplatform/helpers/NetworkResourceAPI.cpp
index c278f800..9bc6dd5c 100644
--- a/launcher/modplatform/helpers/NetworkResourceAPI.cpp
+++ b/launcher/modplatform/helpers/NetworkResourceAPI.cpp
@@ -10,6 +10,8 @@
#include "modplatform/ModIndex.h"
+#include "net/ApiDownload.h"
+
Task::Ptr NetworkResourceAPI::searchProjects(SearchArgs&& args, SearchCallbacks&& callbacks) const
{
auto search_url_optional = getSearchURL(args);
@@ -23,7 +25,7 @@ Task::Ptr NetworkResourceAPI::searchProjects(SearchArgs&& args, SearchCallbacks&
auto response = std::make_shared<QByteArray>();
auto netJob = makeShared<NetJob>(QString("%1::Search").arg(debugName()), APPLICATION->network());
- netJob->addNetAction(Net::Download::makeByteArray(QUrl(search_url), response));
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(QUrl(search_url), response));
QObject::connect(netJob.get(), &NetJob::succeeded, [this, response, callbacks] {
QJsonParseError parse_error{};
@@ -85,7 +87,7 @@ Task::Ptr NetworkResourceAPI::getProjectVersions(VersionSearchArgs&& args, Versi
auto netJob = makeShared<NetJob>(QString("%1::Versions").arg(args.pack.name), APPLICATION->network());
auto response = std::make_shared<QByteArray>();
- netJob->addNetAction(Net::Download::makeByteArray(versions_url, response));
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(versions_url, response));
QObject::connect(netJob.get(), &NetJob::succeeded, [response, callbacks, args] {
QJsonParseError parse_error{};
@@ -113,7 +115,7 @@ Task::Ptr NetworkResourceAPI::getProject(QString addonId, std::shared_ptr<QByteA
auto netJob = makeShared<NetJob>(QString("%1::GetProject").arg(addonId), APPLICATION->network());
- netJob->addNetAction(Net::Download::makeByteArray(QUrl(project_url), response));
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(QUrl(project_url), response));
return netJob;
}
diff --git a/launcher/modplatform/legacy_ftb/PackFetchTask.cpp b/launcher/modplatform/legacy_ftb/PackFetchTask.cpp
index a8a0fc2c..e5ad8244 100644
--- a/launcher/modplatform/legacy_ftb/PackFetchTask.cpp
+++ b/launcher/modplatform/legacy_ftb/PackFetchTask.cpp
@@ -40,6 +40,8 @@
#include "BuildConfig.h"
#include "Application.h"
+#include "net/ApiDownload.h"
+
namespace LegacyFTB {
void PackFetchTask::fetch()
@@ -51,7 +53,7 @@ void PackFetchTask::fetch()
QUrl publicPacksUrl = QUrl(BuildConfig.LEGACY_FTB_CDN_BASE_URL + "static/modpacks.xml");
qDebug() << "Downloading public version info from" << publicPacksUrl.toString();
- jobPtr->addNetAction(Net::Download::makeByteArray(publicPacksUrl, publicModpacksXmlFileData));
+ jobPtr->addNetAction(Net::ApiDownload::makeByteArray(publicPacksUrl, publicModpacksXmlFileData));
QUrl thirdPartyUrl = QUrl(BuildConfig.LEGACY_FTB_CDN_BASE_URL + "static/thirdparty.xml");
qDebug() << "Downloading thirdparty version info from" << thirdPartyUrl.toString();
@@ -71,7 +73,7 @@ void PackFetchTask::fetchPrivate(const QStringList& toFetch)
for (auto& packCode : toFetch) {
auto data = std::make_shared<QByteArray>();
NetJob* job = new NetJob("Fetching private pack", m_network);
- job->addNetAction(Net::Download::makeByteArray(privatePackBaseUrl.arg(packCode), data));
+ job->addNetAction(Net::ApiDownload::makeByteArray(privatePackBaseUrl.arg(packCode), data));
QObject::connect(job, &NetJob::succeeded, this, [this, job, data, packCode] {
ModpackList packs;
diff --git a/launcher/modplatform/legacy_ftb/PackInstallTask.cpp b/launcher/modplatform/legacy_ftb/PackInstallTask.cpp
index 1afe5783..beb295dc 100644
--- a/launcher/modplatform/legacy_ftb/PackInstallTask.cpp
+++ b/launcher/modplatform/legacy_ftb/PackInstallTask.cpp
@@ -48,6 +48,8 @@
#include "Application.h"
#include "BuildConfig.h"
+#include "net/ApiDownload.h"
+
namespace LegacyFTB {
PackInstallTask::PackInstallTask(shared_qobject_ptr<QNetworkAccessManager> network, Modpack pack, QString version)
@@ -77,7 +79,7 @@ void PackInstallTask::downloadPack()
} else {
url = QString(BuildConfig.LEGACY_FTB_CDN_BASE_URL + "modpacks/%1").arg(archivePath);
}
- netJobContainer->addNetAction(Net::Download::makeFile(url, archivePath));
+ netJobContainer->addNetAction(Net::ApiDownload::makeFile(url, archivePath));
connect(netJobContainer.get(), &NetJob::succeeded, this, &PackInstallTask::unzip);
connect(netJobContainer.get(), &NetJob::failed, this, &PackInstallTask::emitFailed);
diff --git a/launcher/modplatform/modrinth/ModrinthAPI.cpp b/launcher/modplatform/modrinth/ModrinthAPI.cpp
index 364cf3f3..466c5b10 100644
--- a/launcher/modplatform/modrinth/ModrinthAPI.cpp
+++ b/launcher/modplatform/modrinth/ModrinthAPI.cpp
@@ -6,6 +6,8 @@
#include "Application.h"
#include "Json.h"
+#include "net/ApiDownload.h"
+#include "net/ApiUpload.h"
#include "net/NetJob.h"
#include "net/Upload.h"
@@ -13,7 +15,7 @@ Task::Ptr ModrinthAPI::currentVersion(QString hash, QString hash_format, std::sh
{
auto netJob = makeShared<NetJob>(QString("Modrinth::GetCurrentVersion"), APPLICATION->network());
- netJob->addNetAction(Net::Download::makeByteArray(
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(
QString(BuildConfig.MODRINTH_PROD_URL + "/version_file/%1?algorithm=%2").arg(hash, hash_format), response));
return netJob;
@@ -31,7 +33,7 @@ Task::Ptr ModrinthAPI::currentVersions(const QStringList& hashes, QString hash_f
QJsonDocument body(body_obj);
auto body_raw = body.toJson();
- netJob->addNetAction(Net::Upload::makeByteArray(QString(BuildConfig.MODRINTH_PROD_URL + "/version_files"), response, body_raw));
+ netJob->addNetAction(Net::ApiUpload::makeByteArray(QString(BuildConfig.MODRINTH_PROD_URL + "/version_files"), response, body_raw));
return netJob;
}
@@ -60,7 +62,7 @@ Task::Ptr ModrinthAPI::latestVersion(QString hash,
QJsonDocument body(body_obj);
auto body_raw = body.toJson();
- netJob->addNetAction(Net::Upload::makeByteArray(
+ netJob->addNetAction(Net::ApiUpload::makeByteArray(
QString(BuildConfig.MODRINTH_PROD_URL + "/version_file/%1/update?algorithm=%2").arg(hash, hash_format), response, body_raw));
return netJob;
@@ -93,7 +95,8 @@ Task::Ptr ModrinthAPI::latestVersions(const QStringList& hashes,
QJsonDocument body(body_obj);
auto body_raw = body.toJson();
- netJob->addNetAction(Net::Upload::makeByteArray(QString(BuildConfig.MODRINTH_PROD_URL + "/version_files/update"), response, body_raw));
+ netJob->addNetAction(
+ Net::ApiUpload::makeByteArray(QString(BuildConfig.MODRINTH_PROD_URL + "/version_files/update"), response, body_raw));
return netJob;
}
@@ -103,7 +106,7 @@ Task::Ptr ModrinthAPI::getProjects(QStringList addonIds, std::shared_ptr<QByteAr
auto netJob = makeShared<NetJob>(QString("Modrinth::GetProjects"), APPLICATION->network());
auto searchUrl = getMultipleModInfoURL(addonIds);
- netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), response));
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(QUrl(searchUrl), response));
return netJob;
}
diff --git a/launcher/modplatform/modrinth/ModrinthInstanceCreationTask.cpp b/launcher/modplatform/modrinth/ModrinthInstanceCreationTask.cpp
index bd0b828c..2e42d6e7 100644
--- a/launcher/modplatform/modrinth/ModrinthInstanceCreationTask.cpp
+++ b/launcher/modplatform/modrinth/ModrinthInstanceCreationTask.cpp
@@ -12,6 +12,7 @@
#include "net/ChecksumValidator.h"
#include "net/NetJob.h"
+#include "net/ApiDownload.h"
#include "settings/INISettingsObject.h"
#include "ui/dialogs/CustomMessageBox.h"
@@ -238,7 +239,7 @@ bool ModrinthCreationTask::createInstance()
}
qDebug() << "Will try to download" << file.downloads.front() << "to" << file_path;
- auto dl = Net::Download::makeFile(file.downloads.dequeue(), file_path);
+ auto dl = Net::ApiDownload::makeFile(file.downloads.dequeue(), file_path);
dl->addValidator(new Net::ChecksumValidator(file.hashAlgorithm, file.hash));
m_files_job->addNetAction(dl);
@@ -247,7 +248,7 @@ bool ModrinthCreationTask::createInstance()
// MultipleOptionsTask's , once those exist :)
auto param = dl.toWeakRef();
connect(dl.get(), &NetAction::failed, [this, &file, file_path, param] {
- auto ndl = Net::Download::makeFile(file.downloads.dequeue(), file_path);
+ auto ndl = Net::ApiDownload::makeFile(file.downloads.dequeue(), file_path);
ndl->addValidator(new Net::ChecksumValidator(file.hashAlgorithm, file.hash));
m_files_job->addNetAction(ndl);
if (auto shared = param.lock()) shared->succeeded();
diff --git a/launcher/modplatform/technic/SingleZipPackInstallTask.cpp b/launcher/modplatform/technic/SingleZipPackInstallTask.cpp
index ab91c466..b2097c1d 100644
--- a/launcher/modplatform/technic/SingleZipPackInstallTask.cpp
+++ b/launcher/modplatform/technic/SingleZipPackInstallTask.cpp
@@ -23,6 +23,8 @@
#include "Application.h"
+#include "net/ApiDownload.h"
+
Technic::SingleZipPackInstallTask::SingleZipPackInstallTask(const QUrl &sourceUrl, const QString &minecraftVersion)
{
m_sourceUrl = sourceUrl;
@@ -45,7 +47,7 @@ void Technic::SingleZipPackInstallTask::executeTask()
auto entry = APPLICATION->metacache()->resolveEntry("general", path);
entry->setStale(true);
m_filesNetJob.reset(new NetJob(tr("Modpack download"), APPLICATION->network()));
- m_filesNetJob->addNetAction(Net::Download::makeCached(m_sourceUrl, entry));
+ m_filesNetJob->addNetAction(Net::ApiDownload::makeCached(m_sourceUrl, entry));
m_archivePath = entry->getFullPath();
auto job = m_filesNetJob.get();
connect(job, &NetJob::succeeded, this, &Technic::SingleZipPackInstallTask::downloadSucceeded);
diff --git a/launcher/modplatform/technic/SolderPackInstallTask.cpp b/launcher/modplatform/technic/SolderPackInstallTask.cpp
index cc1d261e..d7e9f640 100644
--- a/launcher/modplatform/technic/SolderPackInstallTask.cpp
+++ b/launcher/modplatform/technic/SolderPackInstallTask.cpp
@@ -43,6 +43,7 @@
#include "SolderPackManifest.h"
#include "TechnicPackProcessor.h"
#include "net/ChecksumValidator.h"
+#include "net/ApiDownload.h"
Technic::SolderPackInstallTask::SolderPackInstallTask(shared_qobject_ptr<QNetworkAccessManager> network,
const QUrl& solderUrl,
@@ -71,7 +72,7 @@ void Technic::SolderPackInstallTask::executeTask()
m_filesNetJob.reset(new NetJob(tr("Resolving modpack files"), m_network));
auto sourceUrl = QString("%1/modpack/%2/%3").arg(m_solderUrl.toString(), m_pack, m_version);
- m_filesNetJob->addNetAction(Net::Download::makeByteArray(sourceUrl, m_response));
+ m_filesNetJob->addNetAction(Net::ApiDownload::makeByteArray(sourceUrl, m_response));
auto job = m_filesNetJob.get();
connect(job, &NetJob::succeeded, this, &Technic::SolderPackInstallTask::fileListSucceeded);
@@ -112,7 +113,7 @@ void Technic::SolderPackInstallTask::fileListSucceeded()
for (const auto& mod : build.mods) {
auto path = FS::PathCombine(m_outputDir.path(), QString("%1").arg(i));
- auto dl = Net::Download::makeFile(mod.url, path);
+ auto dl = Net::ApiDownload::makeFile(mod.url, path);
if (!mod.md5.isEmpty()) {
auto rawMd5 = QByteArray::fromHex(mod.md5.toLatin1());
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, rawMd5));
diff --git a/launcher/net/ApiDownload.cpp b/launcher/net/ApiDownload.cpp
new file mode 100644
index 00000000..aaa8ff65
--- /dev/null
+++ b/launcher/net/ApiDownload.cpp
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.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 "net/ApiDownload.h"
+#include "ByteArraySink.h"
+#include "ChecksumValidator.h"
+#include "MetaCacheSink.h"
+#include "net/NetAction.h"
+
+namespace Net {
+
+auto ApiDownload::makeCached(QUrl url, MetaEntryPtr entry, Options options) -> Download::Ptr
+{
+ auto dl = makeShared<ApiDownload>();
+ dl->m_url = url;
+ dl->setObjectName(QString("CACHE:") + url.toString());
+ dl->m_options = options;
+ auto md5Node = new ChecksumValidator(QCryptographicHash::Md5);
+ auto cachedNode = new MetaCacheSink(entry, md5Node, options.testFlag(Option::MakeEternal));
+ dl->m_sink.reset(cachedNode);
+ return dl;
+}
+
+auto ApiDownload::makeByteArray(QUrl url, std::shared_ptr<QByteArray> output, Options options) -> Download::Ptr
+{
+ auto dl = makeShared<ApiDownload>();
+ dl->m_url = url;
+ dl->setObjectName(QString("BYTES:") + url.toString());
+ dl->m_options = options;
+ dl->m_sink.reset(new ByteArraySink(output));
+ return dl;
+}
+
+auto ApiDownload::makeFile(QUrl url, QString path, Options options) -> Download::Ptr
+{
+ auto dl = makeShared<ApiDownload>();
+ dl->m_url = url;
+ dl->setObjectName(QString("FILE:") + url.toString());
+ dl->m_options = options;
+ dl->m_sink.reset(new FileSink(path));
+ return dl;
+}
+
+void ApiDownload::init()
+{
+ qDebug() << "Setting up api download";
+ auto api_headers = new ApiHeaderProxy();
+ addHeaderProxy(api_headers);
+}
+} // namespace Net
diff --git a/launcher/net/ApiDownload.h b/launcher/net/ApiDownload.h
new file mode 100644
index 00000000..638c94e1
--- /dev/null
+++ b/launcher/net/ApiDownload.h
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.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/>.
+ *
+ */
+
+#pragma once
+
+#include "ApiHeaderProxy.h"
+#include "Download.h"
+
+namespace Net {
+
+class ApiDownload : public Download {
+ public:
+ virtual ~ApiDownload() = default;
+
+ static auto makeCached(QUrl url, MetaEntryPtr entry, Options options = Option::NoOptions) -> Download::Ptr;
+ static auto makeByteArray(QUrl url, std::shared_ptr<QByteArray> output, Options options = Option::NoOptions) -> Download::Ptr;
+ static auto makeFile(QUrl url, QString path, Options options = Option::NoOptions) -> Download::Ptr;
+
+ void init() override;
+};
+
+} // namespace Net
diff --git a/launcher/net/ApiHeaderProxy.h b/launcher/net/ApiHeaderProxy.h
new file mode 100644
index 00000000..789a6fad
--- /dev/null
+++ b/launcher/net/ApiHeaderProxy.h
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.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/>.
+ *
+ */
+
+#pragma once
+
+#include "Application.h"
+#include "BuildConfig.h"
+#include "net/HeaderProxy.h"
+
+namespace Net {
+
+class ApiHeaderProxy : public HeaderProxy {
+ public:
+ ApiHeaderProxy() : HeaderProxy() {}
+ virtual ~ApiHeaderProxy() = default;
+
+ public:
+ virtual QList<HeaderPair> headers(const QNetworkRequest& request) const override
+ {
+ QList<HeaderPair> hdrs;
+ if (APPLICATION->capabilities() & Application::SupportsFlame && request.url().host() == QUrl(BuildConfig.FLAME_BASE_URL).host()) {
+ hdrs.append({ "x-api-key", APPLICATION->getFlameAPIKey().toUtf8() });
+ } else if (request.url().host() == QUrl(BuildConfig.MODRINTH_PROD_URL).host() ||
+ request.url().host() == QUrl(BuildConfig.MODRINTH_STAGING_URL).host()) {
+ QString token = APPLICATION->getModrinthAPIToken();
+ if (!token.isNull())
+ hdrs.append({ "Authorization", token.toUtf8() });
+ }
+ return hdrs;
+ };
+};
+
+} // namespace Net
diff --git a/launcher/net/ApiUpload.cpp b/launcher/net/ApiUpload.cpp
new file mode 100644
index 00000000..c1221b76
--- /dev/null
+++ b/launcher/net/ApiUpload.cpp
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.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 "net/ApiUpload.h"
+#include "ByteArraySink.h"
+#include "ChecksumValidator.h"
+#include "MetaCacheSink.h"
+#include "net/NetAction.h"
+
+namespace Net {
+
+Upload::Ptr ApiUpload::makeByteArray(QUrl url, std::shared_ptr<QByteArray> output, QByteArray m_post_data)
+{
+ auto up = makeShared<ApiUpload>();
+ up->m_url = std::move(url);
+ up->m_sink.reset(new ByteArraySink(output));
+ up->m_post_data = std::move(m_post_data);
+ return up;
+}
+
+void ApiUpload::init()
+{
+ qDebug() << "Setting up api upload";
+ auto api_headers = new ApiHeaderProxy();
+ addHeaderProxy(api_headers);
+}
+} // namespace Net
diff --git a/launcher/net/ApiUpload.h b/launcher/net/ApiUpload.h
new file mode 100644
index 00000000..b12842b0
--- /dev/null
+++ b/launcher/net/ApiUpload.h
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.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/>.
+ *
+ */
+
+#pragma once
+
+#include "ApiHeaderProxy.h"
+#include "Upload.h"
+
+namespace Net {
+
+class ApiUpload : public Upload {
+ public:
+ virtual ~ApiUpload() = default;
+
+ static Upload::Ptr makeByteArray(QUrl url, std::shared_ptr<QByteArray> output, QByteArray m_post_data);
+
+ void init() override;
+};
+
+} // namespace Net
diff --git a/launcher/net/ByteArraySink.h b/launcher/net/ByteArraySink.h
index d6b17d60..7b8f0f8a 100644
--- a/launcher/net/ByteArraySink.h
+++ b/launcher/net/ByteArraySink.h
@@ -42,8 +42,6 @@ namespace Net {
/*
* Sink object for downloads that uses an external QByteArray it doesn't own as a target.
- * FIXME: It is possible that the QByteArray is freed while we're doing some operation on it,
- * causing a segmentation fault.
*/
class ByteArraySink : public Sink {
public:
diff --git a/launcher/net/Download.cpp b/launcher/net/Download.cpp
index 4ea45c63..d25447b2 100644
--- a/launcher/net/Download.cpp
+++ b/launcher/net/Download.cpp
@@ -47,17 +47,11 @@
#include "ChecksumValidator.h"
#include "MetaCacheSink.h"
-#include "Application.h"
-#include "BuildConfig.h"
-
-#include "net/Logging.h"
#include "net/NetAction.h"
-#include "MMCTime.h"
-#include "StringUtils.h"
-
namespace Net {
+#if defined(LAUNCHER_APPLICATION)
auto Download::makeCached(QUrl url, MetaEntryPtr entry, Options options) -> Download::Ptr
{
auto dl = makeShared<Download>();
@@ -69,6 +63,7 @@ auto Download::makeCached(QUrl url, MetaEntryPtr entry, Options options) -> Down
dl->m_sink.reset(cachedNode);
return dl;
}
+#endif
auto Download::makeByteArray(QUrl url, std::shared_ptr<QByteArray> output, Options options) -> Download::Ptr
{
@@ -90,260 +85,8 @@ auto Download::makeFile(QUrl url, QString path, Options options) -> Download::Pt
return dl;
}
-void Download::addValidator(Validator* v)
-{
- m_sink->addValidator(v);
-}
-
-void Download::executeTask()
-{
- setStatus(tr("Downloading %1").arg(StringUtils::truncateUrlHumanFriendly(m_url, 80)));
-
- if (getState() == Task::State::AbortedByUser) {
- qCWarning(taskDownloadLogC) << getUid().toString() << "Attempt to start an aborted Download:" << m_url.toString();
- emitAborted();
- return;
- }
-
- QNetworkRequest request(m_url);
- m_state = m_sink->init(request);
- switch (m_state) {
- case State::Succeeded:
- emit succeeded();
- qCDebug(taskDownloadLogC) << getUid().toString() << "Download cache hit " << m_url.toString();
- return;
- case State::Running:
- qCDebug(taskDownloadLogC) << getUid().toString() << "Downloading " << m_url.toString();
- break;
- case State::Inactive:
- case State::Failed:
- emitFailed();
- return;
- case State::AbortedByUser:
- emitAborted();
- return;
- }
-
- request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8());
- // TODO remove duplication
- if (APPLICATION->capabilities() & Application::SupportsFlame && request.url().host() == QUrl(BuildConfig.FLAME_BASE_URL).host()) {
- request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8());
- } else if (request.url().host() == QUrl(BuildConfig.MODRINTH_PROD_URL).host() ||
- request.url().host() == QUrl(BuildConfig.MODRINTH_STAGING_URL).host()) {
- QString token = APPLICATION->getModrinthAPIToken();
- if (!token.isNull())
- request.setRawHeader("Authorization", token.toUtf8());
- }
-
-#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
- request.setTransferTimeout();
-#endif
-
- m_last_progress_time = m_clock.now();
- m_last_progress_bytes = 0;
-
- QNetworkReply* rep = m_network->get(request);
- m_reply.reset(rep);
- connect(rep, &QNetworkReply::downloadProgress, this, &Download::downloadProgress);
- connect(rep, &QNetworkReply::finished, this, &Download::downloadFinished);
-#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) // QNetworkReply::errorOccurred added in 5.15
- connect(rep, &QNetworkReply::errorOccurred, this, &Download::downloadError);
-#else
- connect(rep, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error), this, &Download::downloadError);
-#endif
- connect(rep, &QNetworkReply::sslErrors, this, &Download::sslErrors);
- connect(rep, &QNetworkReply::readyRead, this, &Download::downloadReadyRead);
-}
-
-void Download::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
-{
- auto now = m_clock.now();
- auto elapsed = now - m_last_progress_time;
-
- // use milliseconds for speed precision
- auto elapsed_ms = std::chrono::duration_cast<std::chrono::milliseconds>(elapsed);
- auto bytes_received_since = bytesReceived - m_last_progress_bytes;
- auto dl_speed_bps = (double)bytes_received_since / elapsed_ms.count() * 1000;
- auto remaing_time_s = (bytesTotal - bytesReceived) / dl_speed_bps;
-
- //: Current amount of bytes downloaded, out of the total amount of bytes in the download
- QString dl_progress =
- tr("%1 / %2").arg(StringUtils::humanReadableFileSize(bytesReceived)).arg(StringUtils::humanReadableFileSize(bytesTotal));
-
- QString dl_speed_str;
- if (elapsed_ms.count() > 0) {
- auto str_eta = bytesTotal > 0 ? Time::humanReadableDuration(remaing_time_s) : tr("unknown");
- //: Download speed, in bytes per second (remaining download time in parenthesis)
- dl_speed_str =
- tr("%1 /s (%2)").arg(StringUtils::humanReadableFileSize(dl_speed_bps)).arg(str_eta);
- } else {
- //: Download speed at 0 bytes per second
- dl_speed_str = tr("0 B/s");
- }
-
- setDetails(dl_progress + "\n" + dl_speed_str);
-
- setProgress(bytesReceived, bytesTotal);
-}
-
-void Download::downloadError(QNetworkReply::NetworkError error)
-{
- if (error == QNetworkReply::OperationCanceledError) {
- qCCritical(taskDownloadLogC) << getUid().toString() << "Aborted " << m_url.toString();
- m_state = State::AbortedByUser;
- } else {
- if (m_options & Option::AcceptLocalFiles) {
- if (m_sink->hasLocalData()) {
- m_state = State::Succeeded;
- return;
- }
- }
- // error happened during download.
- qCCritical(taskDownloadLogC) << getUid().toString() << "Failed " << m_url.toString() << " with reason " << error;
- m_state = State::Failed;
- }
-}
-
-void Download::sslErrors(const QList<QSslError>& errors)
-{
- int i = 1;
- for (auto error : errors) {
- qCCritical(taskDownloadLogC) << getUid().toString() << "Download" << m_url.toString() << "SSL Error #" << i << " : "
- << error.errorString();
- auto cert = error.certificate();
- qCCritical(taskDownloadLogC) << getUid().toString() << "Certificate in question:\n" << cert.toText();
- i++;
- }
-}
-
-auto Download::handleRedirect() -> bool
-{
- QUrl redirect = m_reply->header(QNetworkRequest::LocationHeader).toUrl();
- if (!redirect.isValid()) {
- if (!m_reply->hasRawHeader("Location")) {
- // no redirect -> it's fine to continue
- return false;
- }
- // there is a Location header, but it's not correct. we need to apply some workarounds...
- QByteArray redirectBA = m_reply->rawHeader("Location");
- if (redirectBA.size() == 0) {
- // empty, yet present redirect header? WTF?
- return false;
- }
- QString redirectStr = QString::fromUtf8(redirectBA);
-
- if (redirectStr.startsWith("//")) {
- /*
- * IF the URL begins with //, we need to insert the URL scheme.
- * See: https://bugreports.qt.io/browse/QTBUG-41061
- * See: http://tools.ietf.org/html/rfc3986#section-4.2
- */
- redirectStr = m_reply->url().scheme() + ":" + redirectStr;
- } else if (redirectStr.startsWith("/")) {
- /*
- * IF the URL begins with /, we need to process it as a relative URL
- */
- auto url = m_reply->url();
- url.setPath(redirectStr, QUrl::TolerantMode);
- redirectStr = url.toString();
- }
-
- /*
- * Next, make sure the URL is parsed in tolerant mode. Qt doesn't parse the location header in tolerant mode, which causes issues.
- * FIXME: report Qt bug for this
- */
- redirect = QUrl(redirectStr, QUrl::TolerantMode);
- if (!redirect.isValid()) {
- qCWarning(taskDownloadLogC) << getUid().toString() << "Failed to parse redirect URL:" << redirectStr;
- downloadError(QNetworkReply::ProtocolFailure);
- return false;
- }
- qCDebug(taskDownloadLogC) << getUid().toString() << "Fixed location header:" << redirect;
- } else {
- qCDebug(taskDownloadLogC) << getUid().toString() << "Location header:" << redirect;
- }
-
- m_url = QUrl(redirect.toString());
- qCDebug(taskDownloadLogC) << getUid().toString() << "Following redirect to " << m_url.toString();
- startAction(m_network);
-
- return true;
-}
-
-void Download::downloadFinished()
-{
- // handle HTTP redirection first
- if (handleRedirect()) {
- qCDebug(taskDownloadLogC) << getUid().toString() << "Download redirected:" << m_url.toString();
- return;
- }
-
- // if the download failed before this point ...
- if (m_state == State::Succeeded) // pretend to succeed so we continue processing :)
- {
- qCDebug(taskDownloadLogC) << getUid().toString() << "Download failed but we are allowed to proceed:" << m_url.toString();
- m_sink->abort();
- m_reply.reset();
- emit succeeded();
- return;
- } else if (m_state == State::Failed) {
- qCDebug(taskDownloadLogC) << getUid().toString() << "Download failed in previous step:" << m_url.toString();
- m_sink->abort();
- m_reply.reset();
- emit failed("");
- return;
- } else if (m_state == State::AbortedByUser) {
- qCDebug(taskDownloadLogC) << getUid().toString() << "Download aborted in previous step:" << m_url.toString();
- m_sink->abort();
- m_reply.reset();
- emit aborted();
- return;
- }
-
- // make sure we got all the remaining data, if any
- auto data = m_reply->readAll();
- if (data.size()) {
- qCDebug(taskDownloadLogC) << getUid().toString() << "Writing extra" << data.size() << "bytes";
- m_state = m_sink->write(data);
- }
-
- // otherwise, finalize the whole graph
- m_state = m_sink->finalize(*m_reply.get());
- if (m_state != State::Succeeded) {
- qCDebug(taskDownloadLogC) << getUid().toString() << "Download failed to finalize:" << m_url.toString();
- m_sink->abort();
- m_reply.reset();
- emit failed("");
- return;
- }
-
- m_reply.reset();
- qCDebug(taskDownloadLogC) << getUid().toString() << "Download succeeded:" << m_url.toString();
- emit succeeded();
-}
-
-void Download::downloadReadyRead()
-{
- if (m_state == State::Running) {
- auto data = m_reply->readAll();
- m_state = m_sink->write(data);
- if (m_state == State::Failed) {
- qCCritical(taskDownloadLogC) << getUid().toString() << "Failed to process response chunk";
- }
- // qDebug() << "Download" << m_url.toString() << "gained" << data.size() << "bytes";
- } else {
- qCCritical(taskDownloadLogC) << getUid().toString() << "Cannot write download data! illegal status " << m_status;
- }
-}
-
-} // namespace Net
-
-auto Net::Download::abort() -> bool
+QNetworkReply* Download::getReply(QNetworkRequest& request)
{
- if (m_reply) {
- m_reply->abort();
- } else {
- m_state = State::AbortedByUser;
- }
- return true;
+ return m_network->get(request);
}
+} // namespace Net \ No newline at end of file
diff --git a/launcher/net/Download.h b/launcher/net/Download.h
index 2e861732..5f6a5caf 100644
--- a/launcher/net/Download.h
+++ b/launcher/net/Download.h
@@ -38,57 +38,26 @@
#pragma once
-#include <chrono>
-
#include "HttpMetaCache.h"
-#include "NetAction.h"
-#include "Sink.h"
-#include "Validator.h"
#include "QObjectPtr.h"
+#include "net/NetRequest.h"
namespace Net {
-class Download : public NetAction {
+class Download : public NetRequest {
Q_OBJECT
-
public:
using Ptr = shared_qobject_ptr<class Download>;
- enum class Option { NoOptions = 0, AcceptLocalFiles = 1, MakeEternal = 2 };
- Q_DECLARE_FLAGS(Options, Option)
-
- public:
- ~Download() override = default;
+ explicit Download() : NetRequest() { logCat = taskDownloadLogC; }
+#if defined(LAUNCHER_APPLICATION)
static auto makeCached(QUrl url, MetaEntryPtr entry, Options options = Option::NoOptions) -> Download::Ptr;
+#endif
+
static auto makeByteArray(QUrl url, std::shared_ptr<QByteArray> output, Options options = Option::NoOptions) -> Download::Ptr;
static auto makeFile(QUrl url, QString path, Options options = Option::NoOptions) -> Download::Ptr;
- public:
- void addValidator(Validator* v);
- auto abort() -> bool override;
- auto canAbort() const -> bool override { return true; };
-
- private:
- auto handleRedirect() -> bool;
-
- protected slots:
- void downloadProgress(qint64 bytesReceived, qint64 bytesTotal) override;
- void downloadError(QNetworkReply::NetworkError error) override;
- void sslErrors(const QList<QSslError>& errors) override;
- void downloadFinished() override;
- void downloadReadyRead() override;
-
- public slots:
- void executeTask() override;
-
- private:
- std::unique_ptr<Sink> m_sink;
- Options m_options;
-
- std::chrono::steady_clock m_clock;
- std::chrono::time_point<std::chrono::steady_clock> m_last_progress_time;
- qint64 m_last_progress_bytes;
+ protected:
+ virtual QNetworkReply* getReply(QNetworkRequest&) override;
};
} // namespace Net
-
-Q_DECLARE_OPERATORS_FOR_FLAGS(Net::Download::Options)
diff --git a/launcher/net/HeaderProxy.h b/launcher/net/HeaderProxy.h
new file mode 100644
index 00000000..f41c5875
--- /dev/null
+++ b/launcher/net/HeaderProxy.h
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.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/>.
+ *
+ */
+
+#pragma once
+
+#include <QDebug>
+#include <QNetworkRequest>
+
+namespace Net {
+
+struct HeaderPair {
+ QByteArray headerName;
+ QByteArray headerValue;
+};
+
+class HeaderProxy {
+ public:
+ HeaderProxy(){};
+ virtual ~HeaderProxy(){};
+
+ public:
+ virtual QList<HeaderPair> headers(const QNetworkRequest& request) const = 0;
+
+ public:
+ void writeHeaders(QNetworkRequest& request)
+ {
+ for (auto header : headers(request)) {
+ request.setRawHeader(header.headerName, header.headerValue);
+ }
+ }
+};
+
+} // namespace Net
diff --git a/launcher/net/NetAction.h b/launcher/net/NetAction.h
index ab9322c2..93076abc 100644
--- a/launcher/net/NetAction.h
+++ b/launcher/net/NetAction.h
@@ -42,6 +42,8 @@
#include "QObjectPtr.h"
#include "tasks/Task.h"
+#include "HeaderProxy.h"
+
class NetAction : public Task {
Q_OBJECT
protected:
@@ -56,13 +58,17 @@ class NetAction : public Task {
void setNetwork(shared_qobject_ptr<QNetworkAccessManager> network) { m_network = network; }
+ void addHeaderProxy(Net::HeaderProxy* proxy) { m_headerProxies.push_back(std::shared_ptr<Net::HeaderProxy>(proxy)); }
+ virtual void init() = 0;
+
protected slots:
virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal) = 0;
virtual void downloadError(QNetworkReply::NetworkError error) = 0;
virtual void downloadFinished() = 0;
virtual void downloadReadyRead() = 0;
- virtual void sslErrors(const QList<QSslError>& errors) {
+ virtual void sslErrors(const QList<QSslError>& errors)
+ {
int i = 1;
for (auto error : errors) {
qCritical() << "Network SSL Error #" << i << " : " << error.errorString();
@@ -70,7 +76,6 @@ class NetAction : public Task {
qCritical() << "Certificate in question:\n" << cert.toText();
i++;
}
-
};
public slots:
@@ -91,4 +96,5 @@ class NetAction : public Task {
/// source URL
QUrl m_url;
+ std::vector<std::shared_ptr<Net::HeaderProxy>> m_headerProxies;
};
diff --git a/launcher/net/NetRequest.cpp b/launcher/net/NetRequest.cpp
new file mode 100644
index 00000000..ff59da18
--- /dev/null
+++ b/launcher/net/NetRequest.cpp
@@ -0,0 +1,331 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
+ * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
+ * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
+ * Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.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/>.
+ *
+ * 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 "NetRequest.h"
+#include <QUrl>
+
+#include <QDateTime>
+#include <QFileInfo>
+#include <memory>
+
+#if defined(LAUNCHER_APPLICATION)
+#include "Application.h"
+#endif
+
+#include "net/NetAction.h"
+
+#include "MMCTime.h"
+#include "StringUtils.h"
+
+namespace Net {
+
+void NetRequest::addValidator(Validator* v)
+{
+ m_sink->addValidator(v);
+}
+
+void NetRequest::executeTask()
+{
+ init();
+
+ setStatus(tr("Requesting %1").arg(StringUtils::truncateUrlHumanFriendly(m_url, 80)));
+
+ if (getState() == Task::State::AbortedByUser) {
+ qCWarning(logCat) << getUid().toString() << "Attempt to start an aborted Request:" << m_url.toString();
+ emitAborted();
+ return;
+ }
+
+ QNetworkRequest request(m_url);
+ m_state = m_sink->init(request);
+ switch (m_state) {
+ case State::Succeeded:
+ qCDebug(logCat) << getUid().toString() << "Request cache hit " << m_url.toString();
+ emit succeeded();
+ emit finished();
+ return;
+ case State::Running:
+ qCDebug(logCat) << getUid().toString() << "Runninng " << m_url.toString();
+ break;
+ case State::Inactive:
+ case State::Failed:
+ emitFailed();
+ return;
+ case State::AbortedByUser:
+ emitAborted();
+ return;
+ }
+
+#if defined(LAUNCHER_APPLICATION)
+ auto user_agent = APPLICATION->getUserAgent();
+#else
+ auto user_agent = BuildConfig.USER_AGENT;
+#endif
+
+ request.setHeader(QNetworkRequest::UserAgentHeader, user_agent.toUtf8());
+ for (auto& header_proxy : m_headerProxies) {
+ header_proxy->writeHeaders(request);
+ }
+ // TODO remove duplication
+
+#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
+ request.setTransferTimeout();
+#endif
+
+ m_last_progress_time = m_clock.now();
+ m_last_progress_bytes = 0;
+
+ QNetworkReply* rep = getReply(request);
+ m_reply.reset(rep);
+ connect(rep, &QNetworkReply::downloadProgress, this, &NetRequest::downloadProgress);
+ connect(rep, &QNetworkReply::finished, this, &NetRequest::downloadFinished);
+#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) // QNetworkReply::errorOccurred added in 5.15
+ connect(rep, &QNetworkReply::errorOccurred, this, &NetRequest::downloadError);
+#else
+ connect(rep, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error), this, &NetRequest::downloadError);
+#endif
+ connect(rep, &QNetworkReply::sslErrors, this, &NetRequest::sslErrors);
+ connect(rep, &QNetworkReply::readyRead, this, &NetRequest::downloadReadyRead);
+}
+
+void NetRequest::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
+{
+ auto now = m_clock.now();
+ auto elapsed = now - m_last_progress_time;
+
+ // use milliseconds for speed precision
+ auto elapsed_ms = std::chrono::duration_cast<std::chrono::milliseconds>(elapsed);
+ auto bytes_received_since = bytesReceived - m_last_progress_bytes;
+ auto dl_speed_bps = (double)bytes_received_since / elapsed_ms.count() * 1000;
+ auto remaining_time_s = (bytesTotal - bytesReceived) / dl_speed_bps;
+
+ //: Current amount of bytes downloaded, out of the total amount of bytes in the download
+ QString dl_progress =
+ tr("%1 / %2").arg(StringUtils::humanReadableFileSize(bytesReceived)).arg(StringUtils::humanReadableFileSize(bytesTotal));
+
+ QString dl_speed_str;
+ if (elapsed_ms.count() > 0) {
+ auto str_eta = bytesTotal > 0 ? Time::humanReadableDuration(remaining_time_s) : tr("unknown");
+ //: Download speed, in bytes per second (remaining download time in parenthesis)
+ dl_speed_str = tr("%1 /s (%2)").arg(StringUtils::humanReadableFileSize(dl_speed_bps)).arg(str_eta);
+ } else {
+ //: Download speed at 0 bytes per second
+ dl_speed_str = tr("0 B/s");
+ }
+
+ setDetails(dl_progress + "\n" + dl_speed_str);
+
+ setProgress(bytesReceived, bytesTotal);
+}
+
+void NetRequest::downloadError(QNetworkReply::NetworkError error)
+{
+ if (error == QNetworkReply::OperationCanceledError) {
+ qCCritical(logCat) << getUid().toString() << "Aborted " << m_url.toString();
+ m_state = State::Failed;
+ } else {
+ if (m_options & Option::AcceptLocalFiles) {
+ if (m_sink->hasLocalData()) {
+ m_state = State::Succeeded;
+ return;
+ }
+ }
+ // error happened during download.
+ qCCritical(logCat) << getUid().toString() << "Failed " << m_url.toString() << " with reason " << error;
+ m_state = State::Failed;
+ }
+}
+
+void NetRequest::sslErrors(const QList<QSslError>& errors)
+{
+ int i = 1;
+ for (auto error : errors) {
+ qCCritical(logCat) << getUid().toString() << "Request" << m_url.toString() << "SSL Error #" << i << " : " << error.errorString();
+ auto cert = error.certificate();
+ qCCritical(logCat) << getUid().toString() << "Certificate in question:\n" << cert.toText();
+ i++;
+ }
+}
+
+auto NetRequest::handleRedirect() -> bool
+{
+ QUrl redirect = m_reply->header(QNetworkRequest::LocationHeader).toUrl();
+ if (!redirect.isValid()) {
+ if (!m_reply->hasRawHeader("Location")) {
+ // no redirect -> it's fine to continue
+ return false;
+ }
+ // there is a Location header, but it's not correct. we need to apply some workarounds...
+ QByteArray redirectBA = m_reply->rawHeader("Location");
+ if (redirectBA.size() == 0) {
+ // empty, yet present redirect header? WTF?
+ return false;
+ }
+ QString redirectStr = QString::fromUtf8(redirectBA);
+
+ if (redirectStr.startsWith("//")) {
+ /*
+ * IF the URL begins with //, we need to insert the URL scheme.
+ * See: https://bugreports.qt.io/browse/QTBUG-41061
+ * See: http://tools.ietf.org/html/rfc3986#section-4.2
+ */
+ redirectStr = m_reply->url().scheme() + ":" + redirectStr;
+ } else if (redirectStr.startsWith("/")) {
+ /*
+ * IF the URL begins with /, we need to process it as a relative URL
+ */
+ auto url = m_reply->url();
+ url.setPath(redirectStr, QUrl::TolerantMode);
+ redirectStr = url.toString();
+ }
+
+ /*
+ * Next, make sure the URL is parsed in tolerant mode. Qt doesn't parse the location header in tolerant mode, which causes issues.
+ * FIXME: report Qt bug for this
+ */
+ redirect = QUrl(redirectStr, QUrl::TolerantMode);
+ if (!redirect.isValid()) {
+ qCWarning(logCat) << getUid().toString() << "Failed to parse redirect URL:" << redirectStr;
+ downloadError(QNetworkReply::ProtocolFailure);
+ return false;
+ }
+ qCDebug(logCat) << getUid().toString() << "Fixed location header:" << redirect;
+ } else {
+ qCDebug(logCat) << getUid().toString() << "Location header:" << redirect;
+ }
+
+ m_url = QUrl(redirect.toString());
+ qCDebug(logCat) << getUid().toString() << "Following redirect to " << m_url.toString();
+ startAction(m_network);
+
+ return true;
+}
+
+void NetRequest::downloadFinished()
+{
+ // handle HTTP redirection first
+ if (handleRedirect()) {
+ qCDebug(logCat) << getUid().toString() << "Request redirected:" << m_url.toString();
+ return;
+ }
+
+ // if the download failed before this point ...
+ if (m_state == State::Succeeded) // pretend to succeed so we continue processing :)
+ {
+ qCDebug(logCat) << getUid().toString() << "Request failed but we are allowed to proceed:" << m_url.toString();
+ m_sink->abort();
+ m_reply.reset();
+ emit succeeded();
+ emit finished();
+ return;
+ } else if (m_state == State::Failed) {
+ qCDebug(logCat) << getUid().toString() << "Request failed in previous step:" << m_url.toString();
+ m_sink->abort();
+ m_reply.reset();
+ emit failed("");
+ emit finished();
+ return;
+ } else if (m_state == State::AbortedByUser) {
+ qCDebug(logCat) << getUid().toString() << "Request aborted in previous step:" << m_url.toString();
+ m_sink->abort();
+ m_reply.reset();
+ emit aborted();
+ emit finished();
+ return;
+ }
+
+ // make sure we got all the remaining data, if any
+ auto data = m_reply->readAll();
+ if (data.size()) {
+ qCDebug(logCat) << getUid().toString() << "Writing extra" << data.size() << "bytes";
+ m_state = m_sink->write(data);
+ if (m_state != State::Succeeded) {
+ qCDebug(logCat) << getUid().toString() << "Request failed to write:" << m_url.toString();
+ m_sink->abort();
+ emit failed("");
+ emit finished();
+ return;
+ }
+ }
+
+ // otherwise, finalize the whole graph
+ m_state = m_sink->finalize(*m_reply.get());
+ if (m_state != State::Succeeded) {
+ qCDebug(logCat) << getUid().toString() << "Request failed to finalize:" << m_url.toString();
+ m_sink->abort();
+ m_reply.reset();
+ emit failed("");
+ emit finished();
+ return;
+ }
+
+ m_reply.reset();
+ qCDebug(logCat) << getUid().toString() << "Request succeeded:" << m_url.toString();
+ emit succeeded();
+ emit finished();
+}
+
+void NetRequest::downloadReadyRead()
+{
+ if (m_state == State::Running) {
+ auto data = m_reply->readAll();
+ m_state = m_sink->write(data);
+ if (m_state == State::Failed) {
+ qCCritical(logCat) << getUid().toString() << "Failed to process response chunk";
+ }
+ // qDebug() << "Request" << m_url.toString() << "gained" << data.size() << "bytes";
+ } else {
+ qCCritical(logCat) << getUid().toString() << "Cannot write download data! illegal status " << m_status;
+ }
+}
+
+auto NetRequest::abort() -> bool
+{
+ m_state = State::AbortedByUser;
+ if (m_reply) {
+#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) // QNetworkReply::errorOccurred added in 5.15
+ disconnect(m_reply.get(), &QNetworkReply::errorOccurred, nullptr, nullptr);
+#else
+ disconnect(m_reply.get(), QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error), nullptr, nullptr);
+#endif
+ m_reply->abort();
+ }
+ return true;
+}
+
+} // namespace Net
diff --git a/launcher/net/NetRequest.h b/launcher/net/NetRequest.h
new file mode 100644
index 00000000..9a602162
--- /dev/null
+++ b/launcher/net/NetRequest.h
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
+ * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
+ * Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.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/>.
+ *
+ * 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.
+ */
+
+#pragma once
+
+#include <qloggingcategory.h>
+#include <chrono>
+
+#include "NetAction.h"
+#include "Sink.h"
+#include "Validator.h"
+
+#include "QObjectPtr.h"
+#include "net/Logging.h"
+
+namespace Net {
+class NetRequest : public NetAction {
+ Q_OBJECT
+ protected:
+ explicit NetRequest() : NetAction(){};
+
+ public:
+ using Ptr = shared_qobject_ptr<class NetRequest>;
+ enum class Option { NoOptions = 0, AcceptLocalFiles = 1, MakeEternal = 2 };
+ Q_DECLARE_FLAGS(Options, Option)
+
+ public:
+ ~NetRequest() override = default;
+
+ void init() override{};
+
+ public:
+ void addValidator(Validator* v);
+ auto abort() -> bool override;
+ auto canAbort() const -> bool override { return true; }
+
+ private:
+ auto handleRedirect() -> bool;
+ virtual QNetworkReply* getReply(QNetworkRequest&) = 0;
+
+ protected slots:
+ void downloadProgress(qint64 bytesReceived, qint64 bytesTotal) override;
+ void downloadError(QNetworkReply::NetworkError error) override;
+ void sslErrors(const QList<QSslError>& errors) override;
+ void downloadFinished() override;
+ void downloadReadyRead() override;
+
+ public slots:
+ void executeTask() override;
+
+ protected:
+ std::unique_ptr<Sink> m_sink;
+ Options m_options;
+
+ typedef const QLoggingCategory& (*logCatFunc)();
+ logCatFunc logCat = taskUploadLogC;
+
+ std::chrono::steady_clock m_clock;
+ std::chrono::time_point<std::chrono::steady_clock> m_last_progress_time;
+ qint64 m_last_progress_bytes;
+};
+} // namespace Net
+
+Q_DECLARE_OPERATORS_FOR_FLAGS(Net::NetRequest::Options)
diff --git a/launcher/net/RawHeaderProxy.h b/launcher/net/RawHeaderProxy.h
new file mode 100644
index 00000000..09b3d4d0
--- /dev/null
+++ b/launcher/net/RawHeaderProxy.h
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
+ * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
+ * Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.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/>.
+ *
+ */
+
+#pragma once
+
+#include "net/HeaderProxy.h"
+
+namespace Net {
+
+class RawHeaderProxy : public HeaderProxy {
+ public:
+ RawHeaderProxy() : HeaderProxy() {}
+ virtual ~RawHeaderProxy() = default;
+
+ public:
+ virtual QList<HeaderPair> headers(const QNetworkRequest&) const override { return m_headers; };
+
+ void addHeader(const HeaderPair& header) { m_headers.append(header); }
+ void addHeader(const QByteArray& headerName, const QByteArray& headerValue) { m_headers.append({ headerName, headerValue }); }
+ void addHeaders(const QList<HeaderPair>& headers) { m_headers.append(headers); }
+
+ private:
+ QList<HeaderPair> m_headers;
+};
+
+} // namespace Net
diff --git a/launcher/net/Upload.cpp b/launcher/net/Upload.cpp
index 3f6f5829..726572e5 100644
--- a/launcher/net/Upload.cpp
+++ b/launcher/net/Upload.cpp
@@ -38,219 +38,16 @@
#include "Upload.h"
+#include <memory>
#include <utility>
-#include "Application.h"
-#include "BuildConfig.h"
#include "ByteArraySink.h"
-#include "net/Logging.h"
-
namespace Net {
-bool Upload::abort()
-{
- if (m_reply) {
- m_reply->abort();
- } else {
- m_state = State::AbortedByUser;
- }
- return true;
-}
-
-void Upload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
-{
- setProgress(bytesReceived, bytesTotal);
-}
-
-void Upload::downloadError(QNetworkReply::NetworkError error)
-{
- if (error == QNetworkReply::OperationCanceledError) {
- qCCritical(taskUploadLogC) << getUid().toString() << "Aborted " << m_url.toString();
- m_state = State::AbortedByUser;
- } else {
- // error happened during download.
- qCCritical(taskUploadLogC) << getUid().toString() << "Failed " << m_url.toString() << " with reason " << error;
- m_state = State::Failed;
- }
-}
-
-void Upload::sslErrors(const QList<QSslError>& errors)
-{
- int i = 1;
- for (const auto& error : errors) {
- qCCritical(taskUploadLogC) << getUid().toString() << "Upload" << m_url.toString() << "SSL Error #" << i << " : "
- << error.errorString();
- auto cert = error.certificate();
- qCCritical(taskUploadLogC) << getUid().toString() << "Certificate in question:\n" << cert.toText();
- i++;
- }
-}
-
-bool Upload::handleRedirect()
-{
- QUrl redirect = m_reply->header(QNetworkRequest::LocationHeader).toUrl();
- if (!redirect.isValid()) {
- if (!m_reply->hasRawHeader("Location")) {
- // no redirect -> it's fine to continue
- return false;
- }
- // there is a Location header, but it's not correct. we need to apply some workarounds...
- QByteArray redirectBA = m_reply->rawHeader("Location");
- if (redirectBA.size() == 0) {
- // empty, yet present redirect header? WTF?
- return false;
- }
- QString redirectStr = QString::fromUtf8(redirectBA);
-
- if (redirectStr.startsWith("//")) {
- /*
- * IF the URL begins with //, we need to insert the URL scheme.
- * See: https://bugreports.qt.io/browse/QTBUG-41061
- * See: http://tools.ietf.org/html/rfc3986#section-4.2
- */
- redirectStr = m_reply->url().scheme() + ":" + redirectStr;
- } else if (redirectStr.startsWith("/")) {
- /*
- * IF the URL begins with /, we need to process it as a relative URL
- */
- auto url = m_reply->url();
- url.setPath(redirectStr, QUrl::TolerantMode);
- redirectStr = url.toString();
- }
-
- /*
- * Next, make sure the URL is parsed in tolerant mode. Qt doesn't parse the location header in tolerant mode, which causes issues.
- * FIXME: report Qt bug for this
- */
- redirect = QUrl(redirectStr, QUrl::TolerantMode);
- if (!redirect.isValid()) {
- qCWarning(taskUploadLogC) << getUid().toString() << "Failed to parse redirect URL:" << redirectStr;
- downloadError(QNetworkReply::ProtocolFailure);
- return false;
- }
- qCDebug(taskUploadLogC) << getUid().toString() << "Fixed location header:" << redirect;
- } else {
- qCDebug(taskUploadLogC) << getUid().toString() << "Location header:" << redirect;
- }
-
- m_url = QUrl(redirect.toString());
- qCDebug(taskUploadLogC) << getUid().toString() << "Following redirect to " << m_url.toString();
- startAction(m_network);
- return true;
-}
-
-void Upload::downloadFinished()
-{
- // handle HTTP redirection first
- // very unlikely for post requests, still can happen
- if (handleRedirect()) {
- qCDebug(taskUploadLogC) << getUid().toString() << "Upload redirected:" << m_url.toString();
- return;
- }
-
- // if the download failed before this point ...
- if (m_state == State::Succeeded) {
- qCDebug(taskUploadLogC) << getUid().toString() << "Upload failed but we are allowed to proceed:" << m_url.toString();
- m_sink->abort();
- m_reply.reset();
- emit succeeded();
- return;
- } else if (m_state == State::Failed) {
- qCDebug(taskUploadLogC) << getUid().toString() << "Upload failed in previous step:" << m_url.toString();
- m_sink->abort();
- m_reply.reset();
- emit failed("");
- return;
- } else if (m_state == State::AbortedByUser) {
- qCDebug(taskUploadLogC) << getUid().toString() << "Upload aborted in previous step:" << m_url.toString();
- m_sink->abort();
- m_reply.reset();
- emit aborted();
- return;
- }
-
- // make sure we got all the remaining data, if any
- auto data = m_reply->readAll();
- if (data.size()) {
- qCDebug(taskUploadLogC) << getUid().toString() << "Writing extra" << data.size() << "bytes";
- m_state = m_sink->write(data);
- }
-
- // otherwise, finalize the whole graph
- m_state = m_sink->finalize(*m_reply.get());
- if (m_state != State::Succeeded) {
- qCDebug(taskUploadLogC) << getUid().toString() << "Upload failed to finalize:" << m_url.toString();
- m_sink->abort();
- m_reply.reset();
- emit failed("");
- return;
- }
- m_reply.reset();
- qCDebug(taskUploadLogC) << getUid().toString() << "Upload succeeded:" << m_url.toString();
- emit succeeded();
-}
-
-void Upload::downloadReadyRead()
-{
- if (m_state == State::Running) {
- auto data = m_reply->readAll();
- m_state = m_sink->write(data);
- }
-}
-
-void Upload::executeTask()
+QNetworkReply* Upload::getReply(QNetworkRequest& request)
{
- setStatus(tr("Uploading %1").arg(m_url.toString()));
-
- if (m_state == State::AbortedByUser) {
- qCWarning(taskUploadLogC) << getUid().toString() << "Attempt to start an aborted Upload:" << m_url.toString();
- emit aborted();
- return;
- }
- QNetworkRequest request(m_url);
- m_state = m_sink->init(request);
- switch (m_state) {
- case State::Succeeded:
- emitSucceeded();
- qCDebug(taskUploadLogC) << getUid().toString() << "Upload cache hit " << m_url.toString();
- return;
- case State::Running:
- qCDebug(taskUploadLogC) << getUid().toString() << "Uploading " << m_url.toString();
- break;
- case State::Inactive:
- case State::Failed:
- emitFailed("");
- return;
- case State::AbortedByUser:
- emitAborted();
- return;
- }
-
- request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8());
- // TODO remove duplication
- if (APPLICATION->capabilities() & Application::SupportsFlame && request.url().host() == QUrl(BuildConfig.FLAME_BASE_URL).host()) {
- request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8());
- } else if (request.url().host() == QUrl(BuildConfig.MODRINTH_PROD_URL).host() ||
- request.url().host() == QUrl(BuildConfig.MODRINTH_STAGING_URL).host()) {
- QString token = APPLICATION->getModrinthAPIToken();
- if (!token.isNull())
- request.setRawHeader("Authorization", token.toUtf8());
- }
-
- // TODO other types of post requests ?
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
- QNetworkReply* rep = m_network->post(request, m_post_data);
-
- m_reply.reset(rep);
- connect(rep, &QNetworkReply::downloadProgress, this, &Upload::downloadProgress);
- connect(rep, &QNetworkReply::finished, this, &Upload::downloadFinished);
-#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) // QNetworkReply::errorOccurred added in 5.15
- connect(rep, &QNetworkReply::errorOccurred, this, &Upload::downloadError);
-#else
- connect(rep, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error), this, &Upload::downloadError);
-#endif
- connect(rep, &QNetworkReply::sslErrors, this, &Upload::sslErrors);
- connect(rep, &QNetworkReply::readyRead, this, &Upload::downloadReadyRead);
+ return m_network->post(request, m_post_data);
}
Upload::Ptr Upload::makeByteArray(QUrl url, std::shared_ptr<QByteArray> output, QByteArray m_post_data)
diff --git a/launcher/net/Upload.h b/launcher/net/Upload.h
index 0b0c9497..f920e556 100644
--- a/launcher/net/Upload.h
+++ b/launcher/net/Upload.h
@@ -37,36 +37,21 @@
#pragma once
-#include "NetAction.h"
-#include "Sink.h"
+#include "net/NetRequest.h"
namespace Net {
-class Upload : public NetAction {
+class Upload : public NetRequest {
Q_OBJECT
-
public:
using Ptr = shared_qobject_ptr<Upload>;
+ explicit Upload() : NetRequest() { logCat = taskUploadLogC; };
static Upload::Ptr makeByteArray(QUrl url, std::shared_ptr<QByteArray> output, QByteArray m_post_data);
- auto abort() -> bool override;
- auto canAbort() const -> bool override { return true; };
-
- protected slots:
- void downloadProgress(qint64 bytesReceived, qint64 bytesTotal) override;
- void downloadError(QNetworkReply::NetworkError error) override;
- void sslErrors(const QList<QSslError>& errors) override;
- void downloadFinished() override;
- void downloadReadyRead() override;
- public slots:
- void executeTask() override;
-
- private:
- std::unique_ptr<Sink> m_sink;
+ protected:
+ virtual QNetworkReply* getReply(QNetworkRequest&) override;
QByteArray m_post_data;
-
- bool handleRedirect();
};
} // namespace Net
diff --git a/launcher/screenshots/ImgurAlbumCreation.h b/launcher/screenshots/ImgurAlbumCreation.h
index 0228b6e4..a2b70d8b 100644
--- a/launcher/screenshots/ImgurAlbumCreation.h
+++ b/launcher/screenshots/ImgurAlbumCreation.h
@@ -57,6 +57,8 @@ public:
return m_id;
}
+ void init() override {};
+
protected
slots:
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal) override;
diff --git a/launcher/screenshots/ImgurUpload.h b/launcher/screenshots/ImgurUpload.h
index 404dc876..e8a6d8d7 100644
--- a/launcher/screenshots/ImgurUpload.h
+++ b/launcher/screenshots/ImgurUpload.h
@@ -46,6 +46,7 @@ public:
static Ptr make(ScreenShot::Ptr shot) {
return Ptr(new ImgurUpload(shot));
}
+ void init() override {};
protected
slots:
diff --git a/launcher/ui/dialogs/NewInstanceDialog.cpp b/launcher/ui/dialogs/NewInstanceDialog.cpp
index 76b139fc..2f1854d8 100644
--- a/launcher/ui/dialogs/NewInstanceDialog.cpp
+++ b/launcher/ui/dialogs/NewInstanceDialog.cpp
@@ -284,28 +284,27 @@ QString NewInstanceDialog::iconKey() const
void NewInstanceDialog::on_iconButton_clicked()
{
- importIconNow(); //so the user can switch back
+ importIconNow(); // so the user can switch back
IconPickerDialog dlg(this);
dlg.execWithSelection(InstIconKey);
- if (dlg.result() == QDialog::Accepted)
- {
+ if (dlg.result() == QDialog::Accepted) {
InstIconKey = dlg.selectedIconKey;
ui->iconButton->setIcon(APPLICATION->icons()->getIcon(InstIconKey));
importIcon = false;
}
}
-void NewInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1)
+void NewInstanceDialog::on_instNameTextBox_textChanged(const QString& arg1)
{
updateDialogState();
}
void NewInstanceDialog::importIconNow()
{
- if(importIcon) {
+ if (importIcon) {
APPLICATION->icons()->installIcon(importIconPath, importIconName);
- InstIconKey = importIconName;
+ InstIconKey = importIconName.mid(0, importIconName.lastIndexOf('.'));
importIcon = false;
}
APPLICATION->settings()->set("NewInstanceGeometry", saveGeometry().toBase64());
diff --git a/launcher/ui/dialogs/SkinUploadDialog.ui b/launcher/ui/dialogs/SkinUploadDialog.ui
index c7b16645..2c81a7fe 100644
--- a/launcher/ui/dialogs/SkinUploadDialog.ui
+++ b/launcher/ui/dialogs/SkinUploadDialog.ui
@@ -42,7 +42,7 @@
</size>
</property>
<property name="text">
- <string notr="true">...</string>
+ <string>Browse</string>
</property>
</widget>
</item>
diff --git a/launcher/ui/pages/global/ExternalToolsPage.ui b/launcher/ui/pages/global/ExternalToolsPage.ui
index 3643094d..47c77842 100644
--- a/launcher/ui/pages/global/ExternalToolsPage.ui
+++ b/launcher/ui/pages/global/ExternalToolsPage.ui
@@ -47,7 +47,7 @@
<item>
<widget class="QPushButton" name="jprofilerPathBtn">
<property name="text">
- <string notr="true">...</string>
+ <string>Browse</string>
</property>
</widget>
</item>
@@ -84,7 +84,7 @@
<item>
<widget class="QPushButton" name="jvisualvmPathBtn">
<property name="text">
- <string notr="true">...</string>
+ <string>Browse</string>
</property>
</widget>
</item>
@@ -121,7 +121,7 @@
<item>
<widget class="QPushButton" name="mceditPathBtn">
<property name="text">
- <string notr="true">...</string>
+ <string>Browse</string>
</property>
</widget>
</item>
@@ -166,7 +166,7 @@
<item row="0" column="2">
<widget class="QToolButton" name="jsonEditorBrowseBtn">
<property name="text">
- <string notr="true">...</string>
+ <string>Browse</string>
</property>
</widget>
</item>
diff --git a/launcher/ui/pages/global/JavaPage.ui b/launcher/ui/pages/global/JavaPage.ui
index 561cf79b..5a547637 100644
--- a/launcher/ui/pages/global/JavaPage.ui
+++ b/launcher/ui/pages/global/JavaPage.ui
@@ -160,37 +160,73 @@
<string>Java Runtime</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
- <item row="3" column="1">
- <widget class="QPushButton" name="javaDetectBtn">
+ <item row="7" column="0" colspan="3">
+ <widget class="QPlainTextEdit" name="jvmArgsTextBox">
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
<property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="text">
- <string>&amp;Auto-detect...</string>
+ <property name="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>100</height>
+ </size>
</property>
</widget>
</item>
- <item row="2" column="0">
- <widget class="QLabel" name="labelJVMArgs">
+ <item row="4" column="0">
+ <widget class="QCheckBox" name="skipCompatibilityCheckbox">
<property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="text">
- <string>JVM arguments:</string>
+ <property name="toolTip">
+ <string>If enabled, the launcher will not check if an instance is compatible with the selected Java version.</string>
</property>
- <property name="alignment">
- <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
+ <property name="text">
+ <string>&amp;Skip Java compatibility checks</string>
</property>
</widget>
</item>
- <item row="0" column="0">
- <widget class="QLabel" name="labelJavaPath">
+ <item row="2" column="0" colspan="3">
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QPushButton" name="javaDetectBtn">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>&amp;Auto-detect...</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="javaTestBtn">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>&amp;Test</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="6" column="0">
+ <widget class="QLabel" name="labelJVMArgs">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
@@ -198,69 +234,50 @@
</sizepolicy>
</property>
<property name="text">
- <string>&amp;Java path:</string>
- </property>
- <property name="buddy">
- <cstring>javaPathTextBox</cstring>
- </property>
- </widget>
- </item>
- <item row="3" column="2">
- <widget class="QPushButton" name="javaTestBtn">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
+ <string>JVM arguments:</string>
</property>
- <property name="text">
- <string>&amp;Test</string>
+ <property name="alignment">
+ <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
- <item row="0" column="1" colspan="2">
+ <item row="1" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
+ <widget class="QLabel" name="labelJavaPath">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>&amp;Java path:</string>
+ </property>
+ <property name="buddy">
+ <cstring>javaPathTextBox</cstring>
+ </property>
+ </widget>
+ </item>
+ <item>
<widget class="QLineEdit" name="javaPathTextBox"/>
</item>
<item>
<widget class="QPushButton" name="javaBrowseBtn">
<property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="maximumSize">
- <size>
- <width>28</width>
- <height>16777215</height>
- </size>
- </property>
<property name="text">
- <string notr="true">...</string>
+ <string>Browse</string>
</property>
</widget>
</item>
</layout>
</item>
- <item row="4" column="1">
- <widget class="QCheckBox" name="skipCompatibilityCheckbox">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="toolTip">
- <string>If enabled, the launcher will not check if an instance is compatible with the selected Java version.</string>
- </property>
- <property name="text">
- <string>&amp;Skip Java compatibility checks</string>
- </property>
- </widget>
- </item>
- <item row="5" column="1">
+ <item row="5" column="0">
<widget class="QCheckBox" name="skipJavaWizardCheckbox">
<property name="toolTip">
<string>If enabled, the launcher will not prompt you to choose a Java version if one isn't found.</string>
@@ -270,25 +287,6 @@
</property>
</widget>
</item>
- <item row="2" column="1" colspan="2">
- <widget class="QPlainTextEdit" name="jvmArgsTextBox">
- <property name="enabled">
- <bool>true</bool>
- </property>
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="maximumSize">
- <size>
- <width>16777215</width>
- <height>100</height>
- </size>
- </property>
- </widget>
- </item>
</layout>
</widget>
</item>
@@ -317,8 +315,6 @@
<tabstop>permGenSpinBox</tabstop>
<tabstop>javaBrowseBtn</tabstop>
<tabstop>javaPathTextBox</tabstop>
- <tabstop>javaDetectBtn</tabstop>
- <tabstop>javaTestBtn</tabstop>
<tabstop>tabWidget</tabstop>
</tabstops>
<resources/>
diff --git a/launcher/ui/pages/global/LauncherPage.ui b/launcher/ui/pages/global/LauncherPage.ui
index 26408f44..bc259a9b 100644
--- a/launcher/ui/pages/global/LauncherPage.ui
+++ b/launcher/ui/pages/global/LauncherPage.ui
@@ -99,7 +99,7 @@
<item row="3" column="2">
<widget class="QToolButton" name="downloadsDirBrowseBtn">
<property name="text">
- <string notr="true">...</string>
+ <string>Browse</string>
</property>
</widget>
</item>
@@ -109,7 +109,7 @@
<item row="1" column="2">
<widget class="QToolButton" name="modsDirBrowseBtn">
<property name="text">
- <string notr="true">...</string>
+ <string>Browse</string>
</property>
</widget>
</item>
@@ -126,14 +126,14 @@
<item row="0" column="2">
<widget class="QToolButton" name="instDirBrowseBtn">
<property name="text">
- <string notr="true">...</string>
+ <string>Browse</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QToolButton" name="iconsDirBrowseBtn">
<property name="text">
- <string notr="true">...</string>
+ <string>Browse</string>
</property>
</widget>
</item>
diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.ui b/launcher/ui/pages/instance/InstanceSettingsPage.ui
index 245433fe..380d8c88 100644
--- a/launcher/ui/pages/instance/InstanceSettingsPage.ui
+++ b/launcher/ui/pages/instance/InstanceSettingsPage.ui
@@ -61,31 +61,7 @@
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0" colspan="3">
- <widget class="QLineEdit" name="javaPathTextBox"/>
- </item>
- <item row="1" column="0">
- <widget class="QPushButton" name="javaDetectBtn">
- <property name="text">
- <string>Auto-detect...</string>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="QPushButton" name="javaBrowseBtn">
- <property name="text">
- <string>Browse...</string>
- </property>
- </widget>
- </item>
- <item row="1" column="2">
- <widget class="QPushButton" name="javaTestBtn">
- <property name="text">
- <string>Test</string>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
+ <item row="4" column="0">
<widget class="QCheckBox" name="skipCompatibilityCheckbox">
<property name="toolTip">
<string>If enabled, the launcher will not check if an instance is compatible with the selected Java version.</string>
@@ -95,6 +71,38 @@
</property>
</widget>
</item>
+ <item row="1" column="0">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLineEdit" name="javaPathTextBox"/>
+ </item>
+ <item>
+ <widget class="QPushButton" name="javaBrowseBtn">
+ <property name="text">
+ <string>Browse</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="2" column="0">
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QPushButton" name="javaDetectBtn">
+ <property name="text">
+ <string>Auto-detect...</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="javaTestBtn">
+ <property name="text">
+ <string>Test</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
</layout>
</widget>
</item>
@@ -699,10 +707,6 @@
<tabstop>openGlobalJavaSettingsButton</tabstop>
<tabstop>settingsTabs</tabstop>
<tabstop>javaSettingsGroupBox</tabstop>
- <tabstop>javaPathTextBox</tabstop>
- <tabstop>javaDetectBtn</tabstop>
- <tabstop>javaBrowseBtn</tabstop>
- <tabstop>javaTestBtn</tabstop>
<tabstop>memoryGroupBox</tabstop>
<tabstop>minMemSpinBox</tabstop>
<tabstop>maxMemSpinBox</tabstop>
diff --git a/launcher/ui/pages/instance/ManagedPackPage.cpp b/launcher/ui/pages/instance/ManagedPackPage.cpp
index 0fc0c986..82de9742 100644
--- a/launcher/ui/pages/instance/ManagedPackPage.cpp
+++ b/launcher/ui/pages/instance/ManagedPackPage.cpp
@@ -23,6 +23,8 @@
#include "ui/dialogs/CustomMessageBox.h"
#include "ui/dialogs/ProgressDialog.h"
+#include "net/ApiDownload.h"
+
/** This is just to override the combo box popup behavior so that the combo box doesn't take the whole screen.
* ... thanks Qt.
*/
@@ -226,7 +228,7 @@ void ModrinthManagedPackPage::parseManagedPack()
QString id = m_inst->getManagedPackID();
m_fetch_job->addNetAction(
- Net::Download::makeByteArray(QString("%1/project/%2/version").arg(BuildConfig.MODRINTH_PROD_URL, id), response));
+ Net::ApiDownload::makeByteArray(QString("%1/project/%2/version").arg(BuildConfig.MODRINTH_PROD_URL, id), response));
QObject::connect(m_fetch_job.get(), &NetJob::succeeded, this, [this, response, id] {
QJsonParseError parse_error{};
@@ -376,7 +378,7 @@ void FlameManagedPackPage::parseManagedPack()
QString id = m_inst->getManagedPackID();
- m_fetch_job->addNetAction(Net::Download::makeByteArray(QString("%1/mods/%2/files").arg(BuildConfig.FLAME_BASE_URL, id), response));
+ m_fetch_job->addNetAction(Net::ApiDownload::makeByteArray(QString("%1/mods/%2/files").arg(BuildConfig.FLAME_BASE_URL, id), response));
QObject::connect(m_fetch_job.get(), &NetJob::succeeded, this, [this, response, id] {
QJsonParseError parse_error{};
diff --git a/launcher/ui/pages/modplatform/ResourceModel.cpp b/launcher/ui/pages/modplatform/ResourceModel.cpp
index 49405a02..3e0c0257 100644
--- a/launcher/ui/pages/modplatform/ResourceModel.cpp
+++ b/launcher/ui/pages/modplatform/ResourceModel.cpp
@@ -17,7 +17,7 @@
#include "BuildConfig.h"
#include "Json.h"
-#include "net/Download.h"
+#include "net/ApiDownload.h"
#include "net/NetJob.h"
#include "modplatform/ModIndex.h"
@@ -281,7 +281,7 @@ std::optional<QIcon> ResourceModel::getIcon(QModelIndex& index, const QUrl& url)
auto cache_entry = APPLICATION->metacache()->resolveEntry(
metaEntryBase(),
QString("logos/%1").arg(QString(QCryptographicHash::hash(url.toEncoded(), QCryptographicHash::Algorithm::Sha1).toHex())));
- auto icon_fetch_action = Net::Download::makeCached(url, cache_entry);
+ auto icon_fetch_action = Net::ApiDownload::makeCached(url, cache_entry);
auto full_file_path = cache_entry->getFullPath();
connect(icon_fetch_action.get(), &NetAction::succeeded, this, [=] {
diff --git a/launcher/ui/pages/modplatform/atlauncher/AtlListModel.cpp b/launcher/ui/pages/modplatform/atlauncher/AtlListModel.cpp
index c6b087d6..39f4f346 100644
--- a/launcher/ui/pages/modplatform/atlauncher/AtlListModel.cpp
+++ b/launcher/ui/pages/modplatform/atlauncher/AtlListModel.cpp
@@ -20,6 +20,8 @@
#include <BuildConfig.h>
#include <Json.h>
+#include "net/ApiDownload.h"
+
namespace Atl {
ListModel::ListModel(QObject* parent) : QAbstractListModel(parent) {}
@@ -75,7 +77,7 @@ void ListModel::request()
auto netJob = makeShared<NetJob>("Atl::Request", APPLICATION->network());
auto url = QString(BuildConfig.ATL_DOWNLOAD_SERVER_URL + "launcher/json/packsnew.json");
- netJob->addNetAction(Net::Download::makeByteArray(QUrl(url), response));
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(QUrl(url), response));
jobPtr = netJob;
jobPtr->start();
@@ -137,8 +139,7 @@ void ListModel::requestFailed(QString reason)
void ListModel::getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback)
{
if (m_logoMap.contains(logo)) {
- callback(
- APPLICATION->metacache()->resolveEntry("ATLauncherPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath());
+ callback(APPLICATION->metacache()->resolveEntry("ATLauncherPacks", QString("logos/%1").arg(logo))->getFullPath());
} else {
requestLogo(logo, logoUrl);
}
@@ -168,9 +169,9 @@ void ListModel::requestLogo(QString file, QString url)
return;
}
- MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("ATLauncherPacks", QString("logos/%1").arg(file.section(".", 0, 0)));
+ MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("ATLauncherPacks", QString("logos/%1").arg(file));
auto job = new NetJob(QString("ATLauncher Icon Download %1").arg(file), APPLICATION->network());
- job->addNetAction(Net::Download::makeCached(QUrl(url), entry));
+ job->addNetAction(Net::ApiDownload::makeCached(QUrl(url), entry));
auto fullPath = entry->getFullPath();
QObject::connect(job, &NetJob::succeeded, this, [this, file, fullPath, job] {
diff --git a/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.cpp b/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.cpp
index 7b61daa7..267894bf 100644
--- a/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.cpp
+++ b/launcher/ui/pages/modplatform/atlauncher/AtlOptionalModDialog.cpp
@@ -43,6 +43,8 @@
#include "modplatform/atlauncher/ATLShareCode.h"
#include "Application.h"
+#include "net/ApiDownload.h"
+
AtlOptionalModListModel::AtlOptionalModListModel(QWidget* parent, ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods)
: QAbstractListModel(parent)
, m_version(version)
@@ -152,7 +154,7 @@ Qt::ItemFlags AtlOptionalModListModel::flags(const QModelIndex &index) const {
void AtlOptionalModListModel::useShareCode(const QString& code) {
m_jobPtr.reset(new NetJob("Atl::Request", APPLICATION->network()));
auto url = QString(BuildConfig.ATL_API_BASE_URL + "share-codes/" + code);
- m_jobPtr->addNetAction(Net::Download::makeByteArray(QUrl(url), m_response));
+ m_jobPtr->addNetAction(Net::ApiDownload::makeByteArray(QUrl(url), m_response));
connect(m_jobPtr.get(), &NetJob::succeeded,
this, &AtlOptionalModListModel::shareCodeSuccess);
diff --git a/launcher/ui/pages/modplatform/flame/FlameModel.cpp b/launcher/ui/pages/modplatform/flame/FlameModel.cpp
index fa55aa68..e32024c4 100644
--- a/launcher/ui/pages/modplatform/flame/FlameModel.cpp
+++ b/launcher/ui/pages/modplatform/flame/FlameModel.cpp
@@ -3,6 +3,8 @@
#include "Application.h"
#include "ui/widgets/ProjectItem.h"
+#include "net/ApiDownload.h"
+
#include <Version.h>
#include <QtMath>
@@ -40,14 +42,16 @@ QVariant ListModel::data(const QModelIndex& index, int role) const
return edit;
}
return pack.description;
- } case Qt::DecorationRole: {
+ }
+ case Qt::DecorationRole: {
if (m_logoMap.contains(pack.logoName)) {
return (m_logoMap.value(pack.logoName));
}
QIcon icon = APPLICATION->getThemedIcon("screenshot-placeholder");
((ListModel*)this)->requestLogo(pack.logoName, pack.logoUrl);
return icon;
- } case Qt::UserRole: {
+ }
+ case Qt::UserRole: {
QVariant v;
v.setValue(pack);
return v;
@@ -68,7 +72,7 @@ QVariant ListModel::data(const QModelIndex& index, int role) const
return QVariant();
}
-bool ListModel::setData(const QModelIndex &index, const QVariant &value, int role)
+bool ListModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
int pos = index.row();
if (pos >= modpacks.size() || pos < 0 || !index.isValid())
@@ -102,9 +106,9 @@ void ListModel::requestLogo(QString logo, QString url)
return;
}
- MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("FlamePacks", QString("logos/%1").arg(logo.section(".", 0, 0)));
+ MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("FlamePacks", QString("logos/%1").arg(logo));
auto job = new NetJob(QString("Flame Icon Download %1").arg(logo), APPLICATION->network());
- job->addNetAction(Net::Download::makeCached(QUrl(url), entry));
+ job->addNetAction(Net::ApiDownload::makeCached(QUrl(url), entry));
auto fullPath = entry->getFullPath();
QObject::connect(job, &NetJob::succeeded, this, [this, logo, fullPath, job] {
@@ -128,7 +132,7 @@ void ListModel::requestLogo(QString logo, QString url)
void ListModel::getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback)
{
if (m_logoMap.contains(logo)) {
- callback(APPLICATION->metacache()->resolveEntry("FlamePacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath());
+ callback(APPLICATION->metacache()->resolveEntry("FlamePacks", QString("logos/%1").arg(logo))->getFullPath());
} else {
requestLogo(logo, logoUrl);
}
@@ -171,7 +175,7 @@ void ListModel::performPaginatedSearch()
.arg(currentSearchTerm)
.arg(currentSort + 1);
- netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), response));
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(QUrl(searchUrl), response));
jobPtr = netJob;
jobPtr->start();
QObject::connect(netJob.get(), &NetJob::succeeded, this, &ListModel::searchRequestFinished);
diff --git a/launcher/ui/pages/modplatform/flame/FlamePage.cpp b/launcher/ui/pages/modplatform/flame/FlamePage.cpp
index cef26bb6..ada67644 100644
--- a/launcher/ui/pages/modplatform/flame/FlamePage.cpp
+++ b/launcher/ui/pages/modplatform/flame/FlamePage.cpp
@@ -42,9 +42,11 @@
#include "FlameModel.h"
#include "InstanceImportTask.h"
#include "Json.h"
+#include "modplatform/flame/FlameAPI.h"
#include "ui/dialogs/NewInstanceDialog.h"
#include "ui/widgets/ProjectItem.h"
-#include "modplatform/flame/FlameAPI.h"
+
+#include "net/ApiDownload.h"
static FlameAPI api;
@@ -132,7 +134,7 @@ void FlamePage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
auto netJob = new NetJob(QString("Flame::PackVersions(%1)").arg(current.name), APPLICATION->network());
auto response = std::make_shared<QByteArray>();
int addonId = current.addonId;
- netJob->addNetAction(Net::Download::makeByteArray(QString("https://api.curseforge.com/v1/mods/%1/files").arg(addonId), response));
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(QString("https://api.curseforge.com/v1/mods/%1/files").arg(addonId), response));
QObject::connect(netJob, &NetJob::succeeded, this, [this, response, addonId, curr] {
if (addonId != current.addonId) {
@@ -207,7 +209,7 @@ void FlamePage::suggestCurrent()
dialog->setSuggestedPack(current.name, new InstanceImportTask(version.downloadUrl, this, std::move(extra_info)));
QString editedLogoName;
- editedLogoName = "curseforge_" + current.logoName.section(".", 0, 0);
+ editedLogoName = "curseforge_" + current.logoName;
listModel->getLogo(current.logoName, current.logoUrl,
[this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); });
}
@@ -252,10 +254,8 @@ void FlamePage::updateUi()
text += "<br>" + tr(" by ") + authorStrs.join(", ");
}
- if(current.extraInfoLoaded) {
- if (!current.extra.issuesUrl.isEmpty()
- || !current.extra.sourceUrl.isEmpty()
- || !current.extra.wikiUrl.isEmpty()) {
+ if (current.extraInfoLoaded) {
+ if (!current.extra.issuesUrl.isEmpty() || !current.extra.sourceUrl.isEmpty() || !current.extra.wikiUrl.isEmpty()) {
text += "<br><br>" + tr("External links:") + "<br>";
}
@@ -267,7 +267,6 @@ void FlamePage::updateUi()
text += "- " + tr("Source code: <a href=%1>%1</a>").arg(current.extra.sourceUrl) + "<br>";
}
-
text += "<hr>";
text += api.getModDescription(current.addonId).toUtf8();
diff --git a/launcher/ui/pages/modplatform/legacy_ftb/ListModel.cpp b/launcher/ui/pages/modplatform/legacy_ftb/ListModel.cpp
index 330dd4fb..a42d4dad 100644
--- a/launcher/ui/pages/modplatform/legacy_ftb/ListModel.cpp
+++ b/launcher/ui/pages/modplatform/legacy_ftb/ListModel.cpp
@@ -37,6 +37,7 @@
#include "Application.h"
#include "net/HttpMetaCache.h"
#include "net/NetJob.h"
+#include "net/ApiDownload.h"
#include <Version.h>
#include "StringUtils.h"
@@ -229,9 +230,9 @@ void ListModel::requestLogo(QString file)
return;
}
- MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(file.section(".", 0, 0)));
+ MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(file));
NetJob* job = new NetJob(QString("FTB Icon Download for %1").arg(file), APPLICATION->network());
- job->addNetAction(Net::Download::makeCached(QUrl(QString(BuildConfig.LEGACY_FTB_CDN_BASE_URL + "static/%1").arg(file)), entry));
+ job->addNetAction(Net::ApiDownload::makeCached(QUrl(QString(BuildConfig.LEGACY_FTB_CDN_BASE_URL + "static/%1").arg(file)), entry));
auto fullPath = entry->getFullPath();
QObject::connect(job, &NetJob::finished, this, [this, file, fullPath, job] {
@@ -255,7 +256,7 @@ void ListModel::requestLogo(QString file)
void ListModel::getLogo(const QString& logo, LogoCallback callback)
{
if (m_logoMap.contains(logo)) {
- callback(APPLICATION->metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath());
+ callback(APPLICATION->metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(logo))->getFullPath());
} else {
requestLogo(logo);
}
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp
index e0046d88..ee498743 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp
@@ -42,6 +42,8 @@
#include "minecraft/PackProfile.h"
#include "ui/widgets/ProjectItem.h"
+#include "net/ApiDownload.h"
+
#include <QMessageBox>
namespace Modrinth {
@@ -142,7 +144,7 @@ void ModpackListModel::performPaginatedSearch()
.arg(currentSearchTerm)
.arg(currentSort);
- netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchAllUrl), m_all_response));
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(QUrl(searchAllUrl), m_all_response));
QObject::connect(netJob.get(), &NetJob::succeeded, this, [this] {
QJsonParseError parse_error_all{};
@@ -218,9 +220,7 @@ void ModpackListModel::searchWithTerm(const QString& term, const int sort)
void ModpackListModel::getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback)
{
if (m_logoMap.contains(logo)) {
- callback(APPLICATION->metacache()
- ->resolveEntry(m_parent->metaEntryBase(), QString("logos/%1").arg(logo.section(".", 0, 0)))
- ->getFullPath());
+ callback(APPLICATION->metacache()->resolveEntry(m_parent->metaEntryBase(), QString("logos/%1").arg(logo))->getFullPath());
} else {
requestLogo(logo, logoUrl);
}
@@ -232,10 +232,9 @@ void ModpackListModel::requestLogo(QString logo, QString url)
return;
}
- MetaEntryPtr entry =
- APPLICATION->metacache()->resolveEntry(m_parent->metaEntryBase(), QString("logos/%1").arg(logo.section(".", 0, 0)));
+ MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry(m_parent->metaEntryBase(), QString("logos/%1").arg(logo));
auto job = new NetJob(QString("%1 Icon Download %2").arg(m_parent->debugName()).arg(logo), APPLICATION->network());
- job->addNetAction(Net::Download::makeCached(QUrl(url), entry));
+ job->addNetAction(Net::ApiDownload::makeCached(QUrl(url), entry));
auto fullPath = entry->getFullPath();
QObject::connect(job, &NetJob::succeeded, this, [this, logo, fullPath, job] {
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp
index c71dd903..e7d75dcf 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp
@@ -46,6 +46,8 @@
#include "ui/widgets/ProjectItem.h"
+#include "net/ApiDownload.h"
+
#include <QComboBox>
#include <QKeyEvent>
#include <QPushButton>
@@ -127,7 +129,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
QString id = current.id;
- netJob->addNetAction(Net::Download::makeByteArray(QString("%1/project/%2").arg(BuildConfig.MODRINTH_PROD_URL, id), response));
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(QString("%1/project/%2").arg(BuildConfig.MODRINTH_PROD_URL, id), response));
QObject::connect(netJob, &NetJob::succeeded, this, [this, response, id, curr] {
if (id != current.id) {
@@ -176,7 +178,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
QString id = current.id;
netJob->addNetAction(
- Net::Download::makeByteArray(QString("%1/project/%2/version").arg(BuildConfig.MODRINTH_PROD_URL, id), response));
+ Net::ApiDownload::makeByteArray(QString("%1/project/%2/version").arg(BuildConfig.MODRINTH_PROD_URL, id), response));
QObject::connect(netJob, &NetJob::succeeded, this, [this, response, id, curr] {
if (id != current.id) {
diff --git a/launcher/ui/pages/modplatform/technic/TechnicModel.cpp b/launcher/ui/pages/modplatform/technic/TechnicModel.cpp
index f08eb289..5ba804db 100644
--- a/launcher/ui/pages/modplatform/technic/TechnicModel.cpp
+++ b/launcher/ui/pages/modplatform/technic/TechnicModel.cpp
@@ -38,6 +38,8 @@
#include "BuildConfig.h"
#include "Json.h"
+#include "net/ApiDownload.h"
+
#include <QIcon>
Technic::ListModel::ListModel(QObject* parent) : QAbstractListModel(parent) {}
@@ -116,7 +118,7 @@ void Technic::ListModel::performSearch()
QString("%1search?build=%2&q=%3").arg(BuildConfig.TECHNIC_API_BASE_URL, BuildConfig.TECHNIC_API_BUILD, currentSearchTerm);
searchMode = List;
}
- netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), response));
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(QUrl(searchUrl), response));
jobPtr = netJob;
jobPtr->start();
QObject::connect(netJob.get(), &NetJob::succeeded, this, &ListModel::searchRequestFinished);
@@ -157,7 +159,7 @@ void Technic::ListModel::searchRequestFinished()
pack.logoName = "null";
} else {
pack.logoUrl = rawURL;
- pack.logoName = rawURL.section(QLatin1Char('/'), -1).section(QLatin1Char('.'), 0, 0);
+ pack.logoName = rawURL.section(QLatin1Char('/'), -1);
}
pack.broken = false;
newList.append(pack);
@@ -179,7 +181,7 @@ void Technic::ListModel::searchRequestFinished()
auto iconUrl = Json::requireString(iconObj, "url");
pack.logoUrl = iconUrl;
- pack.logoName = iconUrl.section(QLatin1Char('/'), -1).section(QLatin1Char('.'), 0, 0);
+ pack.logoName = iconUrl.section(QLatin1Char('/'), -1);
} else {
pack.logoUrl = "null";
pack.logoName = "null";
@@ -254,7 +256,7 @@ void Technic::ListModel::requestLogo(QString logo, QString url)
MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("TechnicPacks", QString("logos/%1").arg(logo));
auto job = new NetJob(QString("Technic Icon Download %1").arg(logo), APPLICATION->network());
- job->addNetAction(Net::Download::makeCached(QUrl(url), entry));
+ job->addNetAction(Net::ApiDownload::makeCached(QUrl(url), entry));
auto fullPath = entry->getFullPath();
diff --git a/launcher/ui/pages/modplatform/technic/TechnicPage.cpp b/launcher/ui/pages/modplatform/technic/TechnicPage.cpp
index fc678fa2..e066fa6f 100644
--- a/launcher/ui/pages/modplatform/technic/TechnicPage.cpp
+++ b/launcher/ui/pages/modplatform/technic/TechnicPage.cpp
@@ -49,6 +49,8 @@
#include "Application.h"
#include "modplatform/technic/SolderPackManifest.h"
+#include "net/ApiDownload.h"
+
TechnicPage::TechnicPage(NewInstanceDialog* dialog, QWidget *parent)
: QWidget(parent), ui(new Ui::TechnicPage), dialog(dialog)
{
@@ -129,21 +131,18 @@ void TechnicPage::suggestCurrent()
return;
}
- QString editedLogoName = "technic_" + current.logoName.section(".", 0, 0);
- model->getLogo(current.logoName, current.logoUrl, [this, editedLogoName](QString logo)
- {
- dialog->setSuggestedIconFromFile(logo, editedLogoName);
- });
+ QString editedLogoName = "technic_" + current.logoName;
+ model->getLogo(current.logoName, current.logoUrl,
+ [this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); });
- if (current.metadataLoaded)
- {
+ if (current.metadataLoaded) {
metadataLoaded();
return;
}
auto netJob = makeShared<NetJob>(QString("Technic::PackMeta(%1)").arg(current.name), APPLICATION->network());
QString slug = current.slug;
- netJob->addNetAction(Net::Download::makeByteArray(QString("%1modpack/%2?build=%3").arg(BuildConfig.TECHNIC_API_BASE_URL, slug, BuildConfig.TECHNIC_API_BUILD), response));
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(QString("%1modpack/%2?build=%3").arg(BuildConfig.TECHNIC_API_BASE_URL, slug, BuildConfig.TECHNIC_API_BUILD), response));
QObject::connect(netJob.get(), &NetJob::succeeded, this, [this, slug]
{
jobPtr.reset();
@@ -249,7 +248,7 @@ void TechnicPage::metadataLoaded()
auto netJob = makeShared<NetJob>(QString("Technic::SolderMeta(%1)").arg(current.name), APPLICATION->network());
auto url = QString("%1/modpack/%2").arg(current.url, current.slug);
- netJob->addNetAction(Net::Download::makeByteArray(QUrl(url), response));
+ netJob->addNetAction(Net::ApiDownload::makeByteArray(QUrl(url), response));
QObject::connect(netJob.get(), &NetJob::succeeded, this, &TechnicPage::onSolderLoaded);
diff --git a/launcher/ui/widgets/PageContainer_p.h b/launcher/ui/widgets/PageContainer_p.h
index da1a66f4..8bf26618 100644
--- a/launcher/ui/widgets/PageContainer_p.h
+++ b/launcher/ui/widgets/PageContainer_p.h
@@ -103,6 +103,8 @@ public:
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
setItemDelegate(new PageViewDelegate(this));
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ // Adjust margins when using Breeze theme
+ setProperty("_kde_side_panel_view", true);
}
virtual QSize sizeHint() const
diff --git a/launcher/ui/widgets/VariableSizedImageObject.cpp b/launcher/ui/widgets/VariableSizedImageObject.cpp
index 991b4a04..3aa3343d 100644
--- a/launcher/ui/widgets/VariableSizedImageObject.cpp
+++ b/launcher/ui/widgets/VariableSizedImageObject.cpp
@@ -26,6 +26,7 @@
#include "Application.h"
#include "net/NetJob.h"
+#include "net/ApiDownload.h"
enum FormatProperties { ImageData = QTextFormat::UserProperty + 1 };
@@ -97,7 +98,7 @@ void VariableSizedImageObject::loadImage(QTextDocument* doc, const QUrl& source,
QString("images/%1").arg(QString(QCryptographicHash::hash(source.toEncoded(), QCryptographicHash::Algorithm::Sha1).toHex())));
auto job = new NetJob(QString("Load Image: %1").arg(source.fileName()), APPLICATION->network());
- job->addNetAction(Net::Download::makeCached(source, entry));
+ job->addNetAction(Net::ApiDownload::makeCached(source, entry));
auto full_entry_path = entry->getFullPath();
auto source_url = source;
diff --git a/launcher/ui/widgets/WideBar.cpp b/launcher/ui/widgets/WideBar.cpp
index a77c45fe..3b57ee89 100644
--- a/launcher/ui/widgets/WideBar.cpp
+++ b/launcher/ui/widgets/WideBar.cpp
@@ -204,8 +204,10 @@ static void copyAction(QAction* from, QAction* to)
void WideBar::showVisibilityMenu(QPoint const& position)
{
- if (!m_bar_menu)
+ if (!m_bar_menu) {
m_bar_menu = std::make_unique<QMenu>(this);
+ m_bar_menu->setTearOffEnabled(true);
+ }
if (m_menu_state == MenuState::Dirty) {
for (auto* old_action : m_bar_menu->actions())