From 141e0a02a0a0c4bbc4cc2e900560db5048366104 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Wed, 4 Feb 2015 21:10:10 +0100 Subject: SCRATCH move things to the right places --- CMakeLists.txt | 44 +- MultiMC.cpp | 2 +- gui/MainWindow.cpp | 11 +- gui/dialogs/ModEditDialogCommon.h | 2 +- gui/dialogs/NotificationDialog.h | 2 +- gui/pages/InstanceSettingsPage.h | 2 +- gui/pages/LegacyJarModPage.cpp | 4 +- gui/pages/LegacyUpgradePage.cpp | 2 +- gui/pages/LegacyUpgradePage.h | 4 +- gui/pages/ModFolderPage.cpp | 4 +- gui/pages/ModFolderPage.h | 2 +- gui/pages/ScreenshotsPage.h | 1 - gui/pages/VersionPage.cpp | 3 +- gui/pages/VersionPage.h | 2 +- gui/widgets/MCModInfoFrame.h | 2 +- logic/BaseInstaller.cpp | 2 +- logic/BaseInstance.h | 7 +- logic/InstanceList.cpp | 12 +- logic/JarUtils.cpp | 158 ------- logic/JarUtils.h | 18 - logic/LegacyInstance.cpp | 346 ---------------- logic/LegacyInstance.h | 127 ------ logic/LegacyUpdate.cpp | 468 --------------------- logic/LegacyUpdate.h | 72 ---- logic/LwjglVersionList.cpp | 189 --------- logic/LwjglVersionList.h | 154 ------- logic/Mod.cpp | 377 ----------------- logic/Mod.h | 130 ------ logic/ModList.cpp | 611 ---------------------------- logic/ModList.h | 158 ------- logic/OneSixInstance.cpp | 472 --------------------- logic/OneSixInstance.h | 109 ----- logic/OneSixUpdate.cpp | 445 -------------------- logic/OneSixUpdate.h | 68 ---- logic/SkinUtils.cpp | 47 --- logic/SkinUtils.h | 23 -- logic/assets/AssetsUtils.cpp | 217 ---------- logic/assets/AssetsUtils.h | 39 -- logic/forge/ForgeInstaller.cpp | 2 +- logic/forge/LegacyForge.h | 2 +- logic/ftb/LegacyFTBInstance.h | 2 +- logic/ftb/OneSixFTBInstance.h | 2 +- logic/liteloader/LiteLoaderInstaller.cpp | 2 +- logic/minecraft/AssetsUtils.cpp | 217 ++++++++++ logic/minecraft/AssetsUtils.h | 39 ++ logic/minecraft/JarUtils.cpp | 158 +++++++ logic/minecraft/JarUtils.h | 18 + logic/minecraft/LegacyInstance.cpp | 346 ++++++++++++++++ logic/minecraft/LegacyInstance.h | 127 ++++++ logic/minecraft/LegacyUpdate.cpp | 467 +++++++++++++++++++++ logic/minecraft/LegacyUpdate.h | 72 ++++ logic/minecraft/LwjglVersionList.cpp | 189 +++++++++ logic/minecraft/LwjglVersionList.h | 154 +++++++ logic/minecraft/MinecraftInstance.h | 3 + logic/minecraft/MinecraftProfile.cpp | 1 - logic/minecraft/Mod.cpp | 377 +++++++++++++++++ logic/minecraft/Mod.h | 130 ++++++ logic/minecraft/ModList.cpp | 610 +++++++++++++++++++++++++++ logic/minecraft/ModList.h | 158 +++++++ logic/minecraft/OneSixInstance.cpp | 472 +++++++++++++++++++++ logic/minecraft/OneSixInstance.h | 109 +++++ logic/minecraft/OneSixProfileStrategy.cpp | 2 +- logic/minecraft/OneSixUpdate.cpp | 445 ++++++++++++++++++++ logic/minecraft/OneSixUpdate.h | 68 ++++ logic/minecraft/SkinUtils.cpp | 47 +++ logic/minecraft/SkinUtils.h | 23 ++ logic/minecraft/VersionBuilder.cpp | 2 +- logic/notifications/NotificationChecker.cpp | 121 ++++++ logic/notifications/NotificationChecker.h | 54 +++ logic/updater/NotificationChecker.cpp | 121 ------ logic/updater/NotificationChecker.h | 54 --- 71 files changed, 4461 insertions(+), 4469 deletions(-) delete mode 100644 logic/JarUtils.cpp delete mode 100644 logic/JarUtils.h delete mode 100644 logic/LegacyInstance.cpp delete mode 100644 logic/LegacyInstance.h delete mode 100644 logic/LegacyUpdate.cpp delete mode 100644 logic/LegacyUpdate.h delete mode 100644 logic/LwjglVersionList.cpp delete mode 100644 logic/LwjglVersionList.h delete mode 100644 logic/Mod.cpp delete mode 100644 logic/Mod.h delete mode 100644 logic/ModList.cpp delete mode 100644 logic/ModList.h delete mode 100644 logic/OneSixInstance.cpp delete mode 100644 logic/OneSixInstance.h delete mode 100644 logic/OneSixUpdate.cpp delete mode 100644 logic/OneSixUpdate.h delete mode 100644 logic/SkinUtils.cpp delete mode 100644 logic/SkinUtils.h delete mode 100644 logic/assets/AssetsUtils.cpp delete mode 100644 logic/assets/AssetsUtils.h create mode 100644 logic/minecraft/AssetsUtils.cpp create mode 100644 logic/minecraft/AssetsUtils.h create mode 100644 logic/minecraft/JarUtils.cpp create mode 100644 logic/minecraft/JarUtils.h create mode 100644 logic/minecraft/LegacyInstance.cpp create mode 100644 logic/minecraft/LegacyInstance.h create mode 100644 logic/minecraft/LegacyUpdate.cpp create mode 100644 logic/minecraft/LegacyUpdate.h create mode 100644 logic/minecraft/LwjglVersionList.cpp create mode 100644 logic/minecraft/LwjglVersionList.h create mode 100644 logic/minecraft/Mod.cpp create mode 100644 logic/minecraft/Mod.h create mode 100644 logic/minecraft/ModList.cpp create mode 100644 logic/minecraft/ModList.h create mode 100644 logic/minecraft/OneSixInstance.cpp create mode 100644 logic/minecraft/OneSixInstance.h create mode 100644 logic/minecraft/OneSixUpdate.cpp create mode 100644 logic/minecraft/OneSixUpdate.h create mode 100644 logic/minecraft/SkinUtils.cpp create mode 100644 logic/minecraft/SkinUtils.h create mode 100644 logic/notifications/NotificationChecker.cpp create mode 100644 logic/notifications/NotificationChecker.h delete mode 100644 logic/updater/NotificationChecker.cpp delete mode 100644 logic/updater/NotificationChecker.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3751da3c..d35753cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -390,10 +390,10 @@ SET(MULTIMC_SOURCES logic/BaseProcess.cpp logic/BaseInstance.h logic/BaseInstance.cpp - logic/Mod.h - logic/Mod.cpp - logic/ModList.h - logic/ModList.cpp + logic/minecraft/Mod.h + logic/minecraft/Mod.cpp + logic/minecraft/ModList.h + logic/minecraft/ModList.cpp # sets and maps for deciding based on versions logic/minecraft/VersionFilterData.h @@ -404,8 +404,8 @@ SET(MULTIMC_SOURCES gui/NagUtils.cpp # Player skin utilities - logic/SkinUtils.h - logic/SkinUtils.cpp + logic/minecraft/SkinUtils.h + logic/minecraft/SkinUtils.cpp # misc model filter @@ -459,8 +459,8 @@ SET(MULTIMC_SOURCES logic/updater/UpdateChecker.cpp logic/updater/DownloadUpdateTask.h logic/updater/DownloadUpdateTask.cpp - logic/updater/NotificationChecker.h - logic/updater/NotificationChecker.cpp + logic/notifications/NotificationChecker.h + logic/notifications/NotificationChecker.cpp # News System logic/news/NewsChecker.h @@ -473,23 +473,23 @@ SET(MULTIMC_SOURCES logic/status/StatusChecker.cpp # legacy instances - logic/LegacyInstance.h - logic/LegacyInstance.cpp - logic/LegacyUpdate.h - logic/LegacyUpdate.cpp + logic/minecraft/LegacyInstance.h + logic/minecraft/LegacyInstance.cpp + logic/minecraft/LegacyUpdate.h + logic/minecraft/LegacyUpdate.cpp # OneSix instances - logic/OneSixUpdate.h - logic/OneSixUpdate.cpp - logic/OneSixInstance.h - logic/OneSixInstance.cpp + logic/minecraft/OneSixUpdate.h + logic/minecraft/OneSixUpdate.cpp + logic/minecraft/OneSixInstance.h + logic/minecraft/OneSixInstance.cpp # a smart pointer wrapper intended for safer use with Qt signal/slot mechanisms logic/QObjectPtr.h # Common utils for instances - logic/JarUtils.h - logic/JarUtils.cpp + logic/minecraft/JarUtils.h + logic/minecraft/JarUtils.cpp # Minecraft support logic/minecraft/GradleSpecifier.h @@ -541,8 +541,8 @@ SET(MULTIMC_SOURCES logic/InstanceList.h logic/InstanceList.cpp - logic/LwjglVersionList.h - logic/LwjglVersionList.cpp + logic/minecraft/LwjglVersionList.h + logic/minecraft/LwjglVersionList.cpp # FTB logic/ftb/OneSixFTBInstance.h @@ -599,8 +599,8 @@ SET(MULTIMC_SOURCES logic/java/JavaCheckerJob.cpp # Assets - logic/assets/AssetsUtils.h - logic/assets/AssetsUtils.cpp + logic/minecraft/AssetsUtils.h + logic/minecraft/AssetsUtils.cpp # Tools logic/tools/BaseExternalTool.h diff --git a/MultiMC.cpp b/MultiMC.cpp index 8efc8073..8375dc1b 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -16,7 +16,7 @@ #include "logic/InstanceList.h" #include "logic/auth/MojangAccountList.h" #include "logic/icons/IconList.h" -#include "logic/LwjglVersionList.h" +#include "logic/minecraft/LwjglVersionList.h" #include "logic/minecraft/MinecraftVersionList.h" #include "logic/liteloader/LiteLoaderVersionList.h" diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 2025a097..7ad93f07 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -362,7 +362,7 @@ namespace Ui { #include "logic/InstanceList.h" #include "logic/minecraft/MinecraftVersionList.h" -#include "logic/LwjglVersionList.h" +#include "logic/minecraft/LwjglVersionList.h" #include "logic/icons/IconList.h" #include "logic/java/JavaVersionList.h" @@ -378,18 +378,15 @@ namespace Ui { #include "logic/Env.h" #include "logic/BaseInstance.h" -#include "logic/OneSixInstance.h" #include "logic/BaseProcess.h" -#include "logic/OneSixUpdate.h" #include "logic/java/JavaUtils.h" #include "gui/NagUtils.h" -#include "logic/SkinUtils.h" +#include "logic/minecraft/SkinUtils.h" -#include "logic/LegacyInstance.h" +//#include "logic/minecraft/LegacyInstance.h" -#include "logic/assets/AssetsUtils.h" #include -#include +#include #include #include "logic/net/CacheDownload.h" diff --git a/gui/dialogs/ModEditDialogCommon.h b/gui/dialogs/ModEditDialogCommon.h index 3ccfbf6b..227e638c 100644 --- a/gui/dialogs/ModEditDialogCommon.h +++ b/gui/dialogs/ModEditDialogCommon.h @@ -2,7 +2,7 @@ #include #include #include -#include +#include bool lastfirst(QModelIndexList &list, int &first, int &last); diff --git a/gui/dialogs/NotificationDialog.h b/gui/dialogs/NotificationDialog.h index b7980a98..4717abd8 100644 --- a/gui/dialogs/NotificationDialog.h +++ b/gui/dialogs/NotificationDialog.h @@ -3,7 +3,7 @@ #include -#include "logic/updater/NotificationChecker.h" +#include "logic/notifications/NotificationChecker.h" namespace Ui { class NotificationDialog; diff --git a/gui/pages/InstanceSettingsPage.h b/gui/pages/InstanceSettingsPage.h index b43ce610..8835d02e 100644 --- a/gui/pages/InstanceSettingsPage.h +++ b/gui/pages/InstanceSettingsPage.h @@ -17,9 +17,9 @@ #include -#include "logic/OneSixInstance.h" #include "logic/net/NetJob.h" #include "logic/java/JavaChecker.h" +#include "logic/BaseInstance.h" #include "BasePage.h" #include "MultiMC.h" diff --git a/gui/pages/LegacyJarModPage.cpp b/gui/pages/LegacyJarModPage.cpp index 219e92ef..55a8300f 100644 --- a/gui/pages/LegacyJarModPage.cpp +++ b/gui/pages/LegacyJarModPage.cpp @@ -25,8 +25,8 @@ #include "gui/dialogs/VersionSelectDialog.h" #include "gui/dialogs/ProgressDialog.h" #include "gui/dialogs/ModEditDialogCommon.h" -#include "logic/ModList.h" -#include "logic/LegacyInstance.h" +#include "logic/minecraft/ModList.h" +#include "logic/minecraft/LegacyInstance.h" #include "logic/forge/ForgeVersion.h" #include "logic/forge/ForgeVersionList.h" #include "logic/Env.h" diff --git a/gui/pages/LegacyUpgradePage.cpp b/gui/pages/LegacyUpgradePage.cpp index 79478efb..bb94d82a 100644 --- a/gui/pages/LegacyUpgradePage.cpp +++ b/gui/pages/LegacyUpgradePage.cpp @@ -1,7 +1,7 @@ #include "LegacyUpgradePage.h" #include "ui_LegacyUpgradePage.h" -#include "logic/LegacyInstance.h" +#include "logic/minecraft/LegacyInstance.h" LegacyUpgradePage::LegacyUpgradePage(LegacyInstance *inst, QWidget *parent) : QWidget(parent), ui(new Ui::LegacyUpgradePage), m_inst(inst) diff --git a/gui/pages/LegacyUpgradePage.h b/gui/pages/LegacyUpgradePage.h index 25782aae..b604da19 100644 --- a/gui/pages/LegacyUpgradePage.h +++ b/gui/pages/LegacyUpgradePage.h @@ -17,9 +17,9 @@ #include -#include "logic/OneSixInstance.h" +#include "logic/minecraft/OneSixInstance.h" #include "logic/net/NetJob.h" -#include "BasePage.h" +#include "gui/pages/BasePage.h" #include namespace Ui diff --git a/gui/pages/ModFolderPage.cpp b/gui/pages/ModFolderPage.cpp index 938ec421..167ba471 100644 --- a/gui/pages/ModFolderPage.cpp +++ b/gui/pages/ModFolderPage.cpp @@ -28,8 +28,8 @@ #include "MultiMC.h" #include "gui/dialogs/CustomMessageBox.h" #include "gui/dialogs/ModEditDialogCommon.h" -#include "logic/ModList.h" -#include "logic/Mod.h" +#include "logic/minecraft/ModList.h" +#include "logic/minecraft/Mod.h" #include "logic/minecraft/VersionFilterData.h" ModFolderPage::ModFolderPage(BaseInstance *inst, std::shared_ptr mods, QString id, diff --git a/gui/pages/ModFolderPage.h b/gui/pages/ModFolderPage.h index d2452ff6..bd5156d4 100644 --- a/gui/pages/ModFolderPage.h +++ b/gui/pages/ModFolderPage.h @@ -17,7 +17,7 @@ #include -#include "logic/OneSixInstance.h" +#include "logic/minecraft/OneSixInstance.h" #include "logic/net/NetJob.h" #include "BasePage.h" #include diff --git a/gui/pages/ScreenshotsPage.h b/gui/pages/ScreenshotsPage.h index 08ffbf26..f5700ba8 100644 --- a/gui/pages/ScreenshotsPage.h +++ b/gui/pages/ScreenshotsPage.h @@ -17,7 +17,6 @@ #include -#include "logic/OneSixInstance.h" #include "BasePage.h" #include diff --git a/gui/pages/VersionPage.cpp b/gui/pages/VersionPage.cpp index 7df0b5c1..712b496f 100644 --- a/gui/pages/VersionPage.cpp +++ b/gui/pages/VersionPage.cpp @@ -37,7 +37,6 @@ #include #include -#include "logic/ModList.h" #include "logic/minecraft/MinecraftProfile.h" #include "logic/forge/ForgeVersionList.h" #include "logic/forge/ForgeInstaller.h" @@ -45,7 +44,7 @@ #include "logic/liteloader/LiteLoaderInstaller.h" #include "logic/minecraft/VersionBuilder.h" #include "logic/auth/MojangAccountList.h" -#include "logic/Mod.h" +#include "logic/minecraft/Mod.h" #include "logic/icons/IconList.h" diff --git a/gui/pages/VersionPage.h b/gui/pages/VersionPage.h index 0354c886..3b90d0c6 100644 --- a/gui/pages/VersionPage.h +++ b/gui/pages/VersionPage.h @@ -17,7 +17,7 @@ #include -#include "logic/OneSixInstance.h" +#include "logic/minecraft/OneSixInstance.h" #include "logic/net/NetJob.h" #include "BasePage.h" diff --git a/gui/widgets/MCModInfoFrame.h b/gui/widgets/MCModInfoFrame.h index 3e45b8ce..9e63d29a 100644 --- a/gui/widgets/MCModInfoFrame.h +++ b/gui/widgets/MCModInfoFrame.h @@ -16,7 +16,7 @@ #pragma once #include -#include "logic/Mod.h" +#include "logic/minecraft/Mod.h" namespace Ui { diff --git a/logic/BaseInstaller.cpp b/logic/BaseInstaller.cpp index 0416c52b..b2cdefbc 100644 --- a/logic/BaseInstaller.cpp +++ b/logic/BaseInstaller.cpp @@ -16,7 +16,7 @@ #include #include "logic/BaseInstaller.h" -#include "logic/OneSixInstance.h" +#include "logic/minecraft/OneSixInstance.h" BaseInstaller::BaseInstaller() { diff --git a/logic/BaseInstance.h b/logic/BaseInstance.h index cd1dcdf0..3a4fa4a6 100644 --- a/logic/BaseInstance.h +++ b/logic/BaseInstance.h @@ -24,18 +24,13 @@ #include "logic/settings/INIFile.h" #include "logic/BaseVersionList.h" #include "logic/auth/MojangAccount.h" -#include "Mod.h" -class ModList; -class QDialog; class QDir; class Task; class BaseProcess; -class OneSixUpdate; -class BaseInstancePrivate; +class BaseInstance; // pointer for lazy people -class BaseInstance; typedef std::shared_ptr InstancePtr; /*! diff --git a/logic/InstanceList.cpp b/logic/InstanceList.cpp index ef6594d9..10faf1ca 100644 --- a/logic/InstanceList.cpp +++ b/logic/InstanceList.cpp @@ -25,16 +25,18 @@ #include #include #include +#include #include "logic/InstanceList.h" #include "logic/icons/IconList.h" -#include "logic/minecraft/MinecraftVersionList.h" #include "logic/BaseInstance.h" -#include "logic/ftb/FTBPlugin.h" + +//FIXME: this really doesn't belong *here* +#include "logic/minecraft/OneSixInstance.h" +#include "logic/minecraft/LegacyInstance.h" +#include "minecraft/MinecraftVersion.h" #include "settings/INISettingsObject.h" -#include "OneSixInstance.h" -#include "LegacyInstance.h" -#include +#include "logic/ftb/FTBPlugin.h" const static int GROUP_FILE_FORMAT_VERSION = 1; diff --git a/logic/JarUtils.cpp b/logic/JarUtils.cpp deleted file mode 100644 index e73af53c..00000000 --- a/logic/JarUtils.cpp +++ /dev/null @@ -1,158 +0,0 @@ -#include "JarUtils.h" -#include -#include -#include -#include - -namespace JarUtils { - -bool mergeZipFiles(QuaZip *into, QFileInfo from, QSet &contained, - std::function filter) -{ - QuaZip modZip(from.filePath()); - modZip.open(QuaZip::mdUnzip); - - QuaZipFile fileInsideMod(&modZip); - QuaZipFile zipOutFile(into); - for (bool more = modZip.goToFirstFile(); more; more = modZip.goToNextFile()) - { - QString filename = modZip.getCurrentFileName(); - if (!filter(filename)) - { - qDebug() << "Skipping file " << filename << " from " - << from.fileName() << " - filtered"; - continue; - } - if (contained.contains(filename)) - { - qDebug() << "Skipping already contained file " << filename << " from " - << from.fileName(); - continue; - } - contained.insert(filename); - - if (!fileInsideMod.open(QIODevice::ReadOnly)) - { - qCritical() << "Failed to open " << filename << " from " << from.fileName(); - return false; - } - - QuaZipNewInfo info_out(fileInsideMod.getActualFileName()); - - if (!zipOutFile.open(QIODevice::WriteOnly, info_out)) - { - qCritical() << "Failed to open " << filename << " in the jar"; - fileInsideMod.close(); - return false; - } - if (!JlCompress::copyData(fileInsideMod, zipOutFile)) - { - zipOutFile.close(); - fileInsideMod.close(); - qCritical() << "Failed to copy data of " << filename << " into the jar"; - return false; - } - zipOutFile.close(); - fileInsideMod.close(); - } - return true; -} - -bool createModdedJar(QString sourceJarPath, QString targetJarPath, const QList& mods) -{ - QuaZip zipOut(targetJarPath); - if (!zipOut.open(QuaZip::mdCreate)) - { - QFile::remove(targetJarPath); - qCritical() << "Failed to open the minecraft.jar for modding"; - return false; - } - // Files already added to the jar. - // These files will be skipped. - QSet addedFiles; - - // Modify the jar - QListIterator i(mods); - i.toBack(); - while (i.hasPrevious()) - { - const Mod &mod = i.previous(); - // do not merge disabled mods. - if (!mod.enabled()) - continue; - if (mod.type() == Mod::MOD_ZIPFILE) - { - if (!mergeZipFiles(&zipOut, mod.filename(), addedFiles, noFilter)) - { - zipOut.close(); - QFile::remove(targetJarPath); - qCritical() << "Failed to add" << mod.filename().fileName() << "to the jar."; - return false; - } - } - else if (mod.type() == Mod::MOD_SINGLEFILE) - { - auto filename = mod.filename(); - if (!JlCompress::compressFile(&zipOut, filename.absoluteFilePath(), - filename.fileName())) - { - zipOut.close(); - QFile::remove(targetJarPath); - qCritical() << "Failed to add" << mod.filename().fileName() << "to the jar."; - return false; - } - addedFiles.insert(filename.fileName()); - } - else if (mod.type() == Mod::MOD_FOLDER) - { - auto filename = mod.filename(); - QString what_to_zip = filename.absoluteFilePath(); - QDir dir(what_to_zip); - dir.cdUp(); - QString parent_dir = dir.absolutePath(); - if (!JlCompress::compressSubDir(&zipOut, what_to_zip, parent_dir, true, addedFiles)) - { - zipOut.close(); - QFile::remove(targetJarPath); - qCritical() << "Failed to add" << mod.filename().fileName() << "to the jar."; - return false; - } - qDebug() << "Adding folder " << filename.fileName() << " from " - << filename.absoluteFilePath(); - } - } - - if (!mergeZipFiles(&zipOut, QFileInfo(sourceJarPath), addedFiles, metaInfFilter)) - { - zipOut.close(); - QFile::remove(targetJarPath); - qCritical() << "Failed to insert minecraft.jar contents."; - return false; - } - - // Recompress the jar - zipOut.close(); - if (zipOut.getZipError() != 0) - { - QFile::remove(targetJarPath); - qCritical() << "Failed to finalize minecraft.jar!"; - return false; - } - return true; -} - -bool noFilter(QString) -{ - return true; -} - -bool metaInfFilter(QString key) -{ - if(key.contains("META-INF")) - { - return false; - } - return true; -} - -} diff --git a/logic/JarUtils.h b/logic/JarUtils.h deleted file mode 100644 index 2e8bd2a7..00000000 --- a/logic/JarUtils.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once -#include -#include -#include -#include "Mod.h" -#include - -class QuaZip; -namespace JarUtils -{ - bool noFilter(QString); - bool metaInfFilter(QString key); - - bool mergeZipFiles(QuaZip *into, QFileInfo from, QSet &contained, - std::function filter); - - bool createModdedJar(QString sourceJarPath, QString targetJarPath, const QList& mods); -} diff --git a/logic/LegacyInstance.cpp b/logic/LegacyInstance.cpp deleted file mode 100644 index 1d4d6150..00000000 --- a/logic/LegacyInstance.cpp +++ /dev/null @@ -1,346 +0,0 @@ -/* Copyright 2013-2015 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 -#include -#include -#include -#include -#include - -#include "LegacyInstance.h" - -#include "logic/LegacyUpdate.h" -#include "logic/icons/IconList.h" -#include "logic/minecraft/MinecraftProcess.h" -#include "gui/pages/LegacyUpgradePage.h" -#include "gui/pages/ModFolderPage.h" -#include "gui/pages/LegacyJarModPage.h" -#include -#include -#include -#include - -LegacyInstance::LegacyInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir) - : MinecraftInstance(globalSettings, settings, rootDir) -{ - m_lwjglFolderSetting = globalSettings->getSetting("LWJGLDir"); - settings->registerSetting("NeedsRebuild", true); - settings->registerSetting("ShouldUpdate", false); - settings->registerSetting("JarVersion", "Unknown"); - settings->registerSetting("LwjglVersion", "2.9.0"); - settings->registerSetting("IntendedJarVersion", ""); - /* - * custom base jar has no default. it is determined in code... see the accessor methods for - *it - * - * for instances that DO NOT have the CustomBaseJar setting (legacy instances), - * [.]minecraft/bin/mcbackup.jar is the default base jar - */ - settings->registerSetting("UseCustomBaseJar", true); - settings->registerSetting("CustomBaseJar", ""); -} - -QList LegacyInstance::getPages() -{ - QList values; - // FIXME: actually implement the legacy instance upgrade, then enable this. - //values.append(new LegacyUpgradePage(this)); - values.append(new LegacyJarModPage(this)); - values.append(new ModFolderPage(this, loaderModList(), "mods", "loadermods", tr("Loader mods"), - "Loader-mods")); - values.append(new ModFolderPage(this, coreModList(), "coremods", "coremods", tr("Core mods"), - "Loader-mods")); - values.append(new TexturePackPage(this)); - values.append(new NotesPage(this)); - values.append(new ScreenshotsPage(PathCombine(minecraftRoot(), "screenshots"))); - values.append(new InstanceSettingsPage(this)); - return values; -} - -QString LegacyInstance::dialogTitle() -{ - return tr("Edit Instance (%1)").arg(name()); -} - -QString LegacyInstance::baseJar() const -{ - bool customJar = m_settings->get("UseCustomBaseJar").toBool(); - if (customJar) - { - return customBaseJar(); - } - else - return defaultBaseJar(); -} - -QString LegacyInstance::customBaseJar() const -{ - QString value = m_settings->get("CustomBaseJar").toString(); - if (value.isNull() || value.isEmpty()) - { - return defaultCustomBaseJar(); - } - return value; -} - -void LegacyInstance::setCustomBaseJar(QString val) -{ - if (val.isNull() || val.isEmpty() || val == defaultCustomBaseJar()) - m_settings->reset("CustomBaseJar"); - else - m_settings->set("CustomBaseJar", val); -} - -void LegacyInstance::setShouldUseCustomBaseJar(bool val) -{ - m_settings->set("UseCustomBaseJar", val); -} - -bool LegacyInstance::shouldUseCustomBaseJar() const -{ - return m_settings->get("UseCustomBaseJar").toBool(); -} - - -std::shared_ptr LegacyInstance::doUpdate() -{ - // make sure the jar mods list is initialized by asking for it. - auto list = jarModList(); - // create an update task - return std::shared_ptr(new LegacyUpdate(this, this)); -} - -BaseProcess *LegacyInstance::prepareForLaunch(AuthSessionPtr account) -{ - QString launchScript; - QIcon icon = ENV.icons()->getIcon(iconKey()); - auto pixmap = icon.pixmap(128, 128); - pixmap.save(PathCombine(minecraftRoot(), "icon.png"), "PNG"); - - // create the launch script - { - // window size - QString windowParams; - if (settings().get("LaunchMaximized").toBool()) - windowParams = "max"; - else - windowParams = QString("%1x%2") - .arg(settings().get("MinecraftWinWidth").toInt()) - .arg(settings().get("MinecraftWinHeight").toInt()); - - QString lwjgl = QDir(m_lwjglFolderSetting->get().toString() + "/" + lwjglVersion()) - .absolutePath(); - launchScript += "userName " + account->player_name + "\n"; - launchScript += "sessionId " + account->session + "\n"; - launchScript += "windowTitle " + windowTitle() + "\n"; - launchScript += "windowParams " + windowParams + "\n"; - launchScript += "lwjgl " + lwjgl + "\n"; - launchScript += "launcher legacy\n"; - } - auto process = MinecraftProcess::create(std::dynamic_pointer_cast(getSharedPtr())); - process->setLaunchScript(launchScript); - process->setWorkdir(minecraftRoot()); - process->setLogin(account); - return process; -} - -void LegacyInstance::cleanupAfterRun() -{ - // FIXME: delete the launcher and icons and whatnot. -} - -std::shared_ptr LegacyInstance::coreModList() const -{ - if (!core_mod_list) - { - core_mod_list.reset(new ModList(coreModsDir())); - } - core_mod_list->update(); - return core_mod_list; -} - -std::shared_ptr LegacyInstance::jarModList() const -{ - if (!jar_mod_list) - { - auto list = new ModList(jarModsDir(), modListFile()); - connect(list, SIGNAL(changed()), SLOT(jarModsChanged())); - jar_mod_list.reset(list); - } - jar_mod_list->update(); - return jar_mod_list; -} - -QList LegacyInstance::getJarMods() const -{ - return jarModList()->allMods(); -} - -void LegacyInstance::jarModsChanged() -{ - qDebug() << "Jar mods of instance " << name() << " have changed. Jar will be rebuilt."; - setShouldRebuild(true); -} - -std::shared_ptr LegacyInstance::loaderModList() const -{ - if (!loader_mod_list) - { - loader_mod_list.reset(new ModList(loaderModsDir())); - } - loader_mod_list->update(); - return loader_mod_list; -} - -std::shared_ptr LegacyInstance::texturePackList() const -{ - if (!texture_pack_list) - { - texture_pack_list.reset(new ModList(texturePacksDir())); - } - texture_pack_list->update(); - return texture_pack_list; -} - -QString LegacyInstance::jarModsDir() const -{ - return PathCombine(instanceRoot(), "instMods"); -} - -QString LegacyInstance::binDir() const -{ - return PathCombine(minecraftRoot(), "bin"); -} - -QString LegacyInstance::libDir() const -{ - return PathCombine(minecraftRoot(), "lib"); -} - -QString LegacyInstance::savesDir() const -{ - return PathCombine(minecraftRoot(), "saves"); -} - -QString LegacyInstance::loaderModsDir() const -{ - return PathCombine(minecraftRoot(), "mods"); -} - -QString LegacyInstance::coreModsDir() const -{ - return PathCombine(minecraftRoot(), "coremods"); -} - -QString LegacyInstance::resourceDir() const -{ - return PathCombine(minecraftRoot(), "resources"); -} -QString LegacyInstance::texturePacksDir() const -{ - return PathCombine(minecraftRoot(), "texturepacks"); -} - -QString LegacyInstance::runnableJar() const -{ - return PathCombine(binDir(), "minecraft.jar"); -} - -QString LegacyInstance::modListFile() const -{ - return PathCombine(instanceRoot(), "modlist"); -} - -QString LegacyInstance::instanceConfigFolder() const -{ - return PathCombine(minecraftRoot(), "config"); -} - -bool LegacyInstance::shouldRebuild() const -{ - return m_settings->get("NeedsRebuild").toBool(); -} - -void LegacyInstance::setShouldRebuild(bool val) -{ - m_settings->set("NeedsRebuild", val); -} - -QString LegacyInstance::currentVersionId() const -{ - return m_settings->get("JarVersion").toString(); -} - -QString LegacyInstance::lwjglVersion() const -{ - return m_settings->get("LwjglVersion").toString(); -} - -void LegacyInstance::setLWJGLVersion(QString val) -{ - m_settings->set("LwjglVersion", val); -} - -QString LegacyInstance::intendedVersionId() const -{ - return m_settings->get("IntendedJarVersion").toString(); -} - -bool LegacyInstance::setIntendedVersionId(QString version) -{ - settings().set("IntendedJarVersion", version); - setShouldUpdate(true); - return true; -} - -bool LegacyInstance::shouldUpdate() const -{ - QVariant var = settings().get("ShouldUpdate"); - if (!var.isValid() || var.toBool() == false) - { - return intendedVersionId() != currentVersionId(); - } - return true; -} - -void LegacyInstance::setShouldUpdate(bool val) -{ - settings().set("ShouldUpdate", val); -} - -QString LegacyInstance::defaultBaseJar() const -{ - return "versions/" + intendedVersionId() + "/" + intendedVersionId() + ".jar"; -} - -QString LegacyInstance::defaultCustomBaseJar() const -{ - return PathCombine(binDir(), "mcbackup.jar"); -} - -QString LegacyInstance::getStatusbarDescription() -{ - if (flags() & VersionBrokenFlag) - { - return tr("Legacy : %1 (broken)").arg(intendedVersionId()); - } - return tr("Legacy : %1").arg(intendedVersionId()); -} - -QString LegacyInstance::lwjglFolder() const -{ - return m_lwjglFolderSetting->get().toString(); -} diff --git a/logic/LegacyInstance.h b/logic/LegacyInstance.h deleted file mode 100644 index 353718c1..00000000 --- a/logic/LegacyInstance.h +++ /dev/null @@ -1,127 +0,0 @@ -/* Copyright 2013-2015 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 "logic/minecraft/MinecraftInstance.h" -#include "gui/pages/BasePageProvider.h" - -class ModList; -class Task; - -class LegacyInstance : public MinecraftInstance, public BasePageProvider -{ - Q_OBJECT -public: - - explicit LegacyInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir); - - virtual void init() {}; - - /// Path to the instance's minecraft.jar - QString runnableJar() const; - - //! Path to the instance's modlist file. - QString modListFile() const; - - ////// Edit Instance Dialog stuff ////// - virtual QList getPages(); - virtual QString dialogTitle(); - - ////// Mod Lists ////// - std::shared_ptr jarModList() const ; - virtual QList< Mod > getJarMods() const override; - std::shared_ptr coreModList() const; - std::shared_ptr loaderModList() const; - std::shared_ptr texturePackList() const override; - - ////// Directories ////// - QString libDir() const; - QString savesDir() const; - QString texturePacksDir() const; - QString jarModsDir() const; - QString binDir() const; - QString loaderModsDir() const; - QString coreModsDir() const; - QString resourceDir() const; - virtual QString instanceConfigFolder() const override; - - /// Get the curent base jar of this instance. By default, it's the - /// versions/$version/$version.jar - QString baseJar() const; - - /// the default base jar of this instance - QString defaultBaseJar() const; - /// the default custom base jar of this instance - QString defaultCustomBaseJar() const; - - /*! - * Whether or not custom base jar is used - */ - bool shouldUseCustomBaseJar() const; - void setShouldUseCustomBaseJar(bool val); - - /*! - * The value of the custom base jar - */ - QString customBaseJar() const; - void setCustomBaseJar(QString val); - - /*! - * Whether or not the instance's minecraft.jar needs to be rebuilt. - * If this is true, when the instance launches, its jar mods will be - * re-added to a fresh minecraft.jar file. - */ - bool shouldRebuild() const; - void setShouldRebuild(bool val); - - virtual QString currentVersionId() const override; - - //! The version of LWJGL that this instance uses. - QString lwjglVersion() const; - - //! Where the lwjgl versions foor this instance can be found... HACK HACK HACK - QString lwjglFolder() const; - - /// st the version of LWJGL libs this instance will use - void setLWJGLVersion(QString val); - - virtual QString intendedVersionId() const override; - virtual bool setIntendedVersionId(QString version) override; - - virtual QSet traits() - { - return {"legacy-instance", "texturepacks"}; - }; - - virtual bool shouldUpdate() const override; - virtual void setShouldUpdate(bool val) override; - virtual std::shared_ptr doUpdate() override; - - virtual BaseProcess *prepareForLaunch(AuthSessionPtr account) override; - virtual void cleanupAfterRun() override; - - virtual QString getStatusbarDescription() override; - -protected: - mutable std::shared_ptr jar_mod_list; - mutable std::shared_ptr core_mod_list; - mutable std::shared_ptr loader_mod_list; - mutable std::shared_ptr texture_pack_list; - std::shared_ptr m_lwjglFolderSetting; -protected -slots: - virtual void jarModsChanged(); -}; diff --git a/logic/LegacyUpdate.cpp b/logic/LegacyUpdate.cpp deleted file mode 100644 index 8b970f08..00000000 --- a/logic/LegacyUpdate.cpp +++ /dev/null @@ -1,468 +0,0 @@ -/* Copyright 2013-2015 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 - -#include -#include -#include -#include - -#include "logic/LegacyUpdate.h" -#include "logic/LwjglVersionList.h" -#include "logic/minecraft/MinecraftVersionList.h" -#include "logic/BaseInstance.h" -#include "logic/LegacyInstance.h" -#include "logic/Env.h" -#include "logic/ModList.h" - -#include -#include "logic/net/URLConstants.h" -#include "JarUtils.h" - -LegacyUpdate::LegacyUpdate(BaseInstance *inst, QObject *parent) : Task(parent), m_inst(inst) -{ -} - -void LegacyUpdate::executeTask() -{ - fmllibsStart(); -} - -void LegacyUpdate::fmllibsStart() -{ - // Get the mod list - LegacyInstance *inst = (LegacyInstance *)m_inst; - auto modList = inst->jarModList(); - - bool forge_present = false; - - QString version = inst->intendedVersionId(); - auto & fmlLibsMapping = g_VersionFilterData.fmlLibsMapping; - if (!fmlLibsMapping.contains(version)) - { - lwjglStart(); - return; - } - - auto &libList = fmlLibsMapping[version]; - - // determine if we need some libs for FML or forge - setStatus(tr("Checking for FML libraries...")); - for (unsigned i = 0; i < modList->size(); i++) - { - auto &mod = modList->operator[](i); - - // do not use disabled mods. - if (!mod.enabled()) - continue; - - if (mod.type() != Mod::MOD_ZIPFILE) - continue; - - if (mod.mmc_id().contains("forge", Qt::CaseInsensitive)) - { - forge_present = true; - break; - } - if (mod.mmc_id().contains("fml", Qt::CaseInsensitive)) - { - forge_present = true; - break; - } - } - // we don't... - if (!forge_present) - { - lwjglStart(); - return; - } - - // now check the lib folder inside the instance for files. - for (auto &lib : libList) - { - QFileInfo libInfo(PathCombine(inst->libDir(), lib.filename)); - if (libInfo.exists()) - continue; - fmlLibsToProcess.append(lib); - } - - // if everything is in place, there's nothing to do here... - if (fmlLibsToProcess.isEmpty()) - { - lwjglStart(); - return; - } - - // download missing libs to our place - setStatus(tr("Dowloading FML libraries...")); - auto dljob = new NetJob("FML libraries"); - auto metacache = ENV.metacache(); - for (auto &lib : fmlLibsToProcess) - { - auto entry = metacache->resolveEntry("fmllibs", lib.filename); - QString urlString = lib.ours ? URLConstants::FMLLIBS_OUR_BASE_URL + lib.filename - : URLConstants::FMLLIBS_FORGE_BASE_URL + lib.filename; - dljob->addNetAction(CacheDownload::make(QUrl(urlString), entry)); - } - - connect(dljob, SIGNAL(succeeded()), SLOT(fmllibsFinished())); - connect(dljob, SIGNAL(failed()), SLOT(fmllibsFailed())); - connect(dljob, SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); - legacyDownloadJob.reset(dljob); - legacyDownloadJob->start(); -} - -void LegacyUpdate::fmllibsFinished() -{ - legacyDownloadJob.reset(); - if(!fmlLibsToProcess.isEmpty()) - { - setStatus(tr("Copying FML libraries into the instance...")); - LegacyInstance *inst = (LegacyInstance *)m_inst; - auto metacache = ENV.metacache(); - int index = 0; - for (auto &lib : fmlLibsToProcess) - { - progress(index, fmlLibsToProcess.size()); - auto entry = metacache->resolveEntry("fmllibs", lib.filename); - auto path = PathCombine(inst->libDir(), lib.filename); - if(!ensureFilePathExists(path)) - { - emitFailed(tr("Failed creating FML library folder inside the instance.")); - return; - } - if (!QFile::copy(entry->getFullPath(), PathCombine(inst->libDir(), lib.filename))) - { - emitFailed(tr("Failed copying Forge/FML library: %1.").arg(lib.filename)); - return; - } - index++; - } - progress(index, fmlLibsToProcess.size()); - } - lwjglStart(); -} - -void LegacyUpdate::fmllibsFailed() -{ - emitFailed("Game update failed: it was impossible to fetch the required FML libraries."); - return; -} - -void LegacyUpdate::lwjglStart() -{ - LegacyInstance *inst = (LegacyInstance *)m_inst; - - lwjglVersion = inst->lwjglVersion(); - lwjglTargetPath = PathCombine(inst->lwjglFolder(), lwjglVersion); - lwjglNativesPath = PathCombine(lwjglTargetPath, "natives"); - - // if the 'done' file exists, we don't have to download this again - QFileInfo doneFile(PathCombine(lwjglTargetPath, "done")); - if (doneFile.exists()) - { - jarStart(); - return; - } - - auto list = std::dynamic_pointer_cast(ENV.getVersionList("org.lwjgl.legacy")); - if (!list->isLoaded()) - { - emitFailed("Too soon! Let the LWJGL list load :)"); - return; - } - - setStatus(tr("Downloading new LWJGL...")); - auto version = std::dynamic_pointer_cast(list->findVersion(lwjglVersion)); - if (!version) - { - emitFailed("Game update failed: the selected LWJGL version is invalid."); - return; - } - - QString url = version->url(); - QUrl realUrl(url); - QString hostname = realUrl.host(); - auto worker = ENV.qnam(); - QNetworkRequest req(realUrl); - req.setRawHeader("Host", hostname.toLatin1()); - req.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)"); - QNetworkReply *rep = worker->get(req); - - m_reply = std::shared_ptr(rep); - connect(rep, SIGNAL(downloadProgress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); - connect(worker.get(), SIGNAL(finished(QNetworkReply *)), - SLOT(lwjglFinished(QNetworkReply *))); -} - -void LegacyUpdate::lwjglFinished(QNetworkReply *reply) -{ - if (m_reply.get() != reply) - { - return; - } - if (reply->error() != QNetworkReply::NoError) - { - emitFailed("Failed to download: " + reply->errorString() + - "\nSometimes you have to wait a bit if you download many LWJGL versions in " - "a row. YMMV"); - return; - } - auto worker = ENV.qnam(); - // Here i check if there is a cookie for me in the reply and extract it - QList cookies = - qvariant_cast>(reply->header(QNetworkRequest::SetCookieHeader)); - if (cookies.count() != 0) - { - // you must tell which cookie goes with which url - worker->cookieJar()->setCookiesFromUrl(cookies, QUrl("sourceforge.net")); - } - - // here you can check for the 302 or whatever other header i need - QVariant newLoc = reply->header(QNetworkRequest::LocationHeader); - if (newLoc.isValid()) - { - QString redirectedTo = reply->header(QNetworkRequest::LocationHeader).toString(); - QUrl realUrl(redirectedTo); - QString hostname = realUrl.host(); - QNetworkRequest req(redirectedTo); - req.setRawHeader("Host", hostname.toLatin1()); - req.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)"); - QNetworkReply *rep = worker->get(req); - connect(rep, SIGNAL(downloadProgress(qint64, qint64)), - SIGNAL(progress(qint64, qint64))); - m_reply = std::shared_ptr(rep); - return; - } - QFile saveMe("lwjgl.zip"); - saveMe.open(QIODevice::WriteOnly); - saveMe.write(m_reply->readAll()); - saveMe.close(); - setStatus(tr("Installing new LWJGL...")); - extractLwjgl(); - jarStart(); -} -void LegacyUpdate::extractLwjgl() -{ - // make sure the directories are there - - bool success = ensureFolderPathExists(lwjglNativesPath); - - if (!success) - { - emitFailed("Failed to extract the lwjgl libs - error when creating required folders."); - return; - } - - QuaZip zip("lwjgl.zip"); - if (!zip.open(QuaZip::mdUnzip)) - { - emitFailed("Failed to extract the lwjgl libs - not a valid archive."); - return; - } - - // and now we are going to access files inside it - QuaZipFile file(&zip); - const QString jarNames[] = {"jinput.jar", "lwjgl_util.jar", "lwjgl.jar"}; - for (bool more = zip.goToFirstFile(); more; more = zip.goToNextFile()) - { - if (!file.open(QIODevice::ReadOnly)) - { - zip.close(); - emitFailed("Failed to extract the lwjgl libs - error while reading archive."); - return; - } - QuaZipFileInfo info; - QString name = file.getActualFileName(); - if (name.endsWith('/')) - { - file.close(); - continue; - } - QString destFileName; - // Look for the jars - for (int i = 0; i < 3; i++) - { - if (name.endsWith(jarNames[i])) - { - destFileName = PathCombine(lwjglTargetPath, jarNames[i]); - } - } - // Not found? look for the natives - if (destFileName.isEmpty()) - { -#ifdef Q_OS_WIN32 - QString nativesDir = "windows"; -#else -#ifdef Q_OS_MAC - QString nativesDir = "macosx"; -#else - QString nativesDir = "linux"; -#endif -#endif - if (name.contains(nativesDir)) - { - int lastSlash = name.lastIndexOf('/'); - int lastBackSlash = name.lastIndexOf('\\'); - if (lastSlash != -1) - name = name.mid(lastSlash + 1); - else if (lastBackSlash != -1) - name = name.mid(lastBackSlash + 1); - destFileName = PathCombine(lwjglNativesPath, name); - } - } - // Now if destFileName is still empty, go to the next file. - if (!destFileName.isEmpty()) - { - setStatus(tr("Installing new LWJGL - extracting ") + name + "..."); - QFile output(destFileName); - output.open(QIODevice::WriteOnly); - output.write(file.readAll()); // FIXME: wste of memory!? - output.close(); - } - file.close(); // do not forget to close! - } - zip.close(); - m_reply.reset(); - QFile doneFile(PathCombine(lwjglTargetPath, "done")); - doneFile.open(QIODevice::WriteOnly); - doneFile.write("done."); - doneFile.close(); -} - -void LegacyUpdate::lwjglFailed() -{ - emitFailed("Bad stuff happened while trying to get the lwjgl libs..."); -} - -void LegacyUpdate::jarStart() -{ - LegacyInstance *inst = (LegacyInstance *)m_inst; - if (!inst->shouldUpdate() || inst->shouldUseCustomBaseJar()) - { - ModTheJar(); - return; - } - - setStatus(tr("Checking for jar updates...")); - // Make directories - QDir binDir(inst->binDir()); - if (!binDir.exists() && !binDir.mkpath(".")) - { - emitFailed("Failed to create bin folder."); - return; - } - - // Build a list of URLs that will need to be downloaded. - setStatus(tr("Downloading new minecraft.jar ...")); - - QString version_id = inst->intendedVersionId(); - QString localPath = version_id + "/" + version_id + ".jar"; - QString urlstr = "http://" + URLConstants::AWS_DOWNLOAD_VERSIONS + localPath; - - auto dljob = new NetJob("Minecraft.jar for version " + version_id); - - auto metacache = ENV.metacache(); - auto entry = metacache->resolveEntry("versions", localPath); - dljob->addNetAction(CacheDownload::make(QUrl(urlstr), entry)); - connect(dljob, SIGNAL(succeeded()), SLOT(jarFinished())); - connect(dljob, SIGNAL(failed()), SLOT(jarFailed())); - connect(dljob, SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); - legacyDownloadJob.reset(dljob); - legacyDownloadJob->start(); -} - -void LegacyUpdate::jarFinished() -{ - // process the jar - ModTheJar(); -} - -void LegacyUpdate::jarFailed() -{ - // bad, bad - emitFailed("Failed to download the minecraft jar. Try again later."); -} - -void LegacyUpdate::ModTheJar() -{ - LegacyInstance *inst = (LegacyInstance *)m_inst; - - if (!inst->shouldRebuild()) - { - emitSucceeded(); - return; - } - - // Get the mod list - auto modList = inst->getJarMods(); - - QFileInfo runnableJar(inst->runnableJar()); - QFileInfo baseJar(inst->baseJar()); - bool base_is_custom = inst->shouldUseCustomBaseJar(); - - // Nothing to do if there are no jar mods to install, no backup and just the mc jar - if (base_is_custom) - { - // yes, this can happen if the instance only has the runnable jar and not the base jar - // it *could* be assumed that such an instance is vanilla, but that wouldn't be safe - // because that's not something mmc4 guarantees - if (runnableJar.isFile() && !baseJar.exists() && modList.empty()) - { - inst->setShouldRebuild(false); - emitSucceeded(); - return; - } - - setStatus(tr("Installing mods: Backing up minecraft.jar ...")); - if (!baseJar.exists() && !QFile::copy(runnableJar.filePath(), baseJar.filePath())) - { - emitFailed("It seems both the active and base jar are gone. A fresh base jar will " - "be used on next run."); - inst->setShouldRebuild(true); - inst->setShouldUpdate(true); - inst->setShouldUseCustomBaseJar(false); - return; - } - } - - if (!baseJar.exists()) - { - emitFailed("The base jar " + baseJar.filePath() + " does not exist"); - return; - } - - if (runnableJar.exists() && !QFile::remove(runnableJar.filePath())) - { - emitFailed("Failed to delete old minecraft.jar"); - return; - } - - setStatus(tr("Installing mods: Opening minecraft.jar ...")); - - QString outputJarPath = runnableJar.filePath(); - QString inputJarPath = baseJar.filePath(); - - if(!JarUtils::createModdedJar(inputJarPath, outputJarPath, modList)) - { - emitFailed(tr("Failed to create the custom Minecraft jar file.")); - return; - } - inst->setShouldRebuild(false); - // inst->UpdateVersion(true); - emitSucceeded(); - return; -} diff --git a/logic/LegacyUpdate.h b/logic/LegacyUpdate.h deleted file mode 100644 index 78e456a1..00000000 --- a/logic/LegacyUpdate.h +++ /dev/null @@ -1,72 +0,0 @@ -/* Copyright 2013-2015 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 -#include -#include - -#include "logic/net/NetJob.h" -#include "logic/tasks/Task.h" -#include "logic/minecraft/VersionFilterData.h" - -class MinecraftVersion; -class BaseInstance; -class QuaZip; -class Mod; - -class LegacyUpdate : public Task -{ - Q_OBJECT -public: - explicit LegacyUpdate(BaseInstance *inst, QObject *parent = 0); - virtual void executeTask(); - -private -slots: - void lwjglStart(); - void lwjglFinished(QNetworkReply *); - void lwjglFailed(); - - void jarStart(); - void jarFinished(); - void jarFailed(); - - void fmllibsStart(); - void fmllibsFinished(); - void fmllibsFailed(); - - void extractLwjgl(); - - void ModTheJar(); - -private: - - std::shared_ptr m_reply; - - // target version, determined during this task - // MinecraftVersion *targetVersion; - QString lwjglURL; - QString lwjglVersion; - - QString lwjglTargetPath; - QString lwjglNativesPath; - -private: - NetJobPtr legacyDownloadJob; - BaseInstance *m_inst = nullptr; - QList fmlLibsToProcess; -}; diff --git a/logic/LwjglVersionList.cpp b/logic/LwjglVersionList.cpp deleted file mode 100644 index 9e101b74..00000000 --- a/logic/LwjglVersionList.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/* Copyright 2013-2015 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 "LwjglVersionList.h" -#include "logic/Env.h" - -#include -#include -#include - -#include - -#define RSS_URL "http://sourceforge.net/projects/java-game-lib/rss" - -LWJGLVersionList::LWJGLVersionList(QObject *parent) : BaseVersionList(parent) -{ - setLoading(false); -} - -QVariant LWJGLVersionList::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) - return QVariant(); - - if (index.row() > count()) - return QVariant(); - - const PtrLWJGLVersion version = m_vlist.at(index.row()); - - switch (role) - { - case Qt::DisplayRole: - return version->name(); - - case Qt::ToolTipRole: - return version->url(); - - default: - return QVariant(); - } -} - -QVariant LWJGLVersionList::headerData(int section, Qt::Orientation orientation, int role) const -{ - switch (role) - { - case Qt::DisplayRole: - return tr("Version"); - - case Qt::ToolTipRole: - return tr("LWJGL version name."); - - default: - return QVariant(); - } -} - -int LWJGLVersionList::columnCount(const QModelIndex &parent) const -{ - return 1; -} - -bool LWJGLVersionList::isLoading() const -{ - return m_loading; -} - -void LWJGLVersionList::loadList() -{ - Q_ASSERT_X(!m_loading, "loadList", "list is already loading (m_loading is true)"); - - setLoading(true); - auto worker = ENV.qnam(); - QNetworkRequest req(QUrl(RSS_URL)); - req.setRawHeader("Accept", "application/rss+xml, text/xml, */*"); - req.setRawHeader("User-Agent", "MultiMC/5.0 (Uncached)"); - reply = worker->get(req); - connect(reply, SIGNAL(finished()), SLOT(netRequestComplete())); -} - -inline QDomElement getDomElementByTagName(QDomElement parent, QString tagname) -{ - QDomNodeList elementList = parent.elementsByTagName(tagname); - if (elementList.count()) - return elementList.at(0).toElement(); - else - return QDomElement(); -} - -void LWJGLVersionList::netRequestComplete() -{ - if (reply->error() == QNetworkReply::NoError) - { - QRegExp lwjglRegex("lwjgl-(([0-9]\\.?)+)\\.zip"); - Q_ASSERT_X(lwjglRegex.isValid(), "load LWJGL list", "LWJGL regex is invalid"); - - QDomDocument doc; - - QString xmlErrorMsg; - int errorLine; - auto rawData = reply->readAll(); - if (!doc.setContent(rawData, false, &xmlErrorMsg, &errorLine)) - { - failed("Failed to load LWJGL list. XML error: " + xmlErrorMsg + " at line " + - QString::number(errorLine)); - setLoading(false); - return; - } - - QDomNodeList items = doc.elementsByTagName("item"); - - QList tempList; - - for (int i = 0; i < items.length(); i++) - { - Q_ASSERT_X(items.at(i).isElement(), "load LWJGL list", - "XML element isn't an element... wat?"); - - QDomElement linkElement = getDomElementByTagName(items.at(i).toElement(), "link"); - if (linkElement.isNull()) - { - qDebug() << "Link element" << i << "in RSS feed doesn't exist! Skipping."; - continue; - } - - QString link = linkElement.text(); - - // Make sure it's a download link. - if (link.endsWith("/download") && link.contains(lwjglRegex)) - { - QString name = link.mid(lwjglRegex.indexIn(link) + 6); - // Subtract 4 here to remove the .zip file extension. - name = name.left(lwjglRegex.matchedLength() - 10); - - QUrl url(link); - if (!url.isValid()) - { - qWarning() << "LWJGL version URL isn't valid:" << link << "Skipping."; - continue; - } - qDebug() << "Discovered LWGL version" << name << "at" << link; - tempList.append(std::make_shared(name, link)); - } - } - - beginResetModel(); - m_vlist.swap(tempList); - endResetModel(); - - qDebug() << "Loaded LWJGL list."; - finished(); - } - else - { - failed("Failed to load LWJGL list. Network error: " + reply->errorString()); - } - - setLoading(false); - reply->deleteLater(); -} - -void LWJGLVersionList::failed(QString msg) -{ - qCritical() << msg; - emit loadListFailed(msg); -} - -void LWJGLVersionList::finished() -{ - emit loadListFinished(); -} - -void LWJGLVersionList::setLoading(bool loading) -{ - m_loading = loading; - emit loadingStateUpdated(m_loading); -} diff --git a/logic/LwjglVersionList.h b/logic/LwjglVersionList.h deleted file mode 100644 index 9205b964..00000000 --- a/logic/LwjglVersionList.h +++ /dev/null @@ -1,154 +0,0 @@ -/* Copyright 2013-2015 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 -#include -#include -#include - -#include -#include "BaseVersion.h" -#include "BaseVersionList.h" - -class LWJGLVersion; -typedef std::shared_ptr PtrLWJGLVersion; - -class LWJGLVersion : public BaseVersion -{ -public: - LWJGLVersion(const QString &name, const QString &url) - : m_name(name), m_url(url) - { - } - - virtual QString descriptor() - { - return m_name; - } - - virtual QString name() - { - return m_name; - } - - virtual QString typeString() const - { - return QObject::tr("Upstream"); - } - - QString url() const - { - return m_url; - } - -protected: - QString m_name; - QString m_url; -}; - -class LWJGLVersionList : public BaseVersionList -{ - Q_OBJECT -public: - explicit LWJGLVersionList(QObject *parent = 0); - - bool isLoaded() - { - return m_vlist.length() > 0; - } - virtual const BaseVersionPtr at(int i) const override - { - return m_vlist[i]; - } - - virtual Task* getLoadTask() - { - return nullptr; - } - - virtual void sort() {}; - - virtual void updateListData(QList< BaseVersionPtr > versions) {}; - - int count() const - { - return m_vlist.length(); - } - - virtual QVariant data(const QModelIndex &index, int role) const; - virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; - virtual int rowCount(const QModelIndex &parent) const - { - return count(); - } - virtual int columnCount(const QModelIndex &parent) const; - - virtual bool isLoading() const; - virtual bool errored() const - { - return m_errored; - } - - virtual QString lastErrorMsg() const - { - return m_lastErrorMsg; - } - -public -slots: - /*! - * Loads the version list. - * This is done asynchronously. On success, the loadListFinished() signal will - * be emitted. The list model will be reset as well, resulting in the modelReset() - * signal being emitted. Note that the model will be reset before loadListFinished() is - * emitted. - * If loading the list failed, the loadListFailed(QString msg), - * signal will be emitted. - */ - virtual void loadList(); - -signals: - /*! - * Emitted when the list either starts or finishes loading. - * \param loading Whether or not the list is loading. - */ - void loadingStateUpdated(bool loading); - - void loadListFinished(); - - void loadListFailed(QString msg); - -private: - QList m_vlist; - - QNetworkReply *m_netReply; - QNetworkReply *reply; - - bool m_loading; - bool m_errored; - QString m_lastErrorMsg; - - void failed(QString msg); - - void finished(); - - void setLoading(bool loading); - -private -slots: - virtual void netRequestComplete(); -}; diff --git a/logic/Mod.cpp b/logic/Mod.cpp deleted file mode 100644 index 7fa4905e..00000000 --- a/logic/Mod.cpp +++ /dev/null @@ -1,377 +0,0 @@ -/* Copyright 2013-2015 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 -#include -#include -#include -#include -#include -#include -#include - -#include "Mod.h" -#include -#include "logic/settings/INIFile.h" -#include - -Mod::Mod(const QFileInfo &file) -{ - repath(file); -} - -void Mod::repath(const QFileInfo &file) -{ - m_file = file; - QString name_base = file.fileName(); - - m_type = Mod::MOD_UNKNOWN; - - if (m_file.isDir()) - { - m_type = MOD_FOLDER; - m_name = name_base; - m_mmc_id = name_base; - } - else if (m_file.isFile()) - { - if (name_base.endsWith(".disabled")) - { - m_enabled = false; - name_base.chop(9); - } - else - { - m_enabled = true; - } - m_mmc_id = name_base; - if (name_base.endsWith(".zip") || name_base.endsWith(".jar")) - { - m_type = MOD_ZIPFILE; - name_base.chop(4); - } - else if (name_base.endsWith(".litemod")) - { - m_type = MOD_LITEMOD; - name_base.chop(8); - } - else - { - m_type = MOD_SINGLEFILE; - } - m_name = name_base; - } - - if (m_type == MOD_ZIPFILE) - { - QuaZip zip(m_file.filePath()); - if (!zip.open(QuaZip::mdUnzip)) - return; - - QuaZipFile file(&zip); - - if (zip.setCurrentFile("mcmod.info")) - { - if (!file.open(QIODevice::ReadOnly)) - { - zip.close(); - return; - } - - ReadMCModInfo(file.readAll()); - file.close(); - zip.close(); - return; - } - else if (zip.setCurrentFile("forgeversion.properties")) - { - if (!file.open(QIODevice::ReadOnly)) - { - zip.close(); - return; - } - - ReadForgeInfo(file.readAll()); - file.close(); - zip.close(); - return; - } - - zip.close(); - } - else if (m_type == MOD_FOLDER) - { - QFileInfo mcmod_info(PathCombine(m_file.filePath(), "mcmod.info")); - if (mcmod_info.isFile()) - { - QFile mcmod(mcmod_info.filePath()); - if (!mcmod.open(QIODevice::ReadOnly)) - return; - auto data = mcmod.readAll(); - if (data.isEmpty() || data.isNull()) - return; - ReadMCModInfo(data); - } - } - else if (m_type == MOD_LITEMOD) - { - QuaZip zip(m_file.filePath()); - if (!zip.open(QuaZip::mdUnzip)) - return; - - QuaZipFile file(&zip); - - if (zip.setCurrentFile("litemod.json")) - { - if (!file.open(QIODevice::ReadOnly)) - { - zip.close(); - return; - } - - ReadLiteModInfo(file.readAll()); - file.close(); - } - zip.close(); - } -} - -// NEW format -// https://github.com/MinecraftForge/FML/wiki/FML-mod-information-file/6f62b37cea040daf350dc253eae6326dd9c822c3 - -// OLD format: -// https://github.com/MinecraftForge/FML/wiki/FML-mod-information-file/5bf6a2d05145ec79387acc0d45c958642fb049fc -void Mod::ReadMCModInfo(QByteArray contents) -{ - auto getInfoFromArray = [&](QJsonArray arr)->void - { - if (!arr.at(0).isObject()) - return; - auto firstObj = arr.at(0).toObject(); - m_mod_id = firstObj.value("modid").toString(); - m_name = firstObj.value("name").toString(); - m_version = firstObj.value("version").toString(); - m_homeurl = firstObj.value("url").toString(); - m_updateurl = firstObj.value("updateUrl").toString(); - m_homeurl = m_homeurl.trimmed(); - if(!m_homeurl.isEmpty()) - { - // fix up url. - if (!m_homeurl.startsWith("http://") && !m_homeurl.startsWith("https://") && - !m_homeurl.startsWith("ftp://")) - { - m_homeurl.prepend("http://"); - } - } - m_description = firstObj.value("description").toString(); - QJsonArray authors = firstObj.value("authorList").toArray(); - if (authors.size() == 0) - authors = firstObj.value("authors").toArray(); - - if (authors.size() == 0) - m_authors = ""; - else if (authors.size() >= 1) - { - m_authors = authors.at(0).toString(); - for (int i = 1; i < authors.size(); i++) - { - m_authors += ", " + authors.at(i).toString(); - } - } - m_credits = firstObj.value("credits").toString(); - return; - } - ; - QJsonParseError jsonError; - QJsonDocument jsonDoc = QJsonDocument::fromJson(contents, &jsonError); - // this is the very old format that had just the array - if (jsonDoc.isArray()) - { - getInfoFromArray(jsonDoc.array()); - } - else if (jsonDoc.isObject()) - { - auto val = jsonDoc.object().value("modinfoversion"); - if(val.isUndefined()) - val = jsonDoc.object().value("modListVersion"); - int version = val.toDouble(); - if (version != 2) - { - qCritical() << "BAD stuff happened to mod json:"; - qCritical() << contents; - return; - } - auto arrVal = jsonDoc.object().value("modlist"); - if(arrVal.isUndefined()) - arrVal = jsonDoc.object().value("modList"); - if (arrVal.isArray()) - { - getInfoFromArray(arrVal.toArray()); - } - } -} - -void Mod::ReadForgeInfo(QByteArray contents) -{ - // Read the data - m_name = "Minecraft Forge"; - m_mod_id = "Forge"; - m_home