From 7c24bcc83476dcbdd7f7acbe14ecef4398962689 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sat, 1 Mar 2014 23:06:47 +0100 Subject: Reorganize the version-related code. --- logic/VersionFinal.cpp | 221 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100644 logic/VersionFinal.cpp (limited to 'logic/VersionFinal.cpp') diff --git a/logic/VersionFinal.cpp b/logic/VersionFinal.cpp new file mode 100644 index 00000000..ce78e8e3 --- /dev/null +++ b/logic/VersionFinal.cpp @@ -0,0 +1,221 @@ +/* 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 "VersionFinal.h" + +#include +#include + +#include "OneSixVersionBuilder.h" + +VersionFinal::VersionFinal(OneSixInstance *instance, QObject *parent) + : QAbstractListModel(parent), m_instance(instance) +{ + clear(); +} + +bool VersionFinal::reload(QWidget *widgetParent, const bool onlyVanilla, const QStringList &external) +{ + beginResetModel(); + bool ret = OneSixVersionBuilder::build(this, m_instance, widgetParent, onlyVanilla, external); + endResetModel(); + return ret; +} + +void VersionFinal::clear() +{ + beginResetModel(); + id.clear(); + time.clear(); + releaseTime.clear(); + type.clear(); + assets.clear(); + processArguments.clear(); + minecraftArguments.clear(); + minimumLauncherVersion = 0xDEADBEAF; + mainClass.clear(); + libraries.clear(); + tweakers.clear(); + versionFiles.clear(); + endResetModel(); +} + +void VersionFinal::dump() const +{ + qDebug().nospace() << "VersionFinal(" + << "\n\tid=" << id + << "\n\ttime=" << time + << "\n\treleaseTime=" << releaseTime + << "\n\ttype=" << type + << "\n\tassets=" << assets + << "\n\tprocessArguments=" << processArguments + << "\n\tminecraftArguments=" << minecraftArguments + << "\n\tminimumLauncherVersion=" << minimumLauncherVersion + << "\n\tmainClass=" << mainClass + << "\n\tlibraries="; + for (auto lib : libraries) + { + qDebug().nospace() << "\n\t\t" << lib.get(); + } + qDebug().nospace() << "\n)"; +} + +bool VersionFinal::canRemove(const int index) const +{ + if (index < versionFiles.size()) + { + return versionFiles.at(index).id != "org.multimc.version.json"; + } + return false; +} + +QString VersionFinal::versionFileId(const int index) const +{ + if (index < 0 || index >= versionFiles.size()) + { + return QString(); + } + return versionFiles.at(index).id; +} + +bool VersionFinal::remove(const int index) +{ + if (canRemove(index)) + { + return QFile::remove(versionFiles.at(index).filename); + } + return false; +} + +QList > VersionFinal::getActiveNormalLibs() +{ + QList > output; + for (auto lib : libraries) + { + if (lib->isActive() && !lib->isNative()) + { + output.append(lib); + } + } + return output; +} + +QList > VersionFinal::getActiveNativeLibs() +{ + QList > output; + for (auto lib : libraries) + { + if (lib->isActive() && lib->isNative()) + { + output.append(lib); + } + } + return output; +} + +std::shared_ptr VersionFinal::fromJson(const QJsonObject &obj) +{ + std::shared_ptr version(new VersionFinal(0)); + if (OneSixVersionBuilder::readJsonAndApplyToVersion(version.get(), obj)) + { + return version; + } + return 0; +} + +QVariant VersionFinal::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + int row = index.row(); + int column = index.column(); + + if (row < 0 || row >= versionFiles.size()) + return QVariant(); + + if (role == Qt::DisplayRole) + { + switch (column) + { + case 0: + return versionFiles.at(row).name; + case 1: + return versionFiles.at(row).version; + default: + return QVariant(); + } + } + return QVariant(); +} + +QVariant VersionFinal::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal) + { + if (role == Qt::DisplayRole) + { + switch (section) + { + case 0: + return tr("Name"); + case 1: + return tr("Version"); + default: + return QVariant(); + } + } + } + return QVariant(); +} + +Qt::ItemFlags VersionFinal::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return Qt::NoItemFlags; + return Qt::ItemIsSelectable | Qt::ItemIsEnabled; +} + +int VersionFinal::rowCount(const QModelIndex &parent) const +{ + return versionFiles.size(); +} + +int VersionFinal::columnCount(const QModelIndex &parent) const +{ + return 2; +} + +QDebug operator<<(QDebug &dbg, const VersionFinal *version) +{ + version->dump(); + return dbg.maybeSpace(); +} +QDebug operator<<(QDebug &dbg, const OneSixLibrary *library) +{ + dbg.nospace() << "OneSixLibrary(" + << "\n\t\t\trawName=" << library->rawName() + << "\n\t\t\tname=" << library->name() + << "\n\t\t\tversion=" << library->version() + << "\n\t\t\ttype=" << library->type() + << "\n\t\t\tisActive=" << library->isActive() + << "\n\t\t\tisNative=" << library->isNative() + << "\n\t\t\tdownloadUrl=" << library->downloadUrl() + << "\n\t\t\tstoragePath=" << library->storagePath() + << "\n\t\t\tabsolutePath=" << library->absoluteUrl() + << "\n\t\t\thint=" << library->hint(); + dbg.nospace() << "\n\t\t)"; + return dbg.maybeSpace(); +} -- cgit From 80d146866c8c5f00c6d790b476a774def71010bf Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 2 Mar 2014 02:17:55 +0100 Subject: Remove widgets from logic. --- logic/VersionFinal.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'logic/VersionFinal.cpp') diff --git a/logic/VersionFinal.cpp b/logic/VersionFinal.cpp index ce78e8e3..3aa95ed7 100644 --- a/logic/VersionFinal.cpp +++ b/logic/VersionFinal.cpp @@ -26,10 +26,10 @@ VersionFinal::VersionFinal(OneSixInstance *instance, QObject *parent) clear(); } -bool VersionFinal::reload(QWidget *widgetParent, const bool onlyVanilla, const QStringList &external) +bool VersionFinal::reload(const bool onlyVanilla, const QStringList &external) { beginResetModel(); - bool ret = OneSixVersionBuilder::build(this, m_instance, widgetParent, onlyVanilla, external); + bool ret = OneSixVersionBuilder::build(this, m_instance, onlyVanilla, external); endResetModel(); return ret; } -- cgit From 29cdc9364b0153d04a211adf3eab86076174c0a1 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Mon, 3 Mar 2014 01:23:10 +0100 Subject: More code butchery related to version files. No end in sight. --- logic/VersionFinal.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'logic/VersionFinal.cpp') diff --git a/logic/VersionFinal.cpp b/logic/VersionFinal.cpp index 3aa95ed7..ec450eda 100644 --- a/logic/VersionFinal.cpp +++ b/logic/VersionFinal.cpp @@ -28,10 +28,10 @@ VersionFinal::VersionFinal(OneSixInstance *instance, QObject *parent) bool VersionFinal::reload(const bool onlyVanilla, const QStringList &external) { + //FIXME: source of epic failure. beginResetModel(); - bool ret = OneSixVersionBuilder::build(this, m_instance, onlyVanilla, external); + OneSixVersionBuilder::build(this, m_instance, onlyVanilla, external); endResetModel(); - return ret; } void VersionFinal::clear() @@ -128,11 +128,15 @@ QList > VersionFinal::getActiveNativeLibs() std::shared_ptr VersionFinal::fromJson(const QJsonObject &obj) { std::shared_ptr version(new VersionFinal(0)); - if (OneSixVersionBuilder::readJsonAndApplyToVersion(version.get(), obj)) + try { - return version; + OneSixVersionBuilder::readJsonAndApplyToVersion(version.get(), obj); } - return 0; + catch(MMCError err) + { + return 0; + } + return version; } QVariant VersionFinal::data(const QModelIndex &index, int role) const -- cgit From 47bc7e5ee377dacfeb7cf3d13f07cfd24db906fb Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Wed, 5 Mar 2014 01:50:05 +0100 Subject: More refactor. --- logic/VersionFinal.cpp | 42 ------------------------------------------ 1 file changed, 42 deletions(-) (limited to 'logic/VersionFinal.cpp') diff --git a/logic/VersionFinal.cpp b/logic/VersionFinal.cpp index ec450eda..8d668014 100644 --- a/logic/VersionFinal.cpp +++ b/logic/VersionFinal.cpp @@ -52,26 +52,6 @@ void VersionFinal::clear() endResetModel(); } -void VersionFinal::dump() const -{ - qDebug().nospace() << "VersionFinal(" - << "\n\tid=" << id - << "\n\ttime=" << time - << "\n\treleaseTime=" << releaseTime - << "\n\ttype=" << type - << "\n\tassets=" << assets - << "\n\tprocessArguments=" << processArguments - << "\n\tminecraftArguments=" << minecraftArguments - << "\n\tminimumLauncherVersion=" << minimumLauncherVersion - << "\n\tmainClass=" << mainClass - << "\n\tlibraries="; - for (auto lib : libraries) - { - qDebug().nospace() << "\n\t\t" << lib.get(); - } - qDebug().nospace() << "\n)"; -} - bool VersionFinal::canRemove(const int index) const { if (index < versionFiles.size()) @@ -201,25 +181,3 @@ int VersionFinal::columnCount(const QModelIndex &parent) const { return 2; } - -QDebug operator<<(QDebug &dbg, const VersionFinal *version) -{ - version->dump(); - return dbg.maybeSpace(); -} -QDebug operator<<(QDebug &dbg, const OneSixLibrary *library) -{ - dbg.nospace() << "OneSixLibrary(" - << "\n\t\t\trawName=" << library->rawName() - << "\n\t\t\tname=" << library->name() - << "\n\t\t\tversion=" << library->version() - << "\n\t\t\ttype=" << library->type() - << "\n\t\t\tisActive=" << library->isActive() - << "\n\t\t\tisNative=" << library->isNative() - << "\n\t\t\tdownloadUrl=" << library->downloadUrl() - << "\n\t\t\tstoragePath=" << library->storagePath() - << "\n\t\t\tabsolutePath=" << library->absoluteUrl() - << "\n\t\t\thint=" << library->hint(); - dbg.nospace() << "\n\t\t)"; - return dbg.maybeSpace(); -} -- cgit From ffff2cd3248a574d3d666731580ac7b8c33e1735 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 9 Mar 2014 17:38:42 +0100 Subject: Remove version patch reordering. Remove the main class display from onesix edit mods. --- logic/VersionFinal.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'logic/VersionFinal.cpp') diff --git a/logic/VersionFinal.cpp b/logic/VersionFinal.cpp index 8d668014..48601d57 100644 --- a/logic/VersionFinal.cpp +++ b/logic/VersionFinal.cpp @@ -56,7 +56,7 @@ bool VersionFinal::canRemove(const int index) const { if (index < versionFiles.size()) { - return versionFiles.at(index).id != "org.multimc.version.json"; + return versionFiles.at(index)->fileId != "org.multimc.version.json"; } return false; } @@ -67,14 +67,14 @@ QString VersionFinal::versionFileId(const int index) const { return QString(); } - return versionFiles.at(index).id; + return versionFiles.at(index)->fileId; } bool VersionFinal::remove(const int index) { if (canRemove(index)) { - return QFile::remove(versionFiles.at(index).filename); + return QFile::remove(versionFiles.at(index)->filename); } return false; } @@ -135,9 +135,9 @@ QVariant VersionFinal::data(const QModelIndex &index, int role) const switch (column) { case 0: - return versionFiles.at(row).name; + return versionFiles.at(row)->name; case 1: - return versionFiles.at(row).version; + return versionFiles.at(row)->version; default: return QVariant(); } -- cgit From b2c803a378695026f12aabc3729eb2139bee1b2c Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 9 Mar 2014 23:42:25 +0100 Subject: Improve reporting of version file errors.x --- logic/VersionFinal.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'logic/VersionFinal.cpp') diff --git a/logic/VersionFinal.cpp b/logic/VersionFinal.cpp index 48601d57..a057ecdd 100644 --- a/logic/VersionFinal.cpp +++ b/logic/VersionFinal.cpp @@ -112,7 +112,7 @@ std::shared_ptr VersionFinal::fromJson(const QJsonObject &obj) { OneSixVersionBuilder::readJsonAndApplyToVersion(version.get(), obj); } - catch(MMCError err) + catch(MMCError & err) { return 0; } -- cgit