From aade36860c373268857ca821c14a13f38c880b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 23 Apr 2014 02:27:40 +0200 Subject: Begin the transformation! Nuke all the things. --- CMakeLists.txt | 53 ++- MultiMC.cpp | 5 +- gui/MainWindow.cpp | 97 +---- gui/MainWindow.h | 10 +- gui/MainWindow.ui | 83 +--- gui/dialogs/InstanceEditDialog.cpp | 623 +++++++++++++++++++++++++++++ gui/dialogs/InstanceEditDialog.h | 97 +++++ gui/dialogs/InstanceEditDialog.ui | 404 +++++++++++++++++++ gui/dialogs/LegacyModEditDialog.cpp | 393 ------------------ gui/dialogs/LegacyModEditDialog.h | 78 ---- gui/dialogs/LegacyModEditDialog.ui | 321 --------------- gui/dialogs/ModEditDialogCommon.cpp | 57 --- gui/dialogs/ModEditDialogCommon.h | 22 - gui/dialogs/OneSixModEditDialog.cpp | 399 ------------------ gui/dialogs/OneSixModEditDialog.h | 75 ---- gui/dialogs/OneSixModEditDialog.ui | 310 -------------- logic/BaseInstaller.h | 2 +- logic/BaseVersion.h | 4 +- logic/ForgeInstaller.cpp | 328 --------------- logic/ForgeInstaller.h | 45 --- logic/InstanceFactory.cpp | 52 +-- logic/LegacyForge.cpp | 56 --- logic/LegacyForge.h | 25 -- logic/LegacyInstance.cpp | 11 +- logic/LegacyUpdate.cpp | 65 +-- logic/LegacyUpdate.h | 9 +- logic/LiteLoaderInstaller.cpp | 150 ------- logic/LiteLoaderInstaller.h | 41 -- logic/MinecraftVersion.h | 45 +-- logic/NostalgiaInstance.cpp | 36 -- logic/NostalgiaInstance.h | 29 -- logic/OneSixFTBInstance.cpp | 4 +- logic/OneSixInstance.cpp | 64 ++- logic/OneSixInstance.h | 11 +- logic/OneSixInstance_p.h | 3 +- logic/OneSixLibrary.h | 2 +- logic/OneSixUpdate.cpp | 2 +- logic/OneSixVersionBuilder.cpp | 10 +- logic/OneSixVersionBuilder.h | 5 +- logic/VersionFile.cpp | 84 +++- logic/VersionFile.h | 19 +- logic/VersionFinal.cpp | 75 ++-- logic/VersionFinal.h | 32 +- logic/forge/ForgeData.cpp | 62 +++ logic/forge/ForgeData.h | 21 + logic/forge/ForgeInstaller.cpp | 380 ++++++++++++++++++ logic/forge/ForgeInstaller.h | 51 +++ logic/forge/ForgeMirror.h | 10 + logic/forge/ForgeMirrors.cpp | 118 ++++++ logic/forge/ForgeMirrors.h | 58 +++ logic/forge/ForgeVersion.cpp | 55 +++ logic/forge/ForgeVersion.h | 31 ++ logic/forge/ForgeVersionList.cpp | 435 ++++++++++++++++++++ logic/forge/ForgeVersionList.h | 83 ++++ logic/forge/ForgeXzDownload.cpp | 389 ++++++++++++++++++ logic/forge/ForgeXzDownload.h | 66 +++ logic/forge/LegacyForge.cpp | 56 +++ logic/forge/LegacyForge.h | 25 ++ logic/lists/ForgeVersionList.cpp | 439 -------------------- logic/lists/ForgeVersionList.h | 128 ------ logic/lists/LiteLoaderVersionList.cpp | 223 ----------- logic/lists/LiteLoaderVersionList.h | 112 ------ logic/lists/MinecraftVersionList.cpp | 16 +- logic/liteloader/LiteLoaderInstaller.cpp | 150 +++++++ logic/liteloader/LiteLoaderInstaller.h | 40 ++ logic/liteloader/LiteLoaderVersionList.cpp | 223 +++++++++++ logic/liteloader/LiteLoaderVersionList.h | 112 ++++++ logic/net/ForgeMirror.h | 10 - logic/net/ForgeMirrors.cpp | 118 ------ logic/net/ForgeMirrors.h | 58 --- logic/net/ForgeXzDownload.cpp | 389 ------------------ logic/net/ForgeXzDownload.h | 66 --- logic/net/NetJob.h | 2 +- 73 files changed, 3819 insertions(+), 4343 deletions(-) create mode 100644 gui/dialogs/InstanceEditDialog.cpp create mode 100644 gui/dialogs/InstanceEditDialog.h create mode 100644 gui/dialogs/InstanceEditDialog.ui delete mode 100644 gui/dialogs/LegacyModEditDialog.cpp delete mode 100644 gui/dialogs/LegacyModEditDialog.h delete mode 100644 gui/dialogs/LegacyModEditDialog.ui delete mode 100644 gui/dialogs/ModEditDialogCommon.cpp delete mode 100644 gui/dialogs/ModEditDialogCommon.h delete mode 100644 gui/dialogs/OneSixModEditDialog.cpp delete mode 100644 gui/dialogs/OneSixModEditDialog.h delete mode 100644 gui/dialogs/OneSixModEditDialog.ui delete mode 100644 logic/ForgeInstaller.cpp delete mode 100644 logic/ForgeInstaller.h delete mode 100644 logic/LegacyForge.cpp delete mode 100644 logic/LegacyForge.h delete mode 100644 logic/LiteLoaderInstaller.cpp delete mode 100644 logic/LiteLoaderInstaller.h delete mode 100644 logic/NostalgiaInstance.cpp delete mode 100644 logic/NostalgiaInstance.h create mode 100644 logic/forge/ForgeData.cpp create mode 100644 logic/forge/ForgeData.h create mode 100644 logic/forge/ForgeInstaller.cpp create mode 100644 logic/forge/ForgeInstaller.h create mode 100644 logic/forge/ForgeMirror.h create mode 100644 logic/forge/ForgeMirrors.cpp create mode 100644 logic/forge/ForgeMirrors.h create mode 100644 logic/forge/ForgeVersion.cpp create mode 100644 logic/forge/ForgeVersion.h create mode 100644 logic/forge/ForgeVersionList.cpp create mode 100644 logic/forge/ForgeVersionList.h create mode 100644 logic/forge/ForgeXzDownload.cpp create mode 100644 logic/forge/ForgeXzDownload.h create mode 100644 logic/forge/LegacyForge.cpp create mode 100644 logic/forge/LegacyForge.h delete mode 100644 logic/lists/ForgeVersionList.cpp delete mode 100644 logic/lists/ForgeVersionList.h delete mode 100644 logic/lists/LiteLoaderVersionList.cpp delete mode 100644 logic/lists/LiteLoaderVersionList.h create mode 100644 logic/liteloader/LiteLoaderInstaller.cpp create mode 100644 logic/liteloader/LiteLoaderInstaller.h create mode 100644 logic/liteloader/LiteLoaderVersionList.cpp create mode 100644 logic/liteloader/LiteLoaderVersionList.h delete mode 100644 logic/net/ForgeMirror.h delete mode 100644 logic/net/ForgeMirrors.cpp delete mode 100644 logic/net/ForgeMirrors.h delete mode 100644 logic/net/ForgeXzDownload.cpp delete mode 100644 logic/net/ForgeXzDownload.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 345bb366..4617020a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -309,12 +309,8 @@ SET(MULTIMC_SOURCES gui/dialogs/InstanceSettings.cpp gui/dialogs/IconPickerDialog.h gui/dialogs/IconPickerDialog.cpp - gui/dialogs/LegacyModEditDialog.h - gui/dialogs/LegacyModEditDialog.cpp - gui/dialogs/OneSixModEditDialog.h - gui/dialogs/OneSixModEditDialog.cpp - gui/dialogs/ModEditDialogCommon.h - gui/dialogs/ModEditDialogCommon.cpp + gui/dialogs/InstanceEditDialog.h + gui/dialogs/InstanceEditDialog.cpp gui/dialogs/EditNotesDialog.h gui/dialogs/EditNotesDialog.cpp gui/dialogs/CustomMessageBox.h @@ -395,10 +391,6 @@ SET(MULTIMC_SOURCES logic/net/ByteArrayDownload.cpp logic/net/CacheDownload.h logic/net/CacheDownload.cpp - logic/net/ForgeMirrors.h - logic/net/ForgeMirrors.cpp - logic/net/ForgeXzDownload.h - logic/net/ForgeXzDownload.cpp logic/net/NetJob.h logic/net/NetJob.cpp logic/net/HttpMetaCache.h @@ -449,9 +441,6 @@ SET(MULTIMC_SOURCES logic/LegacyUpdate.h logic/LegacyUpdate.cpp - logic/LegacyForge.h - logic/LegacyForge.cpp - # OneSix instances logic/OneSixUpdate.h logic/OneSixUpdate.cpp @@ -476,14 +465,6 @@ SET(MULTIMC_SOURCES # Mod installers logic/BaseInstaller.h logic/BaseInstaller.cpp - logic/ForgeInstaller.h - logic/ForgeInstaller.cpp - logic/LiteLoaderInstaller.h - logic/LiteLoaderInstaller.cpp - - # Nostalgia - logic/NostalgiaInstance.h - logic/NostalgiaInstance.cpp # FTB logic/OneSixFTBInstance.h @@ -500,12 +481,8 @@ SET(MULTIMC_SOURCES logic/lists/MinecraftVersionList.cpp logic/lists/LwjglVersionList.h logic/lists/LwjglVersionList.cpp - logic/lists/ForgeVersionList.h - logic/lists/ForgeVersionList.cpp logic/lists/JavaVersionList.h logic/lists/JavaVersionList.cpp - logic/lists/LiteLoaderVersionList.h - logic/lists/LiteLoaderVersionList.cpp # the screenshots feature logic/screenshots/Screenshot.h @@ -566,6 +543,29 @@ SET(MULTIMC_SOURCES logic/tools/JProfiler.cpp logic/tools/JVisualVM.h logic/tools/JVisualVM.cpp + + # Forge and all things forge related + logic/forge/ForgeData.h + logic/forge/ForgeData.cpp + logic/forge/ForgeVersion.h + logic/forge/ForgeVersion.cpp + logic/forge/ForgeVersionList.h + logic/forge/ForgeVersionList.cpp + logic/forge/ForgeMirror.h + logic/forge/ForgeMirrors.h + logic/forge/ForgeMirrors.cpp + logic/forge/ForgeXzDownload.h + logic/forge/ForgeXzDownload.cpp + logic/forge/LegacyForge.h + logic/forge/LegacyForge.cpp + logic/forge/ForgeInstaller.h + logic/forge/ForgeInstaller.cpp + + # Liteloader and related things + logic/liteloader/LiteLoaderInstaller.h + logic/liteloader/LiteLoaderInstaller.cpp + logic/liteloader/LiteLoaderVersionList.h + logic/liteloader/LiteLoaderVersionList.cpp ) @@ -585,8 +585,7 @@ SET(MULTIMC_UIS gui/dialogs/InstanceSettings.ui gui/dialogs/ProgressDialog.ui gui/dialogs/IconPickerDialog.ui - gui/dialogs/LegacyModEditDialog.ui - gui/dialogs/OneSixModEditDialog.ui + gui/dialogs/InstanceEditDialog.ui gui/dialogs/EditNotesDialog.ui gui/dialogs/AccountListDialog.ui gui/dialogs/AccountSelectDialog.ui diff --git a/MultiMC.cpp b/MultiMC.cpp index c1fc089c..28fe8e26 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -17,8 +17,9 @@ #include "logic/icons/IconList.h" #include "logic/lists/LwjglVersionList.h" #include "logic/lists/MinecraftVersionList.h" -#include "logic/lists/ForgeVersionList.h" -#include "logic/lists/LiteLoaderVersionList.h" +#include "logic/liteloader/LiteLoaderVersionList.h" + +#include "logic/forge/ForgeVersionList.h" #include "logic/news/NewsChecker.h" diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 5ba05b2a..95f2ac4c 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -1032,7 +1032,7 @@ void MainWindow::on_actionViewSelectedInstFolder_triggered() } } -void MainWindow::on_actionEditInstMods_triggered() +void MainWindow::on_actionEditInstance_triggered() { if (m_selectedInstance) { @@ -1339,99 +1339,12 @@ void MainWindow::startTask(Task *task) task->start(); } -// Create A Desktop Shortcut -void MainWindow::on_actionMakeDesktopShortcut_triggered() -{ - QString name("Test"); - name = QInputDialog::getText(this, tr("MultiMC Shortcut"), tr("Enter a Shortcut Name."), - QLineEdit::Normal, name); - - Util::createShortCut(Util::getDesktopDir(), QApplication::instance()->applicationFilePath(), - QStringList() << "-dl" << QDir::currentPath() << "test", name, - "application-x-octet-stream"); - - CustomMessageBox::selectable( - this, tr("Not useful"), - tr("A Dummy Shortcut was created. it will not do anything productive"), - QMessageBox::Warning)->show(); -} - // BrowserDialog void MainWindow::openWebPage(QUrl url) { QDesktopServices::openUrl(url); } -void MainWindow::on_actionChangeInstMCVersion_triggered() -{ - if (view->selectionModel()->selectedIndexes().count() < 1) - return; - - VersionSelectDialog vselect(m_selectedInstance->versionList().get(), - tr("Change Minecraft version"), this); - vselect.setFuzzyFilter(1, "*OneSix*"); - if (!vselect.exec() || !vselect.selectedVersion()) - return; - - if (!MMC->accounts()->anyAccountIsValid()) - { - CustomMessageBox::selectable( - this, tr("Error"), - tr("MultiMC cannot download Minecraft or update instances unless you have at least " - "one account added.\nPlease add your Mojang or Minecraft account."), - QMessageBox::Warning)->show(); - return; - } - - if (m_selectedInstance->versionIsCustom()) - { - auto result = CustomMessageBox::selectable( - this, tr("Are you sure?"), - tr("This will remove any library/version customization you did previously. " - "This includes things like Forge install and similar."), - QMessageBox::Warning, QMessageBox::Ok | QMessageBox::Abort, - QMessageBox::Abort)->exec(); - - if (result != QMessageBox::Ok) - return; - } - m_selectedInstance->setIntendedVersionId(vselect.selectedVersion()->descriptor()); - - auto updateTask = m_selectedInstance->doUpdate(); - if (!updateTask) - { - return; - } - ProgressDialog tDialog(this); - connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString))); - tDialog.exec(updateTask.get()); -} - -void MainWindow::on_actionChangeInstLWJGLVersion_triggered() -{ - if (!m_selectedInstance) - return; - - LWJGLSelectDialog lselect(this); - lselect.exec(); - if (lselect.result() == QDialog::Accepted) - { - auto ptr = std::dynamic_pointer_cast(m_selectedInstance); - if(ptr) - ptr->setLWJGLVersion(lselect.selectedVersion()); - } -} - -void MainWindow::on_actionInstanceSettings_triggered() -{ - if (view->selectionModel()->selectedIndexes().count() < 1) - return; - - InstanceSettings settings(&m_selectedInstance->settings(), this); - settings.setWindowTitle(tr("Instance settings")); - settings.exec(); -} - void MainWindow::instanceChanged(const QModelIndex ¤t, const QModelIndex &previous) { if(!current.isValid()) @@ -1446,12 +1359,8 @@ void MainWindow::instanceChanged(const QModelIndex ¤t, const QModelIndex & { ui->instanceToolBar->setEnabled(m_selectedInstance->canLaunch()); renameButton->setText(m_selectedInstance->name()); - ui->actionChangeInstLWJGLVersion->setEnabled( - m_selectedInstance->menuActionEnabled("actionChangeInstLWJGLVersion")); - ui->actionEditInstMods->setEnabled( - m_selectedInstance->menuActionEnabled("actionEditInstMods")); - ui->actionChangeInstMCVersion->setEnabled( - m_selectedInstance->menuActionEnabled("actionChangeInstMCVersion")); + ui->actionEditInstance->setEnabled( + m_selectedInstance->menuActionEnabled("actionEditInstance")); m_statusLeft->setText(m_selectedInstance->getStatusbarDescription()); updateInstanceToolIcon(m_selectedInstance->iconKey()); diff --git a/gui/MainWindow.h b/gui/MainWindow.h index 69cf11b0..0cd2e84b 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -103,11 +103,7 @@ slots: void on_actionRenameInstance_triggered(); - void on_actionMakeDesktopShortcut_triggered(); - - void on_actionChangeInstMCVersion_triggered(); - - void on_actionEditInstMods_triggered(); + void on_actionEditInstance_triggered(); void on_actionEditInstNotes_triggered(); @@ -135,12 +131,8 @@ slots: void taskStart(); void taskEnd(); - void on_actionChangeInstLWJGLVersion_triggered(); - void instanceEnded(); - void on_actionInstanceSettings_triggered(); - // called when an icon is changed in the icon model. void iconUpdated(QString); diff --git a/gui/MainWindow.ui b/gui/MainWindow.ui index 1d7fbec9..8ee196fd 100644 --- a/gui/MainWindow.ui +++ b/gui/MainWindow.ui @@ -74,7 +74,7 @@ - + @@ -115,10 +115,7 @@ - - - - + @@ -284,7 +281,7 @@ Open the MultiMC Patreon page. - + @@ -388,82 +385,18 @@ Edit the notes for the selected instance. - - - true - - - Settings - - - Change settings for the selected instance. - - - Change settings for the selected instance. - - - - - false - - - Make Shortcut - - - Make a shortcut on the desktop for the selected instance. - - - Make a shortcut on the desktop for the selected instance. - - - - - false - - - Manage Saves - - - Manage saves for the selected instance. - - - Manage saves for the selected instance. - - - + Edit Mods - - Edit the mods for the selected instance. - - - Edit the mods for the selected instance. - - - - - Change Version - - - Change the selected instance's Minecraft version. - - - Change the selected instance's Minecraft version. - - - - - false - - - Change LWJGL + + Edit Instance - Change the version of LWJGL for the selected instance to use. + Change the instance settings, mods and versions. - Change the version of LWJGL for the selected instance to use. + Change the instance settings, mods and versions. diff --git a/gui/dialogs/InstanceEditDialog.cpp b/gui/dialogs/InstanceEditDialog.cpp new file mode 100644 index 00000000..fe2d1b03 --- /dev/null +++ b/gui/dialogs/InstanceEditDialog.cpp @@ -0,0 +1,623 @@ +/* Copyright 2013 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 "MultiMC.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "InstanceEditDialog.h" +#include "ui_InstanceEditDialog.h" + +#include "gui/Platform.h" +#include "gui/dialogs/CustomMessageBox.h" +#include "gui/dialogs/VersionSelectDialog.h" + +#include "gui/dialogs/ProgressDialog.h" +#include "InstanceSettings.h" + +#include "logic/ModList.h" +#include "logic/VersionFinal.h" +#include "logic/EnabledItemFilter.h" +#include "logic/forge/ForgeVersionList.h" +#include "logic/forge/ForgeInstaller.h" +#include "logic/liteloader/LiteLoaderVersionList.h" +#include "logic/liteloader/LiteLoaderInstaller.h" +#include "logic/OneSixVersionBuilder.h" +#include "logic/auth/MojangAccountList.h" + +#include +#include + +#include "CustomMessageBox.h" +#include +#include +#include +#include + +bool lastfirst(QModelIndexList &list, int &first, int &last) +{ + if (!list.size()) + return false; + first = last = list[0].row(); + for (auto item : list) + { + int row = item.row(); + if (row < first) + first = row; + if (row > last) + last = row; + } + return true; +} + +void showWebsiteForMod(QWidget *parentDlg, Mod &m) +{ + QString url = m.homeurl(); + if (url.size()) + { + // catch the cases where the protocol is missing + if (!url.startsWith("http")) + { + url = "http://" + url; + } + QDesktopServices::openUrl(url); + } + else + { + CustomMessageBox::selectable( + parentDlg, QObject::tr("How sad!"), + QObject::tr("The mod author didn't provide a website link for this mod."), + QMessageBox::Warning); + } +} + +InstanceEditDialog::InstanceEditDialog(OneSixInstance *inst, QWidget *parent) + : QDialog(parent), ui(new Ui::InstanceEditDialog), m_inst(inst) +{ + MultiMCPlatform::fixWM_CLASS(this); + ui->setupUi(this); + // libraries! + + m_version = m_inst->getFullVersion(); + if (m_version) + { + main_model = new EnabledItemFilter(this); + main_model->setActive(true); + main_model->setSourceModel(m_version.get()); + ui->libraryTreeView->setModel(main_model); + ui->libraryTreeView->installEventFilter(this); + connect(ui->libraryTreeView->selectionModel(), &QItemSelectionModel::currentChanged, + this, &InstanceEditDialog::versionCurrent); + updateVersionControls(); + } + else + { + disableVersionControls(); + } + // Loader mods + { + ensureFolderPathExists(m_inst->loaderModsDir()); + m_mods = m_inst->loaderModList(); + ui->loaderModTreeView->setModel(m_mods.get()); + ui->loaderModTreeView->installEventFilter(this); + m_mods->startWatching(); + auto smodel = ui->loaderModTreeView->selectionModel(); + connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), + SLOT(loaderCurrent(QModelIndex, QModelIndex))); + } + // Core mods + { + ensureFolderPathExists(m_inst->coreModsDir()); + m_coremods = m_inst->coreModList(); + ui->coreModsTreeView->setModel(m_coremods.get()); + ui->coreModsTreeView->installEventFilter(this); + m_coremods->startWatching(); + auto smodel = ui->coreModsTreeView->selectionModel(); + connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), + SLOT(coreCurrent(QModelIndex, QModelIndex))); + } + // resource packs + { + ensureFolderPathExists(m_inst->resourcePacksDir()); + m_resourcepacks = m_inst->resourcePackList(); + ui->resPackTreeView->setModel(m_resourcepacks.get()); + ui->resPackTreeView->installEventFilter(this); + m_resourcepacks->startWatching(); + } + + connect(m_inst, &OneSixInstance::versionReloaded, this, + &InstanceEditDialog::updateVersionControls); +} + +InstanceEditDialog::~InstanceEditDialog() +{ + m_mods->stopWatching(); + m_resourcepacks->stopWatching(); + m_coremods->stopWatching(); + delete ui; +} + +void InstanceEditDialog::updateVersionControls() +{ + ui->forgeBtn->setEnabled(true); + ui->liteloaderBtn->setEnabled(true); +} + +void InstanceEditDialog::disableVersionControls() +{ + ui->forgeBtn->setEnabled(false); + ui->liteloaderBtn->setEnabled(false); + ui->reloadLibrariesBtn->setEnabled(false); + ui->removeLibraryBtn->setEnabled(false); +} + +bool InstanceEditDialog::reloadInstanceVersion() +{ + try + { + m_inst->reloadVersion(); + return true; + } + catch (MMCError &e) + { + QMessageBox::critical(this, tr("Error"), e.cause()); + return false; + } + catch (...) + { + QMessageBox::critical( + this, tr("Error"), + tr("Failed to load the version description file for reasons unknown.")); + return false; + } +} + +void InstanceEditDialog::on_settingsBtn_clicked() +{ + InstanceSettings settings(&m_inst->settings(), this); + settings.setWindowTitle(tr("Instance settings")); + settings.exec(); +} + +void InstanceEditDialog::on_reloadLibrariesBtn_clicked() +{ + reloadInstanceVersion(); +} + +void InstanceEditDialog::on_removeLibraryBtn_clicked() +{ + if (ui->libraryTreeView->currentIndex().isValid()) + { + // FIXME: use actual model, not reloading. + if (!m_version->remove(ui->libraryTreeView->currentIndex().row())) + { + QMessageBox::critical(this, tr("Error"), tr("Couldn't remove file")); + } + } +} + +void InstanceEditDialog::on_resetLibraryOrderBtn_clicked() +{ + try + { + m_version->resetOrder(); + } + catch (MMCError &e) + { + QMessageBox::critical(this, tr("Error"), e.cause()); + } +} + +void InstanceEditDialog::on_moveLibraryUpBtn_clicked() +{ + if (ui->libraryTreeView->selectionModel()->selectedRows().isEmpty()) + { + return; + } + try + { + const int row = ui->libraryTreeView->selectionModel()->selectedRows().first().row(); + const int newRow = 0;m_version->move(row, VersionFinal::MoveUp); + //ui->libraryTreeView->selectionModel()->setCurrentIndex(m_version->index(newRow), QItemSelectionModel::ClearAndSelect); + } + catch (MMCError &e) + { + QMessageBox::critical(this, tr("Error"), e.cause()); + } +} + +void InstanceEditDialog::on_moveLibraryDownBtn_clicked() +{ + if (ui->libraryTreeView->selectionModel()->selectedRows().isEmpty()) + { + return; + } + try + { + const int row = ui->libraryTreeView->selectionModel()->selectedRows().first().row(); + const int newRow = 0;m_version->move(row, VersionFinal::MoveDown); + //ui->libraryTreeView->selectionModel()->setCurrentIndex(m_version->index(newRow), QItemSelectionModel::ClearAndSelect); + } + catch (MMCError &e) + { + QMessageBox::critical(this, tr("Error"), e.cause()); + } +} + +// FIXME: use this for legacy forge... or abstract away. +/* +void LegacyModEditDialog::on_addForgeBtn_clicked() +{ + VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this); + vselect.setFilter(1, m_inst->intendedVersionId()); + if (vselect.exec() && vselect.selectedVersion()) + { + ForgeVersionPtr forge = + std::dynamic_pointer_cast(vselect.selectedVersion()); + if (!forge) + return; + auto entry = MMC->metacache()->resolveEntry("minecraftforge", forge->filename); + if (entry->stale) + { + NetJob *fjob = new NetJob("Forge download"); + fjob->addNetAction(CacheDownload::make(forge->universal_url, entry)); + ProgressDialog dlg(this); + dlg.exec(fjob); + if (dlg.result() == QDialog::Accepted) + { + m_jarmods->stopWatching(); + m_jarmods->installMod(QFileInfo(entry->getFullPath())); + m_jarmods->startWatching(); + } + else + { + // failed to download forge :/ + } + } + else + { + m_jarmods->stopWatching(); + m_jarmods->installMod(QFileInfo(entry->getFullPath())); + m_jarmods->startWatching(); + } + } +}*/ + +void InstanceEditDialog::on_changeMCVersionBtn_clicked() +{ + VersionSelectDialog vselect(m_inst->versionList().get(), tr("Change Minecraft version"), this); + if (!vselect.exec() || !vselect.selectedVersion()) + return; + + if (!MMC->accounts()->anyAccountIsValid()) + { + CustomMessageBox::selectable( + this, tr("Error"), + tr("MultiMC cannot download Minecraft or update instances unless you have at least " + "one account added.\nPlease add your Mojang or Minecraft account."), + QMessageBox::Warning)->show(); + return; + } + + if (m_inst->versionIsCustom()) + { + auto result = CustomMessageBox::selectable( + this, tr("Are you sure?"), + tr("This will remove any library/version customization you did previously. " + "This includes things like Forge install and similar."), + QMessageBox::Warning, QMessageBox::Ok | QMessageBox::Abort, + QMessageBox::Abort)->exec(); + + if (result != QMessageBox::Ok) + return; + m_version->revertToVanilla(); + reloadInstanceVersion(); + } + m_inst->setIntendedVersionId(vselect.selectedVersion()->descriptor()); + + auto updateTask = m_inst->doUpdate(); + if (!updateTask) + { + return; + } + ProgressDialog tDialog(this); + connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString))); + tDialog.exec(updateTask.get()); +} + +/* +void MainWindow::on_actionChangeInstLWJGLVersion_triggered() +{ + if (!m_selectedInstance) + return; + + LWJGLSelectDialog lselect(this); + lselect.exec(); + if (lselect.result() == QDialog::Accepted) + { + auto ptr = std::dynamic_pointer_cast(m_selectedInstance); + if(ptr) + ptr->setLWJGLVersion(lselect.selectedVersion()); + } +} +*/ + + +void InstanceEditDialog::on_forgeBtn_clicked() +{ + // FIXME: use actual model, not reloading. Move logic to model. + if (m_version->hasFtbPack()) + { + if (QMessageBox::question(this, tr("Revert?"), + tr("This action will remove the FTB pack version patch. Continue?")) != + QMessageBox::Yes) + { + return; + } + m_version->removeFtbPack(); + reloadInstanceVersion(); + } + if (m_version->usesLegacyCustomJson()) + { + if (QMessageBox::question(this, tr("Revert?"), + tr("This action will remove your custom.json. Continue?")) != + QMessageBox::Yes) + { + return; + } + m_version->revertToVanilla(); + reloadInstanceVersion(); + } + VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this); + vselect.setExactFilter(1, m_inst->currentVersionId()); + vselect.setEmptyString(tr("No Forge versions are currently available for Minecraft ") + + m_inst->currentVersionId()); + if (vselect.exec() && vselect.selectedVersion()) + { + ProgressDialog dialog(this); + dialog.exec(ForgeInstaller().createInstallTask(m_inst, vselect.selectedVersion(), this)); + } +} + +void InstanceEditDialog::on_liteloaderBtn_clicked() +{ + if (m_version->hasFtbPack()) + { + if (QMessageBox::question(this, tr("Revert?"), + tr("This action will remove the FTB pack version patch. Continue?")) != + QMessageBox::Yes) + { + return; + } + m_version->removeFtbPack(); + reloadInstanceVersion(); + } + if (m_version->usesLegacyCustomJson()) + { + if (QMessageBox::question(this, tr("Revert?"), + tr("This action will remove your custom.json. Continue?")) != + QMessageBox::Yes) + { + return; + } + m_version->revertToVanilla(); + reloadInstanceVersion(); + } + VersionSelectDialog vselect(MMC->liteloaderlist().get(), tr("Select LiteLoader version"), + this); + vselect.setExactFilter(1, m_inst->currentVersionId()); + vselect.setEmptyString(tr("No LiteLoader versions are currently available for Minecraft ") + + m_inst->currentVersionId()); + if (vselect.exec() && vselect.selectedVersion()) + { + ProgressDialog dialog(this); + dialog.exec(LiteLoaderInstaller().createInstallTask(m_inst, vselect.selectedVersion(), this)); + } +} + +bool InstanceEditDialog::loaderListFilter(QKeyEvent *keyEvent) +{ + switch (keyEvent->key()) + { + case Qt::Key_Delete: + on_rmModBtn_clicked(); + return true; + case Qt::Key_Plus: + on_addModBtn_clicked(); + return true; + default: + break; + } + return QDialog::eventFilter(ui->loaderModTreeView, keyEvent); +} + +bool InstanceEditDialog::coreListFilter(QKeyEvent *keyEvent) +{ + switch (keyEvent->key()) + { + case Qt::Key_Delete: + on_rmCoreBtn_clicked(); + return true; + case Qt::Key_Plus: + on_addCoreBtn_clicked(); + return true; + default: + break; + } + return QDialog::eventFilter(ui->coreModsTreeView, keyEvent); +} + +bool InstanceEditDialog::resourcePackListFilter(QKeyEvent *keyEvent) +{ + switch (keyEvent->key()) + { + case Qt::Key_Delete: + on_rmResPackBtn_clicked(); + return true; + case Qt::Key_Plus: + on_addResPackBtn_clicked(); + return true; + default: + break; + } + return QDialog::eventFilter(ui->resPackTreeView, keyEvent); +} + +bool InstanceEditDialog::eventFilter(QObject *obj, QEvent *ev) +{ + if (ev->type() != QEvent::KeyPress) + { + return QDialog::eventFilter(obj, ev); + } + QKeyEvent *keyEvent = static_cast(ev); + if (obj == ui->loaderModTreeView) + return loaderListFilter(keyEvent); + if (obj == ui->coreModsTreeView) + return coreListFilter(keyEvent); + if (obj == ui->resPackTreeView) + return resourcePackListFilter(keyEvent); + return QDialog::eventFilter(obj, ev); +} + +void InstanceEditDialog::on_buttonBox_rejected() +{ + close(); +} + +void InstanceEditDialog::on_addModBtn_clicked() +{ + QStringList fileNames = QFileDialog::getOpenFileNames( + this, QApplication::translate("InstanceEditDialog", "Select Loader Mods")); + for (auto filename : fileNames) + { + m_mods->stopWatching(); + m_mods->installMod(QFileInfo(filename)); + m_mods->startWatching(); + } +} +void InstanceEditDialog::on_rmModBtn_clicked() +{ + int first, last; + auto list = ui->loaderModTreeView->selectionModel()->selectedRows(); + + if (!lastfirst(list, first, last)) + return; + m_mods->stopWatching(); + m_mods->deleteMods(first, last); + m_mods->startWatching(); +} +void InstanceEditDialog::on_viewModBtn_clicked() +{ + openDirInDefaultProgram(m_inst->loaderModsDir(), true); +} + +void InstanceEditDialog::on_addCoreBtn_clicked() +{ + //: Title of core mod selection dialog + QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Core Mods")); + for (auto filename : fileNames) + { + m_coremods->stopWatching(); + m_coremods->installMod(QFileInfo(filename)); + m_coremods->startWatching(); + } +} + +void InstanceEditDialog::on_rmCoreBtn_clicked() +{ + int first, last; + auto list = ui->coreModsTreeView->selectionModel()->selectedRows(); + + if (!lastfirst(list, first, last)) + return; + m_coremods->stopWatching(); + m_coremods->deleteMods(first, last); + m_coremods->startWatching(); +} + +void InstanceEditDialog::on_viewCoreBtn_clicked() +{ + openDirInDefaultProgram(m_inst->coreModsDir(), true); +} + +void InstanceEditDialog::on_addResPackBtn_clicked() +{ + QStringList fileNames = QFileDialog::getOpenFileNames( + this, QApplication::translate("InstanceEditDialog", "Select Resource Packs")); + for (auto filename : fileNames) + { + m_resourcepacks->stopWatching(); + m_resourcepacks->installMod(QFileInfo(filename)); + m_resourcepacks->startWatching(); + } +} +void InstanceEditDialog::on_rmResPackBtn_clicked() +{ + int first, last; + auto list = ui->resPackTreeView->selectionModel()->selectedRows(); + + if (!lastfirst(list, first, last)) + return; + m_resourcepacks->stopWatching(); + m_resourcepacks->deleteMods(first, last); + m_resourcepacks->startWatching(); +} +void InstanceEditDialog::on_viewResPackBtn_clicked() +{ + openDirInDefaultProgram(m_inst->resourcePacksDir(), true); +} + +void InstanceEditDialog::loaderCurrent(QModelIndex current, QModelIndex previous) +{ + if (!current.isValid()) + { + ui->frame->clear(); + return; + } + int row = current.row(); + Mod &m = m_mods->operator[](row); + ui->frame->updateWithMod(m); +} + +void InstanceEditDialog::versionCurrent(const QModelIndex ¤t, + const QModelIndex &previous) +{ + if (!current.isValid()) + { + ui->removeLibraryBtn->setDisabled(true); + } + else + { + ui->removeLibraryBtn->setEnabled(m_version->canRemove(current.row())); + } +} + +void InstanceEditDialog::coreCurrent(QModelIndex current, QModelIndex previous) +{ + if (!current.isValid()) + { + ui->coreMIFrame->clear(); + return; + } + int row = current.row(); + Mod &m = m_coremods->operator[](row); + ui->coreMIFrame->updateWithMod(m); +} diff --git a/gui/dialogs/InstanceEditDialog.h b/gui/dialogs/InstanceEditDialog.h new file mode 100644 index 00000000..ea2c6496 --- /dev/null +++ b/gui/dialogs/InstanceEditDialog.h @@ -0,0 +1,97 @@ +/* Copyright 2013 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 + +class EnabledItemFilter; +namespace Ui +{ +class InstanceEditDialog; +} + +class InstanceEditDialog : public QDialog +{ + Q_OBJECT + +public: + explicit InstanceEditDialog(OneSixInstance *inst, QWidget *parent = 0); + virtual ~InstanceEditDialog(); + +private +slots: + + // version tab + void on_forgeBtn_clicked(); + void on_liteloaderBtn_clicked(); + void on_reloadLibrariesBtn_clicked(); + void on_removeLibraryBtn_clicked(); + void on_resetLibraryOrderBtn_clicked(); + void on_settingsBtn_clicked(); + void on_moveLibraryUpBtn_clicked(); + void on_moveLibraryDownBtn_clicked(); + + // loader mod tab + void on_addModBtn_clicked(); + void on_rmModBtn_clicked(); + void on_viewModBtn_clicked(); + + // core mod tab + void on_addCoreBtn_clicked(); + void on_rmCoreBtn_clicked(); + void on_viewCoreBtn_clicked(); + + // resource pack tab + void on_addResPackBtn_clicked(); + void on_rmResPackBtn_clicked(); + void on_viewResPackBtn_clicked(); + + + // Questionable: SettingsDialog doesn't need this for some reason? + void on_buttonBox_rejected(); + + void updateVersionControls(); + void disableVersionControls(); + void on_changeMCVersionBtn_clicked(); + +protected: + bool eventFilter(QObject *obj, QEvent *ev); + bool jarListFilter(QKeyEvent *ev); + bool loaderListFilter(QKeyEvent *ev); + bool coreListFilter(QKeyEvent *ev); + bool resourcePackListFilter(QKeyEvent *ev); + /// FIXME: this shouldn't be necessary! + bool reloadInstanceVersion(); + +private: + Ui::InstanceEditDialog *ui; + std::shared_ptr m_version; + std::shared_ptr m_mods; + std::shared_ptr m_coremods; + std::shared_ptr m_jarmods; + std::shared_ptr m_resourcepacks; + EnabledItemFilter *main_model; + OneSixInstance *m_inst; + NetJobPtr forgeJob; + +public +slots: + void loaderCurrent(QModelIndex current, QModelIndex previous); + void versionCurrent(const QModelIndex ¤t, const QModelIndex &previous); + void coreCurrent(QModelIndex current, QModelIndex previous); +}; diff --git a/gui/dialogs/InstanceEditDialog.ui b/gui/dialogs/InstanceEditDialog.ui new file mode 100644 index 00000000..0ad79833 --- /dev/null +++ b/gui/dialogs/InstanceEditDialog.ui @@ -0,0 +1,404 @@ + + + InstanceEditDialog + + + + 0 + 0 + 593 + 568 + + + + Edit Instance + + + + + + false + + + QDialogButtonBox::Close + + + + + + + true + + + + 0 + 0 + + + + 0 + + + + Version + + + + + + + + Qt::ScrollBarAlwaysOn + + + Qt::ScrollBarAlwaysOff + + + false + + + + + + + + + + + Change version + + + + + + + Replace any current custom version with Minecraft Forge + + + Install Forge + + + + + + + Install LiteLoader + + + + + + + Add jar mod + + + + + + + Qt::Horizontal + + + + + + + Reload + + + + + + + Remove + + + + + + + Qt::Horizontal + + + + + + + This isn't implemented yet. + + + Move up + + + + + + + This isn't implemented yet. + + + Move down + + + + + + + This isn't implemented yet. + + + Reset order + + + + + + + Qt::Horizontal + + + + + + + Settings + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Core Mods + + + + + + + + QAbstractItemView::DropOnly + + + + + + + + + &Add + + + + + + + &Remove + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + &View Folder + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + Loader Mods + + + + + + + + + + + 0 + 0 + + + + true + + + QAbstractItemView::DropOnly + + + + + + + + + + + &Add + + + + + + + &Remove + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + &View Folder + + + + + + + + + + + + 0 + 0 + + + + + + + + + Resource Packs + + + + + + true + + + QAbstractItemView::DropOnly + + + + + + + + + &Add + + + + + + + &Remove + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + &View Folder + + + + + + + + + + + + + + ModListView + QTreeView +
gui/widgets/ModListView.h
+
+ + MCModInfoFrame + QFrame +
gui/widgets/MCModInfoFrame.h
+ 1 +
+
+ + +
diff --git a/gui/dialogs/LegacyModEditDialog.cpp b/gui/dialogs/LegacyModEditDialog.cpp deleted file mode 100644 index e5039c02..00000000 --- a/gui/dialogs/LegacyModEditDialog.cpp +++ /dev/null @@ -1,393 +0,0 @@ -/* Copyright 2013 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 "MultiMC.h" -#include "LegacyModEditDialog.h" -#include "ModEditDialogCommon.h" -#include "VersionSelectDialog.h" -#include "ProgressDialog.h" -#include "ui_LegacyModEditDialog.h" -#include "logic/ModList.h" -#include "logic/lists/ForgeVersionList.h" -#include "gui/Platform.h" - -#include -#include -//#include -#include -#include -#include - -LegacyModEditDialog::LegacyModEditDialog(LegacyInstance *inst, QWidget *parent) - : QDialog(parent), ui(new Ui::LegacyModEditDialog), m_inst(inst) -{ - MultiMCPlatform::fixWM_CLASS(this); - ui->setupUi(this); - - // Jar mods - { - ensureFolderPathExists(m_inst->jarModsDir()); - m_jarmods = m_inst->jarModList(); - ui->jarModsTreeView->setModel(m_jarmods.get()); -#ifndef Q_OS_LINUX - // FIXME: internal DnD causes segfaults later - ui->jarModsTreeView->setDragDropMode(QAbstractItemView::DragDrop); - // FIXME: DnD is glitched with contiguous (we move only first item in selection) - ui->jarModsTreeView->setSelectionMode(QAbstractItemView::SingleSelection); -#endif - ui->jarModsTreeView->installEventFilter(this); - m_jarmods->startWatching(); - auto smodel = ui->jarModsTreeView->selectionModel(); - connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), - SLOT(jarCurrent(QModelIndex, QModelIndex))); - } - // Core mods - { - ensureFolderPathExists(m_inst->coreModsDir()); - m_coremods = m_inst->coreModList(); - ui->coreModsTreeView->setModel(m_coremods.get()); - ui->coreModsTreeView->installEventFilter(this); - m_coremods->startWatching(); - auto smodel = ui->coreModsTreeView->selectionModel(); - connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), - SLOT(coreCurrent(QModelIndex, QModelIndex))); - } - // Loader mods - { - ensureFolderPathExists(m_inst->loaderModsDir()); - m_mods = m_inst->loaderModList(); - ui->loaderModTreeView->setModel(m_mods.get()); - ui->loaderModTreeView->installEventFilter(this); - m_mods->startWatching(); - auto smodel = ui->loaderModTreeView->selectionModel(); - connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), - SLOT(loaderCurrent(QModelIndex, QModelIndex))); - } - // texture packs - { - ensureFolderPathExists(m_inst->texturePacksDir()); - m_texturepacks = m_inst->texturePackList(); - ui->texPackTreeView->setModel(m_texturepacks.get()); - ui->texPackTreeView->installEventFilter(this); - m_texturepacks->startWatching(); - } -} - -LegacyModEditDialog::~LegacyModEditDialog() -{ - m_mods->stopWatching(); - m_coremods->stopWatching(); - m_jarmods->stopWatching(); - m_texturepacks->stopWatching(); - delete ui; -} - -bool LegacyModEditDialog::coreListFilter(QKeyEvent *keyEvent) -{ - switch (keyEvent->key()) - { - case Qt::Key_Delete: - on_rmCoreBtn_clicked(); - return true; - case Qt::Key_Plus: - on_addCoreBtn_clicked(); - return true; - default: - break; - } - return QDialog::eventFilter(ui->coreModsTreeView, keyEvent); -} - -bool LegacyModEditDialog::jarListFilter(QKeyEvent *keyEvent) -{ - switch (keyEvent->key()) - { - case Qt::Key_Up: - { - if (keyEvent->modifiers() & Qt::ControlModifier) - { - on_moveJarUpBtn_clicked(); - return true; - } - break; - } - case Qt::Key_Down: - { - if (keyEvent->modifiers() & Qt::ControlModifier) - { - on_moveJarDownBtn_clicked(); - return true; - } - break; - } - case Qt::Key_Delete: - on_rmJarBtn_clicked(); - return true; - case Qt::Key_Plus: - on_addJarBtn_clicked(); - return true; - default: - break; - } - return QDialog::eventFilter(ui->jarModsTreeView, keyEvent); -} - -bool LegacyModEditDialog::loaderListFilter(QKeyEvent *keyEvent) -{ - switch (keyEvent->key()) - { - case Qt::Key_Delete: - on_rmModBtn_clicked(); - return true; - case Qt::Key_Plus: - on_addModBtn_clicked(); - return true; - default: - break; - } - return QDialog::eventFilter(ui->loaderModTreeView, keyEvent); -} - -bool LegacyModEditDialog::texturePackListFilter(QKeyEvent *keyEvent) -{ - switch (keyEvent->key()) - { - case Qt::Key_Delete: - on_rmTexPackBtn_clicked(); - return true; - case Qt::Key_Plus: - on_addTexPackBtn_clicked(); - return true; - default: - break; - } - return QDialog::eventFilter(ui->texPackTreeView, keyEvent); -} - -bool LegacyModEditDialog::eventFilter(QObject *obj, QEvent *ev) -{ - if (ev->type() != QEvent::KeyPress) - { - return QDialog::eventFilter(obj, ev); - } - QKeyEvent *keyEvent = static_cast(ev); - if (obj == ui->jarModsTreeView) - return jarListFilter(keyEvent); - if (obj == ui->coreModsTreeView) - return coreListFilter(keyEvent); - if (obj == ui->loaderModTreeView) - return loaderListFilter(keyEvent); - if (obj == ui->texPackTreeView) - return texturePackListFilter(keyEvent); - return QDialog::eventFilter(obj, ev); -} - -void LegacyModEditDialog::on_addCoreBtn_clicked() -{ - //: Title of core mod selection dialog - QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Core Mods")); - for (auto filename : fileNames) - { - m_coremods->stopWatching(); - m_coremods->installMod(QFileInfo(filename)); - m_coremods->startWatching(); - } -} -void LegacyModEditDialog::on_addForgeBtn_clicked() -{ - VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this); - vselect.setExactFilter(1, m_inst->intendedVersionId()); - if (vselect.exec() && vselect.selectedVersion()) - { - ForgeVersionPtr forge = - std::dynamic_pointer_cast(vselect.selectedVersion()); - if (!forge) - return; - auto entry = MMC->metacache()->resolveEntry("minecraftforge", forge->filename); - if (entry->stale) - { - NetJob *fjob = new NetJob("Forge download"); - fjob->addNetAction(CacheDownload::make(forge->universal_url, entry)); - ProgressDialog dlg(this); - dlg.exec(fjob); - if (dlg.result() == QDialog::Accepted) - { - m_jarmods->stopWatching(); - m_jarmods->installMod(QFileInfo(entry->getFullPath())); - m_jarmods->startWatching(); - } - else - { - // failed to download forge :/ - } - } - else - { - m_jarmods->stopWatching(); - m_jarmods->installMod(QFileInfo(entry->getFullPath())); - m_jarmods->startWatching(); - } - } -} -void LegacyModEditDialog::on_addJarBtn_clicked() -{ - //: Title of jar mod selection dialog - QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Jar Mods")); - for (auto filename : fileNames) - { - m_jarmods->stopWatching(); - m_jarmods->installMod(QFileInfo(filename)); - m_jarmods->startWatching(); - } -} -void LegacyModEditDialog::on_addModBtn_clicked() -{ - //: Title of regular mod selection dialog - QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Loader Mods")); - for (auto filename : fileNames) - { - m_mods->stopWatching(); - m_mods->installMod(QFileInfo(filename)); - m_mods->startWatching(); - } -} -void LegacyModEditDialog::on_addTexPackBtn_clicked() -{ - //: Title of texture pack selection dialog - QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Texture Packs")); - for (auto filename : fileNames) - { - m_texturepacks->stopWatching(); - m_texturepacks->installMod(QFileInfo(filename)); - m_texturepacks->startWatching(); - } -} - -void LegacyModEditDialog::on_moveJarDownBtn_clicked() -{ - int first, last; - auto list = ui->jarModsTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - - m_jarmods->moveModsDown(first, last); -} -void LegacyModEditDialog::on_moveJarUpBtn_clicked() -{ - int first, last; - auto list = ui->jarModsTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - m_jarmods->moveModsUp(first, last); -} -void LegacyModEditDialog::on_rmCoreBtn_clicked() -{ - int first, last; - auto list = ui->coreModsTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - m_coremods->stopWatching(); - m_coremods->deleteMods(first, last); - m_coremods->startWatching(); -} -void LegacyModEditDialog::on_rmJarBtn_clicked() -{ - int first, last; - auto list = ui->jarModsTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - m_jarmods->stopWatching(); - m_jarmods->deleteMods(first, last); - m_jarmods->startWatching(); -} -void LegacyModEditDialog::on_rmModBtn_clicked() -{ - int first, last; - auto list = ui->loaderModTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - m_mods->stopWatching(); - m_mods->deleteMods(first, last); - m_mods->startWatching(); -} -void LegacyModEditDialog::on_rmTexPackBtn_clicked() -{ - int first, last; - auto list = ui->texPackTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - m_texturepacks->stopWatching(); - m_texturepacks->deleteMods(first, last); - m_texturepacks->startWatching(); -} -void LegacyModEditDialog::on_viewCoreBtn_clicked() -{ - openDirInDefaultProgram(m_inst->coreModsDir(), true); -} -void LegacyModEditDialog::on_viewModBtn_clicked() -{ - openDirInDefaultProgram(m_inst->loaderModsDir(), true); -} -void LegacyModEditDialog::on_viewTexPackBtn_clicked() -{ - openDirInDefaultProgram(m_inst->texturePacksDir(), true); -} - -void LegacyModEditDialog::on_buttonBox_rejected() -{ - close(); -} - -void LegacyModEditDialog::jarCurrent(QModelIndex current, QModelIndex previous) -{ - if (!current.isValid()) - { - ui->jarMIFrame->clear(); - return; - } - int row = current.row(); - Mod &m = m_jarmods->operator[](row); - ui->jarMIFrame->updateWithMod(m); -} - -void LegacyModEditDialog::coreCurrent(QModelIndex current, QModelIndex previous) -{ - if (!current.isValid()) - { - ui->coreMIFrame->clear(); - return; - } - int row = current.row(); - Mod &m = m_coremods->operator[](row); - ui->coreMIFrame->updateWithMod(m); -} - -void LegacyModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previous) -{ - if (!current.isValid()) - { - ui->loaderMIFrame->clear(); - return; - } - int row = current.row(); - Mod &m = m_mods->operator[](row); - ui->loaderMIFrame->updateWithMod(m); -} diff --git a/gui/dialogs/LegacyModEditDialog.h b/gui/dialogs/LegacyModEditDialog.h deleted file mode 100644 index d5582aef..00000000 --- a/gui/dialogs/LegacyModEditDialog.h +++ /dev/null @@ -1,78 +0,0 @@ -/* Copyright 2013 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 "logic/LegacyInstance.h" -#include - -namespace Ui -{ -class LegacyModEditDialog; -} - -class LegacyModEditDialog : public QDialog -{ - Q_OBJECT - -public: - explicit LegacyModEditDialog(LegacyInstance *inst, QWidget *parent = 0); - ~LegacyModEditDialog(); - -private -slots: - - void on_addJarBtn_clicked(); - void on_rmJarBtn_clicked(); - void on_addForgeBtn_clicked(); - void on_moveJarUpBtn_clicked(); - void on_moveJarDownBtn_clicked(); - - void on_addCoreBtn_clicked(); - void on_rmCoreBtn_clicked(); - void on_viewCoreBtn_clicked(); - - void on_addModBtn_clicked(); - void on_rmModBtn_clicked(); - void on_viewModBtn_clicked(); - - void on_addTexPackBtn_clicked(); - void on_rmTexPackBtn_clicked(); - void on_viewTexPackBtn_clicked(); - - // Questionable: SettingsDialog doesn't need this for some reason? - void on_buttonBox_rejected(); - - void jarCurrent(QModelIndex current, QModelIndex previous); - void coreCurrent(QModelIndex current, QModelIndex previous); - void loaderCurrent(QModelIndex current, QModelIndex previous); - -protected: - bool eventFilter(QObject *obj, QEvent *ev); - bool jarListFilter(QKeyEvent *ev); - bool coreListFilter(QKeyEvent *ev); - bool loaderListFilter(QKeyEvent *ev); - bool texturePackListFilter(QKeyEvent *ev); - -private: - Ui::LegacyModEditDialog *ui; - std::shared_ptr m_mods; - std::shared_ptr m_coremods; - std::shared_ptr m_jarmods; - std::shared_ptr m_texturepacks; - LegacyInstance *m_inst; - NetJobPtr forgeJob; -}; diff --git a/gui/dialogs/LegacyModEditDialog.ui b/gui/dialogs/LegacyModEditDialog.ui deleted file mode 100644 index 0662c712..00000000 --- a/gui/dialogs/LegacyModEditDialog.ui +++ /dev/null @@ -1,321 +0,0 @@ - - - LegacyModEditDialog - - - - 0 - 0 - 540 - 420 - - - - Edit Mods - - - - - - 0 - - - - Jar Mods - - - - - - - - Qt::ScrollBarAlwaysOn - - - Qt::ScrollBarAlwaysOff - - - - - - - - - &Add - - - - - - - &Remove - - - - - - - MCForge - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Move &Up - - - - - - - Move &Down - - - - - - - - - - - QFrame::Plain - - - - - - - - Core Mods - - - - - - - - QAbstractItemView::DropOnly - - - - - - - - - &Add - - - - - - - &Remove - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - &View Folder - - - - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - - Loader Mods - - - - - - - - true - - - QAbstractItemView::DropOnly - - - - - - - - - &Add - - - - - - - &Remove - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - &View Folder - - - - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - - false - - - Texture Packs - - - - - - true - - - QAbstractItemView::DropOnly - - - - - - - - - &Add - - - - - - - &Remove - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - &View Folder - - - - - - - - - - - - - QDialogButtonBox::Close - - - - - - - - ModListView - QTreeView -
gui/widgets/ModListView.h
-
- - MCModInfoFrame - QFrame -
gui/widgets/MCModInfoFrame.h
- 1 -
-
- - -
diff --git a/gui/dialogs/ModEditDialogCommon.cpp b/gui/dialogs/ModEditDialogCommon.cpp deleted file mode 100644 index eee42e5e..00000000 --- a/gui/dialogs/ModEditDialogCommon.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* Copyright 2013 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 "ModEditDialogCommon.h" -#include "CustomMessageBox.h" -#include -#include -#include -#include -bool lastfirst(QModelIndexList &list, int &first, int &last) -{ - if (!list.size()) - return false; - first = last = list[0].row(); - for (auto item : list) - { - int row = item.row(); - if (row < first) - first = row; - if (row > last) - last = row; - } - return true; -} - -void showWebsiteForMod(QWidget *parentDlg, Mod &m) -{ - QString url = m.homeurl(); - if (url.size()) - { - // catch the cases where the protocol is missing - if (!url.startsWith("http")) - { - url = "http://" + url; - } - QDesktopServices::openUrl(url); - } - else - { - CustomMessageBox::selectable( - parentDlg, QObject::tr("How sad!"), - QObject::tr("The mod author didn't provide a website link for this mod."), - QMessageBox::Warning); - } -} diff --git a/gui/dialogs/ModEditDialogCommon.h b/gui/dialogs/ModEditDialogCommon.h deleted file mode 100644 index a226d5a9..00000000 --- a/gui/dialogs/ModEditDialogCommon.h +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright 2013 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 - -bool lastfirst(QModelIndexList &list, int &first, int &last); - -void showWebsiteForMod(QWidget *parentDlg, Mod &m); \ No newline at end of file diff --git a/gui/dialogs/OneSixModEditDialog.cpp b/gui/dialogs/OneSixModEditDialog.cpp deleted file mode 100644 index a3598eb9..00000000 --- a/gui/dialogs/OneSixModEditDialog.cpp +++ /dev/null @@ -1,399 +0,0 @@ -/* Copyright 2013 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 "MultiMC.h" - -#include -#include -#include -#include -#include -#include -#include - -#include "OneSixModEditDialog.h" -#include "ModEditDialogCommon.h" -#include "ui_OneSixModEditDialog.h" - -#include "gui/Platform.h" -#include "gui/dialogs/CustomMessageBox.h" -#include "gui/dialogs/VersionSelectDialog.h" - -#include "gui/dialogs/ProgressDialog.h" - -#include "logic/ModList.h" -#include "logic/VersionFinal.h" -#include "logic/EnabledItemFilter.h" -#include "logic/lists/ForgeVersionList.h" -#include "logic/lists/LiteLoaderVersionList.h" -#include "logic/ForgeInstaller.h" -#include "logic/LiteLoaderInstaller.h" -#include "logic/OneSixVersionBuilder.h" - -OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent) - : QDialog(parent), ui(new Ui::OneSixModEditDialog), m_inst(inst) -{ - MultiMCPlatform::fixWM_CLASS(this); - ui->setupUi(this); - // libraries! - - m_version = m_inst->getFullVersion(); - if (m_version) - { - main_model = new EnabledItemFilter(this); - main_model->setActive(true); - main_model->setSourceModel(m_version.get()); - ui->libraryTreeView->setModel(main_model); - ui->libraryTreeView->installEventFilter(this); - connect(ui->libraryTreeView->selectionModel(), &QItemSelectionModel::currentChanged, - this, &OneSixModEditDialog::versionCurrent); - updateVersionControls(); - } - else - { - disableVersionControls(); - } - // Loader mods - { - ensureFolderPathExists(m_inst->loaderModsDir()); - m_mods = m_inst->loaderModList(); - ui->loaderModTreeView->setModel(m_mods.get()); - ui->loaderModTreeView->installEventFilter(this); - m_mods->startWatching(); - auto smodel = ui->loaderModTreeView->selectionModel(); - connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), - SLOT(loaderCurrent(QModelIndex, QModelIndex))); - } - // resource packs - { - ensureFolderPathExists(m_inst->resourcePacksDir()); - m_resourcepacks = m_inst->resourcePackList(); - ui->resPackTreeView->setModel(m_resourcepacks.get()); - ui->resPackTreeView->installEventFilter(this); - m_resourcepacks->startWatching(); - } - - connect(m_inst, &OneSixInstance::versionReloaded, this, - &OneSixModEditDialog::updateVersionControls); -} - -OneSixModEditDialog::~OneSixModEditDialog() -{ - m_mods->stopWatching(); - m_resourcepacks->stopWatching(); - delete ui; -} - -void OneSixModEditDialog::updateVersionControls() -{ - ui->forgeBtn->setEnabled(true); - ui->liteloaderBtn->setEnabled(true); -} - -void OneSixModEditDialog::disableVersionControls() -{ - ui->forgeBtn->setEnabled(false); - ui->liteloaderBtn->setEnabled(false); - ui->reloadLibrariesBtn->setEnabled(false); - ui->removeLibraryBtn->setEnabled(false); -} - -bool OneSixModEditDialog::reloadInstanceVersion() -{ - try - { - m_inst->reloadVersion(); - return true; - } - catch (MMCError &e) - { - QMessageBox::critical(this, tr("Error"), e.cause()); - return false; - } - catch (...) - { - QMessageBox::critical( - this, tr("Error"), - tr("Failed to load the version description file for reasons unknown.")); - return false; - } -} - -void OneSixModEditDialog::on_reloadLibrariesBtn_clicked() -{ - reloadInstanceVersion(); -} - -void OneSixModEditDialog::on_removeLibraryBtn_clicked() -{ - if (ui->libraryTreeView->currentIndex().isValid()) - { - // FIXME: use actual model, not reloading. - if (!m_version->remove(ui->libraryTreeView->currentIndex().row())) - { - QMessageBox::critical(this, tr("Error"), tr("Couldn't remove file")); - } - } -} - -void OneSixModEditDialog::on_resetLibraryOrderBtn_clicked() -{ - try - { - m_version->resetOrder(); - } - catch (MMCError &e) - { - QMessageBox::critical(this, tr("Error"), e.cause()); - } -} - -void OneSixModEditDialog::on_moveLibraryUpBtn_clicked() -{ - if (ui->libraryTreeView->selectionModel()->selectedRows().isEmpty()) - { - return; - } - try - { - const int row = ui->libraryTreeView->selectionModel()->selectedRows().first().row(); - const int newRow = 0;m_version->move(row, VersionFinal::MoveUp); - //ui->libraryTreeView->selectionModel()->setCurrentIndex(m_version->index(newRow), QItemSelectionModel::ClearAndSelect); - } - catch (MMCError &e) - { - QMessageBox::critical(this, tr("Error"), e.cause()); - } -} - -void OneSixModEditDialog::on_moveLibraryDownBtn_clicked() -{ - if (ui->libraryTreeView->selectionModel()->selectedRows().isEmpty()) - { - return; - } - try - { - const int row = ui->libraryTreeView->selectionModel()->selectedRows().first().row(); - const int newRow = 0;m_version->move(row, VersionFinal::MoveDown); - //ui->libraryTreeView->selectionModel()->setCurrentIndex(m_version->index(newRow), QItemSelectionModel::ClearAndSelect); - } - catch (MMCError &e) - { - QMessageBox::critical(this, tr("Error"), e.cause()); - } -} - -void OneSixModEditDialog::on_forgeBtn_clicked() -{ - // FIXME: use actual model, not reloading. Move logic to model. - if (m_version->hasFtbPack()) - { - if (QMessageBox::question(this, tr("Revert?"), - tr("This action will remove the FTB pack version patch. Continue?")) != - QMessageBox::Yes) - { - return; - } - m_version->removeFtbPack(); - reloadInstanceVersion(); - } - if (m_version->isCustom()) - { - if (QMessageBox::question(this, tr("Revert?"), - tr("This action will remove your custom.json. Continue?")) != - QMessageBox::Yes) - { - return; - } - m_version->revertToBase(); - reloadInstanceVersion(); - } - VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this); - vselect.setExactFilter(1, m_inst->currentVersionId()); - vselect.setEmptyString(tr("No Forge versions are currently available for Minecraft ") + - m_inst->currentVersionId()); - if (vselect.exec() && vselect.selectedVersion()) - { - ProgressDialog dialog(this); - dialog.exec(ForgeInstaller().createInstallTask(m_inst, vselect.selectedVersion(), this)); - } -} - -void OneSixModEditDialog::on_liteloaderBtn_clicked() -{ - if (m_version->hasFtbPack()) - { - if (QMessageBox::question(this, tr("Revert?"), - tr("This action will remove the FTB pack version patch. Continue?")) != - QMessageBox::Yes) - { - return; - } - m_version->removeFtbPack(); - reloadInstanceVersion(); - } - if (m_version->isCustom()) - { - if (QMessageBox::question(this, tr("Revert?"), - tr("This action will remove your custom.json. Continue?")) != - QMessageBox::Yes) - { - return; - } - m_version->revertToBase(); - reloadInstanceVersion(); - } - VersionSelectDialog vselect(MMC->liteloaderlist().get(), tr("Select LiteLoader version"), - this); - vselect.setExactFilter(1, m_inst->currentVersionId()); - vselect.setEmptyString(tr("No LiteLoader versions are currently available for Minecraft ") + - m_inst->currentVersionId()); - if (vselect.exec() && vselect.selectedVersion()) - { - ProgressDialog dialog(this); - dialog.exec(LiteLoaderInstaller().createInstallTask(m_inst, vselect.selectedVersion(), this)); - } -} - -bool OneSixModEditDialog::loaderListFilter(QKeyEvent *keyEvent) -{ - switch (keyEvent->key()) - { - case Qt::Key_Delete: - on_rmModBtn_clicked(); - return true; - case Qt::Key_Plus: - on_addModBtn_clicked(); - return true; - default: - break; - } - return QDialog::eventFilter(ui->loaderModTreeView, keyEvent); -} - -bool OneSixModEditDialog::resourcePackListFilter(QKeyEvent *keyEvent) -{ - switch (keyEvent->key()) - { - case Qt::Key_Delete: - on_rmResPackBtn_clicked(); - return true; - case Qt::Key_Plus: - on_addResPackBtn_clicked(); - return true; - default: - break; - } - return QDialog::eventFilter(ui->resPackTreeView, keyEvent); -} - -bool OneSixModEditDialog::eventFilter(QObject *obj, QEvent *ev) -{ - if (ev->type() != QEvent::KeyPress) - { - return QDialog::eventFilter(obj, ev); - } - QKeyEvent *keyEvent = static_cast(ev); - if (obj == ui->loaderModTreeView) - return loaderListFilter(keyEvent); - if (obj == ui->resPackTreeView) - return resourcePackListFilter(keyEvent); - return QDialog::eventFilter(obj, ev); -} - -void OneSixModEditDialog::on_buttonBox_rejected() -{ - close(); -} - -void OneSixModEditDialog::on_addModBtn_clicked() -{ - QStringList fileNames = QFileDialog::getOpenFileNames( - this, QApplication::translate("LegacyModEditDialog", "Select Loader Mods")); - for (auto filename : fileNames) - { - m_mods->stopWatching(); - m_mods->installMod(QFileInfo(filename)); - m_mods->startWatching(); - } -} -void OneSixModEditDialog::on_rmModBtn_clicked() -{ - int first, last; - auto list = ui->loaderModTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - m_mods->stopWatching(); - m_mods->deleteMods(first, last); - m_mods->startWatching(); -} -void OneSixModEditDialog::on_viewModBtn_clicked() -{ - openDirInDefaultProgram(m_inst->loaderModsDir(), true); -} - -void OneSixModEditDialog::on_addResPackBtn_clicked() -{ - QStringList fileNames = QFileDialog::getOpenFileNames( - this, QApplication::translate("LegacyModEditDialog", "Select Resource Packs")); - for (auto filename : fileNames) - { - m_resourcepacks->stopWatching(); - m_resourcepacks->installMod(QFileInfo(filename)); - m_resourcepacks->startWatching(); - } -} -void OneSixModEditDialog::on_rmResPackBtn_clicked() -{ - int first, last; - auto list = ui->resPackTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - m_resourcepacks->stopWatching(); - m_resourcepacks->deleteMods(first, last); - m_resourcepacks->startWatching(); -} -void OneSixModEditDialog::on_viewResPackBtn_clicked() -{ - openDirInDefaultProgram(m_inst->resourcePacksDir(), true); -} - -void OneSixModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previous) -{ - if (!current.isValid()) - { - ui->frame->clear(); - return; - } - int row = current.row(); - Mod &m = m_mods->operator[](row); - ui->frame->updateWithMod(m); -} - -void OneSixModEditDialog::versionCurrent(const QModelIndex ¤t, - const QModelIndex &previous) -{ - if (!current.isValid()) - { - ui->removeLibraryBtn->setDisabled(true); - } - else - { - ui->removeLibraryBtn->setEnabled(m_version->canRemove(current.row())); - } -} diff --git a/gui/dialogs/OneSixModEditDialog.h b/gui/dialogs/OneSixModEditDialog.h deleted file mode 100644 index e106c6fe..00000000 --- a/gui/dialogs/OneSixModEditDialog.h +++ /dev/null @@ -1,75 +0,0 @@ -/* Copyright 2013 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 - -class EnabledItemFilter; -namespace Ui -{ -class OneSixModEditDialog; -} - -class OneSixModEditDialog : public QDialog -{ - Q_OBJECT - -public: - explicit OneSixModEditDialog(OneSixInstance *inst, QWidget *parent = 0); - virtual ~OneSixModEditDialog(); - -private -slots: - void on_addModBtn_clicked(); - void on_rmModBtn_clicked(); - void on_viewModBtn_clicked(); - - void on_addResPackBtn_clicked(); - void on_rmResPackBtn_clicked(); - void on_viewResPackBtn_clicked(); - // Questionable: SettingsDialog doesn't need this for some reason? - void on_buttonBox_rejected(); - void on_forgeBtn_clicked(); - void on_liteloaderBtn_clicked(); - void on_reloadLibrariesBtn_clicked(); - void on_removeLibraryBtn_clicked(); - void on_resetLibraryOrderBtn_clicked(); - void on_moveLibraryUpBtn_clicked(); - void on_moveLibraryDownBtn_clicked(); - void updateVersionControls(); - void disableVersionControls(); - -protected: - bool eventFilter(QObject *obj, QEvent *ev); - bool loaderListFilter(QKeyEvent *ev); - bool resourcePackListFilter(QKeyEvent *ev); - /// FIXME: this shouldn't be necessary! - bool reloadInstanceVersion(); - -private: - Ui::OneSixModEditDialog *ui; - std::shared_ptr m_version; - std::shared_ptr m_mods; - std::shared_ptr m_resourcepacks; - EnabledItemFilter *main_model; - OneSixInstance *m_inst; - -public -slots: - void loaderCurrent(QModelIndex current, QModelIndex previous); - void versionCurrent(const QModelIndex ¤t, const QModelIndex &previous); -}; diff --git a/gui/dialogs/OneSixModEditDialog.ui b/gui/dialogs/OneSixModEditDialog.ui deleted file mode 100644 index 2c9f70bb..00000000 --- a/gui/dialogs/OneSixModEditDialog.ui +++ /dev/null @@ -1,310 +0,0 @@ - - - OneSixModEditDialog - - - - 0 - 0 - 555 - 463 - - - - Manage Mods - - - - - - true - - - - 0 - 0 - - - - 0 - - - - Version - - - - - - - - Qt::ScrollBarAlwaysOn - - - Qt::ScrollBarAlwaysOff - - - false - - - - - - - - - - - Replace any current custom version with Minecraft Forge - - - Install Forge - - - - - - - Install LiteLoader - - - - - - - Qt::Horizontal - - - - - - - Reload - - - - - - - Remove - - - - - - - Qt::Horizontal - - - - - - - This isn't implemented yet. - - - Move up - - - - - - - This isn't implemented yet. - - - Move down - - - - - - - This isn't implemented yet. - - - Reset order - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - Loader Mods - - - - - - - - - - - 0 - 0 - - - - true - - - QAbstractItemView::DropOnly - - - - - - - - - - - &Add - - - - - - - &Remove - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - &View Folder - - - - - - - - - - - - 0 - 0 - - - - - - - - - Resource Packs - - - - - - true - - - QAbstractItemView::DropOnly - - - - - - - - - &Add - - - - - - - &Remove - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - &View Folder - - - - - - - - - - - - - false - - - QDialogButtonBox::Close - - - - - - - - ModListView - QTreeView -
gui/widgets/ModListView.h
-
- - MCModInfoFrame - QFrame -
gui/widgets/MCModInfoFrame.h
- 1 -
-
- - -
diff --git a/logic/BaseInstaller.h b/logic/BaseInstaller.h index d59833cc..9531fbff 100644 --- a/logic/BaseInstaller.h +++ b/logic/BaseInstaller.h @@ -29,7 +29,7 @@ class BaseInstaller { public: BaseInstaller(); - + virtual ~BaseInstaller(){}; bool isApplied(OneSixInstance *on); virtual bool add(OneSixInstance *to); diff --git a/logic/BaseVersion.h b/logic/BaseVersion.h index 43f5942a..ed63f551 100644 --- a/logic/BaseVersion.h +++ b/logic/BaseVersion.h @@ -16,6 +16,8 @@ #pragma once #include +#include +#include /*! * An abstract base class for versions. @@ -52,4 +54,4 @@ struct BaseVersion typedef std::shared_ptr BaseVersionPtr; -Q_DECLARE_METATYPE(BaseVersionPtr) \ No newline at end of file +Q_DECLARE_METATYPE(BaseVersionPtr) diff --git a/logic/ForgeInstaller.cpp b/logic/ForgeInstaller.cpp deleted file mode 100644 index 94b3f319..00000000 --- a/logic/ForgeInstaller.cpp +++ /dev/null @@ -1,328 +0,0 @@ -/* Copyright 2013 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 "ForgeInstaller.h" -#include "VersionFinal.h" -#include "OneSixLibrary.h" -#include "net/HttpMetaCache.h" -#include -#include -#include -#include -#include -#include -#include "MultiMC.h" -#include "tasks/Task.h" -#include "OneSixInstance.h" -#include "lists/ForgeVersionList.h" -#include "gui/dialogs/ProgressDialog.h" - -#include -#include -#include -#include - -ForgeInstaller::ForgeInstaller() - : BaseInstaller() -{ -} -void ForgeInstaller::prepare(const QString &filename, const QString &universalUrl) -{ - std::shared_ptr newVersion; - m_universal_url = universalUrl; - - QuaZip zip(filename); - if (!zip.open(QuaZip::mdUnzip)) - return; - - QuaZipFile file(&zip); - - // read the install profile - if (!zip.setCurrentFile("install_profile.json")) - return; - - QJsonParseError jsonError; - if (!file.open(QIODevice::ReadOnly)) - return; - QJsonDocument jsonDoc = QJsonDocument::fromJson(file.readAll(), &jsonError); - file.close(); - if (jsonError.error != QJsonParseError::NoError) - return; - - if (!jsonDoc.isObject()) - return; - - QJsonObject root = jsonDoc.object(); - - auto installVal = root.value("install"); - auto versionInfoVal = root.value("versionInfo"); - if (!installVal.isObject() || !versionInfoVal.isObject()) - return; - - // read the forge version info - { - newVersion = VersionFinal::fromJson(versionInfoVal.toObject()); - if (!newVersion) - return; - } - - QJsonObject installObj = installVal.toObject(); - QString libraryName = installObj.value("path").toString(); - internalPath = installObj.value("filePath").toString(); - m_forgeVersionString = installObj.value("version").toString().remove("Forge").trimmed(); - - // where do we put the library? decode the mojang path - OneSixLibrary lib(libraryName); - lib.finalize(); - - auto cacheentry = MMC->metacache()->resolveEntry("libraries", lib.storagePath()); - finalPath = "libraries/" + lib.storagePath(); - if (!ensureFilePathExists(finalPath)) - return; - - if (!zip.setCurrentFile(internalPath)) - return; - if (!file.open(QIODevice::ReadOnly)) - return; - { - QByteArray data = file.readAll(); - // extract file - QSaveFile extraction(finalPath); - if (!extraction.open(QIODevice::WriteOnly)) - return; - if (extraction.write(data) != data.size()) - return; - if (!extraction.commit()) - return; - QCryptographicHash md5sum(QCryptographicHash::Md5); - md5sum.addData(data); - - cacheentry->stale = false; - cacheentry->md5sum = md5sum.result().toHex().constData(); - MMC->metacache()->updateEntry(cacheentry); - } - file.close(); - - m_forge_version = newVersion; - realVersionId = m_forge_version->id = installObj.value("minecraft").toString(); -} -bool ForgeInstaller::add(OneSixInstance *to) -{ - if (!BaseInstaller::add(to)) - { - return false; - } - - QJsonObject obj; - obj.insert("order", 5); - - if (!m_forge_version) - return false; - int sliding_insert_window = 0; - { - QJsonArray librariesPlus; - - // for each library in the version we are adding (except for the blacklisted) - QSet blacklist{"lwjgl", "lwjgl_util", "lwjgl-platform"}; - for (auto lib : m_forge_version->libraries) - { - QString libName = lib->name(); - // WARNING: This could actually break. - // if this is the actual forge lib, set an absolute url for the download - if (libName.contains("minecraftforge")) - { - lib->setAbsoluteUrl(m_universal_url); - } - else if (libName.contains("scala")) - { - lib->setHint("forge-pack-xz"); - } - if (blacklist.contains(libName)) - continue; - - QJsonObject libObj = lib->toJson(); - - bool found = false; - bool equals = false; - // find an entry that matches this one - for (auto tolib : to->getVanillaVersion()->libraries) - { - if (tolib->name() != libName) - continue; - found = true; - if (tolib->toJson() == libObj) - { - equals = true; - } - // replace lib - libObj.insert("insert", QString("replace")); - break; - } - if (equals) - { - continue; - } - if (!found) - { - // add lib - libObj.insert("insert", QString("prepend")); - if (lib->name() == "minecraftforge") - { - libObj.insert("MMC-depend", QString("hard")); - } - sliding_insert_window++; - } - librariesPlus.prepend(libObj); - } - obj.insert("+libraries", librariesPlus); - obj.insert("mainClass", m_forge_version->mainClass); - QString args = m_forge_version->minecraftArguments; - QStringList tweakers; - { - QRegularExpression expression("--tweakClass ([a-zA-Z0-9\\.]*)"); - QRegularExpressionMatch match = expression.match(args); - while (match.hasMatch()) - { - tweakers.append(match.captured(1)); - args.remove(match.capturedStart(), match.capturedLength()); - match = expression.match(args); - } - } - if (!args.isEmpty() && args != to->getVanillaVersion()->minecraftArguments) - { - obj.insert("minecraftArguments", args); - } - if (!tweakers.isEmpty()) - { - obj.insert("+tweakers", QJsonArray::fromStringList(tweakers)); - } - if (!m_forge_version->processArguments.isEmpty() && - m_forge_version->processArguments != to->getVanillaVersion()->processArguments) - { - obj.insert("processArguments", m_forge_version->processArguments); - } - } - - obj.insert("name", QString("Forge")); - obj.insert("fileId", id()); - obj.insert("version", m_forgeVersionString); - obj.insert("mcVersion", to->intendedVersionId()); - - QFile file(filename(to->instanceRoot())); - if (!file.open(QFile::WriteOnly)) - { - QLOG_ERROR() << "Error opening" << file.fileName() - << "for reading:" << file.errorString(); - return false; - } - file.write(QJsonDocument(obj).toJson()); - file.close(); - - return true; -} - -class ForgeInstallTask : public Task -{ - Q_OBJECT -public: - ForgeInstallTask(ForgeInstaller *installer, OneSixInstance *instance, BaseVersionPtr version, QObject *parent = 0) - : Task(parent), m_installer(installer), m_instance(instance), m_version(version) - { - } - -protected: - void executeTask() override - { - { - setStatus(tr("Installing forge...")); - ForgeVersionPtr forgeVersion = - std::dynamic_pointer_cast(m_version); - if (!forgeVersion) - { - emitFailed(tr("Unknown error occured")); - return; - } - auto entry = MMC->metacache()->resolveEntry("minecraftforge", forgeVersion->filename); - if (entry->stale) - { - NetJob *fjob = new NetJob("Forge download"); - fjob->addNetAction(CacheDownload::make(forgeVersion->installer_url, entry)); - connect(fjob, &NetJob::progress, [this](qint64 current, qint64 total){setProgress(100 * current / qMax((qint64)1, total));}); - connect(fjob, &NetJob::status, [this](const QString &msg){setStatus(msg);}); - connect(fjob, &NetJob::failed, [this](){emitFailed(tr("Failure to download forge"));}); - connect(fjob, &NetJob::succeeded, [this, entry, forgeVersion]() - { - if (!install(entry, forgeVersion)) - { - QLOG_ERROR() << "Failure installing forge"; - emitFailed(tr("Failure to install forge")); - } - else - { - reload(); - } - }); - fjob->start(); - } - else - { - if (!install(entry, forgeVersion)) - { - QLOG_ERROR() << "Failure installing forge"; - emitFailed(tr("Failure to install forge")); - } - else - { - reload(); - } - } - } - } - - bool install(const std::shared_ptr &entry, const ForgeVersionPtr &forgeVersion) - { - QString forgePath = entry->getFullPath(); - m_installer->prepare(forgePath, forgeVersion->universal_url); - return m_installer->add(m_instance); - } - void reload() - { - try - { - m_instance->reloadVersion(); - emitSucceeded(); - } - catch (MMCError &e) - { - emitFailed(e.cause()); - } - catch (...) - { - emitFailed(tr("Failed to load the version description file for reasons unknown.")); - } - } - -private: - ForgeInstaller *m_installer; - OneSixInstance *m_instance; - BaseVersionPtr m_version; -}; - -ProgressProvider *ForgeInstaller::createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent) -{ - return new ForgeInstallTask(this, instance, version, parent); -} - -#include "ForgeInstaller.moc" diff --git a/logic/ForgeInstaller.h b/logic/ForgeInstaller.h deleted file mode 100644 index 05cc994b..00000000 --- a/logic/ForgeInstaller.h +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright 2013 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 "BaseInstaller.h" - -#include -#include - -class VersionFinal; - -class ForgeInstaller : public BaseInstaller -{ -public: - ForgeInstaller(); - - void prepare(const QString &filename, const QString &universalUrl); - bool add(OneSixInstance *to) override; - - QString id() const override { return "net.minecraftforge"; } - - ProgressProvider *createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent) override; - -private: - // the version, read from the installer - std::shared_ptr m_forge_version; - QString internalPath; - QString finalPath; - QString realVersionId; - QString m_forgeVersionString; - QString m_universal_url; -}; diff --git a/logic/InstanceFactory.cpp b/logic/InstanceFactory.cpp index 95fd855b..955a3f5b 100644 --- a/logic/InstanceFactory.cpp +++ b/logic/InstanceFactory.cpp @@ -23,7 +23,6 @@ #include "LegacyFTBInstance.h" #include "OneSixInstance.h" #include "OneSixFTBInstance.h" -#include "NostalgiaInstance.h" #include "OneSixInstance.h" #include "BaseVersion.h" #include "MinecraftVersion.h" @@ -51,7 +50,7 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(InstancePtr &inst, QString inst_type = m_settings->get("InstanceType").toString(); // FIXME: replace with a map lookup, where instance classes register their types - if (inst_type == "OneSix") + if (inst_type == "OneSix" || inst_type == "Nostalgia") { inst.reset(new OneSixInstance(instDir, m_settings, this)); } @@ -59,10 +58,6 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(InstancePtr &inst, { inst.reset(new LegacyInstance(instDir, m_settings, this)); } - else if (inst_type == "Nostalgia") - { - inst.reset(new NostalgiaInstance(instDir, m_settings, this)); - } else if (inst_type == "LegacyFTB") { inst.reset(new LegacyFTBInstance(instDir, m_settings, this)); @@ -98,55 +93,26 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance(InstancePtr &in if (type == NormalInst) { - switch (mcVer->type) - { - case MinecraftVersion::Legacy: - // TODO new instance type - m_settings->set("InstanceType", "Legacy"); - inst.reset(new LegacyInstance(instDir, m_settings, this)); - inst->setIntendedVersionId(version->descriptor()); - inst->setShouldUseCustomBaseJar(false); - break; - case MinecraftVersion::OneSix: - m_settings->set("InstanceType", "OneSix"); - inst.reset(new OneSixInstance(instDir, m_settings, this)); - inst->setIntendedVersionId(version->descriptor()); - inst->setShouldUseCustomBaseJar(false); - break; - case MinecraftVersion::Nostalgia: - m_settings->set("InstanceType", "Nostalgia"); - inst.reset(new NostalgiaInstance(instDir, m_settings, this)); - inst->setIntendedVersionId(version->descriptor()); - inst->setShouldUseCustomBaseJar(false); - break; - default: - { - delete m_settings; - return InstanceFactory::NoSuchVersion; - } - } + m_settings->set("InstanceType", "OneSix"); + inst.reset(new OneSixInstance(instDir, m_settings, this)); + inst->setIntendedVersionId(version->descriptor()); + inst->setShouldUseCustomBaseJar(false); } else if (type == FTBInstance) { - switch (mcVer->type) + if(mcVer->usesLegacyLauncher()) { - case MinecraftVersion::Legacy: m_settings->set("InstanceType", "LegacyFTB"); inst.reset(new LegacyFTBInstance(instDir, m_settings, this)); inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); - break; - case MinecraftVersion::OneSix: + } + else + { m_settings->set("InstanceType", "OneSixFTB"); inst.reset(new OneSixFTBInstance(instDir, m_settings, this)); inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); - break; - default: - { - delete m_settings; - return InstanceFactory::NoSuchVersion; - } } } else diff --git a/logic/LegacyForge.cpp b/logic/LegacyForge.cpp deleted file mode 100644 index 94212ae4..00000000 --- a/logic/LegacyForge.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* Copyright 2013 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 "LegacyForge.h" - -MinecraftForge::MinecraftForge(const QString &file) : Mod(file) -{ -} - -bool MinecraftForge::FixVersionIfNeeded(QString newVersion) -{/* - wxString reportedVersion = GetModVersion(); - if(reportedVersion == "..." || reportedVersion.empty()) - { - std::auto_ptr in(new wxFFileInputStream("forge.zip")); - wxTempFileOutputStream out("forge.zip"); - wxTextOutputStream textout(out); - wxZipInputStream inzip(*in); - wxZipOutputStream outzip(out); - std::auto_ptr entry; - // preserve metadata - outzip.CopyArchiveMetaData(inzip); - // copy all entries - while (entry.reset(inzip.GetNextEntry()), entry.get() != NULL) - if (!outzip.CopyEntry(entry.release(), inzip)) - return false; - // release last entry - in.reset(); - outzip.PutNextEntry("forgeversion.properties"); - - wxStringTokenizer tokenizer(newVersion,"."); - wxString verFile; - verFile << wxString("forge.major.number=") << tokenizer.GetNextToken() << "\n"; - verFile << wxString("forge.minor.number=") << tokenizer.GetNextToken() << "\n"; - verFile << wxString("forge.revision.number=") << tokenizer.GetNextToken() << "\n"; - verFile << wxString("forge.build.number=") << tokenizer.GetNextToken() << "\n"; - auto buf = verFile.ToUTF8(); - outzip.Write(buf.data(), buf.length()); - // check if we succeeded - return inzip.Eof() && outzip.Close() && out.Commit(); - } - */ - return true; -} diff --git a/logic/LegacyForge.h b/logic/LegacyForge.h deleted file mode 100644 index f4165ffa..00000000 --- a/logic/LegacyForge.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright 2013 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 "Mod.h" - -class MinecraftForge : public Mod -{ -public: - MinecraftForge(const QString &file); - bool FixVersionIfNeeded(QString newVersion); -}; diff --git a/logic/LegacyInstance.cpp b/logic/LegacyInstance.cpp index 6648e059..bc4d2cfc 100644 --- a/logic/LegacyInstance.cpp +++ b/logic/LegacyInstance.cpp @@ -29,8 +29,6 @@ #include "logic/LegacyUpdate.h" #include "logic/icons/IconList.h" -#include "gui/dialogs/LegacyModEditDialog.h" - LegacyInstance::LegacyInstance(const QString &rootDir, SettingsObject *settings, QObject *parent) : BaseInstance(new LegacyInstancePrivate(), rootDir, settings, parent) @@ -138,7 +136,7 @@ std::shared_ptr LegacyInstance::texturePackList() QDialog *LegacyInstance::createModEditDialog(QWidget *parent) { - return new LegacyModEditDialog(this, parent); + return nullptr; } QString LegacyInstance::jarModsDir() const @@ -280,10 +278,7 @@ QString LegacyInstance::getStatusbarDescription() { if (flags().contains(VersionBrokenFlag)) { - return "Legacy : " + intendedVersionId() + " (broken)"; + return tr("Legacy : %1 (broken)").arg(intendedVersionId()); } - if (shouldUpdate()) - return "Legacy : " + currentVersionId() + " -> " + intendedVersionId(); - else - return "Legacy : " + currentVersionId(); + return tr("Legacy : %1").arg(intendedVersionId()); } diff --git a/logic/LegacyUpdate.cpp b/logic/LegacyUpdate.cpp index 15c99234..6816df40 100644 --- a/logic/LegacyUpdate.cpp +++ b/logic/LegacyUpdate.cpp @@ -30,52 +30,6 @@ LegacyUpdate::LegacyUpdate(BaseInstance *inst, QObject *parent) : Task(parent), m_inst(inst) { - // 1.3 - 1.3.2 - auto libs13 = QList{ - {"argo-2.25.jar", "bb672829fde76cb163004752b86b0484bd0a7f4b", false}, - {"guava-12.0.1.jar", "b8e78b9af7bf45900e14c6f958486b6ca682195f", false}, - {"asm-all-4.0.jar", "98308890597acb64047f7e896638e0d98753ae82", false}}; - - fmlLibsMapping["1.3.2"] = libs13; - - auto libs14 = QList{ - {"argo-2.25.jar", "bb672829fde76cb163004752b86b0484bd0a7f4b", false}, - {"guava-12.0.1.jar", "b8e78b9af7bf45900e14c6f958486b6ca682195f", false}, - {"asm-all-4.0.jar", "98308890597acb64047f7e896638e0d98753ae82", false}, - {"bcprov-jdk15on-147.jar", "b6f5d9926b0afbde9f4dbe3db88c5247be7794bb", false}}; - - fmlLibsMapping["1.4"] = libs14; - fmlLibsMapping["1.4.1"] = libs14; - fmlLibsMapping["1.4.2"] = libs14; - fmlLibsMapping["1.4.3"] = libs14; - fmlLibsMapping["1.4.4"] = libs14; - fmlLibsMapping["1.4.5"] = libs14; - fmlLibsMapping["1.4.6"] = libs14; - fmlLibsMapping["1.4.7"] = libs14; - - fmlLibsMapping["1.5"] = QList{ - {"argo-small-3.2.jar", "58912ea2858d168c50781f956fa5b59f0f7c6b51", false}, - {"guava-14.0-rc3.jar", "931ae21fa8014c3ce686aaa621eae565fefb1a6a", false}, - {"asm-all-4.1.jar", "054986e962b88d8660ae4566475658469595ef58", false}, - {"bcprov-jdk15on-148.jar", "960dea7c9181ba0b17e8bab0c06a43f0a5f04e65", true}, - {"deobfuscation_data_1.5.zip", "5f7c142d53776f16304c0bbe10542014abad6af8", false}, - {"scala-library.jar", "458d046151ad179c85429ed7420ffb1eaf6ddf85", true}}; - - fmlLibsMapping["1.5.1"] = QList{ - {"argo-small-3.2.jar", "58912ea2858d168c50781f956fa5b59f0f7c6b51", false}, - {"guava-14.0-rc3.jar", "931ae21fa8014c3ce686aaa621eae565fefb1a6a", false}, - {"asm-all-4.1.jar", "054986e962b88d8660ae4566475658469595ef58", false}, - {"bcprov-jdk15on-148.jar", "960dea7c9181ba0b17e8bab0c06a43f0a5f04e65", true}, - {"deobfuscation_data_1.5.1.zip", "22e221a0d89516c1f721d6cab056a7e37471d0a6", false}, - {"scala-library.jar", "458d046151ad179c85429ed7420ffb1eaf6ddf85", true}}; - - fmlLibsMapping["1.5.2"] = QList{ - {"argo-small-3.2.jar", "58912ea2858d168c50781f956fa5b59f0f7c6b51", false}, - {"guava-14.0-rc3.jar", "931ae21fa8014c3ce686aaa621eae565fefb1a6a", false}, - {"asm-all-4.1.jar", "054986e962b88d8660ae4566475658469595ef58", false}, - {"bcprov-jdk15on-148.jar", "960dea7c9181ba0b17e8bab0c06a43f0a5f04e65", true}, - {"deobfuscation_data_1.5.2.zip", "446e55cd986582c70fcf12cb27bc00114c5adfd9", false}, - {"scala-library.jar", "458d046151ad179c85429ed7420ffb1eaf6ddf85", true}}; } void LegacyUpdate::executeTask() @@ -110,6 +64,7 @@ void LegacyUpdate::fmllibsStart() bool forge_present = false; QString version = inst->intendedVersionId(); + auto & fmlLibsMapping = g_forgeData.fmlLibsMapping; if (!fmlLibsMapping.contains(version)) { lwjglStart(); @@ -152,7 +107,7 @@ void LegacyUpdate::fmllibsStart() // now check the lib folder inside the instance for files. for (auto &lib : libList) { - QFileInfo libInfo(PathCombine(inst->libDir(), lib.name)); + QFileInfo libInfo(PathCombine(inst->libDir(), lib.filename)); if (libInfo.exists()) continue; fmlLibsToProcess.append(lib); @@ -171,9 +126,9 @@ void LegacyUpdate::fmllibsStart() auto metacache = MMC->metacache(); for (auto &lib : fmlLibsToProcess) { - auto entry = metacache->resolveEntry("fmllibs", lib.name); - QString urlString = lib.ours ? URLConstants::FMLLIBS_OUR_BASE_URL + lib.name - : URLConstants::FMLLIBS_FORGE_BASE_URL + lib.name; + 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)); } @@ -196,16 +151,16 @@ void LegacyUpdate::fmllibsFinished() for (auto &lib : fmlLibsToProcess) { progress(index, fmlLibsToProcess.size()); - auto entry = metacache->resolveEntry("fmllibs", lib.name); - auto path = PathCombine(inst->libDir(), lib.name); + 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.name))) + if (!QFile::copy(entry->getFullPath(), PathCombine(inst->libDir(), lib.filename))) { - emitFailed(tr("Failed copying Forge/FML library: %1.").arg(lib.name)); + emitFailed(tr("Failed copying Forge/FML library: %1.").arg(lib.filename)); return; } index++; @@ -265,8 +220,6 @@ void LegacyUpdate::lwjglStart() connect(rep, SIGNAL(downloadProgress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); connect(worker.get(), SIGNAL(finished(QNetworkReply *)), SLOT(lwjglFinished(QNetworkReply *))); - // connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), - // SLOT(downloadError(QNetworkReply::NetworkError))); } void LegacyUpdate::lwjglFinished(QNetworkReply *reply) diff --git a/logic/LegacyUpdate.h b/logic/LegacyUpdate.h index 5b073cb7..1550ec34 100644 --- a/logic/LegacyUpdate.h +++ b/logic/LegacyUpdate.h @@ -21,19 +21,13 @@ #include "logic/net/NetJob.h" #include "logic/tasks/Task.h" +#include "logic/forge/ForgeData.h" class MinecraftVersion; class BaseInstance; class QuaZip; class Mod; -struct FMLlib -{ - QString name; - QString checksum; - bool ours; -}; - class LegacyUpdate : public Task { Q_OBJECT @@ -84,5 +78,4 @@ private: NetJobPtr legacyDownloadJob; BaseInstance *m_inst = nullptr; QList fmlLibsToProcess; - QMap> fmlLibsMapping; }; diff --git a/logic/LiteLoaderInstaller.cpp b/logic/LiteLoaderInstaller.cpp deleted file mode 100644 index 99cc5643..00000000 --- a/logic/LiteLoaderInstaller.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* Copyright 2013 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 "LiteLoaderInstaller.h" - -#include -#include - -#include "logger/QsLog.h" - -#include "VersionFinal.h" -#include "OneSixLibrary.h" -#include "OneSixInstance.h" -#include "MultiMC.h" -#include "lists/LiteLoaderVersionList.h" - -LiteLoaderInstaller::LiteLoaderInstaller() : BaseInstaller() -{ -} - -void LiteLoaderInstaller::prepare(LiteLoaderVersionPtr version) -{ - m_version = version; -} -bool LiteLoaderInstaller::add(OneSixInstance *to) -{ - if (!BaseInstaller::add(to)) - { - return false; - } - - QJsonObject obj; - - obj.insert("mainClass", QString("net.minecraft.launchwrapper.Launch")); - obj.insert("+tweakers", QJsonArray::fromStringList(QStringList() << m_version->tweakClass)); - obj.insert("order", 10); - - QJsonArray libraries; - - for (auto libStr : m_version->libraries) - { - OneSixLibrary lib(libStr); - lib.finalize(); - QJsonObject libObj = lib.toJson(); - libObj.insert("insert", QString("prepend")); - libraries.append(libObj); - } - - // liteloader - { - OneSixLibrary liteloaderLib("com.mumfrey:liteloader:" + m_version->version); - liteloaderLib.setAbsoluteUrl( - QString("http://dl.liteloader.com/versions/com/mumfrey/liteloader/%1/%2") - .arg(m_version->mcVersion, m_version->file)); - liteloaderLib.finalize(); - QJsonObject llLibObj = liteloaderLib.toJson(); - llLibObj.insert("insert", QString("prepend")); - llLibObj.insert("MMC-depend", QString("hard")); - libraries.append(llLibObj); - } - - obj.insert("+libraries", libraries); - obj.insert("name", QString("LiteLoader")); - obj.insert("fileId", id()); - obj.insert("version", m_version->version); - obj.insert("mcVersion", to->intendedVersionId()); - - QFile file(filename(to->instanceRoot())); - if (!file.open(QFile::WriteOnly)) - { - QLOG_ERROR() << "Error opening" << file.fileName() - << "for reading:" << file.errorString(); - return false; - } - file.write(QJsonDocument(obj).toJson()); - file.close(); - - return true; -} - -class LiteLoaderInstallTask : public Task -{ - Q_OBJECT -public: - LiteLoaderInstallTask(LiteLoaderInstaller *installer, OneSixInstance *instance, - BaseVersionPtr version, QObject *parent) - : Task(parent), m_installer(installer), m_instance(instance), m_version(version) - { - } - -protected: - void executeTask() override - { - LiteLoaderVersionPtr liteloaderVersion = - std::dynamic_pointer_cast(m_version); - if (!liteloaderVersion) - { - return; - } - m_installer->prepare(liteloaderVersion); - if (!m_installer->add(m_instance)) - { - emitFailed(tr("For reasons unknown, the LiteLoader installation failed. Check your " - "MultiMC log files for details.")); - } - else - { - try - { - m_instance->reloadVersion(); - emitSucceeded(); - } - catch (MMCError &e) - { - emitFailed(e.cause()); - } - catch (...) - { - emitFailed( - tr("Failed to load the version description file for reasons unknown.")); - } - } - } - -private: - LiteLoaderInstaller *m_installer; - OneSixInstance *m_instance; - BaseVersionPtr m_version; -}; - -ProgressProvider *LiteLoaderInstaller::createInstallTask(OneSixInstance *instance, - BaseVersionPtr version, - QObject *parent) -{ - return new LiteLoaderInstallTask(this, instance, version, parent); -} - -#include "LiteLoaderInstaller.moc" diff --git a/logic/LiteLoaderInstaller.h b/logic/LiteLoaderInstaller.h deleted file mode 100644 index 3ab5acb2..00000000 --- a/logic/LiteLoaderInstaller.h +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright 2013 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 "BaseInstaller.h" - -#include -#include - -#include "logic/lists/LiteLoaderVersionList.h" - -class LiteLoaderInstaller : public BaseInstaller -{ -public: - LiteLoaderInstaller(); - - void prepare(LiteLoaderVersionPtr version); - bool add(OneSixInstance *to) override; - - ProgressProvider *createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent) override; - -private: - virtual QString id() const override - { - return "com.mumfrey.liteloader"; - } - LiteLoaderVersionPtr m_version; -}; diff --git a/logic/MinecraftVersion.h b/logic/MinecraftVersion.h index 504381a8..6cbfebbe 100644 --- a/logic/MinecraftVersion.h +++ b/logic/MinecraftVersion.h @@ -17,6 +17,7 @@ #include "BaseVersion.h" #include +#include struct MinecraftVersion : public BaseVersion { @@ -29,13 +30,8 @@ struct MinecraftVersion : public BaseVersion /// The URL that this version will be downloaded from. maybe. QString download_url; - /// This version's type. Used internally to identify what kind of version this is. - enum VersionType - { - OneSix, - Legacy, - Nostalgia - } type; + /// extra features enabled for this Minecraft version. Mostly for compatibility + QSet features; /// is this the latest version? bool is_latest = false; @@ -47,6 +43,11 @@ struct MinecraftVersion : public BaseVersion QString m_descriptor; + bool usesLegacyLauncher() + { + return features.contains("legacy"); + } + virtual QString descriptor() { return m_descriptor; @@ -59,31 +60,21 @@ struct MinecraftVersion : public BaseVersion virtual QString typeString() const { - QStringList pre_final; - if (is_latest == true) + if (is_latest && is_snapshot) { - pre_final.append("Latest"); + return QObject::tr("Latest snapshot"); } - switch (type) + else if(is_latest) { - case OneSix: - pre_final.append("OneSix"); - break; - case Legacy: - pre_final.append("Legacy"); - break; - case Nostalgia: - pre_final.append("Nostalgia"); - break; - - default: - pre_final.append(QString("Type(%1)").arg(type)); - break; + return QObject::tr("Latest release"); + } + else if(is_snapshot) + { + return QObject::tr("Old snapshot"); } - if (is_snapshot == true) + else { - pre_final.append("Snapshot"); + return QObject::tr("Regular release"); } - return pre_final.join(' '); } }; diff --git a/logic/NostalgiaInstance.cpp b/logic/NostalgiaInstance.cpp deleted file mode 100644 index 52820725..00000000 --- a/logic/NostalgiaInstance.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright 2013 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 "NostalgiaInstance.h" - -NostalgiaInstance::NostalgiaInstance(const QString &rootDir, SettingsObject *settings, - QObject *parent) - : OneSixInstance(rootDir, settings, parent) -{ -} - -QString NostalgiaInstance::getStatusbarDescription() -{ - if (flags().contains(VersionBrokenFlag)) - { - return "Nostalgia : " + intendedVersionId() + " (broken)"; - } - return "Nostalgia : " + intendedVersionId(); -} - -bool NostalgiaInstance::menuActionEnabled(QString action_name) const -{ - return false; -} diff --git a/logic/NostalgiaInstance.h b/logic/NostalgiaInstance.h deleted file mode 100644 index f95531d2..00000000 --- a/logic/NostalgiaInstance.h +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright 2013 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 "OneSixInstance.h" - -class NostalgiaInstance : public OneSixInstance -{ - Q_OBJECT -public: - explicit NostalgiaInstance(const QString &rootDir, SettingsObject *settings, - QObject *parent = 0); - virtual ~NostalgiaInstance() {}; - virtual QString getStatusbarDescription(); - virtual bool menuActionEnabled(QString action_name) const; -}; diff --git a/logic/OneSixFTBInstance.cpp b/logic/OneSixFTBInstance.cpp index 172830bb..34118111 100644 --- a/logic/OneSixFTBInstance.cpp +++ b/logic/OneSixFTBInstance.cpp @@ -3,8 +3,8 @@ #include "VersionFinal.h" #include "OneSixLibrary.h" #include "tasks/SequentialTask.h" -#include "ForgeInstaller.h" -#include "lists/ForgeVersionList.h" +#include "forge/ForgeInstaller.h" +#include "forge/ForgeVersionList.h" #include "OneSixInstance_p.h" #include "OneSixVersionBuilder.h" #include "MultiMC.h" diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index 6f3018cb..dc452188 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -26,7 +26,7 @@ #include "MultiMC.h" #include "icons/IconList.h" #include "MinecraftProcess.h" -#include "gui/dialogs/OneSixModEditDialog.h" +#include "gui/dialogs/InstanceEditDialog.h" #include OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *settings, QObject *parent) @@ -36,7 +36,6 @@ OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *settings, d->m_settings->registerSetting("IntendedVersion", ""); d->m_settings->registerSetting("ShouldUpdate", false); d->version.reset(new VersionFinal(this, this)); - d->vanillaVersion.reset(new VersionFinal(this, this)); } void OneSixInstance::init() @@ -260,6 +259,17 @@ std::shared_ptr OneSixInstance::loaderModList() return d->loader_mod_list; } +std::shared_ptr OneSixInstance::coreModList() +{ + I_D(OneSixInstance); + if (!d->core_mod_list) + { + d->core_mod_list.reset(new ModList(coreModsDir())); + } + d->core_mod_list->update(); + return d->core_mod_list; +} + std::shared_ptr OneSixInstance::resourcePackList() { I_D(OneSixInstance); @@ -273,7 +283,7 @@ std::shared_ptr OneSixInstance::resourcePackList() QDialog *OneSixInstance::createModEditDialog(QWidget *parent) { - return new OneSixModEditDialog(this, parent); + return new InstanceEditDialog(this, parent); } bool OneSixInstance::setIntendedVersionId(QString version) @@ -307,10 +317,13 @@ bool OneSixInstance::shouldUpdate() const bool OneSixInstance::versionIsCustom() { - QDir patches(PathCombine(instanceRoot(), "patches/")); - return (patches.exists() && patches.count() >= 0) - || QFile::exists(PathCombine(instanceRoot(), "custom.json")) - || QFile::exists(PathCombine(instanceRoot(), "user.json")); + I_D(const OneSixInstance); + auto ver = d->version; + if(ver) + { + return !ver->isVanilla(); + } + return false; } bool OneSixInstance::versionIsFTBPack() @@ -335,15 +348,13 @@ void OneSixInstance::reloadVersion() try { - d->version->reload(false, externalPatches()); - d->vanillaVersion->reload(true, externalPatches()); + d->version->reload(externalPatches()); d->m_flags.remove(VersionBrokenFlag); emit versionReloaded(); } catch(MMCError & error) { d->version->clear(); - d->vanillaVersion->clear(); d->m_flags.insert(VersionBrokenFlag); //TODO: rethrow to show some error message(s)? emit versionReloaded(); @@ -355,7 +366,6 @@ void OneSixInstance::clearVersion() { I_D(OneSixInstance); d->version->clear(); - d->vanillaVersion->clear(); emit versionReloaded(); } @@ -365,12 +375,6 @@ std::shared_ptr OneSixInstance::getFullVersion() const return d->version; } -std::shared_ptr OneSixInstance::getVanillaVersion() const -{ - I_D(const OneSixInstance); - return d->vanillaVersion; -} - QString OneSixInstance::defaultBaseJar() const { return "versions/" + intendedVersionId() + "/" + intendedVersionId() + ".jar"; @@ -396,16 +400,24 @@ bool OneSixInstance::menuActionEnabled(QString action_name) const QString OneSixInstance::getStatusbarDescription() { - QString descr = "OneSix : " + intendedVersionId(); + QStringList traits; if (versionIsCustom()) { - descr += " (custom)"; + traits.append(tr("custom")); } if (flags().contains(VersionBrokenFlag)) { - descr += " (broken)"; + traits.append(tr("broken")); + } + + if(traits.size()) + { + return tr("Minecraft %1 (%2)").arg(intendedVersionId()).arg(traits.join(", ")); + } + else + { + return tr("Minecraft %1").arg(intendedVersionId()); } - return descr; } QDir OneSixInstance::librariesPath() const @@ -449,6 +461,11 @@ QString OneSixInstance::loaderModsDir() const return PathCombine(minecraftRoot(), "mods"); } +QString OneSixInstance::coreModsDir() const +{ + return PathCombine(minecraftRoot(), "coremods"); +} + QString OneSixInstance::resourcePacksDir() const { return PathCombine(minecraftRoot(), "resourcepacks"); @@ -458,3 +475,8 @@ QString OneSixInstance::instanceConfigFolder() const { return PathCombine(minecraftRoot(), "config"); } + +QString OneSixInstance::jarModsDir() const +{ + return PathCombine(instanceRoot(), "jarmods"); +} diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h index 13a392c2..b26ff752 100644 --- a/logic/OneSixInstance.h +++ b/logic/OneSixInstance.h @@ -32,11 +32,14 @@ public: ////// Mod Lists ////// std::shared_ptr loaderModList(); + std::shared_ptr coreModList(); std::shared_ptr resourcePackList(); - ////// Directories ////// + ////// Directories and files ////// + QString jarModsDir() const; QString resourcePacksDir() const; QString loaderModsDir() const; + QString coreModsDir() const; virtual QString instanceConfigFolder() const override; virtual std::shared_ptr doUpdate() override; @@ -60,14 +63,16 @@ public: * throws various exceptions :3 */ void reloadVersion(); + /// clears all version information in preparation for an update void clearVersion(); + /// get the current full version info std::shared_ptr getFullVersion() const; - /// gets the current version info, but only for version.json - std::shared_ptr getVanillaVersion() const; + /// is the current version original, or custom? virtual bool versionIsCustom() override; + /// does this instance have an FTB pack patch inside? bool versionIsFTBPack(); diff --git a/logic/OneSixInstance_p.h b/logic/OneSixInstance_p.h index c70de07c..e75a8da3 100644 --- a/logic/OneSixInstance_p.h +++ b/logic/OneSixInstance_p.h @@ -24,7 +24,8 @@ class OneSixInstancePrivate : public BaseInstancePrivate public: virtual ~OneSixInstancePrivate() {}; std::shared_ptr version; - std::shared_ptr vanillaVersion; + std::shared_ptr jar_mod_list; std::shared_ptr loader_mod_list; + std::shared_ptr core_mod_list; std::shared_ptr resource_pack_list; }; diff --git a/logic/OneSixLibrary.h b/logic/OneSixLibrary.h index 61d4c8e2..1c7169ce 100644 --- a/logic/OneSixLibrary.h +++ b/logic/OneSixLibrary.h @@ -41,7 +41,7 @@ private: // custom values /// absolute URL. takes precedence over m_download_path, if defined QString m_absolute_url; - /// download hint - how to actually get the library + /// type hint - modifies how the library is treated QString m_hint; // derived values used for real things diff --git a/logic/OneSixUpdate.cpp b/logic/OneSixUpdate.cpp index d083c2ba..da2fd29c 100644 --- a/logic/OneSixUpdate.cpp +++ b/logic/OneSixUpdate.cpp @@ -28,7 +28,7 @@ #include "VersionFinal.h" #include "OneSixLibrary.h" #include "OneSixInstance.h" -#include "net/ForgeMirrors.h" +#include "logic/forge/ForgeMirrors.h" #include "net/URLConstants.h" #include "assets/AssetsUtils.h" diff --git a/logic/OneSixVersionBuilder.cpp b/logic/OneSixVersionBuilder.cpp index be3a7da4..3fb96c5e 100644 --- a/logic/OneSixVersionBuilder.cpp +++ b/logic/OneSixVersionBuilder.cpp @@ -38,13 +38,12 @@ OneSixVersionBuilder::OneSixVersionBuilder() { } -void OneSixVersionBuilder::build(VersionFinal *version, OneSixInstance *instance, - const bool onlyVanilla, const QStringList &external) +void OneSixVersionBuilder::build(VersionFinal *version, OneSixInstance *instance, const QStringList &external) { OneSixVersionBuilder builder; builder.m_version = version; builder.m_instance = instance; - builder.buildInternal(onlyVanilla, external); + builder.buildInternal(external); } void OneSixVersionBuilder::readJsonAndApplyToVersion(VersionFinal *version, @@ -56,7 +55,7 @@ void OneSixVersionBuilder::readJsonAndApplyToVersion(VersionFinal *version, builder.readJsonAndApply(obj); } -void OneSixVersionBuilder::buildInternal(const bool onlyVanilla, const QStringList &external) +void OneSixVersionBuilder::buildInternal(const QStringList &external) { m_version->versionFiles.clear(); @@ -111,9 +110,6 @@ void OneSixVersionBuilder::buildInternal(const bool onlyVanilla, const QStringLi // QObject::tr("Error while applying %1. Please check MultiMC-0.log for more // info.").arg(root.absoluteFilePath("version.json"))); - if (onlyVanilla) - break; - // patches/ // load all, put into map for ordering, apply in the right order diff --git a/logic/OneSixVersionBuilder.h b/logic/OneSixVersionBuilder.h index 7a799e5b..6646584e 100644 --- a/logic/OneSixVersionBuilder.h +++ b/logic/OneSixVersionBuilder.h @@ -28,8 +28,7 @@ class OneSixVersionBuilder { OneSixVersionBuilder(); public: - static void build(VersionFinal *version, OneSixInstance *instance, const bool onlyVanilla, - const QStringList &external); + static void build(VersionFinal *version, OneSixInstance *instance, const QStringList &external); static void readJsonAndApplyToVersion(VersionFinal *version, const QJsonObject &obj); static QMap readOverrideOrders(OneSixInstance *instance); @@ -39,7 +38,7 @@ private: VersionFinal *m_version; OneSixInstance *m_instance; - void buildInternal(const bool onlyVanilla, const QStringList &external); + void buildInternal(const QStringList& external); void readJsonAndApply(const QJsonObject &obj); VersionFilePtr parseJsonFile(const QFileInfo &fileInfo, const bool requireOrder, diff --git a/logic/VersionFile.cpp b/logic/VersionFile.cpp index cd2a4f9c..4a850f97 100644 --- a/logic/VersionFile.cpp +++ b/logic/VersionFile.cpp @@ -13,6 +13,43 @@ using namespace MMCJson; #define CURRENT_MINIMUM_LAUNCHER_VERSION 14 +JarmodPtr Jarmod::fromJson(const QJsonObject &libObj, const QString &filename) +{ + JarmodPtr out(new Jarmod()); + if (!libObj.contains("name")) + { + throw JSONValidationError(filename + + "contains a jarmod that doesn't have a 'name' field"); + } + out->name = libObj.value("name").toString(); + + auto readString = [libObj, filename](const QString & key, QString & variable) + { + if (libObj.contains(key)) + { + QJsonValue val = libObj.value(key); + if (!val.isString()) + { + QLOG_WARN() << key << "is not a string in" << filename << "(skipping)"; + } + else + { + variable = val.toString(); + } + } + }; + + readString("url", out->baseurl); + readString("MMC-absoluteUrl", out->absoluteUrl); + if(!out->baseurl.isEmpty() && out->absoluteUrl.isEmpty()) + { + out->absoluteUrl = out->baseurl + out->name; + } + return out; + +} + + RawLibraryPtr RawLibrary::fromJson(const QJsonObject &libObj, const QString &filename) { RawLibraryPtr out(new RawLibrary()); @@ -165,6 +202,14 @@ VersionFilePtr VersionFile::fromJson(const QJsonDocument &doc, const QString &fi } } + if (root.contains("+traits")) + { + for (auto tweakerVal : ensureArray(root.value("+traits"))) + { + out->traits.insert(ensureString(tweakerVal)); + } + } + if (root.contains("libraries")) { // FIXME: This should be done when applying. @@ -188,6 +233,18 @@ VersionFilePtr VersionFile::fromJson(const QJsonDocument &doc, const QString &fi } } + if (root.contains("+jarMods")) + { + for (auto libVal : ensureArray(root.value("+jarMods"))) + { + QJsonObject libObj = ensureObject(libVal); + // parse the jarmod + auto lib = Jarmod::fromJson(libObj, filename); + // and add to jar mods + out->jarMods.append(lib); + } + } + if (root.contains("+libraries")) { for (auto libVal : ensureArray(root.value("+libraries"))) @@ -258,6 +315,7 @@ VersionFilePtr VersionFile::fromJson(const QJsonDocument &doc, const QString &fi out->addLibs.append(lib); } } + if (root.contains("-libraries")) { for (auto libVal : ensureArray(root.value("-libraries"))) @@ -309,6 +367,16 @@ int VersionFile::findLibrary(QList haystack, const QString &ne return retval; } +bool VersionFile::isVanilla() +{ + return fileId == "org.multimc.version.json"; +} + +bool VersionFile::hasJarMods() +{ + return !jarMods.isEmpty(); +} + void VersionFile::applyTo(VersionFinal *version) { if (minimumLauncherVersion != -1) @@ -338,6 +406,10 @@ void VersionFile::applyTo(VersionFinal *version) } if (!processArguments.isNull()) { + if(isVanilla()) + { + version->vanillaProcessArguments = processArguments; + } version->processArguments = processArguments; } if (!type.isNull()) @@ -362,6 +434,10 @@ void VersionFile::applyTo(VersionFinal *version) } if (!overwriteMinecraftArguments.isNull()) { + if(isVanilla()) + { + version->vanillaMinecraftArguments = overwriteMinecraftArguments; + } version->minecraftArguments = overwriteMinecraftArguments; } if (!addMinecraftArguments.isNull()) @@ -384,13 +460,17 @@ void VersionFile::applyTo(VersionFinal *version) { version->tweakers.removeAll(tweaker); } + version->jarMods.append(jarMods); if (shouldOverwriteLibs) { - version->libraries.clear(); + QList libs; for (auto lib : overwriteLibs) { - version->libraries.append(createLibrary(lib)); + libs.append(createLibrary(lib)); } + if(isVanilla()) + version->vanillaLibraries = libs; + version->libraries = libs; } for (auto lib : addLibs) { diff --git a/logic/VersionFile.h b/logic/VersionFile.h index 169a2066..2332e6d4 100644 --- a/logic/VersionFile.h +++ b/logic/VersionFile.h @@ -81,6 +81,18 @@ struct RawLibrary static RawLibraryPtr fromJson(const QJsonObject &libObj, const QString &filename); }; +struct Jarmod; +typedef std::shared_ptr JarmodPtr; +struct Jarmod +{ + QString name; + QString baseurl; + QString hint; + QString absoluteUrl; + + static JarmodPtr fromJson(const QJsonObject &libObj, const QString &filename); +}; + struct VersionFile; typedef std::shared_ptr VersionFilePtr; struct VersionFile @@ -92,7 +104,8 @@ public: /* methods */ static OneSixLibraryPtr createLibrary(RawLibraryPtr lib); int findLibrary(QList haystack, const QString &needle); void applyTo(VersionFinal *version); - + bool isVanilla(); + bool hasJarMods(); public: /* data */ int order = 0; QString name; @@ -124,4 +137,8 @@ public: /* data */ QList overwriteLibs; QList addLibs; QList removeLibs; + + QSet traits; + + QList jarMods; }; diff --git a/logic/VersionFinal.cpp b/logic/VersionFinal.cpp index dedf2ce5..18bd360b 100644 --- a/logic/VersionFinal.cpp +++ b/logic/VersionFinal.cpp @@ -21,16 +21,7 @@ #include "OneSixVersionBuilder.h" #include "OneSixInstance.h" - -template QMap invert(const QMap &in) -{ - QMap out; - for (auto it = in.begin(); it != in.end(); ++it) - { - out.insert(it.value(), it.key()); - } - return out; -} +#include VersionFinal::VersionFinal(OneSixInstance *instance, QObject *parent) : QAbstractListModel(parent), m_instance(instance) @@ -38,11 +29,10 @@ VersionFinal::VersionFinal(OneSixInstance *instance, QObject *parent) clear(); } -void VersionFinal::reload(const bool onlyVanilla, const QStringList &external) +void VersionFinal::reload(const QStringList &external) { - //FIXME: source of epic failure. beginResetModel(); - OneSixVersionBuilder::build(this, m_instance, onlyVanilla, external); + OneSixVersionBuilder::build(this, m_instance, external); reapply(true); endResetModel(); } @@ -60,6 +50,8 @@ void VersionFinal::clear() mainClass.clear(); libraries.clear(); tweakers.clear(); + jarMods.clear(); + traits.clear(); } bool VersionFinal::canRemove(const int index) const @@ -119,6 +111,11 @@ VersionFilePtr VersionFinal::versionFile(const QString &id) return 0; } +bool VersionFinal::hasJarMods() +{ + return !jarMods.isEmpty(); +} + bool VersionFinal::hasFtbPack() { return versionFile("org.multimc.ftb.pack.json") != nullptr; @@ -129,6 +126,36 @@ bool VersionFinal::removeFtbPack() return remove("org.multimc.ftb.pack.json"); } +bool VersionFinal::isVanilla() +{ + QDir patches(PathCombine(m_instance->instanceRoot(), "patches/")); + return versionFiles.size() > 1 || QFile::exists(PathCombine(m_instance->instanceRoot(), "custom.json")); +} + +bool VersionFinal::revertToVanilla() +{ + beginResetModel(); + auto it = versionFiles.begin(); + while (it != versionFiles.end()) + { + if ((*it)->fileId != "org.multimc.version.json") + { + QFile::remove((*it)->filename); + it = versionFiles.erase(it); + } + else + it++; + } + reapply(true); + endResetModel(); + return true; +} + +bool VersionFinal::usesLegacyCustomJson() +{ + return QFile::exists(PathCombine(m_instance->instanceRoot(), "custom.json")); +} + QList > VersionFinal::getActiveNormalLibs() { QList > output; @@ -229,15 +256,6 @@ int VersionFinal::columnCount(const QModelIndex &parent) const return 2; } -bool VersionFinal::isCustom() -{ - return QDir(m_instance->instanceRoot()).exists("custom.json"); -} -bool VersionFinal::revertToBase() -{ - return QDir(m_instance->instanceRoot()).remove("custom.json"); -} - QMap VersionFinal::getExistingOrder() const { @@ -356,8 +374,10 @@ void VersionFinal::finalize() { assets = "legacy"; } - if (minecraftArguments.isEmpty()) + auto finalizeArguments = [&]( QString & minecraftArguments, const QString & processArguments ) -> void { + if (!minecraftArguments.isEmpty()) + return; QString toCompare = processArguments.toLower(); if (toCompare == "legacy") { @@ -370,8 +390,11 @@ void VersionFinal::finalize() else if (toCompare == "username_session_version") { minecraftArguments = "--username ${auth_player_name} " - "--session ${auth_session} " - "--version ${profile_name}"; + "--session ${auth_session} " + "--version ${profile_name}"; } - } + }; + finalizeArguments(vanillaMinecraftArguments, vanillaProcessArguments); + finalizeArguments(minecraftArguments, processArguments); } + diff --git a/logic/VersionFinal.h b/logic/VersionFinal.h index 41fd23bd..71e43399 100644 --- a/logic/VersionFinal.h +++ b/logic/VersionFinal.h @@ -38,22 +38,29 @@ public: virtual int columnCount(const QModelIndex &parent) const; virtual Qt::ItemFlags flags(const QModelIndex &index) const; - void reload(const bool onlyVanilla = false, const QStringList &external = QStringList()); + void reload(const QStringList &external = QStringList()); void clear(); bool canRemove(const int index) const; QString versionFileId(const int index) const; - // does this instance have an all overriding custom.json - bool isCustom(); - // remove custom.json - bool revertToBase(); - // does this instance have an FTB pack patch file? + // is this version unmodded vanilla minecraft? + bool isVanilla(); + // remove any customizations on top of vanilla + bool revertToVanilla(); + + // does this version have an FTB pack patch file? bool hasFtbPack(); // remove FTB pack bool removeFtbPack(); + // does this version have any jar mods? + bool hasJarMods(); + + // does this version still use a legacy custom.json file? + bool usesLegacyCustomJson(); + enum MoveDirection { MoveUp, MoveDown }; void move(const int index, const MoveDirection direction); @@ -91,6 +98,8 @@ public: * ex: "username_session_version" */ QString processArguments; + /// Same as above, but only for vanilla + QString vanillaProcessArguments; /** * arguments that should be used for launching minecraft * @@ -98,6 +107,8 @@ public: * --version ${version_name} --gameDir ${game_directory} --assetsDir ${game_assets}" */ QString minecraftArguments; + /// Same as above, but only for vanilla + QString vanillaMinecraftArguments; /** * the minimum launcher version required by this version ... current is 4 (at point of * writing) @@ -114,6 +125,15 @@ public: /// the list of libs - both active and inactive, native and java QList> libraries; + + /// same, but only vanilla. + QList> vanillaLibraries; + + /// traits, collected from all the version files (version files can only add) + QSet traits; + + /// A list of jar mods. version files can add those. + QList jarMods; /* FIXME: add support for those rules here? Looks like a pile of quick hacks to me though. diff --git a/logic/forge/ForgeData.cpp b/logic/forge/ForgeData.cpp new file mode 100644 index 00000000..700b847b --- /dev/null +++ b/logic/forge/ForgeData.cpp @@ -0,0 +1,62 @@ +#include "ForgeData.h" + +extern ForgeData g_forgeData = ForgeData(); + +ForgeData::ForgeData() +{ + // 1.3.* + auto libs13 = + QList{{"argo-2.25.jar", "bb672829fde76cb163004752b86b0484bd0a7f4b", false}, + {"guava-12.0.1.jar", "b8e78b9af7bf45900e14c6f958486b6ca682195f", false}, + {"asm-all-4.0.jar", "98308890597acb64047f7e896638e0d98753ae82", false}}; + + fmlLibsMapping["1.3.2"] = libs13; + + // 1.4.* + auto libs14 = QList{ + {"argo-2.25.jar", "bb672829fde76cb163004752b86b0484bd0a7f4b", false}, + {"guava-12.0.1.jar", "b8e78b9af7bf45900e14c6f958486b6ca682195f", false}, + {"asm-all-4.0.jar", "98308890597acb64047f7e896638e0d98753ae82", false}, + {"bcprov-jdk15on-147.jar", "b6f5d9926b0afbde9f4dbe3db88c5247be7794bb", false}}; + + fmlLibsMapping["1.4"] = libs14; + fmlLibsMapping["1.4.1"] = libs14; + fmlLibsMapping["1.4.2"] = libs14; + fmlLibsMapping["1.4.3"] = libs14; + fmlLibsMapping["1.4.4"] = libs14; + fmlLibsMapping["1.4.5"] = libs14; + fmlLibsMapping["1.4.6"] = libs14; + fmlLibsMapping["1.4.7"] = libs14; + + // 1.5 + fmlLibsMapping["1.5"] = QList{ + {"argo-small-3.2.jar", "58912ea2858d168c50781f956fa5b59f0f7c6b51", false}, + {"guava-14.0-rc3.jar", "931ae21fa8014c3ce686aaa621eae565fefb1a6a", false}, + {"asm-all-4.1.jar", "054986e962b88d8660ae4566475658469595ef58", false}, + {"bcprov-jdk15on-148.jar", "960dea7c9181ba0b17e8bab0c06a43f0a5f04e65", true}, + {"deobfuscation_data_1.5.zip", "5f7c142d53776f16304c0bbe10542014abad6af8", false}, + {"scala-library.jar", "458d046151ad179c85429ed7420ffb1eaf6ddf85", true}}; + + // 1.5.1 + fmlLibsMapping["1.5.1"] = QList{ + {"argo-small-3.2.jar", "58912ea2858d168c50781f956fa5b59f0f7c6b51", false}, + {"guava-14.0-rc3.jar", "931ae21fa8014c3ce686aaa621eae565fefb1a6a", false}, + {"asm-all-4.1.jar", "054986e962b88d8660ae4566475658469595ef58", false}, + {"bcprov-jdk15on-148.jar", "960dea7c9181ba0b17e8bab0c06a43f0a5f04e65", true}, + {"deobfuscation_data_1.5.1.zip", "22e221a0d89516c1f721d6cab056a7e37471d0a6", false}, + {"scala-library.jar", "458d046151ad179c85429ed7420ffb1eaf6ddf85", true}}; + + // 1.5.2 + fmlLibsMapping["1.5.2"] = QList{ + {"argo-small-3.2.jar", "58912ea2858d168c50781f956fa5b59f0f7c6b51", false}, + {"guava-14.0-rc3.jar", "931ae21fa8014c3ce686aaa621eae565fefb1a6a", false}, + {"asm-all-4.1.jar", "054986e962b88d8660ae4566475658469595ef58", false}, + {"bcprov-jdk15on-148.jar", "960dea7c9181ba0b17e8bab0c06a43f0a5f04e65", true}, + {"deobfuscation_data_1.5.2.zip", "446e55cd986582c70fcf12cb27bc00114c5adfd9", false}, + {"scala-library.jar", "458d046151ad179c85429ed7420ffb1eaf6ddf85", true}}; + + // don't use installers for those. + forgeInstallerBlacklist = QSet({ + "1.5.2" + }); +} diff --git a/logic/forge/ForgeData.h b/logic/forge/ForgeData.h new file mode 100644 index 00000000..27749778 --- /dev/null +++ b/logic/forge/ForgeData.h @@ -0,0 +1,21 @@ +#pragma once +#include +#include +#include + +struct FMLlib +{ + QString filename; + QString checksum; + bool ours; +}; + +struct ForgeData +{ + ForgeData(); + // mapping between minecraft versions and FML libraries required + QMap> fmlLibsMapping; + // set of minecraft versions for which using forge installers is blacklisted + QSet forgeInstallerBlacklist; +}; +extern ForgeData g_forgeData; diff --git a/logic/forge/ForgeInstaller.cpp b/logic/forge/ForgeInstaller.cpp new file mode 100644 index 00000000..1204b855 --- /dev/null +++ b/logic/forge/ForgeInstaller.cpp @@ -0,0 +1,380 @@ +/* Copyright 2013 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 "ForgeInstaller.h" +#include "logic/VersionFinal.h" +#include "logic/OneSixLibrary.h" +#include "logic/net/HttpMetaCache.h" +#include "logic/tasks/Task.h" +#include "logic/OneSixInstance.h" +#include "logic/forge/ForgeVersionList.h" +#include "ForgeData.h" +#include "gui/dialogs/ProgressDialog.h" + +#include +#include +#include +#include +#include +#include +#include "MultiMC.h" +#include +#include +#include +#include + +ForgeInstaller::ForgeInstaller() : BaseInstaller() +{ +} +void ForgeInstaller::prepare(const QString &filename, const QString &universalUrl) +{ + std::shared_ptr newVersion; + m_universal_url = universalUrl; + + QuaZip zip(filename); + if (!zip.open(QuaZip::mdUnzip)) + return; + + QuaZipFile file(&zip); + + // read the install profile + if (!zip.setCurrentFile("install_profile.json")) + return; + + QJsonParseError jsonError; + if (!file.open(QIODevice::ReadOnly)) + return; + QJsonDocument jsonDoc = QJsonDocument::fromJson(file.readAll(), &jsonError); + file.close(); + if (jsonError.error != QJsonParseError::NoError) + return; + + if (!jsonDoc.isObject()) + return; + + QJsonObject root = jsonDoc.object(); + + auto installVal = root.value("install"); + auto versionInfoVal = root.value("versionInfo"); + if (!installVal.isObject() || !versionInfoVal.isObject()) + return; + + // read the forge version info + { + newVersion = VersionFinal::fromJson(versionInfoVal.toObject()); + if (!newVersion) + return; + } + + QJsonObject installObj = installVal.toObject(); + QString libraryName = installObj.value("path").toString(); + internalPath = installObj.value("filePath").toString(); + m_forgeVersionString = installObj.value("version").toString().remove("Forge").trimmed(); + + // where do we put the library? decode the mojang path + OneSixLibrary lib(libraryName); + lib.finalize(); + + auto cacheentry = MMC->metacache()->resolveEntry("libraries", lib.storagePath()); + finalPath = "libraries/" + lib.storagePath(); + if (!ensureFilePathExists(finalPath)) + return; + + if (!zip.setCurrentFile(internalPath)) + return; + if (!file.open(QIODevice::ReadOnly)) + return; + { + QByteArray data = file.readAll(); + // extract file + QSaveFile extraction(finalPath); + if (!extraction.open(QIODevice::WriteOnly)) + return; + if (extraction.write(data) != data.size()) + return; + if (!extraction.commit()) + return; + QCryptographicHash md5sum(QCryptographicHash::Md5); + md5sum.addData(data); + + cacheentry->stale = false; + cacheentry->md5sum = md5sum.result().toHex().constData(); + MMC->metacache()->updateEntry(cacheentry); + } + file.close(); + + m_forge_json = newVersion; + realVersionId = m_forge_json->id = installObj.value("minecraft").toString(); +} +bool ForgeInstaller::add(OneSixInstance *to) +{ + if (!BaseInstaller::add(to)) + { + return false; + } + + QJsonObject obj; + obj.insert("order", 5); + + if (!m_forge_json) + return false; + int sliding_insert_window = 0; + { + QJsonArray librariesPlus; + + // for each library in the version we are adding (except for the blacklisted) + QSet blacklist{"lwjgl", "lwjgl_util", "lwjgl-platform"}; + for (auto lib : m_forge_json->libraries) + { + QString libName = lib->name(); + // WARNING: This could actually break. + // if this is the actual forge lib, set an absolute url for the download + if (libName.contains("minecraftforge")) + { + lib->setAbsoluteUrl(m_universal_url); + } + else if (libName.contains("scala")) + { + lib->setHint("forge-pack-xz"); + } + if (blacklist.contains(libName)) + continue; + + QJsonObject libObj = lib->toJson(); + + bool found = false; + bool equals = false; + // find an entry that matches this one + for (auto tolib : to->getFullVersion()->vanillaLibraries) + { + if (tolib->name() != libName) + continue; + found = true; + if (tolib->toJson() == libObj) + { + equals = true; + } + // replace lib + libObj.insert("insert", QString("replace")); + break; + } + if (equals) + { + continue; + } + if (!found) + { + // add lib + libObj.insert("insert", QString("prepend")); + if (lib->name() == "minecraftforge") + { + libObj.insert("MMC-depend", QString("hard")); + } + sliding_insert_window++; + } + librariesPlus.prepend(libObj); + } + obj.insert("+libraries", librariesPlus); + obj.insert("mainClass", m_forge_json->mainClass); + QString args = m_forge_json->minecraftArguments; + QStringList tweakers; + { + QRegularExpression expression("--tweakClass ([a-zA-Z0-9\\.]*)"); + QRegularExpressionMatch match = expression.match(args); + while (match.hasMatch()) + { + tweakers.append(match.captured(1)); + args.remove(match.capturedStart(), match.capturedLength()); + match = expression.match(args); + } + } + if (!args.isEmpty() && args != to->getFullVersion()->vanillaMinecraftArguments) + { + obj.insert("minecraftArguments", args); + } + if (!tweakers.isEmpty()) + { + obj.insert("+tweakers", QJsonArray::fromStringList(tweakers)); + } + if (!m_forge_json->processArguments.isEmpty() && + m_forge_json->processArguments != to->getFullVersion()->vanillaProcessArguments) + { + obj.insert("processArguments", m_forge_json->processArguments); + } + } + + obj.insert("name", QString("Forge")); + obj.insert("fileId", id()); + obj.insert("version", m_forgeVersionString); + obj.insert("mcVersion", to->intendedVersionId()); + + QFile file(filename(to->instanceRoot())); + if (!file.open(QFile::WriteOnly)) + { + QLOG_ERROR() << "Error opening" << file.fileName() + << "for reading:" << file.errorString(); + return false; + } + file.write(QJsonDocument(obj).toJson()); + file.close(); + + return true; +} + +bool ForgeInstaller::addLegacy(OneSixInstance *to) +{ + if (!BaseInstaller::add(to)) + { + return false; + } + + QJsonObject obj; + obj.insert("order", 5); + { + QJsonArray jarmodsPlus; + { + QJsonObject libObj; + libObj.insert("name", m_forge_version->universal_filename); + jarmodsPlus.append(libObj); + } + obj.insert("+jarMods", jarmodsPlus); + } + + obj.insert("name", QString("Forge")); + obj.insert("fileId", id()); + obj.insert("version", m_forge_version->jobbuildver); + obj.insert("mcVersion", to->intendedVersionId()); + if (g_forgeData.fmlLibsMapping.contains(m_forge_version->mcver)) + { + QJsonArray traitsPlus; + traitsPlus.append(QString("legacyFML")); + obj.insert("+traits", traitsPlus); + } + + QFile file(filename(to->instanceRoot())); + if (!file.open(QFile::WriteOnly)) + { + QLOG_ERROR() << "Error opening" << file.fileName() + << "for reading:" << file.errorString(); + return false; + } + file.write(QJsonDocument(obj).toJson()); + file.close(); + return true; +} + +class ForgeInstallTask : public Task +{ + Q_OBJECT +public: + ForgeInstallTask(ForgeInstaller *installer, OneSixInstance *instance, + BaseVersionPtr version, QObject *parent = 0) + : Task(parent), m_installer(installer), m_instance(instance), m_version(version) + { + } + +protected: + void executeTask() override + { + setStatus(tr("Installing forge...")); + ForgeVersionPtr forgeVersion = std::dynamic_pointer_cast(m_version); + if (!forgeVersion) + { + emitFailed(tr("Unknown error occured")); + return; + } + prepare(forgeVersion); + } + void prepare(ForgeVersionPtr forgeVersion) + { + auto entry = + MMC->metacache()->resolveEntry("minecraftforge", forgeVersion->filename()); + auto installFunction = [this, entry, forgeVersion]() + { + if (!install(entry, forgeVersion)) + { + QLOG_ERROR() << "Failure installing forge"; + emitFailed(tr("Failure to install forge")); + } + else + { + reload(); + } + }; + + if (entry->stale) + { + NetJob *fjob = new NetJob("Forge download"); + fjob->addNetAction(CacheDownload::make(forgeVersion->url(), entry)); + connect(fjob, &NetJob::progress, [this](qint64 current, qint64 total) + { setProgress(100 * current / qMax((qint64)1, total)); }); + connect(fjob, &NetJob::status, [this](const QString & msg) + { setStatus(msg); }); + connect(fjob, &NetJob::failed, [this]() + { emitFailed(tr("Failure to download forge")); }); + connect(fjob, &NetJob::succeeded, installFunction); + fjob->start(); + } + else + { + installFunction(); + } + } + bool install(const std::shared_ptr &entry, const ForgeVersionPtr &forgeVersion) + { + if (forgeVersion->usesInstaller()) + { + QString forgePath = entry->getFullPath(); + m_installer->prepare(forgePath, forgeVersion->universal_url); + return m_installer->add(m_instance); + } + else + return m_installer->addLegacy(m_instance); + } + void reload() + { + try + { + m_instance->reloadVersion(); + emitSucceeded(); + } + catch (MMCError &e) + { + emitFailed(e.cause()); + } + catch (...) + { + emitFailed(tr("Failed to load the version description file for reasons unknown.")); + } + } + +private: + ForgeInstaller *m_installer; + OneSixInstance *m_instance; + BaseVersionPtr m_version; +}; + +ProgressProvider *ForgeInstaller::createInstallTask(OneSixInstance *instance, + BaseVersionPtr version, QObject *parent) +{ + if (!version) + { + return nullptr; + } + m_forge_version = std::dynamic_pointer_cast(version); + return new ForgeInstallTask(this, instance, version, parent); +} + +#include "ForgeInstaller.moc" diff --git a/logic/forge/ForgeInstaller.h b/logic/forge/ForgeInstaller.h new file mode 100644 index 00000000..dafa6305 --- /dev/null +++ b/logic/forge/ForgeInstaller.h @@ -0,0 +1,51 @@ +/* Copyright 2013 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/BaseInstaller.h" + +#include +#include + +class VersionFinal; +class ForgeInstallTask; +class ForgeVersion; + +class ForgeInstaller : public BaseInstaller +{ + friend class ForgeInstallTask; +public: + ForgeInstaller(); + virtual ~ForgeInstaller(){}; + virtual ProgressProvider *createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent) override; + +protected: + virtual QString id() const override { return "net.minecraftforge"; } + void prepare(const QString &filename, const QString &universalUrl); + bool add(OneSixInstance *to) override; + bool addLegacy(OneSixInstance *to); + +private: + // the parsed version json, read from the installer + std::shared_ptr m_forge_json; + // the actual forge version + std::shared_ptr m_forge_version; + QString internalPath; + QString finalPath; + QString realVersionId; + QString m_forgeVersionString; + QString m_universal_url; +}; diff --git a/logic/forge/ForgeMirror.h b/logic/forge/ForgeMirror.h new file mode 100644 index 00000000..2518dffe --- /dev/null +++ b/logic/forge/ForgeMirror.h @@ -0,0 +1,10 @@ +#pragma once +#include + +struct ForgeMirror +{ + QString name; + QString logo_url; + QString website_url; + QString mirror_url; +}; \ No newline at end of file diff --git a/logic/forge/ForgeMirrors.cpp b/logic/forge/ForgeMirrors.cpp new file mode 100644 index 00000000..b224306f --- /dev/null +++ b/logic/forge/ForgeMirrors.cpp @@ -0,0 +1,118 @@ +#include "MultiMC.h" +#include "ForgeMirrors.h" +#include "logger/QsLog.h" +#include +#include + +ForgeMirrors::ForgeMirrors(QList &libs, NetJobPtr parent_job, + QString mirrorlist) +{ + m_libs = libs; + m_parent_job = parent_job; + m_url = QUrl(mirrorlist); + m_status = Job_NotStarted; +} + +void ForgeMirrors::start() +{ + QLOG_INFO() << "Downloading " << m_url.toString(); + QNetworkRequest request(m_url); + request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); + auto worker = MMC->qnam(); + QNetworkReply *rep = worker->get(request); + + m_reply = std::shared_ptr(rep); + connect(rep, SIGNAL(downloadProgress(qint64, qint64)), + SLOT(downloadProgress(qint64, qint64))); + connect(rep, SIGNAL(finished()), SLOT(downloadFinished())); + connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), + SLOT(downloadError(QNetworkReply::NetworkError))); + connect(rep, SIGNAL(readyRead()), SLOT(downloadReadyRead())); +} + +void ForgeMirrors::downloadError(QNetworkReply::NetworkError error) +{ + // error happened during download. + QLOG_ERROR() << "Error getting URL:" << m_url.toString().toLocal8Bit() + << "Network error: " << error; + m_status = Job_Failed; +} + +void ForgeMirrors::downloadFinished() +{ + // if the download succeeded + if (m_status != Job_Failed) + { + // nothing went wrong... ? + parseMirrorList(); + return; + } + // else the download failed, we use a fixed list + else + { + m_status = Job_Finished; + m_reply.reset(); + deferToFixedList(); + return; + } +} + +void ForgeMirrors::deferToFixedList() +{ + m_mirrors.clear(); + m_mirrors.append( + {"Minecraft Forge", "http://files.minecraftforge.net/forge_logo.png", + "http://files.minecraftforge.net/", "http://files.minecraftforge.net/maven/"}); + m_mirrors.append({"Creeper Host", + "http://files.minecraftforge.net/forge_logo.png", + "https://www.creeperhost.net/link.php?id=1", + "http://new.creeperrepo.net/forge/maven/"}); + injectDownloads(); + emit succeeded(m_index_within_job); +} + +void ForgeMirrors::parseMirrorList() +{ + m_status = Job_Finished; + auto data = m_reply->readAll(); + m_reply.reset(); + auto dataLines = data.split('\n'); + for(auto line: dataLines) + { + auto elements = line.split('!'); + if (elements.size() == 4) + { + m_mirrors.append({elements[0],elements[1],elements[2],elements[3]}); + } + } + if(!m_mirrors.size()) + deferToFixedList(); + injectDownloads(); + emit succeeded(m_index_within_job); +} + +void ForgeMirrors::injectDownloads() +{ + // shuffle the mirrors randomly + std::random_device rd; + std::mt19937 rng(rd()); + std::shuffle(m_mirrors.begin(), m_mirrors.end(), rng); + + // tell parent to download the libs + for(auto lib: m_libs) + { + lib->setMirrors(m_mirrors); + m_parent_job->addNetAction(lib); + } +} + +void ForgeMirrors::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) +{ + m_total_progress = bytesTotal; + m_progress = bytesReceived; + emit progress(m_index_within_job, bytesReceived, bytesTotal); +} + +void ForgeMirrors::downloadReadyRead() +{ +} diff --git a/logic/forge/ForgeMirrors.h b/logic/forge/ForgeMirrors.h new file mode 100644 index 00000000..d25762db --- /dev/null +++ b/logic/forge/ForgeMirrors.h @@ -0,0 +1,58 @@ +/* Copyright 2013 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/net/NetAction.h" +#include "logic/net/HttpMetaCache.h" +#include "logic/net/NetJob.h" +#include "logic/forge/ForgeXzDownload.h" +#include +#include +typedef std::shared_ptr ForgeMirrorsPtr; + +class ForgeMirrors : public NetAction +{ + Q_OBJECT +public: + QList m_libs; + NetJobPtr m_parent_job; + QList m_mirrors; + +public: + explicit ForgeMirrors(QList &libs, NetJobPtr parent_job, + QString mirrorlist); + static ForgeMirrorsPtr make(QList &libs, NetJobPtr parent_job, + QString mirrorlist) + { + return ForgeMirrorsPtr(new ForgeMirrors(libs, parent_job, mirrorlist)); + } + virtual ~ForgeMirrors(){}; +protected +slots: + virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); + virtual void downloadError(QNetworkReply::NetworkError error); + virtual void downloadFinished(); + virtual void downloadReadyRead(); + +private: + void parseMirrorList(); + void deferToFixedList(); + void injectDownloads(); + +public +slots: + virtual void start(); +}; diff --git a/logic/forge/ForgeVersion.cpp b/logic/forge/ForgeVersion.cpp new file mode 100644 index 00000000..fd4efc4b --- /dev/null +++ b/logic/forge/ForgeVersion.cpp @@ -0,0 +1,55 @@ +#include "ForgeVersion.h" +#include "ForgeData.h" +#include + +QString ForgeVersion::name() +{ + return "Forge " + jobbuildver; +} + +QString ForgeVersion::descriptor() +{ + return universal_filename; +} + +QString ForgeVersion::typeString() const +{ + if (is_recommended) + return QObject::tr("Recommended"); + return QString(); +} + +bool ForgeVersion::operator<(BaseVersion &a) +{ + ForgeVersion *pa = dynamic_cast(&a); + if (!pa) + return true; + return m_buildnr < pa->m_buildnr; +} + +bool ForgeVersion::operator>(BaseVersion &a) +{ + ForgeVersion *pa = dynamic_cast(&a); + if (!pa) + return false; + return m_buildnr > pa->m_buildnr; +} + +bool ForgeVersion::usesInstaller() +{ + if(installer_url.isEmpty()) + return false; + if(g_forgeData.forgeInstallerBlacklist.contains(mcver)) + return false; + return true; +} + +QString ForgeVersion::filename() +{ + return usesInstaller() ? installer_filename : universal_filename; +} + +QString ForgeVersion::url() +{ + return usesInstaller() ? installer_url : universal_url; +} diff --git a/logic/forge/ForgeVersion.h b/logic/forge/ForgeVersion.h new file mode 100644 index 00000000..74e45c5a --- /dev/null +++ b/logic/forge/ForgeVersion.h @@ -0,0 +1,31 @@ +#pragma once +#include +#include +#include "logic/BaseVersion.h" + +struct ForgeVersion; +typedef std::shared_ptr ForgeVersionPtr; + +struct ForgeVersion : public BaseVersion +{ + virtual QString descriptor() override; + virtual QString name() override; + virtual QString typeString() const override; + virtual bool operator<(BaseVersion &a) override; + virtual bool operator>(BaseVersion &a) override; + + QString filename(); + QString url(); + + bool usesInstaller(); + + int m_buildnr = 0; + QString universal_url; + QString changelog_url; + QString installer_url; + QString jobbuildver; + QString mcver; + QString universal_filename; + QString installer_filename; + bool is_recommended = false; +}; diff --git a/logic/forge/ForgeVersionList.cpp b/logic/forge/ForgeVersionList.cpp new file mode 100644 index 00000000..c873bab7 --- /dev/null +++ b/logic/forge/ForgeVersionList.cpp @@ -0,0 +1,435 @@ +/* Copyright 2013 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 "logic/forge/ForgeVersionList.h" +#include "logic/forge/ForgeVersion.h" +#include "logic/net/NetJob.h" +#include "logic/net/URLConstants.h" +#include "MultiMC.h" + +#include +#include +#include + +#include "logger/QsLog.h" + +ForgeVersionList::ForgeVersionList(QObject *parent) : BaseVersionList(parent) +{ +} + +Task *ForgeVersionList::getLoadTask() +{ + return new ForgeListLoadTask(this); +} + +bool ForgeVersionList::isLoaded() +{ + return m_loaded; +} + +const BaseVersionPtr ForgeVersionList::at(int i) const +{ + return m_vlist.at(i); +} + +int ForgeVersionList::count() const +{ + return m_vlist.count(); +} + +int ForgeVersionList::columnCount(const QModelIndex &parent) const +{ + return 3; +} + +QVariant ForgeVersionList::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (index.row() > count()) + return QVariant(); + + auto version = std::dynamic_pointer_cast(m_vlist[index.row()]); + switch (role) + { + case Qt::DisplayRole: + switch (index.column()) + { + case 0: + return version->name(); + + case 1: + return version->mcver; + + case 2: + return version->typeString(); + default: + return QVariant(); + } + + case Qt::ToolTipRole: + return version->descriptor(); + + case VersionPointerRole: + return qVariantFromValue(m_vlist[index.row()]); + + default: + return QVariant(); + } +} + +QVariant ForgeVersionList::headerData(int section, Qt::Orientation orientation, int role) const +{ + switch (role) + { + case Qt::DisplayRole: + switch (section) + { + case 0: + return "Version"; + + case 1: + return "Minecraft"; + + case 2: + return "Type"; + + default: + return QVariant(); + } + + case Qt::ToolTipRole: + switch (section) + { + case 0: + return "The name of the version."; + + case 1: + return "Minecraft version"; + + case 2: + return "The version's type."; + + default: + return QVariant(); + } + + default: + return QVariant(); + } +} + +BaseVersionPtr ForgeVersionList::getLatestStable() const +{ + return BaseVersionPtr(); +} + +void ForgeVersionList::updateListData(QList versions) +{ + beginResetModel(); + m_vlist = versions; + m_loaded = true; + endResetModel(); + // NOW SORT!! + // sort(); +} + +void ForgeVersionList::sort() +{ + // NO-OP for now +} + +ForgeListLoadTask::ForgeListLoadTask(ForgeVersionList *vlist) : Task() +{ + m_list = vlist; +} + +void ForgeListLoadTask::executeTask() +{ + setStatus(tr("Fetching Forge version lists...")); + auto job = new NetJob("Version index"); + // we do not care if the version is stale or not. + auto forgeListEntry = MMC->metacache()->resolveEntry("minecraftforge", "list.json"); + auto gradleForgeListEntry = MMC->metacache()->resolveEntry("minecraftforge", "json"); + + // verify by poking the server. + forgeListEntry->stale = true; + gradleForgeListEntry->stale = true; + + job->addNetAction(listDownload = CacheDownload::make(QUrl(URLConstants::FORGE_LEGACY_URL), + forgeListEntry)); + job->addNetAction(gradleListDownload = CacheDownload::make( + QUrl(URLConstants::FORGE_GRADLE_URL), gradleForgeListEntry)); + + connect(listDownload.get(), SIGNAL(failed(int)), SLOT(listFailed())); + connect(gradleListDownload.get(), SIGNAL(failed(int)), SLOT(gradleListFailed())); + + listJob.reset(job); + connect(listJob.get(), SIGNAL(succeeded()), SLOT(listDownloaded())); + connect(listJob.get(), SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); + listJob->start(); +} + +bool ForgeListLoadTask::parseForgeList(QList &out) +{ + QByteArray data; + { + auto dlJob = listDownload; + auto filename = std::dynamic_pointer_cast(dlJob)->getTargetFilepath(); + QFile listFile(filename); + if (!listFile.open(QIODevice::ReadOnly)) + { + return false; + } + data = listFile.readAll(); + dlJob.reset(); + } + + QJsonParseError jsonError; + QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); + + if (jsonError.error != QJsonParseError::NoError) + { + emitFailed("Error parsing version list JSON:" + jsonError.errorString()); + return false; + } + + if (!jsonDoc.isObject()) + { + emitFailed("Error parsing version list JSON: JSON root is not an object"); + return false; + } + + QJsonObject root = jsonDoc.object(); + + // Now, get the array of versions. + if (!root.value("builds").isArray()) + { + emitFailed( + "Error parsing version list JSON: version list object is missing 'builds' array"); + return false; + } + QJsonArray builds = root.value("builds").toArray(); + + for (int i = 0; i < builds.count(); i++) + { + // Load the version info. + if (!builds[i].isObject()) + { + // FIXME: log this somewhere + continue; + } + QJsonObject obj = builds[i].toObject(); + int build_nr = obj.value("build").toDouble(0); + if (!build_nr) + continue; + QJsonArray files = obj.value("files").toArray(); + QString url, jobbuildver, mcver, buildtype, universal_filename; + QString changelog_url, installer_url; + QString installer_filename; + bool valid = false; + for (int j = 0; j < files.count(); j++) + { + if (!files[j].isObject()) + { + continue; + } + QJsonObject file = files[j].toObject(); + buildtype = file.value("buildtype").toString(); + if ((buildtype == "client" || buildtype == "universal") && !valid) + { + mcver = file.value("mcver").toString(); + url = file.value("url").toString(); + jobbuildver = file.value("jobbuildver").toString(); + int lastSlash = url.lastIndexOf('/'); + universal_filename = url.mid(lastSlash + 1); + valid = true; + } + else if (buildtype == "changelog") + { + QString ext = file.value("ext").toString(); + if (ext.isEmpty()) + { + continue; + } + changelog_url = file.value("url").toString(); + } + else if (buildtype == "installer") + { + installer_url = file.value("url").toString(); + int lastSlash = installer_url.lastIndexOf('/'); + installer_filename = installer_url.mid(lastSlash + 1); + } + } + if (valid) + { + // Now, we construct the version object and add it to the list. + std::shared_ptr fVersion(new ForgeVersion()); + fVersion->universal_url = url; + fVersion->changelog_url = changelog_url; + fVersion->installer_url = installer_url; + fVersion->jobbuildver = jobbuildver; + fVersion->mcver = mcver; + fVersion->installer_filename = installer_filename; + fVersion->universal_filename = universal_filename; + fVersion->m_buildnr = build_nr; + out.append(fVersion); + } + } + + return true; +} + +bool ForgeListLoadTask::parseForgeGradleList(QList &out) +{ + QByteArray data; + { + auto dlJob = gradleListDownload; + auto filename = std::dynamic_pointer_cast(dlJob)->getTargetFilepath(); + QFile listFile(filename); + if (!listFile.open(QIODevice::ReadOnly)) + { + return false; + } + data = listFile.readAll(); + dlJob.reset(); + } + + QJsonParseError jsonError; + QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); + + if (jsonError.error != QJsonParseError::NoError) + { + emitFailed("Error parsing gradle version list JSON:" + jsonError.errorString()); + return false; + } + + if (!jsonDoc.isObject()) + { + emitFailed("Error parsing gradle version list JSON: JSON root is not an object"); + return false; + } + + QJsonObject root = jsonDoc.object(); + + // we probably could hard code these, but it might still be worth doing it this way + const QString webpath = root.value("webpath").toString(); + const QString artifact = root.value("artifact").toString(); + + QJsonObject numbers = root.value("number").toObject(); + for (auto it = numbers.begin(); it != numbers.end(); ++it) + { + QJsonObject number = it.value().toObject(); + std::shared_ptr fVersion(new ForgeVersion()); + fVersion->m_buildnr = number.value("build").toDouble(); + fVersion->jobbuildver = number.value("version").toString(); + fVersion->mcver = number.value("mcversion").toString(); + fVersion->universal_filename = ""; + QString filename, installer_filename; + QJsonArray files = number.value("files").toArray(); + for (auto fIt = files.begin(); fIt != files.end(); ++fIt) + { + // TODO with gradle we also get checksums, use them + QJsonArray file = (*fIt).toArray(); + if (file.size() < 3) + { + continue; + } + if (file.at(1).toString() == "installer") + { + fVersion->installer_url = QString("%1/%2-%3/%4-%2-%3-installer.%5").arg( + webpath, fVersion->mcver, fVersion->jobbuildver, artifact, + file.at(0).toString()); + installer_filename = QString("%1-%2-%3-installer.%4").arg( + artifact, fVersion->mcver, fVersion->jobbuildver, file.at(0).toString()); + } + else if (file.at(1).toString() == "universal") + { + fVersion->universal_url = QString("%1/%2-%3/%4-%2-%3-universal.%5").arg( + webpath, fVersion->mcver, fVersion->jobbuildver, artifact, + file.at(0).toString()); + filename = QString("%1-%2-%3-universal.%4").arg( + artifact, fVersion->mcver, fVersion->jobbuildver, file.at(0).toString()); + } + else if (file.at(1).toString() == "changelog") + { + fVersion->changelog_url = QString("%1/%2-%3/%4-%2-%3-changelog.%5").arg( + webpath, fVersion->mcver, fVersion->jobbuildver, artifact, + file.at(0).toString()); + } + } + if (fVersion->installer_url.isEmpty() && fVersion->universal_url.isEmpty()) + { + continue; + } + fVersion->universal_filename = filename; + fVersion->installer_filename = installer_filename; + out.append(fVersion); + } + + return true; +} + +void ForgeListLoadTask::listDownloaded() +{ + QList list; + bool ret = true; + if (!parseForgeList(list)) + { + ret = false; + } + if (!parseForgeGradleList(list)) + { + ret = false; + } + + if (!ret) + { + return; + } + std::sort(list.begin(), list.end(), [](const BaseVersionPtr & l, const BaseVersionPtr & r) + { return (*l > *r); }); + + m_list->updateListData(list); + + emitSucceeded(); + return; +} + +void ForgeListLoadTask::listFailed() +{ + auto reply = listDownload->m_reply; + if (reply) + { + QLOG_ERROR() << "Getting forge version list failed: " << reply->errorString(); + } + else + { + QLOG_ERROR() << "Getting forge version list failed for reasons unknown."; + } +} +void ForgeListLoadTask::gradleListFailed() +{ + auto reply = gradleListDownload->m_reply; + if (reply) + { + QLOG_ERROR() << "Getting forge version list failed: " << reply->errorString(); + } + else + { + QLOG_ERROR() << "Getting forge version list failed for reasons unknown."; + } +} diff --git a/logic/forge/ForgeVersionList.h b/logic/forge/ForgeVersionList.h new file mode 100644 index 00000000..c848e9b8 --- /dev/null +++ b/logic/forge/ForgeVersionList.h @@ -0,0 +1,83 @@ +/* Copyright 2013 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 "logic/lists/BaseVersionList.h" +#include "logic/tasks/Task.h" +#include "logic/net/NetJob.h" +#include "logic/forge/ForgeVersion.h" + +class ForgeVersionList : public BaseVersionList +{ + Q_OBJECT +public: + friend class ForgeListLoadTask; + + explicit ForgeVersionList(QObject *parent = 0); + + virtual Task *getLoadTask(); + virtual bool isLoaded(); + virtual const BaseVersionPtr at(int i) const; + virtual int count() const; + virtual void sort(); + + virtual BaseVersionPtr getLatestStable() const; + + virtual QVariant data(const QModelIndex &index, int role) const; + virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; + virtual int columnCount(const QModelIndex &parent) const; + +protected: + QList m_vlist; + + bool m_loaded = false; + +protected +slots: + virtual void updateListData(QList versions); +}; + +class ForgeListLoadTask : public Task +{ + Q_OBJECT + +public: + explicit ForgeListLoadTask(ForgeVersionList *vlist); + + virtual void executeTask(); + +protected +slots: + void listDownloaded(); + void listFailed(); + void gradleListFailed(); + +protected: + NetJobPtr listJob; + ForgeVersionList *m_list; + + CacheDownloadPtr listDownload; + CacheDownloadPtr gradleListDownload; + +private: + bool parseForgeList(QList &out); + bool parseForgeGradleList(QList &out); +}; diff --git a/logic/forge/ForgeXzDownload.cpp b/logic/forge/ForgeXzDownload.cpp new file mode 100644 index 00000000..359ad858 --- /dev/null +++ b/logic/forge/ForgeXzDownload.cpp @@ -0,0 +1,389 @@ +/* Copyright 2013 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 "MultiMC.h" +#include "ForgeXzDownload.h" +#include + +#include +#include +#include +#include +#include "logger/QsLog.h" + +ForgeXzDownload::ForgeXzDownload(QString relative_path, MetaEntryPtr entry) : NetAction() +{ + m_entry = entry; + m_target_path = entry->getFullPath(); + m_pack200_xz_file.setFileTemplate("./dl_temp.XXXXXX"); + m_status = Job_NotStarted; + m_url_path = relative_path; +} + +void ForgeXzDownload::setMirrors(QList &mirrors) +{ + m_mirror_index = 0; + m_mirrors = mirrors; + updateUrl(); +} + +void ForgeXzDownload::start() +{ + m_status = Job_InProgress; + if (!m_entry->stale) + { + m_status = Job_Finished; + emit succeeded(m_index_within_job); + return; + } + // can we actually create the real, final file? + if (!ensureFilePathExists(m_target_path)) + { + m_status = Job_Failed; + emit failed(m_index_within_job); + return; + } + if (m_mirrors.empty()) + { + m_status = Job_Failed; + emit failed(m_index_within_job); + return; + } + + QLOG_INFO() << "Downloading " << m_url.toString(); + QNetworkRequest request(m_url); + request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->etag.toLatin1()); + request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)"); + + auto worker = MMC->qnam(); + QNetworkReply *rep = worker->get(request); + + m_reply = std::shared_ptr(rep); + connect(rep, SIGNAL(downloadProgress(qint64, qint64)), + SLOT(downloadProgress(qint64, qint64))); + connect(rep, SIGNAL(finished()), SLOT(downloadFinished())); + connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), + SLOT(downloadError(QNetworkReply::NetworkError))); + connect(rep, SIGNAL(readyRead()), SLOT(downloadReadyRead())); +} + +void ForgeXzDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) +{ + m_total_progress = bytesTotal; + m_progress = bytesReceived; + emit progress(m_index_within_job, bytesReceived, bytesTotal); +} + +void ForgeXzDownload::downloadError(QNetworkReply::NetworkError error) +{ + // error happened during download. + // TODO: log the reason why + m_status = Job_Failed; +} + +void ForgeXzDownload::failAndTryNextMirror() +{ + m_status = Job_Failed; + int next = m_mirror_index + 1; + if(m_mirrors.size() == next) + m_mirror_index = 0; + else + m_mirror_index = next; + + updateUrl(); + emit failed(m_index_within_job); +} + +void ForgeXzDownload::updateUrl() +{ + QLOG_INFO() << "Updating URL for " << m_url_path; + for (auto possible : m_mirrors) + { + QLOG_INFO() << "Possible: " << possible.name << " : " << possible.mirror_url; + } + QString aggregate = m_mirrors[m_mirror_index].mirror_url + m_url_path + ".pack.xz"; + m_url = QUrl(aggregate); +} + +void ForgeXzDownload::downloadFinished() +{ + //TEST: defer to other possible mirrors (autofail the first one) + /* + QLOG_INFO() <<"dl " << index_within_job << " mirror " << m_mirror_index; + if( m_mirror_index == 0) + { + QLOG_INFO() <<"dl " << index_within_job << " AUTOFAIL"; + m_status = Job_Failed; + m_pack200_xz_file.close(); + m_pack200_xz_file.remove(); + m_reply.reset(); + failAndTryNextMirror(); + return; + } + */ + + // if the download succeeded + if (m_status != Job_Failed) + { + // nothing went wrong... + m_status = Job_Finished; + if (m_pack200_xz_file.isOpen()) + { + // we actually downloaded something! process and isntall it + decompressAndInstall(); + return; + } + else + { + // something bad happened -- on the local machine! + m_status = Job_Failed; + m_pack200_xz_file.remove(); + m_reply.reset(); + emit failed(m_index_within_job); + return; + } + } + // else the download failed + else + { + m_status = Job_Failed; + m_pack200_xz_file.close(); + m_pack200_xz_file.remove(); + m_reply.reset(); + failAndTryNextMirror(); + return; + } +} + +void ForgeXzDownload::downloadReadyRead() +{ + + if (!m_pack200_xz_file.isOpen()) + { + if (!m_pack200_xz_file.open()) + { + /* + * Can't open the file... the job failed + */ + m_reply->abort(); + emit failed(m_index_within_job); + return; + } + } + m_pack200_xz_file.write(m_reply->readAll()); +} + +#include "xz.h" +#include "unpack200.h" +#include + +const size_t buffer_size = 8196; + +void ForgeXzDownload::decompressAndInstall() +{ + // rewind the downloaded temp file + m_pack200_xz_file.seek(0); + // de-xz'd file + QTemporaryFile pack200_file("./dl_temp.XXXXXX"); + pack200_file.open(); + + bool xz_success = false; + // first, de-xz + { + uint8_t in[buffer_size]; + uint8_t out[buffer_size]; + struct xz_buf b; + struct xz_dec *s; + enum xz_ret ret; + xz_crc32_init(); + xz_crc64_init(); + s = xz_dec_init(XZ_DYNALLOC, 1 << 26); + if (s == nullptr) + { + xz_dec_end(s); + failAndTryNextMirror(); + return; + } + b.in = in; + b.in_pos = 0; + b.in_size = 0; + b.out = out; + b.out_pos = 0; + b.out_size = buffer_size; + while (!xz_success) + { + if (b.in_pos == b.in_size) + { + b.in_size = m_pack200_xz_file.read((char *)in, sizeof(in)); + b.in_pos = 0; + } + + ret = xz_dec_run(s, &b); + + if (b.out_pos == sizeof(out)) + { + if (pack200_file.write((char *)out, b.out_pos) != b.out_pos) + { + // msg = "Write error\n"; + xz_dec_end(s); + failAndTryNextMirror(); + return; + } + + b.out_pos = 0; + } + + if (ret == XZ_OK) + continue; + + if (ret == XZ_UNSUPPORTED_CHECK) + { + // unsupported check. this is OK, but we should log this + continue; + } + + if (pack200_file.write((char *)out, b.out_pos) != b.out_pos) + { + // write error + pack200_file.close(); + xz_dec_end(s); + return; + } + + switch (ret) + { + case XZ_STREAM_END: + xz_dec_end(s); + xz_success = true; + break; + + case XZ_MEM_ERROR: + QLOG_ERROR() << "Memory allocation failed\n"; + xz_dec_end(s); + failAndTryNextMirror(); + return; + + case XZ_MEMLIMIT_ERROR: + QLOG_ERROR() << "Memory usage limit reached\n"; + xz_dec_end(s); + failAndTryNextMirror(); + return; + + case XZ_FORMAT_ERROR: + QLOG_ERROR() << "Not a .xz file\n"; + xz_dec_end(s); + failAndTryNextMirror(); + return; + + case XZ_OPTIONS_ERROR: + QLOG_ERROR() << "Unsupported options in the .xz headers\n"; + xz_dec_end(s); + failAndTryNextMirror(); + return; + + case XZ_DATA_ERROR: + case XZ_BUF_ERROR: + QLOG_ERROR() << "File is corrupt\n"; + xz_dec_end(s); + failAndTryNextMirror(); + return; + + default: + QLOG_ERROR() << "Bug!\n"; + xz_dec_end(s); + failAndTryNextMirror(); + return; + } + } + } + m_pack200_xz_file.remove(); + + // revert pack200 + pack200_file.seek(0); + int handle_in = pack200_file.handle(); + // FIXME: dispose of file handles, pointers and the like. Ideally wrap in objects. + if(handle_in == -1) + { + QLOG_ERROR() << "Error reopening " << pack200_file.fileName(); + failAndTryNextMirror(); + return; + } + FILE * file_in = fdopen(handle_in,"r"); + if(!file_in) + { + QLOG_ERROR() << "Error reopening " << pack200_file.fileName(); + failAndTryNextMirror(); + return; + } + QFile qfile_out(m_target_path); + if(!qfile_out.open(QIODevice::WriteOnly)) + { + QLOG_ERROR() << "Error opening " << qfile_out.fileName(); + failAndTryNextMirror(); + return; + } + int handle_out = qfile_out.handle(); + if(handle_out == -1) + { + QLOG_ERROR() << "Error opening " << qfile_out.fileName(); + failAndTryNextMirror(); + return; + } + FILE * file_out = fdopen(handle_out,"w"); + if(!file_out) + { + QLOG_ERROR() << "Error opening " << qfile_out.fileName(); + failAndTryNextMirror(); + return; + } + try + { + unpack_200(file_in, file_out); + } + catch (std::runtime_error &err) + { + m_status = Job_Failed; + QLOG_ERROR() << "Error unpacking " << pack200_file.fileName() << " : " << err.what(); + QFile f(m_target_path); + if (f.exists()) + f.remove(); + failAndTryNextMirror(); + return; + } + pack200_file.remove(); + + QFile jar_file(m_target_path); + + if (!jar_file.open(QIODevice::ReadOnly)) + { + jar_file.remove(); + failAndTryNextMirror(); + return; + } + m_entry->md5sum = QCryptographicHash::hash(jar_file.readAll(), QCryptographicHash::Md5) + .toHex() + .constData(); + jar_file.close(); + + QFileInfo output_file_info(m_target_path); + m_entry->etag = m_reply->rawHeader("ETag").constData(); + m_entry->local_changed_timestamp = + output_file_info.lastModified().toUTC().toMSecsSinceEpoch(); + m_entry->stale = false; + MMC->metacache()->updateEntry(m_entry); + + m_reply.reset(); + emit succeeded(m_index_within_job); +} diff --git a/logic/forge/ForgeXzDownload.h b/logic/forge/ForgeXzDownload.h new file mode 100644 index 00000000..f2564380 --- /dev/null +++ b/logic/forge/ForgeXzDownload.h @@ -0,0 +1,66 @@ +/* Copyright 2013 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/net/NetAction.h" +#include "logic/net/HttpMetaCache.h" +#include +#include +#include "ForgeMirror.h" + +typedef std::shared_ptr ForgeXzDownloadPtr; + +class ForgeXzDownload : public NetAction +{ + Q_OBJECT +public: + MetaEntryPtr m_entry; + /// if saving to file, use the one specified in this string + QString m_target_path; + /// this is the output file, if any + QTemporaryFile m_pack200_xz_file; + /// mirror index (NOT OPTICS, I SWEAR) + int m_mirror_index = 0; + /// list of mirrors to use. Mirror has the url base + QList m_mirrors; + /// path relative to the mirror base + QString m_url_path; + +public: + explicit ForgeXzDownload(QString relative_path, MetaEntryPtr entry); + static ForgeXzDownloadPtr make(QString relative_path, MetaEntryPtr entry) + { + return ForgeXzDownloadPtr(new ForgeXzDownload(relative_path, entry)); + } + virtual ~ForgeXzDownload(){}; + void setMirrors(QList & mirrors); + +protected +slots: + virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); + virtual void downloadError(QNetworkReply::NetworkError error); + virtual void downloadFinished(); + virtual void downloadReadyRead(); + +public +slots: + virtual void start(); + +private: + void decompressAndInstall(); + void failAndTryNextMirror(); + void updateUrl(); +}; diff --git a/logic/forge/LegacyForge.cpp b/logic/forge/LegacyForge.cpp new file mode 100644 index 00000000..94212ae4 --- /dev/null +++ b/logic/forge/LegacyForge.cpp @@ -0,0 +1,56 @@ +/* Copyright 2013 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 "LegacyForge.h" + +MinecraftForge::MinecraftForge(const QString &file) : Mod(file) +{ +} + +bool MinecraftForge::FixVersionIfNeeded(QString newVersion) +{/* + wxString reportedVersion = GetModVersion(); + if(reportedVersion == "..." || reportedVersion.empty()) + { + std::auto_ptr in(new wxFFileInputStream("forge.zip")); + wxTempFileOutputStream out("forge.zip"); + wxTextOutputStream textout(out); + wxZipInputStream inzip(*in); + wxZipOutputStream outzip(out); + std::auto_ptr entry; + // preserve metadata + outzip.CopyArchiveMetaData(inzip); + // copy all entries + while (entry.reset(inzip.GetNextEntry()), entry.get() != NULL) + if (!outzip.CopyEntry(entry.release(), inzip)) + return false; + // release last entry + in.reset(); + outzip.PutNextEntry("forgeversion.properties"); + + wxStringTokenizer tokenizer(newVersion,"."); + wxString verFile; + verFile << wxString("forge.major.number=") << tokenizer.GetNextToken() << "\n"; + verFile << wxString("forge.minor.number=") << tokenizer.GetNextToken() << "\n"; + verFile << wxString("forge.revision.number=") << tokenizer.GetNextToken() << "\n"; + verFile << wxString("forge.build.number=") << tokenizer.GetNextToken() << "\n"; + auto buf = verFile.ToUTF8(); + outzip.Write(buf.data(), buf.length()); + // check if we succeeded + return inzip.Eof() && outzip.Close() && out.Commit(); + } + */ + return true; +} diff --git a/logic/forge/LegacyForge.h b/logic/forge/LegacyForge.h new file mode 100644 index 00000000..ec49f63c --- /dev/null +++ b/logic/forge/LegacyForge.h @@ -0,0 +1,25 @@ +/* Copyright 2013 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/Mod.h" + +class MinecraftForge : public Mod +{ +public: + MinecraftForge(const QString &file); + bool FixVersionIfNeeded(QString newVersion); +}; diff --git a/logic/lists/ForgeVersionList.cpp b/logic/lists/ForgeVersionList.cpp deleted file mode 100644 index 4902dc64..00000000 --- a/logic/lists/ForgeVersionList.cpp +++ /dev/null @@ -1,439 +0,0 @@ -/* Copyright 2013 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 "ForgeVersionList.h" -#include -#include -#include "MultiMC.h" - -#include -#include -#include - -#include "logger/QsLog.h" - -ForgeVersionList::ForgeVersionList(QObject *parent) : BaseVersionList(parent) -{ -} - -Task *ForgeVersionList::getLoadTask() -{ - return new ForgeListLoadTask(this); -} - -bool ForgeVersionList::isLoaded() -{ - return m_loaded; -} - -const BaseVersionPtr ForgeVersionList::at(int i) const -{ - return m_vlist.at(i); -} - -int ForgeVersionList::count() const -{ - return m_vlist.count(); -} - -int ForgeVersionList::columnCount(const QModelIndex &parent) const -{ - return 3; -} - -QVariant ForgeVersionList::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) - return QVariant(); - - if (index.row() > count()) - return QVariant(); - - auto version = std::dynamic_pointer_cast(m_vlist[index.row()]); - switch (role) - { - case Qt::DisplayRole: - switch (index.column()) - { - case 0: - return version->name(); - - case 1: - return version->mcver; - - case 2: - return version->typeString(); - default: - return QVariant(); - } - - case Qt::ToolTipRole: - return version->descriptor(); - - case VersionPointerRole: - return qVariantFromValue(m_vlist[index.row()]); - - default: - return QVariant(); - } -} - -QVariant ForgeVersionList::headerData(int section, Qt::Orientation orientation, int role) const -{ - switch (role) - { - case Qt::DisplayRole: - switch (section) - { - case 0: - return "Version"; - - case 1: - return "Minecraft"; - - case 2: - return "Type"; - - default: - return QVariant(); - } - - case Qt::ToolTipRole: - switch (section) - { - case 0: - return "The name of the version."; - - case 1: - return "Minecraft version"; - - case 2: - return "The version's type."; - - default: - return QVariant(); - } - - default: - return QVariant(); - } -} - -BaseVersionPtr ForgeVersionList::getLatestStable() const -{ - return BaseVersionPtr(); -} - -void ForgeVersionList::updateListData(QList versions) -{ - beginResetModel(); - m_vlist = versions; - m_loaded = true; - endResetModel(); - // NOW SORT!! - // sort(); -} - -void ForgeVersionList::sort() -{ - // NO-OP for now -} - -ForgeListLoadTask::ForgeListLoadTask(ForgeVersionList *vlist) : Task() -{ - m_list = vlist; -} - -void ForgeListLoadTask::executeTask() -{ - setStatus(tr("Fetching Forge version lists...")); - auto job = new NetJob("Version index"); - // we do not care if the version is stale or not. - auto forgeListEntry = MMC->metacache()->resolveEntry("minecraftforge", "list.json"); - auto gradleForgeListEntry = MMC->metacache()->resolveEntry("minecraftforge", "json"); - - // verify by poking the server. - forgeListEntry->stale = true; - gradleForgeListEntry->stale = true; - - job->addNetAction(listDownload = CacheDownload::make(QUrl(URLConstants::FORGE_LEGACY_URL), - forgeListEntry)); - job->addNetAction(gradleListDownload = CacheDownload::make( - QUrl(URLConstants::FORGE_GRADLE_URL), gradleForgeListEntry)); - - connect(listDownload.get(), SIGNAL(failed(int)), SLOT(listFailed())); - connect(gradleListDownload.get(), SIGNAL(failed(int)), SLOT(gradleListFailed())); - - listJob.reset(job); - connect(listJob.get(), SIGNAL(succeeded()), SLOT(listDownloaded())); - connect(listJob.get(), SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); - listJob->start(); -} - -bool ForgeListLoadTask::parseForgeList(QList &out) -{ - QByteArray data; - { - auto dlJob = listDownload; - auto filename = std::dynamic_pointer_cast(dlJob)->getTargetFilepath(); - QFile listFile(filename); - if (!listFile.open(QIODevice::ReadOnly)) - { - return false; - } - data = listFile.readAll(); - dlJob.reset(); - } - - QJsonParseError jsonError; - QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); - - if (jsonError.error != QJsonParseError::NoError) - { - emitFailed("Error parsing version list JSON:" + jsonError.errorString()); - return false; - } - - if (!jsonDoc.isObject()) - { - emitFailed("Error parsing version list JSON: JSON root is not an object"); - return false; - } - - QJsonObject root = jsonDoc.object(); - - // Now, get the array of versions. - if (!root.value("builds").isArray()) - { - emitFailed( - "Error parsing version list JSON: version list object is missing 'builds' array"); - return false; - } - QJsonArray builds = root.value("builds").toArray(); - - for (int i = 0; i < builds.count(); i++) - { - // Load the version info. - if (!builds[i].isObject()) - { - // FIXME: log this somewhere - continue; - } - QJsonObject obj = builds[i].toObject(); - int build_nr = obj.value("build").toDouble(0); - if (!build_nr) - continue; - QJsonArray files = obj.value("files").toArray(); - QString url, jobbuildver, mcver, buildtype, filename; - QString changelog_url, installer_url; - QString installer_filename; - bool valid = false; - for (int j = 0; j < files.count(); j++) - { - if (!files[j].isObject()) - { - continue; - } - QJsonObject file = files[j].toObject(); - buildtype = file.value("buildtype").toString(); - if ((buildtype == "client" || buildtype == "universal") && !valid) - { - mcver = file.value("mcver").toString(); - url = file.value("url").toString(); - jobbuildver = file.value("jobbuildver").toString(); - int lastSlash = url.lastIndexOf('/'); - filename = url.mid(lastSlash + 1); - valid = true; - } - else if (buildtype == "changelog") - { - QString ext = file.value("ext").toString(); - if (ext.isEmpty()) - { - continue; - } - changelog_url = file.value("url").toString(); - } - else if (buildtype == "installer") - { - installer_url = file.value("url").toString(); - int lastSlash = installer_url.lastIndexOf('/'); - installer_filename = installer_url.mid(lastSlash + 1); - } - } - if (valid) - { - // Now, we construct the version object and add it to the list. - std::shared_ptr fVersion(new ForgeVersion()); - fVersion->universal_url = url; - fVersion->changelog_url = changelog_url; - fVersion->installer_url = installer_url; - fVersion->jobbuildver = jobbuildver; - fVersion->mcver = mcver; - if (installer_filename.isEmpty()) - { - fVersion->filename = filename; - } - else - { - fVersion->filename = installer_filename; - } - fVersion->m_buildnr = build_nr; - out.append(fVersion); - } - } - - return true; -} - -bool ForgeListLoadTask::parseForgeGradleList(QList &out) -{ - QByteArray data; - { - auto dlJob = gradleListDownload; - auto filename = std::dynamic_pointer_cast(dlJob)->getTargetFilepath(); - QFile listFile(filename); - if (!listFile.open(QIODevice::ReadOnly)) - { - return false; - } - data = listFile.readAll(); - dlJob.reset(); - } - - QJsonParseError jsonError; - QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); - - if (jsonError.error != QJsonParseError::NoError) - { - emitFailed("Error parsing gradle version list JSON:" + jsonError.errorString()); - return false; - } - - if (!jsonDoc.isObject()) - { - emitFailed("Error parsing gradle version list JSON: JSON root is not an object"); - return false; - } - - QJsonObject root = jsonDoc.object(); - - // we probably could hard code these, but it might still be worth doing it this way - const QString webpath = root.value("webpath").toString(); - const QString artifact = root.value("artifact").toString(); - - QJsonObject numbers = root.value("number").toObject(); - for (auto it = numbers.begin(); it != numbers.end(); ++it) - { - QJsonObject number = it.value().toObject(); - std::shared_ptr fVersion(new ForgeVersion()); - fVersion->m_buildnr = number.value("build").toDouble(); - fVersion->jobbuildver = number.value("version").toString(); - fVersion->mcver = number.value("mcversion").toString(); - fVersion->filename = ""; - QString filename, installer_filename; - QJsonArray files = number.value("files").toArray(); - for (auto fIt = files.begin(); fIt != files.end(); ++fIt) - { - // TODO with gradle we also get checksums, use them - QJsonArray file = (*fIt).toArray(); - if (file.size() < 3) - { - continue; - } - if (file.at(1).toString() == "installer") - { - fVersion->installer_url = QString("%1/%2-%3/%4-%2-%3-installer.%5").arg( - webpath, fVersion->mcver, fVersion->jobbuildver, artifact, - file.at(0).toString()); - installer_filename = QString("%1-%2-%3-installer.%4").arg( - artifact, fVersion->mcver, fVersion->jobbuildver, file.at(0).toString()); - } - else if (file.at(1).toString() == "universal") - { - fVersion->universal_url = QString("%1/%2-%3/%4-%2-%3-universal.%5").arg( - webpath, fVersion->mcver, fVersion->jobbuildver, artifact, - file.at(0).toString()); - filename = QString("%1-%2-%3-universal.%4").arg( - artifact, fVersion->mcver, fVersion->jobbuildver, file.at(0).toString()); - } - else if (file.at(1).toString() == "changelog") - { - fVersion->changelog_url = QString("%1/%2-%3/%4-%2-%3-changelog.%5").arg( - webpath, fVersion->mcver, fVersion->jobbuildver, artifact, - file.at(0).toString()); - } - } - if (fVersion->installer_url.isEmpty() && fVersion->universal_url.isEmpty()) - { - continue; - } - fVersion->filename = fVersion->installer_url.isEmpty() ? filename : installer_filename; - out.append(fVersion); - } - - return true; -} - -void ForgeListLoadTask::listDownloaded() -{ - QList list; - bool ret = true; - if (!parseForgeList(list)) - { - ret = false; - } - if (!parseForgeGradleList(list)) - { - ret = false; - } - - if (!ret) - { - return; - } - std::sort(list.begin(), list.end(), [](const BaseVersionPtr & l, const BaseVersionPtr & r) - { return (*l > *r); }); - - m_list->updateListData(list); - - emitSucceeded(); - return; -} - -void ForgeListLoadTask::listFailed() -{ - auto reply = listDownload->m_reply; - if (reply) - { - QLOG_ERROR() << "Getting forge version list failed: " << reply->errorString(); - } - else - { - QLOG_ERROR() << "Getting forge version list failed for reasons unknown."; - } -} -void ForgeListLoadTask::gradleListFailed() -{ - auto reply = gradleListDownload->m_reply; - if (reply) - { - QLOG_ERROR() << "Getting forge version list failed: " << reply->errorString(); - } - else - { - QLOG_ERROR() << "Getting forge version list failed for reasons unknown."; - } -} diff --git a/logic/lists/ForgeVersionList.h b/logic/lists/ForgeVersionList.h deleted file mode 100644 index b19d3f56..00000000 --- a/logic/lists/ForgeVersionList.h +++ /dev/null @@ -1,128 +0,0 @@ -/* Copyright 2013 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 "BaseVersionList.h" -#include "logic/tasks/Task.h" -#include "logic/net/NetJob.h" - -class ForgeVersion; -typedef std::shared_ptr ForgeVersionPtr; - -struct ForgeVersion : public BaseVersion -{ - virtual QString descriptor() override - { - return filename; - } - ; - virtual QString name() override - { - return "Forge " + jobbuildver; - } - ; - virtual QString typeString() const override - { - if (installer_url.isEmpty()) - return "Universal"; - else - return "Installer"; - } - - virtual bool operator<(BaseVersion &a) override - { - ForgeVersion *pa = dynamic_cast(&a); - if(!pa) - return true; - return m_buildnr < pa->m_buildnr; - } - virtual bool operator>(BaseVersion &a) override - { - ForgeVersion *pa = dynamic_cast(&a); - if(!pa) - return false; - return m_buildnr > pa->m_buildnr; - } - int m_buildnr = 0; - QString universal_url; - QString changelog_url; - QString installer_url; - QString jobbuildver; - QString mcver; - QString filename; -}; - -class ForgeVersionList : public BaseVersionList -{ - Q_OBJECT -public: - friend class ForgeListLoadTask; - - explicit ForgeVersionList(QObject *parent = 0); - - virtual Task *getLoadTask(); - virtual bool isLoaded(); - virtual const BaseVersionPtr at(int i) const; - virtual int count() const; - virtual void sort(); - - virtual BaseVersionPtr getLatestStable() const; - - virtual QVariant data(const QModelIndex &index, int role) const; - virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; - virtual int columnCount(const QModelIndex &parent) const; - -protected: - QList m_vlist; - - bool m_loaded = false; - -protected -slots: - virtual void updateListData(QList versions); -}; - -class ForgeListLoadTask : public Task -{ - Q_OBJECT - -public: - explicit ForgeListLoadTask(ForgeVersionList *vlist); - - virtual void executeTask(); - -protected -slots: - void listDownloaded(); - void listFailed(); - void gradleListFailed(); - -protected: - NetJobPtr listJob; - ForgeVersionList *m_list; - - CacheDownloadPtr listDownload; - CacheDownloadPtr gradleListDownload; - -private: - bool parseForgeList(QList &out); - bool parseForgeGradleList(QList &out); -}; diff --git a/logic/lists/LiteLoaderVersionList.cpp b/logic/lists/LiteLoaderVersionList.cpp deleted file mode 100644 index ef95eefd..00000000 --- a/logic/lists/LiteLoaderVersionList.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/* Copyright 2013 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 "LiteLoaderVersionList.h" -#include "MultiMC.h" -#include "logic/net/URLConstants.h" - -#include - -#include -#include -#include -#include -#include - -#include - -#include - -LiteLoaderVersionList::LiteLoaderVersionList(QObject *parent) : BaseVersionList(parent) -{ -} - -Task *LiteLoaderVersionList::getLoadTask() -{ - return new LLListLoadTask(this); -} - -bool LiteLoaderVersionList::isLoaded() -{ - return m_loaded; -} - -const BaseVersionPtr LiteLoaderVersionList::at(int i) const -{ - return m_vlist.at(i); -} - -int LiteLoaderVersionList::count() const -{ - return m_vlist.count(); -} - -static bool cmpVersions(BaseVersionPtr first, BaseVersionPtr second) -{ - auto left = std::dynamic_pointer_cast(first); - auto right = std::dynamic_pointer_cast(second); - return left->timestamp > right->timestamp; -} - -void LiteLoaderVersionList::sort() -{ - beginResetModel(); - qSort(m_vlist.begin(), m_vlist.end(), cmpVersions); - endResetModel(); -} - -BaseVersionPtr LiteLoaderVersionList::getLatestStable() const -{ - for (int i = 0; i < m_vlist.length(); i++) - { - auto ver = std::dynamic_pointer_cast(m_vlist.at(i)); - if (ver->isLatest) - { - return m_vlist.at(i); - } - } - return BaseVersionPtr(); -} - -void LiteLoaderVersionList::updateListData(QList versions) -{ - beginResetModel(); - m_vlist = versions; - m_loaded = true; - qSort(m_vlist.begin(), m_vlist.end(), cmpVersions); - endResetModel(); -} - -LLListLoadTask::LLListLoadTask(LiteLoaderVersionList *vlist) -{ - m_list = vlist; -} - -LLListLoadTask::~LLListLoadTask() -{ -} - -void LLListLoadTask::executeTask() -{ - setStatus(tr("Loading LiteLoader version list...")); - auto job = new NetJob("Version index"); - // we do not care if the version is stale or not. - auto liteloaderEntry = MMC->metacache()->resolveEntry("liteloader", "versions.json"); - - // verify by poking the server. - liteloaderEntry->stale = true; - - job->addNetAction(listDownload = CacheDownload::make(QUrl(URLConstants::LITELOADER_URL), - liteloaderEntry)); - - connect(listDownload.get(), SIGNAL(failed(int)), SLOT(listFailed())); - - listJob.reset(job); - connect(listJob.get(), SIGNAL(succeeded()), SLOT(listDownloaded())); - connect(listJob.get(), SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); - listJob->start(); -} - -void LLListLoadTask::listFailed() -{ - emitFailed("Failed to load LiteLoader version list."); - return; -} - -void LLListLoadTask::listDownloaded() -{ - QByteArray data; - { - auto dlJob = listDownload; - auto filename = std::dynamic_pointer_cast(dlJob)->getTargetFilepath(); - QFile listFile(filename); - if (!listFile.open(QIODevice::ReadOnly)) - { - emitFailed("Failed to open the LiteLoader version list."); - return; - } - data = listFile.readAll(); - listFile.close(); - dlJob.reset(); - } - - QJsonParseError jsonError; - QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); - - if (jsonError.error != QJsonParseError::NoError) - { - emitFailed("Error parsing version list JSON:" + jsonError.errorString()); - return; - } - - if (!jsonDoc.isObject()) - { - emitFailed("Error parsing version list JSON: jsonDoc is not an object"); - return; - } - - const QJsonObject root = jsonDoc.object(); - - // Now, get the array of versions. - if (!root.value("versions").isObject()) - { - emitFailed("Error parsing version list JSON: missing 'versions' object"); - return; - } - - auto meta = root.value("meta").toObject(); - QString description = meta.value("description").toString(tr("This is a lightweight loader for mods that don't change game mechanics.")); - QString defaultUrl = meta.value("url").toString("http://dl.liteloader.com"); - QString authors = meta.value("authors").toString("Mumfrey"); - auto versions = root.value("versions").toObject(); - - QList tempList; - for (auto vIt = versions.begin(); vIt != versions.end(); ++vIt) - { - const QString mcVersion = vIt.key(); - QString latest; - const QJsonObject artefacts = vIt.value() - .toObject() - .value("artefacts") - .toObject() - .value("com.mumfrey:liteloader") - .toObject(); - QList perMcVersionList; - for (auto aIt = artefacts.begin(); aIt != artefacts.end(); ++aIt) - { - const QString identifier = aIt.key(); - const QJsonObject artefact = aIt.value().toObject(); - if (identifier == "latest") - { - latest = artefact.value("version").toString(); - continue; - } - LiteLoaderVersionPtr version(new LiteLoaderVersion()); - version->version = artefact.value("version").toString(); - version->file = artefact.value("file").toString(); - version->mcVersion = mcVersion; - version->md5 = artefact.value("md5").toString(); - version->timestamp = artefact.value("timestamp").toDouble(); - version->tweakClass = artefact.value("tweakClass").toString(); - version->authors = authors; - version->description = description; - version->defaultUrl = defaultUrl; - const QJsonArray libs = artefact.value("libraries").toArray(); - for (auto lIt = libs.begin(); lIt != libs.end(); ++lIt) - { - version->libraries.append((*lIt).toObject().value("name").toString()); - } - perMcVersionList.append(version); - } - for (auto version : perMcVersionList) - { - auto v = std::dynamic_pointer_cast(version); - v->isLatest = v->version == latest; - } - tempList.append(perMcVersionList); - } - m_list->updateListData(tempList); - - emitSucceeded(); -} diff --git a/logic/lists/LiteLoaderVersionList.h b/logic/lists/LiteLoaderVersionList.h deleted file mode 100644 index bfc913e5..00000000 --- a/logic/lists/LiteLoaderVersionList.h +++ /dev/null @@ -1,112 +0,0 @@ -/* Copyright 2013 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 "BaseVersionList.h" -#include "logic/tasks/Task.h" -#include "logic/BaseVersion.h" -#include - -class LLListLoadTask; -class QNetworkReply; - -class LiteLoaderVersion : public BaseVersion -{ -public: - QString descriptor() override - { - if (isLatest) - { - return QObject::tr("Latest"); - } - return QString(); - } - QString typeString() const override - { - return mcVersion; - } - QString name() override - { - return version; - } - - // important info - QString version; - QString file; - QString mcVersion; - QString md5; - int timestamp; - bool isLatest; - QString tweakClass; - QStringList libraries; - - // meta - QString defaultUrl; - QString description; - QString authors; -}; -typedef std::shared_ptr LiteLoaderVersionPtr; - -class LiteLoaderVersionList : public BaseVersionList -{ - Q_OBJECT -public: - friend class LLListLoadTask; - - explicit LiteLoaderVersionList(QObject *parent = 0); - - virtual Task *getLoadTask(); - virtual bool isLoaded(); - virtual const BaseVersionPtr at(int i) const; - virtual int count() const; - virtual void sort(); - - virtual BaseVersionPtr getLatestStable() const; - -protected: - QList m_vlist; - - bool m_loaded = false; - -protected -slots: - virtual void updateListData(QList versions); -}; - -class LLListLoadTask : public Task -{ - Q_OBJECT - -public: - explicit LLListLoadTask(LiteLoaderVersionList *vlist); - ~LLListLoadTask(); - - virtual void executeTask(); - -protected -slots: - void listDownloaded(); - void listFailed(); - -protected: - NetJobPtr listJob; - CacheDownloadPtr listDownload; - LiteLoaderVersionList *m_list; -}; diff --git a/logic/lists/MinecraftVersionList.cpp b/logic/lists/MinecraftVersionList.cpp index b9d60c61..ec2f2d21 100644 --- a/logic/lists/MinecraftVersionList.cpp +++ b/logic/lists/MinecraftVersionList.cpp @@ -212,6 +212,7 @@ void MCVListLoadTask::list_downloaded() { bool is_snapshot = false; bool is_latest = false; + bool legacyLaunch = false; // Load the version info. if (!versions[i].isObject()) @@ -236,32 +237,28 @@ void MCVListLoadTask::list_downloaded() // FIXME: log this somewhere continue; } - // Parse the type. - MinecraftVersion::VersionType versionType; // OneSix or Legacy. use filter to determine type if (versionTypeStr == "release") { - versionType = legacyWhitelist.contains(versionID) ? MinecraftVersion::Legacy - : MinecraftVersion::OneSix; + legacyLaunch = legacyWhitelist.contains(versionID); is_latest = (versionID == latestReleaseID); is_snapshot = false; } else if (versionTypeStr == "snapshot") // It's a snapshot... yay { - versionType = legacyWhitelist.contains(versionID) ? MinecraftVersion::Legacy - : MinecraftVersion::OneSix; + legacyLaunch = legacyWhitelist.contains(versionID); is_latest = (versionID == latestSnapshotID); is_snapshot = true; } else if (versionTypeStr == "old_alpha") { - versionType = MinecraftVersion::Nostalgia; + legacyLaunch = false; is_latest = false; is_snapshot = false; } else if (versionTypeStr == "old_beta") { - versionType = MinecraftVersion::Legacy; + legacyLaunch = true; is_latest = false; is_snapshot = false; } @@ -280,7 +277,8 @@ void MCVListLoadTask::list_downloaded() mcVersion->download_url = dlUrl; mcVersion->is_latest = is_latest; mcVersion->is_snapshot = is_snapshot; - mcVersion->type = versionType; + if(legacyLaunch) + mcVersion->features.insert("legacy"); tempList.append(mcVersion); } m_list->updateListData(tempList); diff --git a/logic/liteloader/LiteLoaderInstaller.cpp b/logic/liteloader/LiteLoaderInstaller.cpp new file mode 100644 index 00000000..1a94e644 --- /dev/null +++ b/logic/liteloader/LiteLoaderInstaller.cpp @@ -0,0 +1,150 @@ +/* Copyright 2013 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 "LiteLoaderInstaller.h" + +#include +#include + +#include "logger/QsLog.h" + +#include "logic/VersionFinal.h" +#include "logic/OneSixLibrary.h" +#include "logic/OneSixInstance.h" +#include "MultiMC.h" +#include "logic/liteloader/LiteLoaderVersionList.h" + +LiteLoaderInstaller::LiteLoaderInstaller() : BaseInstaller() +{ +} + +void LiteLoaderInstaller::prepare(LiteLoaderVersionPtr version) +{ + m_version = version; +} +bool LiteLoaderInstaller::add(OneSixInstance *to) +{ + if (!BaseInstaller::add(to)) + { + return false; + } + + QJsonObject obj; + + obj.insert("mainClass", QString("net.minecraft.launchwrapper.Launch")); + obj.insert("+tweakers", QJsonArray::fromStringList(QStringList() << m_version->tweakClass)); + obj.insert("order", 10); + + QJsonArray libraries; + + for (auto libStr : m_version->libraries) + { + OneSixLibrary lib(libStr); + lib.finalize(); + QJsonObject libObj = lib.toJson(); + libObj.insert("insert", QString("prepend")); + libraries.append(libObj); + } + + // liteloader + { + OneSixLibrary liteloaderLib("com.mumfrey:liteloader:" + m_version->version); + liteloaderLib.setAbsoluteUrl( + QString("http://dl.liteloader.com/versions/com/mumfrey/liteloader/%1/%2") + .arg(m_version->mcVersion, m_version->file)); + liteloaderLib.finalize(); + QJsonObject llLibObj = liteloaderLib.toJson(); + llLibObj.insert("insert", QString("prepend")); + llLibObj.insert("MMC-depend", QString("hard")); + libraries.append(llLibObj); + } + + obj.insert("+libraries", libraries); + obj.insert("name", QString("LiteLoader")); + obj.insert("fileId", id()); + obj.insert("version", m_version->version); + obj.insert("mcVersion", to->intendedVersionId()); + + QFile file(filename(to->instanceRoot())); + if (!file.open(QFile::WriteOnly)) + { + QLOG_ERROR() << "Error opening" << file.fileName() + << "for reading:" << file.errorString(); + return false; + } + file.write(QJsonDocument(obj).toJson()); + file.close(); + + return true; +} + +class LiteLoaderInstallTask : public Task +{ + Q_OBJECT +public: + LiteLoaderInstallTask(LiteLoaderInstaller *installer, OneSixInstance *instance, + BaseVersionPtr version, QObject *parent) + : Task(parent), m_installer(installer), m_instance(instance), m_version(version) + { + } + +protected: + void executeTask() override + { + LiteLoaderVersionPtr liteloaderVersion = + std::dynamic_pointer_cast(m_version); + if (!liteloaderVersion) + { + return; + } + m_installer->prepare(liteloaderVersion); + if (!m_installer->add(m_instance)) + { + emitFailed(tr("For reasons unknown, the LiteLoader installation failed. Check your " + "MultiMC log files for details.")); + } + else + { + try + { + m_instance->reloadVersion(); + emitSucceeded(); + } + catch (MMCError &e) + { + emitFailed(e.cause()); + } + catch (...) + { + emitFailed( + tr("Failed to load the version description file for reasons unknown.")); + } + } + } + +private: + LiteLoaderInstaller *m_installer; + OneSixInstance *m_instance; + BaseVersionPtr m_version; +}; + +ProgressProvider *LiteLoaderInstaller::createInstallTask(OneSixInstance *instance, + BaseVersionPtr version, + QObject *parent) +{ + return new LiteLoaderInstallTask(this, instance, version, parent); +} + +#include "LiteLoaderInstaller.moc" diff --git a/logic/liteloader/LiteLoaderInstaller.h b/logic/liteloader/LiteLoaderInstaller.h new file mode 100644 index 00000000..43ad6b83 --- /dev/null +++ b/logic/liteloader/LiteLoaderInstaller.h @@ -0,0 +1,40 @@ +/* Copyright 2013 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 "logic/BaseInstaller.h" +#include "logic/liteloader/LiteLoaderVersionList.h" + +class LiteLoaderInstaller : public BaseInstaller +{ +public: + LiteLoaderInstaller(); + + void prepare(LiteLoaderVersionPtr version); + bool add(OneSixInstance *to) override; + + ProgressProvider *createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent) override; + +private: + virtual QString id() const override + { + return "com.mumfrey.liteloader"; + } + LiteLoaderVersionPtr m_version; +}; diff --git a/logic/liteloader/LiteLoaderVersionList.cpp b/logic/liteloader/LiteLoaderVersionList.cpp new file mode 100644 index 00000000..ef95eefd --- /dev/null +++ b/logic/liteloader/LiteLoaderVersionList.cpp @@ -0,0 +1,223 @@ +/* Copyright 2013 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 "LiteLoaderVersionList.h" +#include "MultiMC.h" +#include "logic/net/URLConstants.h" + +#include + +#include +#include +#include +#include +#include + +#include + +#include + +LiteLoaderVersionList::LiteLoaderVersionList(QObject *parent) : BaseVersionList(parent) +{ +} + +Task *LiteLoaderVersionList::getLoadTask() +{ + return new LLListLoadTask(this); +} + +bool LiteLoaderVersionList::isLoaded() +{ + return m_loaded; +} + +const BaseVersionPtr LiteLoaderVersionList::at(int i) const +{ + return m_vlist.at(i); +} + +int LiteLoaderVersionList::count() const +{ + return m_vlist.count(); +} + +static bool cmpVersions(BaseVersionPtr first, BaseVersionPtr second) +{ + auto left = std::dynamic_pointer_cast(first); + auto right = std::dynamic_pointer_cast(second); + return left->timestamp > right->timestamp; +} + +void LiteLoaderVersionList::sort() +{ + beginResetModel(); + qSort(m_vlist.begin(), m_vlist.end(), cmpVersions); + endResetModel(); +} + +BaseVersionPtr LiteLoaderVersionList::getLatestStable() const +{ + for (int i = 0; i < m_vlist.length(); i++) + { + auto ver = std::dynamic_pointer_cast(m_vlist.at(i)); + if (ver->isLatest) + { + return m_vlist.at(i); + } + } + return BaseVersionPtr(); +} + +void LiteLoaderVersionList::updateListData(QList versions) +{ + beginResetModel(); + m_vlist = versions; + m_loaded = true; + qSort(m_vlist.begin(), m_vlist.end(), cmpVersions); + endResetModel(); +} + +LLListLoadTask::LLListLoadTask(LiteLoaderVersionList *vlist) +{ + m_list = vlist; +} + +LLListLoadTask::~LLListLoadTask() +{ +} + +void LLListLoadTask::executeTask() +{ + setStatus(tr("Loading LiteLoader version list...")); + auto job = new NetJob("Version index"); + // we do not care if the version is stale or not. + auto liteloaderEntry = MMC->metacache()->resolveEntry("liteloader", "versions.json"); + + // verify by poking the server. + liteloaderEntry->stale = true; + + job->addNetAction(listDownload = CacheDownload::make(QUrl(URLConstants::LITELOADER_URL), + liteloaderEntry)); + + connect(listDownload.get(), SIGNAL(failed(int)), SLOT(listFailed())); + + listJob.reset(job); + connect(listJob.get(), SIGNAL(succeeded()), SLOT(listDownloaded())); + connect(listJob.get(), SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); + listJob->start(); +} + +void LLListLoadTask::listFailed() +{ + emitFailed("Failed to load LiteLoader version list."); + return; +} + +void LLListLoadTask::listDownloaded() +{ + QByteArray data; + { + auto dlJob = listDownload; + auto filename = std::dynamic_pointer_cast(dlJob)->getTargetFilepath(); + QFile listFile(filename); + if (!listFile.open(QIODevice::ReadOnly)) + { + emitFailed("Failed to open the LiteLoader version list."); + return; + } + data = listFile.readAll(); + listFile.close(); + dlJob.reset(); + } + + QJsonParseError jsonError; + QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); + + if (jsonError.error != QJsonParseError::NoError) + { + emitFailed("Error parsing version list JSON:" + jsonError.errorString()); + return; + } + + if (!jsonDoc.isObject()) + { + emitFailed("Error parsing version list JSON: jsonDoc is not an object"); + return; + } + + const QJsonObject root = jsonDoc.object(); + + // Now, get the array of versions. + if (!root.value("versions").isObject()) + { + emitFailed("Error parsing version list JSON: missing 'versions' object"); + return; + } + + auto meta = root.value("meta").toObject(); + QString description = meta.value("description").toString(tr("This is a lightweight loader for mods that don't change game mechanics.")); + QString defaultUrl = meta.value("url").toString("http://dl.liteloader.com"); + QString authors = meta.value("authors").toString("Mumfrey"); + auto versions = root.value("versions").toObject(); + + QList tempList; + for (auto vIt = versions.begin(); vIt != versions.end(); ++vIt) + { + const QString mcVersion = vIt.key(); + QString latest; + const QJsonObject artefacts = vIt.value() + .toObject() + .value("artefacts") + .toObject() + .value("com.mumfrey:liteloader") + .toObject(); + QList perMcVersionList; + for (auto aIt = artefacts.begin(); aIt != artefacts.end(); ++aIt) + { + const QString identifier = aIt.key(); + const QJsonObject artefact = aIt.value().toObject(); + if (identifier == "latest") + { + latest = artefact.value("version").toString(); + continue; + } + LiteLoaderVersionPtr version(new LiteLoaderVersion()); + version->version = artefact.value("version").toString(); + version->file = artefact.value("file").toString(); + version->mcVersion = mcVersion; + version->md5 = artefact.value("md5").toString(); + version->timestamp = artefact.value("timestamp").toDouble(); + version->tweakClass = artefact.value("tweakClass").toString(); + version->authors = authors; + version->description = description; + version->defaultUrl = defaultUrl; + const QJsonArray libs = artefact.value("libraries").toArray(); + for (auto lIt = libs.begin(); lIt != libs.end(); ++lIt) + { + version->libraries.append((*lIt).toObject().value("name").toString()); + } + perMcVersionList.append(version); + } + for (auto version : perMcVersionList) + { + auto v = std::dynamic_pointer_cast(version); + v->isLatest = v->version == latest; + } + tempList.append(perMcVersionList); + } + m_list->updateListData(tempList); + + emitSucceeded(); +} diff --git a/logic/liteloader/LiteLoaderVersionList.h b/logic/liteloader/LiteLoaderVersionList.h new file mode 100644 index 00000000..aa35f1ca --- /dev/null +++ b/logic/liteloader/LiteLoaderVersionList.h @@ -0,0 +1,112 @@ +/* Copyright 2013 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/lists/BaseVersionList.h" +#include "logic/tasks/Task.h" +#include "logic/BaseVersion.h" +#include "logic/net/NetJob.h" + +class LLListLoadTask; +class QNetworkReply; + +class LiteLoaderVersion : public BaseVersion +{ +public: + QString descriptor() override + { + if (isLatest) + { + return QObject::tr("Latest"); + } + return QString(); + } + QString typeString() const override + { + return mcVersion; + } + QString name() override + { + return version; + } + + // important info + QString version; + QString file; + QString mcVersion; + QString md5; + int timestamp; + bool isLatest; + QString tweakClass; + QStringList libraries; + + // meta + QString defaultUrl; + QString description; + QString authors; +}; +typedef std::shared_ptr LiteLoaderVersionPtr; + +class LiteLoaderVersionList : public BaseVersionList +{ + Q_OBJECT +public: + friend class LLListLoadTask; + + explicit LiteLoaderVersionList(QObject *parent = 0); + + virtual Task *getLoadTask(); + virtual bool isLoaded(); + virtual const BaseVersionPtr at(int i) const; + virtual int count() const; + virtual void sort(); + + virtual BaseVersionPtr getLatestStable() const; + +protected: + QList m_vlist; + + bool m_loaded = false; + +protected +slots: + virtual void updateListData(QList versions); +}; + +class LLListLoadTask : public Task +{ + Q_OBJECT + +public: + explicit LLListLoadTask(LiteLoaderVersionList *vlist); + ~LLListLoadTask(); + + virtual void executeTask(); + +protected +slots: + void listDownloaded(); + void listFailed(); + +protected: + NetJobPtr listJob; + CacheDownloadPtr listDownload; + LiteLoaderVersionList *m_list; +}; diff --git a/logic/net/ForgeMirror.h b/logic/net/ForgeMirror.h deleted file mode 100644 index 2518dffe..00000000 --- a/logic/net/ForgeMirror.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once -#include - -struct ForgeMirror -{ - QString name; - QString logo_url; - QString website_url; - QString mirror_url; -}; \ No newline at end of file diff --git a/logic/net/ForgeMirrors.cpp b/logic/net/ForgeMirrors.cpp deleted file mode 100644 index b224306f..00000000 --- a/logic/net/ForgeMirrors.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include "MultiMC.h" -#include "ForgeMirrors.h" -#include "logger/QsLog.h" -#include -#include - -ForgeMirrors::ForgeMirrors(QList &libs, NetJobPtr parent_job, - QString mirrorlist) -{ - m_libs = libs; - m_parent_job = parent_job; - m_url = QUrl(mirrorlist); - m_status = Job_NotStarted; -} - -void ForgeMirrors::start() -{ - QLOG_INFO() << "Downloading " << m_url.toString(); - QNetworkRequest request(m_url); - request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); - auto worker = MMC->qnam(); - QNetworkReply *rep = worker->get(request); - - m_reply = std::shared_ptr(rep); - connect(rep, SIGNAL(downloadProgress(qint64, qint64)), - SLOT(downloadProgress(qint64, qint64))); - connect(rep, SIGNAL(finished()), SLOT(downloadFinished())); - connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), - SLOT(downloadError(QNetworkReply::NetworkError))); - connect(rep, SIGNAL(readyRead()), SLOT(downloadReadyRead())); -} - -void ForgeMirrors::downloadError(QNetworkReply::NetworkError error) -{ - // error happened during download. - QLOG_ERROR() << "Error getting URL:" << m_url.toString().toLocal8Bit() - << "Network error: " << error; - m_status = Job_Failed; -} - -void ForgeMirrors::downloadFinished() -{ - // if the download succeeded - if (m_status != Job_Failed) - { - // nothing went wrong... ? - parseMirrorList(); - return; - } - // else the download failed, we use a fixed list - else - { - m_status = Job_Finished; - m_reply.reset(); - deferToFixedList(); - return; - } -} - -void ForgeMirrors::deferToFixedList() -{ - m_mirrors.clear(); - m_mirrors.append( - {"Minecraft Forge", "http://files.minecraftforge.net/forge_logo.png", - "http://files.minecraftforge.net/", "http://files.minecraftforge.net/maven/"}); - m_mirrors.append({"Creeper Host", - "http://files.minecraftforge.net/forge_logo.png", - "https://www.creeperhost.net/link.php?id=1", - "http://new.creeperrepo.net/forge/maven/"}); - injectDownloads(); - emit succeeded(m_index_within_job); -} - -void ForgeMirrors::parseMirrorList() -{ - m_status = Job_Finished; - auto data = m_reply->readAll(); - m_reply.reset(); - auto dataLines = data.split('\n'); - for(auto line: dataLines) - { - auto elements = line.split('!'); - if (elements.size() == 4) - { - m_mirrors.append({elements[0],elements[1],elements[2],elements[3]}); - } - } - if(!m_mirrors.size()) - deferToFixedList(); - injectDownloads(); - emit succeeded(m_index_within_job); -} - -void ForgeMirrors::injectDownloads() -{ - // shuffle the mirrors randomly - std::random_device rd; - std::mt19937 rng(rd()); - std::shuffle(m_mirrors.begin(), m_mirrors.end(), rng); - - // tell parent to download the libs - for(auto lib: m_libs) - { - lib->setMirrors(m_mirrors); - m_parent_job->addNetAction(lib); - } -} - -void ForgeMirrors::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) -{ - m_total_progress = bytesTotal; - m_progress = bytesReceived; - emit progress(m_index_within_job, bytesReceived, bytesTotal); -} - -void ForgeMirrors::downloadReadyRead() -{ -} diff --git a/logic/net/ForgeMirrors.h b/logic/net/ForgeMirrors.h deleted file mode 100644 index 6784fba1..00000000 --- a/logic/net/ForgeMirrors.h +++ /dev/null @@ -1,58 +0,0 @@ -/* Copyright 2013 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 "NetAction.h" -#include "HttpMetaCache.h" -#include "ForgeXzDownload.h" -#include "NetJob.h" -#include -#include -typedef std::shared_ptr ForgeMirrorsPtr; - -class ForgeMirrors : public NetAction -{ - Q_OBJECT -public: - QList m_libs; - NetJobPtr m_parent_job; - QList m_mirrors; - -public: - explicit ForgeMirrors(QList &libs, NetJobPtr parent_job, - QString mirrorlist); - static ForgeMirrorsPtr make(QList &libs, NetJobPtr parent_job, - QString mirrorlist) - { - return ForgeMirrorsPtr(new ForgeMirrors(libs, parent_job, mirrorlist)); - } - virtual ~ForgeMirrors(){}; -protected -slots: - virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); - virtual void downloadError(QNetworkReply::NetworkError error); - virtual void downloadFinished(); - virtual void downloadReadyRead(); - -private: - void parseMirrorList(); - void deferToFixedList(); - void injectDownloads(); - -public -slots: - virtual void start(); -}; diff --git a/logic/net/ForgeXzDownload.cpp b/logic/net/ForgeXzDownload.cpp deleted file mode 100644 index 359ad858..00000000 --- a/logic/net/ForgeXzDownload.cpp +++ /dev/null @@ -1,389 +0,0 @@ -/* Copyright 2013 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 "MultiMC.h" -#include "ForgeXzDownload.h" -#include - -#include -#include -#include -#include -#include "logger/QsLog.h" - -ForgeXzDownload::ForgeXzDownload(QString relative_path, MetaEntryPtr entry) : NetAction() -{ - m_entry = entry; - m_target_path = entry->getFullPath(); - m_pack200_xz_file.setFileTemplate("./dl_temp.XXXXXX"); - m_status = Job_NotStarted; - m_url_path = relative_path; -} - -void ForgeXzDownload::setMirrors(QList &mirrors) -{ - m_mirror_index = 0; - m_mirrors = mirrors; - updateUrl(); -} - -void ForgeXzDownload::start() -{ - m_status = Job_InProgress; - if (!m_entry->stale) - { - m_status = Job_Finished; - emit succeeded(m_index_within_job); - return; - } - // can we actually create the real, final file? - if (!ensureFilePathExists(m_target_path)) - { - m_status = Job_Failed; - emit failed(m_index_within_job); - return; - } - if (m_mirrors.empty()) - { - m_status = Job_Failed; - emit failed(m_index_within_job); - return; - } - - QLOG_INFO() << "Downloading " << m_url.toString(); - QNetworkRequest request(m_url); - request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->etag.toLatin1()); - request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)"); - - auto worker = MMC->qnam(); - QNetworkReply *rep = worker->get(request); - - m_reply = std::shared_ptr(rep); - connect(rep, SIGNAL(downloadProgress(qint64, qint64)), - SLOT(downloadProgress(qint64, qint64))); - connect(rep, SIGNAL(finished()), SLOT(downloadFinished())); - connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), - SLOT(downloadError(QNetworkReply::NetworkError))); - connect(rep, SIGNAL(readyRead()), SLOT(downloadReadyRead())); -} - -void ForgeXzDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) -{ - m_total_progress = bytesTotal; - m_progress = bytesReceived; - emit progress(m_index_within_job, bytesReceived, bytesTotal); -} - -void ForgeXzDownload::downloadError(QNetworkReply::NetworkError error) -{ - // error happened during download. - // TODO: log the reason why - m_status = Job_Failed; -} - -void ForgeXzDownload::failAndTryNextMirror() -{ - m_status = Job_Failed; - int next = m_mirror_index + 1; - if(m_mirrors.size() == next) - m_mirror_index = 0; - else - m_mirror_index = next; - - updateUrl(); - emit failed(m_index_within_job); -} - -void ForgeXzDownload::updateUrl() -{ - QLOG_INFO() << "Updating URL for " << m_url_path; - for (auto possible : m_mirrors) - { - QLOG_INFO() << "Possible: " << possible.name << " : " << possible.mirror_url; - } - QString aggregate = m_mirrors[m_mirror_index].mirror_url + m_url_path + ".pack.xz"; - m_url = QUrl(aggregate); -} - -void ForgeXzDownload::downloadFinished() -{ - //TEST: defer to other possible mirrors (autofail the first one) - /* - QLOG_INFO() <<"dl " << index_within_job << " mirror " << m_mirror_index; - if( m_mirror_index == 0) - { - QLOG_INFO() <<"dl " << index_within_job << " AUTOFAIL"; - m_status = Job_Failed; - m_pack200_xz_file.close(); - m_pack200_xz_file.remove(); - m_reply.reset(); - failAndTryNextMirror(); - return; - } - */ - - // if the download succeeded - if (m_status != Job_Failed) - { - // nothing went wrong... - m_status = Job_Finished; - if (m_pack200_xz_file.isOpen()) - { - // we actually downloaded something! process and isntall it - decompressAndInstall(); - return; - } - else - { - // something bad happened -- on the local machine! - m_status = Job_Failed; - m_pack200_xz_file.remove(); - m_reply.reset(); - emit failed(m_index_within_job); - return; - } - } - // else the download failed - else - { - m_status = Job_Failed; - m_pack200_xz_file.close(); - m_pack200_xz_file.remove(); - m_reply.reset(); - failAndTryNextMirror(); - return; - } -} - -void ForgeXzDownload::downloadReadyRead() -{ - - if (!m_pack200_xz_file.isOpen()) - { - if (!m_pack200_xz_file.open()) - { - /* - * Can't open the file... the job failed - */ - m_reply->abort(); - emit failed(m_index_within_job); - return; - } - } - m_pack200_xz_file.write(m_reply->readAll()); -} - -#include "xz.h" -#include "unpack200.h" -#include - -const size_t buffer_size = 8196; - -void ForgeXzDownload::decompressAndInstall() -{ - // rewind the downloaded temp file - m_pack200_xz_file.seek(0); - // de-xz'd file - QTemporaryFile pack200_file("./dl_temp.XXXXXX"); - pack200_file.open(); - - bool xz_success = false; - // first, de-xz - { - uint8_t in[buffer_size]; - uint8_t out[buffer_size]; - struct xz_buf b; - struct xz_dec *s; - enum xz_ret ret; - xz_crc32_init(); - xz_crc64_init(); - s = xz_dec_init(XZ_DYNALLOC, 1 << 26); - if (s == nullptr) - { - xz_dec_end(s); - failAndTryNextMirror(); - return; - } - b.in = in; - b.in_pos = 0; - b.in_size = 0; - b.out = out; - b.out_pos = 0; - b.out_size = buffer_size; - while (!xz_success) - { - if (b.in_pos == b.in_size) - { - b.in_size = m_pack200_xz_file.read((char *)in, sizeof(in)); - b.in_pos = 0; - } - - ret = xz_dec_run(s, &b); - - if (b.out_pos == sizeof(out)) - { - if (pack200_file.write((char *)out, b.out_pos) != b.out_pos) - { - // msg = "Write error\n"; - xz_dec_end(s); - failAndTryNextMirror(); - return; - } - - b.out_pos = 0; - } - - if (ret == XZ_OK) - continue; - - if (ret == XZ_UNSUPPORTED_CHECK) - { - // unsupported check. this is OK, but we should log this - continue; - } - - if (pack200_file.write((char *)out, b.out_pos) != b.out_pos) - { - // write error - pack200_file.close(); - xz_dec_end(s); - return; - } - - switch (ret) - { - case XZ_STREAM_END: - xz_dec_end(s); - xz_success = true; - break; - - case XZ_MEM_ERROR: - QLOG_ERROR() << "Memory allocation failed\n"; - xz_dec_end(s); - failAndTryNextMirror(); - return; - - case XZ_MEMLIMIT_ERROR: - QLOG_ERROR() << "Memory usage limit reached\n"; - xz_dec_end(s); - failAndTryNextMirror(); - return; - - case XZ_FORMAT_ERROR: - QLOG_ERROR() << "Not a .xz file\n"; - xz_dec_end(s); - failAndTryNextMirror(); - return; - - case XZ_OPTIONS_ERROR: - QLOG_ERROR() << "Unsupported options in the .xz headers\n"; - xz_dec_end(s); - failAndTryNextMirror(); - return; - - case XZ_DATA_ERROR: - case XZ_BUF_ERROR: - QLOG_ERROR() << "File is corrupt\n"; - xz_dec_end(s); - failAndTryNextMirror(); - return; - - default: - QLOG_ERROR() << "Bug!\n"; - xz_dec_end(s); - failAndTryNextMirror(); - return; - } - } - } - m_pack200_xz_file.remove(); - - // revert pack200 - pack200_file.seek(0); - int handle_in = pack200_file.handle(); - // FIXME: dispose of file handles, pointers and the like. Ideally wrap in objects. - if(handle_in == -1) - { - QLOG_ERROR() << "Error reopening " << pack200_file.fileName(); - failAndTryNextMirror(); - return; - } - FILE * file_in = fdopen(handle_in,"r"); - if(!file_in) - { - QLOG_ERROR() << "Error reopening " << pack200_file.fileName(); - failAndTryNextMirror(); - return; - } - QFile qfile_out(m_target_path); - if(!qfile_out.open(QIODevice::WriteOnly)) - { - QLOG_ERROR() << "Error opening " << qfile_out.fileName(); - failAndTryNextMirror(); - return; - } - int handle_out = qfile_out.handle(); - if(handle_out == -1) - { - QLOG_ERROR() << "Error opening " << qfile_out.fileName(); - failAndTryNextMirror(); - return; - } - FILE * file_out = fdopen(handle_out,"w"); - if(!file_out) - { - QLOG_ERROR() << "Error opening " << qfile_out.fileName(); - failAndTryNextMirror(); - return; - } - try - { - unpack_200(file_in, file_out); - } - catch (std::runtime_error &err) - { - m_status = Job_Failed; - QLOG_ERROR() << "Error unpacking " << pack200_file.fileName() << " : " << err.what(); - QFile f(m_target_path); - if (f.exists()) - f.remove(); - failAndTryNextMirror(); - return; - } - pack200_file.remove(); - - QFile jar_file(m_target_path); - - if (!jar_file.open(QIODevice::ReadOnly)) - { - jar_file.remove(); - failAndTryNextMirror(); - return; - } - m_entry->md5sum = QCryptographicHash::hash(jar_file.readAll(), QCryptographicHash::Md5) - .toHex() - .constData(); - jar_file.close(); - - QFileInfo output_file_info(m_target_path); - m_entry->etag = m_reply->rawHeader("ETag").constData(); - m_entry->local_changed_timestamp = - output_file_info.lastModified().toUTC().toMSecsSinceEpoch(); - m_entry->stale = false; - MMC->metacache()->updateEntry(m_entry); - - m_reply.reset(); - emit succeeded(m_index_within_job); -} diff --git a/logic/net/ForgeXzDownload.h b/logic/net/ForgeXzDownload.h deleted file mode 100644 index 7bdfb6d9..00000000 --- a/logic/net/ForgeXzDownload.h +++ /dev/null @@ -1,66 +0,0 @@ -/* Copyright 2013 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 "NetAction.h" -#include "HttpMetaCache.h" -#include -#include -#include "ForgeMirror.h" - -typedef std::shared_ptr ForgeXzDownloadPtr; - -class ForgeXzDownload : public NetAction -{ - Q_OBJECT -public: - MetaEntryPtr m_entry; - /// if saving to file, use the one specified in this string - QString m_target_path; - /// this is the output file, if any - QTemporaryFile m_pack200_xz_file; - /// mirror index (NOT OPTICS, I SWEAR) - int m_mirror_index = 0; - /// list of mirrors to use. Mirror has the url base - QList m_mirrors; - /// path relative to the mirror base - QString m_url_path; - -public: - explicit ForgeXzDownload(QString relative_path, MetaEntryPtr entry); - static ForgeXzDownloadPtr make(QString relative_path, MetaEntryPtr entry) - { - return ForgeXzDownloadPtr(new ForgeXzDownload(relative_path, entry)); - } - virtual ~ForgeXzDownload(){}; - void setMirrors(QList & mirrors); - -protected -slots: - virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); - virtual void downloadError(QNetworkReply::NetworkError error); - virtual void downloadFinished(); - virtual void downloadReadyRead(); - -public -slots: - virtual void start(); - -private: - void decompressAndInstall(); - void failAndTryNextMirror(); - void updateUrl(); -}; diff --git a/logic/net/NetJob.h b/logic/net/NetJob.h index 2df8428b..66bf7fb6 100644 --- a/logic/net/NetJob.h +++ b/logic/net/NetJob.h @@ -21,7 +21,7 @@ #include "MD5EtagDownload.h" #include "CacheDownload.h" #include "HttpMetaCache.h" -#include "ForgeXzDownload.h" +//#include "logic/forge/ForgeXzDownload.h" #include "logic/tasks/ProgressProvider.h" class NetJob; -- cgit v1.2.3