diff options
Diffstat (limited to 'launcher')
25 files changed, 499 insertions, 80 deletions
diff --git a/launcher/Application.cpp b/launcher/Application.cpp index a1393510..78de8747 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -194,8 +194,11 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) { { "s", "server" }, "Join the specified server on launch (only valid in combination with --launch)", "address" }, { { "a", "profile" }, "Use the account specified by its profile name (only valid in combination with --launch)", "profile" }, { "alive", "Write a small '" + liveCheckFile + "' file after the launcher starts" }, - { { "I", "import" }, "Import instance from specified zip (local path or URL)", "file" }, + { { "I", "import" }, "Import instance or resource from specified local path or URL", "url" }, { "show", "Opens the window for the specified instance (by instance ID)", "show" } }); + // Has to be positional for some OS to handle that properly + parser.addPositionalArgument("URL", "Import the resource(s) at the given URL(s) (same as -I / --import)", "[URL...]"); + parser.addHelpOption(); parser.addVersionOption(); @@ -208,13 +211,13 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) m_instanceIdToShowWindowOf = parser.value("show"); - for (auto zip_path : parser.values("import")) { - m_zipsToImport.append(QUrl::fromLocalFile(QFileInfo(zip_path).absoluteFilePath())); + for (auto url : parser.values("import")) { + m_urlsToImport.append(normalizeImportUrl(url)); } // treat unspecified positional arguments as import urls - for (auto zip_path : parser.positionalArguments()) { - m_zipsToImport.append(QUrl::fromLocalFile(QFileInfo(zip_path).absoluteFilePath())); + for (auto url : parser.positionalArguments()) { + m_urlsToImport.append(normalizeImportUrl(url)); } // error if --launch is missing with --server or --profile @@ -313,11 +316,11 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) activate.command = "activate"; m_peerInstance->sendMessage(activate.serialize(), timeout); - if (!m_zipsToImport.isEmpty()) { - for (auto zip_url : m_zipsToImport) { + if (!m_urlsToImport.isEmpty()) { + for (auto url : m_urlsToImport) { ApplicationMessage import; import.command = "import"; - import.args.insert("path", zip_url.toString()); + import.args.insert("url", url.toString()); m_peerInstance->sendMessage(import.serialize(), timeout); } } @@ -582,7 +585,9 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) // Native library workarounds m_settings->registerSetting("UseNativeOpenAL", false); + m_settings->registerSetting("CustomOpenALPath", ""); m_settings->registerSetting("UseNativeGLFW", false); + m_settings->registerSetting("CustomGLFWPath", ""); // Peformance related options m_settings->registerSetting("EnableFeralGamemode", false); @@ -842,6 +847,8 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) updateCapabilities(); + detectLibraries(); + if (createSetupWizard()) { return; } @@ -978,9 +985,9 @@ void Application::performMainStartupAction() showMainWindow(false); qDebug() << "<> Main window shown."; } - if (!m_zipsToImport.isEmpty()) { - qDebug() << "<> Importing from zip:" << m_zipsToImport; - m_mainWindow->processURLs(m_zipsToImport); + if (!m_urlsToImport.isEmpty()) { + qDebug() << "<> Importing from url:" << m_urlsToImport; + m_mainWindow->processURLs(m_urlsToImport); } } @@ -1022,12 +1029,12 @@ void Application::messageReceived(const QByteArray& message) if (command == "activate") { showMainWindow(); } else if (command == "import") { - QString path = received.args["path"]; - if (path.isEmpty()) { + QString url = received.args["url"]; + if (url.isEmpty()) { qWarning() << "Received" << command << "message without a zip path/URL."; return; } - m_mainWindow->processURLs({ QUrl::fromLocalFile(QFileInfo(path).absoluteFilePath()) }); + m_mainWindow->processURLs({ normalizeImportUrl(url) }); } else if (command == "launch") { QString id = received.args["id"]; QString server = received.args["server"]; @@ -1412,6 +1419,15 @@ void Application::updateCapabilities() #endif } +void Application::detectLibraries() +{ +#ifdef Q_OS_LINUX + m_detectedGLFWPath = MangoHud::findLibrary(BuildConfig.GLFW_LIBRARY_NAME); + m_detectedOpenALPath = MangoHud::findLibrary(BuildConfig.OPENAL_LIBRARY_NAME); + qDebug() << "Detected native libraries:" << m_detectedGLFWPath << m_detectedOpenALPath; +#endif +} + QString Application::getJarPath(QString jarFile) { QStringList potentialPaths = { @@ -1590,3 +1606,13 @@ void Application::triggerUpdateCheck() qDebug() << "Updater not available."; } } + +QUrl Application::normalizeImportUrl(QString const& url) +{ + auto local_file = QFileInfo(url); + if (local_file.exists()) { + return QUrl::fromLocalFile(local_file.absoluteFilePath()); + } else { + return QUrl::fromUserInput(url); + } +} diff --git a/launcher/Application.h b/launcher/Application.h index 6bc33274..29774b1c 100644 --- a/launcher/Application.h +++ b/launcher/Application.h @@ -142,6 +142,8 @@ class Application : public QApplication { void updateCapabilities(); + void detectLibraries(); + /*! * Finds and returns the full path to a jar file. * Returns a null-string if it could not be found. @@ -177,6 +179,8 @@ class Application : public QApplication { int suitableMaxMem(); + QUrl normalizeImportUrl(QString const& url); + signals: void updateAllowedChanged(bool status); void globalSettingsAboutToOpen(); @@ -275,11 +279,13 @@ class Application : public QApplication { SetupWizard* m_setupWizard = nullptr; public: + QString m_detectedGLFWPath; + QString m_detectedOpenALPath; QString m_instanceIdToLaunch; QString m_serverToJoin; QString m_profileToUse; bool m_liveCheck = false; - QList<QUrl> m_zipsToImport; + QList<QUrl> m_urlsToImport; QString m_instanceIdToShowWindowOf; std::unique_ptr<QFile> logFile; }; diff --git a/launcher/InstanceImportTask.cpp b/launcher/InstanceImportTask.cpp index 3f948a33..bc139e4f 100644 --- a/launcher/InstanceImportTask.cpp +++ b/launcher/InstanceImportTask.cpp @@ -50,6 +50,7 @@ #include "modplatform/technic/TechnicPackProcessor.h" #include "settings/INISettingsObject.h" +#include "tasks/Task.h" #include "net/ApiDownload.h" @@ -90,25 +91,27 @@ void InstanceImportTask::executeTask() setStatus(tr("Downloading modpack:\n%1").arg(m_sourceUrl.toString())); m_downloadRequired = true; - const QString path(m_sourceUrl.host() + '/' + m_sourceUrl.path()); - - auto entry = APPLICATION->metacache()->resolveEntry("general", path); - entry->setStale(true); - m_archivePath = entry->getFullPath(); - - m_filesNetJob.reset(new NetJob(tr("Modpack download"), APPLICATION->network())); - 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); - connect(m_filesNetJob.get(), &NetJob::stepProgress, this, &InstanceImportTask::propagateStepProgress); - connect(m_filesNetJob.get(), &NetJob::failed, this, &InstanceImportTask::downloadFailed); - connect(m_filesNetJob.get(), &NetJob::aborted, this, &InstanceImportTask::downloadAborted); - - m_filesNetJob->start(); + downloadFromUrl(); } } +void InstanceImportTask::downloadFromUrl() +{ + const QString path = m_sourceUrl.host() + '/' + m_sourceUrl.path(); + auto entry = APPLICATION->metacache()->resolveEntry("general", path); + entry->setStale(true); + m_filesNetJob.reset(new NetJob(tr("Modpack download"), APPLICATION->network())); + m_filesNetJob->addNetAction(Net::ApiDownload::makeCached(m_sourceUrl, entry)); + m_archivePath = entry->getFullPath(); + + connect(m_filesNetJob.get(), &NetJob::succeeded, this, &InstanceImportTask::downloadSucceeded); + connect(m_filesNetJob.get(), &NetJob::progress, this, &InstanceImportTask::downloadProgressChanged); + connect(m_filesNetJob.get(), &NetJob::stepProgress, this, &InstanceImportTask::propagateStepProgress); + connect(m_filesNetJob.get(), &NetJob::failed, this, &InstanceImportTask::downloadFailed); + connect(m_filesNetJob.get(), &NetJob::aborted, this, &InstanceImportTask::downloadAborted); + m_filesNetJob->start(); +} + void InstanceImportTask::downloadSucceeded() { processZipPack(); diff --git a/launcher/InstanceImportTask.h b/launcher/InstanceImportTask.h index 4459e440..ca3d30ad 100644 --- a/launcher/InstanceImportTask.h +++ b/launcher/InstanceImportTask.h @@ -101,4 +101,5 @@ class InstanceImportTask : public InstanceTask { // FIXME: nuke QWidget* m_parent; + void downloadFromUrl(); }; diff --git a/launcher/MangoHud.cpp b/launcher/MangoHud.cpp index 5758da3a..ab79f418 100644 --- a/launcher/MangoHud.cpp +++ b/launcher/MangoHud.cpp @@ -16,6 +16,7 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ +#include <QDebug> #include <QDir> #include <QString> #include <QStringList> @@ -26,6 +27,15 @@ #include "Json.h" #include "MangoHud.h" +#ifdef __GLIBC__ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#define UNDEF_GNU_SOURCE +#endif +#include <dlfcn.h> +#include <linux/limits.h> +#endif + namespace MangoHud { QString getLibraryString() @@ -106,4 +116,37 @@ QString getLibraryString() return QString(); } + +QString findLibrary(QString libName) +{ +#ifdef __GLIBC__ + const char* library = libName.toLocal8Bit().constData(); + + void* handle = dlopen(library, RTLD_NOW); + if (!handle) { + qCritical() << "dlopen() failed:" << dlerror(); + return {}; + } + + char path[PATH_MAX]; + if (dlinfo(handle, RTLD_DI_ORIGIN, path) == -1) { + qCritical() << "dlinfo() failed:" << dlerror(); + dlclose(handle); + return {}; + } + + auto fullPath = FS::PathCombine(QString(path), libName); + + dlclose(handle); + return fullPath; +#else + qWarning() << "MangoHud::findLibrary is not implemented on this platform"; + return {}; +#endif +} } // namespace MangoHud + +#ifdef UNDEF_GNU_SOURCE +#undef _GNU_SOURCE +#undef UNDEF_GNU_SOURCE +#endif diff --git a/launcher/MangoHud.h b/launcher/MangoHud.h index 7b7c2849..5361999b 100644 --- a/launcher/MangoHud.h +++ b/launcher/MangoHud.h @@ -24,4 +24,6 @@ namespace MangoHud { QString getLibraryString(); -} + +QString findLibrary(QString libName); +} // namespace MangoHud diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index 305bff67..62d22019 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -166,7 +166,9 @@ void MinecraftInstance::loadSpecificSettings() // Native library workarounds auto nativeLibraryWorkaroundsOverride = m_settings->registerSetting("OverrideNativeWorkarounds", false); m_settings->registerOverride(global_settings->getSetting("UseNativeOpenAL"), nativeLibraryWorkaroundsOverride); + m_settings->registerOverride(global_settings->getSetting("CustomOpenALPath"), nativeLibraryWorkaroundsOverride); m_settings->registerOverride(global_settings->getSetting("UseNativeGLFW"), nativeLibraryWorkaroundsOverride); + m_settings->registerOverride(global_settings->getSetting("CustomGLFWPath"), nativeLibraryWorkaroundsOverride); // Peformance related options auto performanceOverride = m_settings->registerSetting("OverridePerformance", false); @@ -389,6 +391,33 @@ QStringList MinecraftInstance::extraArguments() if (loaders.has_value() && loaders.value() & ResourceAPI::Quilt && settings()->get("DisableQuiltBeacon").toBool()) list.append("-Dloader.disable_beacon=true"); } + + { + QString openALPath; + QString glfwPath; + + if (settings()->get("UseNativeOpenAL").toBool()) { + openALPath = APPLICATION->m_detectedOpenALPath; + auto customPath = settings()->get("CustomOpenALPath").toString(); + if (!customPath.isEmpty()) + openALPath = customPath; + } + if (settings()->get("UseNativeGLFW").toBool()) { + glfwPath = APPLICATION->m_detectedGLFWPath; + auto customPath = settings()->get("CustomGLFWPath").toString(); + if (!customPath.isEmpty()) + glfwPath = customPath; + } + + QFileInfo openALInfo(openALPath); + QFileInfo glfwInfo(glfwPath); + + if (!openALPath.isEmpty() && openALInfo.exists()) + list.append("-Dorg.lwjgl.openal.libname=" + openALInfo.absoluteFilePath()); + if (!glfwPath.isEmpty() && glfwInfo.exists()) + list.append("-Dorg.lwjgl.glfw.libname=" + glfwInfo.absoluteFilePath()); + } + return list; } diff --git a/launcher/minecraft/launch/ExtractNatives.cpp b/launcher/minecraft/launch/ExtractNatives.cpp index cebeaedd..8f3cac4d 100644 --- a/launcher/minecraft/launch/ExtractNatives.cpp +++ b/launcher/minecraft/launch/ExtractNatives.cpp @@ -39,7 +39,7 @@ static QString replaceSuffix(QString target, const QString& suffix, const QStrin return target + replacement; } -static bool unzipNatives(QString source, QString targetFolder, bool applyJnilibHack, bool nativeOpenAL, bool nativeGLFW) +static bool unzipNatives(QString source, QString targetFolder, bool applyJnilibHack) { QuaZip zip(source); if (!zip.open(QuaZip::mdUnzip)) { @@ -52,12 +52,6 @@ static bool unzipNatives(QString source, QString targetFolder, bool applyJnilibH do { QString name = zip.getCurrentFileName(); auto lowercase = name.toLower(); - if (nativeGLFW && name.contains("glfw")) { - continue; - } - if (nativeOpenAL && name.contains("openal")) { - continue; - } if (applyJnilibHack) { name = replaceSuffix(name, ".jnilib", ".dylib"); } @@ -83,14 +77,12 @@ void ExtractNatives::executeTask() return; } auto settings = minecraftInstance->settings(); - bool nativeOpenAL = settings->get("UseNativeOpenAL").toBool(); - bool nativeGLFW = settings->get("UseNativeGLFW").toBool(); auto outputPath = minecraftInstance->getNativePath(); auto javaVersion = minecraftInstance->getJavaVersion(); bool jniHackEnabled = javaVersion.major() >= 8; for (const auto& source : toExtract) { - if (!unzipNatives(source, outputPath, jniHackEnabled, nativeOpenAL, nativeGLFW)) { + if (!unzipNatives(source, outputPath, jniHackEnabled)) { const char* reason = QT_TR_NOOP("Couldn't extract native jar '%1' to destination '%2'"); emit logLine(QString(reason).arg(source, outputPath), MessageLevel::Fatal); emitFailed(tr(reason).arg(source, outputPath)); diff --git a/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp b/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp index 5d1a361d..e5771b7c 100644 --- a/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp +++ b/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp @@ -1005,15 +1005,30 @@ static Meta::Version::Ptr getComponentVersion(const QString& uid, const QString& if (!vlist) return {}; - if (!vlist->isLoaded()) - vlist->load(Net::Mode::Online); + if (!vlist->isLoaded()) { + QEventLoop loadVersionLoop; + auto task = vlist->getLoadTask(); + QObject::connect(task.get(), &Task::finished, &loadVersionLoop, &QEventLoop::quit); + if (!task->isRunning()) + task->start(); + + loadVersionLoop.exec(); + } auto ver = vlist->getVersion(version); if (!ver) return {}; - if (!ver->isLoaded()) + if (!ver->isLoaded()) { + QEventLoop loadVersionLoop; ver->load(Net::Mode::Online); + auto task = ver->getCurrentTask(); + QObject::connect(task.get(), &Task::finished, &loadVersionLoop, &QEventLoop::quit); + if (!task->isRunning()) + task->start(); + + loadVersionLoop.exec(); + } return ver; } diff --git a/launcher/modplatform/flame/FlameAPI.cpp b/launcher/modplatform/flame/FlameAPI.cpp index 73ed1011..74d7db97 100644 --- a/launcher/modplatform/flame/FlameAPI.cpp +++ b/launcher/modplatform/flame/FlameAPI.cpp @@ -204,6 +204,17 @@ Task::Ptr FlameAPI::getFiles(const QStringList& fileIds, std::shared_ptr<QByteAr return netJob; } +Task::Ptr FlameAPI::getFile(const QString& addonId, const QString& fileId, std::shared_ptr<QByteArray> response) const +{ + auto netJob = makeShared<NetJob>(QString("Flame::GetFile"), APPLICATION->network()); + netJob->addNetAction( + Net::ApiDownload::makeByteArray(QUrl(QString("https://api.curseforge.com/v1/mods/%1/files/%2").arg(addonId, fileId)), response)); + + QObject::connect(netJob.get(), &NetJob::failed, [addonId, fileId] { qDebug() << "Flame API file failure" << addonId << fileId; }); + + return netJob; +} + // https://docs.curseforge.com/?python#tocS_ModsSearchSortField static QList<ResourceAPI::SortingMethod> s_sorts = { { 1, "Featured", QObject::tr("Sort by Featured") }, { 2, "Popularity", QObject::tr("Sort by Popularity") }, diff --git a/launcher/modplatform/flame/FlameAPI.h b/launcher/modplatform/flame/FlameAPI.h index af8f3948..a1256e17 100644 --- a/launcher/modplatform/flame/FlameAPI.h +++ b/launcher/modplatform/flame/FlameAPI.h @@ -20,6 +20,7 @@ class FlameAPI : public NetworkResourceAPI { Task::Ptr getProjects(QStringList addonIds, std::shared_ptr<QByteArray> response) const override; Task::Ptr matchFingerprints(const QList<uint>& fingerprints, std::shared_ptr<QByteArray> response); Task::Ptr getFiles(const QStringList& fileIds, std::shared_ptr<QByteArray> response) const; + Task::Ptr getFile(const QString& addonId, const QString& fileId, std::shared_ptr<QByteArray> response) const; [[nodiscard]] auto getSortingMethods() const -> QList<ResourceAPI::SortingMethod> override; diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index a83ff1a2..067108f2 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -85,7 +85,7 @@ #include <launch/LaunchTask.h> #include <minecraft/MinecraftInstance.h> #include <minecraft/auth/AccountList.h> -#include <net/Download.h> +#include <net/ApiDownload.h> #include <net/NetJob.h> #include <news/NewsChecker.h> #include <tools/BaseProfiler.h> @@ -118,11 +118,15 @@ #include "minecraft/mod/ShaderPackFolderModel.h" #include "minecraft/mod/tasks/LocalResourceParse.h" +#include "modplatform/flame/FlameAPI.h" + #include "KonamiCode.h" #include "InstanceCopyTask.h" #include "InstanceImportTask.h" +#include "Json.h" + #include "MMCTime.h" namespace { @@ -929,7 +933,7 @@ void MainWindow::finalizeInstance(InstancePtr inst) } } -void MainWindow::addInstance(QString url) +void MainWindow::addInstance(const QString& url, const QMap<QString, QString>& extra_info) { QString groupName; do { @@ -949,7 +953,7 @@ void MainWindow::addInstance(QString url) groupName = APPLICATION->settings()->get("LastUsedGroupForNewInstance").toString(); } - NewInstanceDialog newInstDlg(groupName, url, this); + NewInstanceDialog newInstDlg(groupName, url, extra_info, this); if (!newInstDlg.exec()) return; @@ -976,18 +980,101 @@ void MainWindow::processURLs(QList<QUrl> urls) if (url.scheme().isEmpty()) url.setScheme("file"); - if (!url.isLocalFile()) { // probably instance/modpack - addInstance(url.toString()); - break; + QMap<QString, QString> extra_info; + QUrl local_url; + if (!url.isLocalFile()) { // download the remote resource and identify + QUrl dl_url; + if (url.scheme() == "curseforge") { + // need to find the download link for the modpack / resource + // format of url curseforge://install?addonId=IDHERE&fileId=IDHERE + QUrlQuery query(url); + + auto addonId = query.allQueryItemValues("addonId")[0]; + auto fileId = query.allQueryItemValues("fileId")[0]; + + extra_info.insert("pack_id", addonId); + extra_info.insert("pack_version_id", fileId); + + auto array = std::make_shared<QByteArray>(); + + auto api = FlameAPI(); + auto job = api.getFile(addonId, fileId, array); + + QString resource_name; + + connect(job.get(), &Task::failed, this, + [this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); }); + connect(job.get(), &Task::succeeded, this, [this, array, addonId, fileId, &dl_url, &resource_name] { + qDebug() << "Returned CFURL Json:\n" << array->toStdString().c_str(); + auto doc = Json::requireDocument(*array); + auto data = Json::ensureObject(Json::ensureObject(doc.object()), "data"); + // No way to find out if it's a mod or a modpack before here + // And also we need to check if it ends with .zip, instead of any better way + auto fileName = Json::ensureString(data, "fileName"); + + // Have to use ensureString then use QUrl to get proper url encoding + dl_url = QUrl(Json::ensureString(data, "downloadUrl", "", "downloadUrl")); + if (!dl_url.isValid()) { + CustomMessageBox::selectable( + this, tr("Error"), + tr("The modpack, mod, or resource %1 is blocked for third-parties! Please download it manually.").arg(fileName), + QMessageBox::Critical) + ->show(); + return; + } + + QFileInfo dl_file(dl_url.fileName()); + resource_name = Json::ensureString(data, "displayName", dl_file.completeBaseName(), "displayName"); + }); + + { // drop stack + ProgressDialog dlUrlDialod(this); + dlUrlDialod.setSkipButton(true, tr("Abort")); + dlUrlDialod.execWithTask(job.get()); + } + + } else { + dl_url = url; + } + + if (!dl_url.isValid()) { + continue; // no valid url to download this resource + } + + const QString path = dl_url.host() + '/' + dl_url.path(); + auto entry = APPLICATION->metacache()->resolveEntry("general", path); + entry->setStale(true); + auto dl_job = unique_qobject_ptr<NetJob>(new NetJob(tr("Modpack download"), APPLICATION->network())); + dl_job->addNetAction(Net::ApiDownload::makeCached(dl_url, entry)); + auto archivePath = entry->getFullPath(); + + bool dl_success = false; + connect(dl_job.get(), &Task::failed, this, + [this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); }); + connect(dl_job.get(), &Task::succeeded, this, [&dl_success] { dl_success = true; }); + + { // drop stack + ProgressDialog dlUrlDialod(this); + dlUrlDialod.setSkipButton(true, tr("Abort")); + dlUrlDialod.execWithTask(dl_job.get()); + } + + if (!dl_success) { + continue; // no local file to identify + } + local_url = QUrl::fromLocalFile(archivePath); + + } else { + local_url = url; } - auto localFileName = QDir::toNativeSeparators(url.toLocalFile()); + auto localFileName = QDir::toNativeSeparators(local_url.toLocalFile()); QFileInfo localFileInfo(localFileName); auto type = ResourceUtils::identify(localFileInfo); if (ResourceUtils::ValidResourceTypes.count(type) == 0) { // probably instance/modpack - addInstance(localFileName); + addInstance(localFileName, extra_info); continue; } diff --git a/launcher/ui/MainWindow.h b/launcher/ui/MainWindow.h index be9c4994..9fd72d25 100644 --- a/launcher/ui/MainWindow.h +++ b/launcher/ui/MainWindow.h @@ -220,7 +220,7 @@ class MainWindow : public QMainWindow { private: void retranslateUi(); - void addInstance(QString url = QString()); + void addInstance(const QString& url = QString(), const QMap<QString, QString>& extra_info = {}); void activateInstance(InstancePtr instance); void setCatBackground(bool enabled); void updateInstanceToolIcon(QString new_icon); diff --git a/launcher/ui/dialogs/NewInstanceDialog.cpp b/launcher/ui/dialogs/NewInstanceDialog.cpp index 1daaa3ce..9613c6b0 100644 --- a/launcher/ui/dialogs/NewInstanceDialog.cpp +++ b/launcher/ui/dialogs/NewInstanceDialog.cpp @@ -62,8 +62,10 @@ #include "ui/pages/modplatform/modrinth/ModrinthPage.h" #include "ui/pages/modplatform/technic/TechnicPage.h" #include "ui/widgets/PageContainer.h" - -NewInstanceDialog::NewInstanceDialog(const QString& initialGroup, const QString& url, QWidget* parent) +NewInstanceDialog::NewInstanceDialog(const QString& initialGroup, + const QString& url, + const QMap<QString, QString>& extra_info, + QWidget* parent) : QDialog(parent), ui(new Ui::NewInstanceDialog) { ui->setupUi(this); @@ -125,6 +127,7 @@ NewInstanceDialog::NewInstanceDialog(const QString& initialGroup, const QString& QUrl actualUrl(url); m_container->selectPage("import"); importPage->setUrl(url); + importPage->setExtraInfo(extra_info); } updateDialogState(); diff --git a/launcher/ui/dialogs/NewInstanceDialog.h b/launcher/ui/dialogs/NewInstanceDialog.h index b348649f..92357956 100644 --- a/launcher/ui/dialogs/NewInstanceDialog.h +++ b/launcher/ui/dialogs/NewInstanceDialog.h @@ -53,7 +53,10 @@ class NewInstanceDialog : public QDialog, public BasePageProvider { Q_OBJECT public: - explicit NewInstanceDialog(const QString& initialGroup, const QString& url = QString(), QWidget* parent = 0); + explicit NewInstanceDialog(const QString& initialGroup, + const QString& url = QString(), + const QMap<QString, QString>& extra_info = {}, + QWidget* parent = 0); ~NewInstanceDialog(); void updateDialogState(); diff --git a/launcher/ui/dialogs/SkinUploadDialog.ui b/launcher/ui/dialogs/SkinUploadDialog.ui index 2c81a7fe..c6df92df 100644 --- a/launcher/ui/dialogs/SkinUploadDialog.ui +++ b/launcher/ui/dialogs/SkinUploadDialog.ui @@ -35,12 +35,6 @@ <verstretch>0</verstretch> </sizepolicy> </property> - <property name="maximumSize"> - <size> - <width>28</width> - <height>16777215</height> - </size> - </property> <property name="text"> <string>Browse</string> </property> diff --git a/launcher/ui/pages/global/MinecraftPage.cpp b/launcher/ui/pages/global/MinecraftPage.cpp index 866a4121..1c774721 100644 --- a/launcher/ui/pages/global/MinecraftPage.cpp +++ b/launcher/ui/pages/global/MinecraftPage.cpp @@ -35,6 +35,7 @@ */ #include "MinecraftPage.h" +#include "BuildConfig.h" #include "ui_MinecraftPage.h" #include <QDir> @@ -44,9 +45,15 @@ #include "Application.h" #include "settings/SettingsObject.h" +#ifdef Q_OS_LINUX +#include "MangoHud.h" +#endif + MinecraftPage::MinecraftPage(QWidget* parent) : QWidget(parent), ui(new Ui::MinecraftPage) { ui->setupUi(this); + connect(ui->useNativeGLFWCheck, &QAbstractButton::toggled, this, &MinecraftPage::onUseNativeGLFWChanged); + connect(ui->useNativeOpenALCheck, &QAbstractButton::toggled, this, &MinecraftPage::onUseNativeOpenALChanged); loadSettings(); updateCheckboxStuff(); } @@ -74,6 +81,16 @@ void MinecraftPage::on_maximizedCheckBox_clicked(bool checked) updateCheckboxStuff(); } +void MinecraftPage::onUseNativeGLFWChanged(bool checked) +{ + ui->lineEditGLFWPath->setEnabled(checked); +} + +void MinecraftPage::onUseNativeOpenALChanged(bool checked) +{ + ui->lineEditOpenALPath->setEnabled(checked); +} + void MinecraftPage::applySettings() { auto s = APPLICATION->settings(); @@ -84,8 +101,10 @@ void MinecraftPage::applySettings() s->set("MinecraftWinHeight", ui->windowHeightSpinBox->value()); // Native library workarounds - s->set("UseNativeOpenAL", ui->useNativeOpenALCheck->isChecked()); s->set("UseNativeGLFW", ui->useNativeGLFWCheck->isChecked()); + s->set("CustomGLFWPath", ui->lineEditGLFWPath->text()); + s->set("UseNativeOpenAL", ui->useNativeOpenALCheck->isChecked()); + s->set("CustomOpenALPath", ui->lineEditOpenALPath->text()); // Peformance related options s->set("EnableFeralGamemode", ui->enableFeralGamemodeCheck->isChecked()); @@ -114,8 +133,20 @@ void MinecraftPage::loadSettings() ui->windowWidthSpinBox->setValue(s->get("MinecraftWinWidth").toInt()); ui->windowHeightSpinBox->setValue(s->get("MinecraftWinHeight").toInt()); - ui->useNativeOpenALCheck->setChecked(s->get("UseNativeOpenAL").toBool()); ui->useNativeGLFWCheck->setChecked(s->get("UseNativeGLFW").toBool()); + ui->lineEditGLFWPath->setText(s->get("CustomGLFWPath").toString()); + ui->lineEditGLFWPath->setPlaceholderText(tr("Path to %1 library file").arg(BuildConfig.GLFW_LIBRARY_NAME)); +#ifdef Q_OS_LINUX + if (!APPLICATION->m_detectedGLFWPath.isEmpty()) + ui->lineEditGLFWPath->setPlaceholderText(tr("Auto detected path: %1").arg(APPLICATION->m_detectedGLFWPath)); +#endif + ui->useNativeOpenALCheck->setChecked(s->get("UseNativeOpenAL").toBool()); + ui->lineEditOpenALPath->setText(s->get("CustomOpenALPath").toString()); + ui->lineEditOpenALPath->setPlaceholderText(tr("Path to %1 library file").arg(BuildConfig.OPENAL_LIBRARY_NAME)); +#ifdef Q_OS_LINUX + if (!APPLICATION->m_detectedOpenALPath.isEmpty()) + ui->lineEditOpenALPath->setPlaceholderText(tr("Auto detected path: %1").arg(APPLICATION->m_detectedOpenALPath)); +#endif ui->enableFeralGamemodeCheck->setChecked(s->get("EnableFeralGamemode").toBool()); ui->enableMangoHud->setChecked(s->get("EnableMangoHud").toBool()); diff --git a/launcher/ui/pages/global/MinecraftPage.h b/launcher/ui/pages/global/MinecraftPage.h index 28c31b5d..5facfbb3 100644 --- a/launcher/ui/pages/global/MinecraftPage.h +++ b/launcher/ui/pages/global/MinecraftPage.h @@ -70,6 +70,9 @@ class MinecraftPage : public QWidget, public BasePage { private slots: void on_maximizedCheckBox_clicked(bool checked); + void onUseNativeGLFWChanged(bool checked); + void onUseNativeOpenALChanged(bool checked); + private: Ui::MinecraftPage* ui; }; diff --git a/launcher/ui/pages/global/MinecraftPage.ui b/launcher/ui/pages/global/MinecraftPage.ui index 393b0f35..98e90e4e 100644 --- a/launcher/ui/pages/global/MinecraftPage.ui +++ b/launcher/ui/pages/global/MinecraftPage.ui @@ -214,21 +214,55 @@ <property name="title"> <string>Native library workarounds</string> </property> - <layout class="QVBoxLayout" name="verticalLayout_11"> - <item> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> <widget class="QCheckBox" name="useNativeGLFWCheck"> <property name="text"> <string>Use system installation of &GLFW</string> </property> </widget> </item> - <item> + <item row="1" column="0"> + <widget class="QLabel" name="labelGLFWPath"> + <property name="text"> + <string>&GLFW library path</string> + </property> + <property name="buddy"> + <cstring>lineEditGLFWPath</cstring> + </property> + </widget> + </item> + <item row="2" column="0"> <widget class="QCheckBox" name="useNativeOpenALCheck"> <property name="text"> <string>Use system installation of &OpenAL</string> </property> </widget> </item> + <item row="3" column="0"> + <widget class="QLabel" name="labelOpenALPath"> + <property name="text"> + <string>&OpenAL library path</string> + </property> + <property name="buddy"> + <cstring>lineEditOpenALPath</cstring> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="lineEditGLFWPath"> + <property name="enabled"> + <bool>false</bool> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QLineEdit" name="lineEditOpenALPath"> + <property name="enabled"> + <bool>false</bool> + </property> + </widget> + </item> </layout> </widget> </item> diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.cpp b/launcher/ui/pages/instance/InstanceSettingsPage.cpp index f7be9168..108f2c27 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.cpp +++ b/launcher/ui/pages/instance/InstanceSettingsPage.cpp @@ -48,6 +48,7 @@ #include "ui/widgets/CustomCommands.h" #include "Application.h" +#include "BuildConfig.h" #include "JavaCommon.h" #include "minecraft/auth/AccountList.h" @@ -66,6 +67,10 @@ InstanceSettingsPage::InstanceSettingsPage(BaseInstance* inst, QWidget* parent) connect(APPLICATION, &Application::globalSettingsClosed, this, &InstanceSettingsPage::loadSettings); connect(ui->instanceAccountSelector, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &InstanceSettingsPage::changeInstanceAccount); + + connect(ui->useNativeGLFWCheck, &QAbstractButton::toggled, this, &InstanceSettingsPage::onUseNativeGLFWChanged); + connect(ui->useNativeOpenALCheck, &QAbstractButton::toggled, this, &InstanceSettingsPage::onUseNativeOpenALChanged); + loadSettings(); updateThresholds(); @@ -198,11 +203,15 @@ void InstanceSettingsPage::applySettings() bool workarounds = ui->nativeWorkaroundsGroupBox->isChecked(); m_settings->set("OverrideNativeWorkarounds", workarounds); if (workarounds) { - m_settings->set("UseNativeOpenAL", ui->useNativeOpenALCheck->isChecked()); m_settings->set("UseNativeGLFW", ui->useNativeGLFWCheck->isChecked()); + m_settings->set("CustomGLFWPath", ui->lineEditGLFWPath->text()); + m_settings->set("UseNativeOpenAL", ui->useNativeOpenALCheck->isChecked()); + m_settings->set("CustomOpenALPath", ui->lineEditOpenALPath->text()); } else { - m_settings->reset("UseNativeOpenAL"); m_settings->reset("UseNativeGLFW"); + m_settings->reset("CustomGLFWPath"); + m_settings->reset("UseNativeOpenAL"); + m_settings->reset("CustomOpenALPath"); } // Performance @@ -312,7 +321,19 @@ void InstanceSettingsPage::loadSettings() // Workarounds ui->nativeWorkaroundsGroupBox->setChecked(m_settings->get("OverrideNativeWorkarounds").toBool()); ui->useNativeGLFWCheck->setChecked(m_settings->get("UseNativeGLFW").toBool()); + ui->lineEditGLFWPath->setText(m_settings->get("CustomGLFWPath").toString()); +#ifdef Q_OS_LINUX + ui->lineEditGLFWPath->setPlaceholderText(APPLICATION->m_detectedGLFWPath); +#else + ui->lineEditGLFWPath->setPlaceholderText(tr("Path to %1 library file").arg(BuildConfig.GLFW_LIBRARY_NAME)); +#endif ui->useNativeOpenALCheck->setChecked(m_settings->get("UseNativeOpenAL").toBool()); + ui->lineEditOpenALPath->setText(m_settings->get("CustomOpenALPath").toString()); +#ifdef Q_OS_LINUX + ui->lineEditOpenALPath->setPlaceholderText(APPLICATION->m_detectedOpenALPath); +#else + ui->lineEditGLFWPath->setPlaceholderText(tr("Path to %1 library file").arg(BuildConfig.OPENAL_LIBRARY_NAME)); +#endif // Performance ui->perfomanceGroupBox->setChecked(m_settings->get("OverridePerformance").toBool()); @@ -408,6 +429,16 @@ void InstanceSettingsPage::on_javaTestBtn_clicked() checker->run(); } +void InstanceSettingsPage::onUseNativeGLFWChanged(bool checked) +{ + ui->lineEditGLFWPath->setEnabled(checked); +} + +void InstanceSettingsPage::onUseNativeOpenALChanged(bool checked) +{ + ui->lineEditOpenALPath->setEnabled(checked); +} + void InstanceSettingsPage::updateAccountsMenu() { ui->instanceAccountSelector->clear(); diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.h b/launcher/ui/pages/instance/InstanceSettingsPage.h index 21ecbaf8..8b78dcb7 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.h +++ b/launcher/ui/pages/instance/InstanceSettingsPage.h @@ -71,6 +71,9 @@ class InstanceSettingsPage : public QWidget, public BasePage { void on_javaBrowseBtn_clicked(); void on_maxMemSpinBox_valueChanged(int i); + void onUseNativeGLFWChanged(bool checked); + void onUseNativeOpenALChanged(bool checked); + void applySettings(); void loadSettings(); diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.ui b/launcher/ui/pages/instance/InstanceSettingsPage.ui index 380d8c88..fcc2a5d0 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.ui +++ b/launcher/ui/pages/instance/InstanceSettingsPage.ui @@ -443,18 +443,52 @@ <property name="checked"> <bool>false</bool> </property> - <layout class="QVBoxLayout" name="verticalLayout_7"> - <item> + <layout class="QGridLayout" name="gridLayout_3"> + <item row="2" column="0"> + <widget class="QCheckBox" name="useNativeOpenALCheck"> + <property name="text"> + <string>Use system installation of OpenAL</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="labelGLFWPath"> + <property name="text"> + <string>&GLFW library path</string> + </property> + <property name="buddy"> + <cstring>lineEditGLFWPath</cstring> + </property> + </widget> + </item> + <item row="0" column="0"> <widget class="QCheckBox" name="useNativeGLFWCheck"> <property name="text"> <string>Use system installation of GLFW</string> </property> </widget> </item> - <item> - <widget class="QCheckBox" name="useNativeOpenALCheck"> + <item row="1" column="1"> + <widget class="QLineEdit" name="lineEditGLFWPath"> + <property name="enabled"> + <bool>false</bool> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="labelOpenALPath"> <property name="text"> - <string>Use system installation of OpenAL</string> + <string>&OpenAL library path</string> + </property> + <property name="buddy"> + <cstring>lineEditOpenALPath</cstring> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QLineEdit" name="lineEditOpenALPath"> + <property name="enabled"> + <bool>false</bool> </property> </widget> </item> diff --git a/launcher/ui/pages/modplatform/ImportPage.cpp b/launcher/ui/pages/modplatform/ImportPage.cpp index ce2777b3..3e3c36b7 100644 --- a/launcher/ui/pages/modplatform/ImportPage.cpp +++ b/launcher/ui/pages/modplatform/ImportPage.cpp @@ -35,13 +35,21 @@ */ #include "ImportPage.h" + +#include "ui/dialogs/ProgressDialog.h" #include "ui_ImportPage.h" #include <QFileDialog> #include <QValidator> +#include <utility> +#include "ui/dialogs/CustomMessageBox.h" #include "ui/dialogs/NewInstanceDialog.h" +#include "modplatform/flame/FlameAPI.h" + +#include "Json.h" + #include "InstanceImportTask.h" class UrlValidator : public QValidator { @@ -106,10 +114,61 @@ void ImportPage::updateState() bool isMRPack = fi.suffix() == "mrpack"; if (fi.exists() && (isZip || isMRPack)) { - QFileInfo file_info(url.fileName()); - dialog->setSuggestedPack(file_info.completeBaseName(), new InstanceImportTask(url, this)); + auto extra_info = QMap(m_extra_info); + qDebug() << "Pack Extra Info" << extra_info << m_extra_info; + dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url, this, std::move(extra_info))); dialog->setSuggestedIcon("default"); } + } else if (url.scheme() == "curseforge") { + // need to find the download link for the modpack + // format of url curseforge://install?addonId=IDHERE&fileId=IDHERE + QUrlQuery query(url); + auto addonId = query.allQueryItemValues("addonId")[0]; + auto fileId = query.allQueryItemValues("fileId")[0]; + auto array = std::make_shared<QByteArray>(); + + auto api = FlameAPI(); + auto job = api.getFile(addonId, fileId, array); + + connect(job.get(), &NetJob::failed, this, + [this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); }); + connect(job.get(), &NetJob::succeeded, this, [this, array, addonId, fileId] { + qDebug() << "Returned CFURL Json:\n" << array->toStdString().c_str(); + auto doc = Json::requireDocument(*array); + auto data = Json::ensureObject(Json::ensureObject(doc.object()), "data"); + // No way to find out if it's a mod or a modpack before here + // And also we need to check if it ends with .zip, instead of any better way + auto fileName = Json::ensureString(data, "fileName"); + if (fileName.endsWith(".zip")) { + // Have to use ensureString then use QUrl to get proper url encoding + auto dl_url = QUrl(Json::ensureString(data, "downloadUrl", "", "downloadUrl")); + if (!dl_url.isValid()) { + CustomMessageBox::selectable( + this, tr("Error"), + tr("The modpack %1 is blocked for third-parties! Please download it manually.").arg(fileName), + QMessageBox::Critical) + ->show(); + return; + } + + QFileInfo dl_file(dl_url.fileName()); + QString pack_name = Json::ensureString(data, "displayName", dl_file.completeBaseName(), "displayName"); + + QMap<QString, QString> extra_info; + extra_info.insert("pack_id", addonId); + extra_info.insert("pack_version_id", fileId); + + dialog->setSuggestedPack(pack_name, new InstanceImportTask(dl_url, this, std::move(extra_info))); + dialog->setSuggestedIcon("default"); + + } else { + CustomMessageBox::selectable(this, tr("Error"), tr("This url isn't a valid modpack !"), QMessageBox::Critical)->show(); + } + }); + ProgressDialog dlUrlDialod(this); + dlUrlDialod.setSkipButton(true, tr("Abort")); + dlUrlDialod.execWithTask(job.get()); + return; } else { if (input.endsWith("?client=y")) { input.chop(9); @@ -118,7 +177,8 @@ void ImportPage::updateState() } // hook, line and sinker. QFileInfo fi(url.fileName()); - dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url, this)); + auto extra_info = QMap(m_extra_info); + dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url, this, std::move(extra_info))); dialog->setSuggestedIcon("default"); } } else { @@ -132,6 +192,12 @@ void ImportPage::setUrl(const QString& url) updateState(); } +void ImportPage::setExtraInfo(const QMap<QString, QString>& extra_info) +{ + m_extra_info = extra_info; + updateState(); +} + void ImportPage::on_modpackBtn_clicked() { auto filter = QMimeDatabase().mimeTypeForName("application/zip").filterString(); diff --git a/launcher/ui/pages/modplatform/ImportPage.h b/launcher/ui/pages/modplatform/ImportPage.h index d846d566..70d7736e 100644 --- a/launcher/ui/pages/modplatform/ImportPage.h +++ b/launcher/ui/pages/modplatform/ImportPage.h @@ -62,7 +62,7 @@ class ImportPage : public QWidget, public BasePage { void setUrl(const QString& url); void openedImpl() override; - + void setExtraInfo(const QMap<QString, QString>& extra_info); private slots: void on_modpackBtn_clicked(); void updateState(); @@ -73,4 +73,5 @@ class ImportPage : public QWidget, public BasePage { private: Ui::ImportPage* ui = nullptr; NewInstanceDialog* dialog = nullptr; + QMap<QString, QString> m_extra_info = {}; }; diff --git a/launcher/ui/pages/modplatform/ImportPage.ui b/launcher/ui/pages/modplatform/ImportPage.ui index 3583cf90..9a9736b8 100644 --- a/launcher/ui/pages/modplatform/ImportPage.ui +++ b/launcher/ui/pages/modplatform/ImportPage.ui @@ -40,7 +40,7 @@ <item> <widget class="QLabel" name="label_5"> <property name="text"> - <string>- CurseForge modpacks (ZIP)</string> + <string>- CurseForge modpacks (ZIP / curseforge:// URL)</string> </property> <property name="alignment"> <set>Qt::AlignCenter</set> |