From 6bea4ec988b7caeac63353fb9d2a354f2fd47dad Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 8 Sep 2013 02:15:20 +0200 Subject: Use HttpMetaCache to minimize network use. --- logic/LegacyUpdate.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'logic/LegacyUpdate.cpp') diff --git a/logic/LegacyUpdate.cpp b/logic/LegacyUpdate.cpp index 626ad1e0..c75a0011 100644 --- a/logic/LegacyUpdate.cpp +++ b/logic/LegacyUpdate.cpp @@ -227,7 +227,9 @@ void LegacyUpdate::jarStart() QString intended_version_id = inst->intendedVersionId(); urlstr += intended_version_id + "/" + intended_version_id + ".jar"; - legacyDownloadJob.reset(new DownloadJob(QUrl(urlstr), inst->defaultBaseJar())); + auto dljob = new DownloadJob("Minecraft.jar for version " + intended_version_id); + dljob->add(QUrl(urlstr), inst->defaultBaseJar()); + legacyDownloadJob.reset(); connect(legacyDownloadJob.data(), SIGNAL(finished()), SLOT(jarFinished())); connect(legacyDownloadJob.data(), SIGNAL(failed()), SLOT(jarFailed())); connect(legacyDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); -- cgit From cffdc4e045d4e72376d83c30ad063c290b071d62 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 8 Sep 2013 19:35:36 +0200 Subject: Fix legacy instance update segfault --- logic/LegacyUpdate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'logic/LegacyUpdate.cpp') diff --git a/logic/LegacyUpdate.cpp b/logic/LegacyUpdate.cpp index c75a0011..7bf12faa 100644 --- a/logic/LegacyUpdate.cpp +++ b/logic/LegacyUpdate.cpp @@ -229,7 +229,7 @@ void LegacyUpdate::jarStart() auto dljob = new DownloadJob("Minecraft.jar for version " + intended_version_id); dljob->add(QUrl(urlstr), inst->defaultBaseJar()); - legacyDownloadJob.reset(); + legacyDownloadJob.reset(dljob); connect(legacyDownloadJob.data(), SIGNAL(finished()), SLOT(jarFinished())); connect(legacyDownloadJob.data(), SIGNAL(failed()), SLOT(jarFailed())); connect(legacyDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); -- cgit From 8062b73074b8e3c94fd97b77b05e7dbb61205d41 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 8 Sep 2013 20:16:38 +0200 Subject: Fix one more legacy update bug --- logic/LegacyUpdate.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'logic/LegacyUpdate.cpp') diff --git a/logic/LegacyUpdate.cpp b/logic/LegacyUpdate.cpp index 7bf12faa..b8e179a5 100644 --- a/logic/LegacyUpdate.cpp +++ b/logic/LegacyUpdate.cpp @@ -230,9 +230,9 @@ void LegacyUpdate::jarStart() auto dljob = new DownloadJob("Minecraft.jar for version " + intended_version_id); dljob->add(QUrl(urlstr), inst->defaultBaseJar()); legacyDownloadJob.reset(dljob); - connect(legacyDownloadJob.data(), SIGNAL(finished()), SLOT(jarFinished())); - connect(legacyDownloadJob.data(), SIGNAL(failed()), SLOT(jarFailed())); - connect(legacyDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); + connect(dljob, SIGNAL(succeeded()), SLOT(jarFinished())); + connect(dljob, SIGNAL(failed()), SLOT(jarFailed())); + connect(dljob, SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); legacyDownloadJob->start(); } -- cgit From d38b90530b3ba3a49c4eb072eb344ae2b0836913 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Mon, 16 Sep 2013 00:54:39 +0200 Subject: Forge version list implementation. Needs integration and testing. --- CMakeLists.txt | 18 +++- MultiMC.cpp | 45 ++++++++ MultiMC.h | 13 +++ gui/ModListView.cpp | 3 +- gui/OneSixModEditDialog.cpp | 12 ++- gui/OneSixModEditDialog.h | 1 + gui/OneSixModEditDialog.ui | 135 +++++++++++++++++++---- gui/lwjglselectdialog.cpp | 16 +-- gui/mainwindow.cpp | 12 +-- gui/newinstancedialog.cpp | 14 +-- gui/newinstancedialog.h | 8 +- gui/versionselectdialog.cpp | 14 +-- gui/versionselectdialog.h | 10 +- logic/BaseInstance.cpp | 5 +- logic/BaseInstance.h | 4 +- logic/BaseVersion.h | 45 ++++++++ logic/EnabledItemFilter.cpp | 30 ++++++ logic/EnabledItemFilter.h | 16 +++ logic/InstanceFactory.cpp | 10 +- logic/InstanceFactory.h | 6 +- logic/InstanceVersion.h | 68 ------------ logic/LegacyUpdate.cpp | 8 +- logic/MinecraftVersion.h | 29 +++-- logic/OneSixInstance.cpp | 21 +++- logic/OneSixInstance.h | 2 + logic/OneSixLibrary.cpp | 13 ++- logic/OneSixLibrary.h | 22 ++++ logic/OneSixUpdate.cpp | 47 +++++--- logic/OneSixVersion.cpp | 71 +++++++++++++ logic/OneSixVersion.h | 11 +- logic/lists/BaseVersionList.cpp | 123 +++++++++++++++++++++ logic/lists/BaseVersionList.h | 121 +++++++++++++++++++++ logic/lists/ForgeVersionList.cpp | 200 +++++++++++++++++++++++++++++++++++ logic/lists/ForgeVersionList.h | 98 +++++++++++++++++ logic/lists/InstVersionList.cpp | 129 ---------------------- logic/lists/InstVersionList.h | 121 --------------------- logic/lists/LwjglVersionList.cpp | 8 -- logic/lists/LwjglVersionList.h | 2 - logic/lists/MinecraftVersionList.cpp | 34 ++---- logic/lists/MinecraftVersionList.h | 21 ++-- 40 files changed, 1091 insertions(+), 475 deletions(-) create mode 100644 logic/BaseVersion.h create mode 100644 logic/EnabledItemFilter.cpp create mode 100644 logic/EnabledItemFilter.h delete mode 100644 logic/InstanceVersion.h create mode 100644 logic/lists/BaseVersionList.cpp create mode 100644 logic/lists/BaseVersionList.h create mode 100644 logic/lists/ForgeVersionList.cpp create mode 100644 logic/lists/ForgeVersionList.h delete mode 100644 logic/lists/InstVersionList.cpp delete mode 100644 logic/lists/InstVersionList.h (limited to 'logic/LegacyUpdate.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index feb46278..d4f0cbbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -172,7 +172,7 @@ gui/LabeledToolButton.h gui/EditNotesDialog.h # Base classes and infrastructure -logic/InstanceVersion.h +logic/BaseVersion.h logic/MinecraftVersion.h logic/InstanceFactory.h logic/BaseUpdate.h @@ -216,10 +216,14 @@ logic/NostalgiaInstance.h # Lists logic/lists/InstanceList.h -logic/lists/InstVersionList.h +logic/lists/IconList.h +logic/lists/BaseVersionList.h logic/lists/MinecraftVersionList.h logic/lists/LwjglVersionList.h -logic/lists/IconList.h +logic/lists/ForgeVersionList.h + +# misc model/view +logic/EnabledItemFilter.h # Tasks logic/tasks/Task.h @@ -288,10 +292,14 @@ logic/NostalgiaInstance.cpp # Lists logic/lists/InstanceList.cpp -logic/lists/InstVersionList.cpp +logic/lists/IconList.cpp +logic/lists/BaseVersionList.cpp logic/lists/MinecraftVersionList.cpp logic/lists/LwjglVersionList.cpp -logic/lists/IconList.cpp +logic/lists/ForgeVersionList.cpp + +# misc model/view +logic/EnabledItemFilter.cpp # Tasks logic/tasks/Task.cpp diff --git a/MultiMC.cpp b/MultiMC.cpp index b49773a1..08e5ed25 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -9,6 +9,10 @@ #include "gui/mainwindow.h" #include "logic/lists/InstanceList.h" #include "logic/lists/IconList.h" +#include "logic/lists/LwjglVersionList.h" +#include "logic/lists/MinecraftVersionList.h" +#include "logic/lists/ForgeVersionList.h" + #include "logic/InstanceLauncher.h" #include "logic/net/HttpMetaCache.h" @@ -158,6 +162,21 @@ MultiMC::~MultiMC() delete m_qt_translator; m_qt_translator = nullptr; } + if(m_icons) + { + delete m_icons; + m_icons = nullptr; + } + if(m_lwjgllist) + { + delete m_lwjgllist; + m_lwjgllist = nullptr; + } + if(m_minecraftlist) + { + delete m_minecraftlist; + m_minecraftlist = nullptr; + } delete m_settings; delete m_metacache; } @@ -276,6 +295,32 @@ IconList* MultiMC::icons() return m_icons; } +LWJGLVersionList* MultiMC::lwjgllist() +{ + if ( !m_lwjgllist ) + { + m_lwjgllist = new LWJGLVersionList(); + } + return m_lwjgllist; +} +ForgeVersionList* MultiMC::forgelist() +{ + if ( !m_forgelist ) + { + m_forgelist = new ForgeVersionList(); + } + return m_forgelist; +} + +MinecraftVersionList* MultiMC::minecraftlist() +{ + if ( !m_minecraftlist ) + { + m_minecraftlist = new MinecraftVersionList(); + } + return m_minecraftlist; +} + int main(int argc, char *argv[]) { diff --git a/MultiMC.h b/MultiMC.h index 216c670b..d3e92584 100644 --- a/MultiMC.h +++ b/MultiMC.h @@ -4,11 +4,14 @@ #include "MultiMCVersion.h" #include "config.h" +class MinecraftVersionList; +class LWJGLVersionList; class HttpMetaCache; class SettingsObject; class InstanceList; class IconList; class QNetworkAccessManager; +class ForgeVersionList; #if defined(MMC) #undef MMC @@ -61,6 +64,12 @@ public: { return m_metacache; } + + LWJGLVersionList * lwjgllist(); + + ForgeVersionList * forgelist(); + + MinecraftVersionList * minecraftlist(); private: void initGlobalSettings(); @@ -76,5 +85,9 @@ private: QNetworkAccessManager * m_qnam = nullptr; HttpMetaCache * m_metacache = nullptr; Status m_status = MultiMC::Failed; + LWJGLVersionList * m_lwjgllist = nullptr; + ForgeVersionList * m_forgelist = nullptr; + MinecraftVersionList * m_minecraftlist = nullptr; + MultiMCVersion m_version = {VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION, VERSION_BUILD}; }; \ No newline at end of file diff --git a/gui/ModListView.cpp b/gui/ModListView.cpp index 34bd4af2..1d0e834c 100644 --- a/gui/ModListView.cpp +++ b/gui/ModListView.cpp @@ -30,6 +30,7 @@ void ModListView::setModel ( QAbstractItemModel* model ) auto head = header(); head->setStretchLastSection(false); head->setSectionResizeMode(0, QHeaderView::Stretch); - head->setSectionResizeMode(1, QHeaderView::ResizeToContents); + for(int i = 1; i < head->count(); i++) + head->setSectionResizeMode(i, QHeaderView::ResizeToContents); dropIndicatorPosition(); } diff --git a/gui/OneSixModEditDialog.cpp b/gui/OneSixModEditDialog.cpp index ab6ad5f0..f778127f 100644 --- a/gui/OneSixModEditDialog.cpp +++ b/gui/OneSixModEditDialog.cpp @@ -22,6 +22,8 @@ #include #include #include +#include "logic/OneSixVersion.h" +#include OneSixModEditDialog::OneSixModEditDialog(OneSixInstance * inst, QWidget *parent): m_inst(inst), @@ -29,9 +31,15 @@ OneSixModEditDialog::OneSixModEditDialog(OneSixInstance * inst, QWidget *parent) ui(new Ui::OneSixModEditDialog) { ui->setupUi(this); - //TODO: libraries! + //libraries! { - // yeah... here be the real dragons. + m_version = m_inst->getFullVersion(); + + auto filter = new EnabledItemFilter(this); + filter->setActive(true); + filter->setSourceModel(m_version.data()); + ui->libraryTreeView->setModel(filter); + ui->libraryTreeView->installEventFilter( this ); } // Loader mods { diff --git a/gui/OneSixModEditDialog.h b/gui/OneSixModEditDialog.h index 3430bd26..c637df01 100644 --- a/gui/OneSixModEditDialog.h +++ b/gui/OneSixModEditDialog.h @@ -46,6 +46,7 @@ protected: bool resourcePackListFilter( QKeyEvent* ev ); private: Ui::OneSixModEditDialog *ui; + QSharedPointer m_version; QSharedPointer m_mods; QSharedPointer m_resourcepacks; OneSixInstance * m_inst; diff --git a/gui/OneSixModEditDialog.ui b/gui/OneSixModEditDialog.ui index 3feca726..bffcaed0 100644 --- a/gui/OneSixModEditDialog.ui +++ b/gui/OneSixModEditDialog.ui @@ -6,15 +6,15 @@ 0 0 - 543 - 423 + 555 + 463 Dialog - - + + true @@ -28,26 +28,121 @@ 0 - - Qt::ElideNone - - - false - - Library + Version - - - Qt::ScrollBarAlwaysOn - - - Qt::ScrollBarAlwaysOff - - + + + + + Qt::ScrollBarAlwaysOn + + + Qt::ScrollBarAlwaysOff + + + + + + + + + Main Class: + + + + + + + + + + + + + + + + Replace any current custom version with Minecraft Forge + + + Install Forge + + + + + + + Create an customized copy of the base version + + + Customize + + + + + + + Revert to original base version + + + Revert + + + + + + + QFrame::Sunken + + + Qt::Horizontal + + + + + + + false + + + Add new libraries + + + &Add + + + + + + + false + + + Remove selected libraries + + + &Remove + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + @@ -163,7 +258,7 @@ - + false diff --git a/gui/lwjglselectdialog.cpp b/gui/lwjglselectdialog.cpp index c3215b7b..7c424a6c 100644 --- a/gui/lwjglselectdialog.cpp +++ b/gui/lwjglselectdialog.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "MultiMC.h" #include "lwjglselectdialog.h" #include "ui_lwjglselectdialog.h" @@ -24,11 +25,12 @@ LWJGLSelectDialog::LWJGLSelectDialog(QWidget *parent) : { ui->setupUi(this); ui->labelStatus->setVisible(false); - ui->lwjglListView->setModel(&LWJGLVersionList::get()); + auto lwjgllist = MMC->lwjgllist(); + ui->lwjglListView->setModel(lwjgllist); - connect(&LWJGLVersionList::get(), SIGNAL(loadingStateUpdated(bool)), SLOT(loadingStateUpdated(bool))); - connect(&LWJGLVersionList::get(), SIGNAL(loadListFailed(QString)), SLOT(loadingFailed(QString))); - loadingStateUpdated(LWJGLVersionList::get().isLoading()); + connect(lwjgllist, SIGNAL(loadingStateUpdated(bool)), SLOT(loadingStateUpdated(bool))); + connect(lwjgllist, SIGNAL(loadListFailed(QString)), SLOT(loadingFailed(QString))); + loadingStateUpdated(lwjgllist->isLoading()); } LWJGLSelectDialog::~LWJGLSelectDialog() @@ -38,15 +40,15 @@ LWJGLSelectDialog::~LWJGLSelectDialog() QString LWJGLSelectDialog::selectedVersion() const { - return LWJGLVersionList::get().data( + return MMC->lwjgllist()->data( ui->lwjglListView->selectionModel()->currentIndex(), Qt::DisplayRole).toString(); } void LWJGLSelectDialog::on_refreshButton_clicked() { - if (!LWJGLVersionList::get().isLoading()) - LWJGLVersionList::get().loadList(); + if (!MMC->lwjgllist()->isLoading()) + MMC->lwjgllist()->loadList(); } void LWJGLSelectDialog::loadingStateUpdated(bool loading) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 747df047..241df383 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -154,14 +154,14 @@ MainWindow::MainWindow ( QWidget *parent ) // run the things that load and download other things... FIXME: this is NOT the place // FIXME: invisible actions in the background = NOPE. { - if (!MinecraftVersionList::getMainList().isLoaded()) + if (!MMC->minecraftlist()->isLoaded()) { - m_versionLoadTask = MinecraftVersionList::getMainList().getLoadTask(); + m_versionLoadTask = MMC->minecraftlist()->getLoadTask(); startTask(m_versionLoadTask); } - if (!LWJGLVersionList::get().isLoaded()) + if (!MMC->lwjgllist()->isLoaded()) { - LWJGLVersionList::get().loadList(); + MMC->lwjgllist()->loadList(); } assets_downloader = new OneSixAssets(); assets_downloader->start(); @@ -245,7 +245,7 @@ void MainWindow::instanceActivated ( QModelIndex index ) void MainWindow::on_actionAddInstance_triggered() { - if (!MinecraftVersionList::getMainList().isLoaded() && + if (!MMC->minecraftlist()->isLoaded() && m_versionLoadTask && m_versionLoadTask->isRunning()) { QEventLoop waitLoop; @@ -604,7 +604,7 @@ void MainWindow::on_actionChangeInstMCVersion_triggered() VersionSelectDialog vselect(m_selectedInstance->versionList(), this); if (vselect.exec() && vselect.selectedVersion()) { - m_selectedInstance->setIntendedVersionId(vselect.selectedVersion()->descriptor); + m_selectedInstance->setIntendedVersionId(vselect.selectedVersion()->descriptor()); } } diff --git a/gui/newinstancedialog.cpp b/gui/newinstancedialog.cpp index ac3bcd7d..af2b11c5 100644 --- a/gui/newinstancedialog.cpp +++ b/gui/newinstancedialog.cpp @@ -18,7 +18,7 @@ #include "ui_newinstancedialog.h" #include "logic/InstanceFactory.h" -#include "logic/InstanceVersion.h" +#include "logic/BaseVersion.h" #include "logic/lists/IconList.h" #include "logic/lists/MinecraftVersionList.h" #include "logic/tasks/Task.h" @@ -48,7 +48,7 @@ NewInstanceDialog::NewInstanceDialog(QWidget *parent) : taskDlg->exec(loadTask); } */ - setSelectedVersion(MinecraftVersionList::getMainList().getLatestStable()); + setSelectedVersion(MMC->minecraftlist()->getLatestStable()); InstIconKey = "infinity"; ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey)); } @@ -63,13 +63,13 @@ void NewInstanceDialog::updateDialogState() ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!instName().isEmpty() && m_selectedVersion); } -void NewInstanceDialog::setSelectedVersion(InstVersionPtr version) +void NewInstanceDialog::setSelectedVersion(BaseVersionPtr version) { m_selectedVersion = version; if (m_selectedVersion) { - ui->versionTextBox->setText(version->name); + ui->versionTextBox->setText(version->name()); } else { @@ -89,18 +89,18 @@ QString NewInstanceDialog::iconKey() const return InstIconKey; } -InstVersionPtr NewInstanceDialog::selectedVersion() const +BaseVersionPtr NewInstanceDialog::selectedVersion() const { return m_selectedVersion; } void NewInstanceDialog::on_btnChangeVersion_clicked() { - VersionSelectDialog vselect(&MinecraftVersionList::getMainList(), this); + VersionSelectDialog vselect(MMC->minecraftlist(), this); vselect.exec(); if (vselect.result() == QDialog::Accepted) { - InstVersionPtr version = vselect.selectedVersion(); + BaseVersionPtr version = vselect.selectedVersion(); if (version) setSelectedVersion(version); } diff --git a/gui/newinstancedialog.h b/gui/newinstancedialog.h index e8c57024..408cf757 100644 --- a/gui/newinstancedialog.h +++ b/gui/newinstancedialog.h @@ -17,7 +17,7 @@ #define NEWINSTANCEDIALOG_H #include -#include "logic/InstanceVersion.h" +#include "logic/BaseVersion.h" namespace Ui { class NewInstanceDialog; @@ -33,13 +33,13 @@ public: void updateDialogState(); - void setSelectedVersion(InstVersionPtr version); + void setSelectedVersion(BaseVersionPtr version); void loadVersionList(); QString instName() const; QString iconKey() const; - InstVersionPtr selectedVersion() const; + BaseVersionPtr selectedVersion() const; private slots: void on_btnChangeVersion_clicked(); @@ -49,7 +49,7 @@ private slots: private: Ui::NewInstanceDialog *ui; - InstVersionPtr m_selectedVersion; + BaseVersionPtr m_selectedVersion; QString InstIconKey; }; diff --git a/gui/versionselectdialog.cpp b/gui/versionselectdialog.cpp index 66d772b0..b14956fd 100644 --- a/gui/versionselectdialog.cpp +++ b/gui/versionselectdialog.cpp @@ -22,11 +22,11 @@ #include -#include -#include +#include +#include #include -VersionSelectDialog::VersionSelectDialog(InstVersionList *vlist, QWidget *parent) : +VersionSelectDialog::VersionSelectDialog(BaseVersionList *vlist, QWidget *parent) : QDialog(parent), ui(new Ui::VersionSelectDialog) { @@ -69,11 +69,11 @@ void VersionSelectDialog::loadList() taskDlg->exec(loadTask); } -InstVersionPtr VersionSelectDialog::selectedVersion() const +BaseVersionPtr VersionSelectDialog::selectedVersion() const { auto currentIndex = ui->listView->selectionModel()->currentIndex(); - auto variant = m_proxyModel->data(currentIndex, InstVersionList::VersionPointerRole); - return variant.value(); + auto variant = m_proxyModel->data(currentIndex, BaseVersionList::VersionPointerRole); + return variant.value(); } void VersionSelectDialog::on_refreshButton_clicked() @@ -83,7 +83,7 @@ void VersionSelectDialog::on_refreshButton_clicked() void VersionSelectDialog::updateFilterState() { - m_proxyModel->setFilterKeyColumn(InstVersionList::TypeColumn); + m_proxyModel->setFilterKeyColumn(BaseVersionList::TypeColumn); QStringList filteredTypes; if (!ui->filterSnapshotsCheckbox->isChecked()) diff --git a/gui/versionselectdialog.h b/gui/versionselectdialog.h index b864aee1..57e4d0df 100644 --- a/gui/versionselectdialog.h +++ b/gui/versionselectdialog.h @@ -19,9 +19,9 @@ #include #include -#include "logic/InstanceVersion.h" +#include "logic/BaseVersion.h" -class InstVersionList; +class BaseVersionList; namespace Ui { @@ -33,7 +33,7 @@ class VersionSelectDialog : public QDialog Q_OBJECT public: - explicit VersionSelectDialog(InstVersionList *vlist, QWidget *parent = 0); + explicit VersionSelectDialog(BaseVersionList *vlist, QWidget *parent = 0); ~VersionSelectDialog(); virtual int exec(); @@ -41,7 +41,7 @@ public: //! Starts a task that loads the list. void loadList(); - InstVersionPtr selectedVersion() const; + BaseVersionPtr selectedVersion() const; private slots: void on_refreshButton_clicked(); @@ -51,7 +51,7 @@ private slots: private: Ui::VersionSelectDialog *ui; - InstVersionList *m_vlist; + BaseVersionList *m_vlist; QSortFilterProxyModel *m_proxyModel; }; diff --git a/logic/BaseInstance.cpp b/logic/BaseInstance.cpp index e166449f..10bb4573 100644 --- a/logic/BaseInstance.cpp +++ b/logic/BaseInstance.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "MultiMC.h" #include "BaseInstance.h" #include "BaseInstance_p.h" @@ -131,9 +132,9 @@ InstanceList *BaseInstance::instList() const return NULL; } -InstVersionList *BaseInstance::versionList() const +BaseVersionList *BaseInstance::versionList() const { - return &MinecraftVersionList::getMainList(); + return MMC->minecraftlist(); } SettingsObject &BaseInstance::settings() const diff --git a/logic/BaseInstance.h b/logic/BaseInstance.h index cc9422be..fa317ba1 100644 --- a/logic/BaseInstance.h +++ b/logic/BaseInstance.h @@ -21,7 +21,7 @@ #include #include "inifile.h" -#include "lists/InstVersionList.h" +#include "lists/BaseVersionList.h" class QDialog; class BaseUpdate; @@ -134,7 +134,7 @@ public: * \brief Gets a pointer to this instance's version list. * \return A pointer to the available version list for this instance. */ - virtual InstVersionList *versionList() const; + virtual BaseVersionList *versionList() const; /*! * \brief Gets this instance's settings object. diff --git a/logic/BaseVersion.h b/logic/BaseVersion.h new file mode 100644 index 00000000..be717fee --- /dev/null +++ b/logic/BaseVersion.h @@ -0,0 +1,45 @@ +/* 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 + +/*! + * An abstract base class for versions. + */ +struct BaseVersion +{ + /*! + * A string used to identify this version in config files. + * This should be unique within the version list or shenanigans will occur. + */ + virtual QString descriptor() = 0; + + /*! + * The name of this version as it is displayed to the user. + * For example: "1.5.1" + */ + virtual QString name() = 0; + + /*! + * This should return a string that describes + * the kind of version this is (Stable, Beta, Snapshot, whatever) + */ + virtual QString typeString() const = 0; +}; + +typedef QSharedPointer BaseVersionPtr; + +Q_DECLARE_METATYPE( BaseVersionPtr ) \ No newline at end of file diff --git a/logic/EnabledItemFilter.cpp b/logic/EnabledItemFilter.cpp new file mode 100644 index 00000000..6ecd0271 --- /dev/null +++ b/logic/EnabledItemFilter.cpp @@ -0,0 +1,30 @@ +#include "EnabledItemFilter.h" + +EnabledItemFilter::EnabledItemFilter(QObject* parent) + :QSortFilterProxyModel(parent) +{ + +} + +void EnabledItemFilter::setActive(bool active) +{ + m_active = active; + invalidateFilter(); +} + +bool EnabledItemFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const +{ + if(!m_active) + return true; + QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); + if(sourceModel()->flags(index) & Qt::ItemIsEnabled) + { + return true; + } + return false; +} + +bool EnabledItemFilter::lessThan(const QModelIndex& left, const QModelIndex& right) const +{ + return QSortFilterProxyModel::lessThan(left, right); +} diff --git a/logic/EnabledItemFilter.h b/logic/EnabledItemFilter.h new file mode 100644 index 00000000..cb6d4041 --- /dev/null +++ b/logic/EnabledItemFilter.h @@ -0,0 +1,16 @@ +#pragma once +#include + +class EnabledItemFilter : public QSortFilterProxyModel +{ + Q_OBJECT +public: + EnabledItemFilter(QObject *parent = 0); + void setActive(bool active); + +protected: + bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; + bool lessThan(const QModelIndex &left, const QModelIndex &right) const; +private: + bool m_active = false; +}; \ No newline at end of file diff --git a/logic/InstanceFactory.cpp b/logic/InstanceFactory.cpp index f0630568..b5832ce5 100644 --- a/logic/InstanceFactory.cpp +++ b/logic/InstanceFactory.cpp @@ -22,7 +22,7 @@ #include "LegacyInstance.h" #include "OneSixInstance.h" #include "NostalgiaInstance.h" -#include "InstanceVersion.h" +#include "BaseVersion.h" #include "MinecraftVersion.h" #include "inifile.h" @@ -68,7 +68,7 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst } -InstanceFactory::InstCreateError InstanceFactory::createInstance( BaseInstance*& inst, InstVersionPtr version, const QString& instDir ) +InstanceFactory::InstCreateError InstanceFactory::createInstance( BaseInstance*& inst, BaseVersionPtr version, const QString& instDir ) { QDir rootDir(instDir); @@ -89,19 +89,19 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance( BaseInstance*& case MinecraftVersion::Legacy: m_settings->set("InstanceType", "Legacy"); inst = new LegacyInstance(instDir, m_settings, this); - inst->setIntendedVersionId(version->descriptor); + inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); break; case MinecraftVersion::OneSix: m_settings->set("InstanceType", "OneSix"); inst = new OneSixInstance(instDir, m_settings, this); - inst->setIntendedVersionId(version->descriptor); + inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); break; case MinecraftVersion::Nostalgia: m_settings->set("InstanceType", "Nostalgia"); inst = new NostalgiaInstance(instDir, m_settings, this); - inst->setIntendedVersionId(version->descriptor); + inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); break; default: diff --git a/logic/InstanceFactory.h b/logic/InstanceFactory.h index ed54f520..1c527749 100644 --- a/logic/InstanceFactory.h +++ b/logic/InstanceFactory.h @@ -19,9 +19,9 @@ #include #include -#include "InstanceVersion.h" +#include "BaseVersion.h" -class InstVersion; +class BaseVersion; class BaseInstance; /*! @@ -61,7 +61,7 @@ public: * - InstExists if the given instance directory is already an instance. * - CantCreateDir if the given instance directory cannot be created. */ - InstCreateError createInstance(BaseInstance *&inst, InstVersionPtr version, const QString &instDir); + InstCreateError createInstance(BaseInstance *&inst, BaseVersionPtr version, const QString &instDir); /*! * \brief Loads an instance from the given directory. diff --git a/logic/InstanceVersion.h b/logic/InstanceVersion.h deleted file mode 100644 index eecd9c4e..00000000 --- a/logic/InstanceVersion.h +++ /dev/null @@ -1,68 +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 - -/*! - * An abstract base class for versions. - */ -struct InstVersion -{ - /*! - * Checks if this version is less (older) than the given version. - * \param other The version to compare this one to. - * \return True if this version is older than the given version. - */ - virtual bool operator<(const InstVersion &rhs) const - { - return timestamp < rhs.timestamp; - } - - /*! - * Checks if this version is greater (newer) than the given version. - * \param other The version to compare this one to. - * \return True if this version is newer than the given version. - */ - virtual bool operator>( const InstVersion& rhs ) const - { - return timestamp > rhs.timestamp; - } - - /*! - * A string used to identify this version in config files. - * This should be unique within the version list or shenanigans will occur. - */ - QString descriptor; - /*! - * The name of this version as it is displayed to the user. - * For example: "1.5.1" - */ - QString name; - /*! - * Gets the version's timestamp. - * This is primarily used for sorting versions in a list. - */ - qint64 timestamp; - - virtual QString typeString() const - { - return "InstVersion"; - } -}; - -typedef QSharedPointer InstVersionPtr; - -Q_DECLARE_METATYPE( InstVersionPtr ) \ No newline at end of file diff --git a/logic/LegacyUpdate.cpp b/logic/LegacyUpdate.cpp index b8e179a5..25be5e7d 100644 --- a/logic/LegacyUpdate.cpp +++ b/logic/LegacyUpdate.cpp @@ -34,15 +34,15 @@ void LegacyUpdate::lwjglStart() return; } - auto &list = LWJGLVersionList::get(); - if(!list.isLoaded()) + auto list = MMC->lwjgllist(); + if(!list->isLoaded()) { emitFailed("Too soon! Let the LWJGL list load :)"); return; } setStatus("Downloading new LWJGL."); - auto version = list.getVersion(lwjglVersion); + auto version = list->getVersion(lwjglVersion); if(!version) { emitFailed("Game update failed: the selected LWJGL version is invalid."); @@ -170,7 +170,7 @@ void LegacyUpdate::extractLwjgl() if (name.contains(nativesDir)) { int lastSlash = name.lastIndexOf('/'); - int lastBackSlash = name.lastIndexOf('/'); + int lastBackSlash = name.lastIndexOf('\\'); if(lastSlash != -1) name = name.mid(lastSlash+1); else if(lastBackSlash != -1) diff --git a/logic/MinecraftVersion.h b/logic/MinecraftVersion.h index 27977262..53c2f5ef 100644 --- a/logic/MinecraftVersion.h +++ b/logic/MinecraftVersion.h @@ -15,17 +15,16 @@ #pragma once -#include "InstanceVersion.h" +#include "BaseVersion.h" #include -struct MinecraftVersion : public InstVersion +struct MinecraftVersion : public BaseVersion { - // From InstVersion: - /* - QString m_descriptor; - QString m_name; - qint64 m_timestamp; - */ + /*! + * Gets the version's timestamp. + * This is primarily used for sorting versions in a list. + */ + qint64 timestamp; /// The URL that this version will be downloaded from. maybe. QString download_url; @@ -44,6 +43,20 @@ struct MinecraftVersion : public InstVersion /// is this a snapshot? bool is_snapshot = false; + QString m_name; + + QString m_descriptor; + + virtual QString descriptor() + { + return m_descriptor; + } + + virtual QString name() + { + return m_name; + } + virtual QString typeString() const { QStringList pre_final; diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index c926df60..7b038c46 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -214,6 +214,13 @@ bool OneSixInstance::shouldUpdate() const return true; } +bool OneSixInstance::versionIsCustom() +{ + QString verpath_custom = PathCombine(instanceRoot(), "custom.json"); + QFile versionfile(verpath_custom); + return versionfile.exists(); +} + QString OneSixInstance::currentVersionId() const { return intendedVersionId(); @@ -224,6 +231,13 @@ 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; + } + QFile versionfile(verpath); if(versionfile.exists() && versionfile.open(QIODevice::ReadOnly)) { @@ -264,7 +278,12 @@ bool OneSixInstance::menuActionEnabled ( QString action_name ) const QString OneSixInstance::getStatusbarDescription() { - return "One Six : " + intendedVersionId(); + QString descr = "One Six : " + intendedVersionId(); + if(versionIsCustom()) + { + descr + " (custom)"; + } + return descr; } QString OneSixInstance::loaderModsDir() const diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h index a4c67ed1..72bde630 100644 --- a/logic/OneSixInstance.h +++ b/logic/OneSixInstance.h @@ -41,6 +41,8 @@ public: bool reloadFullVersion(); /// get the current full version info QSharedPointer getFullVersion(); + /// is the current version original, or custom? + bool versionIsCustom(); virtual QString defaultBaseJar() const; virtual QString defaultCustomBaseJar() const; diff --git a/logic/OneSixLibrary.cpp b/logic/OneSixLibrary.cpp index a109a7f0..a45a4aec 100644 --- a/logic/OneSixLibrary.cpp +++ b/logic/OneSixLibrary.cpp @@ -1,12 +1,13 @@ #include "OneSixLibrary.h" #include "OneSixRule.h" - +#include "OpSys.h" void OneSixLibrary::finalize() { QStringList parts = m_name.split ( ':' ); QString relative = parts[0]; relative.replace ( '.','/' ); relative += '/' + parts[1] + '/' + parts[2] + '/' + parts[1] + '-' + parts[2]; + if ( !m_is_native ) relative += ".jar"; else @@ -21,9 +22,12 @@ void OneSixLibrary::finalize() relative += ".jar"; } } + + m_decentname = parts[1]; + m_decentversion = parts[2]; m_storage_path = relative; m_download_path = m_base_url + relative; - + if ( m_rules.empty() ) { m_is_active = true; @@ -42,6 +46,11 @@ void OneSixLibrary::finalize() if ( m_is_native ) { m_is_active = m_is_active && m_native_suffixes.contains ( currentSystem ); + m_decenttype = "Native"; + } + else + { + m_decenttype = "Java"; } } diff --git a/logic/OneSixLibrary.h b/logic/OneSixLibrary.h index 856e409c..ac16d3d3 100644 --- a/logic/OneSixLibrary.h +++ b/logic/OneSixLibrary.h @@ -16,6 +16,12 @@ private: QList > m_rules; // derived values used for real things + /// a decent name fit for display + QString m_decentname; + /// a decent version fit for display + QString m_decentversion; + /// a decent type fit for display + QString m_decenttype; /// where to store the lib locally QString m_storage_path; /// where to download the lib from @@ -48,8 +54,24 @@ public: /// Set the library composite name void setName(QString name); + /// get a decent-looking name + QString name() + { + return m_decentname; + } + /// get a decent-looking version + QString version() + { + return m_decentversion; + } + /// what kind of library is it? (for display) + QString type() + { + return m_decenttype; + } /// Set the url base for downloads void setBaseUrl(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 diff --git a/logic/OneSixUpdate.cpp b/logic/OneSixUpdate.cpp index a58a9626..67395818 100644 --- a/logic/OneSixUpdate.cpp +++ b/logic/OneSixUpdate.cpp @@ -49,7 +49,7 @@ void OneSixUpdate::executeTask() } // Get a pointer to the version object that corresponds to the instance's version. - targetVersion = MinecraftVersionList::getMainList().findVersion(intendedVersion).dynamicCast(); + targetVersion = MMC->minecraftlist()->findVersion(intendedVersion).dynamicCast(); if(targetVersion == nullptr) { // don't do anything if it was invalid @@ -72,7 +72,7 @@ void OneSixUpdate::versionFileStart() setStatus("Getting the version files from Mojang."); QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/"); - urlstr += targetVersion->descriptor + "/" + targetVersion->descriptor + ".json"; + urlstr += targetVersion->descriptor() + "/" + targetVersion->descriptor() + ".json"; auto job = new DownloadJob("Version index"); job->add(QUrl(urlstr)); specificVersionDownloadJob.reset(job); @@ -85,31 +85,46 @@ void OneSixUpdate::versionFileStart() void OneSixUpdate::versionFileFinished() { DownloadPtr DlJob = specificVersionDownloadJob->first(); + OneSixInstance * inst = (OneSixInstance *) m_inst; - QString version_id = targetVersion->descriptor; + QString version_id = targetVersion->descriptor(); QString inst_dir = m_inst->instanceRoot(); // save the version file in $instanceId/version.json { QString version1 = PathCombine(inst_dir, "/version.json"); ensureFilePathExists(version1); // FIXME: detect errors here, download to a temp file, swap - QFile vfile1 (version1); - vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly ); - vfile1.write(DlJob.dynamicCast()->m_data); - vfile1.close(); + QSaveFile vfile1 (version1); + if(!vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly )) + { + emitFailed("Can't open " + version1 + " for writing."); + return; + } + auto data = DlJob.dynamicCast()->m_data; + qint64 actual = 0; + if((actual = vfile1.write(data)) != data.size()) + { + emitFailed("Failed to write into " + version1 + ". Written " + actual + " out of " + data.size() + '.'); + return; + } + if(!vfile1.commit()) + { + emitFailed("Can't commit changes to " + version1); + return; + } } // the version is downloaded safely. update is 'done' at this point m_inst->setShouldUpdate(false); - // save the version file in versions/$version/$version.json - /* - //QString version2 = QString("versions/") + version_id + "/" + version_id + ".json"; - //ensurePathExists(version2); - //QFile vfile2 (version2); - //vfile2.open(QIODevice::Truncate | QIODevice::WriteOnly ); - //vfile2.write(DlJob->m_data); - //vfile2.close(); - */ + + // delete any custom version inside the instance (it's no longer relevant, we did an update) + QString custom = PathCombine(inst_dir, "/custom.json"); + QFile finfo(custom); + if(finfo.exists()) + { + finfo.remove(); + } + inst->reloadFullVersion(); jarlibStart(); } diff --git a/logic/OneSixVersion.cpp b/logic/OneSixVersion.cpp index 7ffe9a94..dc1b5d6f 100644 --- a/logic/OneSixVersion.cpp +++ b/logic/OneSixVersion.cpp @@ -28,3 +28,74 @@ QList > OneSixVersion::getActiveNativeLibs() } +QVariant OneSixVersion::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 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(); + } +} + +int OneSixVersion::rowCount(const QModelIndex& parent) const +{ + return libraries.size(); +} + +int OneSixVersion::columnCount(const QModelIndex& parent) const +{ + return 3; +} diff --git a/logic/OneSixVersion.h b/logic/OneSixVersion.h index 8f01f82d..6a6a5b4b 100644 --- a/logic/OneSixVersion.h +++ b/logic/OneSixVersion.h @@ -2,8 +2,14 @@ #include class OneSixLibrary; -class OneSixVersion +class OneSixVersion : public QAbstractListModel { +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; public: /// the ID - determines which jar to use! ACTUALLY IMPORTANT! QString id; @@ -58,6 +64,7 @@ public: // QList rules; public: + OneSixVersion() { minimumLauncherVersion = 0xDEADBEEF; @@ -65,4 +72,4 @@ public: QList > getActiveNormalLibs(); QList > getActiveNativeLibs(); -}; \ No newline at end of file +}; diff --git a/logic/lists/BaseVersionList.cpp b/logic/lists/BaseVersionList.cpp new file mode 100644 index 00000000..61da5eeb --- /dev/null +++ b/logic/lists/BaseVersionList.cpp @@ -0,0 +1,123 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "logic/lists/BaseVersionList.h" +#include "logic/BaseVersion.h" + +BaseVersionList::BaseVersionList(QObject *parent) : + QAbstractListModel(parent) +{ +} + +BaseVersionPtr BaseVersionList::findVersion( const QString& descriptor ) +{ + for (int i = 0; i < count(); i++) + { + if (at(i)->descriptor() == descriptor) + return at(i); + } + return BaseVersionPtr(); +} + +BaseVersionPtr BaseVersionList::getLatestStable() const +{ + if (count() <= 0) + return BaseVersionPtr(); + else + return at(0); +} + +QVariant BaseVersionList::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (index.row() > count()) + return QVariant(); + + + BaseVersionPtr version = at(index.row()); + + switch (role) + { + case Qt::DisplayRole: + switch (index.column()) + { + case NameColumn: + return version->name(); + + case TypeColumn: + return version->typeString(); + + default: + return QVariant(); + } + + case Qt::ToolTipRole: + return version->descriptor(); + + case VersionPointerRole: + return qVariantFromValue(version); + + default: + return QVariant(); + } +} + +QVariant BaseVersionList::headerData(int section, Qt::Orientation orientation, int role) const +{ + switch (role) + { + case Qt::DisplayRole: + switch (section) + { + case NameColumn: + return "Name"; + + case TypeColumn: + return "Type"; + + default: + return QVariant(); + } + + case Qt::ToolTipRole: + switch (section) + { + case NameColumn: + return "The name of the version."; + + case TypeColumn: + return "The version's type."; + + default: + return QVariant(); + } + + default: + return QVariant(); + } +} + +int BaseVersionList::rowCount(const QModelIndex &parent) const +{ + // Return count + return count(); +} + +int BaseVersionList::columnCount(const QModelIndex &parent) const +{ + return 2; +} diff --git a/logic/lists/BaseVersionList.h b/logic/lists/BaseVersionList.h new file mode 100644 index 00000000..d37431ed --- /dev/null +++ b/logic/lists/BaseVersionList.h @@ -0,0 +1,121 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include + +#include "logic/BaseVersion.h" + +class Task; + +/*! + * \brief Class that each instance type's version list derives from. + * Version lists are the lists that keep track of the available game versions + * for that instance. This list will not be loaded on startup. It will be loaded + * when the list's load function is called. Before using the version list, you + * should check to see if it has been loaded yet and if not, load the list. + * + * Note that this class also inherits from QAbstractListModel. Methods from that + * class determine how this version list shows up in a list view. Said methods + * all have a default implementation, but they can be overridden by plugins to + * change the behavior of the list. + */ +class BaseVersionList : public QAbstractListModel +{ + Q_OBJECT +public: + enum ModelRoles + { + VersionPointerRole = 0x34B1CB48 + }; + + enum VListColumns + { + // First column - Name + NameColumn = 0, + + // Second column - Type + TypeColumn, + + // Third column - Timestamp + TimeColumn + }; + + explicit BaseVersionList(QObject *parent = 0); + + /*! + * \brief Gets a task that will reload the version list. + * Simply execute the task to load the list. + * The task returned by this function should reset the model when it's done. + * \return A pointer to a task that reloads the version list. + */ + virtual Task *getLoadTask() = 0; + + //! Checks whether or not the list is loaded. If this returns false, the list should be loaded. + virtual bool isLoaded() = 0; + + //! Gets the version at the given index. + virtual const BaseVersionPtr at(int i) const = 0; + + //! Returns the number of versions in the list. + virtual int count() const = 0; + + + //////// List Model Functions //////// + virtual QVariant data(const QModelIndex &index, int role) const; + virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; + virtual int rowCount(const QModelIndex &parent) const; + virtual int columnCount(const QModelIndex &parent) const; + + + /*! + * \brief Finds a version by its descriptor. + * \param The descriptor of the version to find. + * \return A const pointer to the version with the given descriptor. NULL if + * one doesn't exist. + */ + virtual BaseVersionPtr findVersion(const QString &descriptor); + + /*! + * \brief Gets the latest stable version of this instance type. + * This is the version that will be selected by default. + * By default, this is simply the first version in the list. + */ + virtual BaseVersionPtr getLatestStable() const; + + /*! + * Sorts the version list. + */ + virtual void sort() = 0; + +protected slots: + /*! + * Updates this list with the given list of versions. + * This is done by copying each version in the given list and inserting it + * into this one. + * We need to do this so that we can set the parents of the versions are set to this + * version list. This can't be done in the load task, because the versions the load + * task creates are on the load task's thread and Qt won't allow their parents + * to be set to something created on another thread. + * To get around that problem, we invoke this method on the GUI thread, which + * then copies the versions and sets their parents correctly. + * \param versions List of versions whose parents should be set. + */ + virtual void updateListData(QList versions) = 0; +}; diff --git a/logic/lists/ForgeVersionList.cpp b/logic/lists/ForgeVersionList.cpp new file mode 100644 index 00000000..f45b8b6b --- /dev/null +++ b/logic/lists/ForgeVersionList.cpp @@ -0,0 +1,200 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ForgeVersionList.h" +#include +#include "MultiMC.h" + +#include + +#include + +#include + +#define JSON_URL "http://files.minecraftforge.net/minecraftforge/json" + + +ForgeVersionList::ForgeVersionList(QObject* parent): BaseVersionList(parent) +{ + +} + +Task *ForgeVersionList::getLoadTask() +{ + return new ForgeListLoadTask(this); +} + +bool ForgeVersionList::isLoaded() +{ + return m_loaded; +} + +const BaseVersionPtr ForgeVersionList::at(int i) const +{ + return m_vlist.at(i); +} + +int ForgeVersionList::count() const +{ + return m_vlist.count(); +} +/* +bool cmpVersions(BaseVersionPtr first, BaseVersionPtr second) +{ + const BaseVersion & left = *first; + const BaseVersion & right = *second; + return left > right; +} + +void MinecraftVersionList::sort() +{ + beginResetModel(); + qSort(m_vlist.begin(), m_vlist.end(), cmpVersions); + endResetModel(); +} +*/ +BaseVersionPtr ForgeVersionList::getLatestStable() const +{ + return BaseVersionPtr(); +} + +void ForgeVersionList::updateListData(QList versions) +{ + beginResetModel(); + m_vlist = versions; + m_loaded = true; + endResetModel(); + // NOW SORT!! + // sort(); +} + +void ForgeVersionList::sort() +{ + // NO-OP for now +} + + +ForgeListLoadTask::ForgeListLoadTask(ForgeVersionList* vlist): Task() +{ + m_list = vlist; +} + + +void ForgeListLoadTask::executeTask() +{ + auto job = new DownloadJob("Version index"); + job->add(QUrl(JSON_URL)); + listJob.reset(job); + connect(listJob.data(), SIGNAL(succeeded()), SLOT(list_downloaded())); + connect(listJob.data(), SIGNAL(failed()), SLOT(versionFileFailed())); + connect(listJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); + listJob->start(); +} + +void ForgeListLoadTask::list_downloaded() +{ + auto DlJob = listJob->first(); + auto data = DlJob.dynamicCast()->m_data; + + + QJsonParseError jsonError; + QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); + DlJob.reset(); + + if (jsonError.error != QJsonParseError::NoError) + { + emitFailed("Error parsing version list JSON:" + jsonError.errorString()); + return; + } + + if(!jsonDoc.isObject()) + { + emitFailed("Error parsing version list JSON: jsonDoc is not an object"); + return; + } + + QJsonObject root = jsonDoc.object(); + + // Now, get the array of versions. + if(!root.value("builds").isArray()) + { + emitFailed("Error parsing version list JSON: version list object is missing 'builds' array"); + return; + } + QJsonArray builds = root.value("builds").toArray(); + + QList tempList; + for (int i = 0; i < builds.count(); i++) + { + // Load the version info. + if(!builds[i].isObject()) + { + //FIXME: log this somewhere + continue; + } + QJsonObject obj = builds[i].toObject(); + int build_nr = obj.value("build").toDouble(0); + if(!build_nr) + continue; + QJsonArray files = root.value("files").toArray(); + QString url, jobbuildver, mcver, buildtype, filename; + QString changelog_url, installer_url; + bool valid = false; + for(int j = 0; j < files.count(); j++) + { + if(!files[j].isObject()) + continue; + QJsonObject file = files[j].toObject(); + buildtype = file.value("buildtype").toString(); + if((buildtype == "client" || buildtype == "universal") && !valid) + { + mcver = file.value("mcver").toString(); + url = file.value("url").toString(); + jobbuildver = file.value("jobbuildver").toString(); + int lastSlash = url.lastIndexOf('/'); + filename = url.mid(lastSlash+1); + valid = true; + } + else if(buildtype == "changelog") + { + QString ext = file.value("ext").toString(); + if(ext.isEmpty()) + continue; + changelog_url = file.value("url").toString(); + } + else if(buildtype == "installer") + { + installer_url = file.value("url").toString(); + } + } + if(valid) + { + // Now, we construct the version object and add it to the list. + QSharedPointer fVersion(new ForgeVersion()); + fVersion->universal_url = url; + fVersion->changelog_url = changelog_url; + fVersion->installer_url = installer_url; + fVersion->jobbuildver = jobbuildver; + fVersion->mcver = mcver; + fVersion->filename = filename; + fVersion->m_buildnr = build_nr; + tempList.append(fVersion); + } + } + m_list->updateListData(tempList); + + emitSucceeded(); + return; +} diff --git a/logic/lists/ForgeVersionList.h b/logic/lists/ForgeVersionList.h new file mode 100644 index 00000000..8d4a2d46 --- /dev/null +++ b/logic/lists/ForgeVersionList.h @@ -0,0 +1,98 @@ +/* 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 +#include "BaseVersionList.h" +#include "logic/tasks/Task.h" +#include "logic/net/DownloadJob.h" + +class ForgeVersion; +typedef QSharedPointer PtrForgeVersion; + +struct ForgeVersion : public BaseVersion +{ + virtual QString descriptor() + { + return filename; + }; + virtual QString name() + { + return "Forge " + jobbuildver + " (" + mcver + ")"; + }; + virtual QString typeString() const + { + if(installer_url.isEmpty()) + return "Universal"; + else + return "Installer"; + }; + + int m_buildnr = 0; + QString universal_url; + QString changelog_url; + QString installer_url; + QString jobbuildver; + QString mcver; + QString filename; +}; + +class ForgeVersionList : public BaseVersionList +{ + Q_OBJECT +public: + friend class ForgeListLoadTask; + + explicit ForgeVersionList(QObject *parent = 0); + + virtual Task *getLoadTask(); + virtual bool isLoaded(); + virtual const BaseVersionPtr at(int i) const; + virtual int count() const; + virtual void sort(); + + virtual BaseVersionPtr getLatestStable() const; + +protected: + QList m_vlist; + + bool m_loaded; + +protected slots: + virtual void updateListData(QList versions); +}; + +class ForgeListLoadTask : public Task +{ + Q_OBJECT + +public: + explicit ForgeListLoadTask(ForgeVersionList *vlist); + + virtual void executeTask(); + +protected slots: + void list_downloaded(); + +protected: + DownloadJobPtr listJob; + ForgeVersionList *m_list; +}; diff --git a/logic/lists/InstVersionList.cpp b/logic/lists/InstVersionList.cpp deleted file mode 100644 index 7dc67155..00000000 --- a/logic/lists/InstVersionList.cpp +++ /dev/null @@ -1,129 +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 "logic/lists/InstVersionList.h" -#include "logic/InstanceVersion.h" - -InstVersionList::InstVersionList(QObject *parent) : - QAbstractListModel(parent) -{ -} - -InstVersionPtr InstVersionList::findVersion( const QString& descriptor ) -{ - for (int i = 0; i < count(); i++) - { - if (at(i)->descriptor == descriptor) - return at(i); - } - return InstVersionPtr(); -} - -InstVersionPtr InstVersionList::getLatestStable() const -{ - if (count() <= 0) - return InstVersionPtr(); - else - return at(0); -} - -QVariant InstVersionList::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) - return QVariant(); - - if (index.row() > count()) - return QVariant(); - - - InstVersionPtr version = at(index.row()); - - switch (role) - { - case Qt::DisplayRole: - switch (index.column()) - { - case NameColumn: - return version->name; - - case TypeColumn: - return version->typeString(); - - case TimeColumn: - return version->timestamp; - - default: - return QVariant(); - } - - case Qt::ToolTipRole: - return version->descriptor; - - case VersionPointerRole: - return qVariantFromValue(version); - - default: - return QVariant(); - } -} - -QVariant InstVersionList::headerData(int section, Qt::Orientation orientation, int role) const -{ - switch (role) - { - case Qt::DisplayRole: - switch (section) - { - case NameColumn: - return "Name"; - - case TypeColumn: - return "Type"; - - case TimeColumn: - return "Time"; - - default: - return QVariant(); - } - - case Qt::ToolTipRole: - switch (section) - { - case NameColumn: - return "The name of the version."; - - case TypeColumn: - return "The version's type."; - - default: - return QVariant(); - } - - default: - return QVariant(); - } -} - -int InstVersionList::rowCount(const QModelIndex &parent) const -{ - // Return count - return count(); -} - -int InstVersionList::columnCount(const QModelIndex &parent) const -{ - return 2; -} diff --git a/logic/lists/InstVersionList.h b/logic/lists/InstVersionList.h deleted file mode 100644 index bc6aa5d4..00000000 --- a/logic/lists/InstVersionList.h +++ /dev/null @@ -1,121 +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 "logic/InstanceVersion.h" - -class Task; - -/*! - * \brief Class that each instance type's version list derives from. - * Version lists are the lists that keep track of the available game versions - * for that instance. This list will not be loaded on startup. It will be loaded - * when the list's load function is called. Before using the version list, you - * should check to see if it has been loaded yet and if not, load the list. - * - * Note that this class also inherits from QAbstractListModel. Methods from that - * class determine how this version list shows up in a list view. Said methods - * all have a default implementation, but they can be overridden by plugins to - * change the behavior of the list. - */ -class InstVersionList : public QAbstractListModel -{ - Q_OBJECT -public: - enum ModelRoles - { - VersionPointerRole = 0x34B1CB48 - }; - - enum VListColumns - { - // First column - Name - NameColumn = 0, - - // Second column - Type - TypeColumn, - - // Third column - Timestamp - TimeColumn - }; - - explicit InstVersionList(QObject *parent = 0); - - /*! - * \brief Gets a task that will reload the version list. - * Simply execute the task to load the list. - * The task returned by this function should reset the model when it's done. - * \return A pointer to a task that reloads the version list. - */ - virtual Task *getLoadTask() = 0; - - //! Checks whether or not the list is loaded. If this returns false, the list should be loaded. - virtual bool isLoaded() = 0; - - //! Gets the version at the given index. - virtual const InstVersionPtr at(int i) const = 0; - - //! Returns the number of versions in the list. - virtual int count() const = 0; - - - //////// List Model Functions //////// - virtual QVariant data(const QModelIndex &index, int role) const; - virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; - virtual int rowCount(const QModelIndex &parent) const; - virtual int columnCount(const QModelIndex &parent) const; - - - /*! - * \brief Finds a version by its descriptor. - * \param The descriptor of the version to find. - * \return A const pointer to the version with the given descriptor. NULL if - * one doesn't exist. - */ - virtual InstVersionPtr findVersion(const QString &descriptor); - - /*! - * \brief Gets the latest stable version of this instance type. - * This is the version that will be selected by default. - * By default, this is simply the first version in the list. - */ - virtual InstVersionPtr getLatestStable() const; - - /*! - * Sorts the version list. - */ - virtual void sort() = 0; - -protected slots: - /*! - * Updates this list with the given list of versions. - * This is done by copying each version in the given list and inserting it - * into this one. - * We need to do this so that we can set the parents of the versions are set to this - * version list. This can't be done in the load task, because the versions the load - * task creates are on the load task's thread and Qt won't allow their parents - * to be set to something created on another thread. - * To get around that problem, we invoke this method on the GUI thread, which - * then copies the versions and sets their parents correctly. - * \param versions List of versions whose parents should be set. - */ - virtual void updateListData(QList versions) = 0; -}; diff --git a/logic/lists/LwjglVersionList.cpp b/logic/lists/LwjglVersionList.cpp index d7826a82..b3e2dab4 100644 --- a/logic/lists/LwjglVersionList.cpp +++ b/logic/lists/LwjglVersionList.cpp @@ -24,14 +24,6 @@ #define RSS_URL "http://sourceforge.net/api/file/index/project-id/58488/mtime/desc/rss" -LWJGLVersionList mainVersionList; - -LWJGLVersionList &LWJGLVersionList::get() -{ - return mainVersionList; -} - - LWJGLVersionList::LWJGLVersionList(QObject *parent) : QAbstractListModel(parent) { diff --git a/logic/lists/LwjglVersionList.h b/logic/lists/LwjglVersionList.h index 638a0b67..23e92a1a 100644 --- a/logic/lists/LwjglVersionList.h +++ b/logic/lists/LwjglVersionList.h @@ -53,8 +53,6 @@ class LWJGLVersionList : public QAbstractListModel public: explicit LWJGLVersionList(QObject *parent = 0); - static LWJGLVersionList &get(); - bool isLoaded() { return m_vlist.length() > 0; } const PtrLWJGLVersion getVersion(const QString &versionName); diff --git a/logic/lists/MinecraftVersionList.cpp b/logic/lists/MinecraftVersionList.cpp index 42fb1b50..86ba0792 100644 --- a/logic/lists/MinecraftVersionList.cpp +++ b/logic/lists/MinecraftVersionList.cpp @@ -34,10 +34,8 @@ #define ASSETS_URLBASE "http://assets.minecraft.net/" #define MCN_URLBASE "http://sonicrules.org/mcnweb.py" -MinecraftVersionList mcVList; - MinecraftVersionList::MinecraftVersionList(QObject *parent) : - InstVersionList(parent) + BaseVersionList(parent) { } @@ -52,7 +50,7 @@ bool MinecraftVersionList::isLoaded() return m_loaded; } -const InstVersionPtr MinecraftVersionList::at(int i) const +const BaseVersionPtr MinecraftVersionList::at(int i) const { return m_vlist.at(i); } @@ -62,11 +60,11 @@ int MinecraftVersionList::count() const return m_vlist.count(); } -bool cmpVersions(InstVersionPtr first, InstVersionPtr second) +bool cmpVersions(BaseVersionPtr first, BaseVersionPtr second) { - const InstVersion & left = *first; - const InstVersion & right = *second; - return left > right; + auto left = first.dynamicCast(); + auto right = second.dynamicCast(); + return left->timestamp > right->timestamp; } void MinecraftVersionList::sort() @@ -76,7 +74,7 @@ void MinecraftVersionList::sort() endResetModel(); } -InstVersionPtr MinecraftVersionList::getLatestStable() const +BaseVersionPtr MinecraftVersionList::getLatestStable() const { for (int i = 0; i < m_vlist.length(); i++) { @@ -86,15 +84,10 @@ InstVersionPtr MinecraftVersionList::getLatestStable() const return m_vlist.at(i); } } - return InstVersionPtr(); -} - -MinecraftVersionList &MinecraftVersionList::getMainList() -{ - return mcVList; + return BaseVersionPtr(); } -void MinecraftVersionList::updateListData(QList versions) +void MinecraftVersionList::updateListData(QList versions) { beginResetModel(); m_vlist = versions; @@ -214,7 +207,7 @@ void MCVListLoadTask::list_downloaded() } QJsonArray versions = root.value("versions").toArray(); - QList tempList; + QList tempList; for (int i = 0; i < versions.count(); i++) { bool is_snapshot = false; @@ -280,7 +273,7 @@ void MCVListLoadTask::list_downloaded() // Now, we construct the version object and add it to the list. QSharedPointer mcVersion(new MinecraftVersion()); - mcVersion->name = mcVersion->descriptor = versionID; + mcVersion->m_name = mcVersion->m_descriptor = versionID; mcVersion->timestamp = versionTime.toMSecsSinceEpoch(); mcVersion->download_url = dlUrl; mcVersion->is_latest = is_latest; @@ -293,8 +286,3 @@ void MCVListLoadTask::list_downloaded() emitSucceeded(); return; } - -// FIXME: we should have a local cache of the version list and a local cache of version data -bool MCVListLoadTask::loadFromVList() -{ -} diff --git a/logic/lists/MinecraftVersionList.h b/logic/lists/MinecraftVersionList.h index 0477379f..8937ba7b 100644 --- a/logic/lists/MinecraftVersionList.h +++ b/logic/lists/MinecraftVersionList.h @@ -20,14 +20,14 @@ #include #include -#include "InstVersionList.h" +#include "BaseVersionList.h" #include "logic/tasks/Task.h" #include "logic/MinecraftVersion.h" class MCVListLoadTask; class QNetworkReply; -class MinecraftVersionList : public InstVersionList +class MinecraftVersionList : public BaseVersionList { Q_OBJECT public: @@ -37,25 +37,19 @@ public: virtual Task *getLoadTask(); virtual bool isLoaded(); - virtual const InstVersionPtr at(int i) const; + virtual const BaseVersionPtr at(int i) const; virtual int count() const; virtual void sort(); - virtual InstVersionPtr getLatestStable() const; - - /*! - * Gets the main version list instance. - */ - static MinecraftVersionList &getMainList(); - + virtual BaseVersionPtr getLatestStable() const; protected: - QList m_vlist; + QList m_vlist; bool m_loaded; protected slots: - virtual void updateListData(QList versions); + virtual void updateListData(QList versions); }; class MCVListLoadTask : public Task @@ -72,9 +66,6 @@ protected slots: void list_downloaded(); protected: - //! Loads versions from Mojang's official version list. - bool loadFromVList(); - QNetworkReply *vlistReply; MinecraftVersionList *m_list; MinecraftVersion *m_currentStable; -- cgit From b979d0ce5da515793a02802a6421ef607a498323 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Wed, 18 Sep 2013 00:00:35 +0200 Subject: Implement legacy forge button! Many refactors of the task system. Progress dialog now accepts generic ProgressProvider objects --- CMakeLists.txt | 9 ++-- MultiMC.cpp | 1 + gui/LegacyModEditDialog.cpp | 41 +++++++++++++- gui/LegacyModEditDialog.h | 2 + gui/LegacyModEditDialog.ui | 3 -- gui/OneSixModEditDialog.cpp | 22 ++++++-- gui/OneSixModEditDialog.h | 1 + gui/OneSixModEditDialog.ui | 2 +- gui/ProgressDialog.cpp | 108 +++++++++++++++++++++++++++++++++++++ gui/ProgressDialog.h | 62 +++++++++++++++++++++ gui/ProgressDialog.ui | 53 ++++++++++++++++++ gui/mainwindow.cpp | 8 +-- gui/newinstancedialog.cpp | 2 +- gui/taskdialog.cpp | 107 ------------------------------------ gui/taskdialog.h | 61 --------------------- gui/taskdialog.ui | 53 ------------------ gui/versionselectdialog.cpp | 19 +++---- gui/versionselectdialog.h | 5 +- gui/versionselectdialog.ui | 69 ------------------------ logic/BaseUpdate.cpp | 4 +- logic/InstanceLauncher.cpp | 4 +- logic/LegacyUpdate.cpp | 6 +-- logic/OneSixUpdate.cpp | 4 +- logic/lists/ForgeVersionList.cpp | 93 +++++++++++++++++++++++++++----- logic/lists/ForgeVersionList.h | 10 ++-- logic/lists/MinecraftVersionList.h | 2 +- logic/net/DownloadJob.cpp | 2 + logic/net/DownloadJob.h | 19 ++++++- logic/tasks/ProgressProvider.h | 20 +++++++ logic/tasks/Task.cpp | 48 ++++++----------- logic/tasks/Task.h | 48 ++++++----------- 31 files changed, 474 insertions(+), 414 deletions(-) create mode 100644 gui/ProgressDialog.cpp create mode 100644 gui/ProgressDialog.h create mode 100644 gui/ProgressDialog.ui delete mode 100644 gui/taskdialog.cpp delete mode 100644 gui/taskdialog.h delete mode 100644 gui/taskdialog.ui create mode 100644 logic/tasks/ProgressProvider.h (limited to 'logic/LegacyUpdate.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index d4f0cbbf..7f09e324 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,7 +156,7 @@ gui/mainwindow.h gui/settingsdialog.h gui/newinstancedialog.h gui/logindialog.h -gui/taskdialog.h +gui/ProgressDialog.h gui/aboutdialog.h gui/consolewindow.h gui/instancedelegate.h @@ -228,6 +228,7 @@ logic/EnabledItemFilter.h # Tasks logic/tasks/Task.h logic/tasks/LoginTask.h +logic/tasks/ProgressProvider.h ) @@ -239,13 +240,14 @@ gui/mainwindow.cpp gui/settingsdialog.cpp gui/newinstancedialog.cpp gui/logindialog.cpp -gui/taskdialog.cpp gui/aboutdialog.cpp gui/consolewindow.cpp gui/instancedelegate.cpp gui/versionselectdialog.cpp gui/lwjglselectdialog.cpp gui/instancesettings.cpp + +gui/ProgressDialog.cpp gui/IconPickerDialog.cpp gui/LegacyModEditDialog.cpp gui/OneSixModEditDialog.cpp @@ -313,12 +315,13 @@ gui/mainwindow.ui gui/settingsdialog.ui gui/newinstancedialog.ui gui/logindialog.ui -gui/taskdialog.ui gui/aboutdialog.ui gui/consolewindow.ui gui/versionselectdialog.ui gui/lwjglselectdialog.ui gui/instancesettings.ui + +gui/ProgressDialog.ui gui/IconPickerDialog.ui gui/LegacyModEditDialog.ui gui/OneSixModEditDialog.ui diff --git a/MultiMC.cpp b/MultiMC.cpp index 08e5ed25..4b5b40b2 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -282,6 +282,7 @@ void MultiMC::initHttpMetaCache() m_metacache->addBase("assets", QDir("assets").absolutePath()); m_metacache->addBase("versions", QDir("versions").absolutePath()); m_metacache->addBase("libraries", QDir("libraries").absolutePath()); + m_metacache->addBase("minecraftforge", QDir("mods/minecraftforge").absolutePath()); m_metacache->Load(); } diff --git a/gui/LegacyModEditDialog.cpp b/gui/LegacyModEditDialog.cpp index c336f837..ac7f7f25 100644 --- a/gui/LegacyModEditDialog.cpp +++ b/gui/LegacyModEditDialog.cpp @@ -13,10 +13,15 @@ * limitations under the License. */ +#include "MultiMC.h" #include "LegacyModEditDialog.h" #include "ModEditDialogCommon.h" +#include "versionselectdialog.h" +#include "ProgressDialog.h" #include "ui_LegacyModEditDialog.h" -#include +#include "logic/ModList.h" +#include "logic/lists/ForgeVersionList.h" + #include #include #include @@ -194,7 +199,39 @@ void LegacyModEditDialog::on_addCoreBtn_clicked() } void LegacyModEditDialog::on_addForgeBtn_clicked() { - + VersionSelectDialog vselect(MMC->forgelist(), this); + vselect.setFilter(1, m_inst->intendedVersionId()); + if (vselect.exec() && vselect.selectedVersion()) + { + ForgeVersionPtr forge = vselect.selectedVersion().dynamicCast(); + if(!forge) + return; + auto entry = MMC->metacache()->resolveEntry("minecraftforge", forge->filename); + if(entry->stale) + { + DownloadJob * fjob = new DownloadJob("Forge download"); + fjob->add(forge->universal_url, entry); + ProgressDialog dlg(this); + dlg.exec(fjob); + if(dlg.result() == QDialog::Accepted) + { + m_jarmods->stopWatching(); + m_jarmods->installMod(QFileInfo(entry->getFullPath())); + m_jarmods->startWatching(); + } + else + { + // failed to download forge :/ + } + } + else + { + m_jarmods->stopWatching(); + m_jarmods->installMod(QFileInfo(entry->getFullPath())); + m_jarmods->startWatching(); + } + //m_selectedInstance->setIntendedVersionId(->descriptor()); + } } void LegacyModEditDialog::on_addJarBtn_clicked() { diff --git a/gui/LegacyModEditDialog.h b/gui/LegacyModEditDialog.h index bc9ebac0..b824a86a 100644 --- a/gui/LegacyModEditDialog.h +++ b/gui/LegacyModEditDialog.h @@ -17,6 +17,7 @@ #include #include "logic/LegacyInstance.h" +#include namespace Ui { class LegacyModEditDialog; @@ -64,4 +65,5 @@ private: QSharedPointer m_jarmods; QSharedPointer m_texturepacks; LegacyInstance * m_inst; + DownloadJobPtr forgeJob; }; diff --git a/gui/LegacyModEditDialog.ui b/gui/LegacyModEditDialog.ui index bd147c85..73b767dc 100644 --- a/gui/LegacyModEditDialog.ui +++ b/gui/LegacyModEditDialog.ui @@ -52,9 +52,6 @@ - - false - MCForge diff --git a/gui/OneSixModEditDialog.cpp b/gui/OneSixModEditDialog.cpp index f778127f..fad9d2e2 100644 --- a/gui/OneSixModEditDialog.cpp +++ b/gui/OneSixModEditDialog.cpp @@ -12,18 +12,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#include "MultiMC.h" #include "OneSixModEditDialog.h" #include "ModEditDialogCommon.h" #include "ui_OneSixModEditDialog.h" -#include +#include "logic/ModList.h" +#include "logic/OneSixVersion.h" +#include "logic/EnabledItemFilter.h" +#include "logic/lists/ForgeVersionList.h" +#include "gui/versionselectdialog.h" + #include #include #include #include #include -#include "logic/OneSixVersion.h" -#include OneSixModEditDialog::OneSixModEditDialog(OneSixInstance * inst, QWidget *parent): m_inst(inst), @@ -66,6 +69,17 @@ OneSixModEditDialog::~OneSixModEditDialog() delete ui; } +void OneSixModEditDialog::on_forgeBtn_clicked() +{ + VersionSelectDialog vselect(MMC->forgelist(), this); + vselect.setFilter(1, m_inst->currentVersionId()); + if (vselect.exec() && vselect.selectedVersion()) + { + //m_selectedInstance->setIntendedVersionId(vselect.selectedVersion()->descriptor()); + } +} + + bool OneSixModEditDialog::loaderListFilter ( QKeyEvent* keyEvent ) { switch(keyEvent->key()) diff --git a/gui/OneSixModEditDialog.h b/gui/OneSixModEditDialog.h index c637df01..d14c842c 100644 --- a/gui/OneSixModEditDialog.h +++ b/gui/OneSixModEditDialog.h @@ -40,6 +40,7 @@ private slots: void on_viewResPackBtn_clicked(); // Questionable: SettingsDialog doesn't need this for some reason? void on_buttonBox_rejected(); + void on_forgeBtn_clicked(); protected: bool eventFilter(QObject *obj, QEvent *ev); bool loaderListFilter( QKeyEvent* ev ); diff --git a/gui/OneSixModEditDialog.ui b/gui/OneSixModEditDialog.ui index bffcaed0..aadaf3ae 100644 --- a/gui/OneSixModEditDialog.ui +++ b/gui/OneSixModEditDialog.ui @@ -64,7 +64,7 @@ - + Replace any current custom version with Minecraft Forge diff --git a/gui/ProgressDialog.cpp b/gui/ProgressDialog.cpp new file mode 100644 index 00000000..154ab1c0 --- /dev/null +++ b/gui/ProgressDialog.cpp @@ -0,0 +1,108 @@ +/* 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 "ProgressDialog.h" +#include "ui_ProgressDialog.h" + +#include + +#include "logic/tasks/Task.h" + +ProgressDialog::ProgressDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::ProgressDialog) +{ + ui->setupUi(this); + updateSize(); + + changeProgress(0,100); +} + +ProgressDialog::~ProgressDialog() +{ + delete ui; +} + +void ProgressDialog::updateSize() +{ + resize(QSize(480, minimumSizeHint().height())); +} + +int ProgressDialog::exec(ProgressProvider *task) +{ + this->task = task; + + // Connect signals. + connect(task, SIGNAL(started()), SLOT(onTaskStarted())); + connect(task, SIGNAL(failed(QString)), SLOT(onTaskFailed(QString))); + connect(task, SIGNAL(succeeded()), SLOT(onTaskSucceeded())); + connect(task, SIGNAL(status(QString)), SLOT(changeStatus(const QString&))); + connect(task, SIGNAL(progress(qint64,qint64)), SLOT(changeProgress(qint64,qint64))); + + // this makes sure that the task is started after the dialog is created + QMetaObject::invokeMethod(task, "start", Qt::QueuedConnection); + return QDialog::exec(); +} + +ProgressProvider* ProgressDialog::getTask() +{ + return task; +} + +void ProgressDialog::onTaskStarted() +{ + +} + +void ProgressDialog::onTaskFailed(QString failure) +{ + reject(); +} + +void ProgressDialog::onTaskSucceeded() +{ + accept(); +} + +void ProgressDialog::changeStatus(const QString &status) +{ + ui->statusLabel->setText(status); + updateSize(); +} + +void ProgressDialog::changeProgress(qint64 current, qint64 total) +{ + ui->taskProgressBar->setMaximum(total); + ui->taskProgressBar->setValue(current); +} + +void ProgressDialog::keyPressEvent(QKeyEvent* e) +{ + if (e->key() == Qt::Key_Escape) + return; + QDialog::keyPressEvent(e); +} + +void ProgressDialog::closeEvent(QCloseEvent* e) +{ + if (task && task->isRunning()) + { + e->ignore(); + } + else + { + QDialog::closeEvent(e); + } +} diff --git a/gui/ProgressDialog.h b/gui/ProgressDialog.h new file mode 100644 index 00000000..ac6bb412 --- /dev/null +++ b/gui/ProgressDialog.h @@ -0,0 +1,62 @@ +/* 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. + */ + +#ifndef TASKDIALOG_H +#define TASKDIALOG_H + +#include + +class ProgressProvider; + +namespace Ui { +class ProgressDialog; +} + +class ProgressDialog : public QDialog +{ + Q_OBJECT + +public: + explicit ProgressDialog(QWidget *parent = 0); + ~ProgressDialog(); + + void updateSize(); + + int exec(ProgressProvider* task); + + ProgressProvider* getTask(); + +public slots: + void onTaskStarted(); + void onTaskFailed(QString failure); + void onTaskSucceeded(); + + void changeStatus(const QString& status); + void changeProgress(qint64 current, qint64 total); + +signals: + + +protected: + virtual void keyPressEvent(QKeyEvent* e); + virtual void closeEvent(QCloseEvent* e); + +private: + Ui::ProgressDialog *ui; + + ProgressProvider* task; +}; + +#endif // TASKDIALOG_H diff --git a/gui/ProgressDialog.ui b/gui/ProgressDialog.ui new file mode 100644 index 00000000..a56d2a92 --- /dev/null +++ b/gui/ProgressDialog.ui @@ -0,0 +1,53 @@ + + + ProgressDialog + + + + 0 + 0 + 400 + 68 + + + + + 400 + 0 + + + + + 600 + 16777215 + + + + Please wait... + + + + + + Task Status... + + + true + + + + + + + 24 + + + false + + + + + + + + diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 241df383..6f707236 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -42,7 +42,7 @@ #include "gui/settingsdialog.h" #include "gui/newinstancedialog.h" #include "gui/logindialog.h" -#include "gui/taskdialog.h" +#include "gui/ProgressDialog.h" #include "gui/aboutdialog.h" #include "gui/versionselectdialog.h" #include "gui/lwjglselectdialog.h" @@ -479,7 +479,7 @@ void MainWindow::doLogin(const QString& errorMsg) { UserInfo uInfo{loginDlg->getUsername(), loginDlg->getPassword()}; - TaskDialog* tDialog = new TaskDialog(this); + ProgressDialog* tDialog = new ProgressDialog(this); LoginTask* loginTask = new LoginTask(uInfo, tDialog); connect(loginTask, SIGNAL(succeeded()),SLOT(onLoginComplete()), Qt::QueuedConnection); connect(loginTask, SIGNAL(failed(QString)), SLOT(doLogin(QString)), Qt::QueuedConnection); @@ -512,7 +512,7 @@ void MainWindow::onLoginComplete() } else { - TaskDialog *tDialog = new TaskDialog(this); + ProgressDialog *tDialog = new ProgressDialog(this); connect(updateTask, SIGNAL(succeeded()),SLOT(onGameUpdateComplete())); connect(updateTask, SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString))); tDialog->exec(updateTask); @@ -575,7 +575,7 @@ void MainWindow::startTask(Task *task) connect(task, SIGNAL(started()), SLOT(taskStart())); connect(task, SIGNAL(succeeded()), SLOT(taskEnd())); connect(task, SIGNAL(failed(QString)), SLOT(taskEnd())); - task->startTask(); + task->start(); } diff --git a/gui/newinstancedialog.cpp b/gui/newinstancedialog.cpp index af2b11c5..6604d03b 100644 --- a/gui/newinstancedialog.cpp +++ b/gui/newinstancedialog.cpp @@ -24,7 +24,7 @@ #include "logic/tasks/Task.h" #include "versionselectdialog.h" -#include "taskdialog.h" +#include "ProgressDialog.h" #include "IconPickerDialog.h" #include diff --git a/gui/taskdialog.cpp b/gui/taskdialog.cpp deleted file mode 100644 index 8c745b38..00000000 --- a/gui/taskdialog.cpp +++ /dev/null @@ -1,107 +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 "taskdialog.h" -#include "ui_taskdialog.h" - -#include - -#include "logic/tasks/Task.h" - -TaskDialog::TaskDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::TaskDialog) -{ - ui->setupUi(this); - updateSize(); - - changeProgress(0); -} - -TaskDialog::~TaskDialog() -{ - delete ui; -} - -void TaskDialog::updateSize() -{ - resize(QSize(480, minimumSizeHint().height())); -} - -void TaskDialog::exec(Task *task) -{ - this->task = task; - - // Connect signals. - connect(task, SIGNAL(started()), SLOT(onTaskStarted())); - connect(task, SIGNAL(failed(QString)), SLOT(onTaskEnded())); - connect(task, SIGNAL(succeeded()), SLOT(onTaskEnded())); - connect(task, SIGNAL(statusChanged(const QString&)), SLOT(changeStatus(const QString&))); - connect(task, SIGNAL(progressChanged(int)), SLOT(changeProgress(int))); - - // this makes sure that the task is started after the dialog is created - QMetaObject::invokeMethod(task, "startTask", Qt::QueuedConnection); - QDialog::exec(); -} - -Task* TaskDialog::getTask() -{ - return task; -} - -void TaskDialog::onTaskStarted() -{ - -} - -void TaskDialog::onTaskEnded() -{ - close(); -} - -void TaskDialog::changeStatus(const QString &status) -{ - ui->statusLabel->setText(status); - updateSize(); -} - -void TaskDialog::changeProgress(int progress) -{ - if (progress < 0) - progress = 0; - else if (progress > 100) - progress = 100; - - ui->taskProgressBar->setValue(progress); -} - -void TaskDialog::keyPressEvent(QKeyEvent* e) -{ - if (e->key() == Qt::Key_Escape) - return; - QDialog::keyPressEvent(e); -} - -void TaskDialog::closeEvent(QCloseEvent* e) -{ - if (task && task->isRunning()) - { - e->ignore(); - } - else - { - QDialog::closeEvent(e); - } -} diff --git a/gui/taskdialog.h b/gui/taskdialog.h deleted file mode 100644 index 3d31b7be..00000000 --- a/gui/taskdialog.h +++ /dev/null @@ -1,61 +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. - */ - -#ifndef TASKDIALOG_H -#define TASKDIALOG_H - -#include - -class Task; - -namespace Ui { -class TaskDialog; -} - -class TaskDialog : public QDialog -{ - Q_OBJECT - -public: - explicit TaskDialog(QWidget *parent = 0); - ~TaskDialog(); - - void updateSize(); - - void exec(Task* task); - - Task* getTask(); - -public slots: - void onTaskStarted(); - void onTaskEnded(); - - void changeStatus(const QString& status); - void changeProgress(int progress); - -signals: - - -protected: - virtual void keyPressEvent(QKeyEvent* e); - virtual void closeEvent(QCloseEvent* e); - -private: - Ui::TaskDialog *ui; - - Task* task; -}; - -#endif // TASKDIALOG_H diff --git a/gui/taskdialog.ui b/gui/taskdialog.ui deleted file mode 100644 index 1cdf7978..00000000 --- a/gui/taskdialog.ui +++ /dev/null @@ -1,53 +0,0 @@ - - - TaskDialog - - - - 0 - 0 - 400 - 58 - - - - - 400 - 0 - - - - - 600 - 16777215 - - - - Please wait... - - - - - - Task Status... - - - true - - - - - - - 24 - - - false - - - - - - - - diff --git a/gui/versionselectdialog.cpp b/gui/versionselectdialog.cpp index b14956fd..1e60c7d9 100644 --- a/gui/versionselectdialog.cpp +++ b/gui/versionselectdialog.cpp @@ -20,7 +20,7 @@ #include -#include +#include #include #include @@ -41,11 +41,6 @@ VersionSelectDialog::VersionSelectDialog(BaseVersionList *vlist, QWidget *parent ui->listView->setModel(m_proxyModel); ui->listView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); ui->listView->header()->setSectionResizeMode(0, QHeaderView::Stretch); - - connect(ui->filterSnapshotsCheckbox, SIGNAL(clicked()), SLOT(updateFilterState())); - connect(ui->filterMCNostalgiaCheckbox, SIGNAL(clicked()), SLOT(updateFilterState())); - - updateFilterState(); } VersionSelectDialog::~VersionSelectDialog() @@ -63,7 +58,7 @@ int VersionSelectDialog::exec() void VersionSelectDialog::loadList() { - TaskDialog *taskDlg = new TaskDialog(this); + ProgressDialog *taskDlg = new ProgressDialog(this); Task *loadTask = m_vlist->getLoadTask(); loadTask->setParent(taskDlg); taskDlg->exec(loadTask); @@ -81,10 +76,11 @@ void VersionSelectDialog::on_refreshButton_clicked() loadList(); } -void VersionSelectDialog::updateFilterState() +void VersionSelectDialog::setFilter(int column, QString filter) { - m_proxyModel->setFilterKeyColumn(BaseVersionList::TypeColumn); - + m_proxyModel->setFilterKeyColumn(column); + m_proxyModel->setFilterFixedString(filter); + /* QStringList filteredTypes; if (!ui->filterSnapshotsCheckbox->isChecked()) filteredTypes += "Snapshot"; @@ -96,6 +92,5 @@ void VersionSelectDialog::updateFilterState() regexStr = QString("^((?!%1).)*$").arg(filteredTypes.join('|')); qDebug() << "Filter:" << regexStr; - - m_proxyModel->setFilterRegExp(regexStr); + */ } diff --git a/gui/versionselectdialog.h b/gui/versionselectdialog.h index 57e4d0df..0bb1745a 100644 --- a/gui/versionselectdialog.h +++ b/gui/versionselectdialog.h @@ -43,11 +43,10 @@ public: BaseVersionPtr selectedVersion() const; + void setFilter(int column, QString filter); + private slots: void on_refreshButton_clicked(); - - void updateFilterState(); - private: Ui::VersionSelectDialog *ui; diff --git a/gui/versionselectdialog.ui b/gui/versionselectdialog.ui index 02937794..222f29cf 100644 --- a/gui/versionselectdialog.ui +++ b/gui/versionselectdialog.ui @@ -39,75 +39,6 @@ - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - Show &snapshots? - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - Show &Nostalgia? - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - diff --git a/logic/BaseUpdate.cpp b/logic/BaseUpdate.cpp index b086ab14..02b29d32 100644 --- a/logic/BaseUpdate.cpp +++ b/logic/BaseUpdate.cpp @@ -7,7 +7,5 @@ BaseUpdate::BaseUpdate ( BaseInstance* inst, QObject* parent ) : Task ( parent ) void BaseUpdate::updateDownloadProgress(qint64 current, qint64 total) { - // The progress on the current file is current / total - float currentDLProgress = (float) current / (float) total; - setProgress((int)(currentDLProgress * 100)); // convert to percentage + emit progress(current, total); } \ No newline at end of file diff --git a/logic/InstanceLauncher.cpp b/logic/InstanceLauncher.cpp index a0557b37..f2f792c9 100644 --- a/logic/InstanceLauncher.cpp +++ b/logic/InstanceLauncher.cpp @@ -3,7 +3,7 @@ #include #include "gui/logindialog.h" -#include "gui/taskdialog.h" +#include "gui/ProgressDialog.h" #include "gui/consolewindow.h" #include "logic/tasks/LoginTask.h" #include "logic/MinecraftProcess.h" @@ -48,7 +48,7 @@ void InstanceLauncher::doLogin ( const QString& errorMsg ) { UserInfo uInfo {loginDlg->getUsername(), loginDlg->getPassword() }; - TaskDialog* tDialog = new TaskDialog ( nullptr ); + ProgressDialog* tDialog = new ProgressDialog ( nullptr ); LoginTask* loginTask = new LoginTask ( uInfo, tDialog ); connect ( loginTask, SIGNAL ( succeeded() ),SLOT ( onLoginComplete() ), Qt::QueuedConnection ); connect ( loginTask, SIGNAL ( failed ( QString ) ),SLOT ( doLogin ( QString ) ), Qt::QueuedConnection ); diff --git a/logic/LegacyUpdate.cpp b/logic/LegacyUpdate.cpp index 25be5e7d..0f58e3e3 100644 --- a/logic/LegacyUpdate.cpp +++ b/logic/LegacyUpdate.cpp @@ -59,7 +59,7 @@ void LegacyUpdate::lwjglStart() QNetworkReply * rep = worker->get ( req ); m_reply = QSharedPointer (rep, &QObject::deleteLater); - connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); + connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SIGNAL(progress(qint64,qint64))); connect(worker, SIGNAL(finished(QNetworkReply*)), SLOT(lwjglFinished(QNetworkReply*))); //connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(downloadError(QNetworkReply::NetworkError))); } @@ -97,7 +97,7 @@ void LegacyUpdate::lwjglFinished(QNetworkReply* reply) req.setRawHeader("Host", hostname.toLatin1()); req.setHeader(QNetworkRequest::UserAgentHeader, "Wget/1.14 (linux-gnu)"); QNetworkReply * rep = worker->get(req); - connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); + connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SIGNAL(progress(qint64,qint64))); m_reply = QSharedPointer (rep, &QObject::deleteLater); return; } @@ -232,7 +232,7 @@ void LegacyUpdate::jarStart() legacyDownloadJob.reset(dljob); connect(dljob, SIGNAL(succeeded()), SLOT(jarFinished())); connect(dljob, SIGNAL(failed()), SLOT(jarFailed())); - connect(dljob, SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); + connect(dljob, SIGNAL(progress(qint64,qint64)), SIGNAL(progress(qint64,qint64))); legacyDownloadJob->start(); } diff --git a/logic/OneSixUpdate.cpp b/logic/OneSixUpdate.cpp index 67395818..298ad28a 100644 --- a/logic/OneSixUpdate.cpp +++ b/logic/OneSixUpdate.cpp @@ -78,7 +78,7 @@ void OneSixUpdate::versionFileStart() specificVersionDownloadJob.reset(job); connect(specificVersionDownloadJob.data(), SIGNAL(succeeded()), SLOT(versionFileFinished())); connect(specificVersionDownloadJob.data(), SIGNAL(failed()), SLOT(versionFileFailed())); - connect(specificVersionDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); + connect(specificVersionDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SIGNAL(progress(qint64,qint64))); specificVersionDownloadJob->start(); } @@ -171,7 +171,7 @@ void OneSixUpdate::jarlibStart() } connect(jarlibDownloadJob.data(), SIGNAL(succeeded()), SLOT(jarlibFinished())); connect(jarlibDownloadJob.data(), SIGNAL(failed()), SLOT(jarlibFailed())); - connect(jarlibDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); + connect(jarlibDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SIGNAL(progress(qint64,qint64))); jarlibDownloadJob->start(); } diff --git a/logic/lists/ForgeVersionList.cpp b/logic/lists/ForgeVersionList.cpp index f45b8b6b..412c04fe 100644 --- a/logic/lists/ForgeVersionList.cpp +++ b/logic/lists/ForgeVersionList.cpp @@ -50,21 +50,90 @@ int ForgeVersionList::count() const { return m_vlist.count(); } -/* -bool cmpVersions(BaseVersionPtr first, BaseVersionPtr second) + +int ForgeVersionList::columnCount(const QModelIndex& parent) const { - const BaseVersion & left = *first; - const BaseVersion & right = *second; - return left > right; + return 3; } -void MinecraftVersionList::sort() +QVariant ForgeVersionList::data(const QModelIndex &index, int role) const { - beginResetModel(); - qSort(m_vlist.begin(), m_vlist.end(), cmpVersions); - endResetModel(); + if (!index.isValid()) + return QVariant(); + + if (index.row() > count()) + return QVariant(); + + auto version = m_vlist[index.row()].dynamicCast(); + switch (role) + { + case Qt::DisplayRole: + switch (index.column()) + { + case 0: + return version->name(); + + case 1: + return version->mcver; + + case 2: + return version->typeString(); + default: + return QVariant(); + } + + case Qt::ToolTipRole: + return version->descriptor(); + + case VersionPointerRole: + return qVariantFromValue(m_vlist[index.row()]); + + default: + return QVariant(); + } } -*/ + +QVariant ForgeVersionList::headerData(int section, Qt::Orientation orientation, int role) const +{ + switch (role) + { + case Qt::DisplayRole: + switch (section) + { + case 0: + return "Version"; + + case 1: + return "Minecraft"; + + case 2: + return "Type"; + + default: + return QVariant(); + } + + case Qt::ToolTipRole: + switch (section) + { + case 0: + return "The name of the version."; + + case 1: + return "Minecraft version"; + + case 2: + return "The version's type."; + + default: + return QVariant(); + } + + default: + return QVariant(); + } +} + BaseVersionPtr ForgeVersionList::getLatestStable() const { return BaseVersionPtr(); @@ -99,7 +168,7 @@ void ForgeListLoadTask::executeTask() listJob.reset(job); connect(listJob.data(), SIGNAL(succeeded()), SLOT(list_downloaded())); connect(listJob.data(), SIGNAL(failed()), SLOT(versionFileFailed())); - connect(listJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); + connect(listJob.data(), SIGNAL(progress(qint64,qint64)), SIGNAL(progress(qint64,qint64))); listJob->start(); } @@ -148,7 +217,7 @@ void ForgeListLoadTask::list_downloaded() int build_nr = obj.value("build").toDouble(0); if(!build_nr) continue; - QJsonArray files = root.value("files").toArray(); + QJsonArray files = obj.value("files").toArray(); QString url, jobbuildver, mcver, buildtype, filename; QString changelog_url, installer_url; bool valid = false; diff --git a/logic/lists/ForgeVersionList.h b/logic/lists/ForgeVersionList.h index 8d4a2d46..ca6b27bc 100644 --- a/logic/lists/ForgeVersionList.h +++ b/logic/lists/ForgeVersionList.h @@ -26,7 +26,7 @@ #include "logic/net/DownloadJob.h" class ForgeVersion; -typedef QSharedPointer PtrForgeVersion; +typedef QSharedPointer ForgeVersionPtr; struct ForgeVersion : public BaseVersion { @@ -36,7 +36,7 @@ struct ForgeVersion : public BaseVersion }; virtual QString name() { - return "Forge " + jobbuildver + " (" + mcver + ")"; + return "Forge " + jobbuildver; }; virtual QString typeString() const { @@ -71,8 +71,12 @@ public: virtual BaseVersionPtr getLatestStable() const; + virtual QVariant data(const QModelIndex& index, int role) const; + virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; + virtual int columnCount(const QModelIndex& parent) const; + protected: - QList m_vlist; + QList m_vlist; bool m_loaded; diff --git a/logic/lists/MinecraftVersionList.h b/logic/lists/MinecraftVersionList.h index 8937ba7b..fb28ddfe 100644 --- a/logic/lists/MinecraftVersionList.h +++ b/logic/lists/MinecraftVersionList.h @@ -49,7 +49,7 @@ protected: bool m_loaded; protected slots: - virtual void updateListData(QList versions); + virtual void updateListData(QList versions); }; class MCVListLoadTask : public Task diff --git a/logic/net/DownloadJob.cpp b/logic/net/DownloadJob.cpp index 9b083b6b..3acba050 100644 --- a/logic/net/DownloadJob.cpp +++ b/logic/net/DownloadJob.cpp @@ -5,6 +5,8 @@ #include "ByteArrayDownload.h" #include "CacheDownload.h" +#include + ByteArrayDownloadPtr DownloadJob::add ( QUrl url ) { ByteArrayDownloadPtr ptr (new ByteArrayDownload(url)); diff --git a/logic/net/DownloadJob.h b/logic/net/DownloadJob.h index 69a49e59..c8f6a9d7 100644 --- a/logic/net/DownloadJob.h +++ b/logic/net/DownloadJob.h @@ -5,6 +5,7 @@ #include "FileDownload.h" #include "CacheDownload.h" #include "HttpMetaCache.h" +#include "logic/tasks/ProgressProvider.h" class DownloadJob; typedef QSharedPointer DownloadJobPtr; @@ -12,12 +13,12 @@ typedef QSharedPointer DownloadJobPtr; /** * A single file for the downloader/cache to process. */ -class DownloadJob : public QObject +class DownloadJob : public ProgressProvider { Q_OBJECT public: explicit DownloadJob(QString job_name) - :QObject(), m_job_name(job_name){}; + :ProgressProvider(), m_job_name(job_name){}; ByteArrayDownloadPtr add(QUrl url); FileDownloadPtr add(QUrl url, QString rel_target_path); @@ -37,6 +38,19 @@ public: { return downloads.size(); } + virtual void getProgress(qint64& current, qint64& total) + { + current = current_progress; + total = total_progress; + }; + virtual QString getStatus() const + { + return m_job_name; + }; + virtual bool isRunning() const + { + return m_running; + }; signals: void started(); void progress(qint64 current, qint64 total); @@ -56,5 +70,6 @@ private: qint64 total_progress = 0; int num_succeeded = 0; int num_failed = 0; + bool m_running = false; }; diff --git a/logic/tasks/ProgressProvider.h b/logic/tasks/ProgressProvider.h new file mode 100644 index 00000000..e158eb54 --- /dev/null +++ b/logic/tasks/ProgressProvider.h @@ -0,0 +1,20 @@ +#pragma once +#include +class ProgressProvider : public QObject +{ + Q_OBJECT +protected: + explicit ProgressProvider(QObject* parent = 0): QObject(parent){} +signals: + void started(); + void progress(qint64 current, qint64 total); + void succeeded(); + void failed(QString reason); + void status(QString status); +public: + virtual QString getStatus() const = 0; + virtual void getProgress(qint64 ¤t, qint64 &total) = 0; + virtual bool isRunning() const = 0; +public slots: + virtual void start() = 0; +}; diff --git a/logic/tasks/Task.cpp b/logic/tasks/Task.cpp index 7c148591..c75bcb8f 100644 --- a/logic/tasks/Task.cpp +++ b/logic/tasks/Task.cpp @@ -16,70 +16,56 @@ #include "Task.h" Task::Task(QObject *parent) : - QObject(parent) + ProgressProvider(parent) { } QString Task::getStatus() const { - return status; + return m_status; } -void Task::setStatus(const QString &status) +void Task::setStatus(const QString &new_status) { - this->status = status; - emitStatusChange(status); + m_status = new_status; + emit status(new_status); } -int Task::getProgress() const +void Task::setProgress(int new_progress) { - return progress; + m_progress = new_progress; + emit progress(new_progress, 100); } -void Task::setProgress(int progress) +void Task::getProgress(qint64& current, qint64& total) { - this->progress = progress; - emitProgressChange(progress); + current = m_progress; + total = 100; } -void Task::startTask() -{ - emitStarted(); - executeTask(); -} -void Task::emitStarted() +void Task::start() { - running = true; + m_running = true; emit started(); + executeTask(); } void Task::emitFailed(QString reason) { - running = false; + m_running = false; emit failed(reason); } void Task::emitSucceeded() { - running = false; + m_running = false; emit succeeded(); } bool Task::isRunning() const { - return running; -} - - -void Task::emitStatusChange(const QString &status) -{ - emit statusChanged(status); -} - -void Task::emitProgressChange(int progress) -{ - emit progressChanged(progress); + return m_running; } diff --git a/logic/tasks/Task.h b/logic/tasks/Task.h index 91852b0f..cfe71c51 100644 --- a/logic/tasks/Task.h +++ b/logic/tasks/Task.h @@ -13,53 +13,37 @@ * limitations under the License. */ -#ifndef TASK_H -#define TASK_H +#pragma once #include #include +#include "ProgressProvider.h" -class Task : public QObject +class Task : public ProgressProvider { Q_OBJECT public: explicit Task(QObject *parent = 0); - QString getStatus() const; - int getProgress() const; - bool isRunning() const; + virtual QString getStatus() const; + virtual void getProgress(qint64& current, qint64& total); + virtual bool isRunning() const; public slots: - void startTask(); - -protected slots: - void setStatus(const QString& status); - void setProgress(int progress); - -signals: - void started(); - void failed(QString reason); - void succeeded(); - - void statusChanged(Task* task, const QString& status); - void progressChanged(Task* task, int progress); - - void statusChanged(const QString& status); - void progressChanged(int progress); + virtual void start(); protected: virtual void executeTask() = 0; - virtual void emitStarted(); - virtual void emitFailed(QString reason); virtual void emitSucceeded(); + virtual void emitFailed(QString reason); + +protected slots: + void setStatus(const QString& status); + void setProgress(int progress); - virtual void emitStatusChange(const QString &status); - virtual void emitProgressChange(int progress); - - QString status; - int progress; - bool running = false; +protected: + QString m_status; + int m_progress = 0; + bool m_running = false; }; - -#endif // TASK_H -- cgit From ceca6959d2a7f258d62ac4f589095b65084706c3 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 22 Sep 2013 04:21:36 +0200 Subject: Working 1.6 modding (currently only forge) --- .clang-format | 24 ++++ CMakeLists.txt | 144 +++++++++------------ MultiMC.cpp | 70 ++++------- MultiMC.h | 39 +++--- gui/IconPickerDialog.cpp | 4 +- gui/LegacyModEditDialog.cpp | 2 +- gui/OneSixModEditDialog.cpp | 179 ++++++++++++++++----------- gui/OneSixModEditDialog.h | 3 +- gui/instancedelegate.h | 2 +- gui/lwjglselectdialog.cpp | 6 +- gui/mainwindow.cpp | 6 +- gui/mainwindow.ui | 2 +- gui/newinstancedialog.cpp | 2 +- gui/settingsdialog.cpp | 4 +- logic/BaseInstance.cpp | 2 +- logic/BaseInstance.h | 2 +- logic/ForgeInstaller.cpp | 125 +++++++++++++++++++ logic/ForgeInstaller.h | 25 ++++ logic/LegacyUpdate.cpp | 4 +- logic/ModList.h | 3 + logic/OneSixInstance.cpp | 114 +++++++++-------- logic/OneSixLibrary.cpp | 98 +++++++++++---- logic/OneSixLibrary.h | 26 ++-- logic/OneSixRule.cpp | 66 +++++++++- logic/OneSixRule.h | 6 +- logic/OneSixUpdate.cpp | 85 +++++++------ logic/OneSixVersion.cpp | 261 ++++++++++++++++++++++++++++++++++----- logic/OneSixVersion.h | 60 +++++---- logic/OpSys.cpp | 11 ++ logic/OpSys.h | 1 + logic/VersionFactory.cpp | 196 ----------------------------- logic/VersionFactory.h | 24 ---- logic/lists/ForgeVersionList.cpp | 11 +- logic/lists/ForgeVersionList.h | 52 ++++---- logic/tasks/LoginTask.cpp | 2 +- 35 files changed, 992 insertions(+), 669 deletions(-) create mode 100644 .clang-format create mode 100644 logic/ForgeInstaller.cpp create mode 100644 logic/ForgeInstaller.h delete mode 100644 logic/VersionFactory.cpp delete mode 100644 logic/VersionFactory.h (limited to 'logic/LegacyUpdate.cpp') diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..167a8fa7 --- /dev/null +++ b/.clang-format @@ -0,0 +1,24 @@ +UseTab: true +IndentWidth: 4 +TabWidth: 4 +ConstructorInitializerIndentWidth: 4 +AccessModifierOffset: -4 +IndentCaseLabels: false +IndentFunctionDeclarationAfterType: false +NamespaceIndentation: None + +BreakBeforeBraces: Allman +AllowShortIfStatementsOnASingleLine: false +ColumnLimit: 96 +MaxEmptyLinesToKeep: 1 + +Standard: Cpp11 +Cpp11BracedListStyle: true + +SpacesInParentheses: false +SpaceInEmptyParentheses: false +SpacesInCStyleCastParentheses: false +SpaceAfterControlStatementKeyword: true + +AlignTrailingComments: true +SpacesBeforeTrailingComments: 1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f09e324..aa7a91f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,165 +147,143 @@ ADD_DEFINITIONS(-DLIBGROUPVIEW_STATIC) ################################ FILES ################################ -######## Headers ######## -SET(MULTIMC_HEADERS +######## Sources and headers ######## +SET(MULTIMC_SOURCES +# Application base MultiMC.h +MultiMC.cpp MultiMCVersion.h +# GUI gui/mainwindow.h +gui/mainwindow.cpp gui/settingsdialog.h +gui/settingsdialog.cpp gui/newinstancedialog.h +gui/newinstancedialog.cpp gui/logindialog.h +gui/logindialog.cpp gui/ProgressDialog.h +gui/ProgressDialog.cpp gui/aboutdialog.h +gui/aboutdialog.cpp gui/consolewindow.h +gui/consolewindow.cpp gui/instancedelegate.h +gui/instancedelegate.cpp gui/versionselectdialog.h +gui/versionselectdialog.cpp gui/lwjglselectdialog.h +gui/lwjglselectdialog.cpp gui/instancesettings.h +gui/instancesettings.cpp gui/IconPickerDialog.h +gui/IconPickerDialog.cpp gui/LegacyModEditDialog.h +gui/LegacyModEditDialog.cpp gui/OneSixModEditDialog.h +gui/OneSixModEditDialog.cpp gui/ModEditDialogCommon.h +gui/ModEditDialogCommon.cpp gui/ModListView.h +gui/ModListView.cpp gui/LabeledToolButton.h +gui/LabeledToolButton.cpp gui/EditNotesDialog.h +gui/EditNotesDialog.cpp # Base classes and infrastructure logic/BaseVersion.h logic/MinecraftVersion.h logic/InstanceFactory.h +logic/InstanceFactory.cpp logic/BaseUpdate.h +logic/BaseUpdate.cpp logic/BaseInstance.h +logic/BaseInstance.cpp logic/BaseInstance_p.h + logic/MinecraftProcess.h +logic/MinecraftProcess.cpp logic/Mod.h +logic/Mod.cpp logic/ModList.h +logic/ModList.cpp # Basic instance launcher for starting from terminal logic/InstanceLauncher.h +logic/InstanceLauncher.cpp # network stuffs logic/net/Download.h logic/net/FileDownload.h +logic/net/FileDownload.cpp logic/net/ByteArrayDownload.h +logic/net/ByteArrayDownload.cpp logic/net/CacheDownload.h +logic/net/CacheDownload.cpp logic/net/DownloadJob.h +logic/net/DownloadJob.cpp logic/net/HttpMetaCache.h +logic/net/HttpMetaCache.cpp # legacy instances logic/LegacyInstance.h +logic/LegacyInstance.cpp logic/LegacyInstance_p.h logic/LegacyUpdate.h +logic/LegacyUpdate.cpp logic/LegacyForge.h +logic/LegacyForge.cpp # 1.6 instances logic/OneSixAssets.h +logic/OneSixAssets.cpp logic/OneSixInstance.h +logic/OneSixInstance.cpp logic/OneSixInstance_p.h logic/OneSixUpdate.h -logic/OneSixVersion.h -logic/OneSixLibrary.h -logic/OneSixRule.h -logic/VersionFactory.h -logic/OpSys.h - - -# Nostalgia -logic/NostalgiaInstance.h - -# Lists -logic/lists/InstanceList.h -logic/lists/IconList.h -logic/lists/BaseVersionList.h -logic/lists/MinecraftVersionList.h -logic/lists/LwjglVersionList.h -logic/lists/ForgeVersionList.h - -# misc model/view -logic/EnabledItemFilter.h - -# Tasks -logic/tasks/Task.h -logic/tasks/LoginTask.h -logic/tasks/ProgressProvider.h -) - - -######## Sources ######## -SET(MULTIMC_SOURCES -MultiMC.cpp - -gui/mainwindow.cpp -gui/settingsdialog.cpp -gui/newinstancedialog.cpp -gui/logindialog.cpp -gui/aboutdialog.cpp -gui/consolewindow.cpp -gui/instancedelegate.cpp -gui/versionselectdialog.cpp -gui/lwjglselectdialog.cpp -gui/instancesettings.cpp - -gui/ProgressDialog.cpp -gui/IconPickerDialog.cpp -gui/LegacyModEditDialog.cpp -gui/OneSixModEditDialog.cpp -gui/ModEditDialogCommon.cpp -gui/ModListView.cpp -gui/LabeledToolButton.cpp -gui/EditNotesDialog.cpp - -# Base classes and infrastructure -logic/InstanceFactory.cpp -logic/BaseUpdate.cpp -logic/BaseInstance.cpp -logic/MinecraftProcess.cpp -logic/Mod.cpp -logic/ModList.cpp - -# Basic instance launcher for starting from terminal -logic/InstanceLauncher.cpp - -# network stuffs - to be moved into a depend lib ~_~ -logic/net/FileDownload.cpp -logic/net/ByteArrayDownload.cpp -logic/net/CacheDownload.cpp -logic/net/DownloadJob.cpp -logic/net/HttpMetaCache.cpp - -# legacy instances -logic/LegacyInstance.cpp -logic/LegacyUpdate.cpp -logic/LegacyForge.cpp - -# 1.6 instances -logic/OneSixAssets.cpp -logic/OneSixInstance.cpp logic/OneSixUpdate.cpp +logic/OneSixVersion.h logic/OneSixVersion.cpp +logic/OneSixLibrary.h logic/OneSixLibrary.cpp +logic/OneSixRule.h logic/OneSixRule.cpp -logic/VersionFactory.cpp +logic/OpSys.h logic/OpSys.cpp +logic/ForgeInstaller.h +logic/ForgeInstaller.cpp # Nostalgia +logic/NostalgiaInstance.h logic/NostalgiaInstance.cpp # Lists +logic/lists/InstanceList.h logic/lists/InstanceList.cpp +logic/lists/IconList.h logic/lists/IconList.cpp +logic/lists/BaseVersionList.h logic/lists/BaseVersionList.cpp +logic/lists/MinecraftVersionList.h logic/lists/MinecraftVersionList.cpp +logic/lists/LwjglVersionList.h logic/lists/LwjglVersionList.cpp +logic/lists/ForgeVersionList.h logic/lists/ForgeVersionList.cpp # misc model/view +logic/EnabledItemFilter.h logic/EnabledItemFilter.cpp # Tasks +logic/tasks/ProgressProvider.h +logic/tasks/Task.h logic/tasks/Task.cpp +logic/tasks/LoginTask.h logic/tasks/LoginTask.cpp + ) @@ -328,7 +306,7 @@ gui/OneSixModEditDialog.ui gui/EditNotesDialog.ui ) -set (FILES_TO_TRANSLATE ${FILES_TO_TRANSLATE} ${MULTIMC_SOURCES} ${MULTIMC_UIS} ${MULTIMC_HEADERS}) +set (FILES_TO_TRANSLATE ${FILES_TO_TRANSLATE} ${MULTIMC_SOURCES} ${MULTIMC_UIS}) ######## Windows resource files ######## @@ -362,7 +340,7 @@ QT5_ADD_RESOURCES(MULTIMC_QRC multimc.qrc) # Add executable ADD_EXECUTABLE(MultiMC MACOSX_BUNDLE WIN32 - ${MULTIMC_SOURCES} ${MULTIMC_HEADERS} ${MULTIMC_UI} ${MULTIMC_QRC} ${MULTIMC_RCS}) + ${MULTIMC_SOURCES} ${MULTIMC_UI} ${MULTIMC_QRC} ${MULTIMC_RCS}) # Link QT5_USE_MODULES(MultiMC Widgets Network Xml) diff --git a/MultiMC.cpp b/MultiMC.cpp index 4b5b40b2..decc22bf 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -123,7 +123,7 @@ MultiMC::MultiMC ( int& argc, char** argv ) initGlobalSettings(); // and instances - m_instances = new InstanceList(m_settings->get("InstanceDir").toString(),this); + m_instances.reset(new InstanceList(m_settings->get("InstanceDir").toString(),this)); std::cout << "Loading Instances..." << std::endl; m_instances->loadList(); @@ -131,7 +131,7 @@ MultiMC::MultiMC ( int& argc, char** argv ) initHttpMetaCache(); // create the global network manager - m_qnam = new QNetworkAccessManager(this); + m_qnam.reset(new QNetworkAccessManager(this)); // Register meta types. qRegisterMetaType("LoginResponse"); @@ -152,80 +152,59 @@ MultiMC::~MultiMC() { if(m_mmc_translator) { - removeTranslator(m_mmc_translator); - delete m_mmc_translator; - m_mmc_translator = nullptr; + removeTranslator(m_mmc_translator.data()); } if(m_qt_translator) { - removeTranslator(m_qt_translator); - delete m_qt_translator; - m_qt_translator = nullptr; + removeTranslator(m_qt_translator.data()); } - if(m_icons) - { - delete m_icons; - m_icons = nullptr; - } - if(m_lwjgllist) - { - delete m_lwjgllist; - m_lwjgllist = nullptr; - } - if(m_minecraftlist) - { - delete m_minecraftlist; - m_minecraftlist = nullptr; - } - delete m_settings; - delete m_metacache; } void MultiMC::initTranslations() { - m_qt_translator = new QTranslator(); + m_qt_translator.reset(new QTranslator()); if(m_qt_translator->load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) { std::cout << "Loading Qt Language File for " << QLocale::system().name().toLocal8Bit().constData() << "..."; - if(!installTranslator(m_qt_translator)) + if(!installTranslator(m_qt_translator.data())) { std::cout << " failed."; + m_qt_translator.reset(); } std::cout << std::endl; } else { - delete m_qt_translator; - m_qt_translator = nullptr; + m_qt_translator.reset(); } - m_mmc_translator = new QTranslator(); + m_mmc_translator.reset(new QTranslator()); if(m_mmc_translator->load("mmc_" + QLocale::system().name(), QDir("translations").absolutePath())) { std::cout << "Loading MMC Language File for " << QLocale::system().name().toLocal8Bit().constData() << "..."; - if(!installTranslator(m_mmc_translator)) + if(!installTranslator(m_mmc_translator.data())) { std::cout << " failed."; + m_mmc_translator.reset(); } std::cout << std::endl; } else { - delete m_mmc_translator; - m_mmc_translator = nullptr; + m_mmc_translator.reset(); } } void MultiMC::initGlobalSettings() { - m_settings = new INISettingsObject("multimc.cfg", this); + m_settings.reset(new INISettingsObject("multimc.cfg", this)); // Updates m_settings->registerSetting(new Setting("UseDevBuilds", false)); m_settings->registerSetting(new Setting("AutoUpdate", true)); @@ -278,7 +257,7 @@ void MultiMC::initGlobalSettings() void MultiMC::initHttpMetaCache() { - m_metacache = new HttpMetaCache("metacache"); + m_metacache.reset(new HttpMetaCache("metacache")); m_metacache->addBase("assets", QDir("assets").absolutePath()); m_metacache->addBase("versions", QDir("versions").absolutePath()); m_metacache->addBase("libraries", QDir("libraries").absolutePath()); @@ -287,37 +266,38 @@ void MultiMC::initHttpMetaCache() } -IconList* MultiMC::icons() +QSharedPointer MultiMC::icons() { if ( !m_icons ) { - m_icons = new IconList; + m_icons.reset(new IconList); } return m_icons; } -LWJGLVersionList* MultiMC::lwjgllist() +QSharedPointer MultiMC::lwjgllist() { if ( !m_lwjgllist ) { - m_lwjgllist = new LWJGLVersionList(); + m_lwjgllist.reset(new LWJGLVersionList()); } return m_lwjgllist; } -ForgeVersionList* MultiMC::forgelist() + +QSharedPointer MultiMC::forgelist() { if ( !m_forgelist ) { - m_forgelist = new ForgeVersionList(); + m_forgelist.reset(new ForgeVersionList()); } return m_forgelist; } -MinecraftVersionList* MultiMC::minecraftlist() +QSharedPointer MultiMC::minecraftlist() { if ( !m_minecraftlist ) { - m_minecraftlist = new MinecraftVersionList(); + m_minecraftlist.reset(new MinecraftVersionList()); } return m_minecraftlist; } @@ -345,4 +325,6 @@ int main(int argc, char *argv[]) } } -#include "MultiMC.moc" \ No newline at end of file +#include "MultiMC.moc" + + diff --git a/MultiMC.h b/MultiMC.h index d3e92584..1c1298e2 100644 --- a/MultiMC.h +++ b/MultiMC.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "MultiMCVersion.h" #include "config.h" @@ -33,17 +34,17 @@ public: MultiMC ( int& argc, char** argv ); virtual ~MultiMC(); - SettingsObject * settings() + QSharedPointer settings() { return m_settings; }; - InstanceList * instances() + QSharedPointer instances() { return m_instances; }; - IconList * icons(); + QSharedPointer icons(); Status status() { @@ -55,21 +56,21 @@ public: return m_version; } - QNetworkAccessManager * qnam() + QSharedPointer qnam() { return m_qnam; } - HttpMetaCache * metacache() + QSharedPointer metacache() { return m_metacache; } - LWJGLVersionList * lwjgllist(); + QSharedPointer lwjgllist(); - ForgeVersionList * forgelist(); + QSharedPointer forgelist(); - MinecraftVersionList * minecraftlist(); + QSharedPointer minecraftlist(); private: void initGlobalSettings(); @@ -77,17 +78,17 @@ private: void initTranslations(); private: - QTranslator * m_qt_translator = nullptr; - QTranslator * m_mmc_translator = nullptr; - SettingsObject * m_settings = nullptr; - InstanceList * m_instances = nullptr; - IconList * m_icons = nullptr; - QNetworkAccessManager * m_qnam = nullptr; - HttpMetaCache * m_metacache = nullptr; - Status m_status = MultiMC::Failed; - LWJGLVersionList * m_lwjgllist = nullptr; - ForgeVersionList * m_forgelist = nullptr; - MinecraftVersionList * m_minecraftlist = nullptr; + QSharedPointer m_qt_translator; + QSharedPointer m_mmc_translator; + QSharedPointer m_settings; + QSharedPointer m_instances; + QSharedPointer m_icons; + QSharedPointer m_qnam; + QSharedPointer m_metacache; + QSharedPointer m_lwjgllist; + QSharedPointer m_forgelist; + QSharedPointer m_minecraftlist; + Status m_status = MultiMC::Failed; MultiMCVersion m_version = {VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION, VERSION_BUILD}; }; \ No newline at end of file diff --git a/gui/IconPickerDialog.cpp b/gui/IconPickerDialog.cpp index f3947d21..8f5d8256 100644 --- a/gui/IconPickerDialog.cpp +++ b/gui/IconPickerDialog.cpp @@ -39,7 +39,7 @@ IconPickerDialog::IconPickerDialog(QWidget *parent) : contentsWidget->installEventFilter(this); - contentsWidget->setModel(MMC->icons()); + contentsWidget->setModel(MMC->icons().data()); auto buttonAdd = ui->buttonBox->addButton(tr("Add Icon"),QDialogButtonBox::ResetRole); auto buttonRemove = ui->buttonBox->addButton(tr("Remove Icon"),QDialogButtonBox::ResetRole); @@ -119,7 +119,7 @@ void IconPickerDialog::selectionChanged ( QItemSelection selected, QItemSelectio int IconPickerDialog::exec ( QString selection ) { - IconList * list = MMC->icons(); + auto list = MMC->icons(); auto contentsWidget = ui->iconView; selectedIconKey = selection; diff --git a/gui/LegacyModEditDialog.cpp b/gui/LegacyModEditDialog.cpp index 1a1198b1..20296769 100644 --- a/gui/LegacyModEditDialog.cpp +++ b/gui/LegacyModEditDialog.cpp @@ -199,7 +199,7 @@ void LegacyModEditDialog::on_addCoreBtn_clicked() } void LegacyModEditDialog::on_addForgeBtn_clicked() { - VersionSelectDialog vselect(MMC->forgelist(), this); + VersionSelectDialog vselect(MMC->forgelist().data(), this); vselect.setFilter(1, m_inst->intendedVersionId()); if (vselect.exec() && vselect.selectedVersion()) { diff --git a/gui/OneSixModEditDialog.cpp b/gui/OneSixModEditDialog.cpp index 7cbb9cbd..94fea933 100644 --- a/gui/OneSixModEditDialog.cpp +++ b/gui/OneSixModEditDialog.cpp @@ -1,9 +1,9 @@ /* 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 @@ -20,6 +20,7 @@ #include "logic/OneSixVersion.h" #include "logic/EnabledItemFilter.h" #include "logic/lists/ForgeVersionList.h" +#include #include "gui/versionselectdialog.h" #include "ProgressDialog.h" @@ -30,30 +31,33 @@ #include #include -OneSixModEditDialog::OneSixModEditDialog(OneSixInstance * inst, QWidget *parent): - m_inst(inst), - QDialog(parent), - ui(new Ui::OneSixModEditDialog) +OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent) + : m_inst(inst), QDialog(parent), ui(new Ui::OneSixModEditDialog) { ui->setupUi(this); - //libraries! + // libraries! + + m_version = m_inst->getFullVersion(); + if (m_version) { - m_version = m_inst->getFullVersion(); - main_model = new EnabledItemFilter(this); main_model->setActive(true); main_model->setSourceModel(m_version.data()); ui->libraryTreeView->setModel(main_model); - ui->libraryTreeView->installEventFilter( this ); + ui->libraryTreeView->installEventFilter(this); ui->mainClassEdit->setText(m_version->mainClass); - updateButtons(); + updateVersionControls(); + } + else + { + disableVersionControls(); } // Loader mods { ensureFolderPathExists(m_inst->loaderModsDir()); m_mods = m_inst->loaderModList(); ui->loaderModTreeView->setModel(m_mods.data()); - ui->loaderModTreeView->installEventFilter( this ); + ui->loaderModTreeView->installEventFilter(this); m_mods->startWatching(); } // resource packs @@ -61,7 +65,7 @@ OneSixModEditDialog::OneSixModEditDialog(OneSixInstance * inst, QWidget *parent) ensureFolderPathExists(m_inst->resourcePacksDir()); m_resourcepacks = m_inst->resourcePackList(); ui->resPackTreeView->setModel(m_resourcepacks.data()); - ui->resPackTreeView->installEventFilter( this ); + ui->resPackTreeView->installEventFilter(this); m_resourcepacks->startWatching(); } } @@ -73,48 +77,62 @@ OneSixModEditDialog::~OneSixModEditDialog() delete ui; } -void OneSixModEditDialog::updateButtons() +void OneSixModEditDialog::updateVersionControls() { bool customVersion = m_inst->versionIsCustom(); ui->customizeBtn->setEnabled(!customVersion); ui->revertBtn->setEnabled(customVersion); + ui->forgeBtn->setEnabled(true); } +void OneSixModEditDialog::disableVersionControls() +{ + ui->customizeBtn->setEnabled(false); + ui->revertBtn->setEnabled(false); + ui->forgeBtn->setEnabled(false); +} void OneSixModEditDialog::on_customizeBtn_clicked() { - if(m_inst->customizeVersion()) + if (m_inst->customizeVersion()) { m_version = m_inst->getFullVersion(); main_model->setSourceModel(m_version.data()); - updateButtons(); + updateVersionControls(); } } void OneSixModEditDialog::on_revertBtn_clicked() { - auto reply = QMessageBox::question(this, tr("Revert?"), tr("Do you want to revert the version of this instance to its original configuration?"),QMessageBox::Yes|QMessageBox::No); + auto reply = QMessageBox::question( + this, tr("Revert?"), tr("Do you want to revert the " + "version of this instance to its original configuration?"), + QMessageBox::Yes | QMessageBox::No); if (reply == QMessageBox::Yes) { - if(m_inst->revertCustomVersion()) + if (m_inst->revertCustomVersion()) { m_version = m_inst->getFullVersion(); main_model->setSourceModel(m_version.data()); - updateButtons(); + updateVersionControls(); } } } - void OneSixModEditDialog::on_forgeBtn_clicked() { - VersionSelectDialog vselect(MMC->forgelist(), this); + VersionSelectDialog vselect(MMC->forgelist().data(), this); vselect.setFilter(1, m_inst->currentVersionId()); if (vselect.exec() && vselect.selectedVersion()) { - if(m_inst->versionIsCustom()) + 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); + 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(); @@ -122,24 +140,38 @@ void OneSixModEditDialog::on_forgeBtn_clicked() { m_version = m_inst->getFullVersion(); main_model->setSourceModel(m_version.data()); - updateButtons(); + updateVersionControls(); } } - else return; + else + return; + } + else + { + m_inst->customizeVersion(); + m_version = m_inst->getFullVersion(); + main_model->setSourceModel(m_version.data()); + updateVersionControls(); } - ForgeVersionPtr forge = vselect.selectedVersion().dynamicCast(); - if(!forge) + ForgeVersionPtr forgeVersion = vselect.selectedVersion().dynamicCast(); + if (!forgeVersion) return; - auto entry = MMC->metacache()->resolveEntry("minecraftforge", forge->filename); - if(entry->stale) + auto entry = MMC->metacache()->resolveEntry("minecraftforge", forgeVersion->filename); + if (entry->stale) { - DownloadJob * fjob = new DownloadJob("Forge download"); - fjob->add(forge->universal_url, entry); + DownloadJob *fjob = new DownloadJob("Forge download"); + fjob->add(forgeVersion->installer_url, entry); ProgressDialog dlg(this); dlg.exec(fjob); - if(dlg.result() == QDialog::Accepted) + if (dlg.result() == QDialog::Accepted) { // install + QString forgePath = entry->getFullPath(); + ForgeInstaller forge(forgePath, forgeVersion->universal_url); + if (!forge.apply(m_version)) + { + // failure notice + } } else { @@ -149,55 +181,60 @@ void OneSixModEditDialog::on_forgeBtn_clicked() else { // install + QString forgePath = entry->getFullPath(); + ForgeInstaller forge(forgePath, forgeVersion->universal_url); + if (!forge.apply(m_version)) + { + // failure notice + } } } } -bool OneSixModEditDialog::loaderListFilter ( QKeyEvent* keyEvent ) +bool OneSixModEditDialog::loaderListFilter(QKeyEvent *keyEvent) { - switch(keyEvent->key()) + switch (keyEvent->key()) { - case Qt::Key_Delete: - on_rmModBtn_clicked(); - return true; - case Qt::Key_Plus: - on_addModBtn_clicked(); - return true; - default: - break; + case Qt::Key_Delete: + on_rmModBtn_clicked(); + return true; + case Qt::Key_Plus: + on_addModBtn_clicked(); + return true; + default: + break; } - return QDialog::eventFilter( ui->loaderModTreeView, keyEvent ); + return QDialog::eventFilter(ui->loaderModTreeView, keyEvent); } -bool OneSixModEditDialog::resourcePackListFilter ( QKeyEvent* keyEvent ) +bool OneSixModEditDialog::resourcePackListFilter(QKeyEvent *keyEvent) { - switch(keyEvent->key()) + switch (keyEvent->key()) { - case Qt::Key_Delete: - on_rmResPackBtn_clicked(); - return true; - case Qt::Key_Plus: - on_addResPackBtn_clicked(); - return true; - default: - break; + case Qt::Key_Delete: + on_rmResPackBtn_clicked(); + return true; + case Qt::Key_Plus: + on_addResPackBtn_clicked(); + return true; + default: + break; } - return QDialog::eventFilter( ui->resPackTreeView, keyEvent ); + return QDialog::eventFilter(ui->resPackTreeView, keyEvent); } - -bool OneSixModEditDialog::eventFilter ( QObject* obj, QEvent* ev ) +bool OneSixModEditDialog::eventFilter(QObject *obj, QEvent *ev) { if (ev->type() != QEvent::KeyPress) { - return QDialog::eventFilter( obj, ev ); + return QDialog::eventFilter(obj, ev); } - QKeyEvent *keyEvent = static_cast(ev); - if(obj == ui->loaderModTreeView) + QKeyEvent *keyEvent = static_cast(ev); + if (obj == ui->loaderModTreeView) return loaderListFilter(keyEvent); - if(obj == ui->resPackTreeView) + if (obj == ui->resPackTreeView) return resourcePackListFilter(keyEvent); - return QDialog::eventFilter( obj, ev ); + return QDialog::eventFilter(obj, ev); } void OneSixModEditDialog::on_buttonBox_rejected() @@ -207,8 +244,9 @@ void OneSixModEditDialog::on_buttonBox_rejected() void OneSixModEditDialog::on_addModBtn_clicked() { - QStringList fileNames = QFileDialog::getOpenFileNames(this, QApplication::translate("LegacyModEditDialog", "Select Loader Mods")); - for(auto filename:fileNames) + QStringList fileNames = QFileDialog::getOpenFileNames( + this, QApplication::translate("LegacyModEditDialog", "Select Loader Mods")); + for (auto filename : fileNames) { m_mods->stopWatching(); m_mods->installMod(QFileInfo(filename)); @@ -219,8 +257,8 @@ void OneSixModEditDialog::on_rmModBtn_clicked() { int first, last; auto list = ui->loaderModTreeView->selectionModel()->selectedRows(); - - if(!lastfirst(list, first, last)) + + if (!lastfirst(list, first, last)) return; m_mods->stopWatching(); m_mods->deleteMods(first, last); @@ -231,11 +269,11 @@ void OneSixModEditDialog::on_viewModBtn_clicked() openDirInDefaultProgram(m_inst->loaderModsDir(), true); } - void OneSixModEditDialog::on_addResPackBtn_clicked() { - QStringList fileNames = QFileDialog::getOpenFileNames(this, QApplication::translate("LegacyModEditDialog", "Select Resource Packs")); - for(auto filename:fileNames) + QStringList fileNames = QFileDialog::getOpenFileNames( + this, QApplication::translate("LegacyModEditDialog", "Select Resource Packs")); + for (auto filename : fileNames) { m_resourcepacks->stopWatching(); m_resourcepacks->installMod(QFileInfo(filename)); @@ -246,8 +284,8 @@ void OneSixModEditDialog::on_rmResPackBtn_clicked() { int first, last; auto list = ui->resPackTreeView->selectionModel()->selectedRows(); - - if(!lastfirst(list, first, last)) + + if (!lastfirst(list, first, last)) return; m_resourcepacks->stopWatching(); m_resourcepacks->deleteMods(first, last); @@ -257,4 +295,3 @@ void OneSixModEditDialog::on_viewResPackBtn_clicked() { openDirInDefaultProgram(m_inst->resourcePacksDir(), true); } - diff --git a/gui/OneSixModEditDialog.h b/gui/OneSixModEditDialog.h index 714c911a..e70bd73f 100644 --- a/gui/OneSixModEditDialog.h +++ b/gui/OneSixModEditDialog.h @@ -44,7 +44,8 @@ private slots: void on_forgeBtn_clicked(); void on_customizeBtn_clicked(); void on_revertBtn_clicked(); - void updateButtons(); + void updateVersionControls(); + void disableVersionControls(); protected: bool eventFilter(QObject *obj, QEvent *ev); bool loaderListFilter( QKeyEvent* ev ); diff --git a/gui/instancedelegate.h b/gui/instancedelegate.h index c80f95a5..56bc34ba 100644 --- a/gui/instancedelegate.h +++ b/gui/instancedelegate.h @@ -9,4 +9,4 @@ public: protected: void paint ( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const; -}; \ No newline at end of file +}; diff --git a/gui/lwjglselectdialog.cpp b/gui/lwjglselectdialog.cpp index 7c424a6c..e48bb975 100644 --- a/gui/lwjglselectdialog.cpp +++ b/gui/lwjglselectdialog.cpp @@ -26,10 +26,10 @@ LWJGLSelectDialog::LWJGLSelectDialog(QWidget *parent) : ui->setupUi(this); ui->labelStatus->setVisible(false); auto lwjgllist = MMC->lwjgllist(); - ui->lwjglListView->setModel(lwjgllist); + ui->lwjglListView->setModel(lwjgllist.data()); - connect(lwjgllist, SIGNAL(loadingStateUpdated(bool)), SLOT(loadingStateUpdated(bool))); - connect(lwjgllist, SIGNAL(loadListFailed(QString)), SLOT(loadingFailed(QString))); + connect(lwjgllist.data(), SIGNAL(loadingStateUpdated(bool)), SLOT(loadingStateUpdated(bool))); + connect(lwjgllist.data(), SIGNAL(loadListFailed(QString)), SLOT(loadingFailed(QString))); loadingStateUpdated(lwjgllist->isLoading()); } diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 6f707236..d3b167fa 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -124,7 +124,7 @@ MainWindow::MainWindow ( QWidget *parent ) //proxymodel->setDynamicSortFilter ( true ); // FIXME: instList should be global-ish, or at least not tied to the main window... maybe the application itself? - proxymodel->setSourceModel ( MMC->instances() ); + proxymodel->setSourceModel ( MMC->instances().data() ); proxymodel->sort ( 0 ); view->setFrameShape ( QFrame::NoFrame ); view->setModel ( proxymodel ); @@ -149,7 +149,7 @@ MainWindow::MainWindow ( QWidget *parent ) ); // model reset -> selection is invalid. All the instance pointers are wrong. // FIXME: stop using POINTERS everywhere - connect(MMC->instances() ,SIGNAL(dataIsInvalid()),SLOT(selectionBad())); + connect(MMC->instances().data() ,SIGNAL(dataIsInvalid()),SLOT(selectionBad())); // run the things that load and download other things... FIXME: this is NOT the place // FIXME: invisible actions in the background = NOPE. @@ -601,7 +601,7 @@ void MainWindow::on_actionChangeInstMCVersion_triggered() if (view->selectionModel()->selectedIndexes().count() < 1) return; - VersionSelectDialog vselect(m_selectedInstance->versionList(), this); + VersionSelectDialog vselect(m_selectedInstance->versionList().data(), this); if (vselect.exec() && vselect.selectedVersion()) { m_selectedInstance->setIntendedVersionId(vselect.selectedVersion()->descriptor()); diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index 4360f5f6..1cda7a34 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -440,7 +440,7 @@ Meow - <html><head/><body><p align="center"><span style=" font-weight:600; color:#ff0004;">Catnatok!</span></p><p align="center">Or just a cat with a ball of yarn?</p><p align="center"><span style=" font-style:italic;">WHO KNOWS?!</span></p><p align="center"><img src=":/icons/instances/tnt"/></p></body></html> + <html><head/><body><p align="center"><span style=" font-weight:600; color:#ff0004;">Catnarok!</span></p><p align="center">Or just a cat with a ball of yarn?</p><p align="center"><span style=" font-style:italic;">WHO KNOWS?!</span></p><p align="center"><img src=":/icons/instances/tnt"/></p></body></html> diff --git a/gui/newinstancedialog.cpp b/gui/newinstancedialog.cpp index 6604d03b..859077d9 100644 --- a/gui/newinstancedialog.cpp +++ b/gui/newinstancedialog.cpp @@ -96,7 +96,7 @@ BaseVersionPtr NewInstanceDialog::selectedVersion() const void NewInstanceDialog::on_btnChangeVersion_clicked() { - VersionSelectDialog vselect(MMC->minecraftlist(), this); + VersionSelectDialog vselect(MMC->minecraftlist().data(), this); vselect.exec(); if (vselect.result() == QDialog::Accepted) { diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index a5283b36..9736c1c7 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -27,7 +27,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) : { ui->setupUi(this); - loadSettings(MMC->settings()); + loadSettings(MMC->settings().data()); updateCheckboxStuff(); } @@ -85,7 +85,7 @@ void SettingsDialog::on_maximizedCheckBox_clicked(bool checked) void SettingsDialog::on_buttonBox_accepted() { - applySettings(MMC->settings()); + applySettings(MMC->settings().data()); } void SettingsDialog::applySettings(SettingsObject *s) diff --git a/logic/BaseInstance.cpp b/logic/BaseInstance.cpp index 10bb4573..ec86596a 100644 --- a/logic/BaseInstance.cpp +++ b/logic/BaseInstance.cpp @@ -132,7 +132,7 @@ InstanceList *BaseInstance::instList() const return NULL; } -BaseVersionList *BaseInstance::versionList() const +QSharedPointer BaseInstance::versionList() const { return MMC->minecraftlist(); } diff --git a/logic/BaseInstance.h b/logic/BaseInstance.h index fa317ba1..374d1437 100644 --- a/logic/BaseInstance.h +++ b/logic/BaseInstance.h @@ -134,7 +134,7 @@ public: * \brief Gets a pointer to this instance's version list. * \return A pointer to the available version list for this instance. */ - virtual BaseVersionList *versionList() const; + virtual QSharedPointer versionList() const; /*! * \brief Gets this instance's settings object. diff --git a/logic/ForgeInstaller.cpp b/logic/ForgeInstaller.cpp new file mode 100644 index 00000000..00ad8d19 --- /dev/null +++ b/logic/ForgeInstaller.cpp @@ -0,0 +1,125 @@ +#include "ForgeInstaller.h" +#include "OneSixVersion.h" +#include "OneSixLibrary.h" +#include +#include +#include +#include + +ForgeInstaller::ForgeInstaller(QString filename, QString universal_url) +{ + QSharedPointer newVersion; + m_universal_url = universal_url; + + QuaZip zip(filename); + if (!zip.open(QuaZip::mdUnzip)) + return; + + QuaZipFile file(&zip); + + // read the install profile + if (!zip.setCurrentFile("install_profile.json")) + return; + + QJsonParseError jsonError; + if (!file.open(QIODevice::ReadOnly)) + return; + QJsonDocument jsonDoc = QJsonDocument::fromJson(file.readAll(), &jsonError); + file.close(); + if (jsonError.error != QJsonParseError::NoError) + return; + + if (!jsonDoc.isObject()) + return; + + QJsonObject root = jsonDoc.object(); + + auto installVal = root.value("install"); + auto versionInfoVal = root.value("versionInfo"); + if (!installVal.isObject() || !versionInfoVal.isObject()) + return; + + // read the forge version info + { + newVersion = OneSixVersion::fromJson(versionInfoVal.toObject()); + if (!newVersion) + return; + } + + QJsonObject installObj = installVal.toObject(); + QString libraryName = installObj.value("path").toString(); + internalPath = installObj.value("filePath").toString(); + + // where do we put the library? decode the mojang path + OneSixLibrary lib(libraryName); + lib.finalize(); + finalPath = "libraries/" + lib.storagePath(); + if (!ensureFilePathExists(finalPath)) + return; + + if (!zip.setCurrentFile(internalPath)) + return; + if (!file.open(QIODevice::ReadOnly)) + return; + { + QByteArray data = file.readAll(); + // extract file + QSaveFile extraction(finalPath); + if (!extraction.open(QIODevice::WriteOnly)) + return; + if (extraction.write(data) != data.size()) + return; + if (!extraction.commit()) + return; + } + file.close(); + + m_forge_version = newVersion; + realVersionId = m_forge_version->id = installObj.value("minecraft").toString(); +} + +bool ForgeInstaller::apply(QSharedPointer 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) + QSet blacklist{"lwjgl", "lwjgl_util", "lwjgl-platform"}; + for (auto lib : m_forge_version->libraries) + { + QString libName = lib->name(); + // if this is the actual forge lib, set an absolute url for the download + if(libName.contains("minecraftforge")) + { + lib->setAbsoluteUrl(m_universal_url); + } + if (blacklist.contains(libName)) + continue; + + // find an entry that matches this one + bool found = false; + for (auto tolib : to->libraries) + { + if (tolib->name() != libName) + continue; + found = true; + // replace lib + tolib = lib; + break; + } + if (!found) + { + // add lib + to->libraries.insert(sliding_insert_window, lib); + sliding_insert_window++; + } + } + to->mainClass = m_forge_version->mainClass; + to->minecraftArguments = m_forge_version->minecraftArguments; + to->processArguments = m_forge_version->processArguments; + } + to->externalUpdateFinish(); + return to->toOriginalFile(); +} diff --git a/logic/ForgeInstaller.h b/logic/ForgeInstaller.h new file mode 100644 index 00000000..f4ceaaef --- /dev/null +++ b/logic/ForgeInstaller.h @@ -0,0 +1,25 @@ +#pragma once +#include +#include + +class OneSixVersion; + +class ForgeInstaller +{ +public: + ForgeInstaller(QString filename, QString universal_url); + + bool apply(QSharedPointer to); + +private: + // the version, read from the installer + QSharedPointer m_forge_version; + QString internalPath; + QString finalPath; + QString realVersionId; + QString m_universal_url; +}; + + + + diff --git a/logic/LegacyUpdate.cpp b/logic/LegacyUpdate.cpp index 0f58e3e3..84d3d830 100644 --- a/logic/LegacyUpdate.cpp +++ b/logic/LegacyUpdate.cpp @@ -60,7 +60,7 @@ void LegacyUpdate::lwjglStart() m_reply = QSharedPointer (rep, &QObject::deleteLater); connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SIGNAL(progress(qint64,qint64))); - connect(worker, SIGNAL(finished(QNetworkReply*)), SLOT(lwjglFinished(QNetworkReply*))); + connect(worker.data(), SIGNAL(finished(QNetworkReply*)), SLOT(lwjglFinished(QNetworkReply*))); //connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(downloadError(QNetworkReply::NetworkError))); } @@ -77,7 +77,7 @@ void LegacyUpdate::lwjglFinished(QNetworkReply* reply) "\nSometimes you have to wait a bit if you download many LWJGL versions in a row. YMMV"); return; } - auto *worker = MMC->qnam(); + auto worker = MMC->qnam(); //Here i check if there is a cookie for me in the reply and extract it QList cookies = qvariant_cast>(reply->header(QNetworkRequest::SetCookieHeader)); if(cookies.count() != 0) diff --git a/logic/ModList.h b/logic/ModList.h index 5395e9ae..e99b6c82 100644 --- a/logic/ModList.h +++ b/logic/ModList.h @@ -112,3 +112,6 @@ protected: QString m_list_id; QList mods; }; + + + diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index 8124b4a0..9262b155 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -2,7 +2,7 @@ #include "OneSixInstance_p.h" #include "OneSixUpdate.h" #include "MinecraftProcess.h" -#include "VersionFactory.h" +#include "OneSixVersion.h" #include #include @@ -10,8 +10,9 @@ #include #include -OneSixInstance::OneSixInstance ( const QString& rootDir, SettingsObject* setting_obj, QObject* parent ) -: BaseInstance ( new OneSixInstancePrivate(), rootDir, setting_obj, parent ) +OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *setting_obj, + QObject *parent) + : BaseInstance(new OneSixInstancePrivate(), rootDir, setting_obj, parent) { I_D(OneSixInstance); d->m_settings->registerSetting(new Setting("IntendedVersion", "")); @@ -19,7 +20,7 @@ OneSixInstance::OneSixInstance ( const QString& rootDir, SettingsObject* setting reloadFullVersion(); } -BaseUpdate* OneSixInstance::doUpdate() +BaseUpdate *OneSixInstance::doUpdate() { return new OneSixUpdate(this); } @@ -34,10 +35,10 @@ QString replaceTokensIn(QString text, QMap with) int head = 0; while ((head = token_regexp.indexIn(text, head)) != -1) { - result.append(text.mid(tail, head-tail)); + result.append(text.mid(tail, head - tail)); QString key = token_regexp.cap(1); auto iter = with.find(key); - if(iter != with.end()) + if (iter != with.end()) { result.append(*iter); } @@ -48,26 +49,26 @@ QString replaceTokensIn(QString text, QMap with) return result; } -QStringList OneSixInstance::processMinecraftArgs( QString user, QString session ) +QStringList OneSixInstance::processMinecraftArgs(QString user, QString session) { I_D(OneSixInstance); auto version = d->version; QString args_pattern = version->minecraftArguments; - + QMap token_mapping; token_mapping["auth_username"] = user; token_mapping["auth_session"] = session; - //FIXME: user and player name are DIFFERENT! + // FIXME: user and player name are DIFFERENT! token_mapping["auth_player_name"] = user; - //FIXME: WTF is this. I just plugged in a random UUID here. + // FIXME: WTF is this. I just plugged in a random UUID here. token_mapping["auth_uuid"] = "7d4bacf0-fd62-11e2-b778-0800200c9a66"; // obviously fake. - + // this is for offline: /* map["auth_player_name"] = "Player"; map["auth_player_name"] = "00000000-0000-0000-0000-000000000000"; */ - + token_mapping["profile_name"] = name(); token_mapping["version_name"] = version->id; @@ -75,8 +76,8 @@ QStringList OneSixInstance::processMinecraftArgs( QString user, QString session token_mapping["game_directory"] = absRootDir; QString absAssetsDir = QDir("assets/").absolutePath(); token_mapping["game_assets"] = absAssetsDir; - - QStringList parts = args_pattern.split(' ',QString::SkipEmptyParts); + + QStringList parts = args_pattern.split(' ', QString::SkipEmptyParts); for (int i = 0; i < parts.length(); i++) { parts[i] = replaceTokensIn(parts[i], token_mapping); @@ -84,27 +85,28 @@ QStringList OneSixInstance::processMinecraftArgs( QString user, QString session return parts; } -MinecraftProcess* OneSixInstance::prepareForLaunch ( QString user, QString session ) +MinecraftProcess *OneSixInstance::prepareForLaunch(QString user, QString session) { I_D(OneSixInstance); cleanupAfterRun(); auto version = d->version; - if(!version) + if (!version) return nullptr; auto libs_to_extract = version->getActiveNativeLibs(); QString natives_dir_raw = PathCombine(instanceRoot(), "natives/"); bool success = ensureFolderPathExists(natives_dir_raw); - if(!success) + if (!success) { // FIXME: handle errors return nullptr; } - - for(auto lib: libs_to_extract) + + for (auto lib : libs_to_extract) { QString path = "libraries/" + lib->storagePath(); qDebug() << "Will extract " << path.toLocal8Bit(); - if(JlCompress::extractWithExceptions(path, natives_dir_raw, lib->extract_excludes).isEmpty()) + if (JlCompress::extractWithExceptions(path, natives_dir_raw, lib->extract_excludes) + .isEmpty()) { return nullptr; } @@ -116,11 +118,11 @@ MinecraftProcess* OneSixInstance::prepareForLaunch ( QString user, QString sessi args << QString("-Xmx%1m").arg(settings().get("MaxMemAlloc").toInt()); args << QString("-XX:PermSize=%1m").arg(settings().get("PermGen").toInt()); QDir natives_dir(natives_dir_raw); - args << QString("-Djava.library.path=%1").arg( natives_dir.absolutePath() ); + args << QString("-Djava.library.path=%1").arg(natives_dir.absolutePath()); QString classPath; { auto libs = version->getActiveNormalLibs(); - for (auto lib: libs) + for (auto lib : libs) { QFileInfo fi(QString("libraries/") + lib->storagePath()); classPath.append(fi.absoluteFilePath()); @@ -134,16 +136,16 @@ MinecraftProcess* OneSixInstance::prepareForLaunch ( QString user, QString sessi QFileInfo fi(targetstr); classPath.append(fi.absoluteFilePath()); } - if(classPath.size()) + if (classPath.size()) { args << "-cp"; args << classPath; } args << version->mainClass; args.append(processMinecraftArgs(user, session)); - + // create the process and set its parameters - MinecraftProcess * proc = new MinecraftProcess(this); + MinecraftProcess *proc = new MinecraftProcess(this); proc->setMinecraftArguments(args); proc->setMinecraftWorkdir(minecraftRoot()); return proc; @@ -156,10 +158,10 @@ void OneSixInstance::cleanupAfterRun() dir.removeRecursively(); } -QSharedPointer< ModList > OneSixInstance::loaderModList() +QSharedPointer OneSixInstance::loaderModList() { I_D(OneSixInstance); - if(!d->loader_mod_list) + if (!d->loader_mod_list) { d->loader_mod_list.reset(new ModList(loaderModsDir())); } @@ -168,10 +170,10 @@ QSharedPointer< ModList > OneSixInstance::loaderModList() return d->loader_mod_list; } -QSharedPointer< ModList > OneSixInstance::resourcePackList() +QSharedPointer OneSixInstance::resourcePackList() { I_D(OneSixInstance); - if(!d->resource_pack_list) + if (!d->resource_pack_list) { d->resource_pack_list.reset(new ModList(resourcePacksDir())); } @@ -180,13 +182,12 @@ QSharedPointer< ModList > OneSixInstance::resourcePackList() return d->resource_pack_list; } - -QDialog * OneSixInstance::createModEditDialog ( QWidget* parent ) +QDialog *OneSixInstance::createModEditDialog(QWidget *parent) { return new OneSixModEditDialog(this, parent); } -bool OneSixInstance::setIntendedVersionId ( QString version ) +bool OneSixInstance::setIntendedVersionId(QString version) { settings().set("IntendedVersion", version); setShouldUpdate(true); @@ -198,16 +199,16 @@ QString OneSixInstance::intendedVersionId() const return settings().get("IntendedVersion").toString(); } -void OneSixInstance::setShouldUpdate ( bool val ) +void OneSixInstance::setShouldUpdate(bool val) { - settings().set ( "ShouldUpdate", val ); + settings().set("ShouldUpdate", val); } bool OneSixInstance::shouldUpdate() const { I_D(OneSixInstance); - QVariant var = settings().get ( "ShouldUpdate" ); - if ( !var.isValid() || var.toBool() == false ) + QVariant var = settings().get("ShouldUpdate"); + if (!var.isValid() || var.toBool() == false) { return intendedVersionId() != currentVersionId(); } @@ -228,56 +229,51 @@ QString OneSixInstance::currentVersionId() const bool OneSixInstance::customizeVersion() { - if(!versionIsCustom()) + if (!versionIsCustom()) { auto pathCustom = PathCombine(instanceRoot(), "custom.json"); auto pathOrig = PathCombine(instanceRoot(), "version.json"); QFile::copy(pathOrig, pathCustom); return reloadFullVersion(); } - else return true; + else + return true; } bool OneSixInstance::revertCustomVersion() { - if(versionIsCustom()) + if (versionIsCustom()) { auto path = PathCombine(instanceRoot(), "custom.json"); QFile::remove(path); return reloadFullVersion(); } - else return true; + 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()) + if (versionfile.exists()) verpath = verpath_custom; } - - QFile versionfile(verpath); - if(versionfile.exists() && versionfile.open(QIODevice::ReadOnly)) + + auto version = OneSixVersion::fromFile(verpath); + if (version) { - FullVersionFactory fvf; - auto version = fvf.parse(versionfile.readAll()); - versionfile.close(); - if(version) - { - d->version = version; - return true; - } - }; + d->version = version; + return true; + } return false; } -QSharedPointer< OneSixVersion > OneSixInstance::getFullVersion() +QSharedPointer OneSixInstance::getFullVersion() { I_D(OneSixInstance); return d->version; @@ -293,9 +289,9 @@ QString OneSixInstance::defaultCustomBaseJar() const return PathCombine(instanceRoot(), "custom.jar"); } -bool OneSixInstance::menuActionEnabled ( QString action_name ) const +bool OneSixInstance::menuActionEnabled(QString action_name) const { - if(action_name == "actionChangeInstLWJGLVersion") + if (action_name == "actionChangeInstLWJGLVersion") return false; return true; } @@ -303,7 +299,7 @@ bool OneSixInstance::menuActionEnabled ( QString action_name ) const QString OneSixInstance::getStatusbarDescription() { QString descr = "One Six : " + intendedVersionId(); - if(versionIsCustom()) + if (versionIsCustom()) { descr + " (custom)"; } diff --git a/logic/OneSixLibrary.cpp b/logic/OneSixLibrary.cpp index a45a4aec..8da1fde7 100644 --- a/logic/OneSixLibrary.cpp +++ b/logic/OneSixLibrary.cpp @@ -1,18 +1,19 @@ #include "OneSixLibrary.h" #include "OneSixRule.h" #include "OpSys.h" +#include void OneSixLibrary::finalize() { - QStringList parts = m_name.split ( ':' ); + QStringList parts = m_name.split(':'); QString relative = parts[0]; - relative.replace ( '.','/' ); + relative.replace('.', '/'); relative += '/' + parts[1] + '/' + parts[2] + '/' + parts[1] + '-' + parts[2]; - - if ( !m_is_native ) + + if (!m_is_native) relative += ".jar"; else { - if ( m_native_suffixes.contains ( currentSystem ) ) + if (m_native_suffixes.contains(currentSystem)) { relative += "-" + m_native_suffixes[currentSystem] + ".jar"; } @@ -22,30 +23,30 @@ void OneSixLibrary::finalize() relative += ".jar"; } } - + m_decentname = parts[1]; m_decentversion = parts[2]; m_storage_path = relative; - m_download_path = m_base_url + relative; - - if ( m_rules.empty() ) + m_download_url = m_base_url + relative; + + if (m_rules.empty()) { m_is_active = true; } else { RuleAction result = Disallow; - for ( auto rule: m_rules ) + for (auto rule : m_rules) { - RuleAction temp = rule->apply ( this ); - if ( temp != Defer ) + RuleAction temp = rule->apply(this); + if (temp != Defer) result = temp; } - m_is_active = ( result == Allow ); + m_is_active = (result == Allow); } - if ( m_is_native ) + if (m_is_native) { - m_is_active = m_is_active && m_native_suffixes.contains ( currentSystem ); + m_is_active = m_is_active && m_native_suffixes.contains(currentSystem); m_decenttype = "Native"; } else @@ -54,11 +55,11 @@ void OneSixLibrary::finalize() } } -void OneSixLibrary::setName ( QString name ) +void OneSixLibrary::setName(QString name) { m_name = name; } -void OneSixLibrary::setBaseUrl ( QString base_url ) +void OneSixLibrary::setBaseUrl(QString base_url) { m_base_url = base_url; } @@ -66,12 +67,12 @@ void OneSixLibrary::setIsNative() { m_is_native = true; } -void OneSixLibrary::addNative ( OpSys os, QString suffix ) +void OneSixLibrary::addNative(OpSys os, QString suffix) { m_is_native = true; m_native_suffixes[os] = suffix; } -void OneSixLibrary::setRules ( QList< QSharedPointer< Rule > > rules ) +void OneSixLibrary::setRules(QList> rules) { m_rules = rules; } @@ -83,11 +84,66 @@ bool OneSixLibrary::isNative() { return m_is_native; } -QString OneSixLibrary::downloadPath() +QString OneSixLibrary::downloadUrl() { - return m_download_path; + if(m_absolute_url.size()) + return m_absolute_url; + return m_download_url; } QString OneSixLibrary::storagePath() { return m_storage_path; } + +void OneSixLibrary::setAbsoluteUrl(QString absolute_url) +{ + m_absolute_url = absolute_url; +} + +QString OneSixLibrary::absoluteUrl() +{ + return m_absolute_url; +} + +QJsonObject OneSixLibrary::toJson() +{ + QJsonObject libRoot; + libRoot.insert("name", m_name); + if(m_absolute_url.size()) + libRoot.insert("MMC-absulute_url", m_absolute_url); + if(m_base_url != "https://s3.amazonaws.com/Minecraft.Download/libraries/") + libRoot.insert("url", m_base_url); + if (isNative() && m_native_suffixes.size()) + { + QJsonObject nativeList; + auto iter = m_native_suffixes.begin(); + while (iter != m_native_suffixes.end()) + { + nativeList.insert(OpSys_toString(iter.key()), iter.value()); + iter++; + } + libRoot.insert("natives", nativeList); + } + if (isNative() && extract_excludes.size()) + { + QJsonArray excludes; + QJsonObject extract; + for (auto exclude : extract_excludes) + { + excludes.append(exclude); + } + extract.insert("exclude", excludes); + libRoot.insert("extract", extract); + } + if (m_rules.size()) + { + QJsonArray allRules; + for (auto &rule : m_rules) + { + QJsonObject ruleObj = rule->toJson(); + allRules.append(ruleObj); + } + libRoot.insert("rules", allRules); + } + return libRoot; +} diff --git a/logic/OneSixLibrary.h b/logic/OneSixLibrary.h index ac16d3d3..f3106483 100644 --- a/logic/OneSixLibrary.h +++ b/logic/OneSixLibrary.h @@ -3,6 +3,7 @@ #include #include #include +#include #include "OpSys.h" class Rule; @@ -12,9 +13,13 @@ class OneSixLibrary private: // basic values used internally (so far) QString m_name; - QString m_base_url; + QString m_base_url = "https://s3.amazonaws.com/Minecraft.Download/libraries/"; QList > m_rules; - + + // custom values + /// absolute URL. takes precedence over m_download_path, if defined + QString m_absolute_url; + // derived values used for real things /// a decent name fit for display QString m_decentname; @@ -25,11 +30,11 @@ private: /// where to store the lib locally QString m_storage_path; /// where to download the lib from - QString m_download_path; + QString m_download_url; /// is this lib actually active on the current OS? - bool m_is_active; + bool m_is_active = false; /// is the library a native? - bool m_is_native; + bool m_is_native = false; /// native suffixes per OS QMap m_native_suffixes; public: @@ -39,12 +44,11 @@ public: /// Constructor OneSixLibrary(QString name) { - m_is_native = false; - m_is_active = false; m_name = name; - m_base_url = "https://s3.amazonaws.com/Minecraft.Download/libraries/"; } + QJsonObject toJson(); + /** * finalize the library, processing the input values into derived values and state * @@ -84,7 +88,11 @@ public: /// Returns true if the library is native bool isNative(); /// Get the URL to download the library from - QString downloadPath(); + QString downloadUrl(); /// Get the relative path where the library should be saved QString storagePath(); + + /// set an absolute URL for the library. This is an MMC extension. + void setAbsoluteUrl(QString absolute_url); + QString absoluteUrl(); }; diff --git a/logic/OneSixRule.cpp b/logic/OneSixRule.cpp index 85f7d434..545cd641 100644 --- a/logic/OneSixRule.cpp +++ b/logic/OneSixRule.cpp @@ -1,10 +1,72 @@ #include "OneSixRule.h" +#include +#include + +QList> rulesFromJsonV4(QJsonObject &objectWithRules) +{ + QList> rules; + auto rulesVal = objectWithRules.value("rules"); + if (!rulesVal.isArray()) + return rules; + + QJsonArray ruleList = rulesVal.toArray(); + for (auto ruleVal : ruleList) + { + QSharedPointer rule; + if (!ruleVal.isObject()) + continue; + auto ruleObj = ruleVal.toObject(); + auto actionVal = ruleObj.value("action"); + if (!actionVal.isString()) + continue; + auto action = RuleAction_fromString(actionVal.toString()); + if (action == Defer) + continue; + + auto osVal = ruleObj.value("os"); + if (!osVal.isObject()) + { + // add a new implicit action rule + rules.append(ImplicitRule::create(action)); + continue; + } + + auto osObj = osVal.toObject(); + auto osNameVal = osObj.value("name"); + if (!osNameVal.isString()) + continue; + OpSys requiredOs = OpSys_fromString(osNameVal.toString()); + QString versionRegex = osObj.value("version").toString(); + // add a new OS rule + rules.append(OsRule::create(action, requiredOs, versionRegex)); + } +} + +QJsonObject ImplicitRule::toJson() +{ + QJsonObject ruleObj; + ruleObj.insert("action", m_result == Allow ? QString("allow") : QString("disallow")); + return ruleObj; +} + +QJsonObject OsRule::toJson() +{ + QJsonObject ruleObj; + ruleObj.insert("action", m_result == Allow ? QString("allow") : QString("disallow")); + QJsonObject osObj; + { + osObj.insert("name", OpSys_toString(m_system)); + osObj.insert("version", m_version_regexp); + } + ruleObj.insert("os", osObj); + return ruleObj; +} RuleAction RuleAction_fromString(QString name) { - if(name == "allow") + if (name == "allow") return Allow; - if(name == "disallow") + if (name == "disallow") return Disallow; return Defer; } \ No newline at end of file diff --git a/logic/OneSixRule.h b/logic/OneSixRule.h index 465c963f..23d20ff4 100644 --- a/logic/OneSixRule.h +++ b/logic/OneSixRule.h @@ -1,8 +1,6 @@ #pragma once #include #include - -class OneSixLibrary; #include "OneSixLibrary.h" enum RuleAction @@ -13,6 +11,7 @@ enum RuleAction }; RuleAction RuleAction_fromString(QString); +QList> rulesFromJsonV4(QJsonObject &objectWithRules); class Rule { @@ -23,6 +22,7 @@ public: Rule(RuleAction result) :m_result(result) {} virtual ~Rule(){}; + virtual QJsonObject toJson() = 0; RuleAction apply(OneSixLibrary * parent) { if(applies(parent)) @@ -47,6 +47,7 @@ protected: OsRule(RuleAction result, OpSys system, QString version_regexp) : Rule(result), m_system(system), m_version_regexp(version_regexp) {} public: + virtual QJsonObject toJson(); static QSharedPointer create(RuleAction result, OpSys system, QString version_regexp) { return QSharedPointer (new OsRule(result, system, version_regexp)); @@ -63,6 +64,7 @@ protected: ImplicitRule(RuleAction result) : Rule(result) {} public: + virtual QJsonObject toJson(); static QSharedPointer create(RuleAction result) { return QSharedPointer (new ImplicitRule(result)); diff --git a/logic/OneSixUpdate.cpp b/logic/OneSixUpdate.cpp index 298ad28a..d0af8b93 100644 --- a/logic/OneSixUpdate.cpp +++ b/logic/OneSixUpdate.cpp @@ -3,7 +3,7 @@ * 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 @@ -26,20 +26,20 @@ #include "BaseInstance.h" #include "lists/MinecraftVersionList.h" -#include "VersionFactory.h" #include "OneSixVersion.h" #include "OneSixLibrary.h" #include "OneSixInstance.h" #include "pathutils.h" - -OneSixUpdate::OneSixUpdate(BaseInstance *inst, QObject *parent):BaseUpdate(inst, parent){} +OneSixUpdate::OneSixUpdate(BaseInstance *inst, QObject *parent) : BaseUpdate(inst, parent) +{ +} void OneSixUpdate::executeTask() { QString intendedVersion = m_inst->intendedVersionId(); - + // Make directories QDir mcDir(m_inst->minecraftRoot()); if (!mcDir.exists() && !mcDir.mkpath(".")) @@ -47,17 +47,18 @@ void OneSixUpdate::executeTask() emitFailed("Failed to create bin folder."); return; } - + // Get a pointer to the version object that corresponds to the instance's version. - targetVersion = MMC->minecraftlist()->findVersion(intendedVersion).dynamicCast(); - if(targetVersion == nullptr) + targetVersion = + MMC->minecraftlist()->findVersion(intendedVersion).dynamicCast(); + if (targetVersion == nullptr) { // don't do anything if it was invalid emitSucceeded(); return; } - - if(m_inst->shouldUpdate()) + + if (m_inst->shouldUpdate()) { versionFileStart(); } @@ -70,62 +71,65 @@ void OneSixUpdate::executeTask() void OneSixUpdate::versionFileStart() { setStatus("Getting the version files from Mojang."); - + QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/"); urlstr += targetVersion->descriptor() + "/" + targetVersion->descriptor() + ".json"; auto job = new DownloadJob("Version index"); job->add(QUrl(urlstr)); specificVersionDownloadJob.reset(job); - connect(specificVersionDownloadJob.data(), SIGNAL(succeeded()), SLOT(versionFileFinished())); + connect(specificVersionDownloadJob.data(), SIGNAL(succeeded()), + SLOT(versionFileFinished())); connect(specificVersionDownloadJob.data(), SIGNAL(failed()), SLOT(versionFileFailed())); - connect(specificVersionDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SIGNAL(progress(qint64,qint64))); + connect(specificVersionDownloadJob.data(), SIGNAL(progress(qint64, qint64)), + SIGNAL(progress(qint64, qint64))); specificVersionDownloadJob->start(); } void OneSixUpdate::versionFileFinished() { DownloadPtr DlJob = specificVersionDownloadJob->first(); - OneSixInstance * inst = (OneSixInstance *) m_inst; - + OneSixInstance *inst = (OneSixInstance *)m_inst; + QString version_id = targetVersion->descriptor(); QString inst_dir = m_inst->instanceRoot(); // save the version file in $instanceId/version.json { - QString version1 = PathCombine(inst_dir, "/version.json"); + QString version1 = PathCombine(inst_dir, "/version.json"); ensureFilePathExists(version1); // FIXME: detect errors here, download to a temp file, swap - QSaveFile vfile1 (version1); - if(!vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly )) + QSaveFile vfile1(version1); + if (!vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly)) { emitFailed("Can't open " + version1 + " for writing."); return; } auto data = DlJob.dynamicCast()->m_data; qint64 actual = 0; - if((actual = vfile1.write(data)) != data.size()) + if ((actual = vfile1.write(data)) != data.size()) { - emitFailed("Failed to write into " + version1 + ". Written " + actual + " out of " + data.size() + '.'); + emitFailed("Failed to write into " + version1 + ". Written " + actual + " out of " + + data.size() + '.'); return; } - if(!vfile1.commit()) + if (!vfile1.commit()) { emitFailed("Can't commit changes to " + version1); return; } } - + // the version is downloaded safely. update is 'done' at this point m_inst->setShouldUpdate(false); - + // delete any custom version inside the instance (it's no longer relevant, we did an update) - QString custom = PathCombine(inst_dir, "/custom.json"); + QString custom = PathCombine(inst_dir, "/custom.json"); QFile finfo(custom); - if(finfo.exists()) + if (finfo.exists()) { finfo.remove(); } inst->reloadFullVersion(); - + jarlibStart(); } @@ -136,42 +140,44 @@ void OneSixUpdate::versionFileFailed() void OneSixUpdate::jarlibStart() { - OneSixInstance * inst = (OneSixInstance *) m_inst; + OneSixInstance *inst = (OneSixInstance *)m_inst; bool successful = inst->reloadFullVersion(); - if(!successful) + if (!successful) { - emitFailed("Failed to load the version description file (version.json). It might be corrupted, missing or simply too new."); + emitFailed("Failed to load the version description file (version.json). It might be " + "corrupted, missing or simply too new."); return; } - + QSharedPointer version = inst->getFullVersion(); - + // download the right jar, save it in versions/$version/$version.jar QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/"); urlstr += version->id + "/" + version->id + ".jar"; - QString targetstr ("versions/"); + QString targetstr("versions/"); targetstr += version->id + "/" + version->id + ".jar"; - + auto job = new DownloadJob("Libraries for instance " + inst->name()); job->add(QUrl(urlstr), targetstr); jarlibDownloadJob.reset(job); - + auto libs = version->getActiveNativeLibs(); libs.append(version->getActiveNormalLibs()); - + auto metacache = MMC->metacache(); - for(auto lib: libs) + for (auto lib : libs) { - QString download_path = lib->downloadPath(); + QString download_path = lib->downloadUrl(); auto entry = metacache->resolveEntry("libraries", lib->storagePath()); - if(entry->stale) + if (entry->stale) { jarlibDownloadJob->add(download_path, entry); } } connect(jarlibDownloadJob.data(), SIGNAL(succeeded()), SLOT(jarlibFinished())); connect(jarlibDownloadJob.data(), SIGNAL(failed()), SLOT(jarlibFailed())); - connect(jarlibDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SIGNAL(progress(qint64,qint64))); + connect(jarlibDownloadJob.data(), SIGNAL(progress(qint64, qint64)), + SIGNAL(progress(qint64, qint64))); jarlibDownloadJob->start(); } @@ -185,4 +191,3 @@ void OneSixUpdate::jarlibFailed() { emitFailed("Failed to download the binary garbage. Try again. Maybe. IF YOU DARE"); } - diff --git a/logic/OneSixVersion.cpp b/logic/OneSixVersion.cpp index dc1b5d6f..663d903a 100644 --- a/logic/OneSixVersion.cpp +++ b/logic/OneSixVersion.cpp @@ -1,10 +1,201 @@ #include "OneSixVersion.h" #include "OneSixLibrary.h" +#include "OneSixRule.h" -QList > OneSixVersion::getActiveNormalLibs() +QSharedPointer fromJsonV4(QJsonObject root, + QSharedPointer fullVersion) { - QList > output; - for ( auto lib: libraries ) + 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(); + + // 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; + QSharedPointer library(new OneSixLibrary(nameVal.toString())); + + auto urlVal = libObj.value("url"); + if (urlVal.isString()) + { + library->setBaseUrl(urlVal.toString()); + } + auto urlAbsVal = libObj.value("MMC-absulute_url"); + if (urlAbsVal.isString()) + { + library->setAbsoluteUrl(urlAbsVal.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; +} + +QSharedPointer OneSixVersion::fromJson(QJsonObject root) +{ + QSharedPointer readVersion(new OneSixVersion()); + int launcher_ver = readVersion->minimumLauncherVersion = + root.value("minimumLauncherVersion").toDouble(); + + // ADD MORE HERE :D + if (launcher_ver > 0 && launcher_ver <= 7) + return fromJsonV4(root, readVersion); + else + { + return QSharedPointer(); + } +} + +QSharedPointer OneSixVersion::fromFile(QString filepath) +{ + QFile file(filepath); + if (!file.open(QIODevice::ReadOnly)) + { + return QSharedPointer(); + } + + auto data = file.readAll(); + QJsonParseError jsonError; + QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); + + if (jsonError.error != QJsonParseError::NoError) + { + return QSharedPointer(); + } + + if (!jsonDoc.isObject()) + { + return QSharedPointer(); + } + QJsonObject root = jsonDoc.object(); + auto version = fromJson(root); + version->original_file = filepath; + return version; +} + +bool OneSixVersion::toOriginalFile() +{ + if (original_file.isEmpty()) + return false; + QSaveFile file(original_file); + if (!file.open(QIODevice::WriteOnly)) + { + return false; + } + // 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(); +} + +QList> OneSixVersion::getActiveNormalLibs() +{ + QList> output; + for (auto lib : libraries) { if (lib->isActive() && !lib->isNative()) { @@ -14,10 +205,10 @@ QList > OneSixVersion::getActiveNormalLibs() return output; } -QList > OneSixVersion::getActiveNativeLibs() +QList> OneSixVersion::getActiveNativeLibs() { - QList > output; - for ( auto lib: libraries ) + QList> output; + for (auto lib : libraries) { if (lib->isActive() && lib->isNative()) { @@ -27,41 +218,50 @@ QList > OneSixVersion::getActiveNativeLibs() return output; } +void OneSixVersion::externalUpdateStart() +{ + beginResetModel(); +} + +void OneSixVersion::externalUpdateFinish() +{ + endResetModel(); +} -QVariant OneSixVersion::data(const QModelIndex& index, int role) const +QVariant OneSixVersion::data(const QModelIndex &index, int role) const { - if(!index.isValid()) + if (!index.isValid()) return QVariant(); - + int row = index.row(); int column = index.column(); - - if(row < 0 || row >= libraries.size()) + + if (row < 0 || row >= libraries.size()) return QVariant(); - - if(role == Qt::DisplayRole) + + if (role == Qt::DisplayRole) { - switch(column) + switch (column) { - case 0: - return libraries[row]->name(); - case 1: - return libraries[row]->type(); - case 2: - return libraries[row]->version(); - default: - return QVariant(); + 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 OneSixVersion::flags(const QModelIndex& index) const +Qt::ItemFlags OneSixVersion::flags(const QModelIndex &index) const { - if(!index.isValid()) + if (!index.isValid()) return Qt::NoItemFlags; int row = index.row(); - if(libraries[row]->isActive()) + if (libraries[row]->isActive()) { return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemNeverHasChildren; } @@ -69,11 +269,10 @@ Qt::ItemFlags OneSixVersion::flags(const QModelIndex& index) const { return Qt::ItemNeverHasChildren; } - //return QAbstractListModel::flags(index); + // return QAbstractListModel::flags(index); } - -QVariant OneSixVersion::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(); @@ -90,12 +289,12 @@ QVariant OneSixVersion::headerData ( int section, Qt::Orientation orientation, i } } -int OneSixVersion::rowCount(const QModelIndex& parent) const +int OneSixVersion::rowCount(const QModelIndex &parent) const { return libraries.size(); } -int OneSixVersion::columnCount(const QModelIndex& parent) const +int OneSixVersion::columnCount(const QModelIndex &parent) const { - return 3; + return 3; } diff --git a/logic/OneSixVersion.h b/logic/OneSixVersion.h index 6a6a5b4b..69268ecf 100644 --- a/logic/OneSixVersion.h +++ b/logic/OneSixVersion.h @@ -4,13 +4,33 @@ class OneSixLibrary; class OneSixVersion : public QAbstractListModel { + // Things required to implement the Qt list model 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; + 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; + + // serialization/deserialization +public: + bool toOriginalFile(); + static QSharedPointer fromJson(QJsonObject root); + static QSharedPointer fromFile(QString filepath); + 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(); + + // 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 @@ -23,26 +43,27 @@ public: * DEPRECATED: Old versions of the new vanilla launcher used this * ex: "username_session_version" */ - QString processArguments; + 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) + * the minimum launcher version required by this version ... current is 4 (at point of + * writing) */ - int minimumLauncherVersion; + int minimumLauncherVersion = 0xDEADBEEF; /** * The main class to load first */ 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. @@ -58,18 +79,11 @@ public: } } ], - "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!" + "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; - -public: - - OneSixVersion() - { - minimumLauncherVersion = 0xDEADBEEF; - } - - QList > getActiveNormalLibs(); - QList > getActiveNativeLibs(); + + }; diff --git a/logic/OpSys.cpp b/logic/OpSys.cpp index 559479fd..f101fd08 100644 --- a/logic/OpSys.cpp +++ b/logic/OpSys.cpp @@ -9,4 +9,15 @@ OpSys OpSys_fromString(QString name) if(name == "osx") return Os_OSX; return Os_Other; +} + +QString OpSys_toString(OpSys name) +{ + switch(name) + { + case Os_Linux: return "linux"; + case Os_OSX: return "osx"; + case Os_Windows: return "windows"; + default: return "other"; + } } \ No newline at end of file diff --git a/logic/OpSys.h b/logic/OpSys.h index c68c437a..aaa2eb65 100644 --- a/logic/OpSys.h +++ b/logic/OpSys.h @@ -9,6 +9,7 @@ enum OpSys }; OpSys OpSys_fromString(QString); +QString OpSys_toString(OpSys); #ifdef Q_OS_WIN32 #define currentSystem Os_Windows diff --git a/logic/VersionFactory.cpp b/logic/VersionFactory.cpp deleted file mode 100644 index 4fa5ad3f..00000000 --- a/logic/VersionFactory.cpp +++ /dev/null @@ -1,196 +0,0 @@ -#include "VersionFactory.h" -#include "OneSixVersion.h" -#include "OneSixRule.h" - -// Library rules (if any) -QList > FullVersionFactory::parse4rules(QJsonObject & baseObj) -{ - QList > rules; - auto rulesVal = baseObj.value("rules"); - if(rulesVal.isArray()) - { - QJsonArray ruleList = rulesVal.toArray(); - for(auto ruleVal : ruleList) - { - QSharedPointer rule; - if(!ruleVal.isObject()) - continue; - auto ruleObj = ruleVal.toObject(); - auto actionVal = ruleObj.value("action"); - if(!actionVal.isString()) - continue; - auto action = RuleAction_fromString(actionVal.toString()); - if(action == Defer) - continue; - - auto osVal = ruleObj.value("os"); - if(!osVal.isObject()) - { - // add a new implicit action rule - rules.append(ImplicitRule::create(action)); - } - else - { - auto osObj = osVal.toObject(); - auto osNameVal = osObj.value("name"); - if(!osNameVal.isString()) - continue; - OpSys requiredOs = OpSys_fromString(osNameVal.toString()); - QString versionRegex = osObj.value("version").toString(); - // add a new OS rule - rules.append(OsRule::create(action, requiredOs, versionRegex)); - } - } - } - return rules; -} - - -QSharedPointer FullVersionFactory::parse4(QJsonObject root, QSharedPointer fullVersion) -{ - 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(); - - // 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; - QSharedPointer library(new OneSixLibrary(nameVal.toString())); - - auto urlVal = libObj.value("url"); - if(urlVal.isString()) - { - library->setBaseUrl(urlVal.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()) - goto SKIP_EXTRACTS; - auto excludesList = excludesVal.toArray(); - for(auto excludeVal : excludesList) - { - if(excludeVal.isString()) - excludes.append(excludeVal.toString()); - } - library->extract_excludes = excludes; - } - SKIP_EXTRACTS: - - 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(parse4rules(libObj)); - library->finalize(); - fullVersion->libraries.append(library); - } - return fullVersion; -} - -QSharedPointer FullVersionFactory::parse(QByteArray data) -{ - QSharedPointer readVersion(new OneSixVersion()); - - QJsonParseError jsonError; - QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); - - if (jsonError.error != QJsonParseError::NoError) - { - error_string = QString( "Error reading version file :") + " " + jsonError.errorString(); - m_error = FullVersionFactory::ParseError; - return QSharedPointer(); - } - - if(!jsonDoc.isObject()) - { - error_string = "Error reading version file."; - m_error = FullVersionFactory::ParseError; - return QSharedPointer(); - } - QJsonObject root = jsonDoc.object(); - - int launcher_ver = readVersion->minimumLauncherVersion = root.value("minimumLauncherVersion").toDouble(); - // ADD MORE HERE :D - if(launcher_ver > 0 && launcher_ver <= 7) - return parse4(root, readVersion); - else - { - error_string = "Version file was for an unrecognized launcher version. RIP"; - m_error = FullVersionFactory::UnsupportedVersion; - return QSharedPointer(); - } -} - - -FullVersionFactory::FullVersionFactory() -{ - m_error = FullVersionFactory::AllOK; -} diff --git a/logic/VersionFactory.h b/logic/VersionFactory.h deleted file mode 100644 index 0c0ee2d4..00000000 --- a/logic/VersionFactory.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include - -struct OneSixVersion; -class Rule; - -class FullVersionFactory -{ -public: - enum Error - { - AllOK, // all parsed OK - ParseError, // the file was corrupted somehow - UnsupportedVersion // the file was meant for a launcher version we don't support (yet) - } m_error; - QString error_string; - -public: - FullVersionFactory(); - QSharedPointer parse(QByteArray data); -private: - QSharedPointer parse4(QJsonObject root, QSharedPointer product); - QList > parse4rules(QJsonObject & baseObj); -}; \ No newline at end of file diff --git a/logic/lists/ForgeVersionList.cpp b/logic/lists/ForgeVersionList.cpp index 492849ee..9205e70f 100644 --- a/logic/lists/ForgeVersionList.cpp +++ b/logic/lists/ForgeVersionList.cpp @@ -260,8 +260,10 @@ void ForgeListLoadTask::list_downloaded() fVersion->installer_url = installer_url; fVersion->jobbuildver = jobbuildver; fVersion->mcver = mcver; - fVersion->filename = filename; - fVersion->filename = installer_filename; + if(installer_filename.isEmpty()) + fVersion->filename = filename; + else + fVersion->filename = installer_filename; fVersion->m_buildnr = build_nr; tempList.append(fVersion); } @@ -271,3 +273,8 @@ void ForgeListLoadTask::list_downloaded() emitSucceeded(); return; } + + + + + diff --git a/logic/lists/ForgeVersionList.h b/logic/lists/ForgeVersionList.h index ca6b27bc..613de8a6 100644 --- a/logic/lists/ForgeVersionList.h +++ b/logic/lists/ForgeVersionList.h @@ -3,7 +3,7 @@ * 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 @@ -33,19 +33,22 @@ struct ForgeVersion : public BaseVersion virtual QString descriptor() { return filename; - }; + } + ; virtual QString name() { return "Forge " + jobbuildver; - }; + } + ; virtual QString typeString() const { - if(installer_url.isEmpty()) + if (installer_url.isEmpty()) return "Universal"; else return "Installer"; - }; - + } + ; + int m_buildnr = 0; QString universal_url; QString changelog_url; @@ -60,42 +63,45 @@ class ForgeVersionList : public BaseVersionList Q_OBJECT public: friend class ForgeListLoadTask; - + explicit ForgeVersionList(QObject *parent = 0); - + virtual Task *getLoadTask(); virtual bool isLoaded(); virtual const BaseVersionPtr at(int i) const; virtual int count() const; virtual void sort(); - + virtual BaseVersionPtr getLatestStable() const; - - virtual QVariant data(const QModelIndex& index, int role) const; - virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; - virtual int columnCount(const QModelIndex& parent) const; - + + virtual QVariant data(const QModelIndex &index, int role) const; + virtual QVariant headerData(int section, Qt::Orientation orientation, + int role) const; + virtual int columnCount(const QModelIndex &parent) const; + protected: QList m_vlist; - + bool m_loaded; - -protected slots: - virtual void updateListData(QList versions); + +protected +slots: + virtual void updateListData(QList versions); }; class ForgeListLoadTask : public Task { Q_OBJECT - + public: explicit ForgeListLoadTask(ForgeVersionList *vlist); - + virtual void executeTask(); - -protected slots: + +protected +slots: void list_downloaded(); - + protected: DownloadJobPtr listJob; ForgeVersionList *m_list; diff --git a/logic/tasks/LoginTask.cpp b/logic/tasks/LoginTask.cpp index 859827bc..222af618 100644 --- a/logic/tasks/LoginTask.cpp +++ b/logic/tasks/LoginTask.cpp @@ -30,7 +30,7 @@ void LoginTask::executeTask() { setStatus(tr("Logging in...")); auto worker = MMC->qnam(); - connect(worker, SIGNAL(finished(QNetworkReply*)), this, SLOT(processNetReply(QNetworkReply*))); + connect(worker.data(), SIGNAL(finished(QNetworkReply*)), this, SLOT(processNetReply(QNetworkReply*))); QUrl loginURL("https://login.minecraft.net/"); QNetworkRequest netRequest(loginURL); -- cgit From 8b0f8b9e597eb50ff9323037fd5fa1b9e330c467 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Mon, 30 Sep 2013 02:34:46 +0200 Subject: ``Working'' forge unpackers. Needs a lot of hardening but good for alpha. --- CMakeLists.txt | 6 +- depends/pack200/CMakeLists.txt | 1 + depends/pack200/src/unpack.cpp | 6 +- depends/pack200/src/unpack200.cpp | 3 + depends/xz-embedded/CMakeLists.txt | 20 +-- depends/xz-embedded/include/xz.h | 15 ++ gui/LegacyModEditDialog.cpp | 2 +- gui/OneSixModEditDialog.cpp | 2 +- logic/ForgeInstaller.cpp | 5 + logic/LegacyUpdate.cpp | 2 +- logic/OneSixAssets.cpp | 4 +- logic/OneSixLibrary.cpp | 14 +- logic/OneSixLibrary.h | 8 +- logic/OneSixUpdate.cpp | 9 +- logic/OneSixVersion.cpp | 12 +- logic/lists/ForgeVersionList.cpp | 2 +- logic/lists/MinecraftVersionList.h | 2 +- logic/net/DownloadJob.cpp | 16 ++- logic/net/DownloadJob.h | 8 +- logic/net/ForgeXzDownload.cpp | 277 +++++++++++++++++++++++++++++++++++++ logic/net/ForgeXzDownload.h | 35 +++++ 21 files changed, 413 insertions(+), 36 deletions(-) create mode 100644 logic/net/ForgeXzDownload.cpp create mode 100644 logic/net/ForgeXzDownload.h (limited to 'logic/LegacyUpdate.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index bb813a09..a3afe5d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,9 +52,11 @@ add_subdirectory(depends/launcher) # Add xz decompression add_subdirectory(depends/xz-embedded) +include_directories(${XZ_INCLUDE_DIR}) # Add pack200 decompression add_subdirectory(depends/pack200) +include_directories(${PACK200_INCLUDE_DIR}) ######## MultiMC Libs ######## @@ -231,6 +233,8 @@ logic/net/ByteArrayDownload.h logic/net/ByteArrayDownload.cpp logic/net/CacheDownload.h logic/net/CacheDownload.cpp +logic/net/ForgeXzDownload.h +logic/net/ForgeXzDownload.cpp logic/net/DownloadJob.h logic/net/DownloadJob.cpp logic/net/HttpMetaCache.h @@ -354,7 +358,7 @@ ADD_EXECUTABLE(MultiMC MACOSX_BUNDLE WIN32 # Link QT5_USE_MODULES(MultiMC Widgets Network Xml) -TARGET_LINK_LIBRARIES(MultiMC quazip libUtil libSettings libGroupView ${MultiMC_LINK_ADDITIONAL_LIBS}) +TARGET_LINK_LIBRARIES(MultiMC quazip xz-embedded unpack200 libUtil libSettings libGroupView ${MultiMC_LINK_ADDITIONAL_LIBS}) ADD_DEPENDENCIES(MultiMC MultiMCLauncher) diff --git a/depends/pack200/CMakeLists.txt b/depends/pack200/CMakeLists.txt index 657e303c..3e41d378 100644 --- a/depends/pack200/CMakeLists.txt +++ b/depends/pack200/CMakeLists.txt @@ -37,6 +37,7 @@ src/zip.cpp src/zip.h ) +SET(PACK200_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include" PARENT_SCOPE) include_directories(include) add_library(unpack200 STATIC ${PACK200_SRC}) diff --git a/depends/pack200/src/unpack.cpp b/depends/pack200/src/unpack.cpp index 8a66d42a..d7de1b22 100644 --- a/depends/pack200/src/unpack.cpp +++ b/depends/pack200/src/unpack.cpp @@ -1523,7 +1523,8 @@ band **unpacker::attr_definitions::buildBands(unpacker::layout_definition *lo) call.le_body[0] = &cble; // Distinguish backward calls and callables: assert(cble.le_kind == EK_CBLE); - assert(cble.le_len == call_num); + //FIXME: hit this one + //assert(cble.le_len == call_num); cble.le_back |= call.le_back; } calls_to_link.popTo(0); @@ -2777,7 +2778,8 @@ void unpacker::putlayout(band **body) { band &cble = *b.le_body[0]; assert(cble.le_kind == EK_CBLE); - assert(cble.le_len == b.le_len); + //FIXME: hit this one + //assert(cble.le_len == b.le_len); putlayout(cble.le_body); } break; diff --git a/depends/pack200/src/unpack200.cpp b/depends/pack200/src/unpack200.cpp index c6aa0b02..2ff8c34a 100644 --- a/depends/pack200/src/unpack200.cpp +++ b/depends/pack200/src/unpack200.cpp @@ -156,8 +156,11 @@ void unpack_200(std::string input_path, std::string output_path) magic = read_magic(&u, peek, (int)sizeof(peek)); if (magic != (int)JAVA_PACKAGE_MAGIC) { + // we do not feel strongly about this kind of thing... + /* if (magic != EOF_MAGIC) unpack_abort("garbage after end of pack archive"); + */ break; // all done } diff --git a/depends/xz-embedded/CMakeLists.txt b/depends/xz-embedded/CMakeLists.txt index f1c6eb8d..d4987f76 100644 --- a/depends/xz-embedded/CMakeLists.txt +++ b/depends/xz-embedded/CMakeLists.txt @@ -8,33 +8,25 @@ option(XZ_BUILD_MINIDEC "Build a tiny utility that decompresses xz streams" OFF) set(CMAKE_C_FLAGS "-std=c99") include_directories(include) +SET(XZ_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include" PARENT_SCOPE) + +# See include/xz.h for manual feature configuration +# tweak this list and xz.h to fit your needs set(XZ_SOURCES include/xz.h src/xz_config.h src/xz_crc32.c +src/xz_crc64.c src/xz_dec_lzma2.c src/xz_dec_stream.c src/xz_lzma2.h src/xz_private.h src/xz_stream.h +# src/xz_dec_bcj.c ) # TODO: look into what would be needed for plain old lzma -# checksum checks -add_definitions(-DXZ_DEC_ANY_CHECK) -if(XZ_BUILD_CRC64) - add_definitions(-DXZ_USE_CRC64) - LIST(APPEND XZ_SOURCES src/xz_crc64.c) -endif() -# TODO: add SHA256 - -if(XZ_BUILD_BCJ) - add_definitions(-DXZ_DEC_X86 -DXZ_DEC_POWERPC -DXZ_DEC_IA64) - add_definitions(-DXZ_DEC_ARM -DXZ_DEC_ARMTHUMB -DXZ_DEC_SPARC) - LIST(APPEND XZ_SOURCES src/xz_dec_bcj.c) -endif() - add_library(xz-embedded STATIC ${XZ_SOURCES}) add_executable(xzminidec xzminidec.c) target_link_libraries(xzminidec xz-embedded) diff --git a/depends/xz-embedded/include/xz.h b/depends/xz-embedded/include/xz.h index 0a4b38d3..49a96f7b 100644 --- a/depends/xz-embedded/include/xz.h +++ b/depends/xz-embedded/include/xz.h @@ -23,6 +23,21 @@ extern "C" { #endif +/* Definitions that determine available features */ +#define XZ_DEC_ANY_CHECK 1 +#define XZ_USE_CRC64 1 + +// native machine code compression stuff +/* +#define XZ_DEC_X86 +#define XZ_DEC_POWERPC +#define XZ_DEC_IA64 +#define XZ_DEC_ARM +#define XZ_DEC_ARMTHUMB +#define XZ_DEC_SPARC +*/ + + /* In Linux, this is used to make extern functions static when needed. */ #ifndef XZ_EXTERN # define XZ_EXTERN extern diff --git a/gui/LegacyModEditDialog.cpp b/gui/LegacyModEditDialog.cpp index 20296769..053aef6b 100644 --- a/gui/LegacyModEditDialog.cpp +++ b/gui/LegacyModEditDialog.cpp @@ -210,7 +210,7 @@ void LegacyModEditDialog::on_addForgeBtn_clicked() if(entry->stale) { DownloadJob * fjob = new DownloadJob("Forge download"); - fjob->add(forge->universal_url, entry); + fjob->addCacheDownload(forge->universal_url, entry); ProgressDialog dlg(this); dlg.exec(fjob); if(dlg.result() == QDialog::Accepted) diff --git a/gui/OneSixModEditDialog.cpp b/gui/OneSixModEditDialog.cpp index 94fea933..f2e7c5d2 100644 --- a/gui/OneSixModEditDialog.cpp +++ b/gui/OneSixModEditDialog.cpp @@ -160,7 +160,7 @@ void OneSixModEditDialog::on_forgeBtn_clicked() if (entry->stale) { DownloadJob *fjob = new DownloadJob("Forge download"); - fjob->add(forgeVersion->installer_url, entry); + fjob->addCacheDownload(forgeVersion->installer_url, entry); ProgressDialog dlg(this); dlg.exec(fjob); if (dlg.result() == QDialog::Accepted) diff --git a/logic/ForgeInstaller.cpp b/logic/ForgeInstaller.cpp index bcba00e9..9ae3f1e1 100644 --- a/logic/ForgeInstaller.cpp +++ b/logic/ForgeInstaller.cpp @@ -100,11 +100,16 @@ bool ForgeInstaller::apply(QSharedPointer to) for (auto lib : m_forge_version->libraries) { QString libName = lib->name(); + // WARNING: This could actually break. // if this is the actual forge lib, set an absolute url for the download if (libName.contains("minecraftforge")) { lib->setAbsoluteUrl(m_universal_url); } + else if (libName.contains("scala")) + { + lib->setHint("forge-pack-xz"); + } if (blacklist.contains(libName)) continue; diff --git a/logic/LegacyUpdate.cpp b/logic/LegacyUpdate.cpp index 84d3d830..d8e622dd 100644 --- a/logic/LegacyUpdate.cpp +++ b/logic/LegacyUpdate.cpp @@ -228,7 +228,7 @@ void LegacyUpdate::jarStart() urlstr += intended_version_id + "/" + intended_version_id + ".jar"; auto dljob = new DownloadJob("Minecraft.jar for version " + intended_version_id); - dljob->add(QUrl(urlstr), inst->defaultBaseJar()); + dljob->addFileDownload(QUrl(urlstr), inst->defaultBaseJar()); legacyDownloadJob.reset(dljob); connect(dljob, SIGNAL(succeeded()), SLOT(jarFinished())); connect(dljob, SIGNAL(failed()), SLOT(jarFailed())); diff --git a/logic/OneSixAssets.cpp b/logic/OneSixAssets.cpp index 5bdd29d7..ca7a5534 100644 --- a/logic/OneSixAssets.cpp +++ b/logic/OneSixAssets.cpp @@ -113,7 +113,7 @@ void OneSixAssets::fetchXMLFinished() auto entry = metacache->resolveEntry("assets", keyStr, etagStr); if(entry->stale) { - job->add(QUrl(prefix + keyStr), entry); + job->addCacheDownload(QUrl(prefix + keyStr), entry); } } if(job->size()) @@ -130,7 +130,7 @@ void OneSixAssets::fetchXMLFinished() void OneSixAssets::start() { auto job = new DownloadJob("Assets index"); - job->add(QUrl ( "http://s3.amazonaws.com/Minecraft.Resources/" )); + job->addByteArrayDownload(QUrl ( "http://s3.amazonaws.com/Minecraft.Resources/" )); connect ( job, SIGNAL(succeeded()), SLOT ( fetchXMLFinished() ) ); index_job.reset ( job ); job->start(); diff --git a/logic/OneSixLibrary.cpp b/logic/OneSixLibrary.cpp index 8da1fde7..63d42646 100644 --- a/logic/OneSixLibrary.cpp +++ b/logic/OneSixLibrary.cpp @@ -105,12 +105,24 @@ QString OneSixLibrary::absoluteUrl() return m_absolute_url; } +void OneSixLibrary::setHint(QString hint) +{ + m_hint = hint; +} + +QString OneSixLibrary::hint() +{ + return m_hint; +} + QJsonObject OneSixLibrary::toJson() { QJsonObject libRoot; libRoot.insert("name", m_name); if(m_absolute_url.size()) - libRoot.insert("MMC-absulute_url", m_absolute_url); + libRoot.insert("MMC-absoluteUrl", m_absolute_url); + if(m_hint.size()) + libRoot.insert("MMC-hint", m_hint); if(m_base_url != "https://s3.amazonaws.com/Minecraft.Download/libraries/") libRoot.insert("url", m_base_url); if (isNative() && m_native_suffixes.size()) diff --git a/logic/OneSixLibrary.h b/logic/OneSixLibrary.h index f3106483..2a16d8e1 100644 --- a/logic/OneSixLibrary.h +++ b/logic/OneSixLibrary.h @@ -19,6 +19,8 @@ private: // custom values /// absolute URL. takes precedence over m_download_path, if defined QString m_absolute_url; + /// download hint - how to actually get the library + QString m_hint; // derived values used for real things /// a decent name fit for display @@ -91,8 +93,12 @@ public: QString downloadUrl(); /// Get the relative path where the library should be saved QString storagePath(); - + /// set an absolute URL for the library. This is an MMC extension. void setAbsoluteUrl(QString absolute_url); QString absoluteUrl(); + + /// set a hint about how to treat the library. This is an MMC extension. + void setHint(QString hint); + QString hint(); }; diff --git a/logic/OneSixUpdate.cpp b/logic/OneSixUpdate.cpp index 73bd9403..41d8f599 100644 --- a/logic/OneSixUpdate.cpp +++ b/logic/OneSixUpdate.cpp @@ -75,7 +75,7 @@ void OneSixUpdate::versionFileStart() QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/"); urlstr += targetVersion->descriptor() + "/" + targetVersion->descriptor() + ".json"; auto job = new DownloadJob("Version index"); - job->add(QUrl(urlstr)); + job->addByteArrayDownload(QUrl(urlstr)); specificVersionDownloadJob.reset(job); connect(specificVersionDownloadJob.data(), SIGNAL(succeeded()), SLOT(versionFileFinished())); @@ -158,7 +158,7 @@ void OneSixUpdate::jarlibStart() targetstr += version->id + "/" + version->id + ".jar"; auto job = new DownloadJob("Libraries for instance " + inst->name()); - job->add(QUrl(urlstr), targetstr); + job->addFileDownload(QUrl(urlstr), targetstr); jarlibDownloadJob.reset(job); auto libs = version->getActiveNativeLibs(); @@ -171,7 +171,10 @@ void OneSixUpdate::jarlibStart() auto entry = metacache->resolveEntry("libraries", lib->storagePath()); if (entry->stale) { - jarlibDownloadJob->add(download_path, entry); + if(lib->hint() == "forge-pack-xz") + jarlibDownloadJob->addForgeXzDownload(download_path, entry); + else + jarlibDownloadJob->addCacheDownload(download_path, entry); } } connect(jarlibDownloadJob.data(), SIGNAL(succeeded()), SLOT(jarlibFinished())); diff --git a/logic/OneSixVersion.cpp b/logic/OneSixVersion.cpp index 663d903a..64a47562 100644 --- a/logic/OneSixVersion.cpp +++ b/logic/OneSixVersion.cpp @@ -71,11 +71,21 @@ QSharedPointer fromJsonV4(QJsonObject root, { library->setBaseUrl(urlVal.toString()); } - auto urlAbsVal = libObj.value("MMC-absulute_url"); + 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()) diff --git a/logic/lists/ForgeVersionList.cpp b/logic/lists/ForgeVersionList.cpp index 721f2c0a..e2adbf3b 100644 --- a/logic/lists/ForgeVersionList.cpp +++ b/logic/lists/ForgeVersionList.cpp @@ -162,7 +162,7 @@ void ForgeListLoadTask::executeTask() auto job = new DownloadJob("Version index"); // we do not care if the version is stale or not. auto forgeListEntry = MMC->metacache()->resolveEntry("minecraftforge", "list.json"); - job->add(QUrl(JSON_URL), forgeListEntry); + job->addCacheDownload(QUrl(JSON_URL), forgeListEntry); listJob.reset(job); connect(listJob.data(), SIGNAL(succeeded()), SLOT(list_downloaded())); connect(listJob.data(), SIGNAL(failed()), SLOT(versionFileFailed())); diff --git a/logic/lists/MinecraftVersionList.h b/logic/lists/MinecraftVersionList.h index fb28ddfe..ed68efbb 100644 --- a/logic/lists/MinecraftVersionList.h +++ b/logic/lists/MinecraftVersionList.h @@ -46,7 +46,7 @@ public: protected: QList m_vlist; - bool m_loaded; + bool m_loaded = false; protected slots: virtual void updateListData(QList versions); diff --git a/logic/net/DownloadJob.cpp b/logic/net/DownloadJob.cpp index 8da1f39b..03a69555 100644 --- a/logic/net/DownloadJob.cpp +++ b/logic/net/DownloadJob.cpp @@ -7,7 +7,7 @@ #include -ByteArrayDownloadPtr DownloadJob::add(QUrl url) +ByteArrayDownloadPtr DownloadJob::addByteArrayDownload(QUrl url) { ByteArrayDownloadPtr ptr(new ByteArrayDownload(url)); ptr->index_within_job = downloads.size(); @@ -17,7 +17,7 @@ ByteArrayDownloadPtr DownloadJob::add(QUrl url) return ptr; } -FileDownloadPtr DownloadJob::add(QUrl url, QString rel_target_path) +FileDownloadPtr DownloadJob::addFileDownload(QUrl url, QString rel_target_path) { FileDownloadPtr ptr(new FileDownload(url, rel_target_path)); ptr->index_within_job = downloads.size(); @@ -27,7 +27,7 @@ FileDownloadPtr DownloadJob::add(QUrl url, QString rel_target_path) return ptr; } -CacheDownloadPtr DownloadJob::add(QUrl url, MetaEntryPtr entry) +CacheDownloadPtr DownloadJob::addCacheDownload(QUrl url, MetaEntryPtr entry) { CacheDownloadPtr ptr(new CacheDownload(url, entry)); ptr->index_within_job = downloads.size(); @@ -37,6 +37,16 @@ CacheDownloadPtr DownloadJob::add(QUrl url, MetaEntryPtr entry) return ptr; } +ForgeXzDownloadPtr DownloadJob::addForgeXzDownload(QUrl url, MetaEntryPtr entry) +{ + ForgeXzDownloadPtr ptr(new ForgeXzDownload(url, entry)); + ptr->index_within_job = downloads.size(); + downloads.append(ptr); + parts_progress.append(part_info()); + total_progress++; + return ptr; +} + void DownloadJob::partSucceeded(int index) { // do progress. all slots are 1 in size at least diff --git a/logic/net/DownloadJob.h b/logic/net/DownloadJob.h index 5d5ba01a..8c32950a 100644 --- a/logic/net/DownloadJob.h +++ b/logic/net/DownloadJob.h @@ -5,6 +5,7 @@ #include "FileDownload.h" #include "CacheDownload.h" #include "HttpMetaCache.h" +#include "ForgeXzDownload.h" #include "logic/tasks/ProgressProvider.h" class DownloadJob; @@ -20,9 +21,10 @@ public: explicit DownloadJob(QString job_name) :ProgressProvider(), m_job_name(job_name){}; - ByteArrayDownloadPtr add(QUrl url); - FileDownloadPtr add(QUrl url, QString rel_target_path); - CacheDownloadPtr add(QUrl url, MetaEntryPtr entry); + ByteArrayDownloadPtr addByteArrayDownload(QUrl url); + FileDownloadPtr addFileDownload(QUrl url, QString rel_target_path); + CacheDownloadPtr addCacheDownload(QUrl url, MetaEntryPtr entry); + ForgeXzDownloadPtr addForgeXzDownload(QUrl url, MetaEntryPtr entry); DownloadPtr operator[](int index) { diff --git a/logic/net/ForgeXzDownload.cpp b/logic/net/ForgeXzDownload.cpp new file mode 100644 index 00000000..b7e7eedf --- /dev/null +++ b/logic/net/ForgeXzDownload.cpp @@ -0,0 +1,277 @@ +#include "MultiMC.h" +#include "ForgeXzDownload.h" +#include + +#include +#include +#include +#include + +ForgeXzDownload::ForgeXzDownload(QUrl url, MetaEntryPtr entry) + : Download() +{ + QString urlstr = url.toString(); + urlstr.append(".pack.xz"); + m_url = QUrl(urlstr); + m_entry = entry; + m_target_path = entry->getFullPath(); + m_status = Job_NotStarted; + m_opened_for_saving = false; +} + +void ForgeXzDownload::start() +{ + if (!m_entry->stale) + { + emit succeeded(index_within_job); + return; + } + // can we actually create the real, final file? + if (!ensureFilePathExists(m_target_path)) + { + emit failed(index_within_job); + return; + } + qDebug() << "Downloading " << m_url.toString(); + QNetworkRequest request(m_url); + request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->etag.toLatin1()); + + auto worker = MMC->qnam(); + QNetworkReply *rep = worker->get(request); + + m_reply = QSharedPointer(rep, &QObject::deleteLater); + connect(rep, SIGNAL(downloadProgress(qint64, qint64)), + SLOT(downloadProgress(qint64, qint64))); + connect(rep, SIGNAL(finished()), SLOT(downloadFinished())); + connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), + SLOT(downloadError(QNetworkReply::NetworkError))); + connect(rep, SIGNAL(readyRead()), SLOT(downloadReadyRead())); +} + +void ForgeXzDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) +{ + emit progress(index_within_job, bytesReceived, bytesTotal); +} + +void ForgeXzDownload::downloadError(QNetworkReply::NetworkError error) +{ + // error happened during download. + // TODO: log the reason why + m_status = Job_Failed; +} + +void ForgeXzDownload::downloadFinished() +{ + // if the download succeeded + if (m_status != Job_Failed) + { + // nothing went wrong... + m_status = Job_Finished; + if (m_opened_for_saving) + { + // we actually downloaded something! process and isntall it + decompressAndInstall(); + return; + } + else + { + // something bad happened + m_pack200_xz_file.remove(); + m_reply.clear(); + emit failed(index_within_job); + return; + } + } + // else the download failed + else + { + m_pack200_xz_file.close(); + m_pack200_xz_file.remove(); + m_reply.clear(); + emit failed(index_within_job); + return; + } +} + +void ForgeXzDownload::downloadReadyRead() +{ + + if (!m_opened_for_saving) + { + if (!m_pack200_xz_file.open()) + { + /* + * Can't open the file... the job failed + */ + m_reply->abort(); + emit failed(index_within_job); + return; + } + m_opened_for_saving = true; + } + m_pack200_xz_file.write(m_reply->readAll()); +} + +#include "xz.h" +#include "unpack200.h" + +const size_t buffer_size = 8196; + +void ForgeXzDownload::decompressAndInstall() +{ + // rewind the downloaded temp file + m_pack200_xz_file.seek(0); + // de-xz'd file + QTemporaryFile pack200_file; + pack200_file.open(); + + bool xz_success = false; + // first, de-xz + { + uint8_t in[buffer_size]; + uint8_t out[buffer_size]; + struct xz_buf b; + struct xz_dec *s; + enum xz_ret ret; + xz_crc32_init(); + xz_crc64_init(); + s = xz_dec_init(XZ_DYNALLOC, 1 << 26); + if (s == nullptr) + { + xz_dec_end(s); + emit failed(index_within_job); + return; + } + b.in = in; + b.in_pos = 0; + b.in_size = 0; + b.out = out; + b.out_pos = 0; + b.out_size = buffer_size; + while (!xz_success) + { + if (b.in_pos == b.in_size) + { + b.in_size = m_pack200_xz_file.read((char*)in, sizeof(in)); + b.in_pos = 0; + } + + ret = xz_dec_run(s, &b); + + if (b.out_pos == sizeof(out)) + { + if (pack200_file.write((char*)out, b.out_pos) != b.out_pos) + { + // msg = "Write error\n"; + xz_dec_end(s); + emit failed(index_within_job); + return; + } + + b.out_pos = 0; + } + + if (ret == XZ_OK) + continue; + + if (ret == XZ_UNSUPPORTED_CHECK) + { + // unsupported check. this is OK, but we should log this + continue; + } + + if (pack200_file.write((char*)out, b.out_pos) != b.out_pos ) + { + // write error + pack200_file.close(); + xz_dec_end(s); + return; + } + + switch (ret) + { + case XZ_STREAM_END: + xz_dec_end(s); + xz_success = true; + break; + + case XZ_MEM_ERROR: + qDebug() << "Memory allocation failed\n"; + xz_dec_end(s); + emit failed(index_within_job); + return; + + case XZ_MEMLIMIT_ERROR: + qDebug() << "Memory usage limit reached\n"; + xz_dec_end(s); + emit failed(index_within_job); + return; + + case XZ_FORMAT_ERROR: + qDebug() << "Not a .xz file\n"; + xz_dec_end(s); + emit failed(index_within_job); + return; + + case XZ_OPTIONS_ERROR: + qDebug() << "Unsupported options in the .xz headers\n"; + xz_dec_end(s); + emit failed(index_within_job); + return; + + case XZ_DATA_ERROR: + case XZ_BUF_ERROR: + qDebug() << "File is corrupt\n"; + xz_dec_end(s); + emit failed(index_within_job); + return; + + default: + qDebug() << "Bug!\n"; + xz_dec_end(s); + emit failed(index_within_job); + return; + } + } + } + + // revert pack200 + pack200_file.close(); + QString pack_name = pack200_file.fileName(); + try + { + unpack_200(pack_name.toStdString(), m_target_path.toStdString()); + } + catch(std::runtime_error & err) + { + qDebug() << "Error unpacking " << pack_name.toUtf8() << " : " << err.what(); + QFile f(m_target_path); + if(f.exists()) + f.remove(); + emit failed(index_within_job); + return; + } + + QFile jar_file(m_target_path); + + if (!jar_file.open(QIODevice::ReadOnly)) + { + jar_file.remove(); + emit failed(index_within_job); + return; + } + m_entry->md5sum = QCryptographicHash::hash(jar_file.readAll(), QCryptographicHash::Md5) + .toHex() + .constData(); + jar_file.close(); + + QFileInfo output_file_info(m_target_path); + m_entry->etag = m_reply->rawHeader("ETag").constData(); + m_entry->last_changed_timestamp = + output_file_info.lastModified().toUTC().toMSecsSinceEpoch(); + m_entry->stale = false; + MMC->metacache()->updateEntry(m_entry); + + m_reply.clear(); + emit succeeded(index_within_job); +} diff --git a/logic/net/ForgeXzDownload.h b/logic/net/ForgeXzDownload.h new file mode 100644 index 00000000..8cb47783 --- /dev/null +++ b/logic/net/ForgeXzDownload.h @@ -0,0 +1,35 @@ +#pragma once + +#include "Download.h" +#include "HttpMetaCache.h" +#include +#include + +class ForgeXzDownload : public Download +{ + Q_OBJECT +public: + MetaEntryPtr m_entry; + /// is the saving file already open? + bool m_opened_for_saving; + /// if saving to file, use the one specified in this string + QString m_target_path; + /// this is the output file, if any + QTemporaryFile m_pack200_xz_file; + +public: + explicit ForgeXzDownload(QUrl url, MetaEntryPtr entry); + +protected slots: + virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); + virtual void downloadError(QNetworkReply::NetworkError error); + virtual void downloadFinished(); + virtual void downloadReadyRead(); + +public slots: + virtual void start(); +private: + void decompressAndInstall(); +}; + +typedef QSharedPointer ForgeXzDownloadPtr; -- cgit From f83119ce7ec3d11a903901b8eff762d2b0a9f635 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 6 Oct 2013 01:13:40 +0200 Subject: Added file logger --- CMakeLists.txt | 8 + MultiMC.cpp | 34 +++- MultiMC.h | 84 ++++---- gui/IconPickerDialog.cpp | 2 +- gui/LegacyModEditDialog.cpp | 206 ++++++++++---------- gui/LegacyModEditDialog.h | 8 +- gui/OneSixModEditDialog.cpp | 19 +- gui/OneSixModEditDialog.h | 6 +- gui/aboutdialog.ui | 97 +++++----- gui/logindialog.cpp | 10 +- gui/lwjglselectdialog.cpp | 6 +- gui/mainwindow.cpp | 360 ++++++++++++++++++----------------- gui/newinstancedialog.cpp | 2 +- gui/settingsdialog.cpp | 4 +- gui/versionselectdialog.cpp | 2 +- logger/QsDebugOutput.cpp | 52 +++++ logger/QsDebugOutput.h | 34 ++++ logger/QsLog.cpp | 141 ++++++++++++++ logger/QsLog.h | 130 +++++++++++++ logger/QsLogDest.cpp | 83 ++++++++ logger/QsLogDest.h | 53 ++++++ logic/BaseInstance.cpp | 2 +- logic/BaseInstance.h | 6 +- logic/BaseInstance_p.h | 2 +- logic/BaseVersion.h | 4 +- logic/ForgeInstaller.cpp | 4 +- logic/ForgeInstaller.h | 6 +- logic/InstanceFactory.cpp | 5 +- logic/InstanceLauncher.cpp | 2 +- logic/LegacyInstance.cpp | 8 +- logic/LegacyInstance.h | 8 +- logic/LegacyInstance_p.h | 8 +- logic/LegacyUpdate.cpp | 213 +++++++++++---------- logic/LegacyUpdate.h | 2 +- logic/Mod.cpp | 7 +- logic/ModList.cpp | 16 +- logic/OneSixAssets.cpp | 13 +- logic/OneSixInstance.cpp | 9 +- logic/OneSixInstance.h | 6 +- logic/OneSixInstance_p.h | 6 +- logic/OneSixLibrary.cpp | 2 +- logic/OneSixLibrary.h | 6 +- logic/OneSixRule.cpp | 6 +- logic/OneSixRule.h | 10 +- logic/OneSixUpdate.cpp | 25 ++- logic/OneSixUpdate.h | 2 +- logic/OneSixVersion.cpp | 28 +-- logic/OneSixVersion.h | 12 +- logic/lists/ForgeVersionList.cpp | 20 +- logic/lists/ForgeVersionList.h | 2 +- logic/lists/InstanceList.cpp | 218 +++++++++++---------- logic/lists/LwjglVersionList.cpp | 62 +++--- logic/lists/LwjglVersionList.h | 6 +- logic/lists/MinecraftVersionList.cpp | 10 +- logic/net/ByteArrayDownload.cpp | 13 +- logic/net/ByteArrayDownload.h | 2 +- logic/net/CacheDownload.cpp | 10 +- logic/net/CacheDownload.h | 2 +- logic/net/Download.h | 18 +- logic/net/DownloadJob.cpp | 22 +-- logic/net/DownloadJob.h | 2 +- logic/net/FileDownload.cpp | 12 +- logic/net/FileDownload.h | 2 +- logic/net/ForgeXzDownload.cpp | 26 +-- logic/net/ForgeXzDownload.h | 2 +- logic/net/HttpMetaCache.cpp | 6 +- logic/net/HttpMetaCache.h | 2 +- logic/net/LoginTask.cpp | 4 +- logic/tasks/Task.cpp | 2 + 69 files changed, 1375 insertions(+), 827 deletions(-) create mode 100644 logger/QsDebugOutput.cpp create mode 100644 logger/QsDebugOutput.h create mode 100644 logger/QsLog.cpp create mode 100644 logger/QsLog.h create mode 100644 logger/QsLogDest.cpp create mode 100644 logger/QsLogDest.h (limited to 'logic/LegacyUpdate.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index e0637054..7ecfb690 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,6 +168,14 @@ MultiMC.h MultiMC.cpp MultiMCVersion.h +# Logging +logger/QsDebugOutput.cpp +logger/QsDebugOutput.h +logger/QsLog.cpp +logger/QsLog.h +logger/QsLogDest.cpp +logger/QsLogDest.h + # GUI gui/mainwindow.h gui/mainwindow.cpp diff --git a/MultiMC.cpp b/MultiMC.cpp index ee9a9bf8..b685ed13 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -20,6 +20,8 @@ #include "cmdutils.h" #include #include +#include +#include #include "config.h" using namespace Util::Commandline; @@ -123,6 +125,9 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv) // change directory QDir::setCurrent(args["dir"].toString()); + // init the logger + initLogger(); + // load settings initGlobalSettings(); @@ -156,11 +161,11 @@ MultiMC::~MultiMC() { if (m_mmc_translator) { - removeTranslator(m_mmc_translator.data()); + removeTranslator(m_mmc_translator.get()); } if (m_qt_translator) { - removeTranslator(m_qt_translator.data()); + removeTranslator(m_qt_translator.get()); } } @@ -172,7 +177,7 @@ void MultiMC::initTranslations() { std::cout << "Loading Qt Language File for " << QLocale::system().name().toLocal8Bit().constData() << "..."; - if (!installTranslator(m_qt_translator.data())) + if (!installTranslator(m_qt_translator.get())) { std::cout << " failed."; m_qt_translator.reset(); @@ -190,7 +195,7 @@ void MultiMC::initTranslations() { std::cout << "Loading MMC Language File for " << QLocale::system().name().toLocal8Bit().constData() << "..."; - if (!installTranslator(m_mmc_translator.data())) + if (!installTranslator(m_mmc_translator.get())) { std::cout << " failed."; m_mmc_translator.reset(); @@ -203,6 +208,19 @@ void MultiMC::initTranslations() } } +void MultiMC::initLogger() +{ + // init the logging mechanism + QsLogging::Logger &logger = QsLogging::Logger::instance(); + logger.setLoggingLevel(QsLogging::TraceLevel); + m_fileDestination = QsLogging::DestinationFactory::MakeFileDestination("MultiMC.log"); + m_debugDestination = QsLogging::DestinationFactory::MakeDebugOutputDestination(); + logger.addDestination(m_fileDestination.get()); + logger.addDestination(m_debugDestination.get()); + // log all the things + logger.setLoggingLevel(QsLogging::TraceLevel); +} + void MultiMC::initGlobalSettings() { m_settings.reset(new INISettingsObject("multimc.cfg", this)); @@ -275,7 +293,7 @@ void MultiMC::initHttpMetaCache() m_metacache->Load(); } -QSharedPointer MultiMC::icons() +std::shared_ptr MultiMC::icons() { if (!m_icons) { @@ -284,7 +302,7 @@ QSharedPointer MultiMC::icons() return m_icons; } -QSharedPointer MultiMC::lwjgllist() +std::shared_ptr MultiMC::lwjgllist() { if (!m_lwjgllist) { @@ -293,7 +311,7 @@ QSharedPointer MultiMC::lwjgllist() return m_lwjgllist; } -QSharedPointer MultiMC::forgelist() +std::shared_ptr MultiMC::forgelist() { if (!m_forgelist) { @@ -302,7 +320,7 @@ QSharedPointer MultiMC::forgelist() return m_forgelist; } -QSharedPointer MultiMC::minecraftlist() +std::shared_ptr MultiMC::minecraftlist() { if (!m_minecraftlist) { diff --git a/MultiMC.h b/MultiMC.h index c634dd33..ec28cab2 100644 --- a/MultiMC.h +++ b/MultiMC.h @@ -1,9 +1,12 @@ #pragma once #include -#include #include "MultiMCVersion.h" #include "config.h" +#include +#include "logger/QsLog.h" +#include "logger/QsLogDest.h" + class MinecraftVersionList; class LWJGLVersionList; @@ -29,67 +32,72 @@ public: Succeeded, Initialized, }; - + public: - MultiMC ( int& argc, char** argv ); + MultiMC(int &argc, char **argv); virtual ~MultiMC(); - - QSharedPointer settings() + + std::shared_ptr settings() { return m_settings; - }; - - QSharedPointer instances() + } + + std::shared_ptr instances() { return m_instances; - }; - - QSharedPointer icons(); - + } + + std::shared_ptr icons(); + Status status() { return m_status; } - + MultiMCVersion version() { return m_version; } - - QSharedPointer qnam() + + std::shared_ptr qnam() { return m_qnam; } - - QSharedPointer metacache() + + std::shared_ptr metacache() { return m_metacache; } - - QSharedPointer lwjgllist(); - - QSharedPointer forgelist(); - - QSharedPointer minecraftlist(); - + + std::shared_ptr lwjgllist(); + + std::shared_ptr forgelist(); + + std::shared_ptr minecraftlist(); + private: + void initLogger(); + void initGlobalSettings(); - + void initHttpMetaCache(); - + void initTranslations(); + private: - QSharedPointer m_qt_translator; - QSharedPointer m_mmc_translator; - QSharedPointer m_settings; - QSharedPointer m_instances; - QSharedPointer m_icons; - QSharedPointer m_qnam; - QSharedPointer m_metacache; - QSharedPointer m_lwjgllist; - QSharedPointer m_forgelist; - QSharedPointer m_minecraftlist; - + std::shared_ptr m_qt_translator; + std::shared_ptr m_mmc_translator; + std::shared_ptr m_settings; + std::shared_ptr m_instances; + std::shared_ptr m_icons; + std::shared_ptr m_qnam; + std::shared_ptr m_metacache; + std::shared_ptr m_lwjgllist; + std::shared_ptr m_forgelist; + std::shared_ptr m_minecraftlist; + QsLogging::DestinationPtr m_fileDestination; + QsLogging::DestinationPtr m_debugDestination; + Status m_status = MultiMC::Failed; MultiMCVersion m_version = {VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION, VERSION_BUILD}; -}; \ No newline at end of file +}; diff --git a/gui/IconPickerDialog.cpp b/gui/IconPickerDialog.cpp index 8f5d8256..6a1ca546 100644 --- a/gui/IconPickerDialog.cpp +++ b/gui/IconPickerDialog.cpp @@ -39,7 +39,7 @@ IconPickerDialog::IconPickerDialog(QWidget *parent) : contentsWidget->installEventFilter(this); - contentsWidget->setModel(MMC->icons().data()); + contentsWidget->setModel(MMC->icons().get()); auto buttonAdd = ui->buttonBox->addButton(tr("Add Icon"),QDialogButtonBox::ResetRole); auto buttonRemove = ui->buttonBox->addButton(tr("Remove Icon"),QDialogButtonBox::ResetRole); diff --git a/gui/LegacyModEditDialog.cpp b/gui/LegacyModEditDialog.cpp index 053aef6b..c240daff 100644 --- a/gui/LegacyModEditDialog.cpp +++ b/gui/LegacyModEditDialog.cpp @@ -3,7 +3,7 @@ * 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 @@ -28,49 +28,47 @@ #include #include -LegacyModEditDialog::LegacyModEditDialog( LegacyInstance* inst, QWidget* parent ) : - m_inst(inst), - QDialog(parent), - ui(new Ui::LegacyModEditDialog) +LegacyModEditDialog::LegacyModEditDialog(LegacyInstance *inst, QWidget *parent) + : m_inst(inst), QDialog(parent), ui(new Ui::LegacyModEditDialog) { ui->setupUi(this); - + // Jar mods { ensureFolderPathExists(m_inst->jarModsDir()); m_jarmods = m_inst->jarModList(); - ui->jarModsTreeView->setModel(m_jarmods.data()); + ui->jarModsTreeView->setModel(m_jarmods.get()); #ifndef Q_OS_LINUX // FIXME: internal DnD causes segfaults later ui->jarModsTreeView->setDragDropMode(QAbstractItemView::DragDrop); // FIXME: DnD is glitched with contiguous (we move only first item in selection) ui->jarModsTreeView->setSelectionMode(QAbstractItemView::SingleSelection); #endif - ui->jarModsTreeView->installEventFilter( this ); + ui->jarModsTreeView->installEventFilter(this); m_jarmods->startWatching(); } // Core mods { ensureFolderPathExists(m_inst->coreModsDir()); m_coremods = m_inst->coreModList(); - ui->coreModsTreeView->setModel(m_coremods.data()); - ui->coreModsTreeView->installEventFilter( this ); + ui->coreModsTreeView->setModel(m_coremods.get()); + ui->coreModsTreeView->installEventFilter(this); m_coremods->startWatching(); } // Loader mods { ensureFolderPathExists(m_inst->loaderModsDir()); m_mods = m_inst->loaderModList(); - ui->loaderModTreeView->setModel(m_mods.data()); - ui->loaderModTreeView->installEventFilter( this ); + ui->loaderModTreeView->setModel(m_mods.get()); + ui->loaderModTreeView->installEventFilter(this); m_mods->startWatching(); } // texture packs { ensureFolderPathExists(m_inst->texturePacksDir()); m_texturepacks = m_inst->texturePackList(); - ui->texPackTreeView->setModel(m_texturepacks.data()); - ui->texPackTreeView->installEventFilter( this ); + ui->texPackTreeView->setModel(m_texturepacks.get()); + ui->texPackTreeView->installEventFilter(this); m_texturepacks->startWatching(); } } @@ -84,113 +82,111 @@ LegacyModEditDialog::~LegacyModEditDialog() delete ui; } -bool LegacyModEditDialog::coreListFilter ( QKeyEvent* keyEvent ) +bool LegacyModEditDialog::coreListFilter(QKeyEvent *keyEvent) { - switch(keyEvent->key()) + switch (keyEvent->key()) { - case Qt::Key_Delete: - on_rmCoreBtn_clicked(); - return true; - case Qt::Key_Plus: - on_addCoreBtn_clicked(); - return true; - default: - break; + case Qt::Key_Delete: + on_rmCoreBtn_clicked(); + return true; + case Qt::Key_Plus: + on_addCoreBtn_clicked(); + return true; + default: + break; } - return QDialog::eventFilter( ui->coreModsTreeView, keyEvent ); + return QDialog::eventFilter(ui->coreModsTreeView, keyEvent); } -bool LegacyModEditDialog::jarListFilter ( QKeyEvent* keyEvent ) +bool LegacyModEditDialog::jarListFilter(QKeyEvent *keyEvent) { - switch(keyEvent->key()) + switch (keyEvent->key()) { - case Qt::Key_Up: + case Qt::Key_Up: + { + if (keyEvent->modifiers() & Qt::ControlModifier) { - if(keyEvent->modifiers() & Qt::ControlModifier) - { - on_moveJarUpBtn_clicked(); - return true; - } - break; + on_moveJarUpBtn_clicked(); + return true; } - case Qt::Key_Down: + break; + } + case Qt::Key_Down: + { + if (keyEvent->modifiers() & Qt::ControlModifier) { - if(keyEvent->modifiers() & Qt::ControlModifier) - { - on_moveJarDownBtn_clicked(); - return true; - } - break; - } - case Qt::Key_Delete: - on_rmJarBtn_clicked(); - return true; - case Qt::Key_Plus: - on_addJarBtn_clicked(); + on_moveJarDownBtn_clicked(); return true; - default: - break; + } + break; } - return QDialog::eventFilter( ui->jarModsTreeView, keyEvent ); + case Qt::Key_Delete: + on_rmJarBtn_clicked(); + return true; + case Qt::Key_Plus: + on_addJarBtn_clicked(); + return true; + default: + break; + } + return QDialog::eventFilter(ui->jarModsTreeView, keyEvent); } -bool LegacyModEditDialog::loaderListFilter ( QKeyEvent* keyEvent ) +bool LegacyModEditDialog::loaderListFilter(QKeyEvent *keyEvent) { - switch(keyEvent->key()) + switch (keyEvent->key()) { - case Qt::Key_Delete: - on_rmModBtn_clicked(); - return true; - case Qt::Key_Plus: - on_addModBtn_clicked(); - return true; - default: - break; + case Qt::Key_Delete: + on_rmModBtn_clicked(); + return true; + case Qt::Key_Plus: + on_addModBtn_clicked(); + return true; + default: + break; } - return QDialog::eventFilter( ui->loaderModTreeView, keyEvent ); + return QDialog::eventFilter(ui->loaderModTreeView, keyEvent); } -bool LegacyModEditDialog::texturePackListFilter ( QKeyEvent* keyEvent ) +bool LegacyModEditDialog::texturePackListFilter(QKeyEvent *keyEvent) { - switch(keyEvent->key()) + switch (keyEvent->key()) { - case Qt::Key_Delete: - on_rmTexPackBtn_clicked(); - return true; - case Qt::Key_Plus: - on_addTexPackBtn_clicked(); - return true; - default: - break; + case Qt::Key_Delete: + on_rmTexPackBtn_clicked(); + return true; + case Qt::Key_Plus: + on_addTexPackBtn_clicked(); + return true; + default: + break; } - return QDialog::eventFilter( ui->texPackTreeView, keyEvent ); + return QDialog::eventFilter(ui->texPackTreeView, keyEvent); } - -bool LegacyModEditDialog::eventFilter ( QObject* obj, QEvent* ev ) +bool LegacyModEditDialog::eventFilter(QObject *obj, QEvent *ev) { if (ev->type() != QEvent::KeyPress) { - return QDialog::eventFilter( obj, ev ); + return QDialog::eventFilter(obj, ev); } - QKeyEvent *keyEvent = static_cast(ev); - if(obj == ui->jarModsTreeView) + QKeyEvent *keyEvent = static_cast(ev); + if (obj == ui->jarModsTreeView) return jarListFilter(keyEvent); - if(obj == ui->coreModsTreeView) + if (obj == ui->coreModsTreeView) return coreListFilter(keyEvent); - if(obj == ui->loaderModTreeView) + if (obj == ui->loaderModTreeView) return loaderListFilter(keyEvent); - if(obj == ui->texPackTreeView) + if (obj == ui->texPackTreeView) return texturePackListFilter(keyEvent); - return QDialog::eventFilter( obj, ev ); + return QDialog::eventFilter(obj, ev); } - void LegacyModEditDialog::on_addCoreBtn_clicked() { //: Title of core mod selection dialog QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Core Mods")); - for(auto filename:fileNames) + for (auto filename : fileNames) { m_coremods->stopWatching(); m_coremods->installMod(QFileInfo(filename)); @@ -199,21 +195,22 @@ void LegacyModEditDialog::on_addCoreBtn_clicked() } void LegacyModEditDialog::on_addForgeBtn_clicked() { - VersionSelectDialog vselect(MMC->forgelist().data(), this); + VersionSelectDialog vselect(MMC->forgelist().get(), this); vselect.setFilter(1, m_inst->intendedVersionId()); if (vselect.exec() && vselect.selectedVersion()) { - ForgeVersionPtr forge = vselect.selectedVersion().dynamicCast(); - if(!forge) + ForgeVersionPtr forge = + std::dynamic_pointer_cast (vselect.selectedVersion()); + if (!forge) return; auto entry = MMC->metacache()->resolveEntry("minecraftforge", forge->filename); - if(entry->stale) + if (entry->stale) { - DownloadJob * fjob = new DownloadJob("Forge download"); + DownloadJob *fjob = new DownloadJob("Forge download"); fjob->addCacheDownload(forge->universal_url, entry); ProgressDialog dlg(this); dlg.exec(fjob); - if(dlg.result() == QDialog::Accepted) + if (dlg.result() == QDialog::Accepted) { m_jarmods->stopWatching(); m_jarmods->installMod(QFileInfo(entry->getFullPath())); @@ -236,7 +233,7 @@ void LegacyModEditDialog::on_addJarBtn_clicked() { //: Title of jar mod selection dialog QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Jar Mods")); - for(auto filename:fileNames) + for (auto filename : fileNames) { m_jarmods->stopWatching(); m_jarmods->installMod(QFileInfo(filename)); @@ -247,7 +244,7 @@ void LegacyModEditDialog::on_addModBtn_clicked() { //: Title of regular mod selection dialog QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Loader Mods")); - for(auto filename:fileNames) + for (auto filename : fileNames) { m_mods->stopWatching(); m_mods->installMod(QFileInfo(filename)); @@ -258,7 +255,7 @@ void LegacyModEditDialog::on_addTexPackBtn_clicked() { //: Title of texture pack selection dialog QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Texture Packs")); - for(auto filename:fileNames) + for (auto filename : fileNames) { m_texturepacks->stopWatching(); m_texturepacks->installMod(QFileInfo(filename)); @@ -270,8 +267,8 @@ void LegacyModEditDialog::on_moveJarDownBtn_clicked() { int first, last; auto list = ui->jarModsTreeView->selectionModel()->selectedRows(); - - if(!lastfirst(list, first, last)) + + if (!lastfirst(list, first, last)) return; m_jarmods->moveModsDown(first, last); @@ -280,8 +277,8 @@ void LegacyModEditDialog::on_moveJarUpBtn_clicked() { int first, last; auto list = ui->jarModsTreeView->selectionModel()->selectedRows(); - - if(!lastfirst(list, first, last)) + + if (!lastfirst(list, first, last)) return; m_jarmods->moveModsUp(first, last); } @@ -289,8 +286,8 @@ void LegacyModEditDialog::on_rmCoreBtn_clicked() { int first, last; auto list = ui->coreModsTreeView->selectionModel()->selectedRows(); - - if(!lastfirst(list, first, last)) + + if (!lastfirst(list, first, last)) return; m_coremods->stopWatching(); m_coremods->deleteMods(first, last); @@ -300,8 +297,8 @@ void LegacyModEditDialog::on_rmJarBtn_clicked() { int first, last; auto list = ui->jarModsTreeView->selectionModel()->selectedRows(); - - if(!lastfirst(list, first, last)) + + if (!lastfirst(list, first, last)) return; m_jarmods->stopWatching(); m_jarmods->deleteMods(first, last); @@ -311,8 +308,8 @@ void LegacyModEditDialog::on_rmModBtn_clicked() { int first, last; auto list = ui->loaderModTreeView->selectionModel()->selectedRows(); - - if(!lastfirst(list, first, last)) + + if (!lastfirst(list, first, last)) return; m_mods->stopWatching(); m_mods->deleteMods(first, last); @@ -322,8 +319,8 @@ void LegacyModEditDialog::on_rmTexPackBtn_clicked() { int first, last; auto list = ui->texPackTreeView->selectionModel()->selectedRows(); - - if(!lastfirst(list, first, last)) + + if (!lastfirst(list, first, last)) return; m_texturepacks->stopWatching(); m_texturepacks->deleteMods(first, last); @@ -342,7 +339,6 @@ void LegacyModEditDialog::on_viewTexPackBtn_clicked() openDirInDefaultProgram(m_inst->texturePacksDir(), true); } - void LegacyModEditDialog::on_buttonBox_rejected() { close(); diff --git a/gui/LegacyModEditDialog.h b/gui/LegacyModEditDialog.h index b824a86a..5f6973d3 100644 --- a/gui/LegacyModEditDialog.h +++ b/gui/LegacyModEditDialog.h @@ -60,10 +60,10 @@ protected: bool texturePackListFilter( QKeyEvent* ev ); private: Ui::LegacyModEditDialog *ui; - QSharedPointer m_mods; - QSharedPointer m_coremods; - QSharedPointer m_jarmods; - QSharedPointer m_texturepacks; + std::shared_ptr m_mods; + std::shared_ptr m_coremods; + std::shared_ptr m_jarmods; + std::shared_ptr m_texturepacks; LegacyInstance * m_inst; DownloadJobPtr forgeJob; }; diff --git a/gui/OneSixModEditDialog.cpp b/gui/OneSixModEditDialog.cpp index f2e7c5d2..e8c7f9ed 100644 --- a/gui/OneSixModEditDialog.cpp +++ b/gui/OneSixModEditDialog.cpp @@ -42,7 +42,7 @@ OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent) { main_model = new EnabledItemFilter(this); main_model->setActive(true); - main_model->setSourceModel(m_version.data()); + main_model->setSourceModel(m_version.get()); ui->libraryTreeView->setModel(main_model); ui->libraryTreeView->installEventFilter(this); ui->mainClassEdit->setText(m_version->mainClass); @@ -56,7 +56,7 @@ OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent) { ensureFolderPathExists(m_inst->loaderModsDir()); m_mods = m_inst->loaderModList(); - ui->loaderModTreeView->setModel(m_mods.data()); + ui->loaderModTreeView->setModel(m_mods.get()); ui->loaderModTreeView->installEventFilter(this); m_mods->startWatching(); } @@ -64,7 +64,7 @@ OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent) { ensureFolderPathExists(m_inst->resourcePacksDir()); m_resourcepacks = m_inst->resourcePackList(); - ui->resPackTreeView->setModel(m_resourcepacks.data()); + ui->resPackTreeView->setModel(m_resourcepacks.get()); ui->resPackTreeView->installEventFilter(this); m_resourcepacks->startWatching(); } @@ -97,7 +97,7 @@ void OneSixModEditDialog::on_customizeBtn_clicked() if (m_inst->customizeVersion()) { m_version = m_inst->getFullVersion(); - main_model->setSourceModel(m_version.data()); + main_model->setSourceModel(m_version.get()); updateVersionControls(); } } @@ -113,7 +113,7 @@ void OneSixModEditDialog::on_revertBtn_clicked() if (m_inst->revertCustomVersion()) { m_version = m_inst->getFullVersion(); - main_model->setSourceModel(m_version.data()); + main_model->setSourceModel(m_version.get()); updateVersionControls(); } } @@ -121,7 +121,7 @@ void OneSixModEditDialog::on_revertBtn_clicked() void OneSixModEditDialog::on_forgeBtn_clicked() { - VersionSelectDialog vselect(MMC->forgelist().data(), this); + VersionSelectDialog vselect(MMC->forgelist().get(), this); vselect.setFilter(1, m_inst->currentVersionId()); if (vselect.exec() && vselect.selectedVersion()) { @@ -139,7 +139,7 @@ void OneSixModEditDialog::on_forgeBtn_clicked() m_inst->customizeVersion(); { m_version = m_inst->getFullVersion(); - main_model->setSourceModel(m_version.data()); + main_model->setSourceModel(m_version.get()); updateVersionControls(); } } @@ -150,10 +150,11 @@ void OneSixModEditDialog::on_forgeBtn_clicked() { m_inst->customizeVersion(); m_version = m_inst->getFullVersion(); - main_model->setSourceModel(m_version.data()); + main_model->setSourceModel(m_version.get()); updateVersionControls(); } - ForgeVersionPtr forgeVersion = vselect.selectedVersion().dynamicCast(); + ForgeVersionPtr forgeVersion = + std::dynamic_pointer_cast(vselect.selectedVersion()); if (!forgeVersion) return; auto entry = MMC->metacache()->resolveEntry("minecraftforge", forgeVersion->filename); diff --git a/gui/OneSixModEditDialog.h b/gui/OneSixModEditDialog.h index e70bd73f..5c65fea3 100644 --- a/gui/OneSixModEditDialog.h +++ b/gui/OneSixModEditDialog.h @@ -52,9 +52,9 @@ protected: bool resourcePackListFilter( QKeyEvent* ev ); private: Ui::OneSixModEditDialog *ui; - QSharedPointer m_version; - QSharedPointer m_mods; - QSharedPointer m_resourcepacks; + std::shared_ptr m_version; + std::shared_ptr m_mods; + std::shared_ptr m_resourcepacks; EnabledItemFilter * main_model; OneSixInstance * m_inst; }; diff --git a/gui/aboutdialog.ui b/gui/aboutdialog.ui index ac4952f9..bd5cc568 100644 --- a/gui/aboutdialog.ui +++ b/gui/aboutdialog.ui @@ -7,7 +7,7 @@ 0 0 450 - 400 + 429 @@ -101,7 +101,7 @@ 0 0 432 - 159 + 179 @@ -159,8 +159,8 @@ 0 0 - 98 - 93 + 682 + 584 @@ -176,10 +176,10 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:11pt;">Andrew Okin &lt;</span><a href="mailto:forkk@forkk.net"><span style=" font-family:'Ubuntu'; font-size:11pt; text-decoration: underline; color:#0000ff;">forkk@forkk.net</span></a><span style=" font-family:'Ubuntu'; font-size:11pt;">&gt;</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:11pt;">Petr Mrázek &lt;</span><a href="mailto:peterix@gmail.com"><span style=" font-family:'Ubuntu'; font-size:11pt; text-decoration: underline; color:#0000ff;">peterix@gmail.com</span></a><span style=" font-family:'Ubuntu'; font-size:11pt;">&gt;</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:11pt;">Orochimarufan &lt;</span><a href="mailto:orochimarufan.x3@gmail.com"><span style=" font-family:'Ubuntu'; font-size:11pt; text-decoration: underline; color:#0000ff;">orochimarufan.x3@gmail.com</span></a><span style=" font-family:'Ubuntu'; font-size:11pt;">&gt;</span></p></body></html> +</style></head><body style=" font-family:'Bitstream Vera Sans'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">Andrew Okin &lt;</span><a href="mailto:forkk@forkk.net"><span style=" font-family:'Ubuntu'; text-decoration: underline; color:#0000ff;">forkk@forkk.net</span></a><span style=" font-family:'Ubuntu';">&gt;</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">Petr Mrázek &lt;</span><a href="mailto:peterix@gmail.com"><span style=" font-family:'Ubuntu'; text-decoration: underline; color:#0000ff;">peterix@gmail.com</span></a><span style=" font-family:'Ubuntu';">&gt;</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">Orochimarufan &lt;</span><a href="mailto:orochimarufan.x3@gmail.com"><span style=" font-family:'Ubuntu'; text-decoration: underline; color:#0000ff;">orochimarufan.x3@gmail.com</span></a><span style=" font-family:'Ubuntu';">&gt;</span></p></body></html> @@ -190,8 +190,8 @@ p, li { white-space: pre-wrap; } 0 0 - 98 - 93 + 682 + 584 @@ -213,44 +213,45 @@ p, li { white-space: pre-wrap; } <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">Copyright 2012 MultiMC Contributors</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">you may not use this file except in compliance with the License.</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">You may obtain a copy of the License at</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu';"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';"> http://www.apache.org/licenses/LICENSE-2.0</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu';"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">Unless required by applicable law or agreed to in writing, software</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">See the License for the specific language governing permissions and</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">limitations under the License.</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu';"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">MultiMC uses bspatch, </span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">Copyright 2003-2005 Colin Percival</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">All rights reserved</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu';"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">Redistribution and use in source and binary forms, with or without</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">modification, are permitted providing that the following conditions</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">are met: </span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">1. Redistributions of source code must retain the above copyright</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';"> notice, this list of conditions and the following disclaimer.</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">2. Redistributions in binary form must reproduce the above copyright</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';"> notice, this list of conditions and the following disclaimer in the</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';"> documentation and/or other materials provided with the distribution.</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu';"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu';">POSSIBILITY OF SUCH DAMAGE.</span></p></body></html> +</style></head><body style=" font-family:'Bitstream Vera Sans'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">Copyright 2012 MultiMC Contributors</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">you may not use this file except in compliance with the License.</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">You may obtain a copy of the License at</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;"> http://www.apache.org/licenses/LICENSE-2.0</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">Unless required by applicable law or agreed to in writing, software</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">See the License for the specific language governing permissions and</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">limitations under the License.</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">MultiMC uses QSLog, </span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">Copyright (c) 2010, Razvan Petru</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">All rights reserved.</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">Redistribution and use in source and binary forms, with or without modification,</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">are permitted provided that the following conditions are met:</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">* Redistributions of source code must retain the above copyright notice, this</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;"> list of conditions and the following disclaimer.</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">* Redistributions in binary form must reproduce the above copyright notice, this</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;"> list of conditions and the following disclaimer in the documentation and/or other</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;"> materials provided with the distribution.</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">* The name of the contributors may not be used to endorse or promote products</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;"> derived from this software without specific prior written permission.</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:10pt;">OF THE POSSIBILITY OF SUCH DAMAGE.</span></p></body></html> diff --git a/gui/logindialog.cpp b/gui/logindialog.cpp index 37e30c85..fdc94ac7 100644 --- a/gui/logindialog.cpp +++ b/gui/logindialog.cpp @@ -16,7 +16,7 @@ #include "logindialog.h" #include "ui_logindialog.h" #include "keyring.h" -#include +#include LoginDialog::LoginDialog(QWidget *parent, const QString& loginErrMsg) : QDialog(parent), @@ -109,7 +109,7 @@ void LoginDialog::passwordToggled ( bool state ) blockToggles = true; if(!state) { - qDebug() << "password disabled"; + QLOG_DEBUG() << "password disabled"; } else { @@ -117,7 +117,7 @@ void LoginDialog::passwordToggled ( bool state ) { ui->rememberUsernameCheckbox->setChecked(true); } - qDebug() << "password enabled"; + QLOG_DEBUG() << "password enabled"; } blockToggles = false; } @@ -134,11 +134,11 @@ void LoginDialog::usernameToggled ( bool state ) { ui->rememberPasswordCheckbox->setChecked(false); } - qDebug() << "username disabled"; + QLOG_DEBUG() << "username disabled"; } else { - qDebug() << "username enabled"; + QLOG_DEBUG() << "username enabled"; } blockToggles = false; } diff --git a/gui/lwjglselectdialog.cpp b/gui/lwjglselectdialog.cpp index e48bb975..4518e8cd 100644 --- a/gui/lwjglselectdialog.cpp +++ b/gui/lwjglselectdialog.cpp @@ -26,10 +26,10 @@ LWJGLSelectDialog::LWJGLSelectDialog(QWidget *parent) : ui->setupUi(this); ui->labelStatus->setVisible(false); auto lwjgllist = MMC->lwjgllist(); - ui->lwjglListView->setModel(lwjgllist.data()); + ui->lwjglListView->setModel(lwjgllist.get()); - connect(lwjgllist.data(), SIGNAL(loadingStateUpdated(bool)), SLOT(loadingStateUpdated(bool))); - connect(lwjgllist.data(), SIGNAL(loadListFailed(QString)), SLOT(loadingFailed(QString))); + connect(lwjgllist.get(), SIGNAL(loadingStateUpdated(bool)), SLOT(loadingStateUpdated(bool))); + connect(lwjgllist.get(), SIGNAL(loadListFailed(QString)), SLOT(loadingFailed(QString))); loadingStateUpdated(lwjgllist->isLoading()); } diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index d7b77c8b..ecf5f79d 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -68,20 +68,19 @@ #include "LabeledToolButton.h" #include "EditNotesDialog.h" -MainWindow::MainWindow ( QWidget *parent ) - :QMainWindow ( parent ), ui ( new Ui::MainWindow ) +MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { - ui->setupUi ( this ); - setWindowTitle ( QString ( "MultiMC %1" ).arg ( MMC->version().toString() ) ); - + ui->setupUi(this); + setWindowTitle(QString("MultiMC %1").arg(MMC->version().toString())); + // Set the selected instance to null m_selectedInstance = nullptr; // Set active instance to null. m_activeInst = nullptr; - + // OSX magic. setUnifiedTitleAndToolBarOnMac(true); - + // The instance action toolbar customizations { ui->instanceToolBar->setEnabled(false); @@ -92,44 +91,45 @@ MainWindow::MainWindow ( QWidget *parent ) connect(renameButton, SIGNAL(clicked(bool)), SLOT(on_actionRenameInstance_triggered())); ui->instanceToolBar->insertWidget(ui->actionLaunchInstance, renameButton); ui->instanceToolBar->insertSeparator(ui->actionLaunchInstance); - renameButton->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); + renameButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); } - + // Create the instance list widget { - view = new KCategorizedView ( ui->centralWidget ); - drawer = new KCategoryDrawer ( view ); - - view->setSelectionMode ( QAbstractItemView::SingleSelection ); - view->setCategoryDrawer ( drawer ); - view->setCollapsibleBlocks ( true ); - view->setViewMode ( QListView::IconMode ); - view->setFlow ( QListView::LeftToRight ); + view = new KCategorizedView(ui->centralWidget); + drawer = new KCategoryDrawer(view); + + view->setSelectionMode(QAbstractItemView::SingleSelection); + view->setCategoryDrawer(drawer); + view->setCollapsibleBlocks(true); + view->setViewMode(QListView::IconMode); + view->setFlow(QListView::LeftToRight); view->setWordWrap(true); - view->setMouseTracking ( true ); - view->viewport()->setAttribute ( Qt::WA_Hover ); + view->setMouseTracking(true); + view->viewport()->setAttribute(Qt::WA_Hover); auto delegate = new ListViewDelegate(); view->setItemDelegate(delegate); view->setSpacing(10); view->setUniformItemWidths(true); - + // do not show ugly blue border on the mac view->setAttribute(Qt::WA_MacShowFocusRect, false); - + view->installEventFilter(this); - proxymodel = new InstanceProxyModel ( this ); - proxymodel->setSortRole ( KCategorizedSortFilterProxyModel::CategorySortRole ); - proxymodel->setFilterRole ( KCategorizedSortFilterProxyModel::CategorySortRole ); - //proxymodel->setDynamicSortFilter ( true ); - - // FIXME: instList should be global-ish, or at least not tied to the main window... maybe the application itself? - proxymodel->setSourceModel ( MMC->instances().data() ); - proxymodel->sort ( 0 ); - view->setFrameShape ( QFrame::NoFrame ); - view->setModel ( proxymodel ); - - ui->horizontalLayout->addWidget ( view ); + proxymodel = new InstanceProxyModel(this); + proxymodel->setSortRole(KCategorizedSortFilterProxyModel::CategorySortRole); + proxymodel->setFilterRole(KCategorizedSortFilterProxyModel::CategorySortRole); + // proxymodel->setDynamicSortFilter ( true ); + + // FIXME: instList should be global-ish, or at least not tied to the main window... + // maybe the application itself? + proxymodel->setSourceModel(MMC->instances().get()); + proxymodel->sort(0); + view->setFrameShape(QFrame::NoFrame); + view->setModel(proxymodel); + + ui->horizontalLayout->addWidget(view); } // The cat background { @@ -139,18 +139,16 @@ MainWindow::MainWindow ( QWidget *parent ) setCatBackground(cat_enable); } // start instance when double-clicked - connect(view, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(instanceActivated(const QModelIndex &))); + connect(view, SIGNAL(doubleClicked(const QModelIndex &)), this, + SLOT(instanceActivated(const QModelIndex &))); // track the selection -- update the instance toolbar - connect( - view->selectionModel(), - SIGNAL(currentChanged(const QModelIndex &,const QModelIndex &)), - this, - SLOT(instanceChanged(const QModelIndex &,const QModelIndex &)) - ); + connect(view->selectionModel(), + SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, + SLOT(instanceChanged(const QModelIndex &, const QModelIndex &))); // model reset -> selection is invalid. All the instance pointers are wrong. // FIXME: stop using POINTERS everywhere - connect(MMC->instances().data() ,SIGNAL(dataIsInvalid()),SLOT(selectionBad())); - + connect(MMC->instances().get(), SIGNAL(dataIsInvalid()), SLOT(selectionBad())); + // run the things that load and download other things... FIXME: this is NOT the place // FIXME: invisible actions in the background = NOPE. { @@ -176,57 +174,55 @@ MainWindow::~MainWindow() delete assets_downloader; } -bool MainWindow::eventFilter ( QObject* obj, QEvent* ev ) +bool MainWindow::eventFilter(QObject *obj, QEvent *ev) { - if(obj == view) + if (obj == view) { if (ev->type() == QEvent::KeyPress) { - QKeyEvent *keyEvent = static_cast(ev); - switch(keyEvent->key()) + QKeyEvent *keyEvent = static_cast(ev); + switch (keyEvent->key()) { - case Qt::Key_Enter: - case Qt::Key_Return: - on_actionLaunchInstance_triggered(); - return true; - case Qt::Key_Delete: - on_actionDeleteInstance_triggered(); - return true; - case Qt::Key_F5: - on_actionRefresh_triggered(); - return true; - case Qt::Key_F2: - on_actionRenameInstance_triggered(); - return true; - default: - break; + case Qt::Key_Enter: + case Qt::Key_Return: + on_actionLaunchInstance_triggered(); + return true; + case Qt::Key_Delete: + on_actionDeleteInstance_triggered(); + return true; + case Qt::Key_F5: + on_actionRefresh_triggered(); + return true; + case Qt::Key_F2: + on_actionRenameInstance_triggered(); + return true; + default: + break; } } } - return QMainWindow::eventFilter ( obj, ev ); + return QMainWindow::eventFilter(obj, ev); } -void MainWindow::onCatToggled ( bool state ) +void MainWindow::onCatToggled(bool state) { setCatBackground(state); MMC->settings()->set("TheCat", state); } -void MainWindow::setCatBackground ( bool enabled ) +void MainWindow::setCatBackground(bool enabled) { - if(enabled) + if (enabled) { - view->setStyleSheet( - "QListView" - "{" - "background-image: url(:/backgrounds/kitteh);" - "background-attachment: fixed;" - "background-clip: padding;" - "background-position: top right;" - "background-repeat: none;" - "background-color:palette(base);" - "}" - ); + view->setStyleSheet("QListView" + "{" + "background-image: url(:/backgrounds/kitteh);" + "background-attachment: fixed;" + "background-clip: padding;" + "background-position: top right;" + "background-repeat: none;" + "background-color:palette(base);" + "}"); } else { @@ -234,37 +230,37 @@ void MainWindow::setCatBackground ( bool enabled ) } } - -void MainWindow::instanceActivated ( QModelIndex index ) +void MainWindow::instanceActivated(QModelIndex index) { - if(!index.isValid()) + if (!index.isValid()) return; - BaseInstance * inst = (BaseInstance *) index.data(InstanceList::InstancePointerRole).value(); + BaseInstance *inst = + (BaseInstance *)index.data(InstanceList::InstancePointerRole).value(); doLogin(); } void MainWindow::on_actionAddInstance_triggered() { - if (!MMC->minecraftlist()->isLoaded() && - m_versionLoadTask && m_versionLoadTask->isRunning()) + if (!MMC->minecraftlist()->isLoaded() && m_versionLoadTask && + m_versionLoadTask->isRunning()) { QEventLoop waitLoop; waitLoop.connect(m_versionLoadTask, SIGNAL(failed(QString)), SLOT(quit())); waitLoop.connect(m_versionLoadTask, SIGNAL(succeeded()), SLOT(quit())); waitLoop.exec(); } - - NewInstanceDialog newInstDlg( this ); + + NewInstanceDialog newInstDlg(this); if (!newInstDlg.exec()) return; - + BaseInstance *newInstance = NULL; - + QString instDirName = DirNameFromString(newInstDlg.instName()); QString instDir = PathCombine(MMC->settings()->get("InstanceDir").toString(), instDirName); - + auto &loader = InstanceFactory::get(); - + auto error = loader.createInstance(newInstance, newInstDlg.selectedVersion(), instDir); QString errorMsg = QString("Failed to create instance %1: ").arg(instDirName); switch (error) @@ -274,17 +270,17 @@ void MainWindow::on_actionAddInstance_triggered() newInstance->setIconKey(newInstDlg.iconKey()); MMC->instances()->add(InstancePtr(newInstance)); return; - + case InstanceFactory::InstExists: errorMsg += "An instance with the given directory name already exists."; QMessageBox::warning(this, "Error", errorMsg); break; - + case InstanceFactory::CantCreateDir: errorMsg += "Failed to create the instance directory."; QMessageBox::warning(this, "Error", errorMsg); break; - + default: errorMsg += QString("Unknown instance loader error %1").arg(error); QMessageBox::warning(this, "Error", errorMsg); @@ -294,12 +290,12 @@ void MainWindow::on_actionAddInstance_triggered() void MainWindow::on_actionChangeInstIcon_triggered() { - if(!m_selectedInstance) + if (!m_selectedInstance) return; - + IconPickerDialog dlg(this); dlg.exec(m_selectedInstance->iconKey()); - if(dlg.result() == QDialog::Accepted) + if (dlg.result() == QDialog::Accepted) { m_selectedInstance->setIconKey(dlg.selectedIconKey); auto ico = MMC->icons()->getIcon(dlg.selectedIconKey); @@ -307,25 +303,23 @@ void MainWindow::on_actionChangeInstIcon_triggered() } } - void MainWindow::on_actionChangeInstGroup_triggered() { - if(!m_selectedInstance) + if (!m_selectedInstance) return; - + bool ok = false; - QString name ( m_selectedInstance->group() ); - name = QInputDialog::getText ( this, tr ( "Group name" ), tr ( "Enter a new group name." ), - QLineEdit::Normal, name, &ok ); - if(ok) + QString name(m_selectedInstance->group()); + name = QInputDialog::getText(this, tr("Group name"), tr("Enter a new group name."), + QLineEdit::Normal, name, &ok); + if (ok) m_selectedInstance->setGroupPost(name); } - void MainWindow::on_actionViewInstanceFolder_triggered() { - QString str = MMC->settings()->get ( "InstanceDir" ).toString(); - openDirInDefaultProgram ( str ); + QString str = MMC->settings()->get("InstanceDir").toString(); + openDirInDefaultProgram(str); } void MainWindow::on_actionRefresh_triggered() @@ -335,59 +329,58 @@ void MainWindow::on_actionRefresh_triggered() void MainWindow::on_actionViewCentralModsFolder_triggered() { - openDirInDefaultProgram ( MMC->settings()->get ( "CentralModsDir" ).toString() , true); + openDirInDefaultProgram(MMC->settings()->get("CentralModsDir").toString(), true); } void MainWindow::on_actionConfig_Folder_triggered() { - if(m_selectedInstance) + if (m_selectedInstance) { QString str = m_selectedInstance->instanceConfigFolder(); - openDirInDefaultProgram ( QDir(str).absolutePath() ); + openDirInDefaultProgram(QDir(str).absolutePath()); } } - void MainWindow::on_actionCheckUpdate_triggered() { - } void MainWindow::on_actionSettings_triggered() { - SettingsDialog dialog ( this ); + SettingsDialog dialog(this); dialog.exec(); } void MainWindow::on_actionReportBug_triggered() { - openWebPage ( QUrl ( "http://multimc.myjetbrains.com/youtrack/dashboard#newissue=yes" ) ); + openWebPage(QUrl("http://multimc.myjetbrains.com/youtrack/dashboard#newissue=yes")); } void MainWindow::on_actionNews_triggered() { - openWebPage ( QUrl ( "http://forkk.net/tag/multimc.html" ) ); + openWebPage(QUrl("http://forkk.net/tag/multimc.html")); } void MainWindow::on_actionAbout_triggered() { - AboutDialog dialog ( this ); + AboutDialog dialog(this); dialog.exec(); } -void MainWindow::on_mainToolBar_visibilityChanged ( bool ) +void MainWindow::on_mainToolBar_visibilityChanged(bool) { // Don't allow hiding the main toolbar. // This is the only way I could find to prevent it... :/ - ui->mainToolBar->setVisible ( true ); + ui->mainToolBar->setVisible(true); } void MainWindow::on_actionDeleteInstance_triggered() { if (m_selectedInstance) { - int response = QMessageBox::question(this, "CAREFUL", - QString("This is permanent! Are you sure?\nAbout to delete: ") + m_selectedInstance->name()); + int response = QMessageBox::question( + this, "CAREFUL", QString("This is permanent! Are you sure?\nAbout to delete: ") + + m_selectedInstance->name()); if (response == QMessageBox::Yes) { m_selectedInstance->nuke(); @@ -397,31 +390,31 @@ void MainWindow::on_actionDeleteInstance_triggered() void MainWindow::on_actionRenameInstance_triggered() { - if(m_selectedInstance) + if (m_selectedInstance) { bool ok = false; - QString name ( m_selectedInstance->name() ); - name = QInputDialog::getText ( this, tr ( "Instance name" ), tr ( "Enter a new instance name." ), - QLineEdit::Normal, name, &ok ); - + QString name(m_selectedInstance->name()); + name = + QInputDialog::getText(this, tr("Instance name"), tr("Enter a new instance name."), + QLineEdit::Normal, name, &ok); + if (name.length() > 0) { - if(ok && name.length()) + if (ok && name.length()) { m_selectedInstance->setName(name); renameButton->setText(name); } } - } } void MainWindow::on_actionViewSelectedInstFolder_triggered() { - if(m_selectedInstance) + if (m_selectedInstance) { QString str = m_selectedInstance->instanceRoot(); - openDirInDefaultProgram ( QDir(str).absolutePath() ); + openDirInDefaultProgram(QDir(str).absolutePath()); } } @@ -430,59 +423,61 @@ void MainWindow::on_actionEditInstMods_triggered() if (m_selectedInstance) { auto dialog = m_selectedInstance->createModEditDialog(this); - if(dialog) + if (dialog) dialog->exec(); dialog->deleteLater(); } } -void MainWindow::closeEvent ( QCloseEvent *event ) +void MainWindow::closeEvent(QCloseEvent *event) { // Save the window state and geometry. // TODO: Make this work with the new settings system. -// settings->getConfig().setValue("MainWindowGeometry", saveGeometry()); -// settings->getConfig().setValue("MainWindowState", saveState()); - QMainWindow::closeEvent ( event ); + // settings->getConfig().setValue("MainWindowGeometry", saveGeometry()); + // settings->getConfig().setValue("MainWindowState", saveState()); + QMainWindow::closeEvent(event); } -void MainWindow::on_instanceView_customContextMenuRequested ( const QPoint &pos ) +void MainWindow::on_instanceView_customContextMenuRequested(const QPoint &pos) { - QMenu *instContextMenu = new QMenu ( "Instance", this ); + QMenu *instContextMenu = new QMenu("Instance", this); // Add the actions from the toolbar to the context menu. - instContextMenu->addActions ( ui->instanceToolBar->actions() ); + instContextMenu->addActions(ui->instanceToolBar->actions()); - instContextMenu->exec ( view->mapToGlobal ( pos ) ); + instContextMenu->exec(view->mapToGlobal(pos)); } void MainWindow::on_actionLaunchInstance_triggered() { - if(m_selectedInstance) + if (m_selectedInstance) { doLogin(); } } -void MainWindow::doLogin(const QString& errorMsg) +void MainWindow::doLogin(const QString &errorMsg) { if (!m_selectedInstance) return; - - LoginDialog* loginDlg = new LoginDialog(this, errorMsg); + + LoginDialog *loginDlg = new LoginDialog(this, errorMsg); if (!m_selectedInstance->lastLaunch()) loginDlg->forceOnline(); - + loginDlg->exec(); - if(loginDlg->result() == QDialog::Accepted) + if (loginDlg->result() == QDialog::Accepted) { - if (loginDlg->isOnline()) + if (loginDlg->isOnline()) { UserInfo uInfo{loginDlg->getUsername(), loginDlg->getPassword()}; - ProgressDialog* tDialog = new ProgressDialog(this); - LoginTask* loginTask = new LoginTask(uInfo, tDialog); - connect(loginTask, SIGNAL(succeeded()),SLOT(onLoginComplete()), Qt::QueuedConnection); - connect(loginTask, SIGNAL(failed(QString)), SLOT(doLogin(QString)), Qt::QueuedConnection); + ProgressDialog *tDialog = new ProgressDialog(this); + LoginTask *loginTask = new LoginTask(uInfo, tDialog); + connect(loginTask, SIGNAL(succeeded()), SLOT(onLoginComplete()), + Qt::QueuedConnection); + connect(loginTask, SIGNAL(failed(QString)), SLOT(doLogin(QString)), + Qt::QueuedConnection); m_activeInst = m_selectedInstance; tDialog->exec(loginTask); } @@ -490,7 +485,7 @@ void MainWindow::doLogin(const QString& errorMsg) { QString user = loginDlg->getUsername(); if (user.length() == 0) - user = QString("Offline"); + user = QString("Offline"); m_activeLogin = {user, QString("Offline"), QString(), QString()}; m_activeInst = m_selectedInstance; launchInstance(m_activeInst, m_activeLogin); @@ -500,20 +495,20 @@ void MainWindow::doLogin(const QString& errorMsg) void MainWindow::onLoginComplete() { - if(!m_activeInst) + if (!m_activeInst) return; - LoginTask * task = (LoginTask *) QObject::sender(); + LoginTask *task = (LoginTask *)QObject::sender(); m_activeLogin = task->getResult(); - + BaseUpdate *updateTask = m_activeInst->doUpdate(); - if(!updateTask) + if (!updateTask) { launchInstance(m_activeInst, m_activeLogin); } else { ProgressDialog *tDialog = new ProgressDialog(this); - connect(updateTask, SIGNAL(succeeded()),SLOT(onGameUpdateComplete())); + connect(updateTask, SIGNAL(succeeded()), SLOT(onGameUpdateComplete())); connect(updateTask, SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString))); tDialog->exec(updateTask); } @@ -532,11 +527,11 @@ void MainWindow::onGameUpdateError(QString error) void MainWindow::launchInstance(BaseInstance *instance, LoginResponse response) { Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL"); - + proc = instance->prepareForLaunch(response); - if(!proc) + if (!proc) return; - + // Prepare GUI: If it shall stay open disable the required parts if (MMC->settings()->get("NoHide").toBool()) { @@ -546,11 +541,11 @@ void MainWindow::launchInstance(BaseInstance *instance, LoginResponse response) { this->hide(); } - + console = new ConsoleWindow(proc); console->show(); - connect(proc, SIGNAL(log(QString, MessageLevel::Enum)), - console, SLOT(write(QString, MessageLevel::Enum))); + connect(proc, SIGNAL(log(QString, MessageLevel::Enum)), console, + SLOT(write(QString, MessageLevel::Enum))); connect(proc, SIGNAL(ended()), this, SLOT(instanceEnded())); proc->setLogin(response.username, response.session_id); proc->launch(); @@ -566,7 +561,7 @@ void MainWindow::taskEnd() QObject *sender = QObject::sender(); if (sender == m_versionLoadTask) m_versionLoadTask = NULL; - + sender->deleteLater(); } @@ -578,20 +573,24 @@ void MainWindow::startTask(Task *task) task->start(); } - // Create A Desktop Shortcut void MainWindow::on_actionMakeDesktopShortcut_triggered() { - QString name ( "Test" ); - name = QInputDialog::getText ( this, tr ( "MultiMC Shortcut" ), tr ( "Enter a Shortcut Name." ), QLineEdit::Normal, name ); + QString name("Test"); + name = QInputDialog::getText(this, tr("MultiMC Shortcut"), tr("Enter a Shortcut Name."), + QLineEdit::Normal, name); - Util::createShortCut ( Util::getDesktopDir(), QApplication::instance()->applicationFilePath(), QStringList() << "-dl" << QDir::currentPath() << "test", name, "application-x-octet-stream" ); + Util::createShortCut(Util::getDesktopDir(), QApplication::instance()->applicationFilePath(), + QStringList() << "-dl" << QDir::currentPath() << "test", name, + "application-x-octet-stream"); - QMessageBox::warning ( this, tr("Not useful"), tr("A Dummy Shortcut was created. it will not do anything productive") ); + QMessageBox::warning( + this, tr("Not useful"), + tr("A Dummy Shortcut was created. it will not do anything productive")); } // BrowserDialog -void MainWindow::openWebPage ( QUrl url ) +void MainWindow::openWebPage(QUrl url) { QDesktopServices::openUrl(url); } @@ -600,8 +599,8 @@ void MainWindow::on_actionChangeInstMCVersion_triggered() { if (view->selectionModel()->selectedIndexes().count() < 1) return; - - VersionSelectDialog vselect(m_selectedInstance->versionList().data(), this); + + VersionSelectDialog vselect(m_selectedInstance->versionList().get(), this); if (vselect.exec() && vselect.selectedVersion()) { m_selectedInstance->setIntendedVersionId(vselect.selectedVersion()->descriptor()); @@ -612,12 +611,12 @@ void MainWindow::on_actionChangeInstLWJGLVersion_triggered() { if (!m_selectedInstance) return; - + LWJGLSelectDialog lselect(this); lselect.exec(); if (lselect.result() == QDialog::Accepted) { - LegacyInstance * linst = (LegacyInstance *) m_selectedInstance; + LegacyInstance *linst = (LegacyInstance *)m_selectedInstance; linst->setLWJGLVersion(lselect.selectedVersion()); } } @@ -632,18 +631,23 @@ void MainWindow::on_actionInstanceSettings_triggered() settings.exec(); } -void MainWindow::instanceChanged( const QModelIndex& current, const QModelIndex& previous ) +void MainWindow::instanceChanged(const QModelIndex ¤t, const QModelIndex &previous) { - if(current.isValid() && nullptr != (m_selectedInstance = (BaseInstance *) current.data(InstanceList::InstancePointerRole).value())) + if (current.isValid() && + nullptr != (m_selectedInstance = + (BaseInstance *)current.data(InstanceList::InstancePointerRole) + .value())) { ui->instanceToolBar->setEnabled(true); QString iconKey = m_selectedInstance->iconKey(); renameButton->setText(m_selectedInstance->name()); - ui->actionChangeInstLWJGLVersion->setEnabled(m_selectedInstance->menuActionEnabled("actionChangeInstLWJGLVersion")); - ui->actionEditInstMods->setEnabled(m_selectedInstance->menuActionEnabled("actionEditInstMods")); + ui->actionChangeInstLWJGLVersion->setEnabled( + m_selectedInstance->menuActionEnabled("actionChangeInstLWJGLVersion")); + ui->actionEditInstMods->setEnabled( + m_selectedInstance->menuActionEnabled("actionEditInstMods")); statusBar()->clearMessage(); statusBar()->showMessage(m_selectedInstance->getStatusbarDescription()); - auto ico =MMC->icons()->getIcon(iconKey); + auto ico = MMC->icons()->getIcon(iconKey); ui->actionChangeInstIcon->setIcon(ico); } else @@ -663,19 +667,17 @@ void MainWindow::selectionBad() ui->actionChangeInstIcon->setIcon(ico); } - - void MainWindow::on_actionEditInstNotes_triggered() { if (!m_selectedInstance) return; - LegacyInstance * linst = (LegacyInstance *) m_selectedInstance; - + LegacyInstance *linst = (LegacyInstance *)m_selectedInstance; + EditNotesDialog noteedit(linst->notes(), linst->name(), this); noteedit.exec(); if (noteedit.result() == QDialog::Accepted) { - + linst->setNotes(noteedit.getText()); } } diff --git a/gui/newinstancedialog.cpp b/gui/newinstancedialog.cpp index 859077d9..c035302c 100644 --- a/gui/newinstancedialog.cpp +++ b/gui/newinstancedialog.cpp @@ -96,7 +96,7 @@ BaseVersionPtr NewInstanceDialog::selectedVersion() const void NewInstanceDialog::on_btnChangeVersion_clicked() { - VersionSelectDialog vselect(MMC->minecraftlist().data(), this); + VersionSelectDialog vselect(MMC->minecraftlist().get(), this); vselect.exec(); if (vselect.result() == QDialog::Accepted) { diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index 9736c1c7..31fe2d96 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -27,7 +27,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) : { ui->setupUi(this); - loadSettings(MMC->settings().data()); + loadSettings(MMC->settings().get()); updateCheckboxStuff(); } @@ -85,7 +85,7 @@ void SettingsDialog::on_maximizedCheckBox_clicked(bool checked) void SettingsDialog::on_buttonBox_accepted() { - applySettings(MMC->settings().data()); + applySettings(MMC->settings().get()); } void SettingsDialog::applySettings(SettingsObject *s) diff --git a/gui/versionselectdialog.cpp b/gui/versionselectdialog.cpp index 1e60c7d9..ff990188 100644 --- a/gui/versionselectdialog.cpp +++ b/gui/versionselectdialog.cpp @@ -91,6 +91,6 @@ void VersionSelectDialog::setFilter(int column, QString filter) if (filteredTypes.length() > 0) regexStr = QString("^((?!%1).)*$").arg(filteredTypes.join('|')); - qDebug() << "Filter:" << regexStr; + QLOG_DEBUG() << "Filter:" << regexStr; */ } diff --git a/logger/QsDebugOutput.cpp b/logger/QsDebugOutput.cpp new file mode 100644 index 00000000..d68cd5e9 --- /dev/null +++ b/logger/QsDebugOutput.cpp @@ -0,0 +1,52 @@ +// Copyright (c) 2010, Razvan Petru +// All rights reserved. + +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: + +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, this +// list of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// * The name of the contributors may not be used to endorse or promote products +// derived from this software without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "QsDebugOutput.h" +#include +#include + +#if defined(Q_OS_WIN) +#define WIN32_LEAN_AND_MEAN +#include +void QsDebugOutput::output(const QString &message) +{ + OutputDebugStringW(reinterpret_cast(message.utf16())); + OutputDebugStringW(L"\n"); +} +#elif defined(Q_OS_SYMBIAN) +#include +void QsDebugOutput::output(const QString &message) +{ + TPtrC8 symbianMessage(reinterpret_cast(qPrintable(message))); + RDebug::RawPrint(symbianMessage); +} +#elif defined(Q_OS_UNIX) +#include +void QsDebugOutput::output(const QString &message) +{ + fprintf(stderr, "%s\n", qPrintable(message)); + fflush(stderr); +} +#endif diff --git a/logger/QsDebugOutput.h b/logger/QsDebugOutput.h new file mode 100644 index 00000000..8c759a6d --- /dev/null +++ b/logger/QsDebugOutput.h @@ -0,0 +1,34 @@ +// Copyright (c) 2010, Razvan Petru +// All rights reserved. + +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: + +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, this +// list of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// * The name of the contributors may not be used to endorse or promote products +// derived from this software without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. + +#pragma once + +class QString; + +class QsDebugOutput +{ +public: + static void output(const QString &a_message); +}; diff --git a/logger/QsLog.cpp b/logger/QsLog.cpp new file mode 100644 index 00000000..b2a7f465 --- /dev/null +++ b/logger/QsLog.cpp @@ -0,0 +1,141 @@ +// Copyright (c) 2010, Razvan Petru +// All rights reserved. + +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: + +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, this +// list of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// * The name of the contributors may not be used to endorse or promote products +// derived from this software without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "QsLog.h" +#include "QsLogDest.h" +#include +#include +#include +#include +#include +#include +#include + +namespace QsLogging +{ +typedef QList DestinationList; + +static const char *LevelStrings[] = {"TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL" + "UNKNOWN"}; + +// not using Qt::ISODate because we need the milliseconds too +static const QString fmtDateTime("hhhh:mm:ss.zzz"); + +static const char *LevelToText(Level theLevel) +{ + if (theLevel > FatalLevel) + { + assert(!"bad log level"); + return LevelStrings[UnknownLevel]; + } + return LevelStrings[theLevel]; +} + +class LoggerImpl +{ +public: + LoggerImpl() : level(InfoLevel), start_time(QDateTime::currentDateTime()) + { + } + QMutex logMutex; + Level level; + DestinationList destList; + QDateTime start_time; +}; + +Logger::Logger() : d(new LoggerImpl) +{ +} + +Logger::~Logger() +{ + delete d; +} + +void Logger::addDestination(Destination *destination) +{ + assert(destination); + d->destList.push_back(destination); +} + +void Logger::setLoggingLevel(Level newLevel) +{ + d->level = newLevel; +} + +Level Logger::loggingLevel() const +{ + return d->level; +} + +//! creates the complete log message and passes it to the logger +void Logger::Helper::writeToLog() +{ + const char *const levelName = LevelToText(level); + const QString completeMessage(QString("%1\t%2\t%3") + .arg(QDateTime::currentDateTime().toString(fmtDateTime)) + .arg(levelName, 5) + .arg(buffer)); + + Logger &logger = Logger::instance(); + QMutexLocker lock(&logger.d->logMutex); + logger.write(completeMessage); +} + +Logger::Helper::Helper(Level logLevel) : level(logLevel), qtDebug(&buffer) +{ +} + +Logger::Helper::~Helper() +{ + try + { + writeToLog(); + } + catch (std::exception &e) + { + // you shouldn't throw exceptions from a sink + Q_UNUSED(e); + assert(!"exception in logger helper destructor"); + throw; + } +} + +//! sends the message to all the destinations +void Logger::write(const QString &message) +{ + for (DestinationList::iterator it = d->destList.begin(), endIt = d->destList.end(); + it != endIt; ++it) + { + if (!(*it)) + { + assert(!"null log destination"); + continue; + } + (*it)->write(message); + } +} + +} // end namespace diff --git a/logger/QsLog.h b/logger/QsLog.h new file mode 100644 index 00000000..a18c08de --- /dev/null +++ b/logger/QsLog.h @@ -0,0 +1,130 @@ +// Copyright (c) 2010, Razvan Petru +// All rights reserved. + +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: + +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, this +// list of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// * The name of the contributors may not be used to endorse or promote products +// derived from this software without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. + +#pragma once + +#include +#include + +namespace QsLogging +{ +class Destination; +enum Level +{ + TraceLevel = 0, + DebugLevel, + InfoLevel, + WarnLevel, + ErrorLevel, + FatalLevel, + UnknownLevel +}; + +class LoggerImpl; // d pointer +class Logger +{ +public: + static Logger &instance() + { + static Logger staticLog; + return staticLog; + } + + //! Adds a log message destination. Don't add null destinations. + void addDestination(Destination *destination); + //! Logging at a level < 'newLevel' will be ignored + void setLoggingLevel(Level newLevel); + //! The default level is INFO + Level loggingLevel() const; + + //! The helper forwards the streaming to QDebug and builds the final + //! log message. + class Helper + { + public: + explicit Helper(Level logLevel); + ~Helper(); + QDebug &stream() + { + return qtDebug; + } + + private: + void writeToLog(); + + Level level; + QString buffer; + QDebug qtDebug; + }; + +private: + Logger(); + Logger(const Logger &); + Logger &operator=(const Logger &); + ~Logger(); + + void write(const QString &message); + + LoggerImpl *d; +}; + +} // end namespace + +#define QLOG_TRACE() \ + if (QsLogging::Logger::instance().loggingLevel() <= QsLogging::TraceLevel) \ + QsLogging::Logger::Helper(QsLogging::TraceLevel).stream() +#define QLOG_DEBUG() \ + if (QsLogging::Logger::instance().loggingLevel() <= QsLogging::DebugLevel) \ + QsLogging::Logger::Helper(QsLogging::DebugLevel).stream() +#define QLOG_INFO() \ + if (QsLogging::Logger::instance().loggingLevel() <= QsLogging::InfoLevel) \ + QsLogging::Logger::Helper(QsLogging::InfoLevel).stream() +#define QLOG_WARN() \ + if (QsLogging::Logger::instance().loggingLevel() <= QsLogging::WarnLevel) \ + QsLogging::Logger::Helper(QsLogging::WarnLevel).stream() +#define QLOG_ERROR() \ + if (QsLogging::Logger::instance().loggingLevel() <= QsLogging::ErrorLevel) \ + QsLogging::Logger::Helper(QsLogging::ErrorLevel).stream() +#define QLOG_FATAL() QsLogging::Logger::Helper(QsLogging::FatalLevel).stream() + +/* +#define QLOG_TRACE() \ + if (QsLogging::Logger::instance().loggingLevel() <= QsLogging::TraceLevel) \ + QsLogging::Logger::Helper(QsLogging::TraceLevel).stream() << __FILE__ << '@' << __LINE__ +#define QLOG_DEBUG() \ + if (QsLogging::Logger::instance().loggingLevel() <= QsLogging::DebugLevel) \ + QsLogging::Logger::Helper(QsLogging::DebugLevel).stream() << __FILE__ << '@' << __LINE__ +#define QLOG_INFO() \ + if (QsLogging::Logger::instance().loggingLevel() <= QsLogging::InfoLevel) \ + QsLogging::Logger::Helper(QsLogging::InfoLevel).stream() << __FILE__ << '@' << __LINE__ +#define QLOG_WARN() \ + if (QsLogging::Logger::instance().loggingLevel() <= QsLogging::WarnLevel) \ + QsLogging::Logger::Helper(QsLogging::WarnLevel).stream() << __FILE__ << '@' << __LINE__ +#define QLOG_ERROR() \ + if (QsLogging::Logger::instance().loggingLevel() <= QsLogging::ErrorLevel) \ + QsLogging::Logger::Helper(QsLogging::ErrorLevel).stream() << __FILE__ << '@' << __LINE__ +#define QLOG_FATAL() \ + QsLogging::Logger::Helper(QsLogging::FatalLevel).stream() << __FILE__ << '@' << __LINE__ +*/ \ No newline at end of file diff --git a/logger/QsLogDest.cpp b/logger/QsLogDest.cpp new file mode 100644 index 00000000..36297a14 --- /dev/null +++ b/logger/QsLogDest.cpp @@ -0,0 +1,83 @@ +// Copyright (c) 2010, Razvan Petru +// All rights reserved. + +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: + +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, this +// list of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// * The name of the contributors may not be used to endorse or promote products +// derived from this software without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "QsLogDest.h" +#include "QsDebugOutput.h" +#include +#include +#include + +namespace QsLogging +{ + +//! file message sink +class FileDestination : public Destination +{ +public: + FileDestination(const QString &filePath); + virtual void write(const QString &message); + +private: + QFile mFile; + QTextStream mOutputStream; +}; + +FileDestination::FileDestination(const QString &filePath) +{ + mFile.setFileName(filePath); + mFile.open(QFile::WriteOnly | QFile::Text | + QFile::Truncate); // fixme: should throw on failure + mOutputStream.setDevice(&mFile); +} + +void FileDestination::write(const QString &message) +{ + mOutputStream << message << endl; + mOutputStream.flush(); +} + +//! debugger sink +class DebugOutputDestination : public Destination +{ +public: + virtual void write(const QString &message); +}; + +void DebugOutputDestination::write(const QString &message) +{ + QsDebugOutput::output(message); +} + +DestinationPtr DestinationFactory::MakeFileDestination(const QString &filePath) +{ + return DestinationPtr(new FileDestination(filePath)); +} + +DestinationPtr DestinationFactory::MakeDebugOutputDestination() +{ + return DestinationPtr(new DebugOutputDestination); +} + +} // end namespace diff --git a/logger/QsLogDest.h b/logger/QsLogDest.h new file mode 100644 index 00000000..32f1a9d0 --- /dev/null +++ b/logger/QsLogDest.h @@ -0,0 +1,53 @@ +// Copyright (c) 2010, Razvan Petru +// All rights reserved. + +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: + +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, this +// list of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// * The name of the contributors may not be used to endorse or promote products +// derived from this software without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. + +#pragma once + +#include +class QString; + +namespace QsLogging +{ + +class Destination +{ +public: + virtual ~Destination() + { + } + virtual void write(const QString &message) = 0; +}; +typedef std::shared_ptr DestinationPtr; + +//! Creates logging destinations/sinks. The caller will have ownership of +//! the newly created destinations. +class DestinationFactory +{ +public: + static DestinationPtr MakeFileDestination(const QString &filePath); + static DestinationPtr MakeDebugOutputDestination(); +}; + +} // end namespace diff --git a/logic/BaseInstance.cpp b/logic/BaseInstance.cpp index ec86596a..6a6b195b 100644 --- a/logic/BaseInstance.cpp +++ b/logic/BaseInstance.cpp @@ -132,7 +132,7 @@ InstanceList *BaseInstance::instList() const return NULL; } -QSharedPointer BaseInstance::versionList() const +std::shared_ptr BaseInstance::versionList() const { return MMC->minecraftlist(); } diff --git a/logic/BaseInstance.h b/logic/BaseInstance.h index 0056327a..e360d3ae 100644 --- a/logic/BaseInstance.h +++ b/logic/BaseInstance.h @@ -135,7 +135,7 @@ public: * \brief Gets a pointer to this instance's version list. * \return A pointer to the available version list for this instance. */ - virtual QSharedPointer versionList() const; + virtual std::shared_ptr versionList() const; /*! * \brief Gets this instance's settings object. @@ -179,9 +179,9 @@ signals: void nuked(BaseInstance * inst); protected: - QSharedPointer inst_d; + std::shared_ptr inst_d; }; // pointer for lazy people -typedef QSharedPointer InstancePtr; +typedef std::shared_ptr InstancePtr; diff --git a/logic/BaseInstance_p.h b/logic/BaseInstance_p.h index a30916a4..06c0c0ba 100644 --- a/logic/BaseInstance_p.h +++ b/logic/BaseInstance_p.h @@ -4,7 +4,7 @@ class BaseInstance; -#define I_D(Class) Class##Private * const d = (Class##Private * const) inst_d.data() +#define I_D(Class) Class##Private * const d = (Class##Private * const) inst_d.get() struct BaseInstancePrivate { diff --git a/logic/BaseVersion.h b/logic/BaseVersion.h index be717fee..01745c46 100644 --- a/logic/BaseVersion.h +++ b/logic/BaseVersion.h @@ -14,7 +14,7 @@ */ #pragma once -#include +#include /*! * An abstract base class for versions. @@ -40,6 +40,6 @@ struct BaseVersion virtual QString typeString() const = 0; }; -typedef QSharedPointer BaseVersionPtr; +typedef std::shared_ptr BaseVersionPtr; Q_DECLARE_METATYPE( BaseVersionPtr ) \ No newline at end of file diff --git a/logic/ForgeInstaller.cpp b/logic/ForgeInstaller.cpp index 9ae3f1e1..a946dd44 100644 --- a/logic/ForgeInstaller.cpp +++ b/logic/ForgeInstaller.cpp @@ -10,7 +10,7 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url) { - QSharedPointer newVersion; + std::shared_ptr newVersion; m_universal_url = universal_url; QuaZip zip(filename); @@ -88,7 +88,7 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url) realVersionId = m_forge_version->id = installObj.value("minecraft").toString(); } -bool ForgeInstaller::apply(QSharedPointer to) +bool ForgeInstaller::apply(std::shared_ptr to) { if (!m_forge_version) return false; diff --git a/logic/ForgeInstaller.h b/logic/ForgeInstaller.h index f4ceaaef..f6f22a2a 100644 --- a/logic/ForgeInstaller.h +++ b/logic/ForgeInstaller.h @@ -1,6 +1,6 @@ #pragma once #include -#include +#include class OneSixVersion; @@ -9,11 +9,11 @@ class ForgeInstaller public: ForgeInstaller(QString filename, QString universal_url); - bool apply(QSharedPointer to); + bool apply(std::shared_ptr to); private: // the version, read from the installer - QSharedPointer 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 b5832ce5..0da62803 100644 --- a/logic/InstanceFactory.cpp +++ b/logic/InstanceFactory.cpp @@ -30,6 +30,7 @@ #include #include "pathutils.h" +#include InstanceFactory InstanceFactory::loader; @@ -72,12 +73,12 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance( BaseInstance*& { QDir rootDir(instDir); - qDebug(instDir.toUtf8()); + QLOG_DEBUG() << instDir.toUtf8(); if (!rootDir.exists() && !rootDir.mkpath(".")) { return InstanceFactory::CantCreateDir; } - auto mcVer = version.dynamicCast(); + auto mcVer = std::dynamic_pointer_cast(version); if(!mcVer) return InstanceFactory::NoSuchVersion; diff --git a/logic/InstanceLauncher.cpp b/logic/InstanceLauncher.cpp index 93b87f23..720052a3 100644 --- a/logic/InstanceLauncher.cpp +++ b/logic/InstanceLauncher.cpp @@ -61,7 +61,7 @@ int InstanceLauncher::launch() { std::cout << "Launching Instance '" << qPrintable ( instId ) << "'" << std::endl; auto instance = MMC->instances()->getInstanceById(instId); - if ( instance.isNull() ) + if ( !instance ) { std::cout << "Could not find instance requested. note that you have to specify the ID, not the NAME" << std::endl; return 1; diff --git a/logic/LegacyInstance.cpp b/logic/LegacyInstance.cpp index 4f367980..2ffcb075 100644 --- a/logic/LegacyInstance.cpp +++ b/logic/LegacyInstance.cpp @@ -92,7 +92,7 @@ void LegacyInstance::cleanupAfterRun() //FIXME: delete the launcher and icons and whatnot. } -QSharedPointer< ModList > LegacyInstance::coreModList() +std::shared_ptr< ModList > LegacyInstance::coreModList() { I_D(LegacyInstance); if(!d->core_mod_list) @@ -104,7 +104,7 @@ QSharedPointer< ModList > LegacyInstance::coreModList() return d->core_mod_list; } -QSharedPointer< ModList > LegacyInstance::jarModList() +std::shared_ptr< ModList > LegacyInstance::jarModList() { I_D(LegacyInstance); if(!d->jar_mod_list) @@ -124,7 +124,7 @@ void LegacyInstance::jarModsChanged() } -QSharedPointer< ModList > LegacyInstance::loaderModList() +std::shared_ptr< ModList > LegacyInstance::loaderModList() { I_D(LegacyInstance); if(!d->loader_mod_list) @@ -136,7 +136,7 @@ QSharedPointer< ModList > LegacyInstance::loaderModList() return d->loader_mod_list; } -QSharedPointer< ModList > LegacyInstance::texturePackList() +std::shared_ptr< ModList > LegacyInstance::texturePackList() { I_D(LegacyInstance); if(!d->texture_pack_list) diff --git a/logic/LegacyInstance.h b/logic/LegacyInstance.h index 2eab9035..d7438cca 100644 --- a/logic/LegacyInstance.h +++ b/logic/LegacyInstance.h @@ -19,10 +19,10 @@ public: QString modListFile() const; ////// Mod Lists ////// - QSharedPointer jarModList(); - QSharedPointer coreModList(); - QSharedPointer loaderModList(); - QSharedPointer texturePackList(); + std::shared_ptr jarModList(); + std::shared_ptr coreModList(); + std::shared_ptr loaderModList(); + std::shared_ptr texturePackList(); ////// Directories ////// QString savesDir() const; diff --git a/logic/LegacyInstance_p.h b/logic/LegacyInstance_p.h index d1f417fe..0809b8d2 100644 --- a/logic/LegacyInstance_p.h +++ b/logic/LegacyInstance_p.h @@ -9,8 +9,8 @@ class ModList; struct LegacyInstancePrivate: public BaseInstancePrivate { - QSharedPointer jar_mod_list; - QSharedPointer core_mod_list; - QSharedPointer loader_mod_list; - QSharedPointer texture_pack_list; + std::shared_ptr jar_mod_list; + std::shared_ptr core_mod_list; + std::shared_ptr loader_mod_list; + std::shared_ptr texture_pack_list; }; \ No newline at end of file diff --git a/logic/LegacyUpdate.cpp b/logic/LegacyUpdate.cpp index d8e622dd..5f5a2e52 100644 --- a/logic/LegacyUpdate.cpp +++ b/logic/LegacyUpdate.cpp @@ -9,9 +9,11 @@ #include #include #include +#include - -LegacyUpdate::LegacyUpdate ( BaseInstance* inst, QObject* parent ) : BaseUpdate ( inst, parent ) {} +LegacyUpdate::LegacyUpdate(BaseInstance *inst, QObject *parent) : BaseUpdate(inst, parent) +{ +} void LegacyUpdate::executeTask() { @@ -20,35 +22,35 @@ void LegacyUpdate::executeTask() void LegacyUpdate::lwjglStart() { - LegacyInstance * inst = (LegacyInstance *) m_inst; + LegacyInstance *inst = (LegacyInstance *)m_inst; + + lwjglVersion = inst->lwjglVersion(); + lwjglTargetPath = PathCombine("lwjgl", lwjglVersion); + lwjglNativesPath = PathCombine(lwjglTargetPath, "natives"); - lwjglVersion = inst->lwjglVersion(); - lwjglTargetPath = PathCombine("lwjgl", lwjglVersion ); - lwjglNativesPath = PathCombine( lwjglTargetPath, "natives"); - // if the 'done' file exists, we don't have to download this again QFileInfo doneFile(PathCombine(lwjglTargetPath, "done")); - if(doneFile.exists()) + if (doneFile.exists()) { jarStart(); return; } - + auto list = MMC->lwjgllist(); - if(!list->isLoaded()) + if (!list->isLoaded()) { emitFailed("Too soon! Let the LWJGL list load :)"); return; } - + setStatus("Downloading new LWJGL."); auto version = list->getVersion(lwjglVersion); - if(!version) + if (!version) { emitFailed("Game update failed: the selected LWJGL version is invalid."); return; } - + QString url = version->url(); QUrl realUrl(url); QString hostname = realUrl.host(); @@ -56,39 +58,42 @@ void LegacyUpdate::lwjglStart() QNetworkRequest req(realUrl); req.setRawHeader("Host", hostname.toLatin1()); req.setHeader(QNetworkRequest::UserAgentHeader, "Wget/1.14 (linux-gnu)"); - QNetworkReply * rep = worker->get ( req ); - - m_reply = QSharedPointer (rep, &QObject::deleteLater); - connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SIGNAL(progress(qint64,qint64))); - connect(worker.data(), SIGNAL(finished(QNetworkReply*)), SLOT(lwjglFinished(QNetworkReply*))); - //connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(downloadError(QNetworkReply::NetworkError))); + QNetworkReply *rep = worker->get(req); + + m_reply = std::shared_ptr(rep); + connect(rep, SIGNAL(downloadProgress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); + connect(worker.get(), SIGNAL(finished(QNetworkReply *)), + SLOT(lwjglFinished(QNetworkReply *))); + // connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), + // SLOT(downloadError(QNetworkReply::NetworkError))); } -void LegacyUpdate::lwjglFinished(QNetworkReply* reply) +void LegacyUpdate::lwjglFinished(QNetworkReply *reply) { - if(m_reply != reply) + if (m_reply.get() != reply) { return; } - if(reply->error() != QNetworkReply::NoError) + if (reply->error() != QNetworkReply::NoError) { - emitFailed( "Failed to download: "+ - reply->errorString()+ - "\nSometimes you have to wait a bit if you download many LWJGL versions in a row. YMMV"); + emitFailed("Failed to download: " + reply->errorString() + + "\nSometimes you have to wait a bit if you download many LWJGL versions in " + "a row. YMMV"); return; } auto worker = MMC->qnam(); - //Here i check if there is a cookie for me in the reply and extract it - QList cookies = qvariant_cast>(reply->header(QNetworkRequest::SetCookieHeader)); - if(cookies.count() != 0) + // Here i check if there is a cookie for me in the reply and extract it + QList cookies = + qvariant_cast>(reply->header(QNetworkRequest::SetCookieHeader)); + if (cookies.count() != 0) { - //you must tell which cookie goes with which url + // you must tell which cookie goes with which url worker->cookieJar()->setCookiesFromUrl(cookies, QUrl("sourceforge.net")); } - //here you can check for the 302 or whatever other header i need + // here you can check for the 302 or whatever other header i need QVariant newLoc = reply->header(QNetworkRequest::LocationHeader); - if(newLoc.isValid()) + if (newLoc.isValid()) { QString redirectedTo = reply->header(QNetworkRequest::LocationHeader).toString(); QUrl realUrl(redirectedTo); @@ -96,9 +101,10 @@ void LegacyUpdate::lwjglFinished(QNetworkReply* reply) QNetworkRequest req(redirectedTo); req.setRawHeader("Host", hostname.toLatin1()); req.setHeader(QNetworkRequest::UserAgentHeader, "Wget/1.14 (linux-gnu)"); - QNetworkReply * rep = worker->get(req); - connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SIGNAL(progress(qint64,qint64))); - m_reply = QSharedPointer (rep, &QObject::deleteLater); + QNetworkReply *rep = worker->get(req); + connect(rep, SIGNAL(downloadProgress(qint64, qint64)), + SIGNAL(progress(qint64, qint64))); + m_reply = std::shared_ptr(rep); return; } QFile saveMe("lwjgl.zip"); @@ -114,26 +120,26 @@ void LegacyUpdate::extractLwjgl() // make sure the directories are there bool success = ensureFolderPathExists(lwjglNativesPath); - - if(!success) + + if (!success) { emitFailed("Failed to extract the lwjgl libs - error when creating required folders."); return; } - + QuaZip zip("lwjgl.zip"); - if(!zip.open(QuaZip::mdUnzip)) + if (!zip.open(QuaZip::mdUnzip)) { emitFailed("Failed to extract the lwjgl libs - not a valid archive."); return; } - + // and now we are going to access files inside it QuaZipFile file(&zip); - const QString jarNames[] = { "jinput.jar", "lwjgl_util.jar", "lwjgl.jar" }; - for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) + const QString jarNames[] = {"jinput.jar", "lwjgl_util.jar", "lwjgl.jar"}; + for (bool more = zip.goToFirstFile(); more; more = zip.goToNextFile()) { - if(!file.open(QIODevice::ReadOnly)) + if (!file.open(QIODevice::ReadOnly)) { zip.close(); emitFailed("Failed to extract the lwjgl libs - error while reading archive."); @@ -141,7 +147,7 @@ void LegacyUpdate::extractLwjgl() } QuaZipFileInfo info; QString name = file.getActualFileName(); - if(name.endsWith('/')) + if (name.endsWith('/')) { file.close(); continue; @@ -156,25 +162,25 @@ void LegacyUpdate::extractLwjgl() } } // Not found? look for the natives - if(destFileName.isEmpty()) + if (destFileName.isEmpty()) { #ifdef Q_OS_WIN32 QString nativesDir = "windows"; #else - #ifdef Q_OS_MAC +#ifdef Q_OS_MAC QString nativesDir = "macosx"; - #else +#else QString nativesDir = "linux"; - #endif +#endif #endif if (name.contains(nativesDir)) { int lastSlash = name.lastIndexOf('/'); int lastBackSlash = name.lastIndexOf('\\'); - if(lastSlash != -1) - name = name.mid(lastSlash+1); - else if(lastBackSlash != -1) - name = name.mid(lastBackSlash+1); + if (lastSlash != -1) + name = name.mid(lastSlash + 1); + else if (lastBackSlash != -1) + name = name.mid(lastBackSlash + 1); destFileName = PathCombine(lwjglNativesPath, name); } } @@ -190,7 +196,7 @@ void LegacyUpdate::extractLwjgl() file.close(); // do not forget to close! } zip.close(); - m_reply.clear(); + m_reply.reset(); QFile doneFile(PathCombine(lwjglTargetPath, "done")); doneFile.open(QIODevice::WriteOnly); doneFile.write("done."); @@ -204,13 +210,13 @@ void LegacyUpdate::lwjglFailed() void LegacyUpdate::jarStart() { - LegacyInstance * inst = (LegacyInstance *) m_inst; - if(!inst->shouldUpdate() || inst->shouldUseCustomBaseJar()) + LegacyInstance *inst = (LegacyInstance *)m_inst; + if (!inst->shouldUpdate() || inst->shouldUseCustomBaseJar()) { ModTheJar(); return; } - + setStatus("Checking for jar updates..."); // Make directories QDir binDir(inst->binDir()); @@ -226,13 +232,13 @@ void LegacyUpdate::jarStart() QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/"); QString intended_version_id = inst->intendedVersionId(); urlstr += intended_version_id + "/" + intended_version_id + ".jar"; - + auto dljob = new DownloadJob("Minecraft.jar for version " + intended_version_id); dljob->addFileDownload(QUrl(urlstr), inst->defaultBaseJar()); legacyDownloadJob.reset(dljob); connect(dljob, SIGNAL(succeeded()), SLOT(jarFinished())); connect(dljob, SIGNAL(failed()), SLOT(jarFailed())); - connect(dljob, SIGNAL(progress(qint64,qint64)), SIGNAL(progress(qint64,qint64))); + connect(dljob, SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); legacyDownloadJob->start(); } @@ -248,34 +254,36 @@ void LegacyUpdate::jarFailed() emitFailed("Failed to download the minecraft jar. Try again later."); } -bool LegacyUpdate::MergeZipFiles( QuaZip* into, QFileInfo from, QSet< QString >& contained, MetainfAction metainf ) +bool LegacyUpdate::MergeZipFiles(QuaZip *into, QFileInfo from, QSet &contained, + MetainfAction metainf) { setStatus("Installing mods - Adding " + from.fileName()); - + QuaZip modZip(from.filePath()); modZip.open(QuaZip::mdUnzip); - + QuaZipFile fileInsideMod(&modZip); - QuaZipFile zipOutFile( into ); - for(bool more=modZip.goToFirstFile(); more; more=modZip.goToNextFile()) + QuaZipFile zipOutFile(into); + for (bool more = modZip.goToFirstFile(); more; more = modZip.goToNextFile()) { QString filename = modZip.getCurrentFileName(); - if(filename.contains("META-INF") && metainf == LegacyUpdate::IgnoreMetainf) + if (filename.contains("META-INF") && metainf == LegacyUpdate::IgnoreMetainf) { - qDebug() << "Skipping META-INF " << filename << " from " << from.fileName(); + QLOG_INFO() << "Skipping META-INF " << filename << " from " << from.fileName(); continue; } - if(contained.contains(filename)) + if (contained.contains(filename)) { - qDebug() << "Skipping already contained file " << filename << " from " << from.fileName(); + QLOG_INFO() << "Skipping already contained file " << filename << " from " + << from.fileName(); continue; } contained.insert(filename); - qDebug() << "Adding file " << filename << " from " << from.fileName(); - - if(!fileInsideMod.open(QIODevice::ReadOnly)) + QLOG_INFO() << "Adding file " << filename << " from " << from.fileName(); + + if (!fileInsideMod.open(QIODevice::ReadOnly)) { - qDebug() << "Failed to open " << filename << " from " << from.fileName(); + QLOG_ERROR() << "Failed to open " << filename << " from " << from.fileName(); return false; } /* @@ -286,17 +294,17 @@ bool LegacyUpdate::MergeZipFiles( QuaZip* into, QFileInfo from, QSet< QString >& /* info_out.externalAttr = old_info.externalAttr; */ - if(!zipOutFile.open(QIODevice::WriteOnly, info_out)) + if (!zipOutFile.open(QIODevice::WriteOnly, info_out)) { - qDebug() << "Failed to open " << filename << " in the jar"; + QLOG_ERROR() << "Failed to open " << filename << " in the jar"; fileInsideMod.close(); return false; } - if(!JlCompress::copyData(fileInsideMod, zipOutFile)) + if (!JlCompress::copyData(fileInsideMod, zipOutFile)) { zipOutFile.close(); fileInsideMod.close(); - qDebug() << "Failed to copy data of " << filename << " into the jar"; + QLOG_ERROR() << "Failed to copy data of " << filename << " into the jar"; return false; } zipOutFile.close(); @@ -307,34 +315,34 @@ bool LegacyUpdate::MergeZipFiles( QuaZip* into, QFileInfo from, QSet< QString >& void LegacyUpdate::ModTheJar() { - LegacyInstance * inst = (LegacyInstance *) m_inst; - - if(!inst->shouldRebuild()) + LegacyInstance *inst = (LegacyInstance *)m_inst; + + if (!inst->shouldRebuild()) { emitSucceeded(); return; } - + // Get the mod list auto modList = inst->jarModList(); - - QFileInfo runnableJar (inst->runnableJar()); - QFileInfo baseJar (inst->baseJar()); + + QFileInfo runnableJar(inst->runnableJar()); + QFileInfo baseJar(inst->baseJar()); bool base_is_custom = inst->shouldUseCustomBaseJar(); - + // Nothing to do if there are no jar mods to install, no backup and just the mc jar - if(base_is_custom) + if (base_is_custom) { // yes, this can happen if the instance only has the runnable jar and not the base jar // it *could* be assumed that such an instance is vanilla, but that wouldn't be safe // because that's not something mmc4 guarantees - if(runnableJar.isFile() && !baseJar.exists() && modList->empty()) + if (runnableJar.isFile() && !baseJar.exists() && modList->empty()) { inst->setShouldRebuild(false); emitSucceeded(); return; } - + setStatus("Installing mods - backing up minecraft.jar..."); if (!baseJar.exists() && !QFile::copy(runnableJar.filePath(), baseJar.filePath())) { @@ -342,24 +350,24 @@ void LegacyUpdate::ModTheJar() return; } } - + if (!baseJar.exists()) { emitFailed("The base jar " + baseJar.filePath() + " does not exist"); return; } - + if (runnableJar.exists() && !QFile::remove(runnableJar.filePath())) { emitFailed("Failed to delete old minecraft.jar"); return; } - - //TaskStep(); // STEP 1 + + // TaskStep(); // STEP 1 setStatus("Installing mods - Opening minecraft.jar"); QuaZip zipOut(runnableJar.filePath()); - if(!zipOut.open(QuaZip::mdCreate)) + if (!zipOut.open(QuaZip::mdCreate)) { QFile::remove(runnableJar.filePath()); emitFailed("Failed to open the minecraft.jar for modding"); @@ -376,7 +384,7 @@ void LegacyUpdate::ModTheJar() auto &mod = modList->operator[](i); if (mod.type() == Mod::MOD_ZIPFILE) { - if(!MergeZipFiles(&zipOut, mod.filename(), addedFiles, LegacyUpdate::KeepMetainf)) + if (!MergeZipFiles(&zipOut, mod.filename(), addedFiles, LegacyUpdate::KeepMetainf)) { zipOut.close(); QFile::remove(runnableJar.filePath()); @@ -387,7 +395,8 @@ void LegacyUpdate::ModTheJar() else if (mod.type() == Mod::MOD_SINGLEFILE) { auto filename = mod.filename(); - if(!JlCompress::compressFile(&zipOut, filename.absoluteFilePath(), filename.fileName())) + if (!JlCompress::compressFile(&zipOut, filename.absoluteFilePath(), + filename.fileName())) { zipOut.close(); QFile::remove(runnableJar.filePath()); @@ -395,7 +404,8 @@ void LegacyUpdate::ModTheJar() return; } addedFiles.insert(filename.fileName()); - qDebug() << "Adding file " << filename.fileName() << " from " << filename.absoluteFilePath(); + QLOG_INFO() << "Adding file " << filename.fileName() << " from " + << filename.absoluteFilePath(); } else if (mod.type() == Mod::MOD_FOLDER) { @@ -404,35 +414,36 @@ void LegacyUpdate::ModTheJar() QDir dir(what_to_zip); dir.cdUp(); QString parent_dir = dir.absolutePath(); - if(!JlCompress::compressSubDir(&zipOut, what_to_zip, parent_dir, true, addedFiles)) + if (!JlCompress::compressSubDir(&zipOut, what_to_zip, parent_dir, true, addedFiles)) { zipOut.close(); QFile::remove(runnableJar.filePath()); emitFailed("Failed to add " + filename.fileName() + " to the jar"); return; } - qDebug() << "Adding folder " << filename.fileName() << " from " << filename.absoluteFilePath(); + QLOG_INFO() << "Adding folder " << filename.fileName() << " from " + << filename.absoluteFilePath(); } } - - if(!MergeZipFiles(&zipOut, baseJar, addedFiles, LegacyUpdate::IgnoreMetainf)) + + if (!MergeZipFiles(&zipOut, baseJar, addedFiles, LegacyUpdate::IgnoreMetainf)) { zipOut.close(); QFile::remove(runnableJar.filePath()); emitFailed("Failed to insert minecraft.jar contents."); return; } - + // Recompress the jar zipOut.close(); - if(zipOut.getZipError()!=0) + if (zipOut.getZipError() != 0) { QFile::remove(runnableJar.filePath()); emitFailed("Failed to finalize minecraft.jar!"); return; - } + } inst->setShouldRebuild(false); - //inst->UpdateVersion(true); + // inst->UpdateVersion(true); emitSucceeded(); return; } \ No newline at end of file diff --git a/logic/LegacyUpdate.h b/logic/LegacyUpdate.h index 05c00495..e84ec56a 100644 --- a/logic/LegacyUpdate.h +++ b/logic/LegacyUpdate.h @@ -56,7 +56,7 @@ private: bool MergeZipFiles(QuaZip *into, QFileInfo from, QSet& contained, MetainfAction metainf); private: - QSharedPointer m_reply; + std::shared_ptr m_reply; // target version, determined during this task // MinecraftVersion *targetVersion; diff --git a/logic/Mod.cpp b/logic/Mod.cpp index 38faa760..75e0a3a9 100644 --- a/logic/Mod.cpp +++ b/logic/Mod.cpp @@ -20,14 +20,13 @@ #include #include #include -#include #include #include #include "Mod.h" #include #include - +#include Mod::Mod( const QFileInfo& file ) { @@ -134,8 +133,8 @@ void Mod::ReadMCModInfo(QByteArray contents) int version = val.toDouble(); if(version != 2) { - qDebug() << "BAD stuff happened to mod json:"; - qDebug() << contents; + QLOG_ERROR() << "BAD stuff happened to mod json:"; + QLOG_ERROR() << contents; return; } auto arrVal = jsonDoc.object().value("modlist"); diff --git a/logic/ModList.cpp b/logic/ModList.cpp index 84511e4c..a600afff 100644 --- a/logic/ModList.cpp +++ b/logic/ModList.cpp @@ -19,9 +19,9 @@ #include #include #include -#include #include #include +#include ModList::ModList ( const QString& dir, const QString& list_file ) : QAbstractListModel(), m_dir(dir), m_list_file(list_file) @@ -39,18 +39,18 @@ void ModList::startWatching() { is_watching = m_watcher->addPath(m_dir.absolutePath()); if(is_watching) - qDebug() << "Started watching " << m_dir.absolutePath(); + QLOG_INFO() << "Started watching " << m_dir.absolutePath(); else - qDebug() << "Failed to start watching " << m_dir.absolutePath(); + QLOG_INFO() << "Failed to start watching " << m_dir.absolutePath(); } void ModList::stopWatching() { is_watching = !m_watcher->removePath(m_dir.absolutePath()); if(!is_watching) - qDebug() << "Stopped watching " << m_dir.absolutePath(); + QLOG_INFO() << "Stopped watching " << m_dir.absolutePath(); else - qDebug() << "Failed to stop watching " << m_dir.absolutePath(); + QLOG_INFO() << "Failed to stop watching " << m_dir.absolutePath(); } @@ -436,7 +436,7 @@ bool ModList::dropMimeData ( const QMimeData* data, Qt::DropAction action, int r row = rowCount(); if (column == -1) column = 0; - qDebug() << "Drop row: " << row << " column: " << column; + QLOG_INFO() << "Drop row: " << row << " column: " << column; // files dropped from outside? if(data->hasUrls()) @@ -452,7 +452,7 @@ bool ModList::dropMimeData ( const QMimeData* data, Qt::DropAction action, int r continue; QString filename = url.toLocalFile(); installMod(filename, row); - qDebug() << "installing: " << filename; + QLOG_INFO() << "installing: " << filename; } if(was_watching) startWatching(); @@ -466,7 +466,7 @@ bool ModList::dropMimeData ( const QMimeData* data, Qt::DropAction action, int r return false; QString remoteId = list[0]; int remoteIndex = list[1].toInt(); - qDebug() << "move: " << sourcestr; + QLOG_INFO() << "move: " << sourcestr; // no moving of things between two lists if(remoteId != m_list_id) return false; diff --git a/logic/OneSixAssets.cpp b/logic/OneSixAssets.cpp index ca7a5534..6aa0a207 100644 --- a/logic/OneSixAssets.cpp +++ b/logic/OneSixAssets.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include "OneSixAssets.h" #include "net/DownloadJob.h" @@ -21,6 +21,7 @@ class ThreadedDeleter : public QThread public: void run() { + QLOG_INFO() << "Cleaning up assets folder..."; QDirIterator iter ( m_base, QDirIterator::Subdirectories ); int base_length = m_base.length(); while ( iter.hasNext() ) @@ -34,12 +35,12 @@ public: trimmedf.remove ( 0, base_length + 1 ); if ( m_whitelist.contains ( trimmedf ) ) { - // qDebug() << trimmedf << " gets to live"; + QLOG_TRACE() << trimmedf << " gets to live"; } else { // DO NOT TOLERATE JUNK - // qDebug() << trimmedf << " dies"; + QLOG_TRACE() << trimmedf << " dies"; QFile f ( filename ); f.remove(); } @@ -67,13 +68,15 @@ void OneSixAssets::fetchXMLFinished() nuke_whitelist.clear(); auto firstJob = index_job->first(); - QByteArray ba = firstJob.dynamicCast()->m_data; + QByteArray ba = std::dynamic_pointer_cast(firstJob)->m_data; QString xmlErrorMsg; QDomDocument doc; if ( !doc.setContent ( ba, false, &xmlErrorMsg ) ) { - qDebug() << "Failed to process s3.amazonaws.com/Minecraft.Resources. XML error:" << xmlErrorMsg << ba; + QLOG_ERROR() << "Failed to process s3.amazonaws.com/Minecraft.Resources. XML error:" << xmlErrorMsg << ba; + emit failed(); + return; } //QRegExp etag_match(".*([a-f0-9]{32}).*"); QDomNodeList contents = doc.elementsByTagName ( "Contents" ); diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index 6e39b5b5..c5d546a3 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -9,6 +9,7 @@ #include #include #include +#include OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *setting_obj, QObject *parent) @@ -102,7 +103,7 @@ MinecraftProcess *OneSixInstance::prepareForLaunch(LoginResponse response) for (auto lib : libs_to_extract) { QString path = "libraries/" + lib->storagePath(); - qDebug() << "Will extract " << path.toLocal8Bit(); + QLOG_INFO() << "Will extract " << path.toLocal8Bit(); if (JlCompress::extractWithExceptions(path, natives_dir_raw, lib->extract_excludes) .isEmpty()) { @@ -156,7 +157,7 @@ void OneSixInstance::cleanupAfterRun() dir.removeRecursively(); } -QSharedPointer OneSixInstance::loaderModList() +std::shared_ptr OneSixInstance::loaderModList() { I_D(OneSixInstance); if (!d->loader_mod_list) @@ -168,7 +169,7 @@ QSharedPointer OneSixInstance::loaderModList() return d->loader_mod_list; } -QSharedPointer OneSixInstance::resourcePackList() +std::shared_ptr OneSixInstance::resourcePackList() { I_D(OneSixInstance); if (!d->resource_pack_list) @@ -271,7 +272,7 @@ bool OneSixInstance::reloadFullVersion() return false; } -QSharedPointer OneSixInstance::getFullVersion() +std::shared_ptr OneSixInstance::getFullVersion() { I_D(OneSixInstance); return d->version; diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h index 33091188..8f5c22e6 100644 --- a/logic/OneSixInstance.h +++ b/logic/OneSixInstance.h @@ -14,8 +14,8 @@ public: ////// Mod Lists ////// - QSharedPointer loaderModList(); - QSharedPointer resourcePackList(); + std::shared_ptr loaderModList(); + std::shared_ptr resourcePackList(); ////// Directories ////// QString resourcePacksDir() const; @@ -40,7 +40,7 @@ public: /// reload the full version json file. return true on success! bool reloadFullVersion(); /// get the current full version info - QSharedPointer getFullVersion(); + std::shared_ptr getFullVersion(); /// revert the current custom version back to base bool revertCustomVersion(); /// customize the current base version diff --git a/logic/OneSixInstance_p.h b/logic/OneSixInstance_p.h index 7b1ca82e..06737b6f 100644 --- a/logic/OneSixInstance_p.h +++ b/logic/OneSixInstance_p.h @@ -7,7 +7,7 @@ struct OneSixInstancePrivate: public BaseInstancePrivate { - QSharedPointer version; - QSharedPointer loader_mod_list; - QSharedPointer resource_pack_list; + 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/OneSixLibrary.cpp index 63d42646..0643abe3 100644 --- a/logic/OneSixLibrary.cpp +++ b/logic/OneSixLibrary.cpp @@ -72,7 +72,7 @@ void OneSixLibrary::addNative(OpSys os, QString suffix) m_is_native = true; m_native_suffixes[os] = suffix; } -void OneSixLibrary::setRules(QList> rules) +void OneSixLibrary::setRules(QList> rules) { m_rules = rules; } diff --git a/logic/OneSixLibrary.h b/logic/OneSixLibrary.h index 2a16d8e1..a8bcc364 100644 --- a/logic/OneSixLibrary.h +++ b/logic/OneSixLibrary.h @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include "OpSys.h" @@ -14,7 +14,7 @@ private: // basic values used internally (so far) QString m_name; QString m_base_url = "https://s3.amazonaws.com/Minecraft.Download/libraries/"; - QList > m_rules; + QList > m_rules; // custom values /// absolute URL. takes precedence over m_download_path, if defined @@ -83,7 +83,7 @@ public: /// Attach a name suffix to the specified OS native void addNative(OpSys os, QString suffix); /// Set the load rules - void setRules(QList > rules); + void setRules(QList > rules); /// Returns true if the library should be loaded (or extracted, in case of natives) bool isActive(); diff --git a/logic/OneSixRule.cpp b/logic/OneSixRule.cpp index 545cd641..cb64c9ba 100644 --- a/logic/OneSixRule.cpp +++ b/logic/OneSixRule.cpp @@ -2,9 +2,9 @@ #include #include -QList> rulesFromJsonV4(QJsonObject &objectWithRules) +QList> rulesFromJsonV4(QJsonObject &objectWithRules) { - QList> rules; + QList> rules; auto rulesVal = objectWithRules.value("rules"); if (!rulesVal.isArray()) return rules; @@ -12,7 +12,7 @@ QList> rulesFromJsonV4(QJsonObject &objectWithRules) QJsonArray ruleList = rulesVal.toArray(); for (auto ruleVal : ruleList) { - QSharedPointer rule; + std::shared_ptr rule; if (!ruleVal.isObject()) continue; auto ruleObj = ruleVal.toObject(); diff --git a/logic/OneSixRule.h b/logic/OneSixRule.h index 23d20ff4..6be01f1b 100644 --- a/logic/OneSixRule.h +++ b/logic/OneSixRule.h @@ -11,7 +11,7 @@ enum RuleAction }; RuleAction RuleAction_fromString(QString); -QList> rulesFromJsonV4(QJsonObject &objectWithRules); +QList> rulesFromJsonV4(QJsonObject &objectWithRules); class Rule { @@ -48,9 +48,9 @@ protected: : Rule(result), m_system(system), m_version_regexp(version_regexp) {} public: virtual QJsonObject toJson(); - static QSharedPointer create(RuleAction result, OpSys system, QString version_regexp) + static std::shared_ptr create(RuleAction result, OpSys system, QString version_regexp) { - return QSharedPointer (new OsRule(result, system, version_regexp)); + return std::shared_ptr (new OsRule(result, system, version_regexp)); } }; @@ -65,8 +65,8 @@ protected: : Rule(result) {} public: virtual QJsonObject toJson(); - static QSharedPointer create(RuleAction result) + static std::shared_ptr create(RuleAction result) { - return QSharedPointer (new ImplicitRule(result)); + return std::shared_ptr (new ImplicitRule(result)); } }; diff --git a/logic/OneSixUpdate.cpp b/logic/OneSixUpdate.cpp index 41d8f599..008995ae 100644 --- a/logic/OneSixUpdate.cpp +++ b/logic/OneSixUpdate.cpp @@ -22,8 +22,6 @@ #include #include -#include - #include "BaseInstance.h" #include "lists/MinecraftVersionList.h" #include "OneSixVersion.h" @@ -49,8 +47,8 @@ void OneSixUpdate::executeTask() } // Get a pointer to the version object that corresponds to the instance's version. - targetVersion = - MMC->minecraftlist()->findVersion(intendedVersion).dynamicCast(); + targetVersion = std::dynamic_pointer_cast( + MMC->minecraftlist()->findVersion(intendedVersion)); if (targetVersion == nullptr) { // don't do anything if it was invalid @@ -77,10 +75,9 @@ void OneSixUpdate::versionFileStart() auto job = new DownloadJob("Version index"); job->addByteArrayDownload(QUrl(urlstr)); specificVersionDownloadJob.reset(job); - connect(specificVersionDownloadJob.data(), SIGNAL(succeeded()), - SLOT(versionFileFinished())); - connect(specificVersionDownloadJob.data(), SIGNAL(failed()), SLOT(versionFileFailed())); - connect(specificVersionDownloadJob.data(), SIGNAL(progress(qint64, qint64)), + connect(specificVersionDownloadJob.get(), SIGNAL(succeeded()), SLOT(versionFileFinished())); + connect(specificVersionDownloadJob.get(), SIGNAL(failed()), SLOT(versionFileFailed())); + connect(specificVersionDownloadJob.get(), SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); specificVersionDownloadJob->start(); } @@ -103,7 +100,7 @@ void OneSixUpdate::versionFileFinished() emitFailed("Can't open " + version1 + " for writing."); return; } - auto data = DlJob.dynamicCast()->m_data; + auto data = std::dynamic_pointer_cast(DlJob)->m_data; qint64 actual = 0; if ((actual = vfile1.write(data)) != data.size()) { @@ -149,7 +146,7 @@ void OneSixUpdate::jarlibStart() return; } - QSharedPointer version = inst->getFullVersion(); + std::shared_ptr version = inst->getFullVersion(); // download the right jar, save it in versions/$version/$version.jar QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/"); @@ -171,15 +168,15 @@ void OneSixUpdate::jarlibStart() auto entry = metacache->resolveEntry("libraries", lib->storagePath()); if (entry->stale) { - if(lib->hint() == "forge-pack-xz") + if (lib->hint() == "forge-pack-xz") jarlibDownloadJob->addForgeXzDownload(download_path, entry); else jarlibDownloadJob->addCacheDownload(download_path, entry); } } - connect(jarlibDownloadJob.data(), SIGNAL(succeeded()), SLOT(jarlibFinished())); - connect(jarlibDownloadJob.data(), SIGNAL(failed()), SLOT(jarlibFailed())); - connect(jarlibDownloadJob.data(), SIGNAL(progress(qint64, qint64)), + connect(jarlibDownloadJob.get(), SIGNAL(succeeded()), SLOT(jarlibFinished())); + connect(jarlibDownloadJob.get(), SIGNAL(failed()), SLOT(jarlibFailed())); + connect(jarlibDownloadJob.get(), SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); jarlibDownloadJob->start(); diff --git a/logic/OneSixUpdate.h b/logic/OneSixUpdate.h index 7314a6d1..ed8dcbcd 100644 --- a/logic/OneSixUpdate.h +++ b/logic/OneSixUpdate.h @@ -47,7 +47,7 @@ private: DownloadJobPtr jarlibDownloadJob; // target version, determined during this task - QSharedPointer targetVersion; + std::shared_ptr targetVersion; }; diff --git a/logic/OneSixVersion.cpp b/logic/OneSixVersion.cpp index 64a47562..f7efedf9 100644 --- a/logic/OneSixVersion.cpp +++ b/logic/OneSixVersion.cpp @@ -2,8 +2,8 @@ #include "OneSixLibrary.h" #include "OneSixRule.h" -QSharedPointer fromJsonV4(QJsonObject root, - QSharedPointer fullVersion) +std::shared_ptr fromJsonV4(QJsonObject root, + std::shared_ptr fullVersion) { fullVersion->id = root.value("id").toString(); @@ -64,7 +64,7 @@ QSharedPointer fromJsonV4(QJsonObject root, auto nameVal = libObj.value("name"); if (!nameVal.isString()) continue; - QSharedPointer library(new OneSixLibrary(nameVal.toString())); + std::shared_ptr library(new OneSixLibrary(nameVal.toString())); auto urlVal = libObj.value("url"); if (urlVal.isString()) @@ -129,9 +129,9 @@ QSharedPointer fromJsonV4(QJsonObject root, return fullVersion; } -QSharedPointer OneSixVersion::fromJson(QJsonObject root) +std::shared_ptr OneSixVersion::fromJson(QJsonObject root) { - QSharedPointer readVersion(new OneSixVersion()); + std::shared_ptr readVersion(new OneSixVersion()); int launcher_ver = readVersion->minimumLauncherVersion = root.value("minimumLauncherVersion").toDouble(); @@ -140,16 +140,16 @@ QSharedPointer OneSixVersion::fromJson(QJsonObject root) return fromJsonV4(root, readVersion); else { - return QSharedPointer(); + return std::shared_ptr(); } } -QSharedPointer OneSixVersion::fromFile(QString filepath) +std::shared_ptr OneSixVersion::fromFile(QString filepath) { QFile file(filepath); if (!file.open(QIODevice::ReadOnly)) { - return QSharedPointer(); + return std::shared_ptr(); } auto data = file.readAll(); @@ -158,12 +158,12 @@ QSharedPointer OneSixVersion::fromFile(QString filepath) if (jsonError.error != QJsonParseError::NoError) { - return QSharedPointer(); + return std::shared_ptr(); } if (!jsonDoc.isObject()) { - return QSharedPointer(); + return std::shared_ptr(); } QJsonObject root = jsonDoc.object(); auto version = fromJson(root); @@ -202,9 +202,9 @@ bool OneSixVersion::toOriginalFile() return file.commit(); } -QList> OneSixVersion::getActiveNormalLibs() +QList> OneSixVersion::getActiveNormalLibs() { - QList> output; + QList> output; for (auto lib : libraries) { if (lib->isActive() && !lib->isNative()) @@ -215,9 +215,9 @@ QList> OneSixVersion::getActiveNormalLibs() return output; } -QList> OneSixVersion::getActiveNativeLibs() +QList> OneSixVersion::getActiveNativeLibs() { - QList> output; + QList> output; for (auto lib : libraries) { if (lib->isActive() && lib->isNative()) diff --git a/logic/OneSixVersion.h b/logic/OneSixVersion.h index 69268ecf..3529138c 100644 --- a/logic/OneSixVersion.h +++ b/logic/OneSixVersion.h @@ -1,5 +1,7 @@ #pragma once #include +#include + class OneSixLibrary; class OneSixVersion : public QAbstractListModel @@ -16,12 +18,12 @@ public: // serialization/deserialization public: bool toOriginalFile(); - static QSharedPointer fromJson(QJsonObject root); - static QSharedPointer 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(); @@ -62,7 +64,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/ForgeVersionList.cpp b/logic/lists/ForgeVersionList.cpp index ac1a4ef5..9b698135 100644 --- a/logic/lists/ForgeVersionList.cpp +++ b/logic/lists/ForgeVersionList.cpp @@ -18,11 +18,11 @@ #include "MultiMC.h" #include - #include - #include +#include + #define JSON_URL "http://files.minecraftforge.net/minecraftforge/json" ForgeVersionList::ForgeVersionList(QObject *parent) : BaseVersionList(parent) @@ -62,7 +62,7 @@ QVariant ForgeVersionList::data(const QModelIndex &index, int role) const if (index.row() > count()) return QVariant(); - auto version = m_vlist[index.row()].dynamicCast(); + auto version = std::dynamic_pointer_cast(m_vlist[index.row()]); switch (role) { case Qt::DisplayRole: @@ -164,9 +164,9 @@ void ForgeListLoadTask::executeTask() auto forgeListEntry = MMC->metacache()->resolveEntry("minecraftforge", "list.json"); job->addCacheDownload(QUrl(JSON_URL), forgeListEntry); listJob.reset(job); - connect(listJob.data(), SIGNAL(succeeded()), SLOT(list_downloaded())); - connect(listJob.data(), SIGNAL(failed()), SLOT(list_failed())); - connect(listJob.data(), SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); + connect(listJob.get(), SIGNAL(succeeded()), SLOT(list_downloaded())); + connect(listJob.get(), SIGNAL(failed()), SLOT(list_failed())); + connect(listJob.get(), SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); listJob->start(); } @@ -176,10 +176,10 @@ void ForgeListLoadTask::list_failed() auto reply = DlJob->m_reply; if(reply) { - qDebug() << "Getting forge version list failed: " << reply->errorString(); + QLOG_ERROR() << "Getting forge version list failed: " << reply->errorString(); } else - qDebug() << "Getting forge version list failed for reasons unknown."; + QLOG_ERROR() << "Getting forge version list failed for reasons unknown."; } void ForgeListLoadTask::list_downloaded() @@ -187,7 +187,7 @@ void ForgeListLoadTask::list_downloaded() QByteArray data; { auto DlJob = listJob->first(); - auto filename = DlJob.dynamicCast()->m_target_path; + auto filename = std::dynamic_pointer_cast(DlJob)->m_target_path; QFile listFile(filename); if(!listFile.open(QIODevice::ReadOnly)) return; @@ -272,7 +272,7 @@ void ForgeListLoadTask::list_downloaded() if (valid) { // Now, we construct the version object and add it to the list. - QSharedPointer fVersion(new ForgeVersion()); + std::shared_ptr fVersion(new ForgeVersion()); fVersion->universal_url = url; fVersion->changelog_url = changelog_url; fVersion->installer_url = installer_url; diff --git a/logic/lists/ForgeVersionList.h b/logic/lists/ForgeVersionList.h index 4abfe9ce..56a207c8 100644 --- a/logic/lists/ForgeVersionList.h +++ b/logic/lists/ForgeVersionList.h @@ -26,7 +26,7 @@ #include "logic/net/DownloadJob.h" class ForgeVersion; -typedef QSharedPointer ForgeVersionPtr; +typedef std::shared_ptr ForgeVersionPtr; struct ForgeVersion : public BaseVersion { diff --git a/logic/lists/InstanceList.cpp b/logic/lists/InstanceList.cpp index b930f781..ac054267 100644 --- a/logic/lists/InstanceList.cpp +++ b/logic/lists/InstanceList.cpp @@ -3,7 +3,7 @@ * 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 @@ -29,13 +29,13 @@ #include "logic/lists/IconList.h" #include "logic/BaseInstance.h" #include "logic/InstanceFactory.h" +#include const static int GROUP_FILE_FORMAT_VERSION = 1; -InstanceList::InstanceList(const QString &instDir, QObject *parent) : - QAbstractListModel ( parent ), m_instDir("instances") +InstanceList::InstanceList(const QString &instDir, QObject *parent) + : QAbstractListModel(parent), m_instDir("instances") { - } InstanceList::~InstanceList() @@ -43,32 +43,32 @@ InstanceList::~InstanceList() saveGroupList(); } -int InstanceList::rowCount ( const QModelIndex& parent ) const +int InstanceList::rowCount(const QModelIndex &parent) const { - Q_UNUSED ( parent ); + Q_UNUSED(parent); return m_instances.count(); } -QModelIndex InstanceList::index ( int row, int column, const QModelIndex& parent ) const +QModelIndex InstanceList::index(int row, int column, const QModelIndex &parent) const { - Q_UNUSED ( parent ); - if ( row < 0 || row >= m_instances.size() ) + Q_UNUSED(parent); + if (row < 0 || row >= m_instances.size()) return QModelIndex(); - return createIndex ( row, column, ( void* ) m_instances.at ( row ).data() ); + return createIndex(row, column, (void *)m_instances.at(row).get()); } -QVariant InstanceList::data ( const QModelIndex& index, int role ) const +QVariant InstanceList::data(const QModelIndex &index, int role) const { - if ( !index.isValid() ) + if (!index.isValid()) { return QVariant(); } - BaseInstance *pdata = static_cast ( index.internalPointer() ); - switch ( role ) + BaseInstance *pdata = static_cast(index.internalPointer()); + switch (role) { case InstancePointerRole: { - QVariant v = qVariantFromValue((void *) pdata); + QVariant v = qVariantFromValue((void *)pdata); return v; } case Qt::DisplayRole: @@ -96,12 +96,12 @@ QVariant InstanceList::data ( const QModelIndex& index, int role ) const return QVariant(); } -Qt::ItemFlags InstanceList::flags ( const QModelIndex& index ) const +Qt::ItemFlags InstanceList::flags(const QModelIndex &index) const { Qt::ItemFlags f; - if ( index.isValid() ) + if (index.isValid()) { - f |= ( Qt::ItemIsEnabled | Qt::ItemIsSelectable ); + f |= (Qt::ItemIsEnabled | Qt::ItemIsSelectable); } return f; } @@ -116,23 +116,23 @@ void InstanceList::saveGroupList() { QString groupFileName = m_instDir + "/instgroups.json"; QFile groupFile(groupFileName); - + // if you can't open the file, fail - if (!groupFile.open(QIODevice::WriteOnly| QIODevice::Truncate)) + if (!groupFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) { // An error occurred. Ignore it. - qDebug("Failed to read instance group file."); + QLOG_ERROR() << "Failed to read instance group file."; return; } QTextStream out(&groupFile); - QMap > groupMap; - for(auto instance: m_instances) + QMap> groupMap; + for (auto instance : m_instances) { QString id = instance->id(); QString group = instance->group(); - if(group.isEmpty()) + if (group.isEmpty()) continue; - if(!groupMap.count(group)) + if (!groupMap.count(group)) { QSet set; set.insert(id); @@ -145,109 +145,114 @@ void InstanceList::saveGroupList() } } QJsonObject toplevel; - toplevel.insert("formatVersion",QJsonValue(QString("1"))); + toplevel.insert("formatVersion", QJsonValue(QString("1"))); QJsonObject groupsArr; - for(auto iter = groupMap.begin(); iter != groupMap.end(); iter++) + for (auto iter = groupMap.begin(); iter != groupMap.end(); iter++) { auto list = iter.value(); auto name = iter.key(); QJsonObject groupObj; QJsonArray instanceArr; - groupObj.insert("hidden",QJsonValue(QString("false"))); - for(auto item: list) + groupObj.insert("hidden", QJsonValue(QString("false"))); + for (auto item : list) { instanceArr.append(QJsonValue(item)); } - groupObj.insert("instances",instanceArr); - groupsArr.insert(name,groupObj); + groupObj.insert("instances", instanceArr); + groupsArr.insert(name, groupObj); } - toplevel.insert("groups",groupsArr); + toplevel.insert("groups", groupsArr); QJsonDocument doc(toplevel); groupFile.write(doc.toJson()); groupFile.close(); } -void InstanceList::loadGroupList(QMap & groupMap) +void InstanceList::loadGroupList(QMap &groupMap) { QString groupFileName = m_instDir + "/instgroups.json"; - + // if there's no group file, fail - if(!QFileInfo(groupFileName).exists()) + if (!QFileInfo(groupFileName).exists()) return; - + QFile groupFile(groupFileName); - + // if you can't open the file, fail if (!groupFile.open(QIODevice::ReadOnly)) { // An error occurred. Ignore it. - qDebug("Failed to read instance group file."); + QLOG_ERROR() << "Failed to read instance group file."; return; } - + QTextStream in(&groupFile); QString jsonStr = in.readAll(); groupFile.close(); - + QJsonParseError error; QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonStr.toUtf8(), &error); - + // if the json was bad, fail if (error.error != QJsonParseError::NoError) { - qWarning(QString("Failed to parse instance group file: %1 at offset %2"). - arg(error.errorString(), QString::number(error.offset)).toUtf8()); + QLOG_ERROR() << QString("Failed to parse instance group file: %1 at offset %2") + .arg(error.errorString(), QString::number(error.offset)) + .toUtf8(); return; } - + // if the root of the json wasn't an object, fail if (!jsonDoc.isObject()) { qWarning("Invalid group file. Root entry should be an object."); return; } - + QJsonObject rootObj = jsonDoc.object(); - + // Make sure the format version matches, otherwise fail. if (rootObj.value("formatVersion").toVariant().toInt() != GROUP_FILE_FORMAT_VERSION) return; - + // Get the groups. if it's not an object, fail if (!rootObj.value("groups").isObject()) { qWarning("Invalid group list JSON: 'groups' should be an object."); return; } - + // Iterate through all the groups. QJsonObject groupMapping = rootObj.value("groups").toObject(); for (QJsonObject::iterator iter = groupMapping.begin(); iter != groupMapping.end(); iter++) { QString groupName = iter.key(); - + // If not an object, complain and skip to the next one. if (!iter.value().isObject()) { qWarning(QString("Group '%1' in the group list should " - "be an object.").arg(groupName).toUtf8()); + "be an object.") + .arg(groupName) + .toUtf8()); continue; } - + QJsonObject groupObj = iter.value().toObject(); if (!groupObj.value("instances").isArray()) { qWarning(QString("Group '%1' in the group list is invalid. " - "It should contain an array " - "called 'instances'.").arg(groupName).toUtf8()); + "It should contain an array " + "called 'instances'.") + .arg(groupName) + .toUtf8()); continue; } - + // Iterate through the list of instances in the group. QJsonArray instancesArray = groupObj.value("instances").toArray(); - - for (QJsonArray::iterator iter2 = instancesArray.begin(); - iter2 != instancesArray.end(); iter2++) + + for (QJsonArray::iterator iter2 = instancesArray.begin(); iter2 != instancesArray.end(); + iter2++) { groupMap[(*iter2).toString()] = groupName; } @@ -259,9 +264,9 @@ InstanceList::InstListError InstanceList::loadList() // load the instance groups QMap groupMap; loadGroupList(groupMap); - + beginResetModel(); - + m_instances.clear(); QDir dir(m_instDir); QDirIterator iter(dir); @@ -270,53 +275,55 @@ InstanceList::InstListError InstanceList::loadList() QString subDir = iter.next(); if (!QFileInfo(PathCombine(subDir, "instance.cfg")).exists()) continue; - + BaseInstance *instPtr = NULL; auto &loader = InstanceFactory::get(); auto error = loader.loadInstance(instPtr, subDir); - - switch(error) + + switch (error) { - case InstanceFactory::NoLoadError: - break; - case InstanceFactory::NotAnInstance: - break; + case InstanceFactory::NoLoadError: + break; + case InstanceFactory::NotAnInstance: + break; } - - if (error != InstanceFactory::NoLoadError && - error != InstanceFactory::NotAnInstance) + + if (error != InstanceFactory::NoLoadError && error != InstanceFactory::NotAnInstance) { - QString errorMsg = QString("Failed to load instance %1: "). - arg(QFileInfo(subDir).baseName()).toUtf8(); - + QString errorMsg = QString("Failed to load instance %1: ") + .arg(QFileInfo(subDir).baseName()) + .toUtf8(); + switch (error) { default: - errorMsg += QString("Unknown instance loader error %1"). - arg(error); + errorMsg += QString("Unknown instance loader error %1").arg(error); break; } - qDebug(errorMsg.toUtf8()); + QLOG_ERROR() << errorMsg.toUtf8(); } else if (!instPtr) { - qDebug(QString("Error loading instance %1. Instance loader returned null."). - arg(QFileInfo(subDir).baseName()).toUtf8()); + QLOG_ERROR() << QString("Error loading instance %1. Instance loader returned null.") + .arg(QFileInfo(subDir).baseName()) + .toUtf8(); } else { - QSharedPointer inst(instPtr); + std::shared_ptr inst(instPtr); auto iter = groupMap.find(inst->id()); - if(iter != groupMap.end()) + if (iter != groupMap.end()) { inst->setGroupInitial((*iter)); } - qDebug(QString("Loaded instance %1").arg(inst->name()).toUtf8()); + QLOG_INFO() << QString("Loaded instance %1").arg(inst->name()).toUtf8(); inst->setParent(this); m_instances.append(inst); - connect(instPtr, SIGNAL(propertiesChanged(BaseInstance*)),this, SLOT(propertiesChanged(BaseInstance*))); - connect(instPtr, SIGNAL(groupChanged()),this, SLOT(groupChanged())); - connect(instPtr, SIGNAL(nuked(BaseInstance*)), this, SLOT(instanceNuked(BaseInstance*))); + connect(instPtr, SIGNAL(propertiesChanged(BaseInstance *)), this, + SLOT(propertiesChanged(BaseInstance *))); + connect(instPtr, SIGNAL(groupChanged()), this, SLOT(groupChanged())); + connect(instPtr, SIGNAL(nuked(BaseInstance *)), this, + SLOT(instanceNuked(BaseInstance *))); } } endResetModel(); @@ -332,7 +339,8 @@ void InstanceList::clear() m_instances.clear(); endResetModel(); emit dataIsInvalid(); -}; +} +; /// Add an instance. Triggers notifications, returns the new index int InstanceList::add(InstancePtr t) @@ -340,9 +348,10 @@ int InstanceList::add(InstancePtr t) beginInsertRows(QModelIndex(), m_instances.size(), m_instances.size()); m_instances.append(t); t->setParent(this); - connect(t.data(), SIGNAL(propertiesChanged(BaseInstance*)),this, SLOT(propertiesChanged(BaseInstance*))); - connect(t.data(), SIGNAL(groupChanged()),this, SLOT(groupChanged())); - connect(t.data(), SIGNAL(nuked(BaseInstance*)), this, SLOT(instanceNuked(BaseInstance*))); + connect(t.get(), SIGNAL(propertiesChanged(BaseInstance *)), this, + SLOT(propertiesChanged(BaseInstance *))); + connect(t.get(), SIGNAL(groupChanged()), this, SLOT(groupChanged())); + connect(t.get(), SIGNAL(nuked(BaseInstance *)), this, SLOT(instanceNuked(BaseInstance *))); endInsertRows(); return count() - 1; } @@ -351,7 +360,7 @@ InstancePtr InstanceList::getInstanceById(QString instId) { QListIterator iter(m_instances); InstancePtr inst; - while(iter.hasNext()) + while (iter.hasNext()) { inst = iter.next(); if (inst->id() == instId) @@ -363,11 +372,11 @@ InstancePtr InstanceList::getInstanceById(QString instId) return iter.peekPrevious(); } -int InstanceList::getInstIndex ( BaseInstance* inst ) +int InstanceList::getInstIndex(BaseInstance *inst) { - for(int i = 0; i < m_instances.count(); i++) + for (int i = 0; i < m_instances.count(); i++) { - if(inst == m_instances[i].data()) + if (inst == m_instances[i].get()) { return i; } @@ -375,40 +384,39 @@ int InstanceList::getInstIndex ( BaseInstance* inst ) return -1; } - -void InstanceList::instanceNuked ( BaseInstance* inst ) +void InstanceList::instanceNuked(BaseInstance *inst) { int i = getInstIndex(inst); - if(i != -1) + if (i != -1) { - beginRemoveRows(QModelIndex(),i,i); + beginRemoveRows(QModelIndex(), i, i); m_instances.removeAt(i); endRemoveRows(); } } - -void InstanceList::propertiesChanged(BaseInstance * inst) +void InstanceList::propertiesChanged(BaseInstance *inst) { int i = getInstIndex(inst); - if(i != -1) + if (i != -1) { emit dataChanged(index(i), index(i)); } } -InstanceProxyModel::InstanceProxyModel ( QObject *parent ) - : KCategorizedSortFilterProxyModel ( parent ) +InstanceProxyModel::InstanceProxyModel(QObject *parent) + : KCategorizedSortFilterProxyModel(parent) { // disable since by default we are globally sorting by date: setCategorizedModel(true); } -bool InstanceProxyModel::subSortLessThan (const QModelIndex& left, const QModelIndex& right ) const +bool InstanceProxyModel::subSortLessThan(const QModelIndex &left, + const QModelIndex &right) const { - BaseInstance *pdataLeft = static_cast ( left.internalPointer() ); - BaseInstance *pdataRight = static_cast ( right.internalPointer() ); - //kDebug() << *pdataLeft << *pdataRight; + BaseInstance *pdataLeft = static_cast(left.internalPointer()); + BaseInstance *pdataRight = static_cast(right.internalPointer()); + // kDebug() << *pdataLeft << *pdataRight; return QString::localeAwareCompare(pdataLeft->name(), pdataRight->name()) < 0; - //return pdataLeft->name() < pdataRight->name(); + // return pdataLeft->name() < pdataRight->name(); } diff --git a/logic/lists/LwjglVersionList.cpp b/logic/lists/LwjglVersionList.cpp index b3e2dab4..6bf401ec 100644 --- a/logic/lists/LwjglVersionList.cpp +++ b/logic/lists/LwjglVersionList.cpp @@ -3,7 +3,7 @@ * 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 @@ -17,15 +17,14 @@ #include "MultiMC.h" #include - #include - #include +#include + #define RSS_URL "http://sourceforge.net/api/file/index/project-id/58488/mtime/desc/rss" -LWJGLVersionList::LWJGLVersionList(QObject *parent) : - QAbstractListModel(parent) +LWJGLVersionList::LWJGLVersionList(QObject *parent) : QAbstractListModel(parent) { setLoading(false); } @@ -34,20 +33,20 @@ QVariant LWJGLVersionList::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); - + if (index.row() > count()) return QVariant(); - + const PtrLWJGLVersion version = at(index.row()); - + switch (role) { case Qt::DisplayRole: return version->name(); - + case Qt::ToolTipRole: return version->url(); - + default: return QVariant(); } @@ -59,10 +58,10 @@ QVariant LWJGLVersionList::headerData(int section, Qt::Orientation orientation, { case Qt::DisplayRole: return "Version"; - + case Qt::ToolTipRole: return "LWJGL version name."; - + default: return QVariant(); } @@ -81,7 +80,7 @@ bool LWJGLVersionList::isLoading() const void LWJGLVersionList::loadList() { Q_ASSERT_X(!m_loading, "loadList", "list is already loading (m_loading is true)"); - + setLoading(true); auto worker = MMC->qnam(); reply = worker->get(QNetworkRequest(QUrl(RSS_URL))); @@ -102,68 +101,68 @@ void LWJGLVersionList::netRequestComplete() if (reply->error() == QNetworkReply::NoError) { QRegExp lwjglRegex("lwjgl-(([0-9]\\.?)+)\\.zip"); - Q_ASSERT_X(lwjglRegex.isValid(), "load LWJGL list", - "LWJGL regex is invalid"); - + Q_ASSERT_X(lwjglRegex.isValid(), "load LWJGL list", "LWJGL regex is invalid"); + QDomDocument doc; - + QString xmlErrorMsg; int errorLine; if (!doc.setContent(reply->readAll(), false, &xmlErrorMsg, &errorLine)) { - failed("Failed to load LWJGL list. XML error: " + xmlErrorMsg + " at line " + QString::number(errorLine)); + failed("Failed to load LWJGL list. XML error: " + xmlErrorMsg + " at line " + + QString::number(errorLine)); setLoading(false); return; } - + QDomNodeList items = doc.elementsByTagName("item"); - + QList tempList; - + for (int i = 0; i < items.length(); i++) { Q_ASSERT_X(items.at(i).isElement(), "load LWJGL list", "XML element isn't an element... wat?"); - + QDomElement linkElement = getDomElementByTagName(items.at(i).toElement(), "link"); if (linkElement.isNull()) { qWarning() << "Link element" << i << "in RSS feed doesn't exist! Skipping."; continue; } - + QString link = linkElement.text(); - + // Make sure it's a download link. if (link.endsWith("/download") && link.contains(lwjglRegex)) { QString name = link.mid(lwjglRegex.indexIn(link) + 6); // Subtract 4 here to remove the .zip file extension. name = name.left(lwjglRegex.matchedLength() - 10); - + QUrl url(link); if (!url.isValid()) { qWarning() << "LWJGL version URL isn't valid:" << link << "Skipping."; continue; } - + tempList.append(LWJGLVersion::Create(name, link)); } } - + beginResetModel(); m_vlist.swap(tempList); endResetModel(); - - qDebug("Loaded LWJGL list."); + + QLOG_INFO() << "Loaded LWJGL list."; finished(); } else { failed("Failed to load LWJGL list. Network error: " + reply->errorString()); } - + setLoading(false); reply->deleteLater(); } @@ -173,13 +172,12 @@ const PtrLWJGLVersion LWJGLVersionList::getVersion(const QString &versionName) for (int i = 0; i < count(); i++) { QString name = at(i)->name(); - if ( name == versionName) + if (name == versionName) return at(i); } return PtrLWJGLVersion(); } - void LWJGLVersionList::failed(QString msg) { qWarning() << msg; diff --git a/logic/lists/LwjglVersionList.h b/logic/lists/LwjglVersionList.h index 23e92a1a..99712292 100644 --- a/logic/lists/LwjglVersionList.h +++ b/logic/lists/LwjglVersionList.h @@ -17,13 +17,13 @@ #include #include -#include #include - #include +#include + class LWJGLVersion; -typedef QSharedPointer PtrLWJGLVersion; +typedef std::shared_ptr PtrLWJGLVersion; class LWJGLVersion : public QObject { diff --git a/logic/lists/MinecraftVersionList.cpp b/logic/lists/MinecraftVersionList.cpp index 35f7251e..36611165 100644 --- a/logic/lists/MinecraftVersionList.cpp +++ b/logic/lists/MinecraftVersionList.cpp @@ -16,8 +16,6 @@ #include "MinecraftVersionList.h" #include -#include - #include #include @@ -62,8 +60,8 @@ int MinecraftVersionList::count() const bool cmpVersions(BaseVersionPtr first, BaseVersionPtr second) { - auto left = first.dynamicCast(); - auto right = second.dynamicCast(); + auto left = std::dynamic_pointer_cast(first); + auto right = std::dynamic_pointer_cast(second); return left->timestamp > right->timestamp; } @@ -78,7 +76,7 @@ BaseVersionPtr MinecraftVersionList::getLatestStable() const { for (int i = 0; i < m_vlist.length(); i++) { - auto ver = m_vlist.at(i).dynamicCast(); + auto ver =std::dynamic_pointer_cast(m_vlist.at(i)); if (ver->is_latest && !ver->is_snapshot) { return m_vlist.at(i); @@ -272,7 +270,7 @@ void MCVListLoadTask::list_downloaded() QString dlUrl = QString(MCVLIST_URLBASE) + versionID + "/"; // Now, we construct the version object and add it to the list. - QSharedPointer mcVersion(new MinecraftVersion()); + std::shared_ptr mcVersion(new MinecraftVersion()); mcVersion->m_name = mcVersion->m_descriptor = versionID; mcVersion->timestamp = versionTime.toMSecsSinceEpoch(); mcVersion->download_url = dlUrl; diff --git a/logic/net/ByteArrayDownload.cpp b/logic/net/ByteArrayDownload.cpp index b7a68c60..ba771eef 100644 --- a/logic/net/ByteArrayDownload.cpp +++ b/logic/net/ByteArrayDownload.cpp @@ -1,6 +1,6 @@ #include "ByteArrayDownload.h" #include "MultiMC.h" -#include +#include ByteArrayDownload::ByteArrayDownload(QUrl url) : Download() { @@ -10,13 +10,13 @@ ByteArrayDownload::ByteArrayDownload(QUrl url) : Download() void ByteArrayDownload::start() { - qDebug() << "Downloading " << m_url.toString(); + QLOG_INFO() << "Downloading " << m_url.toString(); QNetworkRequest request(m_url); request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); auto worker = MMC->qnam(); QNetworkReply *rep = worker->get(request); - m_reply = QSharedPointer(rep, &QObject::deleteLater); + m_reply = std::shared_ptr(rep); connect(rep, SIGNAL(downloadProgress(qint64, qint64)), SLOT(downloadProgress(qint64, qint64))); connect(rep, SIGNAL(finished()), SLOT(downloadFinished())); @@ -33,7 +33,8 @@ void ByteArrayDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal void ByteArrayDownload::downloadError(QNetworkReply::NetworkError error) { // error happened during download. - qDebug() << "URL:" << m_url.toString().toLocal8Bit() << "Network error: " << error; + QLOG_ERROR() << "Error getting URL:" << m_url.toString().toLocal8Bit() + << "Network error: " << error; m_status = Job_Failed; } @@ -45,14 +46,14 @@ void ByteArrayDownload::downloadFinished() // nothing went wrong... m_status = Job_Finished; m_data = m_reply->readAll(); - m_reply.clear(); + m_reply.reset(); emit succeeded(index_within_job); return; } // else the download failed else { - m_reply.clear(); + m_reply.reset(); emit failed(index_within_job); return; } diff --git a/logic/net/ByteArrayDownload.h b/logic/net/ByteArrayDownload.h index 428b21db..cfc6a8d0 100644 --- a/logic/net/ByteArrayDownload.h +++ b/logic/net/ByteArrayDownload.h @@ -21,4 +21,4 @@ protected slots: void downloadReadyRead(); }; -typedef QSharedPointer ByteArrayDownloadPtr; +typedef std::shared_ptr ByteArrayDownloadPtr; diff --git a/logic/net/CacheDownload.cpp b/logic/net/CacheDownload.cpp index 9fc1f127..0e653e05 100644 --- a/logic/net/CacheDownload.cpp +++ b/logic/net/CacheDownload.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include CacheDownload::CacheDownload(QUrl url, MetaEntryPtr entry) : Download(), md5sum(QCryptographicHash::Md5) @@ -31,7 +31,7 @@ void CacheDownload::start() emit failed(index_within_job); return; } - qDebug() << "Downloading " << m_url.toString(); + QLOG_INFO() << "Downloading " << m_url.toString(); QNetworkRequest request(m_url); request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->etag.toLatin1()); request.setHeader(QNetworkRequest::UserAgentHeader,"MultiMC/5.0 (Cached)"); @@ -39,7 +39,7 @@ void CacheDownload::start() auto worker = MMC->qnam(); QNetworkReply *rep = worker->get(request); - m_reply = QSharedPointer(rep, &QObject::deleteLater); + m_reply = std::shared_ptr(rep); connect(rep, SIGNAL(downloadProgress(qint64, qint64)), SLOT(downloadProgress(qint64, qint64))); connect(rep, SIGNAL(finished()), SLOT(downloadFinished())); @@ -92,7 +92,7 @@ void CacheDownload::downloadFinished() m_entry->stale = false; MMC->metacache()->updateEntry(m_entry); - m_reply.clear(); + m_reply.reset(); emit succeeded(index_within_job); return; } @@ -101,7 +101,7 @@ void CacheDownload::downloadFinished() { m_output_file.close(); m_output_file.remove(); - m_reply.clear(); + m_reply.reset(); emit failed(index_within_job); return; } diff --git a/logic/net/CacheDownload.h b/logic/net/CacheDownload.h index f95dabd5..295391b1 100644 --- a/logic/net/CacheDownload.h +++ b/logic/net/CacheDownload.h @@ -31,4 +31,4 @@ public slots: virtual void start(); }; -typedef QSharedPointer CacheDownloadPtr; +typedef std::shared_ptr CacheDownloadPtr; diff --git a/logic/net/Download.h b/logic/net/Download.h index 91f09dec..ca4bee9f 100644 --- a/logic/net/Download.h +++ b/logic/net/Download.h @@ -2,10 +2,9 @@ #include #include -#include +#include #include - enum JobStatus { Job_NotStarted, @@ -18,20 +17,21 @@ class Download : public QObject { Q_OBJECT protected: - explicit Download(): QObject(0){}; + explicit Download() : QObject(0) {}; + public: virtual ~Download() {}; public: /// the network reply - QSharedPointer m_reply; - + std::shared_ptr m_reply; + /// source URL QUrl m_url; - + /// The file's status JobStatus m_status; - + /// index within the parent job int index_within_job = 0; @@ -46,9 +46,9 @@ protected slots: virtual void downloadError(QNetworkReply::NetworkError error) = 0; virtual void downloadFinished() = 0; virtual void downloadReadyRead() = 0; - + public slots: virtual void start() = 0; }; -typedef QSharedPointer DownloadPtr; +typedef std::shared_ptr DownloadPtr; diff --git a/logic/net/DownloadJob.cpp b/logic/net/DownloadJob.cpp index 03a69555..f6275b7a 100644 --- a/logic/net/DownloadJob.cpp +++ b/logic/net/DownloadJob.cpp @@ -5,7 +5,7 @@ #include "ByteArrayDownload.h" #include "CacheDownload.h" -#include +#include ByteArrayDownloadPtr DownloadJob::addByteArrayDownload(QUrl url) { @@ -54,18 +54,18 @@ void DownloadJob::partSucceeded(int index) partProgress(index, slot.total_progress, slot.total_progress); num_succeeded++; - qDebug() << m_job_name.toLocal8Bit() << " progress: " << num_succeeded << "/" + QLOG_INFO() << m_job_name.toLocal8Bit() << " progress: " << num_succeeded << "/" << downloads.size(); if (num_failed + num_succeeded == downloads.size()) { if (num_failed) { - qDebug() << m_job_name.toLocal8Bit() << " failed."; + QLOG_ERROR() << m_job_name.toLocal8Bit() << " failed."; emit failed(); } else { - qDebug() << m_job_name.toLocal8Bit() << " succeeded."; + QLOG_INFO() << m_job_name.toLocal8Bit() << " succeeded."; emit succeeded(); } } @@ -76,17 +76,17 @@ void DownloadJob::partFailed(int index) auto &slot = parts_progress[index]; if (slot.failures == 3) { - qDebug() << "Part " << index << " failed 3 times (" << downloads[index]->m_url << ")"; + QLOG_ERROR() << "Part " << index << " failed 3 times (" << downloads[index]->m_url << ")"; num_failed++; if (num_failed + num_succeeded == downloads.size()) { - qDebug() << m_job_name.toLocal8Bit() << " failed."; + QLOG_ERROR() << m_job_name.toLocal8Bit() << " failed."; emit failed(); } } else { - qDebug() << "Part " << index << " failed, restarting (" << downloads[index]->m_url + QLOG_ERROR() << "Part " << index << " failed, restarting (" << downloads[index]->m_url << ")"; // restart the job slot.failures++; @@ -110,12 +110,12 @@ void DownloadJob::partProgress(int index, qint64 bytesReceived, qint64 bytesTota void DownloadJob::start() { - qDebug() << m_job_name.toLocal8Bit() << " started."; + QLOG_INFO() << m_job_name.toLocal8Bit() << " started."; for (auto iter : downloads) { - connect(iter.data(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int))); - connect(iter.data(), SIGNAL(failed(int)), SLOT(partFailed(int))); - connect(iter.data(), SIGNAL(progress(int, qint64, qint64)), + connect(iter.get(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int))); + connect(iter.get(), SIGNAL(failed(int)), SLOT(partFailed(int))); + connect(iter.get(), SIGNAL(progress(int, qint64, qint64)), SLOT(partProgress(int, qint64, qint64))); iter->start(); } diff --git a/logic/net/DownloadJob.h b/logic/net/DownloadJob.h index 8c32950a..91b014ad 100644 --- a/logic/net/DownloadJob.h +++ b/logic/net/DownloadJob.h @@ -9,7 +9,7 @@ #include "logic/tasks/ProgressProvider.h" class DownloadJob; -typedef QSharedPointer DownloadJobPtr; +typedef std::shared_ptr DownloadJobPtr; /** * A single file for the downloader/cache to process. diff --git a/logic/net/FileDownload.cpp b/logic/net/FileDownload.cpp index 353fd58b..3f38b0fa 100644 --- a/logic/net/FileDownload.cpp +++ b/logic/net/FileDownload.cpp @@ -2,7 +2,7 @@ #include "FileDownload.h" #include #include -#include +#include FileDownload::FileDownload ( QUrl url, QString target_path ) @@ -28,7 +28,7 @@ void FileDownload::start() // skip this file if they match if ( m_check_md5 && hash == m_expected_md5 ) { - qDebug() << "Skipping " << m_url.toString() << ": md5 match."; + QLOG_INFO() << "Skipping " << m_url.toString() << ": md5 match."; emit succeeded(index_within_job); return; } @@ -43,7 +43,7 @@ void FileDownload::start() return; } - qDebug() << "Downloading " << m_url.toString(); + QLOG_INFO() << "Downloading " << m_url.toString(); QNetworkRequest request ( m_url ); request.setRawHeader(QString("If-None-Match").toLatin1(), m_expected_md5.toLatin1()); request.setHeader(QNetworkRequest::UserAgentHeader,"MultiMC/5.0 (Uncached)"); @@ -51,7 +51,7 @@ void FileDownload::start() auto worker = MMC->qnam(); QNetworkReply * rep = worker->get ( request ); - m_reply = QSharedPointer ( rep, &QObject::deleteLater ); + m_reply = std::shared_ptr ( rep ); connect ( rep, SIGNAL ( downloadProgress ( qint64,qint64 ) ), SLOT ( downloadProgress ( qint64,qint64 ) ) ); connect ( rep, SIGNAL ( finished() ), SLOT ( downloadFinished() ) ); connect ( rep, SIGNAL ( error ( QNetworkReply::NetworkError ) ), SLOT ( downloadError ( QNetworkReply::NetworkError ) ) ); @@ -79,7 +79,7 @@ void FileDownload::downloadFinished() m_status = Job_Finished; m_output_file.close(); - m_reply.clear(); + m_reply.reset(); emit succeeded(index_within_job); return; } @@ -87,7 +87,7 @@ void FileDownload::downloadFinished() else { m_output_file.close(); - m_reply.clear(); + m_reply.reset(); emit failed(index_within_job); return; } diff --git a/logic/net/FileDownload.h b/logic/net/FileDownload.h index 190bee58..9abb590d 100644 --- a/logic/net/FileDownload.h +++ b/logic/net/FileDownload.h @@ -32,4 +32,4 @@ public slots: virtual void start(); }; -typedef QSharedPointer FileDownloadPtr; +typedef std::shared_ptr FileDownloadPtr; diff --git a/logic/net/ForgeXzDownload.cpp b/logic/net/ForgeXzDownload.cpp index 6d66abce..3ec2155b 100644 --- a/logic/net/ForgeXzDownload.cpp +++ b/logic/net/ForgeXzDownload.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include ForgeXzDownload::ForgeXzDownload(QUrl url, MetaEntryPtr entry) : Download() @@ -32,7 +32,7 @@ void ForgeXzDownload::start() emit failed(index_within_job); return; } - qDebug() << "Downloading " << m_url.toString(); + QLOG_INFO() << "Downloading " << m_url.toString(); QNetworkRequest request(m_url); request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->etag.toLatin1()); request.setHeader(QNetworkRequest::UserAgentHeader,"MultiMC/5.0 (Cached)"); @@ -40,7 +40,7 @@ void ForgeXzDownload::start() auto worker = MMC->qnam(); QNetworkReply *rep = worker->get(request); - m_reply = QSharedPointer(rep, &QObject::deleteLater); + m_reply = std::shared_ptr(rep); connect(rep, SIGNAL(downloadProgress(qint64, qint64)), SLOT(downloadProgress(qint64, qint64))); connect(rep, SIGNAL(finished()), SLOT(downloadFinished())); @@ -78,7 +78,7 @@ void ForgeXzDownload::downloadFinished() { // something bad happened m_pack200_xz_file.remove(); - m_reply.clear(); + m_reply.reset(); emit failed(index_within_job); return; } @@ -88,7 +88,7 @@ void ForgeXzDownload::downloadFinished() { m_pack200_xz_file.close(); m_pack200_xz_file.remove(); - m_reply.clear(); + m_reply.reset(); emit failed(index_within_job); return; } @@ -198,38 +198,38 @@ void ForgeXzDownload::decompressAndInstall() break; case XZ_MEM_ERROR: - qDebug() << "Memory allocation failed\n"; + QLOG_ERROR() << "Memory allocation failed\n"; xz_dec_end(s); emit failed(index_within_job); return; case XZ_MEMLIMIT_ERROR: - qDebug() << "Memory usage limit reached\n"; + QLOG_ERROR() << "Memory usage limit reached\n"; xz_dec_end(s); emit failed(index_within_job); return; case XZ_FORMAT_ERROR: - qDebug() << "Not a .xz file\n"; + QLOG_ERROR() << "Not a .xz file\n"; xz_dec_end(s); emit failed(index_within_job); return; case XZ_OPTIONS_ERROR: - qDebug() << "Unsupported options in the .xz headers\n"; + QLOG_ERROR() << "Unsupported options in the .xz headers\n"; xz_dec_end(s); emit failed(index_within_job); return; case XZ_DATA_ERROR: case XZ_BUF_ERROR: - qDebug() << "File is corrupt\n"; + QLOG_ERROR() << "File is corrupt\n"; xz_dec_end(s); emit failed(index_within_job); return; default: - qDebug() << "Bug!\n"; + QLOG_ERROR() << "Bug!\n"; xz_dec_end(s); emit failed(index_within_job); return; @@ -246,7 +246,7 @@ void ForgeXzDownload::decompressAndInstall() } catch(std::runtime_error & err) { - qDebug() << "Error unpacking " << pack_name.toUtf8() << " : " << err.what(); + QLOG_ERROR() << "Error unpacking " << pack_name.toUtf8() << " : " << err.what(); QFile f(m_target_path); if(f.exists()) f.remove(); @@ -274,6 +274,6 @@ void ForgeXzDownload::decompressAndInstall() m_entry->stale = false; MMC->metacache()->updateEntry(m_entry); - m_reply.clear(); + m_reply.reset(); emit succeeded(index_within_job); } diff --git a/logic/net/ForgeXzDownload.h b/logic/net/ForgeXzDownload.h index 8cb47783..5d677947 100644 --- a/logic/net/ForgeXzDownload.h +++ b/logic/net/ForgeXzDownload.h @@ -32,4 +32,4 @@ private: void decompressAndInstall(); }; -typedef QSharedPointer ForgeXzDownloadPtr; +typedef std::shared_ptr ForgeXzDownloadPtr; diff --git a/logic/net/HttpMetaCache.cpp b/logic/net/HttpMetaCache.cpp index 46801ab3..9c642a0f 100644 --- a/logic/net/HttpMetaCache.cpp +++ b/logic/net/HttpMetaCache.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include @@ -105,12 +105,12 @@ bool HttpMetaCache::updateEntry ( MetaEntryPtr stale_entry ) { if(!m_entries.contains(stale_entry->base)) { - qDebug() << "Cannot add entry with unknown base: " << stale_entry->base.toLocal8Bit(); + QLOG_ERROR() << "Cannot add entry with unknown base: " << stale_entry->base.toLocal8Bit(); return false; } if(stale_entry->stale) { - qDebug() << "Cannot add stale entry: " << stale_entry->getFullPath().toLocal8Bit(); + QLOG_ERROR() << "Cannot add stale entry: " << stale_entry->getFullPath().toLocal8Bit(); return false; } m_entries[stale_entry->base].entry_list[stale_entry->path] = stale_entry; diff --git a/logic/net/HttpMetaCache.h b/logic/net/HttpMetaCache.h index daf6c43f..8107839e 100644 --- a/logic/net/HttpMetaCache.h +++ b/logic/net/HttpMetaCache.h @@ -15,7 +15,7 @@ struct MetaEntry QString getFullPath(); }; -typedef QSharedPointer MetaEntryPtr; +typedef std::shared_ptr MetaEntryPtr; class HttpMetaCache : public QObject { diff --git a/logic/net/LoginTask.cpp b/logic/net/LoginTask.cpp index 2a45400e..5de8efa9 100644 --- a/logic/net/LoginTask.cpp +++ b/logic/net/LoginTask.cpp @@ -40,7 +40,7 @@ void LoginTask::legacyLogin() { setStatus(tr("Logging in...")); auto worker = MMC->qnam(); - connect(worker.data(), SIGNAL(finished(QNetworkReply *)), this, + connect(worker.get(), SIGNAL(finished(QNetworkReply *)), this, SLOT(processLegacyReply(QNetworkReply *))); QUrl loginURL("https://login.minecraft.net/"); @@ -134,7 +134,7 @@ void LoginTask::yggdrasilLogin() { setStatus(tr("Logging in...")); auto worker = MMC->qnam(); - connect(worker.data(), SIGNAL(finished(QNetworkReply *)), this, + connect(worker.get(), SIGNAL(finished(QNetworkReply *)), this, SLOT(processYggdrasilReply(QNetworkReply *))); /* diff --git a/logic/tasks/Task.cpp b/logic/tasks/Task.cpp index c75bcb8f..2f137c55 100644 --- a/logic/tasks/Task.cpp +++ b/logic/tasks/Task.cpp @@ -14,6 +14,7 @@ */ #include "Task.h" +#include Task::Task(QObject *parent) : ProgressProvider(parent) @@ -55,6 +56,7 @@ void Task::start() void Task::emitFailed(QString reason) { m_running = false; + QLOG_ERROR() << "Task failed: " << reason; emit failed(reason); } -- cgit From 73f8bc5c92cb4a9b7ce507309001c6b206b5c8eb Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Thu, 10 Oct 2013 01:47:48 +0200 Subject: Version changing removes any existing version json. --- gui/MCModInfoFrame.ui | 14 +------ gui/mainwindow.cpp | 9 +++++ logic/BaseInstance.h | 98 +++++++++++++++++++++++++----------------------- logic/LegacyInstance.h | 52 ++++++++++++++----------- logic/LegacyUpdate.cpp | 4 +- logic/OneSixInstance.cpp | 11 +++++- logic/OneSixInstance.h | 39 +++++++++---------- 7 files changed, 124 insertions(+), 103 deletions(-) (limited to 'logic/LegacyUpdate.cpp') diff --git a/gui/MCModInfoFrame.ui b/gui/MCModInfoFrame.ui index b24251ae..60e0a65c 100644 --- a/gui/MCModInfoFrame.ui +++ b/gui/MCModInfoFrame.ui @@ -7,7 +7,7 @@ 0 0 527 - 68 + 113 @@ -28,12 +28,6 @@ - - - 0 - 0 - - Select a mod to view title and authors... @@ -53,12 +47,6 @@ - - - 0 - 0 - - Select a mod to view description... diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 5784b85a..c726591d 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -606,6 +606,15 @@ void MainWindow::on_actionChangeInstMCVersion_triggered() vselect.setFilter(1, "OneSix"); if (vselect.exec() && vselect.selectedVersion()) { + if (m_selectedInstance->versionIsCustom()) + { + auto result = QMessageBox::warning( + this, tr("Are you sure?"), + tr("This will remove any library/version customization you did previously. " + "This includes things like Forge install and similar."), QMessageBox::Ok, QMessageBox::Abort); + if(result != QMessageBox::Ok) + return; + } m_selectedInstance->setIntendedVersionId(vselect.selectedVersion()->descriptor()); } } diff --git a/logic/BaseInstance.h b/logic/BaseInstance.h index e360d3ae..b083c24a 100644 --- a/logic/BaseInstance.h +++ b/logic/BaseInstance.h @@ -3,7 +3,7 @@ * 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 @@ -33,9 +33,9 @@ class BaseInstancePrivate; /*! * \brief Base class for instances. - * This class implements many functions that are common between instances and + * This class implements many functions that are common between instances and * provides a standard interface for all instances. - * + * * To create a new instance type, create a new class inheriting from this class * and implement the pure virtual functions. */ @@ -44,66 +44,72 @@ class BaseInstance : public QObject Q_OBJECT protected: /// no-touchy! - BaseInstance(BaseInstancePrivate * d, const QString &rootDir, SettingsObject * settings, QObject *parent = 0); + BaseInstance(BaseInstancePrivate *d, const QString &rootDir, SettingsObject *settings, + QObject *parent = 0); + public: /// virtual destructor to make sure the destruction is COMPLETE virtual ~BaseInstance() {}; - - /// nuke thoroughly - deletes the instance contents, notifies the list/model which is responsible of cleaning up the husk + + /// nuke thoroughly - deletes the instance contents, notifies the list/model which is + /// responsible of cleaning up the husk void nuke(); - - /// The instance's ID. The ID SHALL be determined by MMC internally. The ID IS guaranteed to be unique. + + /// The instance's ID. The ID SHALL be determined by MMC internally. The ID IS guaranteed to + /// be unique. QString id() const; - + /// get the type of this instance QString instanceType() const; - + /// Path to the instance's root directory. QString instanceRoot() const; - + /// Path to the instance's minecraft directory. QString minecraftRoot() const; - + QString name() const; void setName(QString val); - + QString iconKey() const; void setIconKey(QString val); - + QString notes() const; void setNotes(QString val); - + QString group() const; void setGroupInitial(QString val); void setGroupPost(QString val); - - + virtual QString intendedVersionId() const = 0; virtual bool setIntendedVersionId(QString version) = 0; - + + virtual bool versionIsCustom() = 0; + /*! * The instance's current version. - * This value represents the instance's current version. If this value is + * This value represents the instance's current version. If this value is * different from the intendedVersion, the instance should be updated. * \warning Don't change this value unless you know what you're doing. */ virtual QString currentVersionId() const = 0; - //virtual void setCurrentVersionId(QString val) = 0; - + // virtual void setCurrentVersionId(QString val) = 0; + /*! * Whether or not Minecraft should be downloaded when the instance is launched. */ virtual bool shouldUpdate() const = 0; virtual void setShouldUpdate(bool val) = 0; - /// Get the curent base jar of this instance. By default, it's the versions/$version/$version.jar + /// Get the curent base jar of this instance. By default, it's the + /// versions/$version/$version.jar QString baseJar() const; /// the default base jar of this instance virtual QString defaultBaseJar() const = 0; /// the default custom base jar of this instance virtual QString defaultCustomBaseJar() const = 0; - + /*! * Whether or not custom base jar is used */ @@ -114,7 +120,7 @@ public: */ QString customBaseJar() const; void setCustomBaseJar(QString val); - + /** * Gets the time that the instance was last launched. * Stored in milliseconds since epoch. @@ -122,53 +128,54 @@ public: qint64 lastLaunch() const; /// Sets the last launched time to 'val' milliseconds since epoch void setLastLaunch(qint64 val = QDateTime::currentMSecsSinceEpoch()); - + /*! - * \brief Gets the instance list that this instance is a part of. - * Returns NULL if this instance is not in a list + * \brief Gets the instance list that this instance is a part of. + * Returns NULL if this instance is not in a list * (the parent is not an InstanceList). - * \return A pointer to the InstanceList containing this instance. + * \return A pointer to the InstanceList containing this instance. */ InstanceList *instList() const; - + /*! * \brief Gets a pointer to this instance's version list. * \return A pointer to the available version list for this instance. */ virtual std::shared_ptr versionList() const; - + /*! * \brief Gets this instance's settings object. * This settings object stores instance-specific settings. * \return A pointer to this instance's settings object. */ virtual SettingsObject &settings() const; - + /// returns a valid update task if update is needed, NULL otherwise - virtual BaseUpdate* doUpdate() = 0; - + virtual BaseUpdate *doUpdate() = 0; + /// returns a valid minecraft process, ready for launch - virtual MinecraftProcess* prepareForLaunch(LoginResponse response) = 0; - - /// do any necessary cleanups after the instance finishes. also runs before 'prepareForLaunch' + virtual MinecraftProcess *prepareForLaunch(LoginResponse response) = 0; + + /// do any necessary cleanups after the instance finishes. also runs before + /// 'prepareForLaunch' virtual void cleanupAfterRun() = 0; - + /// create a mod edit dialog for the instance - virtual QDialog * createModEditDialog ( QWidget* parent ) = 0; - + virtual QDialog *createModEditDialog(QWidget *parent) = 0; + /// is a particular action enabled with this instance selected? virtual bool menuActionEnabled(QString action_name) const = 0; - + virtual QString getStatusbarDescription() = 0; - + /// FIXME: this really should be elsewhere... virtual QString instanceConfigFolder() const = 0; - + signals: /*! * \brief Signal emitted when properties relevant to the instance view change */ - void propertiesChanged(BaseInstance * inst); + void propertiesChanged(BaseInstance *inst); /*! * \brief Signal emitted when groups are affected in any way */ @@ -176,12 +183,11 @@ signals: /*! * \brief The instance just got nuked. Hurray! */ - void nuked(BaseInstance * inst); - + void nuked(BaseInstance *inst); + protected: std::shared_ptr inst_d; }; // pointer for lazy people typedef std::shared_ptr InstancePtr; - diff --git a/logic/LegacyInstance.h b/logic/LegacyInstance.h index d7438cca..8bf334f6 100644 --- a/logic/LegacyInstance.h +++ b/logic/LegacyInstance.h @@ -9,21 +9,22 @@ class LegacyInstance : public BaseInstance { Q_OBJECT public: - - explicit LegacyInstance(const QString &rootDir, SettingsObject * settings, QObject *parent = 0); - + + explicit LegacyInstance(const QString &rootDir, SettingsObject *settings, + QObject *parent = 0); + /// Path to the instance's minecraft.jar QString runnableJar() const; - + //! Path to the instance's modlist file. QString modListFile() const; - + ////// Mod Lists ////// std::shared_ptr jarModList(); std::shared_ptr coreModList(); std::shared_ptr loaderModList(); std::shared_ptr texturePackList(); - + ////// Directories ////// QString savesDir() const; QString texturePacksDir() const; @@ -33,40 +34,47 @@ public: QString coreModsDir() const; QString resourceDir() const; virtual QString instanceConfigFolder() const; - + /*! * Whether or not the instance's minecraft.jar needs to be rebuilt. - * If this is true, when the instance launches, its jar mods will be + * If this is true, when the instance launches, its jar mods will be * re-added to a fresh minecraft.jar file. */ bool shouldRebuild() const; void setShouldRebuild(bool val); - + virtual QString currentVersionId() const; virtual void setCurrentVersionId(QString val); - + //! The version of LWJGL that this instance uses. QString lwjglVersion() const; /// st the version of LWJGL libs this instance will use void setLWJGLVersion(QString val); - + virtual QString intendedVersionId() const; - virtual bool setIntendedVersionId ( QString version ); - + virtual bool setIntendedVersionId(QString version); + // the `version' of Legacy instances is defined by the launcher code. + // in contrast with OneSix, where `version' is described in a json file + virtual bool versionIsCustom() override + { + return false; + }; + virtual bool shouldUpdate() const; virtual void setShouldUpdate(bool val); - virtual BaseUpdate* doUpdate(); - - virtual MinecraftProcess* prepareForLaunch(LoginResponse response); + virtual BaseUpdate *doUpdate(); + + virtual MinecraftProcess *prepareForLaunch(LoginResponse response); virtual void cleanupAfterRun(); - virtual QDialog * createModEditDialog ( QWidget* parent ); - + virtual QDialog *createModEditDialog(QWidget *parent); + virtual QString defaultBaseJar() const; virtual QString defaultCustomBaseJar() const; - - bool menuActionEnabled ( QString action_name ) const; + + bool menuActionEnabled(QString action_name) const; virtual QString getStatusbarDescription(); - -protected slots: + +protected +slots: virtual void jarModsChanged(); }; \ No newline at end of file diff --git a/logic/LegacyUpdate.cpp b/logic/LegacyUpdate.cpp index 5f5a2e52..66b4bf8a 100644 --- a/logic/LegacyUpdate.cpp +++ b/logic/LegacyUpdate.cpp @@ -57,7 +57,7 @@ void LegacyUpdate::lwjglStart() auto worker = MMC->qnam(); QNetworkRequest req(realUrl); req.setRawHeader("Host", hostname.toLatin1()); - req.setHeader(QNetworkRequest::UserAgentHeader, "Wget/1.14 (linux-gnu)"); + req.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)"); QNetworkReply *rep = worker->get(req); m_reply = std::shared_ptr(rep); @@ -100,7 +100,7 @@ void LegacyUpdate::lwjglFinished(QNetworkReply *reply) QString hostname = realUrl.host(); QNetworkRequest req(redirectedTo); req.setRawHeader("Host", hostname.toLatin1()); - req.setHeader(QNetworkRequest::UserAgentHeader, "Wget/1.14 (linux-gnu)"); + req.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)"); QNetworkReply *rep = worker->get(req); connect(rep, SIGNAL(downloadProgress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index ad3f9f58..1b7b5bb4 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -192,6 +192,11 @@ bool OneSixInstance::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; } @@ -271,7 +276,11 @@ bool OneSixInstance::reloadFullVersion() d->version = version; return true; } - return false; + else + { + d->version.reset(); + return false; + } } std::shared_ptr OneSixInstance::getFullVersion() diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h index 8f5c22e6..d2276afc 100644 --- a/logic/OneSixInstance.h +++ b/logic/OneSixInstance.h @@ -10,33 +10,33 @@ class OneSixInstance : public BaseInstance { Q_OBJECT public: - explicit OneSixInstance(const QString &rootDir, SettingsObject * settings, QObject *parent = 0); - - + explicit OneSixInstance(const QString &rootDir, SettingsObject *settings, + QObject *parent = 0); + ////// Mod Lists ////// std::shared_ptr loaderModList(); std::shared_ptr resourcePackList(); - + ////// Directories ////// QString resourcePacksDir() const; QString loaderModsDir() const; virtual QString instanceConfigFolder() const; - - virtual BaseUpdate* doUpdate(); - virtual MinecraftProcess* prepareForLaunch ( LoginResponse response ); + + virtual BaseUpdate *doUpdate(); + virtual MinecraftProcess *prepareForLaunch(LoginResponse response); virtual void cleanupAfterRun(); - + virtual QString intendedVersionId() const; - virtual bool setIntendedVersionId ( QString version ); - + virtual bool setIntendedVersionId(QString version); + virtual QString currentVersionId() const; // virtual void setCurrentVersionId ( QString val ) {}; - + virtual bool shouldUpdate() const; virtual void setShouldUpdate(bool val); - - virtual QDialog * createModEditDialog ( QWidget* parent ); - + + virtual QDialog *createModEditDialog(QWidget *parent); + /// reload the full version json file. return true on success! bool reloadFullVersion(); /// get the current full version info @@ -46,13 +46,14 @@ public: /// customize the current base version bool customizeVersion(); /// is the current version original, or custom? - bool versionIsCustom(); - + virtual bool versionIsCustom() override; + virtual QString defaultBaseJar() const; virtual QString defaultCustomBaseJar() const; - - virtual bool menuActionEnabled ( QString action_name ) const; + + virtual bool menuActionEnabled(QString action_name) const; virtual QString getStatusbarDescription(); + private: - QStringList processMinecraftArgs( LoginResponse response ); + QStringList processMinecraftArgs(LoginResponse response); }; \ No newline at end of file -- cgit