From a1a06cc89f7f1d904a1b71d330d6129b866ff29b Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Wed, 22 Jan 2014 07:33:32 +0100 Subject: [PATCH 01/13] Derpstances. Everything renamed. Launching does not yet work. --- CMakeLists.txt | 36 +-- gui/MainWindow.cpp | 4 +- ...odEditDialog.cpp => DerpModEditDialog.cpp} | 114 ++----- ...SixModEditDialog.h => DerpModEditDialog.h} | 18 +- ...xModEditDialog.ui => DerpModEditDialog.ui} | 27 +- logic/BaseInstance.h | 2 +- ...SixFTBInstance.cpp => DerpFTBInstance.cpp} | 40 ++- ...{OneSixFTBInstance.h => DerpFTBInstance.h} | 10 +- .../{OneSixInstance.cpp => DerpInstance.cpp} | 161 ++++------ logic/{OneSixInstance.h => DerpInstance.h} | 29 +- .../{OneSixInstance_p.h => DerpInstance_p.h} | 15 +- logic/{OneSixLibrary.cpp => DerpLibrary.cpp} | 38 +-- logic/{OneSixLibrary.h => DerpLibrary.h} | 32 +- logic/{OneSixRule.cpp => DerpRule.cpp} | 4 +- logic/{OneSixRule.h => DerpRule.h} | 10 +- logic/{OneSixUpdate.cpp => DerpUpdate.cpp} | 58 ++-- logic/{OneSixUpdate.h => DerpUpdate.h} | 4 +- logic/DerpVersion.cpp | 164 ++++++++++ logic/DerpVersion.h | 110 +++++++ logic/DerpVersionBuilder.cpp | 279 ++++++++++++++++++ logic/DerpVersionBuilder.h | 43 +++ logic/ForgeInstaller.cpp | 22 +- logic/ForgeInstaller.h | 6 +- logic/InstanceFactory.cpp | 36 +-- logic/LegacyInstance.h | 2 +- logic/LiteLoaderInstaller.cpp | 25 +- logic/LiteLoaderInstaller.h | 8 +- logic/MinecraftVersion.h | 6 +- logic/NostalgiaInstance.cpp | 2 +- logic/NostalgiaInstance.h | 4 +- logic/OneSixVersion.cpp | 50 ++-- logic/OneSixVersion.h | 14 +- logic/lists/MinecraftVersionList.cpp | 6 +- 33 files changed, 920 insertions(+), 459 deletions(-) rename gui/dialogs/{OneSixModEditDialog.cpp => DerpModEditDialog.cpp} (69%) rename gui/dialogs/{OneSixModEditDialog.h => DerpModEditDialog.h} (80%) rename gui/dialogs/{OneSixModEditDialog.ui => DerpModEditDialog.ui} (91%) rename logic/{OneSixFTBInstance.cpp => DerpFTBInstance.cpp} (67%) rename logic/{OneSixFTBInstance.h => DerpFTBInstance.h} (56%) rename logic/{OneSixInstance.cpp => DerpInstance.cpp} (70%) rename logic/{OneSixInstance.h => DerpInstance.h} (76%) rename logic/{OneSixInstance_p.h => DerpInstance_p.h} (74%) rename logic/{OneSixLibrary.cpp => DerpLibrary.cpp} (87%) rename logic/{OneSixLibrary.h => DerpLibrary.h} (85%) rename logic/{OneSixRule.cpp => DerpRule.cpp} (98%) rename logic/{OneSixRule.h => DerpRule.h} (90%) rename logic/{OneSixUpdate.cpp => DerpUpdate.cpp} (88%) rename logic/{OneSixUpdate.h => DerpUpdate.h} (92%) create mode 100644 logic/DerpVersion.cpp create mode 100644 logic/DerpVersion.h create mode 100644 logic/DerpVersionBuilder.cpp create mode 100644 logic/DerpVersionBuilder.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b276cf8..43de626b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -297,8 +297,8 @@ 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/DerpModEditDialog.h +gui/dialogs/DerpModEditDialog.cpp gui/dialogs/ModEditDialogCommon.h gui/dialogs/ModEditDialogCommon.cpp gui/dialogs/EditNotesDialog.h @@ -405,32 +405,34 @@ logic/LegacyUpdate.cpp logic/LegacyForge.h logic/LegacyForge.cpp -# 1.6 instances -logic/OneSixInstance.h -logic/OneSixInstance.cpp -logic/OneSixInstance_p.h -logic/OneSixUpdate.h -logic/OneSixUpdate.cpp -logic/OneSixVersion.h -logic/OneSixVersion.cpp -logic/OneSixLibrary.h -logic/OneSixLibrary.cpp -logic/OneSixRule.h -logic/OneSixRule.cpp +# Derp instances +logic/DerpUpdate.h +logic/DerpUpdate.cpp +logic/DerpVersion.h +logic/DerpVersion.cpp +logic/DerpLibrary.h +logic/DerpLibrary.cpp +logic/DerpRule.h +logic/DerpRule.cpp logic/OpSys.h logic/OpSys.cpp logic/ForgeInstaller.h logic/ForgeInstaller.cpp logic/LiteLoaderInstaller.h logic/LiteLoaderInstaller.cpp +logic/DerpInstance.h +logic/DerpInstance.cpp +logic/DerpInstance_p.h +logic/DerpVersionBuilder.h +logic/DerpVersionBuilder.cpp # Nostalgia logic/NostalgiaInstance.h logic/NostalgiaInstance.cpp # FTB -logic/OneSixFTBInstance.h -logic/OneSixFTBInstance.cpp +logic/DerpFTBInstance.h +logic/DerpFTBInstance.cpp logic/LegacyFTBInstance.h logic/LegacyFTBInstance.cpp @@ -506,7 +508,7 @@ gui/dialogs/InstanceSettings.ui gui/dialogs/ProgressDialog.ui gui/dialogs/IconPickerDialog.ui gui/dialogs/LegacyModEditDialog.ui -gui/dialogs/OneSixModEditDialog.ui +gui/dialogs/DerpModEditDialog.ui gui/dialogs/EditNotesDialog.ui gui/dialogs/AccountListDialog.ui gui/dialogs/AccountSelectDialog.ui diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index ee9c3fad..ba394a94 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -84,7 +84,7 @@ #include "logic/BaseInstance.h" #include "logic/InstanceFactory.h" #include "logic/MinecraftProcess.h" -#include "logic/OneSixUpdate.h" +#include "logic/DerpUpdate.h" #include "logic/JavaUtils.h" #include "logic/NagUtils.h" #include "logic/SkinUtils.h" @@ -1257,7 +1257,7 @@ void MainWindow::on_actionChangeInstMCVersion_triggered() VersionSelectDialog vselect(m_selectedInstance->versionList().get(), tr("Change Minecraft version"), this); - vselect.setFilter(1, "OneSix"); + vselect.setFilter(1, "Derp"); if(!vselect.exec() || !vselect.selectedVersion()) return; diff --git a/gui/dialogs/OneSixModEditDialog.cpp b/gui/dialogs/DerpModEditDialog.cpp similarity index 69% rename from gui/dialogs/OneSixModEditDialog.cpp rename to gui/dialogs/DerpModEditDialog.cpp index 3982f17d..be17404c 100644 --- a/gui/dialogs/OneSixModEditDialog.cpp +++ b/gui/dialogs/DerpModEditDialog.cpp @@ -23,9 +23,9 @@ #include #include -#include "OneSixModEditDialog.h" +#include "DerpModEditDialog.h" #include "ModEditDialogCommon.h" -#include "ui_OneSixModEditDialog.h" +#include "ui_DerpModEditDialog.h" #include "gui/Platform.h" #include "gui/dialogs/CustomMessageBox.h" @@ -34,14 +34,14 @@ #include "gui/dialogs/ProgressDialog.h" #include "logic/ModList.h" -#include "logic/OneSixVersion.h" +#include "logic/DerpVersion.h" #include "logic/EnabledItemFilter.h" #include "logic/lists/ForgeVersionList.h" #include "logic/ForgeInstaller.h" #include "logic/LiteLoaderInstaller.h" -OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent) - : QDialog(parent), ui(new Ui::OneSixModEditDialog), m_inst(inst) +DerpModEditDialog::DerpModEditDialog(DerpInstance *inst, QWidget *parent) + : QDialog(parent), ui(new Ui::DerpModEditDialog), m_inst(inst) { MultiMCPlatform::fixWM_CLASS(this); ui->setupUi(this); @@ -81,64 +81,35 @@ OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent) ui->resPackTreeView->installEventFilter(this); m_resourcepacks->startWatching(); } + + connect(m_inst, &DerpInstance::versionReloaded, this, &DerpModEditDialog::updateVersionControls); } -OneSixModEditDialog::~OneSixModEditDialog() +DerpModEditDialog::~DerpModEditDialog() { m_mods->stopWatching(); m_resourcepacks->stopWatching(); delete ui; } -void OneSixModEditDialog::updateVersionControls() +void DerpModEditDialog::updateVersionControls() { bool customVersion = m_inst->versionIsCustom(); - ui->customizeBtn->setEnabled(!customVersion); - ui->revertBtn->setEnabled(customVersion); ui->forgeBtn->setEnabled(true); ui->liteloaderBtn->setEnabled(LiteLoaderInstaller(m_inst->intendedVersionId()).canApply()); ui->customEditorBtn->setEnabled(customVersion); } -void OneSixModEditDialog::disableVersionControls() +void DerpModEditDialog::disableVersionControls() { - ui->customizeBtn->setEnabled(false); - ui->revertBtn->setEnabled(false); ui->forgeBtn->setEnabled(false); ui->liteloaderBtn->setEnabled(false); ui->customEditorBtn->setEnabled(false); } -void OneSixModEditDialog::on_customizeBtn_clicked() +void DerpModEditDialog::on_customEditorBtn_clicked() { - if (m_inst->customizeVersion()) - { - m_version = m_inst->getFullVersion(); - main_model->setSourceModel(m_version.get()); - updateVersionControls(); - } -} - -void OneSixModEditDialog::on_revertBtn_clicked() -{ - auto response = CustomMessageBox::selectable( - this, tr("Revert?"), tr("Do you want to revert the " - "version of this instance to its original configuration?"), - QMessageBox::Question, QMessageBox::Yes | QMessageBox::No)->exec(); - if (response == QMessageBox::Yes) - { - if (m_inst->revertCustomVersion()) - { - m_version = m_inst->getFullVersion(); - main_model->setSourceModel(m_version.get()); - updateVersionControls(); - } - } -} - -void OneSixModEditDialog::on_customEditorBtn_clicked() -{ - if (m_inst->versionIsCustom()) + if (QDir(m_inst->instanceRoot()).exists("custom.json")) { if (!MMC->openJsonEditor(m_inst->instanceRoot() + "/custom.json")) { @@ -147,40 +118,12 @@ void OneSixModEditDialog::on_customEditorBtn_clicked() } } -void OneSixModEditDialog::on_forgeBtn_clicked() +void DerpModEditDialog::on_forgeBtn_clicked() { VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this); vselect.setFilter(1, m_inst->currentVersionId()); if (vselect.exec() && vselect.selectedVersion()) { - if (m_inst->versionIsCustom()) - { - auto reply = QMessageBox::question( - this, tr("Revert?"), - tr("This will revert any " - "changes you did to the version up to this point. Is that " - "OK?"), - QMessageBox::Yes | QMessageBox::No); - if (reply == QMessageBox::Yes) - { - m_inst->revertCustomVersion(); - m_inst->customizeVersion(); - { - m_version = m_inst->getFullVersion(); - main_model->setSourceModel(m_version.get()); - updateVersionControls(); - } - } - else - return; - } - else - { - m_inst->customizeVersion(); - m_version = m_inst->getFullVersion(); - main_model->setSourceModel(m_version.get()); - updateVersionControls(); - } ForgeVersionPtr forgeVersion = std::dynamic_pointer_cast(vselect.selectedVersion()); if (!forgeVersion) @@ -220,7 +163,7 @@ void OneSixModEditDialog::on_forgeBtn_clicked() } } -void OneSixModEditDialog::on_liteloaderBtn_clicked() +void DerpModEditDialog::on_liteloaderBtn_clicked() { LiteLoaderInstaller liteloader(m_inst->intendedVersionId()); if (!liteloader.canApply()) @@ -231,13 +174,6 @@ void OneSixModEditDialog::on_liteloaderBtn_clicked() "into this version of Minecraft")); return; } - if (!m_inst->versionIsCustom()) - { - m_inst->customizeVersion(); - m_version = m_inst->getFullVersion(); - main_model->setSourceModel(m_version.get()); - updateVersionControls(); - } if (!liteloader.apply(m_version)) { QMessageBox::critical( @@ -246,7 +182,7 @@ void OneSixModEditDialog::on_liteloaderBtn_clicked() } } -bool OneSixModEditDialog::loaderListFilter(QKeyEvent *keyEvent) +bool DerpModEditDialog::loaderListFilter(QKeyEvent *keyEvent) { switch (keyEvent->key()) { @@ -262,7 +198,7 @@ bool OneSixModEditDialog::loaderListFilter(QKeyEvent *keyEvent) return QDialog::eventFilter(ui->loaderModTreeView, keyEvent); } -bool OneSixModEditDialog::resourcePackListFilter(QKeyEvent *keyEvent) +bool DerpModEditDialog::resourcePackListFilter(QKeyEvent *keyEvent) { switch (keyEvent->key()) { @@ -278,7 +214,7 @@ bool OneSixModEditDialog::resourcePackListFilter(QKeyEvent *keyEvent) return QDialog::eventFilter(ui->resPackTreeView, keyEvent); } -bool OneSixModEditDialog::eventFilter(QObject *obj, QEvent *ev) +bool DerpModEditDialog::eventFilter(QObject *obj, QEvent *ev) { if (ev->type() != QEvent::KeyPress) { @@ -292,12 +228,12 @@ bool OneSixModEditDialog::eventFilter(QObject *obj, QEvent *ev) return QDialog::eventFilter(obj, ev); } -void OneSixModEditDialog::on_buttonBox_rejected() +void DerpModEditDialog::on_buttonBox_rejected() { close(); } -void OneSixModEditDialog::on_addModBtn_clicked() +void DerpModEditDialog::on_addModBtn_clicked() { QStringList fileNames = QFileDialog::getOpenFileNames( this, QApplication::translate("LegacyModEditDialog", "Select Loader Mods")); @@ -308,7 +244,7 @@ void OneSixModEditDialog::on_addModBtn_clicked() m_mods->startWatching(); } } -void OneSixModEditDialog::on_rmModBtn_clicked() +void DerpModEditDialog::on_rmModBtn_clicked() { int first, last; auto list = ui->loaderModTreeView->selectionModel()->selectedRows(); @@ -319,12 +255,12 @@ void OneSixModEditDialog::on_rmModBtn_clicked() m_mods->deleteMods(first, last); m_mods->startWatching(); } -void OneSixModEditDialog::on_viewModBtn_clicked() +void DerpModEditDialog::on_viewModBtn_clicked() { openDirInDefaultProgram(m_inst->loaderModsDir(), true); } -void OneSixModEditDialog::on_addResPackBtn_clicked() +void DerpModEditDialog::on_addResPackBtn_clicked() { QStringList fileNames = QFileDialog::getOpenFileNames( this, QApplication::translate("LegacyModEditDialog", "Select Resource Packs")); @@ -335,7 +271,7 @@ void OneSixModEditDialog::on_addResPackBtn_clicked() m_resourcepacks->startWatching(); } } -void OneSixModEditDialog::on_rmResPackBtn_clicked() +void DerpModEditDialog::on_rmResPackBtn_clicked() { int first, last; auto list = ui->resPackTreeView->selectionModel()->selectedRows(); @@ -346,12 +282,12 @@ void OneSixModEditDialog::on_rmResPackBtn_clicked() m_resourcepacks->deleteMods(first, last); m_resourcepacks->startWatching(); } -void OneSixModEditDialog::on_viewResPackBtn_clicked() +void DerpModEditDialog::on_viewResPackBtn_clicked() { openDirInDefaultProgram(m_inst->resourcePacksDir(), true); } -void OneSixModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previous) +void DerpModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previous) { if (!current.isValid()) { diff --git a/gui/dialogs/OneSixModEditDialog.h b/gui/dialogs/DerpModEditDialog.h similarity index 80% rename from gui/dialogs/OneSixModEditDialog.h rename to gui/dialogs/DerpModEditDialog.h index 2510c59c..e9e61c65 100644 --- a/gui/dialogs/OneSixModEditDialog.h +++ b/gui/dialogs/DerpModEditDialog.h @@ -16,21 +16,21 @@ #pragma once #include -#include +#include class EnabledItemFilter; namespace Ui { -class OneSixModEditDialog; +class DerpModEditDialog; } -class OneSixModEditDialog : public QDialog +class DerpModEditDialog : public QDialog { Q_OBJECT public: - explicit OneSixModEditDialog(OneSixInstance *inst, QWidget *parent = 0); - virtual ~OneSixModEditDialog(); + explicit DerpModEditDialog(DerpInstance *inst, QWidget *parent = 0); + virtual ~DerpModEditDialog(); private slots: @@ -45,8 +45,6 @@ slots: void on_buttonBox_rejected(); void on_forgeBtn_clicked(); void on_liteloaderBtn_clicked(); - void on_customizeBtn_clicked(); - void on_revertBtn_clicked(); void on_customEditorBtn_clicked(); void updateVersionControls(); void disableVersionControls(); @@ -57,12 +55,12 @@ protected: bool resourcePackListFilter(QKeyEvent *ev); private: - Ui::OneSixModEditDialog *ui; - std::shared_ptr m_version; + Ui::DerpModEditDialog *ui; + std::shared_ptr m_version; std::shared_ptr m_mods; std::shared_ptr m_resourcepacks; EnabledItemFilter *main_model; - OneSixInstance *m_inst; + DerpInstance *m_inst; public slots: void loaderCurrent(QModelIndex current, QModelIndex previous); diff --git a/gui/dialogs/OneSixModEditDialog.ui b/gui/dialogs/DerpModEditDialog.ui similarity index 91% rename from gui/dialogs/OneSixModEditDialog.ui rename to gui/dialogs/DerpModEditDialog.ui index 899e0cbf..7aaf1564 100644 --- a/gui/dialogs/OneSixModEditDialog.ui +++ b/gui/dialogs/DerpModEditDialog.ui @@ -1,7 +1,7 @@ - OneSixModEditDialog - + DerpModEditDialog + 0 @@ -84,29 +84,6 @@ - - - - Create an customized copy of the base version - - - Customize - - - - - - - false - - - Revert to original base version - - - Revert - - - diff --git a/logic/BaseInstance.h b/logic/BaseInstance.h index a861e9b2..79640c84 100644 --- a/logic/BaseInstance.h +++ b/logic/BaseInstance.h @@ -27,7 +27,7 @@ class QDialog; class Task; class MinecraftProcess; -class OneSixUpdate; +class DerpUpdate; class InstanceList; class BaseInstancePrivate; diff --git a/logic/OneSixFTBInstance.cpp b/logic/DerpFTBInstance.cpp similarity index 67% rename from logic/OneSixFTBInstance.cpp rename to logic/DerpFTBInstance.cpp index e50a5b53..f9aeeca0 100644 --- a/logic/OneSixFTBInstance.cpp +++ b/logic/DerpFTBInstance.cpp @@ -1,17 +1,17 @@ -#include "OneSixFTBInstance.h" +#include "DerpFTBInstance.h" -#include "OneSixVersion.h" -#include "OneSixLibrary.h" +#include "DerpVersion.h" +#include "DerpLibrary.h" #include "tasks/SequentialTask.h" #include "ForgeInstaller.h" #include "lists/ForgeVersionList.h" #include "MultiMC.h" -class OneSixFTBInstanceForge : public Task +class DerpFTBInstanceForge : public Task { Q_OBJECT public: - explicit OneSixFTBInstanceForge(const QString &version, OneSixFTBInstance *inst, QObject *parent = 0) : + explicit DerpFTBInstanceForge(const QString &version, DerpFTBInstance *inst, QObject *parent = 0) : Task(parent), instance(inst), version("Forge " + version) { } @@ -38,7 +38,7 @@ public: fjob = new NetJob("Forge download"); fjob->addNetAction(CacheDownload::make(forgeVersion->installer_url, entry)); connect(fjob, &NetJob::failed, [this](){emitFailed(m_failReason);}); - connect(fjob, &NetJob::succeeded, this, &OneSixFTBInstanceForge::installForge); + connect(fjob, &NetJob::succeeded, this, &DerpFTBInstanceForge::installForge); connect(fjob, &NetJob::progress, [this](qint64 c, qint64 total){ setProgress(100 * c / total); }); fjob->start(); } @@ -60,8 +60,6 @@ slots: emitFailed(tr("Couldn't load the version config")); return; } - instance->revertCustomVersion(); - instance->customizeVersion(); auto version = instance->getFullVersion(); if (!forge.apply(version)) { @@ -72,41 +70,41 @@ slots: } private: - OneSixFTBInstance *instance; + DerpFTBInstance *instance; QString version; ForgeVersionPtr forgeVersion; MetaEntryPtr entry; NetJob *fjob; }; -OneSixFTBInstance::OneSixFTBInstance(const QString &rootDir, SettingsObject *settings, QObject *parent) : - OneSixInstance(rootDir, settings, parent) +DerpFTBInstance::DerpFTBInstance(const QString &rootDir, SettingsObject *settings, QObject *parent) : + DerpInstance(rootDir, settings, parent) { QFile f(QDir(minecraftRoot()).absoluteFilePath("pack.json")); if (f.open(QFile::ReadOnly)) { QString data = QString::fromUtf8(f.readAll()); QRegularExpressionMatch match = QRegularExpression("net.minecraftforge:minecraftforge:[\\.\\d]*").match(data); - m_forge.reset(new OneSixLibrary(match.captured())); + m_forge.reset(new DerpLibrary(match.captured())); m_forge->finalize(); } } -QString OneSixFTBInstance::id() const +QString DerpFTBInstance::id() const { return "FTB/" + BaseInstance::id(); } -QString OneSixFTBInstance::getStatusbarDescription() +QString DerpFTBInstance::getStatusbarDescription() { - return "OneSix FTB: " + intendedVersionId(); + return "Derp FTB: " + intendedVersionId(); } -bool OneSixFTBInstance::menuActionEnabled(QString action_name) const +bool DerpFTBInstance::menuActionEnabled(QString action_name) const { return false; } -std::shared_ptr OneSixFTBInstance::doUpdate(bool only_prepare) +std::shared_ptr DerpFTBInstance::doUpdate(bool only_prepare) { std::shared_ptr task; task.reset(new SequentialTask(this)); @@ -114,12 +112,12 @@ std::shared_ptr OneSixFTBInstance::doUpdate(bool only_prepare) { task->addTask(std::shared_ptr(MMC->forgelist()->getLoadTask())); } - task->addTask(OneSixInstance::doUpdate(only_prepare)); - task->addTask(std::shared_ptr(new OneSixFTBInstanceForge(m_forge->version(), this, this))); + task->addTask(DerpInstance::doUpdate(only_prepare)); + task->addTask(std::shared_ptr(new DerpFTBInstanceForge(m_forge->version(), this, this))); //FIXME: yes. this may appear dumb. but the previous step can change the list, so we do it all again. //TODO: Add a graph task. Construct graphs of tasks so we may capture the logic properly. - task->addTask(OneSixInstance::doUpdate(only_prepare)); + task->addTask(DerpInstance::doUpdate(only_prepare)); return task; } -#include "OneSixFTBInstance.moc" +#include "DerpFTBInstance.moc" diff --git a/logic/OneSixFTBInstance.h b/logic/DerpFTBInstance.h similarity index 56% rename from logic/OneSixFTBInstance.h rename to logic/DerpFTBInstance.h index dc028819..c16998bf 100644 --- a/logic/OneSixFTBInstance.h +++ b/logic/DerpFTBInstance.h @@ -1,14 +1,14 @@ #pragma once -#include "OneSixInstance.h" +#include "DerpInstance.h" -class OneSixLibrary; +class DerpLibrary; -class OneSixFTBInstance : public OneSixInstance +class DerpFTBInstance : public DerpInstance { Q_OBJECT public: - explicit OneSixFTBInstance(const QString &rootDir, SettingsObject *settings, + explicit DerpFTBInstance(const QString &rootDir, SettingsObject *settings, QObject *parent = 0); virtual QString getStatusbarDescription(); virtual bool menuActionEnabled(QString action_name) const; @@ -18,5 +18,5 @@ public: virtual QString id() const; private: - std::shared_ptr m_forge; + std::shared_ptr m_forge; }; diff --git a/logic/OneSixInstance.cpp b/logic/DerpInstance.cpp similarity index 70% rename from logic/OneSixInstance.cpp rename to logic/DerpInstance.cpp index 3cfc1c76..31ed7c95 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/DerpInstance.cpp @@ -13,37 +13,35 @@ * limitations under the License. */ -#include "MultiMC.h" -#include "OneSixInstance.h" -#include "OneSixInstance_p.h" -#include "OneSixUpdate.h" -#include "MinecraftProcess.h" -#include "OneSixVersion.h" -#include "JavaChecker.h" -#include "logic/icons/IconList.h" +#include "DerpInstance.h" -#include -#include -#include -#include -#include "gui/dialogs/OneSixModEditDialog.h" -#include "logger/QsLog.h" -#include "logic/assets/AssetsUtils.h" #include -OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *setting_obj, - QObject *parent) - : BaseInstance(new OneSixInstancePrivate(), rootDir, setting_obj, parent) +#include "DerpInstance_p.h" +#include "DerpUpdate.h" +#include "DerpVersion.h" +#include "pathutils.h" +#include "logger/QsLog.h" +#include "assets/AssetsUtils.h" +#include "MultiMC.h" +#include "icons/IconList.h" +#include "MinecraftProcess.h" +#include "gui/dialogs/DerpModEditDialog.h" + +DerpInstance::DerpInstance(const QString &rootDir, SettingsObject *settings, QObject *parent) + : BaseInstance(new DerpInstancePrivate(), rootDir, settings, parent) { - I_D(OneSixInstance); + I_D(DerpInstance); d->m_settings->registerSetting("IntendedVersion", ""); d->m_settings->registerSetting("ShouldUpdate", false); + d->version.reset(new DerpVersion(this, this)); reloadFullVersion(); } -std::shared_ptr OneSixInstance::doUpdate(bool only_prepare) + +std::shared_ptr DerpInstance::doUpdate(bool only_prepare) { - return std::shared_ptr(new OneSixUpdate(this, only_prepare)); + return std::shared_ptr(new DerpUpdate(this, only_prepare)); } QString replaceTokensIn(QString text, QMap with) @@ -70,7 +68,7 @@ QString replaceTokensIn(QString text, QMap with) return result; } -QDir OneSixInstance::reconstructAssets(std::shared_ptr version) +QDir DerpInstance::reconstructAssets(std::shared_ptr version) { QDir assetsDir = QDir("assets/"); QDir indexDir = QDir(PathCombine(assetsDir.path(), "indexes")); @@ -130,9 +128,9 @@ QDir OneSixInstance::reconstructAssets(std::shared_ptr version) return virtualRoot; } -QStringList OneSixInstance::processMinecraftArgs(MojangAccountPtr account) +QStringList DerpInstance::processMinecraftArgs(MojangAccountPtr account) { - I_D(OneSixInstance); + I_D(DerpInstance); auto version = d->version; QString args_pattern = version->minecraftArguments; @@ -182,9 +180,9 @@ QStringList OneSixInstance::processMinecraftArgs(MojangAccountPtr account) return parts; } -MinecraftProcess *OneSixInstance::prepareForLaunch(MojangAccountPtr account) +MinecraftProcess *DerpInstance::prepareForLaunch(MojangAccountPtr account) { - I_D(OneSixInstance); + I_D(DerpInstance); QIcon icon = MMC->icons()->getIcon(iconKey()); auto pixmap = icon.pixmap(128, 128); @@ -229,7 +227,9 @@ MinecraftProcess *OneSixInstance::prepareForLaunch(MojangAccountPtr account) QDir natives_dir(PathCombine(instanceRoot(), "natives/")); launchScript += "windowTitle " + windowTitle() + "\n"; launchScript += "natives " + natives_dir.absolutePath() + "\n"; - launchScript += "launch onesix\n"; + launchScript += "launch onesix"; + + qDebug() << launchScript; // create the process and set its parameters MinecraftProcess *proc = new MinecraftProcess(this); @@ -239,16 +239,16 @@ MinecraftProcess *OneSixInstance::prepareForLaunch(MojangAccountPtr account) return proc; } -void OneSixInstance::cleanupAfterRun() +void DerpInstance::cleanupAfterRun() { QString target_dir = PathCombine(instanceRoot(), "natives/"); QDir dir(target_dir); dir.removeRecursively(); } -std::shared_ptr OneSixInstance::loaderModList() +std::shared_ptr DerpInstance::loaderModList() { - I_D(OneSixInstance); + I_D(DerpInstance); if (!d->loader_mod_list) { d->loader_mod_list.reset(new ModList(loaderModsDir())); @@ -257,9 +257,9 @@ std::shared_ptr OneSixInstance::loaderModList() return d->loader_mod_list; } -std::shared_ptr OneSixInstance::resourcePackList() +std::shared_ptr DerpInstance::resourcePackList() { - I_D(OneSixInstance); + I_D(DerpInstance); if (!d->resource_pack_list) { d->resource_pack_list.reset(new ModList(resourcePacksDir())); @@ -268,34 +268,32 @@ std::shared_ptr OneSixInstance::resourcePackList() return d->resource_pack_list; } -QDialog *OneSixInstance::createModEditDialog(QWidget *parent) +QDialog *DerpInstance::createModEditDialog(QWidget *parent) { - return new OneSixModEditDialog(this, parent); + return new DerpModEditDialog(this, parent); } -bool OneSixInstance::setIntendedVersionId(QString version) +bool DerpInstance::setIntendedVersionId(QString version) { settings().set("IntendedVersion", version); setShouldUpdate(true); - auto pathCustom = PathCombine(instanceRoot(), "custom.json"); auto pathOrig = PathCombine(instanceRoot(), "version.json"); - QFile::remove(pathCustom); QFile::remove(pathOrig); reloadFullVersion(); return true; } -QString OneSixInstance::intendedVersionId() const +QString DerpInstance::intendedVersionId() const { return settings().get("IntendedVersion").toString(); } -void OneSixInstance::setShouldUpdate(bool val) +void DerpInstance::setShouldUpdate(bool val) { settings().set("ShouldUpdate", val); } -bool OneSixInstance::shouldUpdate() const +bool DerpInstance::shouldUpdate() const { QVariant var = settings().get("ShouldUpdate"); if (!var.isValid() || var.toBool() == false) @@ -305,94 +303,53 @@ bool OneSixInstance::shouldUpdate() const return true; } -bool OneSixInstance::versionIsCustom() +bool DerpInstance::versionIsCustom() { - QString verpath_custom = PathCombine(instanceRoot(), "custom.json"); - QFile versionfile(verpath_custom); - return versionfile.exists(); + QDir patches(PathCombine(instanceRoot(), "patches/")); + return QFile::exists(PathCombine(instanceRoot(), "custom.json")) + || (patches.exists() && patches.count() >= 0); } -QString OneSixInstance::currentVersionId() const +QString DerpInstance::currentVersionId() const { return intendedVersionId(); } -bool OneSixInstance::customizeVersion() +bool DerpInstance::reloadFullVersion(QWidget *widgetParent) { - if (!versionIsCustom()) - { - auto pathCustom = PathCombine(instanceRoot(), "custom.json"); - auto pathOrig = PathCombine(instanceRoot(), "version.json"); - QFile::copy(pathOrig, pathCustom); - return reloadFullVersion(); - } - else - return true; + I_D(DerpInstance); + + bool ret = d->version->reload(widgetParent); + emit versionReloaded(); + return ret; } -bool OneSixInstance::revertCustomVersion() +std::shared_ptr DerpInstance::getFullVersion() { - if (versionIsCustom()) - { - auto path = PathCombine(instanceRoot(), "custom.json"); - QFile::remove(path); - return reloadFullVersion(); - } - else - return true; -} - -bool OneSixInstance::reloadFullVersion() -{ - I_D(OneSixInstance); - - QString verpath = PathCombine(instanceRoot(), "version.json"); - { - QString verpath_custom = PathCombine(instanceRoot(), "custom.json"); - QFile versionfile(verpath_custom); - if (versionfile.exists()) - verpath = verpath_custom; - } - - auto version = OneSixVersion::fromFile(verpath); - if (version) - { - d->version = version; - return true; - } - else - { - d->version.reset(); - return false; - } -} - -std::shared_ptr OneSixInstance::getFullVersion() -{ - I_D(OneSixInstance); + I_D(DerpInstance); return d->version; } -QString OneSixInstance::defaultBaseJar() const +QString DerpInstance::defaultBaseJar() const { return "versions/" + intendedVersionId() + "/" + intendedVersionId() + ".jar"; } -QString OneSixInstance::defaultCustomBaseJar() const +QString DerpInstance::defaultCustomBaseJar() const { return PathCombine(instanceRoot(), "custom.jar"); } -bool OneSixInstance::menuActionEnabled(QString action_name) const +bool DerpInstance::menuActionEnabled(QString action_name) const { if (action_name == "actionChangeInstLWJGLVersion") return false; return true; } -QString OneSixInstance::getStatusbarDescription() +QString DerpInstance::getStatusbarDescription() { - QString descr = "One Six : " + intendedVersionId(); + QString descr = "Derp : " + intendedVersionId(); if (versionIsCustom()) { descr + " (custom)"; @@ -400,17 +357,17 @@ QString OneSixInstance::getStatusbarDescription() return descr; } -QString OneSixInstance::loaderModsDir() const +QString DerpInstance::loaderModsDir() const { return PathCombine(minecraftRoot(), "mods"); } -QString OneSixInstance::resourcePacksDir() const +QString DerpInstance::resourcePacksDir() const { return PathCombine(minecraftRoot(), "resourcepacks"); } -QString OneSixInstance::instanceConfigFolder() const +QString DerpInstance::instanceConfigFolder() const { return PathCombine(minecraftRoot(), "config"); } diff --git a/logic/OneSixInstance.h b/logic/DerpInstance.h similarity index 76% rename from logic/OneSixInstance.h rename to logic/DerpInstance.h index f869e345..37d3df52 100644 --- a/logic/OneSixInstance.h +++ b/logic/DerpInstance.h @@ -15,21 +15,17 @@ #pragma once -#include -#include - #include "BaseInstance.h" -class OneSixVersion; -class Task; -class ModList; +#include "DerpVersion.h" +#include "ModList.h" -class OneSixInstance : public BaseInstance +class DerpInstance : public BaseInstance { Q_OBJECT public: - explicit OneSixInstance(const QString &rootDir, SettingsObject *settings, - QObject *parent = 0); + explicit DerpInstance(const QString &rootDir, SettingsObject *settings, + QObject *parent = 0); ////// Mod Lists ////// std::shared_ptr loaderModList(); @@ -55,14 +51,10 @@ public: virtual QDialog *createModEditDialog(QWidget *parent) override; - /// reload the full version json file. return true on success! - bool reloadFullVersion(); + /// reload the full version json files. return true on success! + bool reloadFullVersion(QWidget *widgetParent = 0); /// get the current full version info - std::shared_ptr getFullVersion(); - /// revert the current custom version back to base - bool revertCustomVersion(); - /// customize the current base version - bool customizeVersion(); + std::shared_ptr getFullVersion(); /// is the current version original, or custom? virtual bool versionIsCustom() override; @@ -72,7 +64,10 @@ public: virtual bool menuActionEnabled(QString action_name) const override; virtual QString getStatusbarDescription() override; +signals: + void versionReloaded(); + private: QStringList processMinecraftArgs(MojangAccountPtr account); - QDir reconstructAssets(std::shared_ptr version); + QDir reconstructAssets(std::shared_ptr version); }; diff --git a/logic/OneSixInstance_p.h b/logic/DerpInstance_p.h similarity index 74% rename from logic/OneSixInstance_p.h rename to logic/DerpInstance_p.h index 6b7ea431..41f7b62d 100644 --- a/logic/OneSixInstance_p.h +++ b/logic/DerpInstance_p.h @@ -15,16 +15,13 @@ #pragma once -#include +#include "BaseInstance_p.h" +#include "DerpVersion.h" +#include "ModList.h" -#include "logic/BaseInstance_p.h" -#include "logic/OneSixVersion.h" -#include "logic/OneSixLibrary.h" -#include "logic/ModList.h" - -struct OneSixInstancePrivate : public BaseInstancePrivate +struct DerpInstancePrivate : public BaseInstancePrivate { - std::shared_ptr version; + std::shared_ptr version; std::shared_ptr loader_mod_list; std::shared_ptr resource_pack_list; -}; \ No newline at end of file +}; diff --git a/logic/OneSixLibrary.cpp b/logic/DerpLibrary.cpp similarity index 87% rename from logic/OneSixLibrary.cpp rename to logic/DerpLibrary.cpp index 7b80d5e7..ba4d516b 100644 --- a/logic/OneSixLibrary.cpp +++ b/logic/DerpLibrary.cpp @@ -15,15 +15,15 @@ #include -#include "OneSixLibrary.h" -#include "OneSixRule.h" +#include "DerpLibrary.h" +#include "DerpRule.h" #include "OpSys.h" #include "logic/net/URLConstants.h" #include #include #include "logger/QsLog.h" -void OneSixLibrary::finalize() +void DerpLibrary::finalize() { QStringList parts = m_name.split(':'); QString relative = parts[0]; @@ -76,67 +76,67 @@ void OneSixLibrary::finalize() } } -void OneSixLibrary::setName(QString name) +void DerpLibrary::setName(const QString &name) { m_name = name; } -void OneSixLibrary::setBaseUrl(QString base_url) +void DerpLibrary::setBaseUrl(const QString &base_url) { m_base_url = base_url; } -void OneSixLibrary::setIsNative() +void DerpLibrary::setIsNative() { m_is_native = true; } -void OneSixLibrary::addNative(OpSys os, QString suffix) +void DerpLibrary::addNative(OpSys os, const QString &suffix) { m_is_native = true; m_native_suffixes[os] = suffix; } -void OneSixLibrary::setRules(QList> rules) +void DerpLibrary::setRules(QList> rules) { m_rules = rules; } -bool OneSixLibrary::isActive() +bool DerpLibrary::isActive() const { return m_is_active; } -bool OneSixLibrary::isNative() +bool DerpLibrary::isNative() const { return m_is_native; } -QString OneSixLibrary::downloadUrl() +QString DerpLibrary::downloadUrl() const { if (m_absolute_url.size()) return m_absolute_url; return m_download_url; } -QString OneSixLibrary::storagePath() +QString DerpLibrary::storagePath() const { return m_storage_path; } -void OneSixLibrary::setAbsoluteUrl(QString absolute_url) +void DerpLibrary::setAbsoluteUrl(const QString &absolute_url) { m_absolute_url = absolute_url; } -QString OneSixLibrary::absoluteUrl() +QString DerpLibrary::absoluteUrl() const { return m_absolute_url; } -void OneSixLibrary::setHint(QString hint) +void DerpLibrary::setHint(const QString &hint) { m_hint = hint; } -QString OneSixLibrary::hint() +QString DerpLibrary::hint() const { return m_hint; } -bool OneSixLibrary::filesExist() +bool DerpLibrary::filesExist() { QString storage = storagePath(); if (storage.contains("${arch}")) @@ -167,7 +167,7 @@ bool OneSixLibrary::filesExist() return true; } -bool OneSixLibrary::extractTo(QString target_dir) +bool DerpLibrary::extractTo(QString target_dir) { QString storage = storagePath(); if (storage.contains("${arch}")) @@ -220,7 +220,7 @@ bool OneSixLibrary::extractTo(QString target_dir) return true; } -QJsonObject OneSixLibrary::toJson() +QJsonObject DerpLibrary::toJson() { QJsonObject libRoot; libRoot.insert("name", m_name); diff --git a/logic/OneSixLibrary.h b/logic/DerpLibrary.h similarity index 85% rename from logic/OneSixLibrary.h rename to logic/DerpLibrary.h index 227cdbef..d1cee843 100644 --- a/logic/OneSixLibrary.h +++ b/logic/DerpLibrary.h @@ -26,7 +26,7 @@ class Rule; -class OneSixLibrary +class DerpLibrary { private: // basic values used internally (so far) @@ -63,7 +63,7 @@ public: public: /// Constructor - OneSixLibrary(QString name) + DerpLibrary(const QString &name) { m_name = name; } @@ -84,48 +84,48 @@ public: void finalize(); /// Set the library composite name - void setName(QString name); + void setName(const QString &name); /// get a decent-looking name - QString name() + QString name() const { return m_decentname; } /// get a decent-looking version - QString version() + QString version() const { return m_decentversion; } /// what kind of library is it? (for display) - QString type() + QString type() const { return m_decenttype; } /// Set the url base for downloads - void setBaseUrl(QString base_url); + void setBaseUrl(const QString &base_url); /// Call this to mark the library as 'native' (it's a zip archive with DLLs) void setIsNative(); /// Attach a name suffix to the specified OS native - void addNative(OpSys os, QString suffix); + void addNative(OpSys os, const QString &suffix); /// Set the load rules void setRules(QList> rules); /// Returns true if the library should be loaded (or extracted, in case of natives) - bool isActive(); + bool isActive() const; /// Returns true if the library is native - bool isNative(); + bool isNative() const; /// Get the URL to download the library from - QString downloadUrl(); + QString downloadUrl() const; /// Get the relative path where the library should be saved - QString storagePath(); + QString storagePath() const; /// set an absolute URL for the library. This is an MMC extension. - void setAbsoluteUrl(QString absolute_url); - QString absoluteUrl(); + void setAbsoluteUrl(const QString &absolute_url); + QString absoluteUrl() const; /// set a hint about how to treat the library. This is an MMC extension. - void setHint(QString hint); - QString hint(); + void setHint(const QString &hint); + QString hint() const; bool extractTo(QString target_dir); bool filesExist(); diff --git a/logic/OneSixRule.cpp b/logic/DerpRule.cpp similarity index 98% rename from logic/OneSixRule.cpp rename to logic/DerpRule.cpp index 392b1dd1..d4cf1ba3 100644 --- a/logic/OneSixRule.cpp +++ b/logic/DerpRule.cpp @@ -16,7 +16,7 @@ #include #include -#include "OneSixRule.h" +#include "DerpRule.h" QList> rulesFromJsonV4(QJsonObject &objectWithRules) { @@ -86,4 +86,4 @@ RuleAction RuleAction_fromString(QString name) if (name == "disallow") return Disallow; return Defer; -} \ No newline at end of file +} diff --git a/logic/OneSixRule.h b/logic/DerpRule.h similarity index 90% rename from logic/OneSixRule.h rename to logic/DerpRule.h index 5a13cbd9..7895ea98 100644 --- a/logic/OneSixRule.h +++ b/logic/DerpRule.h @@ -17,7 +17,7 @@ #include -#include "logic/OneSixLibrary.h" +#include "logic/DerpLibrary.h" enum RuleAction { @@ -33,7 +33,7 @@ class Rule { protected: RuleAction m_result; - virtual bool applies(OneSixLibrary *parent) = 0; + virtual bool applies(DerpLibrary *parent) = 0; public: Rule(RuleAction result) : m_result(result) @@ -41,7 +41,7 @@ public: } virtual ~Rule() {}; virtual QJsonObject toJson() = 0; - RuleAction apply(OneSixLibrary *parent) + RuleAction apply(DerpLibrary *parent) { if (applies(parent)) return m_result; @@ -60,7 +60,7 @@ private: QString m_version_regexp; protected: - virtual bool applies(OneSixLibrary *) + virtual bool applies(DerpLibrary *) { return (m_system == currentSystem); } @@ -81,7 +81,7 @@ public: class ImplicitRule : public Rule { protected: - virtual bool applies(OneSixLibrary *) + virtual bool applies(DerpLibrary *) { return true; } diff --git a/logic/OneSixUpdate.cpp b/logic/DerpUpdate.cpp similarity index 88% rename from logic/OneSixUpdate.cpp rename to logic/DerpUpdate.cpp index 0119ab07..e1600d28 100644 --- a/logic/OneSixUpdate.cpp +++ b/logic/DerpUpdate.cpp @@ -14,7 +14,7 @@ */ #include "MultiMC.h" -#include "OneSixUpdate.h" +#include "DerpUpdate.h" #include @@ -25,9 +25,9 @@ #include "BaseInstance.h" #include "lists/MinecraftVersionList.h" -#include "OneSixVersion.h" -#include "OneSixLibrary.h" -#include "OneSixInstance.h" +#include "DerpVersion.h" +#include "DerpLibrary.h" +#include "DerpInstance.h" #include "net/ForgeMirrors.h" #include "net/URLConstants.h" #include "assets/AssetsUtils.h" @@ -35,12 +35,12 @@ #include "pathutils.h" #include -OneSixUpdate::OneSixUpdate(BaseInstance *inst, bool only_prepare, QObject *parent) +DerpUpdate::DerpUpdate(BaseInstance *inst, bool only_prepare, QObject *parent) : Task(parent), m_inst(inst), m_only_prepare(only_prepare) { } -void OneSixUpdate::executeTask() +void DerpUpdate::executeTask() { QString intendedVersion = m_inst->intendedVersionId(); @@ -77,7 +77,7 @@ void OneSixUpdate::executeTask() } } -void OneSixUpdate::versionFileStart() +void DerpUpdate::versionFileStart() { QLOG_INFO() << m_inst->name() << ": getting version file."; setStatus(tr("Getting the version files from Mojang...")); @@ -94,10 +94,10 @@ void OneSixUpdate::versionFileStart() specificVersionDownloadJob->start(); } -void OneSixUpdate::versionFileFinished() +void DerpUpdate::versionFileFinished() { NetActionPtr DlJob = specificVersionDownloadJob->first(); - OneSixInstance *inst = (OneSixInstance *)m_inst; + DerpInstance *inst = (DerpInstance *)m_inst; QString version_id = targetVersion->descriptor(); QString inst_dir = m_inst->instanceRoot(); @@ -142,16 +142,16 @@ void OneSixUpdate::versionFileFinished() jarlibStart(); } -void OneSixUpdate::versionFileFailed() +void DerpUpdate::versionFileFailed() { emitFailed("Failed to download the version description. Try again."); } -void OneSixUpdate::assetIndexStart() +void DerpUpdate::assetIndexStart() { setStatus(tr("Updating assets index...")); - OneSixInstance *inst = (OneSixInstance *)m_inst; - std::shared_ptr version = inst->getFullVersion(); + DerpInstance *inst = (DerpInstance *)m_inst; + std::shared_ptr version = inst->getFullVersion(); QString assetName = version->assets; QUrl indexUrl = "http://" + URLConstants::AWS_DOWNLOAD_INDEXES + assetName + ".json"; QString localPath = assetName + ".json"; @@ -170,12 +170,12 @@ void OneSixUpdate::assetIndexStart() jarlibDownloadJob->start(); } -void OneSixUpdate::assetIndexFinished() +void DerpUpdate::assetIndexFinished() { AssetsIndex index; - OneSixInstance *inst = (OneSixInstance *)m_inst; - std::shared_ptr version = inst->getFullVersion(); + DerpInstance *inst = (DerpInstance *)m_inst; + std::shared_ptr version = inst->getFullVersion(); QString assetName = version->assets; QString asset_fname = "assets/indexes/" + assetName + ".json"; @@ -215,26 +215,26 @@ void OneSixUpdate::assetIndexFinished() assetsFinished(); } -void OneSixUpdate::assetIndexFailed() +void DerpUpdate::assetIndexFailed() { emitFailed("Failed to download the assets index!"); } -void OneSixUpdate::assetsFinished() +void DerpUpdate::assetsFinished() { prepareForLaunch(); } -void OneSixUpdate::assetsFailed() +void DerpUpdate::assetsFailed() { emitFailed("Failed to download assets!"); } -void OneSixUpdate::jarlibStart() +void DerpUpdate::jarlibStart() { setStatus(tr("Getting the library files from Mojang...")); QLOG_INFO() << m_inst->name() << ": downloading libraries"; - OneSixInstance *inst = (OneSixInstance *)m_inst; + DerpInstance *inst = (DerpInstance *)m_inst; bool successful = inst->reloadFullVersion(); if (!successful) { @@ -244,7 +244,7 @@ void OneSixUpdate::jarlibStart() } // Build a list of URLs that will need to be downloaded. - std::shared_ptr version = inst->getFullVersion(); + std::shared_ptr version = inst->getFullVersion(); // minecraft.jar for this version { QString version_id = version->id; @@ -318,12 +318,12 @@ void OneSixUpdate::jarlibStart() jarlibDownloadJob->start(); } -void OneSixUpdate::jarlibFinished() +void DerpUpdate::jarlibFinished() { assetIndexStart(); } -void OneSixUpdate::jarlibFailed() +void DerpUpdate::jarlibFailed() { QStringList failed = jarlibDownloadJob->getFailedFiles(); QString failed_all = failed.join("\n"); @@ -331,17 +331,17 @@ void OneSixUpdate::jarlibFailed() "\n\nPlease try again."); } -void OneSixUpdate::prepareForLaunch() +void DerpUpdate::prepareForLaunch() { setStatus(tr("Preparing for launch...")); QLOG_INFO() << m_inst->name() << ": preparing for launch"; - auto onesix_inst = (OneSixInstance *)m_inst; + auto derp_inst = (DerpInstance *)m_inst; // delete any leftovers, if they are present. - onesix_inst->cleanupAfterRun(); + derp_inst->cleanupAfterRun(); - QString natives_dir_raw = PathCombine(onesix_inst->instanceRoot(), "natives/"); - auto version = onesix_inst->getFullVersion(); + QString natives_dir_raw = PathCombine(derp_inst->instanceRoot(), "natives/"); + auto version = derp_inst->getFullVersion(); if (!version) { emitFailed("The version information for this instance is not complete. Try re-creating " diff --git a/logic/OneSixUpdate.h b/logic/DerpUpdate.h similarity index 92% rename from logic/OneSixUpdate.h rename to logic/DerpUpdate.h index bc717a94..475f6c35 100644 --- a/logic/OneSixUpdate.h +++ b/logic/DerpUpdate.h @@ -25,11 +25,11 @@ class MinecraftVersion; class BaseInstance; -class OneSixUpdate : public Task +class DerpUpdate : public Task { Q_OBJECT public: - explicit OneSixUpdate(BaseInstance *inst, bool prepare_for_launch, QObject *parent = 0); + explicit DerpUpdate(BaseInstance *inst, bool prepare_for_launch, QObject *parent = 0); virtual void executeTask(); private diff --git a/logic/DerpVersion.cpp b/logic/DerpVersion.cpp new file mode 100644 index 00000000..f13ac620 --- /dev/null +++ b/logic/DerpVersion.cpp @@ -0,0 +1,164 @@ +/* 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 "DerpVersion.h" + +#include + +#include "DerpVersionBuilder.h" + +DerpVersion::DerpVersion(DerpInstance *instance, QObject *parent) + : QAbstractListModel(parent), m_instance(instance) +{ +} + +bool DerpVersion::reload(QWidget *widgetParent) +{ + return DerpVersionBuilder::build(this, m_instance, widgetParent); +} + +QList > DerpVersion::getActiveNormalLibs() +{ + QList > output; + for (auto lib : libraries) + { + if (lib->isActive() && !lib->isNative()) + { + output.append(lib); + } + } + return output; +} + +QList > DerpVersion::getActiveNativeLibs() +{ + QList > output; + for (auto lib : libraries) + { + if (lib->isActive() && lib->isNative()) + { + output.append(lib); + } + } + return output; +} + +QVariant DerpVersion::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + int row = index.row(); + int column = index.column(); + + if (row < 0 || row >= libraries.size()) + return QVariant(); + + if (role == Qt::DisplayRole) + { + switch (column) + { + case 0: + return libraries[row]->name(); + case 1: + return libraries[row]->type(); + case 2: + return libraries[row]->version(); + default: + return QVariant(); + } + } + return QVariant(); +} + +Qt::ItemFlags DerpVersion::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return Qt::NoItemFlags; + int row = index.row(); + if (libraries[row]->isActive()) + { + return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemNeverHasChildren; + } + else + { + return Qt::ItemNeverHasChildren; + } + // return QAbstractListModel::flags(index); +} + +QVariant DerpVersion::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role != Qt::DisplayRole || orientation != Qt::Horizontal) + return QVariant(); + switch (section) + { + case 0: + return QString("Name"); + case 1: + return QString("Type"); + case 2: + return QString("Version"); + default: + return QString(); + } +} + +int DerpVersion::rowCount(const QModelIndex &parent) const +{ + return libraries.size(); +} + +int DerpVersion::columnCount(const QModelIndex &parent) const +{ + return 3; +} + +QDebug operator<<(QDebug &dbg, const DerpVersion *version) +{ + dbg.nospace() << "DerpVersion(" + << "\n\tid=" << version->id + << "\n\ttime=" << version->time + << "\n\treleaseTime=" << version->releaseTime + << "\n\ttype=" << version->type + << "\n\tassets=" << version->assets + << "\n\tprocessArguments=" << version->processArguments + << "\n\tminecraftArguments=" << version->minecraftArguments + << "\n\tminimumLauncherVersion=" << version->minimumLauncherVersion + << "\n\tmainClass=" << version->mainClass + << "\n\tlibraries="; + for (auto lib : version->libraries) + { + dbg.nospace() << "\n\t\t" << lib.get(); + } + dbg.nospace() << "\n)"; + return dbg.maybeSpace(); +} +QDebug operator<<(QDebug &dbg, const DerpLibrary *library) +{ + dbg.nospace() << "DerpLibrary(" + << "\n\t\t\trawName=" << library->rawName() + << "\n\t\t\tname=" << library->name() + << "\n\t\t\tversion=" << library->version() + << "\n\t\t\ttype=" << library->type() + << "\n\t\t\tisActive=" << library->isActive() + << "\n\t\t\tisNative=" << library->isNative() + << "\n\t\t\tdownloadUrl=" << library->downloadUrl() + << "\n\t\t\tstoragePath=" << library->storagePath() + << "\n\t\t\tabsolutePath=" << library->absoluteUrl() + << "\n\t\t\thint=" << library->hint(); + dbg.nospace() << "\n\t\t)"; + return dbg.maybeSpace(); +} diff --git a/logic/DerpVersion.h b/logic/DerpVersion.h new file mode 100644 index 00000000..cadfa850 --- /dev/null +++ b/logic/DerpVersion.h @@ -0,0 +1,110 @@ +/* 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 "DerpLibrary.h" + +class DerpInstance; + +class DerpVersion : public QAbstractListModel +{ + Q_OBJECT +public: + explicit DerpVersion(DerpInstance *instance, QObject *parent = 0); + + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + virtual QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + virtual int columnCount(const QModelIndex &parent) const; + virtual Qt::ItemFlags flags(const QModelIndex &index) const; + + bool reload(QWidget *widgetParent); + +public: + QList> getActiveNormalLibs(); + QList> getActiveNativeLibs(); + + // data members +public: + /// the ID - determines which jar to use! ACTUALLY IMPORTANT! + QString id; + /// Last updated time - as a string + QString time; + /// Release time - as a string + QString releaseTime; + /// Release type - "release" or "snapshot" + QString type; + /// Assets type - "legacy" or a version ID + QString assets; + /** + * DEPRECATED: Old versions of the new vanilla launcher used this + * ex: "username_session_version" + */ + QString processArguments; + /** + * arguments that should be used for launching minecraft + * + * ex: "--username ${auth_player_name} --session ${auth_session} + * --version ${version_name} --gameDir ${game_directory} --assetsDir ${game_assets}" + */ + QString minecraftArguments; + /** + * the minimum launcher version required by this version ... current is 4 (at point of + * writing) + */ + int minimumLauncherVersion = 0xDEADBEEF; + /** + * The main class to load first + */ + QString mainClass; + + /// the list of libs - both active and inactive, native and java + QList> libraries; + + /* + FIXME: add support for those rules here? Looks like a pile of quick hacks to me though. + + "rules": [ + { + "action": "allow" + }, + { + "action": "disallow", + "os": { + "name": "osx", + "version": "^10\\.5\\.\\d$" + } + } + ], + "incompatibilityReason": "There is a bug in LWJGL which makes it incompatible with OSX + 10.5.8. Please go to New Profile and use 1.5.2 for now. Sorry!" + } + */ + // QList rules; + +private: + DerpInstance *m_instance; +}; + +QDebug operator<<(QDebug &dbg, const DerpVersion *version); +QDebug operator<<(QDebug &dbg, const DerpLibrary *library); diff --git a/logic/DerpVersionBuilder.cpp b/logic/DerpVersionBuilder.cpp new file mode 100644 index 00000000..d8091f32 --- /dev/null +++ b/logic/DerpVersionBuilder.cpp @@ -0,0 +1,279 @@ +/* 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 "DerpVersionBuilder.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "DerpVersion.h" +#include "DerpInstance.h" +#include "DerpRule.h" + +DerpVersionBuilder::DerpVersionBuilder() +{ + +} + +bool DerpVersionBuilder::build(DerpVersion *version, DerpInstance *instance, QWidget *widgetParent) +{ + DerpVersionBuilder builder; + builder.m_version = version; + builder.m_instance = instance; + builder.m_widgetParent = widgetParent; + return builder.build(); +} + +bool DerpVersionBuilder::build() +{ + clear(); + + QDir root(m_instance->instanceRoot()); + QDir patches(root.absoluteFilePath("patches/")); + + // version.json -> patches/*.json -> custom.json + + // version.json + { + QJsonObject obj; + if (!read(QFileInfo(root.absoluteFilePath("version.json")), &obj)) + { + return false; + } + if (!apply(obj)) + { + return false; + } + } + + // patches/ + { + // load all, put into map for ordering, apply in the right order + + QMap objects; + for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files)) + { + QJsonObject obj; + if (!read(info, &obj)) + { + return false; + } + if (!obj.contains("order") || !obj.value("order").isDouble()) + { + QMessageBox::critical(m_widgetParent, QObject::tr("Error"), QObject::tr("Missing or invalid 'order' in %1").arg(info.absoluteFilePath())); + return false; + } + objects.insert(obj.value("order").toDouble(), obj); + } + for (auto object : objects.values()) + { + if (!apply(object)) + { + return false; + } + } + } + + // custom.json + { + if (QFile::exists(root.absoluteFilePath("custom.json"))) + { + QJsonObject obj; + if (!read(QFileInfo(root.absoluteFilePath("custom.json")), &obj)) + { + return false; + } + if (!apply(obj)) + { + return false; + } + } + } + + return true; +} + +void DerpVersionBuilder::clear() +{ + m_version->id.clear(); + m_version->time.clear(); + m_version->releaseTime.clear(); + m_version->type.clear(); + m_version->assets.clear(); + m_version->processArguments.clear(); + m_version->minecraftArguments.clear(); + m_version->minimumLauncherVersion = 0xDEADBEAF; + m_version->mainClass.clear(); + m_version->libraries.clear(); +} + +void applyString(const QJsonObject &obj, const QString &key, QString &out) +{ + if (obj.contains(key) && obj.value(key).isString()) + { + out = obj.value(key).toString(); + } +} +void applyString(const QJsonObject &obj, const QString &key, std::shared_ptr lib, void(DerpLibrary::*func)(const QString &val)) +{ + if (obj.contains(key) && obj.value(key).isString()) + { + (lib.get()->*func)(obj.value(key).toString()); + } +} +bool DerpVersionBuilder::apply(const QJsonObject &object) +{ + applyString(object, "id", m_version->id); + applyString(object, "mainClass", m_version->mainClass); + applyString(object, "processArguments", m_version->processArguments); + { + const QString toCompare = m_version->processArguments.toLower(); + if (toCompare == "legacy") + { + m_version->minecraftArguments = " ${auth_player_name} ${auth_session}"; + } + else if (toCompare == "username_session") + { + m_version->minecraftArguments = "--username ${auth_player_name} --session ${auth_session}"; + } + else if (toCompare == "username_session_version") + { + m_version->minecraftArguments = "--username ${auth_player_name} --session ${auth_session} --version ${profile_name}"; + } + } + applyString(object, "minecraftArguments", m_version->minecraftArguments); + applyString(object, "type", m_version->type); + applyString(object, "releaseTime", m_version->releaseTime); + applyString(object, "time", m_version->time); + applyString(object, "assets", m_version->assets); + { + if (m_version->assets.isEmpty()) + { + m_version->assets = "legacy"; + } + } + if (object.contains("minimumLauncherVersion")) + { + auto minLauncherVersionVal = object.value("minimumLauncherVersion"); + if (minLauncherVersionVal.isDouble()) + { + m_version->minimumLauncherVersion = minLauncherVersionVal.toDouble(); + } + } + + // libraries + { + auto librariesValue = object.value("libraries"); + if (!librariesValue.isArray()) + { + QMessageBox::critical(m_widgetParent, QObject::tr("Error"), QObject::tr("One json files contains a libraries field, but it's not an array")); + return false; + } + for (auto libVal : librariesValue.toArray()) + { + if (!libVal.isObject()) + { + continue; + } + + QJsonObject libObj = libVal.toObject(); + + // Library name + auto nameVal = libObj.value("name"); + if (!nameVal.isString()) + { + continue; + } + std::shared_ptr library(new DerpLibrary(nameVal.toString())); + + applyString(libObj, "url", library, &DerpLibrary::setBaseUrl); + applyString(libObj, "MMC-hint", library, &DerpLibrary::setHint); + applyString(libObj, "MMC-absulute_url", library, &DerpLibrary::setAbsoluteUrl); + applyString(libObj, "MMC-absoluteUrl", library, &DerpLibrary::setAbsoluteUrl); + + auto extractVal = libObj.value("extract"); + if (extractVal.isObject()) + { + QStringList excludes; + auto extractObj = extractVal.toObject(); + auto excludesVal = extractObj.value("exclude"); + if (excludesVal.isArray()) + { + auto excludesList = excludesVal.toArray(); + for (auto excludeVal : excludesList) + { + if (excludeVal.isString()) + { + excludes.append(excludeVal.toString()); + } + } + library->extract_excludes = excludes; + } + } + + auto nativesVal = libObj.value("natives"); + if (nativesVal.isObject()) + { + library->setIsNative(); + auto nativesObj = nativesVal.toObject(); + for (auto it = nativesObj.begin(); it != nativesObj.end(); ++it) + { + auto osType = OpSys_fromString(it.key()); + if (osType == Os_Other) + { + continue; + } + if (!it.value().isString()) + { + continue; + } + library->addNative(osType, it.value().toString()); + } + } + + library->setRules(rulesFromJsonV4(libObj)); + library->finalize(); + m_version->libraries.append(library); + } + } + + return true; +} + +bool DerpVersionBuilder::read(const QFileInfo &fileInfo, QJsonObject *out) +{ + QFile file(fileInfo.absoluteFilePath()); + if (!file.open(QFile::ReadOnly)) + { + QMessageBox::critical(m_widgetParent, QObject::tr("Error"), QObject::tr("Unable to open %1: %2").arg(file.fileName(), file.errorString())); + return false; + } + QJsonParseError error; + QJsonDocument doc = QJsonDocument::fromJson(file.readAll(), &error); + if (error.error != QJsonParseError::NoError) + { + QMessageBox::critical(m_widgetParent, QObject::tr("Error"), QObject::tr("Unable to parse %1: %2 at %3").arg(file.fileName(), error.errorString()).arg(error.offset)); + return false; + } + *out = doc.object(); + return true; +} diff --git a/logic/DerpVersionBuilder.h b/logic/DerpVersionBuilder.h new file mode 100644 index 00000000..739065db --- /dev/null +++ b/logic/DerpVersionBuilder.h @@ -0,0 +1,43 @@ +/* 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 + +class DerpVersion; +class DerpInstance; +class QWidget; +class QJsonObject; +class QFileInfo; + +class DerpVersionBuilder +{ + DerpVersionBuilder(); +public: + static bool build(DerpVersion *version, DerpInstance *instance, QWidget *widgetParent); + +private: + DerpVersion *m_version; + DerpInstance *m_instance; + QWidget *m_widgetParent; + + bool build(); + + void clear(); + bool apply(const QJsonObject &object); + + bool read(const QFileInfo &fileInfo, QJsonObject *out); +}; diff --git a/logic/ForgeInstaller.cpp b/logic/ForgeInstaller.cpp index 8d4c5b41..29735a7d 100644 --- a/logic/ForgeInstaller.cpp +++ b/logic/ForgeInstaller.cpp @@ -14,8 +14,8 @@ */ #include "ForgeInstaller.h" -#include "OneSixVersion.h" -#include "OneSixLibrary.h" +#include "DerpVersion.h" +#include "DerpLibrary.h" #include "net/HttpMetaCache.h" #include #include @@ -23,9 +23,15 @@ #include #include "MultiMC.h" +#include +#include +#include + +// DERPFIX + ForgeInstaller::ForgeInstaller(QString filename, QString universal_url) { - std::shared_ptr newVersion; + std::shared_ptr newVersion; m_universal_url = universal_url; QuaZip zip(filename); @@ -58,7 +64,7 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url) // read the forge version info { - newVersion = OneSixVersion::fromJson(versionInfoVal.toObject()); + // DERPFIX newVersion = DerpVersion::fromJson(versionInfoVal.toObject()); if (!newVersion) return; } @@ -68,7 +74,7 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url) internalPath = installObj.value("filePath").toString(); // where do we put the library? decode the mojang path - OneSixLibrary lib(libraryName); + DerpLibrary lib(libraryName); lib.finalize(); auto cacheentry = MMC->metacache()->resolveEntry("libraries", lib.storagePath()); @@ -103,11 +109,10 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url) realVersionId = m_forge_version->id = installObj.value("minecraft").toString(); } -bool ForgeInstaller::apply(std::shared_ptr to) +bool ForgeInstaller::apply(std::shared_ptr to) { if (!m_forge_version) return false; - to->externalUpdateStart(); int sliding_insert_window = 0; { // for each library in the version we are adding (except for the blacklisted) @@ -150,6 +155,5 @@ bool ForgeInstaller::apply(std::shared_ptr to) to->minecraftArguments = m_forge_version->minecraftArguments; to->processArguments = m_forge_version->processArguments; } - to->externalUpdateFinish(); - return to->toOriginalFile(); + return true; } diff --git a/logic/ForgeInstaller.h b/logic/ForgeInstaller.h index 0b9f9c77..65cad87c 100644 --- a/logic/ForgeInstaller.h +++ b/logic/ForgeInstaller.h @@ -17,18 +17,18 @@ #include #include -class OneSixVersion; +class DerpVersion; class ForgeInstaller { public: ForgeInstaller(QString filename, QString universal_url); - bool apply(std::shared_ptr to); + bool apply(std::shared_ptr to); private: // the version, read from the installer - std::shared_ptr m_forge_version; + std::shared_ptr m_forge_version; QString internalPath; QString finalPath; QString realVersionId; diff --git a/logic/InstanceFactory.cpp b/logic/InstanceFactory.cpp index 1f1a5879..c50ec4e4 100644 --- a/logic/InstanceFactory.cpp +++ b/logic/InstanceFactory.cpp @@ -21,9 +21,10 @@ #include "BaseInstance.h" #include "LegacyInstance.h" #include "LegacyFTBInstance.h" -#include "OneSixInstance.h" -#include "OneSixFTBInstance.h" +#include "DerpInstance.h" +#include "DerpFTBInstance.h" #include "NostalgiaInstance.h" +#include "DerpInstance.h" #include "BaseVersion.h" #include "MinecraftVersion.h" @@ -50,14 +51,14 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst QString inst_type = m_settings->get("InstanceType").toString(); // FIXME: replace with a map lookup, where instance classes register their types - if (inst_type == "Legacy") + if (inst_type == "Derp" || inst_type == "OneSix") + { + inst = new DerpInstance(instDir, m_settings, this); + } + else if (inst_type == "Legacy") { inst = new LegacyInstance(instDir, m_settings, this); } - else if (inst_type == "OneSix") - { - inst = new OneSixInstance(instDir, m_settings, this); - } else if (inst_type == "Nostalgia") { inst = new NostalgiaInstance(instDir, m_settings, this); @@ -66,9 +67,9 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst { inst = new LegacyFTBInstance(instDir, m_settings, this); } - else if (inst_type == "OneSixFTB") + else if (inst_type == "OneSixFTB" || inst_type == "DerpFTB") { - inst = new OneSixFTBInstance(instDir, m_settings, this); + inst = new DerpFTBInstance(instDir, m_settings, this); } else { @@ -101,14 +102,15 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance(BaseInstance *& switch (mcVer->type) { case MinecraftVersion::Legacy: + // TODO derp m_settings->set("InstanceType", "Legacy"); inst = new LegacyInstance(instDir, m_settings, this); inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); break; - case MinecraftVersion::OneSix: - m_settings->set("InstanceType", "OneSix"); - inst = new OneSixInstance(instDir, m_settings, this); + case MinecraftVersion::Derp: + m_settings->set("InstanceType", "Derp"); + inst = new DerpInstance(instDir, m_settings, this); inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); break; @@ -135,9 +137,9 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance(BaseInstance *& inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); break; - case MinecraftVersion::OneSix: - m_settings->set("InstanceType", "OneSixFTB"); - inst = new OneSixFTBInstance(instDir, m_settings, this); + case MinecraftVersion::Derp: + m_settings->set("InstanceType", "DerpFTB"); + inst = new DerpFTBInstance(instDir, m_settings, this); inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); break; @@ -174,8 +176,8 @@ InstanceFactory::InstCreateError InstanceFactory::copyInstance(BaseInstance *&ne m_settings->registerSetting("InstanceType", "Legacy"); QString inst_type = m_settings->get("InstanceType").toString(); - if(inst_type == "OneSixFTB") - m_settings->set("InstanceType", "OneSix"); + if(inst_type == "OneSixFTB" || inst_type == "DerpFTB") + m_settings->set("InstanceType", "Derp"); if(inst_type == "LegacyFTB") m_settings->set("InstanceType", "Legacy"); diff --git a/logic/LegacyInstance.h b/logic/LegacyInstance.h index 1e7d9eb6..1ff17cbd 100644 --- a/logic/LegacyInstance.h +++ b/logic/LegacyInstance.h @@ -68,7 +68,7 @@ public: virtual QString intendedVersionId() const override; virtual bool setIntendedVersionId(QString version) override; // the `version' of Legacy instances is defined by the launcher code. - // in contrast with OneSix, where `version' is described in a json file + // in contrast with Derp, where `version' is described in a json file virtual bool versionIsCustom() override { return false; diff --git a/logic/LiteLoaderInstaller.cpp b/logic/LiteLoaderInstaller.cpp index 07fffff3..8a120eab 100644 --- a/logic/LiteLoaderInstaller.cpp +++ b/logic/LiteLoaderInstaller.cpp @@ -15,8 +15,8 @@ #include "LiteLoaderInstaller.h" -#include "OneSixVersion.h" -#include "OneSixLibrary.h" +#include "DerpVersion.h" +#include "DerpLibrary.h" QMap LiteLoaderInstaller::m_launcherWrapperVersionMapping; @@ -36,9 +36,9 @@ bool LiteLoaderInstaller::canApply() const return m_launcherWrapperVersionMapping.contains(m_mcVersion); } -bool LiteLoaderInstaller::apply(std::shared_ptr to) +bool LiteLoaderInstaller::apply(std::shared_ptr to) { - to->externalUpdateStart(); + // DERPFIX applyLaunchwrapper(to); applyLiteLoader(to); @@ -51,15 +51,14 @@ bool LiteLoaderInstaller::apply(std::shared_ptr to) " --tweakClass com.mumfrey.liteloader.launch.LiteLoaderTweaker"); } - to->externalUpdateFinish(); - return to->toOriginalFile(); + return true; } -void LiteLoaderInstaller::applyLaunchwrapper(std::shared_ptr to) +void LiteLoaderInstaller::applyLaunchwrapper(std::shared_ptr to) { const QString intendedVersion = m_launcherWrapperVersionMapping[m_mcVersion]; - QMutableListIterator> it(to->libraries); + QMutableListIterator> it(to->libraries); while (it.hasNext()) { it.next(); @@ -76,15 +75,15 @@ void LiteLoaderInstaller::applyLaunchwrapper(std::shared_ptr to) } } - std::shared_ptr lib(new OneSixLibrary( + std::shared_ptr lib(new DerpLibrary( "net.minecraft:launchwrapper:" + m_launcherWrapperVersionMapping[m_mcVersion])); lib->finalize(); to->libraries.prepend(lib); } -void LiteLoaderInstaller::applyLiteLoader(std::shared_ptr to) +void LiteLoaderInstaller::applyLiteLoader(std::shared_ptr to) { - QMutableListIterator> it(to->libraries); + QMutableListIterator> it(to->libraries); while (it.hasNext()) { it.next(); @@ -94,8 +93,8 @@ void LiteLoaderInstaller::applyLiteLoader(std::shared_ptr to) } } - std::shared_ptr lib( - new OneSixLibrary("com.mumfrey:liteloader:" + m_mcVersion)); + std::shared_ptr lib( + new DerpLibrary("com.mumfrey:liteloader:" + m_mcVersion)); lib->setBaseUrl("http://dl.liteloader.com/versions/"); lib->finalize(); to->libraries.prepend(lib); diff --git a/logic/LiteLoaderInstaller.h b/logic/LiteLoaderInstaller.h index 44b306d6..d7b8ce77 100644 --- a/logic/LiteLoaderInstaller.h +++ b/logic/LiteLoaderInstaller.h @@ -18,7 +18,7 @@ #include #include -class OneSixVersion; +class DerpVersion; class LiteLoaderInstaller { @@ -27,13 +27,13 @@ public: bool canApply() const; - bool apply(std::shared_ptr to); + bool apply(std::shared_ptr to); private: QString m_mcVersion; - void applyLaunchwrapper(std::shared_ptr to); - void applyLiteLoader(std::shared_ptr to); + void applyLaunchwrapper(std::shared_ptr to); + void applyLiteLoader(std::shared_ptr to); static QMap m_launcherWrapperVersionMapping; }; diff --git a/logic/MinecraftVersion.h b/logic/MinecraftVersion.h index 504381a8..dd849ce9 100644 --- a/logic/MinecraftVersion.h +++ b/logic/MinecraftVersion.h @@ -32,7 +32,7 @@ struct MinecraftVersion : public BaseVersion /// This version's type. Used internally to identify what kind of version this is. enum VersionType { - OneSix, + Derp, Legacy, Nostalgia } type; @@ -66,8 +66,8 @@ struct MinecraftVersion : public BaseVersion } switch (type) { - case OneSix: - pre_final.append("OneSix"); + case Derp: + pre_final.append("Derp"); break; case Legacy: pre_final.append("Legacy"); diff --git a/logic/NostalgiaInstance.cpp b/logic/NostalgiaInstance.cpp index 2e23ee71..f27954a7 100644 --- a/logic/NostalgiaInstance.cpp +++ b/logic/NostalgiaInstance.cpp @@ -17,7 +17,7 @@ NostalgiaInstance::NostalgiaInstance(const QString &rootDir, SettingsObject *settings, QObject *parent) - : OneSixInstance(rootDir, settings, parent) + : DerpInstance(rootDir, settings, parent) { } diff --git a/logic/NostalgiaInstance.h b/logic/NostalgiaInstance.h index a26f7f0a..6a6b91a1 100644 --- a/logic/NostalgiaInstance.h +++ b/logic/NostalgiaInstance.h @@ -15,9 +15,9 @@ #pragma once -#include "OneSixInstance.h" +#include "DerpInstance.h" -class NostalgiaInstance : public OneSixInstance +class NostalgiaInstance : public DerpInstance { Q_OBJECT public: diff --git a/logic/OneSixVersion.cpp b/logic/OneSixVersion.cpp index 8ae685f0..3571be9b 100644 --- a/logic/OneSixVersion.cpp +++ b/logic/OneSixVersion.cpp @@ -13,14 +13,14 @@ * limitations under the License. */ -#include "logic/OneSixVersion.h" -#include "logic/OneSixLibrary.h" -#include "logic/OneSixRule.h" +#include "logic/DerpVersion.h" +#include "logic/DerpLibrary.h" +#include "logic/DerpRule.h" #include "logger/QsLog.h" -std::shared_ptr fromJsonV4(QJsonObject root, - std::shared_ptr fullVersion) +std::shared_ptr fromJsonV4(QJsonObject root, + std::shared_ptr fullVersion) { fullVersion->id = root.value("id").toString(); @@ -93,7 +93,7 @@ std::shared_ptr fromJsonV4(QJsonObject root, auto nameVal = libObj.value("name"); if (!nameVal.isString()) continue; - std::shared_ptr library(new OneSixLibrary(nameVal.toString())); + std::shared_ptr library(new DerpLibrary(nameVal.toString())); auto urlVal = libObj.value("url"); if (urlVal.isString()) @@ -158,9 +158,9 @@ std::shared_ptr fromJsonV4(QJsonObject root, return fullVersion; } -std::shared_ptr OneSixVersion::fromJson(QJsonObject root) +std::shared_ptr DerpVersion::fromJson(QJsonObject root) { - std::shared_ptr readVersion(new OneSixVersion()); + std::shared_ptr readVersion(new DerpVersion()); int launcher_ver = readVersion->minimumLauncherVersion = root.value("minimumLauncherVersion").toDouble(); @@ -169,16 +169,16 @@ std::shared_ptr OneSixVersion::fromJson(QJsonObject root) return fromJsonV4(root, readVersion); else { - return std::shared_ptr(); + return std::shared_ptr(); } } -std::shared_ptr OneSixVersion::fromFile(QString filepath) +std::shared_ptr DerpVersion::fromFile(QString filepath) { QFile file(filepath); if (!file.open(QIODevice::ReadOnly)) { - return std::shared_ptr(); + return std::shared_ptr(); } auto data = file.readAll(); @@ -187,12 +187,12 @@ std::shared_ptr OneSixVersion::fromFile(QString filepath) if (jsonError.error != QJsonParseError::NoError) { - return std::shared_ptr(); + return std::shared_ptr(); } if (!jsonDoc.isObject()) { - return std::shared_ptr(); + return std::shared_ptr(); } QJsonObject root = jsonDoc.object(); auto version = fromJson(root); @@ -201,7 +201,7 @@ std::shared_ptr OneSixVersion::fromFile(QString filepath) return version; } -bool OneSixVersion::toOriginalFile() +bool DerpVersion::toOriginalFile() { if (original_file.isEmpty()) return false; @@ -232,9 +232,9 @@ bool OneSixVersion::toOriginalFile() return file.commit(); } -QList> OneSixVersion::getActiveNormalLibs() +QList> DerpVersion::getActiveNormalLibs() { - QList> output; + QList> output; for (auto lib : libraries) { if (lib->isActive() && !lib->isNative()) @@ -245,9 +245,9 @@ QList> OneSixVersion::getActiveNormalLibs() return output; } -QList> OneSixVersion::getActiveNativeLibs() +QList> DerpVersion::getActiveNativeLibs() { - QList> output; + QList> output; for (auto lib : libraries) { if (lib->isActive() && lib->isNative()) @@ -258,17 +258,17 @@ QList> OneSixVersion::getActiveNativeLibs() return output; } -void OneSixVersion::externalUpdateStart() +void DerpVersion::externalUpdateStart() { beginResetModel(); } -void OneSixVersion::externalUpdateFinish() +void DerpVersion::externalUpdateFinish() { endResetModel(); } -QVariant OneSixVersion::data(const QModelIndex &index, int role) const +QVariant DerpVersion::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); @@ -296,7 +296,7 @@ QVariant OneSixVersion::data(const QModelIndex &index, int role) const return QVariant(); } -Qt::ItemFlags OneSixVersion::flags(const QModelIndex &index) const +Qt::ItemFlags DerpVersion::flags(const QModelIndex &index) const { if (!index.isValid()) return Qt::NoItemFlags; @@ -312,7 +312,7 @@ Qt::ItemFlags OneSixVersion::flags(const QModelIndex &index) const // return QAbstractListModel::flags(index); } -QVariant OneSixVersion::headerData(int section, Qt::Orientation orientation, int role) const +QVariant DerpVersion::headerData(int section, Qt::Orientation orientation, int role) const { if (role != Qt::DisplayRole || orientation != Qt::Horizontal) return QVariant(); @@ -329,12 +329,12 @@ QVariant OneSixVersion::headerData(int section, Qt::Orientation orientation, int } } -int OneSixVersion::rowCount(const QModelIndex &parent) const +int DerpVersion::rowCount(const QModelIndex &parent) const { return libraries.size(); } -int OneSixVersion::columnCount(const QModelIndex &parent) const +int DerpVersion::columnCount(const QModelIndex &parent) const { return 3; } diff --git a/logic/OneSixVersion.h b/logic/OneSixVersion.h index 036f3d53..e8f744aa 100644 --- a/logic/OneSixVersion.h +++ b/logic/OneSixVersion.h @@ -17,9 +17,9 @@ #include #include -class OneSixLibrary; +class DerpLibrary; -class OneSixVersion : public QAbstractListModel +class DerpVersion : public QAbstractListModel { // Things required to implement the Qt list model public: @@ -33,12 +33,12 @@ public: // serialization/deserialization public: bool toOriginalFile(); - static std::shared_ptr fromJson(QJsonObject root); - static std::shared_ptr fromFile(QString filepath); + static std::shared_ptr fromJson(QJsonObject root); + static std::shared_ptr fromFile(QString filepath); public: - QList> getActiveNormalLibs(); - QList> getActiveNativeLibs(); + QList> getActiveNormalLibs(); + QList> getActiveNativeLibs(); // called when something starts/stops messing with the object // FIXME: these are ugly in every possible way. void externalUpdateStart(); @@ -81,7 +81,7 @@ public: QString mainClass; /// the list of libs - both active and inactive, native and java - QList> libraries; + QList> libraries; /* FIXME: add support for those rules here? Looks like a pile of quick hacks to me though. diff --git a/logic/lists/MinecraftVersionList.cpp b/logic/lists/MinecraftVersionList.cpp index 91f86df0..29894b5a 100644 --- a/logic/lists/MinecraftVersionList.cpp +++ b/logic/lists/MinecraftVersionList.cpp @@ -234,18 +234,18 @@ void MCVListLoadTask::list_downloaded() } // Parse the type. MinecraftVersion::VersionType versionType; - // OneSix or Legacy. use filter to determine type + // Derp or Legacy. use filter to determine type if (versionTypeStr == "release") { versionType = legacyWhitelist.contains(versionID) ? MinecraftVersion::Legacy - : MinecraftVersion::OneSix; + : MinecraftVersion::Derp; is_latest = (versionID == latestReleaseID); is_snapshot = false; } else if (versionTypeStr == "snapshot") // It's a snapshot... yay { versionType = legacyWhitelist.contains(versionID) ? MinecraftVersion::Legacy - : MinecraftVersion::OneSix; + : MinecraftVersion::Derp; is_latest = (versionID == latestSnapshotID); is_snapshot = true; } From 13ac46bc185e861f9772f85adf757890dbb80a57 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Wed, 22 Jan 2014 14:06:32 +0100 Subject: [PATCH 02/13] Fix launching --- logic/DerpInstance.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/logic/DerpInstance.cpp b/logic/DerpInstance.cpp index 31ed7c95..440c90a4 100644 --- a/logic/DerpInstance.cpp +++ b/logic/DerpInstance.cpp @@ -227,9 +227,7 @@ MinecraftProcess *DerpInstance::prepareForLaunch(MojangAccountPtr account) QDir natives_dir(PathCombine(instanceRoot(), "natives/")); launchScript += "windowTitle " + windowTitle() + "\n"; launchScript += "natives " + natives_dir.absolutePath() + "\n"; - launchScript += "launch onesix"; - - qDebug() << launchScript; + launchScript += "launch onesix\n"; // create the process and set its parameters MinecraftProcess *proc = new MinecraftProcess(this); From 0a592ab99bc68ad918f74206edf2a77cc257683c Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Wed, 22 Jan 2014 15:20:48 +0100 Subject: [PATCH 03/13] Work towards liteloader support. Fix creating new instance --- gui/dialogs/DerpModEditDialog.cpp | 8 +- logic/DerpInstance.cpp | 22 ++++-- logic/DerpInstance.h | 2 + logic/DerpVersion.cpp | 15 ++++ logic/DerpVersion.h | 1 + logic/DerpVersionBuilder.cpp | 18 +---- logic/LiteLoaderInstaller.cpp | 123 +++++++++++++++++------------- logic/LiteLoaderInstaller.h | 18 +++-- 8 files changed, 123 insertions(+), 84 deletions(-) diff --git a/gui/dialogs/DerpModEditDialog.cpp b/gui/dialogs/DerpModEditDialog.cpp index be17404c..aafaa2e2 100644 --- a/gui/dialogs/DerpModEditDialog.cpp +++ b/gui/dialogs/DerpModEditDialog.cpp @@ -96,7 +96,7 @@ void DerpModEditDialog::updateVersionControls() { bool customVersion = m_inst->versionIsCustom(); ui->forgeBtn->setEnabled(true); - ui->liteloaderBtn->setEnabled(LiteLoaderInstaller(m_inst->intendedVersionId()).canApply()); + ui->liteloaderBtn->setEnabled(LiteLoaderInstaller().canApply(m_inst)); ui->customEditorBtn->setEnabled(customVersion); } @@ -165,8 +165,8 @@ void DerpModEditDialog::on_forgeBtn_clicked() void DerpModEditDialog::on_liteloaderBtn_clicked() { - LiteLoaderInstaller liteloader(m_inst->intendedVersionId()); - if (!liteloader.canApply()) + LiteLoaderInstaller liteloader; + if (!liteloader.canApply(m_inst)) { QMessageBox::critical( this, tr("LiteLoader"), @@ -174,7 +174,7 @@ void DerpModEditDialog::on_liteloaderBtn_clicked() "into this version of Minecraft")); return; } - if (!liteloader.apply(m_version)) + if (!liteloader.add(m_inst)) { QMessageBox::critical( this, tr("LiteLoader"), diff --git a/logic/DerpInstance.cpp b/logic/DerpInstance.cpp index 672ba6c4..e6b92b1f 100644 --- a/logic/DerpInstance.cpp +++ b/logic/DerpInstance.cpp @@ -35,10 +35,16 @@ DerpInstance::DerpInstance(const QString &rootDir, SettingsObject *settings, QOb d->m_settings->registerSetting("IntendedVersion", ""); d->m_settings->registerSetting("ShouldUpdate", false); d->version.reset(new DerpVersion(this, this)); - reloadFullVersion(); + if (QDir(instanceRoot()).exists("version.json")) + { + reloadFullVersion(); + } + else + { + clearFullVersion(); + } } - std::shared_ptr DerpInstance::doUpdate(bool only_prepare) { return std::shared_ptr(new DerpUpdate(this, only_prepare)); @@ -280,9 +286,8 @@ bool DerpInstance::setIntendedVersionId(QString version) { settings().set("IntendedVersion", version); setShouldUpdate(true); - auto pathOrig = PathCombine(instanceRoot(), "version.json"); - QFile::remove(pathOrig); - reloadFullVersion(); + QFile::remove(PathCombine(instanceRoot(), "version.json")); + clearFullVersion(); return true; } @@ -327,6 +332,13 @@ bool DerpInstance::reloadFullVersion(QWidget *widgetParent) return ret; } +void DerpInstance::clearFullVersion() +{ + I_D(DerpInstance); + d->version->clear(); + emit versionReloaded(); +} + std::shared_ptr DerpInstance::getFullVersion() { I_D(DerpInstance); diff --git a/logic/DerpInstance.h b/logic/DerpInstance.h index 37d3df52..46f953c0 100644 --- a/logic/DerpInstance.h +++ b/logic/DerpInstance.h @@ -53,6 +53,8 @@ public: /// reload the full version json files. return true on success! bool reloadFullVersion(QWidget *widgetParent = 0); + /// clears all version information in preparation for an update + void clearFullVersion(); /// get the current full version info std::shared_ptr getFullVersion(); /// is the current version original, or custom? diff --git a/logic/DerpVersion.cpp b/logic/DerpVersion.cpp index f13ac620..cabb2b24 100644 --- a/logic/DerpVersion.cpp +++ b/logic/DerpVersion.cpp @@ -22,6 +22,7 @@ DerpVersion::DerpVersion(DerpInstance *instance, QObject *parent) : QAbstractListModel(parent), m_instance(instance) { + clear(); } bool DerpVersion::reload(QWidget *widgetParent) @@ -29,6 +30,20 @@ bool DerpVersion::reload(QWidget *widgetParent) return DerpVersionBuilder::build(this, m_instance, widgetParent); } +void DerpVersion::clear() +{ + id.clear(); + time.clear(); + releaseTime.clear(); + type.clear(); + assets.clear(); + processArguments.clear(); + minecraftArguments.clear(); + minimumLauncherVersion = 0xDEADBEAF; + mainClass.clear(); + libraries.clear(); +} + QList > DerpVersion::getActiveNormalLibs() { QList > output; diff --git a/logic/DerpVersion.h b/logic/DerpVersion.h index cadfa850..f2132ad8 100644 --- a/logic/DerpVersion.h +++ b/logic/DerpVersion.h @@ -39,6 +39,7 @@ public: virtual Qt::ItemFlags flags(const QModelIndex &index) const; bool reload(QWidget *widgetParent); + void clear(); public: QList> getActiveNormalLibs(); diff --git a/logic/DerpVersionBuilder.cpp b/logic/DerpVersionBuilder.cpp index d8091f32..b0da8205 100644 --- a/logic/DerpVersionBuilder.cpp +++ b/logic/DerpVersionBuilder.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "DerpVersion.h" #include "DerpInstance.h" @@ -45,7 +46,7 @@ bool DerpVersionBuilder::build(DerpVersion *version, DerpInstance *instance, QWi bool DerpVersionBuilder::build() { - clear(); + m_version->clear(); QDir root(m_instance->instanceRoot()); QDir patches(root.absoluteFilePath("patches/")); @@ -112,20 +113,6 @@ bool DerpVersionBuilder::build() return true; } -void DerpVersionBuilder::clear() -{ - m_version->id.clear(); - m_version->time.clear(); - m_version->releaseTime.clear(); - m_version->type.clear(); - m_version->assets.clear(); - m_version->processArguments.clear(); - m_version->minecraftArguments.clear(); - m_version->minimumLauncherVersion = 0xDEADBEAF; - m_version->mainClass.clear(); - m_version->libraries.clear(); -} - void applyString(const QJsonObject &obj, const QString &key, QString &out) { if (obj.contains(key) && obj.value(key).isString()) @@ -181,6 +168,7 @@ bool DerpVersionBuilder::apply(const QJsonObject &object) } // libraries + if (object.contains("libraries")) { auto librariesValue = object.value("libraries"); if (!librariesValue.isArray()) diff --git a/logic/LiteLoaderInstaller.cpp b/logic/LiteLoaderInstaller.cpp index 8a120eab..8aed47e7 100644 --- a/logic/LiteLoaderInstaller.cpp +++ b/logic/LiteLoaderInstaller.cpp @@ -15,12 +15,18 @@ #include "LiteLoaderInstaller.h" +#include +#include + +#include "logger/QsLog.h" + #include "DerpVersion.h" #include "DerpLibrary.h" +#include "DerpInstance.h" QMap LiteLoaderInstaller::m_launcherWrapperVersionMapping; -LiteLoaderInstaller::LiteLoaderInstaller(const QString &mcVersion) : m_mcVersion(mcVersion) +LiteLoaderInstaller::LiteLoaderInstaller() { if (m_launcherWrapperVersionMapping.isEmpty()) { @@ -31,71 +37,82 @@ LiteLoaderInstaller::LiteLoaderInstaller(const QString &mcVersion) : m_mcVersion } } -bool LiteLoaderInstaller::canApply() const +bool LiteLoaderInstaller::canApply(DerpInstance *instance) const { - return m_launcherWrapperVersionMapping.contains(m_mcVersion); + return m_launcherWrapperVersionMapping.contains(instance->intendedVersionId()); } -bool LiteLoaderInstaller::apply(std::shared_ptr to) +bool LiteLoaderInstaller::isApplied(DerpInstance *on) { - // DERPFIX + return QFile::exists(filename(on->instanceRoot())); +} - applyLaunchwrapper(to); - applyLiteLoader(to); - - to->mainClass = "net.minecraft.launchwrapper.Launch"; - if (!to->minecraftArguments.contains( - " --tweakClass com.mumfrey.liteloader.launch.LiteLoaderTweaker")) +bool LiteLoaderInstaller::add(DerpInstance *to) +{ + if (!patchesDir(to->instanceRoot()).exists()) { - to->minecraftArguments.append( - " --tweakClass com.mumfrey.liteloader.launch.LiteLoaderTweaker"); + QDir(to->instanceRoot()).mkdir("patches"); } + if (isApplied(to)) + { + if (!remove(to)) + { + return false; + } + } + + QJsonObject obj; + + obj.insert("mainClass", QString("net.minecraft.launchwrapper.Launch")); + obj.insert("+minecraftArguments", QString(" --tweakClass com.mumfrey.liteloader.launch.LiteLoaderTweaker")); + obj.insert("order", 10); + + QJsonArray libraries; + + // launchwrapper + { + DerpLibrary launchwrapperLib("net.minecraft:launchwrapper:" + m_launcherWrapperVersionMapping[to->intendedVersionId()]); + launchwrapperLib.finalize(); + QJsonObject lwLibObj = launchwrapperLib.toJson(); + lwLibObj.insert("insert", QString("beginning")); + libraries.append(lwLibObj); + } + + // liteloader + { + DerpLibrary liteloaderLib("com.mumfrey:liteloader:" + to->intendedVersionId()); + liteloaderLib.setBaseUrl("http://dl.liteloader.com/versions/"); + liteloaderLib.finalize(); + QJsonObject llLibObj = liteloaderLib.toJson(); + llLibObj.insert("insert", QString("beginning")); + libraries.append(llLibObj); + } + + obj.insert("+libraries", libraries); + + 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; } -void LiteLoaderInstaller::applyLaunchwrapper(std::shared_ptr to) +bool LiteLoaderInstaller::remove(DerpInstance *from) { - const QString intendedVersion = m_launcherWrapperVersionMapping[m_mcVersion]; - - QMutableListIterator> it(to->libraries); - while (it.hasNext()) - { - it.next(); - if (it.value()->rawName().startsWith("net.minecraft:launchwrapper:")) - { - if (it.value()->version() >= intendedVersion) - { - return; - } - else - { - it.remove(); - } - } - } - - std::shared_ptr lib(new DerpLibrary( - "net.minecraft:launchwrapper:" + m_launcherWrapperVersionMapping[m_mcVersion])); - lib->finalize(); - to->libraries.prepend(lib); + return QFile::remove(filename(from->instanceRoot())); } -void LiteLoaderInstaller::applyLiteLoader(std::shared_ptr to) +QString LiteLoaderInstaller::filename(const QString &root) const { - QMutableListIterator> it(to->libraries); - while (it.hasNext()) - { - it.next(); - if (it.value()->rawName().startsWith("com.mumfrey:liteloader:")) - { - it.remove(); - } - } - - std::shared_ptr lib( - new DerpLibrary("com.mumfrey:liteloader:" + m_mcVersion)); - lib->setBaseUrl("http://dl.liteloader.com/versions/"); - lib->finalize(); - to->libraries.prepend(lib); + return patchesDir(root).absoluteFilePath(id() + ".json"); +} +QDir LiteLoaderInstaller::patchesDir(const QString &root) const +{ + return QDir(root + "/patches/"); } diff --git a/logic/LiteLoaderInstaller.h b/logic/LiteLoaderInstaller.h index d7b8ce77..48ef4baf 100644 --- a/logic/LiteLoaderInstaller.h +++ b/logic/LiteLoaderInstaller.h @@ -19,21 +19,25 @@ #include class DerpVersion; +class DerpInstance; +class QDir; +// TODO base class class LiteLoaderInstaller { public: - LiteLoaderInstaller(const QString &mcVersion); + LiteLoaderInstaller(); - bool canApply() const; + bool canApply(DerpInstance *instance) const; + bool isApplied(DerpInstance *on); - bool apply(std::shared_ptr to); + bool add(DerpInstance *to); + bool remove(DerpInstance *from); private: - QString m_mcVersion; - - void applyLaunchwrapper(std::shared_ptr to); - void applyLiteLoader(std::shared_ptr to); + virtual QString id() const { return "com.mumfrey.liteloader"; } + QString filename(const QString &root) const; + QDir patchesDir(const QString &root) const; static QMap m_launcherWrapperVersionMapping; }; From c39d26f4453166603749826eee1a732c815047d0 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Wed, 22 Jan 2014 22:15:50 +0100 Subject: [PATCH 04/13] Got liteloader working. Patching more or less works --- logic/DerpRule.cpp | 2 +- logic/DerpRule.h | 2 +- logic/DerpVersionBuilder.cpp | 272 ++++++++++++++++++++++++++-------- logic/DerpVersionBuilder.h | 8 + logic/LiteLoaderInstaller.cpp | 4 +- 5 files changed, 221 insertions(+), 67 deletions(-) diff --git a/logic/DerpRule.cpp b/logic/DerpRule.cpp index d4cf1ba3..5ed200e3 100644 --- a/logic/DerpRule.cpp +++ b/logic/DerpRule.cpp @@ -18,7 +18,7 @@ #include "DerpRule.h" -QList> rulesFromJsonV4(QJsonObject &objectWithRules) +QList> rulesFromJsonV4(const QJsonObject &objectWithRules) { QList> rules; auto rulesVal = objectWithRules.value("rules"); diff --git a/logic/DerpRule.h b/logic/DerpRule.h index 7895ea98..0254028c 100644 --- a/logic/DerpRule.h +++ b/logic/DerpRule.h @@ -27,7 +27,7 @@ enum RuleAction }; RuleAction RuleAction_fromString(QString); -QList> rulesFromJsonV4(QJsonObject &objectWithRules); +QList> rulesFromJsonV4(const QJsonObject &objectWithRules); class Rule { diff --git a/logic/DerpVersionBuilder.cpp b/logic/DerpVersionBuilder.cpp index b0da8205..eb215cca 100644 --- a/logic/DerpVersionBuilder.cpp +++ b/logic/DerpVersionBuilder.cpp @@ -113,12 +113,23 @@ bool DerpVersionBuilder::build() return true; } -void applyString(const QJsonObject &obj, const QString &key, QString &out) +void applyString(const QJsonObject &obj, const QString &key, QString &out, const bool onlyOverride = true) { if (obj.contains(key) && obj.value(key).isString()) { out = obj.value(key).toString(); } + else if (!onlyOverride) + { + if (obj.contains("+" + key) && obj.value("+" + key).isString()) + { + out += obj.value("+" + key).toString(); + } + else if (obj.contains("-" + key) && obj.value("-" + key).isString()) + { + out.remove(obj.value("-" + key).toString()); + } + } } void applyString(const QJsonObject &obj, const QString &key, std::shared_ptr lib, void(DerpLibrary::*func)(const QString &val)) { @@ -131,7 +142,7 @@ bool DerpVersionBuilder::apply(const QJsonObject &object) { applyString(object, "id", m_version->id); applyString(object, "mainClass", m_version->mainClass); - applyString(object, "processArguments", m_version->processArguments); + applyString(object, "processArguments", m_version->processArguments, false); { const QString toCompare = m_version->processArguments.toLower(); if (toCompare == "legacy") @@ -147,7 +158,7 @@ bool DerpVersionBuilder::apply(const QJsonObject &object) m_version->minecraftArguments = "--username ${auth_player_name} --session ${auth_session} --version ${profile_name}"; } } - applyString(object, "minecraftArguments", m_version->minecraftArguments); + applyString(object, "minecraftArguments", m_version->minecraftArguments, false); applyString(object, "type", m_version->type); applyString(object, "releaseTime", m_version->releaseTime); applyString(object, "time", m_version->time); @@ -170,80 +181,215 @@ bool DerpVersionBuilder::apply(const QJsonObject &object) // libraries if (object.contains("libraries")) { + m_version->libraries.clear(); auto librariesValue = object.value("libraries"); if (!librariesValue.isArray()) { QMessageBox::critical(m_widgetParent, QObject::tr("Error"), QObject::tr("One json files contains a libraries field, but it's not an array")); return false; } + auto array = librariesValue.toArray(); + for (auto libVal : array) + { + if (libVal.isObject()) + { + if (!applyLibrary(libVal.toObject(), Override)) + { + return false; + } + } + + } + } + + // +libraries + if (object.contains("+libraries")) + { + auto librariesValue = object.value("+libraries"); + if (!librariesValue.isArray()) + { + QMessageBox::critical(m_widgetParent, QObject::tr("Error"), QObject::tr("One json files contains a libraries field, but it's not an array")); + return false; + } for (auto libVal : librariesValue.toArray()) { - if (!libVal.isObject()) + if (libVal.isObject()) { - continue; + applyLibrary(libVal.toObject(), Add); } - QJsonObject libObj = libVal.toObject(); - - // Library name - auto nameVal = libObj.value("name"); - if (!nameVal.isString()) - { - continue; - } - std::shared_ptr library(new DerpLibrary(nameVal.toString())); - - applyString(libObj, "url", library, &DerpLibrary::setBaseUrl); - applyString(libObj, "MMC-hint", library, &DerpLibrary::setHint); - applyString(libObj, "MMC-absulute_url", library, &DerpLibrary::setAbsoluteUrl); - applyString(libObj, "MMC-absoluteUrl", library, &DerpLibrary::setAbsoluteUrl); - - auto extractVal = libObj.value("extract"); - if (extractVal.isObject()) - { - QStringList excludes; - auto extractObj = extractVal.toObject(); - auto excludesVal = extractObj.value("exclude"); - if (excludesVal.isArray()) - { - auto excludesList = excludesVal.toArray(); - for (auto excludeVal : excludesList) - { - if (excludeVal.isString()) - { - excludes.append(excludeVal.toString()); - } - } - library->extract_excludes = excludes; - } - } - - auto nativesVal = libObj.value("natives"); - if (nativesVal.isObject()) - { - library->setIsNative(); - auto nativesObj = nativesVal.toObject(); - for (auto it = nativesObj.begin(); it != nativesObj.end(); ++it) - { - auto osType = OpSys_fromString(it.key()); - if (osType == Os_Other) - { - continue; - } - if (!it.value().isString()) - { - continue; - } - library->addNative(osType, it.value().toString()); - } - } - - library->setRules(rulesFromJsonV4(libObj)); - library->finalize(); - m_version->libraries.append(library); } } + // -libraries + if (object.contains("-libraries")) + { + auto librariesValue = object.value("-libraries"); + if (!librariesValue.isArray()) + { + QMessageBox::critical(m_widgetParent, QObject::tr("Error"), QObject::tr("One json files contains a libraries field, but it's not an array")); + return false; + } + for (auto libVal : librariesValue.toArray()) + { + if (libVal.isObject()) + { + applyLibrary(libVal.toObject(), Remove); + } + + } + } + + return true; +} + +int findLibrary(QList > haystack, const QString &needle) +{ + for (int i = 0; i < haystack.size(); ++i) + { + if (QRegExp(needle, Qt::CaseSensitive, QRegExp::WildcardUnix).indexIn(haystack.at(i)->rawName()) != -1) + { + return i; + } + } + return -1; +} + +bool DerpVersionBuilder::applyLibrary(const QJsonObject &lib, const DerpVersionBuilder::Type type) +{ + // Library name + auto nameVal = lib.value("name"); + if (!nameVal.isString()) + { + return false; + } + auto name = nameVal.toString(); + + if (type == Remove) + { + int index = findLibrary(m_version->libraries, name); + if (index >= 0) + { + m_version->libraries.removeAt(index); + } + return true; + } + + if (type == Add && !lib.contains("insert")) + { + return false; + } + + std::shared_ptr library; + + if (lib.value("insert").toString() == "apply" && type == Add) + { + library = m_version->libraries[findLibrary(m_version->libraries, name)]; + } + else + { + library.reset(new DerpLibrary(nameVal.toString())); + } + + applyString(lib, "url", library, &DerpLibrary::setBaseUrl); + applyString(lib, "MMC-hint", library, &DerpLibrary::setHint); + applyString(lib, "MMC-absulute_url", library, &DerpLibrary::setAbsoluteUrl); + applyString(lib, "MMC-absoluteUrl", library, &DerpLibrary::setAbsoluteUrl); + + auto extractVal = lib.value("extract"); + if (extractVal.isObject()) + { + QStringList excludes; + auto extractObj = extractVal.toObject(); + auto excludesVal = extractObj.value("exclude"); + if (excludesVal.isArray()) + { + auto excludesList = excludesVal.toArray(); + for (auto excludeVal : excludesList) + { + if (excludeVal.isString()) + { + excludes.append(excludeVal.toString()); + } + } + library->extract_excludes = excludes; + } + } + + auto nativesVal = lib.value("natives"); + if (nativesVal.isObject()) + { + library->setIsNative(); + auto nativesObj = nativesVal.toObject(); + for (auto it = nativesObj.begin(); it != nativesObj.end(); ++it) + { + auto osType = OpSys_fromString(it.key()); + if (osType == Os_Other) + { + continue; + } + if (!it.value().isString()) + { + continue; + } + library->addNative(osType, it.value().toString()); + } + } + + if (lib.contains("rules")) + { + library->setRules(rulesFromJsonV4(lib)); + } + library->finalize(); + if (type == Override) + { + qDebug() << "appending" << library->rawName(); + m_version->libraries.append(library); + } + else if (lib.value("insert").toString() != "apply") + { + if (lib.value("insert").toString() == "append") + { + m_version->libraries.append(library); + } + else if (lib.value("insert").toString() == "prepend") + { + m_version->libraries.prepend(library); + } + else if (lib.value("insert").isObject()) + { + QJsonObject insertObj = lib.value("insert").toObject(); + if (insertObj.isEmpty()) + { + QMessageBox::critical(m_widgetParent, QObject::tr("Error"), QObject::tr("'insert' object empty")); + return false; + } + const QString key = insertObj.keys().first(); + const QString value = insertObj.value(key).toString(); + const int index = findLibrary(m_version->libraries, value); + if (index >= 0) + { + if (key == "before") + { + m_version->libraries.insert(index, library); + } + else if (key == "after") + { + m_version->libraries.insert(index + 1, library); + } + else + { + QMessageBox::critical(m_widgetParent, QObject::tr("Error"), QObject::tr("Invalid value for 'insert': %1").arg(lib.value("insert").toString())); + return false; + } + } + } + else + { + QMessageBox::critical(m_widgetParent, QObject::tr("Error"), QObject::tr("Invalid value for 'insert': %1").arg(lib.value("insert").toString())); + return false; + } + } return true; } diff --git a/logic/DerpVersionBuilder.h b/logic/DerpVersionBuilder.h index 739065db..5354cb0e 100644 --- a/logic/DerpVersionBuilder.h +++ b/logic/DerpVersionBuilder.h @@ -34,10 +34,18 @@ private: DerpInstance *m_instance; QWidget *m_widgetParent; + enum Type + { + Override, + Add, + Remove + }; + bool build(); void clear(); bool apply(const QJsonObject &object); + bool applyLibrary(const QJsonObject &lib, const Type type); bool read(const QFileInfo &fileInfo, QJsonObject *out); }; diff --git a/logic/LiteLoaderInstaller.cpp b/logic/LiteLoaderInstaller.cpp index 8aed47e7..d582f03a 100644 --- a/logic/LiteLoaderInstaller.cpp +++ b/logic/LiteLoaderInstaller.cpp @@ -75,7 +75,7 @@ bool LiteLoaderInstaller::add(DerpInstance *to) DerpLibrary launchwrapperLib("net.minecraft:launchwrapper:" + m_launcherWrapperVersionMapping[to->intendedVersionId()]); launchwrapperLib.finalize(); QJsonObject lwLibObj = launchwrapperLib.toJson(); - lwLibObj.insert("insert", QString("beginning")); + lwLibObj.insert("insert", QString("prepend")); libraries.append(lwLibObj); } @@ -85,7 +85,7 @@ bool LiteLoaderInstaller::add(DerpInstance *to) liteloaderLib.setBaseUrl("http://dl.liteloader.com/versions/"); liteloaderLib.finalize(); QJsonObject llLibObj = liteloaderLib.toJson(); - llLibObj.insert("insert", QString("beginning")); + llLibObj.insert("insert", QString("prepend")); libraries.append(llLibObj); } From 156bc8f27656c115bf1b023cd4ebc5f629df3887 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Thu, 23 Jan 2014 21:31:41 +0100 Subject: [PATCH 05/13] Forge works now too, and so does forge+liteloader --- CMakeLists.txt | 2 + gui/dialogs/DerpModEditDialog.cpp | 16 +++++--- logic/BaseInstaller.cpp | 66 +++++++++++++++++++++++++++++++ logic/BaseInstaller.h | 39 ++++++++++++++++++ logic/DerpFTBInstance.cpp | 2 +- logic/DerpVersion.cpp | 47 ++++++++++++++-------- logic/DerpVersion.h | 4 ++ logic/DerpVersionBuilder.cpp | 37 ++++++++++++++++- logic/DerpVersionBuilder.h | 2 + logic/ForgeInstaller.cpp | 48 ++++++++++++++++------ logic/ForgeInstaller.h | 9 ++++- logic/LiteLoaderInstaller.cpp | 32 ++------------- logic/LiteLoaderInstaller.h | 22 ++++------- 13 files changed, 245 insertions(+), 81 deletions(-) create mode 100644 logic/BaseInstaller.cpp create mode 100644 logic/BaseInstaller.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 43de626b..c5339a30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -416,6 +416,8 @@ logic/DerpRule.h logic/DerpRule.cpp logic/OpSys.h logic/OpSys.cpp +logic/BaseInstaller.h +logic/BaseInstaller.cpp logic/ForgeInstaller.h logic/ForgeInstaller.cpp logic/LiteLoaderInstaller.h diff --git a/gui/dialogs/DerpModEditDialog.cpp b/gui/dialogs/DerpModEditDialog.cpp index aafaa2e2..216aa59d 100644 --- a/gui/dialogs/DerpModEditDialog.cpp +++ b/gui/dialogs/DerpModEditDialog.cpp @@ -55,7 +55,6 @@ DerpModEditDialog::DerpModEditDialog(DerpInstance *inst, QWidget *parent) main_model->setSourceModel(m_version.get()); ui->libraryTreeView->setModel(main_model); ui->libraryTreeView->installEventFilter(this); - ui->mainClassEdit->setText(m_version->mainClass); updateVersionControls(); } else @@ -98,6 +97,7 @@ void DerpModEditDialog::updateVersionControls() ui->forgeBtn->setEnabled(true); ui->liteloaderBtn->setEnabled(LiteLoaderInstaller().canApply(m_inst)); ui->customEditorBtn->setEnabled(customVersion); + ui->mainClassEdit->setText(m_version->mainClass); } void DerpModEditDialog::disableVersionControls() @@ -105,6 +105,7 @@ void DerpModEditDialog::disableVersionControls() ui->forgeBtn->setEnabled(false); ui->liteloaderBtn->setEnabled(false); ui->customEditorBtn->setEnabled(false); + ui->mainClassEdit->setText(""); } void DerpModEditDialog::on_customEditorBtn_clicked() @@ -140,9 +141,9 @@ void DerpModEditDialog::on_forgeBtn_clicked() // install QString forgePath = entry->getFullPath(); ForgeInstaller forge(forgePath, forgeVersion->universal_url); - if (!forge.apply(m_version)) + if (!forge.add(m_inst)) { - // failure notice + QLOG_ERROR() << "Failure installing forge"; } } else @@ -155,12 +156,13 @@ void DerpModEditDialog::on_forgeBtn_clicked() // install QString forgePath = entry->getFullPath(); ForgeInstaller forge(forgePath, forgeVersion->universal_url); - if (!forge.apply(m_version)) + if (!forge.add(m_inst)) { - // failure notice + QLOG_ERROR() << "Failure installing forge"; } } } + m_inst->reloadFullVersion(this); } void DerpModEditDialog::on_liteloaderBtn_clicked() @@ -180,6 +182,10 @@ void DerpModEditDialog::on_liteloaderBtn_clicked() this, tr("LiteLoader"), tr("For reasons unknown, the LiteLoader installation failed. Check your MultiMC log files for details.")); } + else + { + m_inst->reloadFullVersion(this); + } } bool DerpModEditDialog::loaderListFilter(QKeyEvent *keyEvent) diff --git a/logic/BaseInstaller.cpp b/logic/BaseInstaller.cpp new file mode 100644 index 00000000..74a8e909 --- /dev/null +++ b/logic/BaseInstaller.cpp @@ -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. + */ + +#include "BaseInstaller.h" + +#include + +#include "DerpVersion.h" +#include "DerpLibrary.h" +#include "DerpInstance.h" + +#include "cmdutils.h" + +BaseInstaller::BaseInstaller() +{ + +} + +bool BaseInstaller::isApplied(DerpInstance *on) +{ + return QFile::exists(filename(on->instanceRoot())); +} + +bool BaseInstaller::add(DerpInstance *to) +{ + if (!patchesDir(to->instanceRoot()).exists()) + { + QDir(to->instanceRoot()).mkdir("patches"); + } + + if (isApplied(to)) + { + if (!remove(to)) + { + return false; + } + } + + return true; +} + +bool BaseInstaller::remove(DerpInstance *from) +{ + return QFile::remove(filename(from->instanceRoot())); +} + +QString BaseInstaller::filename(const QString &root) const +{ + return patchesDir(root).absoluteFilePath(id() + ".json"); +} +QDir BaseInstaller::patchesDir(const QString &root) const +{ + return QDir(root + "/patches/"); +} diff --git a/logic/BaseInstaller.h b/logic/BaseInstaller.h new file mode 100644 index 00000000..08f78bfc --- /dev/null +++ b/logic/BaseInstaller.h @@ -0,0 +1,39 @@ +/* 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 + +class DerpInstance; +class QDir; +class QString; + +class BaseInstaller +{ +public: + BaseInstaller(); + + virtual bool canApply(DerpInstance *instance) const { return true; } + bool isApplied(DerpInstance *on); + + virtual bool add(DerpInstance *to); + virtual bool remove(DerpInstance *from); + +protected: + virtual QString id() const = 0; + QString filename(const QString &root) const; + QDir patchesDir(const QString &root) const; +}; diff --git a/logic/DerpFTBInstance.cpp b/logic/DerpFTBInstance.cpp index f9aeeca0..9b687461 100644 --- a/logic/DerpFTBInstance.cpp +++ b/logic/DerpFTBInstance.cpp @@ -61,7 +61,7 @@ slots: return; } auto version = instance->getFullVersion(); - if (!forge.apply(version)) + if (!forge.add(instance)) { emitFailed(tr("Couldn't install Forge")); return; diff --git a/logic/DerpVersion.cpp b/logic/DerpVersion.cpp index cabb2b24..f4a8dd97 100644 --- a/logic/DerpVersion.cpp +++ b/logic/DerpVersion.cpp @@ -44,6 +44,26 @@ void DerpVersion::clear() libraries.clear(); } +void DerpVersion::dump() const +{ + qDebug().nospace() << "DerpVersion(" + << "\n\tid=" << id + << "\n\ttime=" << time + << "\n\treleaseTime=" << releaseTime + << "\n\ttype=" << type + << "\n\tassets=" << assets + << "\n\tprocessArguments=" << processArguments + << "\n\tminecraftArguments=" << minecraftArguments + << "\n\tminimumLauncherVersion=" << minimumLauncherVersion + << "\n\tmainClass=" << mainClass + << "\n\tlibraries="; + for (auto lib : libraries) + { + qDebug().nospace() << "\n\t\t" << lib.get(); + } + qDebug().nospace() << "\n)"; +} + QList > DerpVersion::getActiveNormalLibs() { QList > output; @@ -70,6 +90,16 @@ QList > DerpVersion::getActiveNativeLibs() return output; } +std::shared_ptr DerpVersion::fromJson(const QJsonObject &obj) +{ + std::shared_ptr version(new DerpVersion(0)); + if (DerpVersionBuilder::read(version.get(), obj)) + { + return version; + } + return 0; +} + QVariant DerpVersion::data(const QModelIndex &index, int role) const { if (!index.isValid()) @@ -143,22 +173,7 @@ int DerpVersion::columnCount(const QModelIndex &parent) const QDebug operator<<(QDebug &dbg, const DerpVersion *version) { - dbg.nospace() << "DerpVersion(" - << "\n\tid=" << version->id - << "\n\ttime=" << version->time - << "\n\treleaseTime=" << version->releaseTime - << "\n\ttype=" << version->type - << "\n\tassets=" << version->assets - << "\n\tprocessArguments=" << version->processArguments - << "\n\tminecraftArguments=" << version->minecraftArguments - << "\n\tminimumLauncherVersion=" << version->minimumLauncherVersion - << "\n\tmainClass=" << version->mainClass - << "\n\tlibraries="; - for (auto lib : version->libraries) - { - dbg.nospace() << "\n\t\t" << lib.get(); - } - dbg.nospace() << "\n)"; + version->dump(); return dbg.maybeSpace(); } QDebug operator<<(QDebug &dbg, const DerpLibrary *library) diff --git a/logic/DerpVersion.h b/logic/DerpVersion.h index f2132ad8..4481d146 100644 --- a/logic/DerpVersion.h +++ b/logic/DerpVersion.h @@ -41,10 +41,14 @@ public: bool reload(QWidget *widgetParent); void clear(); + void dump() const; + public: QList> getActiveNormalLibs(); QList> getActiveNativeLibs(); + static std::shared_ptr fromJson(const QJsonObject &obj); + // data members public: /// the ID - determines which jar to use! ACTUALLY IMPORTANT! diff --git a/logic/DerpVersionBuilder.cpp b/logic/DerpVersionBuilder.cpp index eb215cca..20f43404 100644 --- a/logic/DerpVersionBuilder.cpp +++ b/logic/DerpVersionBuilder.cpp @@ -29,6 +29,7 @@ #include "DerpVersion.h" #include "DerpInstance.h" #include "DerpRule.h" +#include "logger/QsLog.h" DerpVersionBuilder::DerpVersionBuilder() { @@ -44,6 +45,15 @@ bool DerpVersionBuilder::build(DerpVersion *version, DerpInstance *instance, QWi return builder.build(); } +bool DerpVersionBuilder::read(DerpVersion *version, const QJsonObject &obj) +{ + DerpVersionBuilder builder; + builder.m_version = version; + builder.m_instance = 0; + builder.m_widgetParent = 0; + return builder.read(obj); +} + bool DerpVersionBuilder::build() { m_version->clear(); @@ -55,6 +65,7 @@ bool DerpVersionBuilder::build() // version.json { + QLOG_INFO() << "Reading version.json"; QJsonObject obj; if (!read(QFileInfo(root.absoluteFilePath("version.json")), &obj)) { @@ -73,6 +84,7 @@ bool DerpVersionBuilder::build() QMap objects; for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files)) { + QLOG_INFO() << "Reading" << info.fileName(); QJsonObject obj; if (!read(info, &obj)) { @@ -87,6 +99,7 @@ bool DerpVersionBuilder::build() } for (auto object : objects.values()) { + qDebug() << "Applying object with order" << objects.key(object); if (!apply(object)) { return false; @@ -98,6 +111,7 @@ bool DerpVersionBuilder::build() { if (QFile::exists(root.absoluteFilePath("custom.json"))) { + QLOG_INFO() << "Reading custom.json"; QJsonObject obj; if (!read(QFileInfo(root.absoluteFilePath("custom.json")), &obj)) { @@ -113,6 +127,13 @@ bool DerpVersionBuilder::build() return true; } +bool DerpVersionBuilder::read(const QJsonObject &obj) +{ + m_version->clear(); + + return apply(obj); +} + void applyString(const QJsonObject &obj, const QString &key, QString &out, const bool onlyOverride = true) { if (obj.contains(key) && obj.value(key).isString()) @@ -142,7 +163,9 @@ bool DerpVersionBuilder::apply(const QJsonObject &object) { applyString(object, "id", m_version->id); applyString(object, "mainClass", m_version->mainClass); + applyString(object, "minecraftArguments", m_version->minecraftArguments, false); applyString(object, "processArguments", m_version->processArguments, false); + if (m_version->minecraftArguments.isEmpty()) { const QString toCompare = m_version->processArguments.toLower(); if (toCompare == "legacy") @@ -158,7 +181,6 @@ bool DerpVersionBuilder::apply(const QJsonObject &object) m_version->minecraftArguments = "--username ${auth_player_name} --session ${auth_session} --version ${profile_name}"; } } - applyString(object, "minecraftArguments", m_version->minecraftArguments, false); applyString(object, "type", m_version->type); applyString(object, "releaseTime", m_version->releaseTime); applyString(object, "time", m_version->time); @@ -282,6 +304,18 @@ bool DerpVersionBuilder::applyLibrary(const QJsonObject &lib, const DerpVersionB std::shared_ptr library; + if (lib.value("insert").toString() != "apply" && type == Add) + { + QMutableListIterator > it(m_version->libraries); + while (it.hasNext()) + { + if (it.next()->rawName() == name) + { + it.remove(); + } + } + } + if (lib.value("insert").toString() == "apply" && type == Add) { library = m_version->libraries[findLibrary(m_version->libraries, name)]; @@ -343,7 +377,6 @@ bool DerpVersionBuilder::applyLibrary(const QJsonObject &lib, const DerpVersionB library->finalize(); if (type == Override) { - qDebug() << "appending" << library->rawName(); m_version->libraries.append(library); } else if (lib.value("insert").toString() != "apply") diff --git a/logic/DerpVersionBuilder.h b/logic/DerpVersionBuilder.h index 5354cb0e..b94cd8e9 100644 --- a/logic/DerpVersionBuilder.h +++ b/logic/DerpVersionBuilder.h @@ -28,6 +28,7 @@ class DerpVersionBuilder DerpVersionBuilder(); public: static bool build(DerpVersion *version, DerpInstance *instance, QWidget *widgetParent); + static bool read(DerpVersion *version, const QJsonObject &obj); private: DerpVersion *m_version; @@ -42,6 +43,7 @@ private: }; bool build(); + bool read(const QJsonObject &obj); void clear(); bool apply(const QJsonObject &object); diff --git a/logic/ForgeInstaller.cpp b/logic/ForgeInstaller.cpp index 29735a7d..35663ddd 100644 --- a/logic/ForgeInstaller.cpp +++ b/logic/ForgeInstaller.cpp @@ -22,13 +22,13 @@ #include #include #include "MultiMC.h" +#include "DerpInstance.h" #include +#include #include #include -// DERPFIX - ForgeInstaller::ForgeInstaller(QString filename, QString universal_url) { std::shared_ptr newVersion; @@ -64,7 +64,7 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url) // read the forge version info { - // DERPFIX newVersion = DerpVersion::fromJson(versionInfoVal.toObject()); + newVersion = DerpVersion::fromJson(versionInfoVal.toObject()); if (!newVersion) return; } @@ -109,12 +109,22 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url) realVersionId = m_forge_version->id = installObj.value("minecraft").toString(); } -bool ForgeInstaller::apply(std::shared_ptr to) +bool ForgeInstaller::add(DerpInstance *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) @@ -133,27 +143,43 @@ bool ForgeInstaller::apply(std::shared_ptr to) if (blacklist.contains(libName)) continue; - // find an entry that matches this one + QJsonObject libObj = lib->toJson(); + bool found = false; - for (auto tolib : to->libraries) + // find an entry that matches this one + for (auto tolib : to->getFullVersion()->libraries) { if (tolib->name() != libName) continue; found = true; // replace lib - tolib = lib; + libObj.insert("insert", QString("apply")); break; } if (!found) { // add lib - to->libraries.insert(sliding_insert_window, lib); + QJsonObject insertObj; + insertObj.insert("before", to->getFullVersion()->libraries.at(sliding_insert_window)->rawName()); + libObj.insert("insert", insertObj); sliding_insert_window++; } + librariesPlus.append(libObj); } - to->mainClass = m_forge_version->mainClass; - to->minecraftArguments = m_forge_version->minecraftArguments; - to->processArguments = m_forge_version->processArguments; + obj.insert("+libraries", librariesPlus); + obj.insert("mainClass", m_forge_version->mainClass); + obj.insert("minecraftArguments", m_forge_version->minecraftArguments); + obj.insert("processArguments", m_forge_version->processArguments); } + + 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; } diff --git a/logic/ForgeInstaller.h b/logic/ForgeInstaller.h index 65cad87c..6490b5bf 100644 --- a/logic/ForgeInstaller.h +++ b/logic/ForgeInstaller.h @@ -14,17 +14,22 @@ */ #pragma once + +#include "BaseInstaller.h" + #include #include class DerpVersion; -class ForgeInstaller +class ForgeInstaller : public BaseInstaller { public: ForgeInstaller(QString filename, QString universal_url); - bool apply(std::shared_ptr to); + bool add(DerpInstance *to) override; + + QString id() const override { return "net.minecraftforge"; } private: // the version, read from the installer diff --git a/logic/LiteLoaderInstaller.cpp b/logic/LiteLoaderInstaller.cpp index d582f03a..71c7011f 100644 --- a/logic/LiteLoaderInstaller.cpp +++ b/logic/LiteLoaderInstaller.cpp @@ -27,6 +27,7 @@ QMap LiteLoaderInstaller::m_launcherWrapperVersionMapping; LiteLoaderInstaller::LiteLoaderInstaller() + : BaseInstaller() { if (m_launcherWrapperVersionMapping.isEmpty()) { @@ -42,24 +43,11 @@ bool LiteLoaderInstaller::canApply(DerpInstance *instance) const return m_launcherWrapperVersionMapping.contains(instance->intendedVersionId()); } -bool LiteLoaderInstaller::isApplied(DerpInstance *on) -{ - return QFile::exists(filename(on->instanceRoot())); -} - bool LiteLoaderInstaller::add(DerpInstance *to) { - if (!patchesDir(to->instanceRoot()).exists()) + if (!BaseInstaller::add(to)) { - QDir(to->instanceRoot()).mkdir("patches"); - } - - if (isApplied(to)) - { - if (!remove(to)) - { - return false; - } + return false; } QJsonObject obj; @@ -102,17 +90,3 @@ bool LiteLoaderInstaller::add(DerpInstance *to) return true; } - -bool LiteLoaderInstaller::remove(DerpInstance *from) -{ - return QFile::remove(filename(from->instanceRoot())); -} - -QString LiteLoaderInstaller::filename(const QString &root) const -{ - return patchesDir(root).absoluteFilePath(id() + ".json"); -} -QDir LiteLoaderInstaller::patchesDir(const QString &root) const -{ - return QDir(root + "/patches/"); -} diff --git a/logic/LiteLoaderInstaller.h b/logic/LiteLoaderInstaller.h index 48ef4baf..c128ee22 100644 --- a/logic/LiteLoaderInstaller.h +++ b/logic/LiteLoaderInstaller.h @@ -14,30 +14,22 @@ */ #pragma once + +#include "BaseInstaller.h" + #include #include -#include -class DerpVersion; -class DerpInstance; -class QDir; - -// TODO base class -class LiteLoaderInstaller +class LiteLoaderInstaller : public BaseInstaller { public: LiteLoaderInstaller(); - bool canApply(DerpInstance *instance) const; - bool isApplied(DerpInstance *on); - - bool add(DerpInstance *to); - bool remove(DerpInstance *from); + bool canApply(DerpInstance *instance) const override; + bool add(DerpInstance *to) override; private: - virtual QString id() const { return "com.mumfrey.liteloader"; } - QString filename(const QString &root) const; - QDir patchesDir(const QString &root) const; + virtual QString id() const override { return "com.mumfrey.liteloader"; } static QMap m_launcherWrapperVersionMapping; }; From 7d5787025aa5cebf6778f71e79f248f10b8541c9 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Fri, 24 Jan 2014 18:12:02 +0100 Subject: [PATCH 06/13] Change naming from Derp -> OneSix until the new instance type supports legacy --- CMakeLists.txt | 38 +-- gui/MainWindow.cpp | 4 +- ...EditDialog.cpp => OneSixModEditDialog.cpp} | 46 +-- ...pModEditDialog.h => OneSixModEditDialog.h} | 16 +- ...odEditDialog.ui => OneSixModEditDialog.ui} | 4 +- logic/BaseInstaller.cpp | 12 +- logic/BaseInstaller.h | 10 +- logic/BaseInstance.h | 2 +- logic/DerpVersion.cpp | 194 ------------ logic/DerpVersion.h | 115 ------- logic/ForgeInstaller.cpp | 14 +- logic/ForgeInstaller.h | 6 +- logic/InstanceFactory.cpp | 32 +- logic/LegacyInstance.h | 2 +- logic/LiteLoaderInstaller.cpp | 14 +- logic/LiteLoaderInstaller.h | 4 +- logic/MinecraftVersion.h | 6 +- logic/NostalgiaInstance.cpp | 2 +- logic/NostalgiaInstance.h | 4 +- ...pFTBInstance.cpp => OneSixFTBInstance.cpp} | 38 +-- ...{DerpFTBInstance.h => OneSixFTBInstance.h} | 10 +- .../{DerpInstance.cpp => OneSixInstance.cpp} | 86 +++--- logic/{DerpInstance.h => OneSixInstance.h} | 10 +- .../{DerpInstance_p.h => OneSixInstance_p.h} | 6 +- logic/{DerpLibrary.cpp => OneSixLibrary.cpp} | 38 +-- logic/{DerpLibrary.h => OneSixLibrary.h} | 4 +- logic/{DerpRule.cpp => OneSixRule.cpp} | 2 +- logic/{DerpRule.h => OneSixRule.h} | 10 +- logic/{DerpUpdate.cpp => OneSixUpdate.cpp} | 58 ++-- logic/{DerpUpdate.h => OneSixUpdate.h} | 4 +- logic/OneSixVersion.cpp | 292 +++++------------- logic/OneSixVersion.h | 45 +-- ...onBuilder.cpp => OneSixVersionBuilder.cpp} | 46 +-- ...ersionBuilder.h => OneSixVersionBuilder.h} | 16 +- logic/lists/MinecraftVersionList.cpp | 6 +- 35 files changed, 375 insertions(+), 821 deletions(-) rename gui/dialogs/{DerpModEditDialog.cpp => OneSixModEditDialog.cpp} (84%) rename gui/dialogs/{DerpModEditDialog.h => OneSixModEditDialog.h} (83%) rename gui/dialogs/{DerpModEditDialog.ui => OneSixModEditDialog.ui} (99%) delete mode 100644 logic/DerpVersion.cpp delete mode 100644 logic/DerpVersion.h rename logic/{DerpFTBInstance.cpp => OneSixFTBInstance.cpp} (69%) rename logic/{DerpFTBInstance.h => OneSixFTBInstance.h} (56%) rename logic/{DerpInstance.cpp => OneSixInstance.cpp} (80%) rename logic/{DerpInstance.h => OneSixInstance.h} (89%) rename logic/{DerpInstance_p.h => OneSixInstance_p.h} (85%) rename logic/{DerpLibrary.cpp => OneSixLibrary.cpp} (86%) rename logic/{DerpLibrary.h => OneSixLibrary.h} (98%) rename logic/{DerpRule.cpp => OneSixRule.cpp} (98%) rename logic/{DerpRule.h => OneSixRule.h} (90%) rename logic/{DerpUpdate.cpp => OneSixUpdate.cpp} (88%) rename logic/{DerpUpdate.h => OneSixUpdate.h} (92%) rename logic/{DerpVersionBuilder.cpp => OneSixVersionBuilder.cpp} (87%) rename logic/{DerpVersionBuilder.h => OneSixVersionBuilder.h} (76%) diff --git a/CMakeLists.txt b/CMakeLists.txt index c5339a30..6218ee7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -297,8 +297,8 @@ gui/dialogs/IconPickerDialog.h gui/dialogs/IconPickerDialog.cpp gui/dialogs/LegacyModEditDialog.h gui/dialogs/LegacyModEditDialog.cpp -gui/dialogs/DerpModEditDialog.h -gui/dialogs/DerpModEditDialog.cpp +gui/dialogs/OneSixModEditDialog.h +gui/dialogs/OneSixModEditDialog.cpp gui/dialogs/ModEditDialogCommon.h gui/dialogs/ModEditDialogCommon.cpp gui/dialogs/EditNotesDialog.h @@ -405,15 +405,15 @@ logic/LegacyUpdate.cpp logic/LegacyForge.h logic/LegacyForge.cpp -# Derp instances -logic/DerpUpdate.h -logic/DerpUpdate.cpp -logic/DerpVersion.h -logic/DerpVersion.cpp -logic/DerpLibrary.h -logic/DerpLibrary.cpp -logic/DerpRule.h -logic/DerpRule.cpp +# OneSix instances +logic/OneSixUpdate.h +logic/OneSixUpdate.cpp +logic/OneSixVersion.h +logic/OneSixVersion.cpp +logic/OneSixLibrary.h +logic/OneSixLibrary.cpp +logic/OneSixRule.h +logic/OneSixRule.cpp logic/OpSys.h logic/OpSys.cpp logic/BaseInstaller.h @@ -422,19 +422,19 @@ logic/ForgeInstaller.h logic/ForgeInstaller.cpp logic/LiteLoaderInstaller.h logic/LiteLoaderInstaller.cpp -logic/DerpInstance.h -logic/DerpInstance.cpp -logic/DerpInstance_p.h -logic/DerpVersionBuilder.h -logic/DerpVersionBuilder.cpp +logic/OneSixInstance.h +logic/OneSixInstance.cpp +logic/OneSixInstance_p.h +logic/OneSixVersionBuilder.h +logic/OneSixVersionBuilder.cpp # Nostalgia logic/NostalgiaInstance.h logic/NostalgiaInstance.cpp # FTB -logic/DerpFTBInstance.h -logic/DerpFTBInstance.cpp +logic/OneSixFTBInstance.h +logic/OneSixFTBInstance.cpp logic/LegacyFTBInstance.h logic/LegacyFTBInstance.cpp @@ -510,7 +510,7 @@ gui/dialogs/InstanceSettings.ui gui/dialogs/ProgressDialog.ui gui/dialogs/IconPickerDialog.ui gui/dialogs/LegacyModEditDialog.ui -gui/dialogs/DerpModEditDialog.ui +gui/dialogs/OneSixModEditDialog.ui gui/dialogs/EditNotesDialog.ui gui/dialogs/AccountListDialog.ui gui/dialogs/AccountSelectDialog.ui diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index ba394a94..ee9c3fad 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -84,7 +84,7 @@ #include "logic/BaseInstance.h" #include "logic/InstanceFactory.h" #include "logic/MinecraftProcess.h" -#include "logic/DerpUpdate.h" +#include "logic/OneSixUpdate.h" #include "logic/JavaUtils.h" #include "logic/NagUtils.h" #include "logic/SkinUtils.h" @@ -1257,7 +1257,7 @@ void MainWindow::on_actionChangeInstMCVersion_triggered() VersionSelectDialog vselect(m_selectedInstance->versionList().get(), tr("Change Minecraft version"), this); - vselect.setFilter(1, "Derp"); + vselect.setFilter(1, "OneSix"); if(!vselect.exec() || !vselect.selectedVersion()) return; diff --git a/gui/dialogs/DerpModEditDialog.cpp b/gui/dialogs/OneSixModEditDialog.cpp similarity index 84% rename from gui/dialogs/DerpModEditDialog.cpp rename to gui/dialogs/OneSixModEditDialog.cpp index 216aa59d..625a7c91 100644 --- a/gui/dialogs/DerpModEditDialog.cpp +++ b/gui/dialogs/OneSixModEditDialog.cpp @@ -23,9 +23,9 @@ #include #include -#include "DerpModEditDialog.h" +#include "OneSixModEditDialog.h" #include "ModEditDialogCommon.h" -#include "ui_DerpModEditDialog.h" +#include "ui_OneSixModEditDialog.h" #include "gui/Platform.h" #include "gui/dialogs/CustomMessageBox.h" @@ -34,14 +34,14 @@ #include "gui/dialogs/ProgressDialog.h" #include "logic/ModList.h" -#include "logic/DerpVersion.h" +#include "logic/OneSixVersion.h" #include "logic/EnabledItemFilter.h" #include "logic/lists/ForgeVersionList.h" #include "logic/ForgeInstaller.h" #include "logic/LiteLoaderInstaller.h" -DerpModEditDialog::DerpModEditDialog(DerpInstance *inst, QWidget *parent) - : QDialog(parent), ui(new Ui::DerpModEditDialog), m_inst(inst) +OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent) + : QDialog(parent), ui(new Ui::OneSixModEditDialog), m_inst(inst) { MultiMCPlatform::fixWM_CLASS(this); ui->setupUi(this); @@ -81,17 +81,17 @@ DerpModEditDialog::DerpModEditDialog(DerpInstance *inst, QWidget *parent) m_resourcepacks->startWatching(); } - connect(m_inst, &DerpInstance::versionReloaded, this, &DerpModEditDialog::updateVersionControls); + connect(m_inst, &OneSixInstance::versionReloaded, this, &OneSixModEditDialog::updateVersionControls); } -DerpModEditDialog::~DerpModEditDialog() +OneSixModEditDialog::~OneSixModEditDialog() { m_mods->stopWatching(); m_resourcepacks->stopWatching(); delete ui; } -void DerpModEditDialog::updateVersionControls() +void OneSixModEditDialog::updateVersionControls() { bool customVersion = m_inst->versionIsCustom(); ui->forgeBtn->setEnabled(true); @@ -100,7 +100,7 @@ void DerpModEditDialog::updateVersionControls() ui->mainClassEdit->setText(m_version->mainClass); } -void DerpModEditDialog::disableVersionControls() +void OneSixModEditDialog::disableVersionControls() { ui->forgeBtn->setEnabled(false); ui->liteloaderBtn->setEnabled(false); @@ -108,7 +108,7 @@ void DerpModEditDialog::disableVersionControls() ui->mainClassEdit->setText(""); } -void DerpModEditDialog::on_customEditorBtn_clicked() +void OneSixModEditDialog::on_customEditorBtn_clicked() { if (QDir(m_inst->instanceRoot()).exists("custom.json")) { @@ -119,7 +119,7 @@ void DerpModEditDialog::on_customEditorBtn_clicked() } } -void DerpModEditDialog::on_forgeBtn_clicked() +void OneSixModEditDialog::on_forgeBtn_clicked() { VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this); vselect.setFilter(1, m_inst->currentVersionId()); @@ -165,7 +165,7 @@ void DerpModEditDialog::on_forgeBtn_clicked() m_inst->reloadFullVersion(this); } -void DerpModEditDialog::on_liteloaderBtn_clicked() +void OneSixModEditDialog::on_liteloaderBtn_clicked() { LiteLoaderInstaller liteloader; if (!liteloader.canApply(m_inst)) @@ -188,7 +188,7 @@ void DerpModEditDialog::on_liteloaderBtn_clicked() } } -bool DerpModEditDialog::loaderListFilter(QKeyEvent *keyEvent) +bool OneSixModEditDialog::loaderListFilter(QKeyEvent *keyEvent) { switch (keyEvent->key()) { @@ -204,7 +204,7 @@ bool DerpModEditDialog::loaderListFilter(QKeyEvent *keyEvent) return QDialog::eventFilter(ui->loaderModTreeView, keyEvent); } -bool DerpModEditDialog::resourcePackListFilter(QKeyEvent *keyEvent) +bool OneSixModEditDialog::resourcePackListFilter(QKeyEvent *keyEvent) { switch (keyEvent->key()) { @@ -220,7 +220,7 @@ bool DerpModEditDialog::resourcePackListFilter(QKeyEvent *keyEvent) return QDialog::eventFilter(ui->resPackTreeView, keyEvent); } -bool DerpModEditDialog::eventFilter(QObject *obj, QEvent *ev) +bool OneSixModEditDialog::eventFilter(QObject *obj, QEvent *ev) { if (ev->type() != QEvent::KeyPress) { @@ -234,12 +234,12 @@ bool DerpModEditDialog::eventFilter(QObject *obj, QEvent *ev) return QDialog::eventFilter(obj, ev); } -void DerpModEditDialog::on_buttonBox_rejected() +void OneSixModEditDialog::on_buttonBox_rejected() { close(); } -void DerpModEditDialog::on_addModBtn_clicked() +void OneSixModEditDialog::on_addModBtn_clicked() { QStringList fileNames = QFileDialog::getOpenFileNames( this, QApplication::translate("LegacyModEditDialog", "Select Loader Mods")); @@ -250,7 +250,7 @@ void DerpModEditDialog::on_addModBtn_clicked() m_mods->startWatching(); } } -void DerpModEditDialog::on_rmModBtn_clicked() +void OneSixModEditDialog::on_rmModBtn_clicked() { int first, last; auto list = ui->loaderModTreeView->selectionModel()->selectedRows(); @@ -261,12 +261,12 @@ void DerpModEditDialog::on_rmModBtn_clicked() m_mods->deleteMods(first, last); m_mods->startWatching(); } -void DerpModEditDialog::on_viewModBtn_clicked() +void OneSixModEditDialog::on_viewModBtn_clicked() { openDirInDefaultProgram(m_inst->loaderModsDir(), true); } -void DerpModEditDialog::on_addResPackBtn_clicked() +void OneSixModEditDialog::on_addResPackBtn_clicked() { QStringList fileNames = QFileDialog::getOpenFileNames( this, QApplication::translate("LegacyModEditDialog", "Select Resource Packs")); @@ -277,7 +277,7 @@ void DerpModEditDialog::on_addResPackBtn_clicked() m_resourcepacks->startWatching(); } } -void DerpModEditDialog::on_rmResPackBtn_clicked() +void OneSixModEditDialog::on_rmResPackBtn_clicked() { int first, last; auto list = ui->resPackTreeView->selectionModel()->selectedRows(); @@ -288,12 +288,12 @@ void DerpModEditDialog::on_rmResPackBtn_clicked() m_resourcepacks->deleteMods(first, last); m_resourcepacks->startWatching(); } -void DerpModEditDialog::on_viewResPackBtn_clicked() +void OneSixModEditDialog::on_viewResPackBtn_clicked() { openDirInDefaultProgram(m_inst->resourcePacksDir(), true); } -void DerpModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previous) +void OneSixModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previous) { if (!current.isValid()) { diff --git a/gui/dialogs/DerpModEditDialog.h b/gui/dialogs/OneSixModEditDialog.h similarity index 83% rename from gui/dialogs/DerpModEditDialog.h rename to gui/dialogs/OneSixModEditDialog.h index e9e61c65..161604c9 100644 --- a/gui/dialogs/DerpModEditDialog.h +++ b/gui/dialogs/OneSixModEditDialog.h @@ -16,21 +16,21 @@ #pragma once #include -#include +#include class EnabledItemFilter; namespace Ui { -class DerpModEditDialog; +class OneSixModEditDialog; } -class DerpModEditDialog : public QDialog +class OneSixModEditDialog : public QDialog { Q_OBJECT public: - explicit DerpModEditDialog(DerpInstance *inst, QWidget *parent = 0); - virtual ~DerpModEditDialog(); + explicit OneSixModEditDialog(OneSixInstance *inst, QWidget *parent = 0); + virtual ~OneSixModEditDialog(); private slots: @@ -55,12 +55,12 @@ protected: bool resourcePackListFilter(QKeyEvent *ev); private: - Ui::DerpModEditDialog *ui; - std::shared_ptr m_version; + Ui::OneSixModEditDialog *ui; + std::shared_ptr m_version; std::shared_ptr m_mods; std::shared_ptr m_resourcepacks; EnabledItemFilter *main_model; - DerpInstance *m_inst; + OneSixInstance *m_inst; public slots: void loaderCurrent(QModelIndex current, QModelIndex previous); diff --git a/gui/dialogs/DerpModEditDialog.ui b/gui/dialogs/OneSixModEditDialog.ui similarity index 99% rename from gui/dialogs/DerpModEditDialog.ui rename to gui/dialogs/OneSixModEditDialog.ui index 7aaf1564..d57d0f85 100644 --- a/gui/dialogs/DerpModEditDialog.ui +++ b/gui/dialogs/OneSixModEditDialog.ui @@ -1,7 +1,7 @@ - DerpModEditDialog - + OneSixModEditDialog + 0 diff --git a/logic/BaseInstaller.cpp b/logic/BaseInstaller.cpp index 74a8e909..92aa0c92 100644 --- a/logic/BaseInstaller.cpp +++ b/logic/BaseInstaller.cpp @@ -17,9 +17,9 @@ #include -#include "DerpVersion.h" -#include "DerpLibrary.h" -#include "DerpInstance.h" +#include "OneSixVersion.h" +#include "OneSixLibrary.h" +#include "OneSixInstance.h" #include "cmdutils.h" @@ -28,12 +28,12 @@ BaseInstaller::BaseInstaller() } -bool BaseInstaller::isApplied(DerpInstance *on) +bool BaseInstaller::isApplied(OneSixInstance *on) { return QFile::exists(filename(on->instanceRoot())); } -bool BaseInstaller::add(DerpInstance *to) +bool BaseInstaller::add(OneSixInstance *to) { if (!patchesDir(to->instanceRoot()).exists()) { @@ -51,7 +51,7 @@ bool BaseInstaller::add(DerpInstance *to) return true; } -bool BaseInstaller::remove(DerpInstance *from) +bool BaseInstaller::remove(OneSixInstance *from) { return QFile::remove(filename(from->instanceRoot())); } diff --git a/logic/BaseInstaller.h b/logic/BaseInstaller.h index 08f78bfc..df7eab89 100644 --- a/logic/BaseInstaller.h +++ b/logic/BaseInstaller.h @@ -17,7 +17,7 @@ #include -class DerpInstance; +class OneSixInstance; class QDir; class QString; @@ -26,11 +26,11 @@ class BaseInstaller public: BaseInstaller(); - virtual bool canApply(DerpInstance *instance) const { return true; } - bool isApplied(DerpInstance *on); + virtual bool canApply(OneSixInstance *instance) const { return true; } + bool isApplied(OneSixInstance *on); - virtual bool add(DerpInstance *to); - virtual bool remove(DerpInstance *from); + virtual bool add(OneSixInstance *to); + virtual bool remove(OneSixInstance *from); protected: virtual QString id() const = 0; diff --git a/logic/BaseInstance.h b/logic/BaseInstance.h index 79640c84..a861e9b2 100644 --- a/logic/BaseInstance.h +++ b/logic/BaseInstance.h @@ -27,7 +27,7 @@ class QDialog; class Task; class MinecraftProcess; -class DerpUpdate; +class OneSixUpdate; class InstanceList; class BaseInstancePrivate; diff --git a/logic/DerpVersion.cpp b/logic/DerpVersion.cpp deleted file mode 100644 index f4a8dd97..00000000 --- a/logic/DerpVersion.cpp +++ /dev/null @@ -1,194 +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 "DerpVersion.h" - -#include - -#include "DerpVersionBuilder.h" - -DerpVersion::DerpVersion(DerpInstance *instance, QObject *parent) - : QAbstractListModel(parent), m_instance(instance) -{ - clear(); -} - -bool DerpVersion::reload(QWidget *widgetParent) -{ - return DerpVersionBuilder::build(this, m_instance, widgetParent); -} - -void DerpVersion::clear() -{ - id.clear(); - time.clear(); - releaseTime.clear(); - type.clear(); - assets.clear(); - processArguments.clear(); - minecraftArguments.clear(); - minimumLauncherVersion = 0xDEADBEAF; - mainClass.clear(); - libraries.clear(); -} - -void DerpVersion::dump() const -{ - qDebug().nospace() << "DerpVersion(" - << "\n\tid=" << id - << "\n\ttime=" << time - << "\n\treleaseTime=" << releaseTime - << "\n\ttype=" << type - << "\n\tassets=" << assets - << "\n\tprocessArguments=" << processArguments - << "\n\tminecraftArguments=" << minecraftArguments - << "\n\tminimumLauncherVersion=" << minimumLauncherVersion - << "\n\tmainClass=" << mainClass - << "\n\tlibraries="; - for (auto lib : libraries) - { - qDebug().nospace() << "\n\t\t" << lib.get(); - } - qDebug().nospace() << "\n)"; -} - -QList > DerpVersion::getActiveNormalLibs() -{ - QList > output; - for (auto lib : libraries) - { - if (lib->isActive() && !lib->isNative()) - { - output.append(lib); - } - } - return output; -} - -QList > DerpVersion::getActiveNativeLibs() -{ - QList > output; - for (auto lib : libraries) - { - if (lib->isActive() && lib->isNative()) - { - output.append(lib); - } - } - return output; -} - -std::shared_ptr DerpVersion::fromJson(const QJsonObject &obj) -{ - std::shared_ptr version(new DerpVersion(0)); - if (DerpVersionBuilder::read(version.get(), obj)) - { - return version; - } - return 0; -} - -QVariant DerpVersion::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) - return QVariant(); - - int row = index.row(); - int column = index.column(); - - if (row < 0 || row >= libraries.size()) - return QVariant(); - - if (role == Qt::DisplayRole) - { - switch (column) - { - case 0: - return libraries[row]->name(); - case 1: - return libraries[row]->type(); - case 2: - return libraries[row]->version(); - default: - return QVariant(); - } - } - return QVariant(); -} - -Qt::ItemFlags DerpVersion::flags(const QModelIndex &index) const -{ - if (!index.isValid()) - return Qt::NoItemFlags; - int row = index.row(); - if (libraries[row]->isActive()) - { - return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemNeverHasChildren; - } - else - { - return Qt::ItemNeverHasChildren; - } - // return QAbstractListModel::flags(index); -} - -QVariant DerpVersion::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (role != Qt::DisplayRole || orientation != Qt::Horizontal) - return QVariant(); - switch (section) - { - case 0: - return QString("Name"); - case 1: - return QString("Type"); - case 2: - return QString("Version"); - default: - return QString(); - } -} - -int DerpVersion::rowCount(const QModelIndex &parent) const -{ - return libraries.size(); -} - -int DerpVersion::columnCount(const QModelIndex &parent) const -{ - return 3; -} - -QDebug operator<<(QDebug &dbg, const DerpVersion *version) -{ - version->dump(); - return dbg.maybeSpace(); -} -QDebug operator<<(QDebug &dbg, const DerpLibrary *library) -{ - dbg.nospace() << "DerpLibrary(" - << "\n\t\t\trawName=" << library->rawName() - << "\n\t\t\tname=" << library->name() - << "\n\t\t\tversion=" << library->version() - << "\n\t\t\ttype=" << library->type() - << "\n\t\t\tisActive=" << library->isActive() - << "\n\t\t\tisNative=" << library->isNative() - << "\n\t\t\tdownloadUrl=" << library->downloadUrl() - << "\n\t\t\tstoragePath=" << library->storagePath() - << "\n\t\t\tabsolutePath=" << library->absoluteUrl() - << "\n\t\t\thint=" << library->hint(); - dbg.nospace() << "\n\t\t)"; - return dbg.maybeSpace(); -} diff --git a/logic/DerpVersion.h b/logic/DerpVersion.h deleted file mode 100644 index 4481d146..00000000 --- a/logic/DerpVersion.h +++ /dev/null @@ -1,115 +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 "DerpLibrary.h" - -class DerpInstance; - -class DerpVersion : public QAbstractListModel -{ - Q_OBJECT -public: - explicit DerpVersion(DerpInstance *instance, QObject *parent = 0); - - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; - virtual QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const; - virtual int columnCount(const QModelIndex &parent) const; - virtual Qt::ItemFlags flags(const QModelIndex &index) const; - - bool reload(QWidget *widgetParent); - void clear(); - - void dump() const; - -public: - QList> getActiveNormalLibs(); - QList> getActiveNativeLibs(); - - static std::shared_ptr fromJson(const QJsonObject &obj); - - // data members -public: - /// the ID - determines which jar to use! ACTUALLY IMPORTANT! - QString id; - /// Last updated time - as a string - QString time; - /// Release time - as a string - QString releaseTime; - /// Release type - "release" or "snapshot" - QString type; - /// Assets type - "legacy" or a version ID - QString assets; - /** - * DEPRECATED: Old versions of the new vanilla launcher used this - * ex: "username_session_version" - */ - QString processArguments; - /** - * arguments that should be used for launching minecraft - * - * ex: "--username ${auth_player_name} --session ${auth_session} - * --version ${version_name} --gameDir ${game_directory} --assetsDir ${game_assets}" - */ - QString minecraftArguments; - /** - * the minimum launcher version required by this version ... current is 4 (at point of - * writing) - */ - int minimumLauncherVersion = 0xDEADBEEF; - /** - * The main class to load first - */ - QString mainClass; - - /// the list of libs - both active and inactive, native and java - QList> libraries; - - /* - FIXME: add support for those rules here? Looks like a pile of quick hacks to me though. - - "rules": [ - { - "action": "allow" - }, - { - "action": "disallow", - "os": { - "name": "osx", - "version": "^10\\.5\\.\\d$" - } - } - ], - "incompatibilityReason": "There is a bug in LWJGL which makes it incompatible with OSX - 10.5.8. Please go to New Profile and use 1.5.2 for now. Sorry!" - } - */ - // QList rules; - -private: - DerpInstance *m_instance; -}; - -QDebug operator<<(QDebug &dbg, const DerpVersion *version); -QDebug operator<<(QDebug &dbg, const DerpLibrary *library); diff --git a/logic/ForgeInstaller.cpp b/logic/ForgeInstaller.cpp index 35663ddd..863c3dfd 100644 --- a/logic/ForgeInstaller.cpp +++ b/logic/ForgeInstaller.cpp @@ -14,15 +14,15 @@ */ #include "ForgeInstaller.h" -#include "DerpVersion.h" -#include "DerpLibrary.h" +#include "OneSixVersion.h" +#include "OneSixLibrary.h" #include "net/HttpMetaCache.h" #include #include #include #include #include "MultiMC.h" -#include "DerpInstance.h" +#include "OneSixInstance.h" #include #include @@ -31,7 +31,7 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url) { - std::shared_ptr newVersion; + std::shared_ptr newVersion; m_universal_url = universal_url; QuaZip zip(filename); @@ -64,7 +64,7 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url) // read the forge version info { - newVersion = DerpVersion::fromJson(versionInfoVal.toObject()); + newVersion = OneSixVersion::fromJson(versionInfoVal.toObject()); if (!newVersion) return; } @@ -74,7 +74,7 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url) internalPath = installObj.value("filePath").toString(); // where do we put the library? decode the mojang path - DerpLibrary lib(libraryName); + OneSixLibrary lib(libraryName); lib.finalize(); auto cacheentry = MMC->metacache()->resolveEntry("libraries", lib.storagePath()); @@ -109,7 +109,7 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url) realVersionId = m_forge_version->id = installObj.value("minecraft").toString(); } -bool ForgeInstaller::add(DerpInstance *to) +bool ForgeInstaller::add(OneSixInstance *to) { if (!BaseInstaller::add(to)) { diff --git a/logic/ForgeInstaller.h b/logic/ForgeInstaller.h index 6490b5bf..eb8ecd79 100644 --- a/logic/ForgeInstaller.h +++ b/logic/ForgeInstaller.h @@ -20,20 +20,20 @@ #include #include -class DerpVersion; +class OneSixVersion; class ForgeInstaller : public BaseInstaller { public: ForgeInstaller(QString filename, QString universal_url); - bool add(DerpInstance *to) override; + bool add(OneSixInstance *to) override; QString id() const override { return "net.minecraftforge"; } private: // the version, read from the installer - std::shared_ptr m_forge_version; + std::shared_ptr m_forge_version; QString internalPath; QString finalPath; QString realVersionId; diff --git a/logic/InstanceFactory.cpp b/logic/InstanceFactory.cpp index c50ec4e4..730bcd69 100644 --- a/logic/InstanceFactory.cpp +++ b/logic/InstanceFactory.cpp @@ -21,10 +21,10 @@ #include "BaseInstance.h" #include "LegacyInstance.h" #include "LegacyFTBInstance.h" -#include "DerpInstance.h" -#include "DerpFTBInstance.h" +#include "OneSixInstance.h" +#include "OneSixFTBInstance.h" #include "NostalgiaInstance.h" -#include "DerpInstance.h" +#include "OneSixInstance.h" #include "BaseVersion.h" #include "MinecraftVersion.h" @@ -51,9 +51,9 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst QString inst_type = m_settings->get("InstanceType").toString(); // FIXME: replace with a map lookup, where instance classes register their types - if (inst_type == "Derp" || inst_type == "OneSix") + if (inst_type == "OneSix" || inst_type == "OneSix") { - inst = new DerpInstance(instDir, m_settings, this); + inst = new OneSixInstance(instDir, m_settings, this); } else if (inst_type == "Legacy") { @@ -67,9 +67,9 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst { inst = new LegacyFTBInstance(instDir, m_settings, this); } - else if (inst_type == "OneSixFTB" || inst_type == "DerpFTB") + else if (inst_type == "OneSixFTB" || inst_type == "OneSixFTB") { - inst = new DerpFTBInstance(instDir, m_settings, this); + inst = new OneSixFTBInstance(instDir, m_settings, this); } else { @@ -102,15 +102,15 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance(BaseInstance *& switch (mcVer->type) { case MinecraftVersion::Legacy: - // TODO derp + // TODO OneSix m_settings->set("InstanceType", "Legacy"); inst = new LegacyInstance(instDir, m_settings, this); inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); break; - case MinecraftVersion::Derp: - m_settings->set("InstanceType", "Derp"); - inst = new DerpInstance(instDir, m_settings, this); + case MinecraftVersion::OneSix: + m_settings->set("InstanceType", "OneSix"); + inst = new OneSixInstance(instDir, m_settings, this); inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); break; @@ -137,9 +137,9 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance(BaseInstance *& inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); break; - case MinecraftVersion::Derp: - m_settings->set("InstanceType", "DerpFTB"); - inst = new DerpFTBInstance(instDir, m_settings, this); + case MinecraftVersion::OneSix: + m_settings->set("InstanceType", "OneSixFTB"); + inst = new OneSixFTBInstance(instDir, m_settings, this); inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); break; @@ -176,8 +176,8 @@ InstanceFactory::InstCreateError InstanceFactory::copyInstance(BaseInstance *&ne m_settings->registerSetting("InstanceType", "Legacy"); QString inst_type = m_settings->get("InstanceType").toString(); - if(inst_type == "OneSixFTB" || inst_type == "DerpFTB") - m_settings->set("InstanceType", "Derp"); + if(inst_type == "OneSixFTB" || inst_type == "OneSixFTB") + m_settings->set("InstanceType", "OneSix"); if(inst_type == "LegacyFTB") m_settings->set("InstanceType", "Legacy"); diff --git a/logic/LegacyInstance.h b/logic/LegacyInstance.h index 1ff17cbd..1e7d9eb6 100644 --- a/logic/LegacyInstance.h +++ b/logic/LegacyInstance.h @@ -68,7 +68,7 @@ public: virtual QString intendedVersionId() const override; virtual bool setIntendedVersionId(QString version) override; // the `version' of Legacy instances is defined by the launcher code. - // in contrast with Derp, where `version' is described in a json file + // in contrast with OneSix, where `version' is described in a json file virtual bool versionIsCustom() override { return false; diff --git a/logic/LiteLoaderInstaller.cpp b/logic/LiteLoaderInstaller.cpp index 71c7011f..1ce9d3f4 100644 --- a/logic/LiteLoaderInstaller.cpp +++ b/logic/LiteLoaderInstaller.cpp @@ -20,9 +20,9 @@ #include "logger/QsLog.h" -#include "DerpVersion.h" -#include "DerpLibrary.h" -#include "DerpInstance.h" +#include "OneSixVersion.h" +#include "OneSixLibrary.h" +#include "OneSixInstance.h" QMap LiteLoaderInstaller::m_launcherWrapperVersionMapping; @@ -38,12 +38,12 @@ LiteLoaderInstaller::LiteLoaderInstaller() } } -bool LiteLoaderInstaller::canApply(DerpInstance *instance) const +bool LiteLoaderInstaller::canApply(OneSixInstance *instance) const { return m_launcherWrapperVersionMapping.contains(instance->intendedVersionId()); } -bool LiteLoaderInstaller::add(DerpInstance *to) +bool LiteLoaderInstaller::add(OneSixInstance *to) { if (!BaseInstaller::add(to)) { @@ -60,7 +60,7 @@ bool LiteLoaderInstaller::add(DerpInstance *to) // launchwrapper { - DerpLibrary launchwrapperLib("net.minecraft:launchwrapper:" + m_launcherWrapperVersionMapping[to->intendedVersionId()]); + OneSixLibrary launchwrapperLib("net.minecraft:launchwrapper:" + m_launcherWrapperVersionMapping[to->intendedVersionId()]); launchwrapperLib.finalize(); QJsonObject lwLibObj = launchwrapperLib.toJson(); lwLibObj.insert("insert", QString("prepend")); @@ -69,7 +69,7 @@ bool LiteLoaderInstaller::add(DerpInstance *to) // liteloader { - DerpLibrary liteloaderLib("com.mumfrey:liteloader:" + to->intendedVersionId()); + OneSixLibrary liteloaderLib("com.mumfrey:liteloader:" + to->intendedVersionId()); liteloaderLib.setBaseUrl("http://dl.liteloader.com/versions/"); liteloaderLib.finalize(); QJsonObject llLibObj = liteloaderLib.toJson(); diff --git a/logic/LiteLoaderInstaller.h b/logic/LiteLoaderInstaller.h index c128ee22..5e01b16c 100644 --- a/logic/LiteLoaderInstaller.h +++ b/logic/LiteLoaderInstaller.h @@ -25,8 +25,8 @@ class LiteLoaderInstaller : public BaseInstaller public: LiteLoaderInstaller(); - bool canApply(DerpInstance *instance) const override; - bool add(DerpInstance *to) override; + bool canApply(OneSixInstance *instance) const override; + bool add(OneSixInstance *to) override; private: virtual QString id() const override { return "com.mumfrey.liteloader"; } diff --git a/logic/MinecraftVersion.h b/logic/MinecraftVersion.h index dd849ce9..504381a8 100644 --- a/logic/MinecraftVersion.h +++ b/logic/MinecraftVersion.h @@ -32,7 +32,7 @@ struct MinecraftVersion : public BaseVersion /// This version's type. Used internally to identify what kind of version this is. enum VersionType { - Derp, + OneSix, Legacy, Nostalgia } type; @@ -66,8 +66,8 @@ struct MinecraftVersion : public BaseVersion } switch (type) { - case Derp: - pre_final.append("Derp"); + case OneSix: + pre_final.append("OneSix"); break; case Legacy: pre_final.append("Legacy"); diff --git a/logic/NostalgiaInstance.cpp b/logic/NostalgiaInstance.cpp index f27954a7..2e23ee71 100644 --- a/logic/NostalgiaInstance.cpp +++ b/logic/NostalgiaInstance.cpp @@ -17,7 +17,7 @@ NostalgiaInstance::NostalgiaInstance(const QString &rootDir, SettingsObject *settings, QObject *parent) - : DerpInstance(rootDir, settings, parent) + : OneSixInstance(rootDir, settings, parent) { } diff --git a/logic/NostalgiaInstance.h b/logic/NostalgiaInstance.h index 6a6b91a1..a26f7f0a 100644 --- a/logic/NostalgiaInstance.h +++ b/logic/NostalgiaInstance.h @@ -15,9 +15,9 @@ #pragma once -#include "DerpInstance.h" +#include "OneSixInstance.h" -class NostalgiaInstance : public DerpInstance +class NostalgiaInstance : public OneSixInstance { Q_OBJECT public: diff --git a/logic/DerpFTBInstance.cpp b/logic/OneSixFTBInstance.cpp similarity index 69% rename from logic/DerpFTBInstance.cpp rename to logic/OneSixFTBInstance.cpp index 9b687461..71bc1470 100644 --- a/logic/DerpFTBInstance.cpp +++ b/logic/OneSixFTBInstance.cpp @@ -1,17 +1,17 @@ -#include "DerpFTBInstance.h" +#include "OneSixFTBInstance.h" -#include "DerpVersion.h" -#include "DerpLibrary.h" +#include "OneSixVersion.h" +#include "OneSixLibrary.h" #include "tasks/SequentialTask.h" #include "ForgeInstaller.h" #include "lists/ForgeVersionList.h" #include "MultiMC.h" -class DerpFTBInstanceForge : public Task +class OneSixFTBInstanceForge : public Task { Q_OBJECT public: - explicit DerpFTBInstanceForge(const QString &version, DerpFTBInstance *inst, QObject *parent = 0) : + explicit OneSixFTBInstanceForge(const QString &version, OneSixFTBInstance *inst, QObject *parent = 0) : Task(parent), instance(inst), version("Forge " + version) { } @@ -38,7 +38,7 @@ public: fjob = new NetJob("Forge download"); fjob->addNetAction(CacheDownload::make(forgeVersion->installer_url, entry)); connect(fjob, &NetJob::failed, [this](){emitFailed(m_failReason);}); - connect(fjob, &NetJob::succeeded, this, &DerpFTBInstanceForge::installForge); + connect(fjob, &NetJob::succeeded, this, &OneSixFTBInstanceForge::installForge); connect(fjob, &NetJob::progress, [this](qint64 c, qint64 total){ setProgress(100 * c / total); }); fjob->start(); } @@ -70,41 +70,41 @@ slots: } private: - DerpFTBInstance *instance; + OneSixFTBInstance *instance; QString version; ForgeVersionPtr forgeVersion; MetaEntryPtr entry; NetJob *fjob; }; -DerpFTBInstance::DerpFTBInstance(const QString &rootDir, SettingsObject *settings, QObject *parent) : - DerpInstance(rootDir, settings, parent) +OneSixFTBInstance::OneSixFTBInstance(const QString &rootDir, SettingsObject *settings, QObject *parent) : + OneSixInstance(rootDir, settings, parent) { QFile f(QDir(minecraftRoot()).absoluteFilePath("pack.json")); if (f.open(QFile::ReadOnly)) { QString data = QString::fromUtf8(f.readAll()); QRegularExpressionMatch match = QRegularExpression("net.minecraftforge:minecraftforge:[\\.\\d]*").match(data); - m_forge.reset(new DerpLibrary(match.captured())); + m_forge.reset(new OneSixLibrary(match.captured())); m_forge->finalize(); } } -QString DerpFTBInstance::id() const +QString OneSixFTBInstance::id() const { return "FTB/" + BaseInstance::id(); } -QString DerpFTBInstance::getStatusbarDescription() +QString OneSixFTBInstance::getStatusbarDescription() { - return "Derp FTB: " + intendedVersionId(); + return "OneSix FTB: " + intendedVersionId(); } -bool DerpFTBInstance::menuActionEnabled(QString action_name) const +bool OneSixFTBInstance::menuActionEnabled(QString action_name) const { return false; } -std::shared_ptr DerpFTBInstance::doUpdate(bool only_prepare) +std::shared_ptr OneSixFTBInstance::doUpdate(bool only_prepare) { std::shared_ptr task; task.reset(new SequentialTask(this)); @@ -112,12 +112,12 @@ std::shared_ptr DerpFTBInstance::doUpdate(bool only_prepare) { task->addTask(std::shared_ptr(MMC->forgelist()->getLoadTask())); } - task->addTask(DerpInstance::doUpdate(only_prepare)); - task->addTask(std::shared_ptr(new DerpFTBInstanceForge(m_forge->version(), this, this))); + task->addTask(OneSixInstance::doUpdate(only_prepare)); + task->addTask(std::shared_ptr(new OneSixFTBInstanceForge(m_forge->version(), this, this))); //FIXME: yes. this may appear dumb. but the previous step can change the list, so we do it all again. //TODO: Add a graph task. Construct graphs of tasks so we may capture the logic properly. - task->addTask(DerpInstance::doUpdate(only_prepare)); + task->addTask(OneSixInstance::doUpdate(only_prepare)); return task; } -#include "DerpFTBInstance.moc" +#include "OneSixFTBInstance.moc" diff --git a/logic/DerpFTBInstance.h b/logic/OneSixFTBInstance.h similarity index 56% rename from logic/DerpFTBInstance.h rename to logic/OneSixFTBInstance.h index c16998bf..dc028819 100644 --- a/logic/DerpFTBInstance.h +++ b/logic/OneSixFTBInstance.h @@ -1,14 +1,14 @@ #pragma once -#include "DerpInstance.h" +#include "OneSixInstance.h" -class DerpLibrary; +class OneSixLibrary; -class DerpFTBInstance : public DerpInstance +class OneSixFTBInstance : public OneSixInstance { Q_OBJECT public: - explicit DerpFTBInstance(const QString &rootDir, SettingsObject *settings, + explicit OneSixFTBInstance(const QString &rootDir, SettingsObject *settings, QObject *parent = 0); virtual QString getStatusbarDescription(); virtual bool menuActionEnabled(QString action_name) const; @@ -18,5 +18,5 @@ public: virtual QString id() const; private: - std::shared_ptr m_forge; + std::shared_ptr m_forge; }; diff --git a/logic/DerpInstance.cpp b/logic/OneSixInstance.cpp similarity index 80% rename from logic/DerpInstance.cpp rename to logic/OneSixInstance.cpp index e6b92b1f..c43a5187 100644 --- a/logic/DerpInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -13,28 +13,28 @@ * limitations under the License. */ -#include "DerpInstance.h" +#include "OneSixInstance.h" #include -#include "DerpInstance_p.h" -#include "DerpUpdate.h" -#include "DerpVersion.h" +#include "OneSixInstance_p.h" +#include "OneSixUpdate.h" +#include "OneSixVersion.h" #include "pathutils.h" #include "logger/QsLog.h" #include "assets/AssetsUtils.h" #include "MultiMC.h" #include "icons/IconList.h" #include "MinecraftProcess.h" -#include "gui/dialogs/DerpModEditDialog.h" +#include "gui/dialogs/OneSixModEditDialog.h" -DerpInstance::DerpInstance(const QString &rootDir, SettingsObject *settings, QObject *parent) - : BaseInstance(new DerpInstancePrivate(), rootDir, settings, parent) +OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *settings, QObject *parent) + : BaseInstance(new OneSixInstancePrivate(), rootDir, settings, parent) { - I_D(DerpInstance); + I_D(OneSixInstance); d->m_settings->registerSetting("IntendedVersion", ""); d->m_settings->registerSetting("ShouldUpdate", false); - d->version.reset(new DerpVersion(this, this)); + d->version.reset(new OneSixVersion(this, this)); if (QDir(instanceRoot()).exists("version.json")) { reloadFullVersion(); @@ -45,9 +45,9 @@ DerpInstance::DerpInstance(const QString &rootDir, SettingsObject *settings, QOb } } -std::shared_ptr DerpInstance::doUpdate(bool only_prepare) +std::shared_ptr OneSixInstance::doUpdate(bool only_prepare) { - return std::shared_ptr(new DerpUpdate(this, only_prepare)); + return std::shared_ptr(new OneSixUpdate(this, only_prepare)); } QString replaceTokensIn(QString text, QMap with) @@ -74,7 +74,7 @@ QString replaceTokensIn(QString text, QMap with) return result; } -QDir DerpInstance::reconstructAssets(std::shared_ptr version) +QDir OneSixInstance::reconstructAssets(std::shared_ptr version) { QDir assetsDir = QDir("assets/"); QDir indexDir = QDir(PathCombine(assetsDir.path(), "indexes")); @@ -134,9 +134,9 @@ QDir DerpInstance::reconstructAssets(std::shared_ptr version) return virtualRoot; } -QStringList DerpInstance::processMinecraftArgs(MojangAccountPtr account) +QStringList OneSixInstance::processMinecraftArgs(MojangAccountPtr account) { - I_D(DerpInstance); + I_D(OneSixInstance); auto version = d->version; QString args_pattern = version->minecraftArguments; @@ -186,9 +186,9 @@ QStringList DerpInstance::processMinecraftArgs(MojangAccountPtr account) return parts; } -MinecraftProcess *DerpInstance::prepareForLaunch(MojangAccountPtr account) +MinecraftProcess *OneSixInstance::prepareForLaunch(MojangAccountPtr account) { - I_D(DerpInstance); + I_D(OneSixInstance); QIcon icon = MMC->icons()->getIcon(iconKey()); auto pixmap = icon.pixmap(128, 128); @@ -248,16 +248,16 @@ MinecraftProcess *DerpInstance::prepareForLaunch(MojangAccountPtr account) return proc; } -void DerpInstance::cleanupAfterRun() +void OneSixInstance::cleanupAfterRun() { QString target_dir = PathCombine(instanceRoot(), "natives/"); QDir dir(target_dir); dir.removeRecursively(); } -std::shared_ptr DerpInstance::loaderModList() +std::shared_ptr OneSixInstance::loaderModList() { - I_D(DerpInstance); + I_D(OneSixInstance); if (!d->loader_mod_list) { d->loader_mod_list.reset(new ModList(loaderModsDir())); @@ -266,9 +266,9 @@ std::shared_ptr DerpInstance::loaderModList() return d->loader_mod_list; } -std::shared_ptr DerpInstance::resourcePackList() +std::shared_ptr OneSixInstance::resourcePackList() { - I_D(DerpInstance); + I_D(OneSixInstance); if (!d->resource_pack_list) { d->resource_pack_list.reset(new ModList(resourcePacksDir())); @@ -277,12 +277,12 @@ std::shared_ptr DerpInstance::resourcePackList() return d->resource_pack_list; } -QDialog *DerpInstance::createModEditDialog(QWidget *parent) +QDialog *OneSixInstance::createModEditDialog(QWidget *parent) { - return new DerpModEditDialog(this, parent); + return new OneSixModEditDialog(this, parent); } -bool DerpInstance::setIntendedVersionId(QString version) +bool OneSixInstance::setIntendedVersionId(QString version) { settings().set("IntendedVersion", version); setShouldUpdate(true); @@ -291,17 +291,17 @@ bool DerpInstance::setIntendedVersionId(QString version) return true; } -QString DerpInstance::intendedVersionId() const +QString OneSixInstance::intendedVersionId() const { return settings().get("IntendedVersion").toString(); } -void DerpInstance::setShouldUpdate(bool val) +void OneSixInstance::setShouldUpdate(bool val) { settings().set("ShouldUpdate", val); } -bool DerpInstance::shouldUpdate() const +bool OneSixInstance::shouldUpdate() const { QVariant var = settings().get("ShouldUpdate"); if (!var.isValid() || var.toBool() == false) @@ -311,60 +311,60 @@ bool DerpInstance::shouldUpdate() const return true; } -bool DerpInstance::versionIsCustom() +bool OneSixInstance::versionIsCustom() { QDir patches(PathCombine(instanceRoot(), "patches/")); return QFile::exists(PathCombine(instanceRoot(), "custom.json")) || (patches.exists() && patches.count() >= 0); } -QString DerpInstance::currentVersionId() const +QString OneSixInstance::currentVersionId() const { return intendedVersionId(); } -bool DerpInstance::reloadFullVersion(QWidget *widgetParent) +bool OneSixInstance::reloadFullVersion(QWidget *widgetParent) { - I_D(DerpInstance); + I_D(OneSixInstance); bool ret = d->version->reload(widgetParent); emit versionReloaded(); return ret; } -void DerpInstance::clearFullVersion() +void OneSixInstance::clearFullVersion() { - I_D(DerpInstance); + I_D(OneSixInstance); d->version->clear(); emit versionReloaded(); } -std::shared_ptr DerpInstance::getFullVersion() +std::shared_ptr OneSixInstance::getFullVersion() { - I_D(DerpInstance); + I_D(OneSixInstance); return d->version; } -QString DerpInstance::defaultBaseJar() const +QString OneSixInstance::defaultBaseJar() const { return "versions/" + intendedVersionId() + "/" + intendedVersionId() + ".jar"; } -QString DerpInstance::defaultCustomBaseJar() const +QString OneSixInstance::defaultCustomBaseJar() const { return PathCombine(instanceRoot(), "custom.jar"); } -bool DerpInstance::menuActionEnabled(QString action_name) const +bool OneSixInstance::menuActionEnabled(QString action_name) const { if (action_name == "actionChangeInstLWJGLVersion") return false; return true; } -QString DerpInstance::getStatusbarDescription() +QString OneSixInstance::getStatusbarDescription() { - QString descr = "Derp : " + intendedVersionId(); + QString descr = "OneSix : " + intendedVersionId(); if (versionIsCustom()) { descr + " (custom)"; @@ -372,17 +372,17 @@ QString DerpInstance::getStatusbarDescription() return descr; } -QString DerpInstance::loaderModsDir() const +QString OneSixInstance::loaderModsDir() const { return PathCombine(minecraftRoot(), "mods"); } -QString DerpInstance::resourcePacksDir() const +QString OneSixInstance::resourcePacksDir() const { return PathCombine(minecraftRoot(), "resourcepacks"); } -QString DerpInstance::instanceConfigFolder() const +QString OneSixInstance::instanceConfigFolder() const { return PathCombine(minecraftRoot(), "config"); } diff --git a/logic/DerpInstance.h b/logic/OneSixInstance.h similarity index 89% rename from logic/DerpInstance.h rename to logic/OneSixInstance.h index 46f953c0..94577828 100644 --- a/logic/DerpInstance.h +++ b/logic/OneSixInstance.h @@ -17,14 +17,14 @@ #include "BaseInstance.h" -#include "DerpVersion.h" +#include "OneSixVersion.h" #include "ModList.h" -class DerpInstance : public BaseInstance +class OneSixInstance : public BaseInstance { Q_OBJECT public: - explicit DerpInstance(const QString &rootDir, SettingsObject *settings, + explicit OneSixInstance(const QString &rootDir, SettingsObject *settings, QObject *parent = 0); ////// Mod Lists ////// @@ -56,7 +56,7 @@ public: /// clears all version information in preparation for an update void clearFullVersion(); /// get the current full version info - std::shared_ptr getFullVersion(); + std::shared_ptr getFullVersion(); /// is the current version original, or custom? virtual bool versionIsCustom() override; @@ -71,5 +71,5 @@ signals: private: QStringList processMinecraftArgs(MojangAccountPtr account); - QDir reconstructAssets(std::shared_ptr version); + QDir reconstructAssets(std::shared_ptr version); }; diff --git a/logic/DerpInstance_p.h b/logic/OneSixInstance_p.h similarity index 85% rename from logic/DerpInstance_p.h rename to logic/OneSixInstance_p.h index 41f7b62d..a2b70ac9 100644 --- a/logic/DerpInstance_p.h +++ b/logic/OneSixInstance_p.h @@ -16,12 +16,12 @@ #pragma once #include "BaseInstance_p.h" -#include "DerpVersion.h" +#include "OneSixVersion.h" #include "ModList.h" -struct DerpInstancePrivate : public BaseInstancePrivate +struct OneSixInstancePrivate : public BaseInstancePrivate { - std::shared_ptr version; + std::shared_ptr version; std::shared_ptr loader_mod_list; std::shared_ptr resource_pack_list; }; diff --git a/logic/DerpLibrary.cpp b/logic/OneSixLibrary.cpp similarity index 86% rename from logic/DerpLibrary.cpp rename to logic/OneSixLibrary.cpp index ba4d516b..4d892d53 100644 --- a/logic/DerpLibrary.cpp +++ b/logic/OneSixLibrary.cpp @@ -15,15 +15,15 @@ #include -#include "DerpLibrary.h" -#include "DerpRule.h" +#include "OneSixLibrary.h" +#include "OneSixRule.h" #include "OpSys.h" #include "logic/net/URLConstants.h" #include #include #include "logger/QsLog.h" -void DerpLibrary::finalize() +void OneSixLibrary::finalize() { QStringList parts = m_name.split(':'); QString relative = parts[0]; @@ -76,67 +76,67 @@ void DerpLibrary::finalize() } } -void DerpLibrary::setName(const QString &name) +void OneSixLibrary::setName(const QString &name) { m_name = name; } -void DerpLibrary::setBaseUrl(const QString &base_url) +void OneSixLibrary::setBaseUrl(const QString &base_url) { m_base_url = base_url; } -void DerpLibrary::setIsNative() +void OneSixLibrary::setIsNative() { m_is_native = true; } -void DerpLibrary::addNative(OpSys os, const QString &suffix) +void OneSixLibrary::addNative(OpSys os, const QString &suffix) { m_is_native = true; m_native_suffixes[os] = suffix; } -void DerpLibrary::setRules(QList> rules) +void OneSixLibrary::setRules(QList> rules) { m_rules = rules; } -bool DerpLibrary::isActive() const +bool OneSixLibrary::isActive() const { return m_is_active; } -bool DerpLibrary::isNative() const +bool OneSixLibrary::isNative() const { return m_is_native; } -QString DerpLibrary::downloadUrl() const +QString OneSixLibrary::downloadUrl() const { if (m_absolute_url.size()) return m_absolute_url; return m_download_url; } -QString DerpLibrary::storagePath() const +QString OneSixLibrary::storagePath() const { return m_storage_path; } -void DerpLibrary::setAbsoluteUrl(const QString &absolute_url) +void OneSixLibrary::setAbsoluteUrl(const QString &absolute_url) { m_absolute_url = absolute_url; } -QString DerpLibrary::absoluteUrl() const +QString OneSixLibrary::absoluteUrl() const { return m_absolute_url; } -void DerpLibrary::setHint(const QString &hint) +void OneSixLibrary::setHint(const QString &hint) { m_hint = hint; } -QString DerpLibrary::hint() const +QString OneSixLibrary::hint() const { return m_hint; } -bool DerpLibrary::filesExist() +bool OneSixLibrary::filesExist() { QString storage = storagePath(); if (storage.contains("${arch}")) @@ -167,7 +167,7 @@ bool DerpLibrary::filesExist() return true; } -bool DerpLibrary::extractTo(QString target_dir) +bool OneSixLibrary::extractTo(QString target_dir) { QString storage = storagePath(); if (storage.contains("${arch}")) @@ -220,7 +220,7 @@ bool DerpLibrary::extractTo(QString target_dir) return true; } -QJsonObject DerpLibrary::toJson() +QJsonObject OneSixLibrary::toJson() { QJsonObject libRoot; libRoot.insert("name", m_name); diff --git a/logic/DerpLibrary.h b/logic/OneSixLibrary.h similarity index 98% rename from logic/DerpLibrary.h rename to logic/OneSixLibrary.h index d1cee843..52f89969 100644 --- a/logic/DerpLibrary.h +++ b/logic/OneSixLibrary.h @@ -26,7 +26,7 @@ class Rule; -class DerpLibrary +class OneSixLibrary { private: // basic values used internally (so far) @@ -63,7 +63,7 @@ public: public: /// Constructor - DerpLibrary(const QString &name) + OneSixLibrary(const QString &name) { m_name = name; } diff --git a/logic/DerpRule.cpp b/logic/OneSixRule.cpp similarity index 98% rename from logic/DerpRule.cpp rename to logic/OneSixRule.cpp index 5ed200e3..d8d13b50 100644 --- a/logic/DerpRule.cpp +++ b/logic/OneSixRule.cpp @@ -16,7 +16,7 @@ #include #include -#include "DerpRule.h" +#include "OneSixRule.h" QList> rulesFromJsonV4(const QJsonObject &objectWithRules) { diff --git a/logic/DerpRule.h b/logic/OneSixRule.h similarity index 90% rename from logic/DerpRule.h rename to logic/OneSixRule.h index 0254028c..426e2886 100644 --- a/logic/DerpRule.h +++ b/logic/OneSixRule.h @@ -17,7 +17,7 @@ #include -#include "logic/DerpLibrary.h" +#include "logic/OneSixLibrary.h" enum RuleAction { @@ -33,7 +33,7 @@ class Rule { protected: RuleAction m_result; - virtual bool applies(DerpLibrary *parent) = 0; + virtual bool applies(OneSixLibrary *parent) = 0; public: Rule(RuleAction result) : m_result(result) @@ -41,7 +41,7 @@ public: } virtual ~Rule() {}; virtual QJsonObject toJson() = 0; - RuleAction apply(DerpLibrary *parent) + RuleAction apply(OneSixLibrary *parent) { if (applies(parent)) return m_result; @@ -60,7 +60,7 @@ private: QString m_version_regexp; protected: - virtual bool applies(DerpLibrary *) + virtual bool applies(OneSixLibrary *) { return (m_system == currentSystem); } @@ -81,7 +81,7 @@ public: class ImplicitRule : public Rule { protected: - virtual bool applies(DerpLibrary *) + virtual bool applies(OneSixLibrary *) { return true; } diff --git a/logic/DerpUpdate.cpp b/logic/OneSixUpdate.cpp similarity index 88% rename from logic/DerpUpdate.cpp rename to logic/OneSixUpdate.cpp index 5686e4ac..f51b6c23 100644 --- a/logic/DerpUpdate.cpp +++ b/logic/OneSixUpdate.cpp @@ -14,7 +14,7 @@ */ #include "MultiMC.h" -#include "DerpUpdate.h" +#include "OneSixUpdate.h" #include @@ -25,9 +25,9 @@ #include "BaseInstance.h" #include "lists/MinecraftVersionList.h" -#include "DerpVersion.h" -#include "DerpLibrary.h" -#include "DerpInstance.h" +#include "OneSixVersion.h" +#include "OneSixLibrary.h" +#include "OneSixInstance.h" #include "net/ForgeMirrors.h" #include "net/URLConstants.h" #include "assets/AssetsUtils.h" @@ -35,12 +35,12 @@ #include "pathutils.h" #include -DerpUpdate::DerpUpdate(BaseInstance *inst, bool only_prepare, QObject *parent) +OneSixUpdate::OneSixUpdate(BaseInstance *inst, bool only_prepare, QObject *parent) : Task(parent), m_inst(inst), m_only_prepare(only_prepare) { } -void DerpUpdate::executeTask() +void OneSixUpdate::executeTask() { QString intendedVersion = m_inst->intendedVersionId(); @@ -77,7 +77,7 @@ void DerpUpdate::executeTask() } } -void DerpUpdate::versionFileStart() +void OneSixUpdate::versionFileStart() { QLOG_INFO() << m_inst->name() << ": getting version file."; setStatus(tr("Getting the version files from Mojang...")); @@ -94,10 +94,10 @@ void DerpUpdate::versionFileStart() specificVersionDownloadJob->start(); } -void DerpUpdate::versionFileFinished() +void OneSixUpdate::versionFileFinished() { NetActionPtr DlJob = specificVersionDownloadJob->first(); - DerpInstance *inst = (DerpInstance *)m_inst; + OneSixInstance *inst = (OneSixInstance *)m_inst; QString version_id = targetVersion->descriptor(); QString inst_dir = m_inst->instanceRoot(); @@ -142,16 +142,16 @@ void DerpUpdate::versionFileFinished() jarlibStart(); } -void DerpUpdate::versionFileFailed() +void OneSixUpdate::versionFileFailed() { emitFailed("Failed to download the version description. Try again."); } -void DerpUpdate::assetIndexStart() +void OneSixUpdate::assetIndexStart() { setStatus(tr("Updating assets index...")); - DerpInstance *inst = (DerpInstance *)m_inst; - std::shared_ptr version = inst->getFullVersion(); + OneSixInstance *inst = (OneSixInstance *)m_inst; + std::shared_ptr version = inst->getFullVersion(); QString assetName = version->assets; QUrl indexUrl = "http://" + URLConstants::AWS_DOWNLOAD_INDEXES + assetName + ".json"; QString localPath = assetName + ".json"; @@ -170,12 +170,12 @@ void DerpUpdate::assetIndexStart() jarlibDownloadJob->start(); } -void DerpUpdate::assetIndexFinished() +void OneSixUpdate::assetIndexFinished() { AssetsIndex index; - DerpInstance *inst = (DerpInstance *)m_inst; - std::shared_ptr version = inst->getFullVersion(); + OneSixInstance *inst = (OneSixInstance *)m_inst; + std::shared_ptr version = inst->getFullVersion(); QString assetName = version->assets; QString asset_fname = "assets/indexes/" + assetName + ".json"; @@ -215,26 +215,26 @@ void DerpUpdate::assetIndexFinished() assetsFinished(); } -void DerpUpdate::assetIndexFailed() +void OneSixUpdate::assetIndexFailed() { emitFailed("Failed to download the assets index!"); } -void DerpUpdate::assetsFinished() +void OneSixUpdate::assetsFinished() { prepareForLaunch(); } -void DerpUpdate::assetsFailed() +void OneSixUpdate::assetsFailed() { emitFailed("Failed to download assets!"); } -void DerpUpdate::jarlibStart() +void OneSixUpdate::jarlibStart() { setStatus(tr("Getting the library files from Mojang...")); QLOG_INFO() << m_inst->name() << ": downloading libraries"; - DerpInstance *inst = (DerpInstance *)m_inst; + OneSixInstance *inst = (OneSixInstance *)m_inst; bool successful = inst->reloadFullVersion(); if (!successful) { @@ -244,7 +244,7 @@ void DerpUpdate::jarlibStart() } // Build a list of URLs that will need to be downloaded. - std::shared_ptr version = inst->getFullVersion(); + std::shared_ptr version = inst->getFullVersion(); // minecraft.jar for this version { QString version_id = version->id; @@ -318,12 +318,12 @@ void DerpUpdate::jarlibStart() jarlibDownloadJob->start(); } -void DerpUpdate::jarlibFinished() +void OneSixUpdate::jarlibFinished() { assetIndexStart(); } -void DerpUpdate::jarlibFailed() +void OneSixUpdate::jarlibFailed() { QStringList failed = jarlibDownloadJob->getFailedFiles(); QString failed_all = failed.join("\n"); @@ -331,17 +331,17 @@ void DerpUpdate::jarlibFailed() "\n\nPlease try again."); } -void DerpUpdate::prepareForLaunch() +void OneSixUpdate::prepareForLaunch() { setStatus(tr("Preparing for launch...")); QLOG_INFO() << m_inst->name() << ": preparing for launch"; - auto derp_inst = (DerpInstance *)m_inst; + auto OneSix_inst = (OneSixInstance *)m_inst; // delete any leftovers, if they are present. - derp_inst->cleanupAfterRun(); + OneSix_inst->cleanupAfterRun(); - QString natives_dir_raw = PathCombine(derp_inst->instanceRoot(), "natives/"); - auto version = derp_inst->getFullVersion(); + QString natives_dir_raw = PathCombine(OneSix_inst->instanceRoot(), "natives/"); + auto version = OneSix_inst->getFullVersion(); if (!version) { emitFailed("The version information for this instance is not complete. Try re-creating " diff --git a/logic/DerpUpdate.h b/logic/OneSixUpdate.h similarity index 92% rename from logic/DerpUpdate.h rename to logic/OneSixUpdate.h index 475f6c35..bc717a94 100644 --- a/logic/DerpUpdate.h +++ b/logic/OneSixUpdate.h @@ -25,11 +25,11 @@ class MinecraftVersion; class BaseInstance; -class DerpUpdate : public Task +class OneSixUpdate : public Task { Q_OBJECT public: - explicit DerpUpdate(BaseInstance *inst, bool prepare_for_launch, QObject *parent = 0); + explicit OneSixUpdate(BaseInstance *inst, bool prepare_for_launch, QObject *parent = 0); virtual void executeTask(); private diff --git a/logic/OneSixVersion.cpp b/logic/OneSixVersion.cpp index 3571be9b..3db3bd77 100644 --- a/logic/OneSixVersion.cpp +++ b/logic/OneSixVersion.cpp @@ -13,228 +13,60 @@ * limitations under the License. */ -#include "logic/DerpVersion.h" -#include "logic/DerpLibrary.h" -#include "logic/DerpRule.h" +#include "OneSixVersion.h" -#include "logger/QsLog.h" +#include -std::shared_ptr fromJsonV4(QJsonObject root, - std::shared_ptr fullVersion) +#include "OneSixVersionBuilder.h" + +OneSixVersion::OneSixVersion(OneSixInstance *instance, QObject *parent) + : QAbstractListModel(parent), m_instance(instance) { - fullVersion->id = root.value("id").toString(); - - fullVersion->mainClass = root.value("mainClass").toString(); - auto procArgsValue = root.value("processArguments"); - if (procArgsValue.isString()) - { - fullVersion->processArguments = procArgsValue.toString(); - QString toCompare = fullVersion->processArguments.toLower(); - if (toCompare == "legacy") - { - fullVersion->minecraftArguments = " ${auth_player_name} ${auth_session}"; - } - else if (toCompare == "username_session") - { - fullVersion->minecraftArguments = - "--username ${auth_player_name} --session ${auth_session}"; - } - else if (toCompare == "username_session_version") - { - fullVersion->minecraftArguments = "--username ${auth_player_name} " - "--session ${auth_session} " - "--version ${profile_name}"; - } - } - - auto minecraftArgsValue = root.value("minecraftArguments"); - if (minecraftArgsValue.isString()) - { - fullVersion->minecraftArguments = minecraftArgsValue.toString(); - } - - auto minecraftTypeValue = root.value("type"); - if (minecraftTypeValue.isString()) - { - fullVersion->type = minecraftTypeValue.toString(); - } - - fullVersion->releaseTime = root.value("releaseTime").toString(); - fullVersion->time = root.value("time").toString(); - - auto assetsID = root.value("assets"); - if (assetsID.isString()) - { - fullVersion->assets = assetsID.toString(); - } - else - { - fullVersion->assets = "legacy"; - } - - QLOG_DEBUG() << "Assets version:" << fullVersion->assets; - - // Iterate through the list, if it's a list. - auto librariesValue = root.value("libraries"); - if (!librariesValue.isArray()) - return fullVersion; - - QJsonArray libList = root.value("libraries").toArray(); - for (auto libVal : libList) - { - if (!libVal.isObject()) - { - continue; - } - - QJsonObject libObj = libVal.toObject(); - - // Library name - auto nameVal = libObj.value("name"); - if (!nameVal.isString()) - continue; - std::shared_ptr library(new DerpLibrary(nameVal.toString())); - - auto urlVal = libObj.value("url"); - if (urlVal.isString()) - { - library->setBaseUrl(urlVal.toString()); - } - auto hintVal = libObj.value("MMC-hint"); - if (hintVal.isString()) - { - library->setHint(hintVal.toString()); - } - auto urlAbsVal = libObj.value("MMC-absoluteUrl"); - auto urlAbsuVal = libObj.value("MMC-absulute_url"); // compatibility - if (urlAbsVal.isString()) - { - library->setAbsoluteUrl(urlAbsVal.toString()); - } - else if (urlAbsuVal.isString()) - { - library->setAbsoluteUrl(urlAbsuVal.toString()); - } - // Extract excludes (if any) - auto extractVal = libObj.value("extract"); - if (extractVal.isObject()) - { - QStringList excludes; - auto extractObj = extractVal.toObject(); - auto excludesVal = extractObj.value("exclude"); - if (excludesVal.isArray()) - { - auto excludesList = excludesVal.toArray(); - for (auto excludeVal : excludesList) - { - if (excludeVal.isString()) - excludes.append(excludeVal.toString()); - } - library->extract_excludes = excludes; - } - } - - auto nativesVal = libObj.value("natives"); - if (nativesVal.isObject()) - { - library->setIsNative(); - auto nativesObj = nativesVal.toObject(); - auto iter = nativesObj.begin(); - while (iter != nativesObj.end()) - { - auto osType = OpSys_fromString(iter.key()); - if (osType == Os_Other) - continue; - if (!iter.value().isString()) - continue; - library->addNative(osType, iter.value().toString()); - iter++; - } - } - library->setRules(rulesFromJsonV4(libObj)); - library->finalize(); - fullVersion->libraries.append(library); - } - return fullVersion; + clear(); } -std::shared_ptr DerpVersion::fromJson(QJsonObject root) +bool OneSixVersion::reload(QWidget *widgetParent) { - std::shared_ptr readVersion(new DerpVersion()); - int launcher_ver = readVersion->minimumLauncherVersion = - root.value("minimumLauncherVersion").toDouble(); - - // ADD MORE HERE :D - if (launcher_ver > 0 && launcher_ver <= 13) - return fromJsonV4(root, readVersion); - else - { - return std::shared_ptr(); - } + return OneSixVersionBuilder::build(this, m_instance, widgetParent); } -std::shared_ptr DerpVersion::fromFile(QString filepath) +void OneSixVersion::clear() { - QFile file(filepath); - if (!file.open(QIODevice::ReadOnly)) - { - return std::shared_ptr(); - } - - auto data = file.readAll(); - QJsonParseError jsonError; - QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); - - if (jsonError.error != QJsonParseError::NoError) - { - return std::shared_ptr(); - } - - if (!jsonDoc.isObject()) - { - return std::shared_ptr(); - } - QJsonObject root = jsonDoc.object(); - auto version = fromJson(root); - if (version) - version->original_file = filepath; - return version; + id.clear(); + time.clear(); + releaseTime.clear(); + type.clear(); + assets.clear(); + processArguments.clear(); + minecraftArguments.clear(); + minimumLauncherVersion = 0xDEADBEAF; + mainClass.clear(); + libraries.clear(); } -bool DerpVersion::toOriginalFile() +void OneSixVersion::dump() const { - if (original_file.isEmpty()) - return false; - QSaveFile file(original_file); - if (!file.open(QIODevice::WriteOnly)) + qDebug().nospace() << "OneSixVersion(" + << "\n\tid=" << id + << "\n\ttime=" << time + << "\n\treleaseTime=" << releaseTime + << "\n\ttype=" << type + << "\n\tassets=" << assets + << "\n\tprocessArguments=" << processArguments + << "\n\tminecraftArguments=" << minecraftArguments + << "\n\tminimumLauncherVersion=" << minimumLauncherVersion + << "\n\tmainClass=" << mainClass + << "\n\tlibraries="; + for (auto lib : libraries) { - return false; + qDebug().nospace() << "\n\t\t" << lib.get(); } - // serialize base attributes (those we care about anyway) - QJsonObject root; - root.insert("minecraftArguments", minecraftArguments); - root.insert("mainClass", mainClass); - root.insert("minimumLauncherVersion", minimumLauncherVersion); - root.insert("time", time); - root.insert("id", id); - root.insert("type", type); - // screw processArguments - root.insert("releaseTime", releaseTime); - QJsonArray libarray; - for (const auto &lib : libraries) - { - libarray.append(lib->toJson()); - } - if (libarray.count()) - root.insert("libraries", libarray); - QJsonDocument doc(root); - file.write(doc.toJson()); - return file.commit(); + qDebug().nospace() << "\n)"; } -QList> DerpVersion::getActiveNormalLibs() +QList > OneSixVersion::getActiveNormalLibs() { - QList> output; + QList > output; for (auto lib : libraries) { if (lib->isActive() && !lib->isNative()) @@ -245,9 +77,9 @@ QList> DerpVersion::getActiveNormalLibs() return output; } -QList> DerpVersion::getActiveNativeLibs() +QList > OneSixVersion::getActiveNativeLibs() { - QList> output; + QList > output; for (auto lib : libraries) { if (lib->isActive() && lib->isNative()) @@ -258,17 +90,17 @@ QList> DerpVersion::getActiveNativeLibs() return output; } -void DerpVersion::externalUpdateStart() +std::shared_ptr OneSixVersion::fromJson(const QJsonObject &obj) { - beginResetModel(); + std::shared_ptr version(new OneSixVersion(0)); + if (OneSixVersionBuilder::read(version.get(), obj)) + { + return version; + } + return 0; } -void DerpVersion::externalUpdateFinish() -{ - endResetModel(); -} - -QVariant DerpVersion::data(const QModelIndex &index, int role) const +QVariant OneSixVersion::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); @@ -296,7 +128,7 @@ QVariant DerpVersion::data(const QModelIndex &index, int role) const return QVariant(); } -Qt::ItemFlags DerpVersion::flags(const QModelIndex &index) const +Qt::ItemFlags OneSixVersion::flags(const QModelIndex &index) const { if (!index.isValid()) return Qt::NoItemFlags; @@ -312,7 +144,7 @@ Qt::ItemFlags DerpVersion::flags(const QModelIndex &index) const // return QAbstractListModel::flags(index); } -QVariant DerpVersion::headerData(int section, Qt::Orientation orientation, int role) const +QVariant OneSixVersion::headerData(int section, Qt::Orientation orientation, int role) const { if (role != Qt::DisplayRole || orientation != Qt::Horizontal) return QVariant(); @@ -329,12 +161,34 @@ QVariant DerpVersion::headerData(int section, Qt::Orientation orientation, int r } } -int DerpVersion::rowCount(const QModelIndex &parent) const +int OneSixVersion::rowCount(const QModelIndex &parent) const { return libraries.size(); } -int DerpVersion::columnCount(const QModelIndex &parent) const +int OneSixVersion::columnCount(const QModelIndex &parent) const { return 3; } + +QDebug operator<<(QDebug &dbg, const OneSixVersion *version) +{ + version->dump(); + return dbg.maybeSpace(); +} +QDebug operator<<(QDebug &dbg, const OneSixLibrary *library) +{ + dbg.nospace() << "OneSixLibrary(" + << "\n\t\t\trawName=" << library->rawName() + << "\n\t\t\tname=" << library->name() + << "\n\t\t\tversion=" << library->version() + << "\n\t\t\ttype=" << library->type() + << "\n\t\t\tisActive=" << library->isActive() + << "\n\t\t\tisNative=" << library->isNative() + << "\n\t\t\tdownloadUrl=" << library->downloadUrl() + << "\n\t\t\tstoragePath=" << library->storagePath() + << "\n\t\t\tabsolutePath=" << library->absoluteUrl() + << "\n\t\t\thint=" << library->hint(); + dbg.nospace() << "\n\t\t)"; + return dbg.maybeSpace(); +} diff --git a/logic/OneSixVersion.h b/logic/OneSixVersion.h index e8f744aa..00afd010 100644 --- a/logic/OneSixVersion.h +++ b/logic/OneSixVersion.h @@ -14,15 +14,23 @@ */ #pragma once -#include + +#include + +#include +#include #include -class DerpLibrary; +#include "OneSixLibrary.h" -class DerpVersion : public QAbstractListModel +class OneSixInstance; + +class OneSixVersion : public QAbstractListModel { - // Things required to implement the Qt list model + Q_OBJECT public: + explicit OneSixVersion(OneSixInstance *instance, QObject *parent = 0); + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; virtual QVariant headerData(int section, Qt::Orientation orientation, @@ -30,24 +38,19 @@ public: virtual int columnCount(const QModelIndex &parent) const; virtual Qt::ItemFlags flags(const QModelIndex &index) const; - // serialization/deserialization -public: - bool toOriginalFile(); - static std::shared_ptr fromJson(QJsonObject root); - static std::shared_ptr fromFile(QString filepath); + bool reload(QWidget *widgetParent); + void clear(); + + void dump() const; public: - QList> getActiveNormalLibs(); - QList> getActiveNativeLibs(); - // called when something starts/stops messing with the object - // FIXME: these are ugly in every possible way. - void externalUpdateStart(); - void externalUpdateFinish(); + QList> getActiveNormalLibs(); + QList> getActiveNativeLibs(); + + static std::shared_ptr fromJson(const QJsonObject &obj); // data members public: - /// file this was read from. blank, if none - QString original_file; /// the ID - determines which jar to use! ACTUALLY IMPORTANT! QString id; /// Last updated time - as a string @@ -81,7 +84,7 @@ public: QString mainClass; /// the list of libs - both active and inactive, native and java - QList> libraries; + QList> libraries; /* FIXME: add support for those rules here? Looks like a pile of quick hacks to me though. @@ -103,4 +106,10 @@ public: } */ // QList rules; + +private: + OneSixInstance *m_instance; }; + +QDebug operator<<(QDebug &dbg, const OneSixVersion *version); +QDebug operator<<(QDebug &dbg, const OneSixLibrary *library); diff --git a/logic/DerpVersionBuilder.cpp b/logic/OneSixVersionBuilder.cpp similarity index 87% rename from logic/DerpVersionBuilder.cpp rename to logic/OneSixVersionBuilder.cpp index 20f43404..85f55a52 100644 --- a/logic/DerpVersionBuilder.cpp +++ b/logic/OneSixVersionBuilder.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "DerpVersionBuilder.h" +#include "OneSixVersionBuilder.h" #include #include @@ -26,35 +26,35 @@ #include #include -#include "DerpVersion.h" -#include "DerpInstance.h" -#include "DerpRule.h" +#include "OneSixVersion.h" +#include "OneSixInstance.h" +#include "OneSixRule.h" #include "logger/QsLog.h" -DerpVersionBuilder::DerpVersionBuilder() +OneSixVersionBuilder::OneSixVersionBuilder() { } -bool DerpVersionBuilder::build(DerpVersion *version, DerpInstance *instance, QWidget *widgetParent) +bool OneSixVersionBuilder::build(OneSixVersion *version, OneSixInstance *instance, QWidget *widgetParent) { - DerpVersionBuilder builder; + OneSixVersionBuilder builder; builder.m_version = version; builder.m_instance = instance; builder.m_widgetParent = widgetParent; return builder.build(); } -bool DerpVersionBuilder::read(DerpVersion *version, const QJsonObject &obj) +bool OneSixVersionBuilder::read(OneSixVersion *version, const QJsonObject &obj) { - DerpVersionBuilder builder; + OneSixVersionBuilder builder; builder.m_version = version; builder.m_instance = 0; builder.m_widgetParent = 0; return builder.read(obj); } -bool DerpVersionBuilder::build() +bool OneSixVersionBuilder::build() { m_version->clear(); @@ -127,7 +127,7 @@ bool DerpVersionBuilder::build() return true; } -bool DerpVersionBuilder::read(const QJsonObject &obj) +bool OneSixVersionBuilder::read(const QJsonObject &obj) { m_version->clear(); @@ -152,14 +152,14 @@ void applyString(const QJsonObject &obj, const QString &key, QString &out, const } } } -void applyString(const QJsonObject &obj, const QString &key, std::shared_ptr lib, void(DerpLibrary::*func)(const QString &val)) +void applyString(const QJsonObject &obj, const QString &key, std::shared_ptr lib, void(OneSixLibrary::*func)(const QString &val)) { if (obj.contains(key) && obj.value(key).isString()) { (lib.get()->*func)(obj.value(key).toString()); } } -bool DerpVersionBuilder::apply(const QJsonObject &object) +bool OneSixVersionBuilder::apply(const QJsonObject &object) { applyString(object, "id", m_version->id); applyString(object, "mainClass", m_version->mainClass); @@ -265,7 +265,7 @@ bool DerpVersionBuilder::apply(const QJsonObject &object) return true; } -int findLibrary(QList > haystack, const QString &needle) +int findLibrary(QList > haystack, const QString &needle) { for (int i = 0; i < haystack.size(); ++i) { @@ -277,7 +277,7 @@ int findLibrary(QList > haystack, const QString &ne return -1; } -bool DerpVersionBuilder::applyLibrary(const QJsonObject &lib, const DerpVersionBuilder::Type type) +bool OneSixVersionBuilder::applyLibrary(const QJsonObject &lib, const OneSixVersionBuilder::Type type) { // Library name auto nameVal = lib.value("name"); @@ -302,11 +302,11 @@ bool DerpVersionBuilder::applyLibrary(const QJsonObject &lib, const DerpVersionB return false; } - std::shared_ptr library; + std::shared_ptr library; if (lib.value("insert").toString() != "apply" && type == Add) { - QMutableListIterator > it(m_version->libraries); + QMutableListIterator > it(m_version->libraries); while (it.hasNext()) { if (it.next()->rawName() == name) @@ -322,13 +322,13 @@ bool DerpVersionBuilder::applyLibrary(const QJsonObject &lib, const DerpVersionB } else { - library.reset(new DerpLibrary(nameVal.toString())); + library.reset(new OneSixLibrary(nameVal.toString())); } - applyString(lib, "url", library, &DerpLibrary::setBaseUrl); - applyString(lib, "MMC-hint", library, &DerpLibrary::setHint); - applyString(lib, "MMC-absulute_url", library, &DerpLibrary::setAbsoluteUrl); - applyString(lib, "MMC-absoluteUrl", library, &DerpLibrary::setAbsoluteUrl); + applyString(lib, "url", library, &OneSixLibrary::setBaseUrl); + applyString(lib, "MMC-hint", library, &OneSixLibrary::setHint); + applyString(lib, "MMC-absulute_url", library, &OneSixLibrary::setAbsoluteUrl); + applyString(lib, "MMC-absoluteUrl", library, &OneSixLibrary::setAbsoluteUrl); auto extractVal = lib.value("extract"); if (extractVal.isObject()) @@ -426,7 +426,7 @@ bool DerpVersionBuilder::applyLibrary(const QJsonObject &lib, const DerpVersionB return true; } -bool DerpVersionBuilder::read(const QFileInfo &fileInfo, QJsonObject *out) +bool OneSixVersionBuilder::read(const QFileInfo &fileInfo, QJsonObject *out) { QFile file(fileInfo.absoluteFilePath()); if (!file.open(QFile::ReadOnly)) diff --git a/logic/DerpVersionBuilder.h b/logic/OneSixVersionBuilder.h similarity index 76% rename from logic/DerpVersionBuilder.h rename to logic/OneSixVersionBuilder.h index b94cd8e9..a3ba331c 100644 --- a/logic/DerpVersionBuilder.h +++ b/logic/OneSixVersionBuilder.h @@ -17,22 +17,22 @@ #include -class DerpVersion; -class DerpInstance; +class OneSixVersion; +class OneSixInstance; class QWidget; class QJsonObject; class QFileInfo; -class DerpVersionBuilder +class OneSixVersionBuilder { - DerpVersionBuilder(); + OneSixVersionBuilder(); public: - static bool build(DerpVersion *version, DerpInstance *instance, QWidget *widgetParent); - static bool read(DerpVersion *version, const QJsonObject &obj); + static bool build(OneSixVersion *version, OneSixInstance *instance, QWidget *widgetParent); + static bool read(OneSixVersion *version, const QJsonObject &obj); private: - DerpVersion *m_version; - DerpInstance *m_instance; + OneSixVersion *m_version; + OneSixInstance *m_instance; QWidget *m_widgetParent; enum Type diff --git a/logic/lists/MinecraftVersionList.cpp b/logic/lists/MinecraftVersionList.cpp index 29894b5a..91f86df0 100644 --- a/logic/lists/MinecraftVersionList.cpp +++ b/logic/lists/MinecraftVersionList.cpp @@ -234,18 +234,18 @@ void MCVListLoadTask::list_downloaded() } // Parse the type. MinecraftVersion::VersionType versionType; - // Derp or Legacy. use filter to determine type + // OneSix or Legacy. use filter to determine type if (versionTypeStr == "release") { versionType = legacyWhitelist.contains(versionID) ? MinecraftVersion::Legacy - : MinecraftVersion::Derp; + : MinecraftVersion::OneSix; is_latest = (versionID == latestReleaseID); is_snapshot = false; } else if (versionTypeStr == "snapshot") // It's a snapshot... yay { versionType = legacyWhitelist.contains(versionID) ? MinecraftVersion::Legacy - : MinecraftVersion::Derp; + : MinecraftVersion::OneSix; is_latest = (versionID == latestSnapshotID); is_snapshot = true; } From 0f7b38c76bacc210beae21c4e23cc312f53fa5e4 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Fri, 24 Jan 2014 18:17:26 +0100 Subject: [PATCH 07/13] Fix some stuff --- logic/InstanceFactory.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/logic/InstanceFactory.cpp b/logic/InstanceFactory.cpp index 730bcd69..807bccd0 100644 --- a/logic/InstanceFactory.cpp +++ b/logic/InstanceFactory.cpp @@ -51,7 +51,7 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&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" || inst_type == "OneSix") + if (inst_type == "OneSix") { inst = new OneSixInstance(instDir, m_settings, this); } @@ -67,7 +67,7 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst { inst = new LegacyFTBInstance(instDir, m_settings, this); } - else if (inst_type == "OneSixFTB" || inst_type == "OneSixFTB") + else if (inst_type == "OneSixFTB") { inst = new OneSixFTBInstance(instDir, m_settings, this); } @@ -102,7 +102,7 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance(BaseInstance *& switch (mcVer->type) { case MinecraftVersion::Legacy: - // TODO OneSix + // TODO new instance type m_settings->set("InstanceType", "Legacy"); inst = new LegacyInstance(instDir, m_settings, this); inst->setIntendedVersionId(version->descriptor()); @@ -176,7 +176,7 @@ InstanceFactory::InstCreateError InstanceFactory::copyInstance(BaseInstance *&ne m_settings->registerSetting("InstanceType", "Legacy"); QString inst_type = m_settings->get("InstanceType").toString(); - if(inst_type == "OneSixFTB" || inst_type == "OneSixFTB") + if(inst_type == "OneSixFTB") m_settings->set("InstanceType", "OneSix"); if(inst_type == "LegacyFTB") m_settings->set("InstanceType", "Legacy"); From f9ea3dbfdea0db5626a6afadcfd599a5f53d8abd Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Mon, 27 Jan 2014 19:20:07 +0100 Subject: [PATCH 08/13] Split parsing/applying. Better error logging. Fix crash. --- gui/dialogs/OneSixModEditDialog.cpp | 4 +- logic/ForgeInstaller.cpp | 49 +- logic/OneSixFTBInstance.cpp | 2 +- logic/OneSixInstance.cpp | 30 +- logic/OneSixInstance.h | 8 +- logic/OneSixInstance_p.h | 1 + logic/OneSixLibrary.cpp | 14 +- logic/OneSixLibrary.h | 2 + logic/OneSixUpdate.cpp | 4 +- logic/OneSixVersion.cpp | 5 +- logic/OneSixVersion.h | 6 +- logic/OneSixVersionBuilder.cpp | 1054 +++++++++++++++++++-------- logic/OneSixVersionBuilder.h | 18 +- 13 files changed, 842 insertions(+), 355 deletions(-) diff --git a/gui/dialogs/OneSixModEditDialog.cpp b/gui/dialogs/OneSixModEditDialog.cpp index 625a7c91..ad15311b 100644 --- a/gui/dialogs/OneSixModEditDialog.cpp +++ b/gui/dialogs/OneSixModEditDialog.cpp @@ -162,7 +162,7 @@ void OneSixModEditDialog::on_forgeBtn_clicked() } } } - m_inst->reloadFullVersion(this); + m_inst->reloadVersion(this); } void OneSixModEditDialog::on_liteloaderBtn_clicked() @@ -184,7 +184,7 @@ void OneSixModEditDialog::on_liteloaderBtn_clicked() } else { - m_inst->reloadFullVersion(this); + m_inst->reloadVersion(this); } } diff --git a/logic/ForgeInstaller.cpp b/logic/ForgeInstaller.cpp index 863c3dfd..c0340e95 100644 --- a/logic/ForgeInstaller.cpp +++ b/logic/ForgeInstaller.cpp @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include "MultiMC.h" #include "OneSixInstance.h" @@ -146,36 +148,71 @@ bool ForgeInstaller::add(OneSixInstance *to) QJsonObject libObj = lib->toJson(); bool found = false; + bool equals = false; // find an entry that matches this one - for (auto tolib : to->getFullVersion()->libraries) + for (auto tolib : to->getNonCustomVersion()->libraries) { if (tolib->name() != libName) continue; found = true; + if (tolib->toJson() == libObj) + { + equals = true; + } // replace lib libObj.insert("insert", QString("apply")); break; } + if (equals) + { + continue; + } if (!found) { // add lib QJsonObject insertObj; - insertObj.insert("before", to->getFullVersion()->libraries.at(sliding_insert_window)->rawName()); + insertObj.insert( + "before", + to->getFullVersion()->libraries.at(sliding_insert_window + 1)->rawName()); libObj.insert("insert", insertObj); sliding_insert_window++; } - librariesPlus.append(libObj); + librariesPlus.prepend(libObj); } obj.insert("+libraries", librariesPlus); obj.insert("mainClass", m_forge_version->mainClass); - obj.insert("minecraftArguments", m_forge_version->minecraftArguments); - obj.insert("processArguments", m_forge_version->processArguments); + 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->getNonCustomVersion()->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->getNonCustomVersion()->processArguments) + { + obj.insert("processArguments", m_forge_version->processArguments); + } } QFile file(filename(to->instanceRoot())); if (!file.open(QFile::WriteOnly)) { - QLOG_ERROR() << "Error opening" << file.fileName() << "for reading:" << file.errorString(); + QLOG_ERROR() << "Error opening" << file.fileName() + << "for reading:" << file.errorString(); return false; } file.write(QJsonDocument(obj).toJson()); diff --git a/logic/OneSixFTBInstance.cpp b/logic/OneSixFTBInstance.cpp index 71bc1470..54bfbe2b 100644 --- a/logic/OneSixFTBInstance.cpp +++ b/logic/OneSixFTBInstance.cpp @@ -55,7 +55,7 @@ slots: setStatus(tr("Installing Forge...")); QString forgePath = entry->getFullPath(); ForgeInstaller forge(forgePath, forgeVersion->universal_url); - if (!instance->reloadFullVersion()) + if (!instance->reloadVersion()) { emitFailed(tr("Couldn't load the version config")); return; diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index c43a5187..19d5e112 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -35,13 +35,14 @@ OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *settings, d->m_settings->registerSetting("IntendedVersion", ""); d->m_settings->registerSetting("ShouldUpdate", false); d->version.reset(new OneSixVersion(this, this)); + d->nonCustomVersion.reset(new OneSixVersion(this, this)); if (QDir(instanceRoot()).exists("version.json")) { - reloadFullVersion(); + reloadVersion(); } else { - clearFullVersion(); + clearVersion(); } } @@ -139,6 +140,10 @@ QStringList OneSixInstance::processMinecraftArgs(MojangAccountPtr account) I_D(OneSixInstance); auto version = d->version; QString args_pattern = version->minecraftArguments; + for (auto tweaker : version->tweakers) + { + args_pattern += " --tweakClass " + tweaker; + } QMap token_mapping; // yggdrasil! @@ -287,7 +292,7 @@ bool OneSixInstance::setIntendedVersionId(QString version) settings().set("IntendedVersion", version); setShouldUpdate(true); QFile::remove(PathCombine(instanceRoot(), "version.json")); - clearFullVersion(); + clearVersion(); return true; } @@ -323,28 +328,39 @@ QString OneSixInstance::currentVersionId() const return intendedVersionId(); } -bool OneSixInstance::reloadFullVersion(QWidget *widgetParent) +bool OneSixInstance::reloadVersion(QWidget *widgetParent) { I_D(OneSixInstance); bool ret = d->version->reload(widgetParent); + if (ret) + { + ret = d->nonCustomVersion->reload(widgetParent, true); + } emit versionReloaded(); return ret; } -void OneSixInstance::clearFullVersion() +void OneSixInstance::clearVersion() { I_D(OneSixInstance); d->version->clear(); + d->nonCustomVersion->clear(); emit versionReloaded(); } -std::shared_ptr OneSixInstance::getFullVersion() +std::shared_ptr OneSixInstance::getFullVersion() const { - I_D(OneSixInstance); + I_D(const OneSixInstance); return d->version; } +std::shared_ptr OneSixInstance::getNonCustomVersion() const +{ + I_D(const OneSixInstance); + return d->nonCustomVersion; +} + QString OneSixInstance::defaultBaseJar() const { return "versions/" + intendedVersionId() + "/" + intendedVersionId() + ".jar"; diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h index 94577828..ee64e886 100644 --- a/logic/OneSixInstance.h +++ b/logic/OneSixInstance.h @@ -52,11 +52,13 @@ public: virtual QDialog *createModEditDialog(QWidget *parent) override; /// reload the full version json files. return true on success! - bool reloadFullVersion(QWidget *widgetParent = 0); + bool reloadVersion(QWidget *widgetParent = 0); /// clears all version information in preparation for an update - void clearFullVersion(); + void clearVersion(); /// get the current full version info - std::shared_ptr getFullVersion(); + std::shared_ptr getFullVersion() const; + /// gets the current version info, excluding custom.json + std::shared_ptr getNonCustomVersion() const; /// is the current version original, or custom? virtual bool versionIsCustom() override; diff --git a/logic/OneSixInstance_p.h b/logic/OneSixInstance_p.h index a2b70ac9..6dc74e50 100644 --- a/logic/OneSixInstance_p.h +++ b/logic/OneSixInstance_p.h @@ -22,6 +22,7 @@ struct OneSixInstancePrivate : public BaseInstancePrivate { std::shared_ptr version; + std::shared_ptr nonCustomVersion; std::shared_ptr loader_mod_list; std::shared_ptr resource_pack_list; }; diff --git a/logic/OneSixLibrary.cpp b/logic/OneSixLibrary.cpp index 4d892d53..2b1f0600 100644 --- a/logic/OneSixLibrary.cpp +++ b/logic/OneSixLibrary.cpp @@ -93,6 +93,10 @@ void OneSixLibrary::addNative(OpSys os, const QString &suffix) m_is_native = true; m_native_suffixes[os] = suffix; } +void OneSixLibrary::clearSuffixes() +{ + m_native_suffixes.clear(); +} void OneSixLibrary::setRules(QList> rules) { m_rules = rules; @@ -176,7 +180,7 @@ bool OneSixLibrary::extractTo(QString target_dir) cooked_storage.replace("${arch}", "32"); QString origin = PathCombine("libraries", cooked_storage); QString target_dir_cooked = PathCombine(target_dir, "32"); - if(!ensureFolderPathExists(target_dir_cooked)) + if (!ensureFolderPathExists(target_dir_cooked)) { QLOG_ERROR() << "Couldn't create folder " + target_dir_cooked; return false; @@ -191,7 +195,7 @@ bool OneSixLibrary::extractTo(QString target_dir) cooked_storage.replace("${arch}", "64"); origin = PathCombine("libraries", cooked_storage); target_dir_cooked = PathCombine(target_dir, "64"); - if(!ensureFolderPathExists(target_dir_cooked)) + if (!ensureFolderPathExists(target_dir_cooked)) { QLOG_ERROR() << "Couldn't create folder " + target_dir_cooked; return false; @@ -205,7 +209,7 @@ bool OneSixLibrary::extractTo(QString target_dir) } else { - if(!ensureFolderPathExists(target_dir)) + if (!ensureFolderPathExists(target_dir)) { QLOG_ERROR() << "Couldn't create folder " + target_dir; return false; @@ -230,8 +234,10 @@ QJsonObject OneSixLibrary::toJson() libRoot.insert("MMC-hint", m_hint); if (m_base_url != "http://" + URLConstants::AWS_DOWNLOAD_LIBRARIES && m_base_url != "https://" + URLConstants::AWS_DOWNLOAD_LIBRARIES && - m_base_url != "https://" + URLConstants::LIBRARY_BASE) + m_base_url != "https://" + URLConstants::LIBRARY_BASE && !m_base_url.isEmpty()) + { libRoot.insert("url", m_base_url); + } if (isNative() && m_native_suffixes.size()) { QJsonObject nativeList; diff --git a/logic/OneSixLibrary.h b/logic/OneSixLibrary.h index 52f89969..5384015a 100644 --- a/logic/OneSixLibrary.h +++ b/logic/OneSixLibrary.h @@ -107,6 +107,8 @@ public: void setIsNative(); /// Attach a name suffix to the specified OS native void addNative(OpSys os, const QString &suffix); + /// Clears all suffixes + void clearSuffixes(); /// Set the load rules void setRules(QList> rules); diff --git a/logic/OneSixUpdate.cpp b/logic/OneSixUpdate.cpp index f51b6c23..c056bc4c 100644 --- a/logic/OneSixUpdate.cpp +++ b/logic/OneSixUpdate.cpp @@ -137,7 +137,7 @@ void OneSixUpdate::versionFileFinished() { finfo.remove(); } - inst->reloadFullVersion(); + inst->reloadVersion(); jarlibStart(); } @@ -235,7 +235,7 @@ void OneSixUpdate::jarlibStart() setStatus(tr("Getting the library files from Mojang...")); QLOG_INFO() << m_inst->name() << ": downloading libraries"; OneSixInstance *inst = (OneSixInstance *)m_inst; - bool successful = inst->reloadFullVersion(); + bool successful = inst->reloadVersion(); if (!successful) { emitFailed("Failed to load the version description file. It might be " diff --git a/logic/OneSixVersion.cpp b/logic/OneSixVersion.cpp index 3db3bd77..1b6bc9cb 100644 --- a/logic/OneSixVersion.cpp +++ b/logic/OneSixVersion.cpp @@ -25,9 +25,9 @@ OneSixVersion::OneSixVersion(OneSixInstance *instance, QObject *parent) clear(); } -bool OneSixVersion::reload(QWidget *widgetParent) +bool OneSixVersion::reload(QWidget *widgetParent, const bool excludeCustom) { - return OneSixVersionBuilder::build(this, m_instance, widgetParent); + return OneSixVersionBuilder::build(this, m_instance, widgetParent, excludeCustom); } void OneSixVersion::clear() @@ -42,6 +42,7 @@ void OneSixVersion::clear() minimumLauncherVersion = 0xDEADBEAF; mainClass.clear(); libraries.clear(); + tweakers.clear(); } void OneSixVersion::dump() const diff --git a/logic/OneSixVersion.h b/logic/OneSixVersion.h index 00afd010..767e05db 100644 --- a/logic/OneSixVersion.h +++ b/logic/OneSixVersion.h @@ -38,7 +38,7 @@ public: virtual int columnCount(const QModelIndex &parent) const; virtual Qt::ItemFlags flags(const QModelIndex &index) const; - bool reload(QWidget *widgetParent); + bool reload(QWidget *widgetParent, const bool excludeCustom = false); void clear(); void dump() const; @@ -78,6 +78,10 @@ public: * writing) */ int minimumLauncherVersion = 0xDEADBEEF; + /** + * A list of all tweaker classes + */ + QStringList tweakers; /** * The main class to load first */ diff --git a/logic/OneSixVersionBuilder.cpp b/logic/OneSixVersionBuilder.cpp index 85f55a52..c031a94a 100644 --- a/logic/OneSixVersionBuilder.cpp +++ b/logic/OneSixVersionBuilder.cpp @@ -31,18 +31,660 @@ #include "OneSixRule.h" #include "logger/QsLog.h" +struct VersionFile +{ + int order; + QString id; + QString mainClass; + QString overwriteMinecraftArguments; + QString addMinecraftArguments; + QString removeMinecraftArguments; + QString processArguments; + QString type; + QString releaseTime; + QString time; + QString assets; + int minimumLauncherVersion = -1; + + bool shouldOverwriteTweakers = false; + QStringList overwriteTweakers; + QStringList addTweakers; + QStringList removeTweakers; + + struct Library + { + QString name; + QString url; + QString hint; + QString absoluteUrl; + bool applyExcludes = false; + QStringList excludes; + bool applyNatives = false; + QList> natives; + bool applyRules = false; + QList> rules; + + // user for '+' libraries + enum InsertType + { + Apply, + Append, + Prepend, + InsertBefore, + InsertAfter, + Replace + }; + InsertType insertType; + QString insertData; + }; + bool shouldOverwriteLibs = false; + QList overwriteLibs; + QList addLibs; + QList removeLibs; + + static Library fromLibraryJson(const QJsonObject &libObj, const QString &filename, + bool &isError) + { + isError = true; + Library out; + if (!libObj.contains("name")) + { + QLOG_ERROR() << filename << "contains a library that doesn't have a 'name' field"; + return out; + } + 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.url); + readString("MMC-hint", out.hint); + readString("MMC-absulute_url", out.absoluteUrl); + readString("MMC-absoluteUrl", out.absoluteUrl); + if (libObj.contains("extract")) + { + if (!libObj.value("extract").isObject()) + { + QLOG_ERROR() + << filename + << "contains a library with an 'extract' field that's not an object"; + return out; + } + QJsonObject extractObj = libObj.value("extract").toObject(); + if (!extractObj.contains("exclude") || !extractObj.value("exclude").isArray()) + { + QLOG_ERROR() << filename + << "contains a library with an invalid 'extract' field"; + return out; + } + out.applyExcludes = true; + QJsonArray excludeArray = extractObj.value("exclude").toArray(); + for (auto excludeVal : excludeArray) + { + if (!excludeVal.isString()) + { + QLOG_WARN() << filename << "contains a library that contains an 'extract' " + "field that contains an invalid 'exclude' entry " + "(skipping)"; + } + else + { + out.excludes.append(excludeVal.toString()); + } + } + } + if (libObj.contains("natives")) + { + if (!libObj.value("natives").isObject()) + { + QLOG_ERROR() + << filename + << "contains a library with a 'natives' field that's not an object"; + return out; + } + out.applyNatives = true; + QJsonObject nativesObj = libObj.value("natives").toObject(); + for (auto it = nativesObj.begin(); it != nativesObj.end(); ++it) + { + if (!it.value().isString()) + { + QLOG_WARN() << filename << "contains an invalid native (skipping)"; + } + OpSys opSys = OpSys_fromString(it.key()); + if (opSys != Os_Other) + { + out.natives.append(qMakePair(opSys, it.value().toString())); + } + } + } + if (libObj.contains("rules")) + { + out.applyRules = true; + out.rules = rulesFromJsonV4(libObj); + } + isError = false; + return out; + } + static VersionFile fromJson(const QJsonDocument &doc, const QString &filename, + const bool requireOrder, bool &isError) + { + VersionFile out; + isError = true; + if (doc.isEmpty() || doc.isNull()) + { + QLOG_ERROR() << filename << "is empty or null"; + return out; + } + if (!doc.isObject()) + { + QLOG_ERROR() << "The root of" << filename << "is not an object"; + return out; + } + + QJsonObject root = doc.object(); + + if (requireOrder) + { + if (root.contains("order")) + { + if (root.value("order").isDouble()) + { + out.order = root.value("order").toDouble(); + } + else + { + QLOG_ERROR() << "'order' field contains an invalid value in" << filename; + return out; + } + } + else + { + QLOG_ERROR() << filename << "doesn't contain an order field"; + } + } + + auto readString = [root, filename](const QString &key, QString &variable) + { + if (root.contains(key)) + { + QJsonValue val = root.value(key); + if (!val.isString()) + { + QLOG_WARN() << key << "is not a string in" << filename << "(skipping)"; + } + else + { + variable = val.toString(); + } + } + }; + + readString("id", out.id); + readString("mainClass", out.mainClass); + readString("processArguments", out.processArguments); + readString("minecraftArguments", out.overwriteMinecraftArguments); + readString("+minecraftArguments", out.addMinecraftArguments); + readString("-minecraftArguments", out.removeMinecraftArguments); + readString("type", out.type); + readString("releaseTime", out.releaseTime); + readString("time", out.time); + readString("assets", out.assets); + if (root.contains("minimumLauncherVersion")) + { + QJsonValue val = root.value("minimumLauncherVersion"); + if (!val.isDouble()) + { + QLOG_WARN() << "minimumLauncherVersion is not an int in" << filename + << "(skipping)"; + } + else + { + out.minimumLauncherVersion = val.toDouble(); + } + } + + if (root.contains("tweakers")) + { + QJsonValue tweakersVal = root.value("tweakers"); + if (!tweakersVal.isArray()) + { + QLOG_ERROR() << filename << "contains a 'tweakers' field, but it's not an array"; + return out; + } + out.shouldOverwriteTweakers = true; + QJsonArray tweakers = root.value("tweakers").toArray(); + for (auto tweakerVal : tweakers) + { + if (!tweakerVal.isString()) + { + QLOG_ERROR() << filename << "contains a 'tweakers' field entry that's not a string"; + return out; + } + out.overwriteTweakers.append(tweakerVal.toString()); + } + } + if (root.contains("+tweakers")) + { + QJsonValue tweakersVal = root.value("+tweakers"); + if (!tweakersVal.isArray()) + { + QLOG_ERROR() << filename << "contains a '+tweakers' field, but it's not an array"; + return out; + } + QJsonArray tweakers = root.value("+tweakers").toArray(); + for (auto tweakerVal : tweakers) + { + if (!tweakerVal.isString()) + { + QLOG_ERROR() << filename << "contains a '+tweakers' field entry that's not a string"; + return out; + } + out.addTweakers.append(tweakerVal.toString()); + } + } + if (root.contains("-tweakers")) + { + QJsonValue tweakersVal = root.value("-tweakers"); + if (!tweakersVal.isArray()) + { + QLOG_ERROR() << filename << "contains a '-tweakers' field, but it's not an array"; + return out; + } + out.shouldOverwriteTweakers = true; + QJsonArray tweakers = root.value("-tweakers").toArray(); + for (auto tweakerVal : tweakers) + { + if (!tweakerVal.isString()) + { + QLOG_ERROR() << filename << "contains a '-tweakers' field entry that's not a string"; + return out; + } + out.removeTweakers.append(tweakerVal.toString()); + } + } + + if (root.contains("libraries")) + { + out.shouldOverwriteLibs = true; + QJsonValue librariesVal = root.value("libraries"); + if (!librariesVal.isArray()) + { + QLOG_ERROR() << filename + << "contains a 'libraries' field, but its not an array"; + return out; + } + QJsonArray librariesArray = librariesVal.toArray(); + for (auto libVal : librariesArray) + { + if (!libVal.isObject()) + { + QLOG_ERROR() << filename << "contains a library that's not an object"; + return out; + } + QJsonObject libObj = libVal.toObject(); + bool error; + Library lib = fromLibraryJson(libObj, filename, error); + if (error) + { + QLOG_ERROR() << "Error while reading a library entry in" << filename; + return out; + } + out.overwriteLibs.append(lib); + } + } + if (root.contains("+libraries")) + { + QJsonValue librariesVal = root.value("+libraries"); + if (!librariesVal.isArray()) + { + QLOG_ERROR() << filename + << "contains a '+libraries' field, but its not an array"; + return out; + } + QJsonArray librariesArray = librariesVal.toArray(); + for (auto libVal : librariesArray) + { + if (!libVal.isObject()) + { + QLOG_ERROR() << filename << "contains a library that's not an object"; + return out; + } + QJsonObject libObj = libVal.toObject(); + bool error; + Library lib = fromLibraryJson(libObj, filename, error); + if (error) + { + QLOG_ERROR() << "Error while reading a library entry in" << filename; + return out; + } + if (!libObj.contains("insert")) + { + QLOG_ERROR() << "Missing 'insert' field in '+libraries' field in" + << filename; + return out; + } + QJsonValue insertVal = libObj.value("insert"); + QString insertString; + { + if (insertVal.isString()) + { + insertString = insertVal.toString(); + } + else if (insertVal.isObject()) + { + QJsonObject insertObj = insertVal.toObject(); + if (insertObj.isEmpty()) + { + QLOG_ERROR() << "One library has an empty insert object in" + << filename; + return out; + } + insertString = insertObj.keys().first(); + lib.insertData = insertObj.value(insertString).toString(); + } + } + if (insertString == "apply") + { + lib.insertType = Library::Apply; + } + else if (insertString == "append") + { + lib.insertType = Library::Append; + } + else if (insertString == "prepend") + { + lib.insertType = Library::Prepend; + } + else if (insertString == "before") + { + lib.insertType = Library::InsertBefore; + } + else if (insertString == "after") + { + lib.insertType = Library::InsertAfter; + } + else if (insertString == "replace") + { + lib.insertType = Library::Replace; + } + else + { + QLOG_ERROR() << "A '+' library in" << filename + << "contains an invalid insert type"; + return out; + } + out.addLibs.append(lib); + } + } + if (root.contains("-libraries")) + { + QJsonValue librariesVal = root.value("-libraries"); + if (!librariesVal.isArray()) + { + QLOG_ERROR() << filename + << "contains a '-libraries' field, but its not an array"; + return out; + } + QJsonArray librariesArray = librariesVal.toArray(); + for (auto libVal : librariesArray) + { + if (!libVal.isObject()) + { + QLOG_ERROR() << filename << "contains a library that's not an object"; + return out; + } + QJsonObject libObj = libVal.toObject(); + if (!libObj.contains("name")) + { + QLOG_ERROR() << filename << "contains a library without a name"; + return out; + } + if (!libObj.value("name").isString()) + { + QLOG_ERROR() << filename + << "contains a library without a valid 'name' field"; + return out; + } + out.removeLibs.append(libObj.value("name").toString()); + } + } + + isError = false; + return out; + } + + static std::shared_ptr createLibrary(const Library &lib) + { + std::shared_ptr out(new OneSixLibrary(lib.name)); + out->setBaseUrl(lib.url); + out->setHint(lib.hint); + out->setAbsoluteUrl(lib.absoluteUrl); + out->extract_excludes = lib.excludes; + for (auto native : lib.natives) + { + out->addNative(native.first, native.second); + } + out->setRules(lib.rules); + out->finalize(); + return out; + } + int findLibrary(QList> haystack, const QString &needle) + { + for (int i = 0; i < haystack.size(); ++i) + { + if (QRegExp(needle, Qt::CaseSensitive, QRegExp::WildcardUnix) + .indexIn(haystack.at(i)->rawName()) != -1) + { + return i; + } + } + return -1; + } + void applyTo(OneSixVersion *version, bool &isError) + { + isError = true; + if (!id.isNull()) + { + version->id = id; + } + if (!mainClass.isNull()) + { + version->mainClass = mainClass; + } + if (!processArguments.isNull()) + { + version->processArguments = processArguments; + } + if (!type.isNull()) + { + version->type = type; + } + if (!releaseTime.isNull()) + { + version->releaseTime = releaseTime; + } + if (!time.isNull()) + { + version->time = time; + } + if (!assets.isNull()) + { + version->assets = assets; + } + if (minimumLauncherVersion >= 0) + { + version->minimumLauncherVersion = minimumLauncherVersion; + } + if (!overwriteMinecraftArguments.isNull()) + { + version->minecraftArguments = overwriteMinecraftArguments; + } + if (!addMinecraftArguments.isNull()) + { + version->minecraftArguments += addMinecraftArguments; + } + if (!removeMinecraftArguments.isNull()) + { + version->minecraftArguments.remove(removeMinecraftArguments); + } + if (shouldOverwriteTweakers) + { + version->tweakers = overwriteTweakers; + } + for (auto tweaker : addTweakers) + { + version->tweakers += tweaker; + } + for (auto tweaker : removeTweakers) + { + version->tweakers.removeAll(tweaker); + } + if (shouldOverwriteLibs) + { + version->libraries.clear(); + for (auto lib : overwriteLibs) + { + version->libraries.append(createLibrary(lib)); + } + } + for (auto lib : addLibs) + { + switch (lib.insertType) + { + case Library::Apply: + { + + int index = findLibrary(version->libraries, lib.name); + if (index >= 0) + { + auto library = version->libraries[index]; + if (!lib.url.isNull()) + { + library->setBaseUrl(lib.url); + } + if (!lib.hint.isNull()) + { + library->setHint(lib.hint); + } + if (!lib.absoluteUrl.isNull()) + { + library->setAbsoluteUrl(lib.absoluteUrl); + } + if (lib.applyExcludes) + { + library->extract_excludes = lib.excludes; + } + if (lib.applyNatives) + { + library->clearSuffixes(); + for (auto native : lib.natives) + { + library->addNative(native.first, native.second); + } + } + if (lib.applyRules) + { + library->setRules(lib.rules); + } + library->finalize(); + } + else + { + QLOG_WARN() << "Couldn't find" << lib.insertData << "(skipping)"; + } + break; + } + case Library::Append: + version->libraries.append(createLibrary(lib)); + break; + case Library::Prepend: + version->libraries.prepend(createLibrary(lib)); + break; + case Library::InsertBefore: + { + + int index = findLibrary(version->libraries, lib.insertData); + if (index >= 0) + { + version->libraries.insert(index, createLibrary(lib)); + } + else + { + QLOG_WARN() << "Couldn't find" << lib.insertData << "(skipping)"; + } + break; + } + case Library::InsertAfter: + { + + int index = findLibrary(version->libraries, lib.insertData); + if (index >= 0) + { + version->libraries.insert(index + 1, createLibrary(lib)); + } + else + { + QLOG_WARN() << "Couldn't find" << lib.insertData << "(skipping)"; + } + break; + } + case Library::Replace: + { + int index = findLibrary(version->libraries, lib.insertData); + if (index >= 0) + { + version->libraries.replace(index, createLibrary(lib)); + } + else + { + QLOG_WARN() << "Couldn't find" << lib.insertData << "(skipping)"; + } + break; + } + } + } + for (auto lib : removeLibs) + { + int index = findLibrary(version->libraries, lib); + if (index >= 0) + { + version->libraries.removeAt(index); + } + else + { + QLOG_WARN() << "Couldn't find" << lib << "(skipping)"; + } + } + + isError = false; + } +}; + OneSixVersionBuilder::OneSixVersionBuilder() { - } -bool OneSixVersionBuilder::build(OneSixVersion *version, OneSixInstance *instance, QWidget *widgetParent) +bool OneSixVersionBuilder::build(OneSixVersion *version, OneSixInstance *instance, + QWidget *widgetParent, const bool excludeCustom) { OneSixVersionBuilder builder; builder.m_version = version; builder.m_instance = instance; builder.m_widgetParent = widgetParent; - return builder.build(); + return builder.build(excludeCustom); } bool OneSixVersionBuilder::read(OneSixVersion *version, const QJsonObject &obj) @@ -54,7 +696,7 @@ bool OneSixVersionBuilder::read(OneSixVersion *version, const QJsonObject &obj) return builder.read(obj); } -bool OneSixVersionBuilder::build() +bool OneSixVersionBuilder::build(const bool excludeCustom) { m_version->clear(); @@ -66,13 +708,20 @@ bool OneSixVersionBuilder::build() // version.json { QLOG_INFO() << "Reading version.json"; - QJsonObject obj; - if (!read(QFileInfo(root.absoluteFilePath("version.json")), &obj)) + VersionFile file; + if (!read(QFileInfo(root.absoluteFilePath("version.json")), false, &file)) { return false; } - if (!apply(obj)) + bool isError = false; + file.applyTo(m_version, isError); + if (isError) { + QMessageBox::critical( + m_widgetParent, QObject::tr("Error"), + QObject::tr( + "Error while applying %1. Please check MultiMC-0.log for more info.") + .arg(root.absoluteFilePath("version.json"))); return false; } } @@ -81,49 +730,87 @@ bool OneSixVersionBuilder::build() { // load all, put into map for ordering, apply in the right order - QMap objects; + QMap> files; for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files)) { QLOG_INFO() << "Reading" << info.fileName(); - QJsonObject obj; - if (!read(info, &obj)) + VersionFile file; + if (!read(info, true, &file)) { return false; } - if (!obj.contains("order") || !obj.value("order").isDouble()) - { - QMessageBox::critical(m_widgetParent, QObject::tr("Error"), QObject::tr("Missing or invalid 'order' in %1").arg(info.absoluteFilePath())); - return false; - } - objects.insert(obj.value("order").toDouble(), obj); + files.insert(file.order, qMakePair(info.fileName(), file)); } - for (auto object : objects.values()) + for (auto order : files.keys()) { - qDebug() << "Applying object with order" << objects.key(object); - if (!apply(object)) + QLOG_DEBUG() << "Applying file with order" << order; + auto filePair = files[order]; + bool isError = false; + filePair.second.applyTo(m_version, isError); + if (isError) { + QMessageBox::critical( + m_widgetParent, QObject::tr("Error"), + QObject::tr( + "Error while applying %1. Please check MultiMC-0.log for more info.") + .arg(filePair.first)); return false; } } } // custom.json + if (!excludeCustom) { if (QFile::exists(root.absoluteFilePath("custom.json"))) { QLOG_INFO() << "Reading custom.json"; - QJsonObject obj; - if (!read(QFileInfo(root.absoluteFilePath("custom.json")), &obj)) + VersionFile file; + if (!read(QFileInfo(root.absoluteFilePath("custom.json")), false, &file)) { return false; } - if (!apply(obj)) + bool isError = false; + file.applyTo(m_version, isError); + if (isError) { + QMessageBox::critical( + m_widgetParent, QObject::tr("Error"), + QObject::tr( + "Error while applying %1. Please check MultiMC-0.log for more info.") + .arg(root.absoluteFilePath("custom.json"))); return false; } } } + // some final touches + { + if (m_version->assets.isEmpty()) + { + m_version->assets = "legacy"; + } + if (m_version->minecraftArguments.isEmpty()) + { + QString toCompare = m_version->processArguments.toLower(); + if (toCompare == "legacy") + { + m_version->minecraftArguments = " ${auth_player_name} ${auth_session}"; + } + else if (toCompare == "username_session") + { + m_version->minecraftArguments = + "--username ${auth_player_name} --session ${auth_session}"; + } + else if (toCompare == "username_session_version") + { + m_version->minecraftArguments = "--username ${auth_player_name} " + "--session ${auth_session} " + "--version ${profile_name}"; + } + } + } + return true; } @@ -131,316 +818,57 @@ bool OneSixVersionBuilder::read(const QJsonObject &obj) { m_version->clear(); - return apply(obj); -} - -void applyString(const QJsonObject &obj, const QString &key, QString &out, const bool onlyOverride = true) -{ - if (obj.contains(key) && obj.value(key).isString()) + bool isError = false; + VersionFile file = VersionFile::fromJson(QJsonDocument(obj), QString(), false, isError); + if (isError) { - out = obj.value(key).toString(); + QMessageBox::critical( + m_widgetParent, QObject::tr("Error"), + QObject::tr("Error while reading. Please check MultiMC-0.log for more info.")); + return false; } - else if (!onlyOverride) + file.applyTo(m_version, isError); + if (isError) { - if (obj.contains("+" + key) && obj.value("+" + key).isString()) - { - out += obj.value("+" + key).toString(); - } - else if (obj.contains("-" + key) && obj.value("-" + key).isString()) - { - out.remove(obj.value("-" + key).toString()); - } - } -} -void applyString(const QJsonObject &obj, const QString &key, std::shared_ptr lib, void(OneSixLibrary::*func)(const QString &val)) -{ - if (obj.contains(key) && obj.value(key).isString()) - { - (lib.get()->*func)(obj.value(key).toString()); - } -} -bool OneSixVersionBuilder::apply(const QJsonObject &object) -{ - applyString(object, "id", m_version->id); - applyString(object, "mainClass", m_version->mainClass); - applyString(object, "minecraftArguments", m_version->minecraftArguments, false); - applyString(object, "processArguments", m_version->processArguments, false); - if (m_version->minecraftArguments.isEmpty()) - { - const QString toCompare = m_version->processArguments.toLower(); - if (toCompare == "legacy") - { - m_version->minecraftArguments = " ${auth_player_name} ${auth_session}"; - } - else if (toCompare == "username_session") - { - m_version->minecraftArguments = "--username ${auth_player_name} --session ${auth_session}"; - } - else if (toCompare == "username_session_version") - { - m_version->minecraftArguments = "--username ${auth_player_name} --session ${auth_session} --version ${profile_name}"; - } - } - applyString(object, "type", m_version->type); - applyString(object, "releaseTime", m_version->releaseTime); - applyString(object, "time", m_version->time); - applyString(object, "assets", m_version->assets); - { - if (m_version->assets.isEmpty()) - { - m_version->assets = "legacy"; - } - } - if (object.contains("minimumLauncherVersion")) - { - auto minLauncherVersionVal = object.value("minimumLauncherVersion"); - if (minLauncherVersionVal.isDouble()) - { - m_version->minimumLauncherVersion = minLauncherVersionVal.toDouble(); - } - } - - // libraries - if (object.contains("libraries")) - { - m_version->libraries.clear(); - auto librariesValue = object.value("libraries"); - if (!librariesValue.isArray()) - { - QMessageBox::critical(m_widgetParent, QObject::tr("Error"), QObject::tr("One json files contains a libraries field, but it's not an array")); - return false; - } - auto array = librariesValue.toArray(); - for (auto libVal : array) - { - if (libVal.isObject()) - { - if (!applyLibrary(libVal.toObject(), Override)) - { - return false; - } - } - - } - } - - // +libraries - if (object.contains("+libraries")) - { - auto librariesValue = object.value("+libraries"); - if (!librariesValue.isArray()) - { - QMessageBox::critical(m_widgetParent, QObject::tr("Error"), QObject::tr("One json files contains a libraries field, but it's not an array")); - return false; - } - for (auto libVal : librariesValue.toArray()) - { - if (libVal.isObject()) - { - applyLibrary(libVal.toObject(), Add); - } - - } - } - - // -libraries - if (object.contains("-libraries")) - { - auto librariesValue = object.value("-libraries"); - if (!librariesValue.isArray()) - { - QMessageBox::critical(m_widgetParent, QObject::tr("Error"), QObject::tr("One json files contains a libraries field, but it's not an array")); - return false; - } - for (auto libVal : librariesValue.toArray()) - { - if (libVal.isObject()) - { - applyLibrary(libVal.toObject(), Remove); - } - - } + QMessageBox::critical( + m_widgetParent, QObject::tr("Error"), + QObject::tr("Error while applying. Please check MultiMC-0.log for more info.")); + return false; } return true; } -int findLibrary(QList > haystack, const QString &needle) -{ - for (int i = 0; i < haystack.size(); ++i) - { - if (QRegExp(needle, Qt::CaseSensitive, QRegExp::WildcardUnix).indexIn(haystack.at(i)->rawName()) != -1) - { - return i; - } - } - return -1; -} - -bool OneSixVersionBuilder::applyLibrary(const QJsonObject &lib, const OneSixVersionBuilder::Type type) -{ - // Library name - auto nameVal = lib.value("name"); - if (!nameVal.isString()) - { - return false; - } - auto name = nameVal.toString(); - - if (type == Remove) - { - int index = findLibrary(m_version->libraries, name); - if (index >= 0) - { - m_version->libraries.removeAt(index); - } - return true; - } - - if (type == Add && !lib.contains("insert")) - { - return false; - } - - std::shared_ptr library; - - if (lib.value("insert").toString() != "apply" && type == Add) - { - QMutableListIterator > it(m_version->libraries); - while (it.hasNext()) - { - if (it.next()->rawName() == name) - { - it.remove(); - } - } - } - - if (lib.value("insert").toString() == "apply" && type == Add) - { - library = m_version->libraries[findLibrary(m_version->libraries, name)]; - } - else - { - library.reset(new OneSixLibrary(nameVal.toString())); - } - - applyString(lib, "url", library, &OneSixLibrary::setBaseUrl); - applyString(lib, "MMC-hint", library, &OneSixLibrary::setHint); - applyString(lib, "MMC-absulute_url", library, &OneSixLibrary::setAbsoluteUrl); - applyString(lib, "MMC-absoluteUrl", library, &OneSixLibrary::setAbsoluteUrl); - - auto extractVal = lib.value("extract"); - if (extractVal.isObject()) - { - QStringList excludes; - auto extractObj = extractVal.toObject(); - auto excludesVal = extractObj.value("exclude"); - if (excludesVal.isArray()) - { - auto excludesList = excludesVal.toArray(); - for (auto excludeVal : excludesList) - { - if (excludeVal.isString()) - { - excludes.append(excludeVal.toString()); - } - } - library->extract_excludes = excludes; - } - } - - auto nativesVal = lib.value("natives"); - if (nativesVal.isObject()) - { - library->setIsNative(); - auto nativesObj = nativesVal.toObject(); - for (auto it = nativesObj.begin(); it != nativesObj.end(); ++it) - { - auto osType = OpSys_fromString(it.key()); - if (osType == Os_Other) - { - continue; - } - if (!it.value().isString()) - { - continue; - } - library->addNative(osType, it.value().toString()); - } - } - - if (lib.contains("rules")) - { - library->setRules(rulesFromJsonV4(lib)); - } - library->finalize(); - if (type == Override) - { - m_version->libraries.append(library); - } - else if (lib.value("insert").toString() != "apply") - { - if (lib.value("insert").toString() == "append") - { - m_version->libraries.append(library); - } - else if (lib.value("insert").toString() == "prepend") - { - m_version->libraries.prepend(library); - } - else if (lib.value("insert").isObject()) - { - QJsonObject insertObj = lib.value("insert").toObject(); - if (insertObj.isEmpty()) - { - QMessageBox::critical(m_widgetParent, QObject::tr("Error"), QObject::tr("'insert' object empty")); - return false; - } - const QString key = insertObj.keys().first(); - const QString value = insertObj.value(key).toString(); - const int index = findLibrary(m_version->libraries, value); - if (index >= 0) - { - if (key == "before") - { - m_version->libraries.insert(index, library); - } - else if (key == "after") - { - m_version->libraries.insert(index + 1, library); - } - else - { - QMessageBox::critical(m_widgetParent, QObject::tr("Error"), QObject::tr("Invalid value for 'insert': %1").arg(lib.value("insert").toString())); - return false; - } - } - } - else - { - QMessageBox::critical(m_widgetParent, QObject::tr("Error"), QObject::tr("Invalid value for 'insert': %1").arg(lib.value("insert").toString())); - return false; - } - } - return true; -} - -bool OneSixVersionBuilder::read(const QFileInfo &fileInfo, QJsonObject *out) +bool OneSixVersionBuilder::read(const QFileInfo &fileInfo, const bool requireOrder, + VersionFile *out) { QFile file(fileInfo.absoluteFilePath()); if (!file.open(QFile::ReadOnly)) { - QMessageBox::critical(m_widgetParent, QObject::tr("Error"), QObject::tr("Unable to open %1: %2").arg(file.fileName(), file.errorString())); + QMessageBox::critical( + m_widgetParent, QObject::tr("Error"), + QObject::tr("Unable to open %1: %2").arg(file.fileName(), file.errorString())); return false; } QJsonParseError error; QJsonDocument doc = QJsonDocument::fromJson(file.readAll(), &error); if (error.error != QJsonParseError::NoError) { - QMessageBox::critical(m_widgetParent, QObject::tr("Error"), QObject::tr("Unable to parse %1: %2 at %3").arg(file.fileName(), error.errorString()).arg(error.offset)); + QMessageBox::critical(m_widgetParent, QObject::tr("Error"), + QObject::tr("Unable to parse %1: %2 at %3") + .arg(file.fileName(), error.errorString()) + .arg(error.offset)); return false; } - *out = doc.object(); + bool isError = false; + *out = VersionFile::fromJson(doc, file.fileName(), requireOrder, isError); + if (isError) + { + QMessageBox::critical( + m_widgetParent, QObject::tr("Error"), + QObject::tr("Error while reading %1. Please check MultiMC-0.log for more info.") + .arg(file.fileName())); + ; + } return true; } diff --git a/logic/OneSixVersionBuilder.h b/logic/OneSixVersionBuilder.h index a3ba331c..ac8c13bf 100644 --- a/logic/OneSixVersionBuilder.h +++ b/logic/OneSixVersionBuilder.h @@ -22,12 +22,13 @@ class OneSixInstance; class QWidget; class QJsonObject; class QFileInfo; +class VersionFile; class OneSixVersionBuilder { OneSixVersionBuilder(); public: - static bool build(OneSixVersion *version, OneSixInstance *instance, QWidget *widgetParent); + static bool build(OneSixVersion *version, OneSixInstance *instance, QWidget *widgetParent, const bool excludeCustom); static bool read(OneSixVersion *version, const QJsonObject &obj); private: @@ -35,19 +36,8 @@ private: OneSixInstance *m_instance; QWidget *m_widgetParent; - enum Type - { - Override, - Add, - Remove - }; - - bool build(); + bool build(const bool excludeCustom); bool read(const QJsonObject &obj); - void clear(); - bool apply(const QJsonObject &object); - bool applyLibrary(const QJsonObject &lib, const Type type); - - bool read(const QFileInfo &fileInfo, QJsonObject *out); + bool read(const QFileInfo &fileInfo, const bool requireOrder, VersionFile *out); }; From 176783c8caacafd5d320c2fef7374335ee54796b Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Mon, 27 Jan 2014 20:17:29 +0100 Subject: [PATCH 09/13] Have the libraries tab show tweaker mods instead of libraries --- gui/dialogs/OneSixModEditDialog.ui | 10 ++++++ logic/LiteLoaderInstaller.cpp | 2 +- logic/OneSixVersion.cpp | 52 +++++++----------------------- logic/OneSixVersion.h | 2 -- 4 files changed, 23 insertions(+), 43 deletions(-) diff --git a/gui/dialogs/OneSixModEditDialog.ui b/gui/dialogs/OneSixModEditDialog.ui index d57d0f85..67642c23 100644 --- a/gui/dialogs/OneSixModEditDialog.ui +++ b/gui/dialogs/OneSixModEditDialog.ui @@ -35,6 +35,13 @@ + + + + Tweakers: + + + @@ -43,6 +50,9 @@ Qt::ScrollBarAlwaysOff + + false + diff --git a/logic/LiteLoaderInstaller.cpp b/logic/LiteLoaderInstaller.cpp index 1ce9d3f4..1c38fd5e 100644 --- a/logic/LiteLoaderInstaller.cpp +++ b/logic/LiteLoaderInstaller.cpp @@ -53,7 +53,7 @@ bool LiteLoaderInstaller::add(OneSixInstance *to) QJsonObject obj; obj.insert("mainClass", QString("net.minecraft.launchwrapper.Launch")); - obj.insert("+minecraftArguments", QString(" --tweakClass com.mumfrey.liteloader.launch.LiteLoaderTweaker")); + obj.insert("+tweakers", QJsonArray::fromStringList(QStringList() << "com.mumfrey.liteloader.launch.LiteLoaderTweaker")); obj.insert("order", 10); QJsonArray libraries; diff --git a/logic/OneSixVersion.cpp b/logic/OneSixVersion.cpp index 1b6bc9cb..1abd5114 100644 --- a/logic/OneSixVersion.cpp +++ b/logic/OneSixVersion.cpp @@ -27,11 +27,15 @@ OneSixVersion::OneSixVersion(OneSixInstance *instance, QObject *parent) bool OneSixVersion::reload(QWidget *widgetParent, const bool excludeCustom) { - return OneSixVersionBuilder::build(this, m_instance, widgetParent, excludeCustom); + beginResetModel(); + bool ret = OneSixVersionBuilder::build(this, m_instance, widgetParent, excludeCustom); + endResetModel(); + return ret; } void OneSixVersion::clear() { + beginResetModel(); id.clear(); time.clear(); releaseTime.clear(); @@ -43,6 +47,7 @@ void OneSixVersion::clear() mainClass.clear(); libraries.clear(); tweakers.clear(); + endResetModel(); } void OneSixVersion::dump() const @@ -109,21 +114,14 @@ QVariant OneSixVersion::data(const QModelIndex &index, int role) const int row = index.row(); int column = index.column(); - if (row < 0 || row >= libraries.size()) + if (row < 0 || row >= tweakers.size()) return QVariant(); if (role == Qt::DisplayRole) { - switch (column) + if (column == 0) { - case 0: - return libraries[row]->name(); - case 1: - return libraries[row]->type(); - case 2: - return libraries[row]->version(); - default: - return QVariant(); + return tweakers.at(row); } } return QVariant(); @@ -133,43 +131,17 @@ Qt::ItemFlags OneSixVersion::flags(const QModelIndex &index) const { if (!index.isValid()) return Qt::NoItemFlags; - int row = index.row(); - if (libraries[row]->isActive()) - { - return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemNeverHasChildren; - } - else - { - return Qt::ItemNeverHasChildren; - } - // return QAbstractListModel::flags(index); -} - -QVariant OneSixVersion::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (role != Qt::DisplayRole || orientation != Qt::Horizontal) - return QVariant(); - switch (section) - { - case 0: - return QString("Name"); - case 1: - return QString("Type"); - case 2: - return QString("Version"); - default: - return QString(); - } + return Qt::ItemIsSelectable | Qt::ItemIsEnabled; } int OneSixVersion::rowCount(const QModelIndex &parent) const { - return libraries.size(); + return tweakers.size(); } int OneSixVersion::columnCount(const QModelIndex &parent) const { - return 3; + return 1; } QDebug operator<<(QDebug &dbg, const OneSixVersion *version) diff --git a/logic/OneSixVersion.h b/logic/OneSixVersion.h index 767e05db..98a4b418 100644 --- a/logic/OneSixVersion.h +++ b/logic/OneSixVersion.h @@ -33,8 +33,6 @@ public: virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; - virtual QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const; virtual int columnCount(const QModelIndex &parent) const; virtual Qt::ItemFlags flags(const QModelIndex &index) const; From 986141b5035c99747c7e06cd447b8b4e27eb2b27 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Mon, 27 Jan 2014 22:23:07 +0100 Subject: [PATCH 10/13] Fix library ordering --- logic/ForgeInstaller.cpp | 8 ++------ logic/LiteLoaderInstaller.cpp | 2 +- logic/OneSixVersionBuilder.cpp | 36 +++++++++++++--------------------- 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/logic/ForgeInstaller.cpp b/logic/ForgeInstaller.cpp index c0340e95..8d2445ed 100644 --- a/logic/ForgeInstaller.cpp +++ b/logic/ForgeInstaller.cpp @@ -160,7 +160,7 @@ bool ForgeInstaller::add(OneSixInstance *to) equals = true; } // replace lib - libObj.insert("insert", QString("apply")); + libObj.insert("insert", QString("replace")); break; } if (equals) @@ -170,11 +170,7 @@ bool ForgeInstaller::add(OneSixInstance *to) if (!found) { // add lib - QJsonObject insertObj; - insertObj.insert( - "before", - to->getFullVersion()->libraries.at(sliding_insert_window + 1)->rawName()); - libObj.insert("insert", insertObj); + libObj.insert("insert", QString("prepend-if-not-exists")); sliding_insert_window++; } librariesPlus.prepend(libObj); diff --git a/logic/LiteLoaderInstaller.cpp b/logic/LiteLoaderInstaller.cpp index 1c38fd5e..f658f834 100644 --- a/logic/LiteLoaderInstaller.cpp +++ b/logic/LiteLoaderInstaller.cpp @@ -63,7 +63,7 @@ bool LiteLoaderInstaller::add(OneSixInstance *to) OneSixLibrary launchwrapperLib("net.minecraft:launchwrapper:" + m_launcherWrapperVersionMapping[to->intendedVersionId()]); launchwrapperLib.finalize(); QJsonObject lwLibObj = launchwrapperLib.toJson(); - lwLibObj.insert("insert", QString("prepend")); + lwLibObj.insert("insert", QString("prepend-if-not-exists")); libraries.append(lwLibObj); } diff --git a/logic/OneSixVersionBuilder.cpp b/logic/OneSixVersionBuilder.cpp index c031a94a..3b119b45 100644 --- a/logic/OneSixVersionBuilder.cpp +++ b/logic/OneSixVersionBuilder.cpp @@ -70,8 +70,8 @@ struct VersionFile Apply, Append, Prepend, - InsertBefore, - InsertAfter, + AppendIfNotExists, + PrependIfNotExists, Replace }; InsertType insertType; @@ -408,13 +408,13 @@ struct VersionFile { lib.insertType = Library::Prepend; } - else if (insertString == "before") + else if (insertString == "prepend-if-not-exists") { - lib.insertType = Library::InsertBefore; + lib.insertType = Library::PrependIfNotExists; } - else if (insertString == "after") + else if (insertString == "append-if-not-exists") { - lib.insertType = Library::InsertAfter; + lib.insertType = Library::PrependIfNotExists; } else if (insertString == "replace") { @@ -613,31 +613,23 @@ struct VersionFile case Library::Prepend: version->libraries.prepend(createLibrary(lib)); break; - case Library::InsertBefore: + case Library::AppendIfNotExists: { - int index = findLibrary(version->libraries, lib.insertData); - if (index >= 0) + int index = findLibrary(version->libraries, lib.name); + if (index < 0) { - version->libraries.insert(index, createLibrary(lib)); - } - else - { - QLOG_WARN() << "Couldn't find" << lib.insertData << "(skipping)"; + version->libraries.append(createLibrary(lib)); } break; } - case Library::InsertAfter: + case Library::PrependIfNotExists: { - int index = findLibrary(version->libraries, lib.insertData); - if (index >= 0) + int index = findLibrary(version->libraries, lib.name); + if (index < 0) { - version->libraries.insert(index + 1, createLibrary(lib)); - } - else - { - QLOG_WARN() << "Couldn't find" << lib.insertData << "(skipping)"; + version->libraries.prepend(createLibrary(lib)); } break; } From 556d8f0ec16e5030cfbfac9dc0fc2c796e829dcb Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Tue, 28 Jan 2014 07:39:43 +0100 Subject: [PATCH 11/13] custom.json overrides all. For user patching there now is instance.json --- logic/OneSixVersionBuilder.cpp | 119 ++++++++++++++++++++------------- 1 file changed, 71 insertions(+), 48 deletions(-) diff --git a/logic/OneSixVersionBuilder.cpp b/logic/OneSixVersionBuilder.cpp index 3b119b45..a8e7253b 100644 --- a/logic/OneSixVersionBuilder.cpp +++ b/logic/OneSixVersionBuilder.cpp @@ -695,13 +695,11 @@ bool OneSixVersionBuilder::build(const bool excludeCustom) QDir root(m_instance->instanceRoot()); QDir patches(root.absoluteFilePath("patches/")); - // version.json -> patches/*.json -> custom.json - - // version.json + if (QFile::exists(root.absoluteFilePath("custom.json"))) { - QLOG_INFO() << "Reading version.json"; + QLOG_INFO() << "Reading custom.json"; VersionFile file; - if (!read(QFileInfo(root.absoluteFilePath("version.json")), false, &file)) + if (!read(QFileInfo(root.absoluteFilePath("custom.json")), false, &file)) { return false; } @@ -713,52 +711,19 @@ bool OneSixVersionBuilder::build(const bool excludeCustom) m_widgetParent, QObject::tr("Error"), QObject::tr( "Error while applying %1. Please check MultiMC-0.log for more info.") - .arg(root.absoluteFilePath("version.json"))); + .arg(root.absoluteFilePath("custom.json"))); return false; } } - - // patches/ + else { - // load all, put into map for ordering, apply in the right order + // version.json -> patches/*.json -> instance.json - QMap> files; - for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files)) + // version.json { - QLOG_INFO() << "Reading" << info.fileName(); + QLOG_INFO() << "Reading version.json"; VersionFile file; - if (!read(info, true, &file)) - { - return false; - } - files.insert(file.order, qMakePair(info.fileName(), file)); - } - for (auto order : files.keys()) - { - QLOG_DEBUG() << "Applying file with order" << order; - auto filePair = files[order]; - bool isError = false; - filePair.second.applyTo(m_version, isError); - if (isError) - { - QMessageBox::critical( - m_widgetParent, QObject::tr("Error"), - QObject::tr( - "Error while applying %1. Please check MultiMC-0.log for more info.") - .arg(filePair.first)); - return false; - } - } - } - - // custom.json - if (!excludeCustom) - { - if (QFile::exists(root.absoluteFilePath("custom.json"))) - { - QLOG_INFO() << "Reading custom.json"; - VersionFile file; - if (!read(QFileInfo(root.absoluteFilePath("custom.json")), false, &file)) + if (!read(QFileInfo(root.absoluteFilePath("version.json")), false, &file)) { return false; } @@ -767,13 +732,71 @@ bool OneSixVersionBuilder::build(const bool excludeCustom) if (isError) { QMessageBox::critical( - m_widgetParent, QObject::tr("Error"), - QObject::tr( - "Error while applying %1. Please check MultiMC-0.log for more info.") - .arg(root.absoluteFilePath("custom.json"))); + m_widgetParent, QObject::tr("Error"), + QObject::tr( + "Error while applying %1. Please check MultiMC-0.log for more info.") + .arg(root.absoluteFilePath("version.json"))); return false; } } + + // patches/ + { + // load all, put into map for ordering, apply in the right order + + QMap> files; + for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files)) + { + QLOG_INFO() << "Reading" << info.fileName(); + VersionFile file; + if (!read(info, true, &file)) + { + return false; + } + files.insert(file.order, qMakePair(info.fileName(), file)); + } + for (auto order : files.keys()) + { + QLOG_DEBUG() << "Applying file with order" << order; + auto filePair = files[order]; + bool isError = false; + filePair.second.applyTo(m_version, isError); + if (isError) + { + QMessageBox::critical( + m_widgetParent, QObject::tr("Error"), + QObject::tr( + "Error while applying %1. Please check MultiMC-0.log for more info.") + .arg(filePair.first)); + return false; + } + } + } + + // instance.json + if (!excludeCustom) + { + if (QFile::exists(root.absoluteFilePath("instance.json"))) + { + QLOG_INFO() << "Reading instance.json"; + VersionFile file; + if (!read(QFileInfo(root.absoluteFilePath("instance.json")), false, &file)) + { + return false; + } + bool isError = false; + file.applyTo(m_version, isError); + if (isError) + { + QMessageBox::critical( + m_widgetParent, QObject::tr("Error"), + QObject::tr( + "Error while applying %1. Please check MultiMC-0.log for more info.") + .arg(root.absoluteFilePath("instance.json"))); + return false; + } + } + } } // some final touches From 4a9e213238234b03fdd994143726a3f75290fc26 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sat, 1 Feb 2014 14:52:21 +0100 Subject: [PATCH 12/13] Change the OneSix library view. It now shows a list of patches. --- gui/dialogs/OneSixModEditDialog.cpp | 63 +++++++++++++++++++++++++---- gui/dialogs/OneSixModEditDialog.h | 5 ++- gui/dialogs/OneSixModEditDialog.ui | 36 ++++------------- logic/ForgeInstaller.cpp | 6 +++ logic/ForgeInstaller.h | 1 + logic/LiteLoaderInstaller.cpp | 4 ++ logic/OneSixInstance.cpp | 5 ++- logic/OneSixVersion.cpp | 55 ++++++++++++++++++++++--- logic/OneSixVersion.h | 17 ++++++++ logic/OneSixVersionBuilder.cpp | 40 +++++++++++++++--- 10 files changed, 183 insertions(+), 49 deletions(-) diff --git a/gui/dialogs/OneSixModEditDialog.cpp b/gui/dialogs/OneSixModEditDialog.cpp index ad15311b..a34409f5 100644 --- a/gui/dialogs/OneSixModEditDialog.cpp +++ b/gui/dialogs/OneSixModEditDialog.cpp @@ -55,6 +55,8 @@ OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent) 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 @@ -93,10 +95,8 @@ OneSixModEditDialog::~OneSixModEditDialog() void OneSixModEditDialog::updateVersionControls() { - bool customVersion = m_inst->versionIsCustom(); ui->forgeBtn->setEnabled(true); ui->liteloaderBtn->setEnabled(LiteLoaderInstaller().canApply(m_inst)); - ui->customEditorBtn->setEnabled(customVersion); ui->mainClassEdit->setText(m_version->mainClass); } @@ -104,23 +104,52 @@ void OneSixModEditDialog::disableVersionControls() { ui->forgeBtn->setEnabled(false); ui->liteloaderBtn->setEnabled(false); - ui->customEditorBtn->setEnabled(false); + ui->reloadLibrariesBtn->setEnabled(false); + ui->removeLibraryBtn->setEnabled(false); ui->mainClassEdit->setText(""); } -void OneSixModEditDialog::on_customEditorBtn_clicked() +void OneSixModEditDialog::on_userEditorBtn_clicked() { - if (QDir(m_inst->instanceRoot()).exists("custom.json")) + if (QDir(m_inst->instanceRoot()).exists("user.json")) { - if (!MMC->openJsonEditor(m_inst->instanceRoot() + "/custom.json")) + if (!MMC->openJsonEditor(m_inst->instanceRoot() + "/user.json")) { - QMessageBox::warning(this, tr("Error"), tr("Unable to open custom.json, check the settings")); + QMessageBox::warning(this, tr("Error"), tr("Unable to open user.json, check the settings")); + } + } +} + +void OneSixModEditDialog::on_reloadLibrariesBtn_clicked() +{ + m_inst->reloadVersion(this); +} + +void OneSixModEditDialog::on_removeLibraryBtn_clicked() +{ + if (ui->libraryTreeView->currentIndex().isValid()) + { + if (!m_version->remove(ui->libraryTreeView->currentIndex().row())) + { + QMessageBox::critical(this, tr("Error"), tr("Couldn't remove file")); + } + else + { + m_inst->reloadVersion(this); } } } void OneSixModEditDialog::on_forgeBtn_clicked() { + if (QDir(m_inst->instanceRoot()).exists("custom.json")) + { + if (QMessageBox::question(this, tr("Revert?"), tr("This action will remove your custom.json. Continue?")) != QMessageBox::Yes) + { + return; + } + QDir(m_inst->instanceRoot()).remove("custom.json"); + } VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this); vselect.setFilter(1, m_inst->currentVersionId()); if (vselect.exec() && vselect.selectedVersion()) @@ -167,6 +196,14 @@ void OneSixModEditDialog::on_forgeBtn_clicked() void OneSixModEditDialog::on_liteloaderBtn_clicked() { + if (QDir(m_inst->instanceRoot()).exists("custom.json")) + { + if (QMessageBox::question(this, tr("Revert?"), tr("This action will remove your custom.json. Continue?")) != QMessageBox::Yes) + { + return; + } + QDir(m_inst->instanceRoot()).remove("custom.json"); + } LiteLoaderInstaller liteloader; if (!liteloader.canApply(m_inst)) { @@ -304,3 +341,15 @@ void OneSixModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previou 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 index 161604c9..7e759f48 100644 --- a/gui/dialogs/OneSixModEditDialog.h +++ b/gui/dialogs/OneSixModEditDialog.h @@ -45,7 +45,9 @@ slots: void on_buttonBox_rejected(); void on_forgeBtn_clicked(); void on_liteloaderBtn_clicked(); - void on_customEditorBtn_clicked(); + void on_userEditorBtn_clicked(); + void on_reloadLibrariesBtn_clicked(); + void on_removeLibraryBtn_clicked(); void updateVersionControls(); void disableVersionControls(); @@ -64,4 +66,5 @@ private: 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 index 67642c23..d90c6d93 100644 --- a/gui/dialogs/OneSixModEditDialog.ui +++ b/gui/dialogs/OneSixModEditDialog.ui @@ -26,7 +26,7 @@ - 1 + 0 @@ -35,13 +35,6 @@ - - - - Tweakers: - - - @@ -51,7 +44,7 @@ Qt::ScrollBarAlwaysOff - false + true @@ -96,37 +89,22 @@ - - QFrame::Sunken - Qt::Horizontal - - - false - - - Add new libraries - + - &Add + Reload - - false - - - Remove selected libraries - - &Remove + Remove @@ -138,9 +116,9 @@ - + - Open custom.json + Open user.json diff --git a/logic/ForgeInstaller.cpp b/logic/ForgeInstaller.cpp index 8d2445ed..c7160d6e 100644 --- a/logic/ForgeInstaller.cpp +++ b/logic/ForgeInstaller.cpp @@ -74,6 +74,7 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url) 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); @@ -204,6 +205,11 @@ bool ForgeInstaller::add(OneSixInstance *to) } } + obj.insert("name", QString("Forge")); + obj.insert("id", id()); + obj.insert("version", m_forgeVersionString); + obj.insert("mcVersion", to->intendedVersionId()); + QFile file(filename(to->instanceRoot())); if (!file.open(QFile::WriteOnly)) { diff --git a/logic/ForgeInstaller.h b/logic/ForgeInstaller.h index eb8ecd79..c5052092 100644 --- a/logic/ForgeInstaller.h +++ b/logic/ForgeInstaller.h @@ -37,5 +37,6 @@ private: QString internalPath; QString finalPath; QString realVersionId; + QString m_forgeVersionString; QString m_universal_url; }; diff --git a/logic/LiteLoaderInstaller.cpp b/logic/LiteLoaderInstaller.cpp index f658f834..48bbaeff 100644 --- a/logic/LiteLoaderInstaller.cpp +++ b/logic/LiteLoaderInstaller.cpp @@ -78,6 +78,10 @@ bool LiteLoaderInstaller::add(OneSixInstance *to) } obj.insert("+libraries", libraries); + obj.insert("name", QString("LiteLoader")); + obj.insert("id", id()); + obj.insert("version", to->intendedVersionId()); + obj.insert("mcVersion", to->intendedVersionId()); QFile file(filename(to->instanceRoot())); if (!file.open(QFile::WriteOnly)) diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index 19d5e112..88c40316 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -319,8 +319,9 @@ bool OneSixInstance::shouldUpdate() const bool OneSixInstance::versionIsCustom() { QDir patches(PathCombine(instanceRoot(), "patches/")); - return QFile::exists(PathCombine(instanceRoot(), "custom.json")) - || (patches.exists() && patches.count() >= 0); + return (patches.exists() && patches.count() >= 0) + || QFile::exists(PathCombine(instanceRoot(), "custom.json")) + || QFile::exists(PathCombine(instanceRoot(), "user.json")); } QString OneSixInstance::currentVersionId() const diff --git a/logic/OneSixVersion.cpp b/logic/OneSixVersion.cpp index 1abd5114..0b6d1986 100644 --- a/logic/OneSixVersion.cpp +++ b/logic/OneSixVersion.cpp @@ -16,6 +16,7 @@ #include "OneSixVersion.h" #include +#include #include "OneSixVersionBuilder.h" @@ -47,6 +48,7 @@ void OneSixVersion::clear() mainClass.clear(); libraries.clear(); tweakers.clear(); + versionFiles.clear(); endResetModel(); } @@ -70,6 +72,24 @@ void OneSixVersion::dump() const qDebug().nospace() << "\n)"; } +bool OneSixVersion::canRemove(const int index) const +{ + if (index < versionFiles.size()) + { + return versionFiles.at(index).id != "org.multimc.version.json"; + } + return false; +} + +bool OneSixVersion::remove(const int index) +{ + if (canRemove(index)) + { + return QFile::remove(versionFiles.at(index).filename); + } + return false; +} + QList > OneSixVersion::getActiveNormalLibs() { QList > output; @@ -114,14 +134,39 @@ QVariant OneSixVersion::data(const QModelIndex &index, int role) const int row = index.row(); int column = index.column(); - if (row < 0 || row >= tweakers.size()) + if (row < 0 || row >= versionFiles.size()) return QVariant(); if (role == Qt::DisplayRole) { - if (column == 0) + switch (column) { - return tweakers.at(row); + case 0: + return versionFiles.at(row).name; + case 1: + return versionFiles.at(row).version; + default: + return QVariant(); + } + } + return QVariant(); +} + +QVariant OneSixVersion::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal) + { + if (role == Qt::DisplayRole) + { + switch (section) + { + case 0: + return tr("Name"); + case 1: + return tr("Version"); + default: + return QVariant(); + } } } return QVariant(); @@ -136,12 +181,12 @@ Qt::ItemFlags OneSixVersion::flags(const QModelIndex &index) const int OneSixVersion::rowCount(const QModelIndex &parent) const { - return tweakers.size(); + return versionFiles.size(); } int OneSixVersion::columnCount(const QModelIndex &parent) const { - return 1; + return 2; } QDebug operator<<(QDebug &dbg, const OneSixVersion *version) diff --git a/logic/OneSixVersion.h b/logic/OneSixVersion.h index 98a4b418..d7a6684d 100644 --- a/logic/OneSixVersion.h +++ b/logic/OneSixVersion.h @@ -32,6 +32,7 @@ public: explicit OneSixVersion(OneSixInstance *instance, QObject *parent = 0); virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; virtual int columnCount(const QModelIndex &parent) const; virtual Qt::ItemFlags flags(const QModelIndex &index) const; @@ -41,6 +42,12 @@ public: void dump() const; + bool canRemove(const int index) const; + +public +slots: + bool remove(const int index); + public: QList> getActiveNormalLibs(); QList> getActiveNativeLibs(); @@ -109,6 +116,16 @@ public: */ // QList rules; + struct VersionFile + { + QString name; + QString id; + QString version; + QString mcVersion; + QString filename; + }; + QList versionFiles; + private: OneSixInstance *m_instance; }; diff --git a/logic/OneSixVersionBuilder.cpp b/logic/OneSixVersionBuilder.cpp index a8e7253b..08506d4b 100644 --- a/logic/OneSixVersionBuilder.cpp +++ b/logic/OneSixVersionBuilder.cpp @@ -34,6 +34,14 @@ struct VersionFile { int order; + QString name; + QString fileId; + QString version; + // TODO use the mcVersion to determine if a version file should be removed on update + QString mcVersion; + QString filename; + // TODO requirements + // QMap requirements; QString id; QString mainClass; QString overwriteMinecraftArguments; @@ -216,6 +224,12 @@ struct VersionFile } } + out.name = root.value("name").toString(); + out.fileId = root.value("id").toString(); + out.version = root.value("version").toString(); + out.mcVersion = root.value("mcVersion").toString(); + out.filename = filename; + auto readString = [root, filename](const QString &key, QString &variable) { if (root.contains(key)) @@ -661,6 +675,14 @@ struct VersionFile } } + OneSixVersion::VersionFile versionFile; + versionFile.name = name; + versionFile.id = fileId; + versionFile.version = this->version; + versionFile.mcVersion = mcVersion; + versionFile.filename = filename; + version->versionFiles.append(versionFile); + isError = false; } }; @@ -727,6 +749,10 @@ bool OneSixVersionBuilder::build(const bool excludeCustom) { return false; } + file.name = "version.json"; + file.fileId = "org.multimc.version.json"; + file.version = m_instance->intendedVersionId(); + file.mcVersion = m_instance->intendedVersionId(); bool isError = false; file.applyTo(m_version, isError); if (isError) @@ -773,17 +799,21 @@ bool OneSixVersionBuilder::build(const bool excludeCustom) } } - // instance.json + // user.json if (!excludeCustom) { - if (QFile::exists(root.absoluteFilePath("instance.json"))) + if (QFile::exists(root.absoluteFilePath("user.json"))) { - QLOG_INFO() << "Reading instance.json"; + QLOG_INFO() << "Reading user.json"; VersionFile file; - if (!read(QFileInfo(root.absoluteFilePath("instance.json")), false, &file)) + if (!read(QFileInfo(root.absoluteFilePath("user.json")), false, &file)) { return false; } + file.name = "user.json"; + file.fileId = "org.multimc.user.json"; + file.version = QString(); + file.mcVersion = QString(); bool isError = false; file.applyTo(m_version, isError); if (isError) @@ -792,7 +822,7 @@ bool OneSixVersionBuilder::build(const bool excludeCustom) m_widgetParent, QObject::tr("Error"), QObject::tr( "Error while applying %1. Please check MultiMC-0.log for more info.") - .arg(root.absoluteFilePath("instance.json"))); + .arg(root.absoluteFilePath("user.json"))); return false; } } From 8637cce4333aaf56a231d5fab866b0e770436783 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sat, 1 Feb 2014 16:26:38 +0100 Subject: [PATCH 13/13] Fix a bug --- gui/dialogs/OneSixModEditDialog.cpp | 15 ++++++++++++--- logic/ForgeInstaller.cpp | 2 +- logic/LiteLoaderInstaller.cpp | 2 +- logic/OneSixVersionBuilder.cpp | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/gui/dialogs/OneSixModEditDialog.cpp b/gui/dialogs/OneSixModEditDialog.cpp index a34409f5..ebd685e8 100644 --- a/gui/dialogs/OneSixModEditDialog.cpp +++ b/gui/dialogs/OneSixModEditDialog.cpp @@ -111,12 +111,21 @@ void OneSixModEditDialog::disableVersionControls() void OneSixModEditDialog::on_userEditorBtn_clicked() { - if (QDir(m_inst->instanceRoot()).exists("user.json")) + QDir root(m_inst->instanceRoot()); + if (!root.exists("user.json")) { - if (!MMC->openJsonEditor(m_inst->instanceRoot() + "/user.json")) + QFile file(root.absoluteFilePath("user.json")); + if (!file.open(QFile::WriteOnly)) { - QMessageBox::warning(this, tr("Error"), tr("Unable to open user.json, check the settings")); + QMessageBox::critical(this, tr("Error"), tr("Couldn't write a skeletion user.json file: %1").arg(file.errorString())); + return; } + file.write("{\n}"); + file.close(); + } + if (!MMC->openJsonEditor(root.absoluteFilePath("user.json"))) + { + QMessageBox::warning(this, tr("Error"), tr("Unable to open user.json, check the settings")); } } diff --git a/logic/ForgeInstaller.cpp b/logic/ForgeInstaller.cpp index c7160d6e..47c42694 100644 --- a/logic/ForgeInstaller.cpp +++ b/logic/ForgeInstaller.cpp @@ -206,7 +206,7 @@ bool ForgeInstaller::add(OneSixInstance *to) } obj.insert("name", QString("Forge")); - obj.insert("id", id()); + obj.insert("fileId", id()); obj.insert("version", m_forgeVersionString); obj.insert("mcVersion", to->intendedVersionId()); diff --git a/logic/LiteLoaderInstaller.cpp b/logic/LiteLoaderInstaller.cpp index 48bbaeff..60a43d49 100644 --- a/logic/LiteLoaderInstaller.cpp +++ b/logic/LiteLoaderInstaller.cpp @@ -79,7 +79,7 @@ bool LiteLoaderInstaller::add(OneSixInstance *to) obj.insert("+libraries", libraries); obj.insert("name", QString("LiteLoader")); - obj.insert("id", id()); + obj.insert("fileId", id()); obj.insert("version", to->intendedVersionId()); obj.insert("mcVersion", to->intendedVersionId()); diff --git a/logic/OneSixVersionBuilder.cpp b/logic/OneSixVersionBuilder.cpp index 08506d4b..a541766b 100644 --- a/logic/OneSixVersionBuilder.cpp +++ b/logic/OneSixVersionBuilder.cpp @@ -225,7 +225,7 @@ struct VersionFile } out.name = root.value("name").toString(); - out.fileId = root.value("id").toString(); + out.fileId = root.value("fileId").toString(); out.version = root.value("version").toString(); out.mcVersion = root.value("mcVersion").toString(); out.filename = filename;