diff options
| author | Petr Mrázek <peterix@gmail.com> | 2014-09-06 18:16:56 +0200 |
|---|---|---|
| committer | Petr Mrázek <peterix@gmail.com> | 2014-09-06 19:03:05 +0200 |
| commit | 20cb97a35af5097e9d3b2062c0dfcb5f2e5fff5c (patch) | |
| tree | 56bf51e681f2e73590a549499bd83d7b505c39f8 | |
| parent | 36efcf8d3c0cbd7823fc65569cfc2b011435db2c (diff) | |
| download | PrismLauncher-20cb97a35af5097e9d3b2062c0dfcb5f2e5fff5c.tar.gz PrismLauncher-20cb97a35af5097e9d3b2062c0dfcb5f2e5fff5c.tar.bz2 PrismLauncher-20cb97a35af5097e9d3b2062c0dfcb5f2e5fff5c.zip | |
Sync from quickmods
57 files changed, 569 insertions, 326 deletions
diff --git a/MultiMC.cpp b/MultiMC.cpp index 94be69f8..d33fb5db 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -251,12 +251,12 @@ MultiMC::MultiMC(int &argc, char **argv, bool root_override) : QApplication(argc std::shared_ptr<BaseProfilerFactory>(new JVisualVMFactory())); for (auto profiler : m_profilers.values()) { - profiler->registerSettings(m_settings.get()); + profiler->registerSettings(m_settings); } m_tools.insert("mcedit", std::shared_ptr<BaseDetachedToolFactory>(new MCEditFactory())); for (auto tool : m_tools.values()) { - tool->registerSettings(m_settings.get()); + tool->registerSettings(m_settings); } // launch instance, if that's what should be done diff --git a/depends/util/include/modutils.h b/depends/util/include/modutils.h index e04db66f..1fecd4d5 100644 --- a/depends/util/include/modutils.h +++ b/depends/util/include/modutils.h @@ -1,6 +1,8 @@ #pragma once #include <QString> +#include <QList> + #include "libutil_config.h" class QUrl; @@ -10,10 +12,12 @@ namespace Util struct Version { Version(const QString &str); + Version() {} bool operator<(const Version &other) const; bool operator<=(const Version &other) const; bool operator>(const Version &other) const; + bool operator>=(const Version &other) const; bool operator==(const Version &other) const; bool operator!=(const Version &other) const; @@ -24,9 +28,34 @@ struct Version private: QString m_string; + struct Section + { + explicit Section(const QString &str, const int num) : numValid(true), number(num), string(str) {} + explicit Section(const QString &str) : numValid(false), string(str) {} + explicit Section() {} + bool numValid; + int number; + QString string; + + inline bool operator!=(const Section &other) const + { + return (numValid && other.numValid) ? (number != other.number) : (string != other.string); + } + inline bool operator<(const Section &other) const + { + return (numValid && other.numValid) ? (number < other.number) : (string < other.string); + } + inline bool operator>(const Section &other) const + { + return (numValid && other.numValid) ? (number > other.number) : (string > other.string); + } + }; + QList<Section> m_sections; + + void parse(); }; -LIBUTIL_EXPORT QUrl expandQMURL(const QString &in); LIBUTIL_EXPORT bool versionIsInInterval(const QString &version, const QString &interval); +LIBUTIL_EXPORT bool versionIsInInterval(const Version &version, const QString &interval); } diff --git a/depends/util/src/modutils.cpp b/depends/util/src/modutils.cpp index 44a04b72..67c09dec 100644 --- a/depends/util/src/modutils.cpp +++ b/depends/util/src/modutils.cpp @@ -7,42 +7,20 @@ Util::Version::Version(const QString &str) : m_string(str) { + parse(); } bool Util::Version::operator<(const Version &other) const { - QStringList parts1 = m_string.split('.'); - QStringList parts2 = other.m_string.split('.'); - - while (!parts1.isEmpty() && !parts2.isEmpty()) + const int size = qMax(m_sections.size(), other.m_sections.size()); + for (int i = 0; i < size; ++i) { - QString part1 = parts1.isEmpty() ? "0" : parts1.takeFirst(); - QString part2 = parts2.isEmpty() ? "0" : parts2.takeFirst(); - bool ok1 = false; - bool ok2 = false; - int int1 = part1.toInt(&ok1); - int int2 = part2.toInt(&ok2); - if (ok1 && ok2) - { - if (int1 == int2) - { - continue; - } - else - { - return int1 < int2; - } - } - else + const Section sec1 = (i >= m_sections.size()) ? Section("0", 0) : m_sections.at(i); + const Section sec2 = + (i >= other.m_sections.size()) ? Section("0", 0) : other.m_sections.at(i); + if (sec1 != sec2) { - if (part1 == part2) - { - continue; - } - else - { - return part1 < part2; - } + return sec1 < sec2; } } @@ -54,77 +32,35 @@ bool Util::Version::operator<=(const Util::Version &other) const } bool Util::Version::operator>(const Version &other) const { - QStringList parts1 = m_string.split('.'); - QStringList parts2 = other.m_string.split('.'); - - while (!parts1.isEmpty() && !parts2.isEmpty()) + const int size = qMax(m_sections.size(), other.m_sections.size()); + for (int i = 0; i < size; ++i) { - QString part1 = parts1.isEmpty() ? "0" : parts1.takeFirst(); - QString part2 = parts2.isEmpty() ? "0" : parts2.takeFirst(); - bool ok1 = false; - bool ok2 = false; - int int1 = part1.toInt(&ok1); - int int2 = part2.toInt(&ok2); - if (ok1 && ok2) + const Section sec1 = (i >= m_sections.size()) ? Section("0", 0) : m_sections.at(i); + const Section sec2 = + (i >= other.m_sections.size()) ? Section("0", 0) : other.m_sections.at(i); + if (sec1 != sec2) { - if (int1 == int2) - { - continue; - } - else - { - return int1 > int2; - } - } - else - { - if (part1 == part2) - { - continue; - } - else - { - return part1 > part2; - } + return sec1 > sec2; } } return false; } +bool Util::Version::operator>=(const Version &other) const +{ + return *this > other || *this == other; +} bool Util::Version::operator==(const Version &other) const { - QStringList parts1 = m_string.split('.'); - QStringList parts2 = other.m_string.split('.'); - - while (!parts1.isEmpty() && !parts2.isEmpty()) + const int size = qMax(m_sections.size(), other.m_sections.size()); + for (int i = 0; i < size; ++i) { - QString part1 = parts1.isEmpty() ? "0" : parts1.takeFirst(); - QString part2 = parts2.isEmpty() ? "0" : parts2.takeFirst(); - bool ok1 = false; - bool ok2 = false; - int int1 = part1.toInt(&ok1); - int int2 = part2.toInt(&ok2); - if (ok1 && ok2) + const Section sec1 = (i >= m_sections.size()) ? Section("0", 0) : m_sections.at(i); + const Section sec2 = + (i >= other.m_sections.size()) ? Section("0", 0) : other.m_sections.at(i); + if (sec1 != sec2) { - if (int1 == int2) - { - continue; - } - else - { - return false; - } - } - else - { - if (part1 == part2) - { - continue; - } - else - { - return false; - } + return false; } } @@ -135,45 +71,41 @@ bool Util::Version::operator!=(const Version &other) const return !operator==(other); } -QUrl Util::expandQMURL(const QString &in) +void Util::Version::parse() { - QUrl inUrl(in); - if (inUrl.scheme() == "github") - { - // needed because QUrl makes the host all lower cases - const QString repo = in.mid(in.indexOf(inUrl.host(), 0, Qt::CaseInsensitive), inUrl.host().size()); - QUrl out; - out.setScheme("https"); - out.setHost("raw.github.com"); - out.setPath(QString("/%1/%2/%3%4") - .arg(inUrl.userInfo(), repo, - inUrl.fragment().isEmpty() ? "master" : inUrl.fragment(), inUrl.path())); - return out; - } - else if (inUrl.scheme() == "mcf") - { - QUrl out; - out.setScheme("http"); - out.setHost("www.minecraftforum.net"); - out.setPath(QString("/topic/%1-").arg(inUrl.path())); - return out; - } - else + m_sections.clear(); + + QStringList parts = m_string.split('.'); + + for (const auto part : parts) { - return in; + bool ok = false; + int num = part.toInt(&ok); + if (ok) + { + m_sections.append(Section(part, num)); + } + else + { + m_sections.append(Section(part)); + } } } bool Util::versionIsInInterval(const QString &version, const QString &interval) { - if (interval.isEmpty() || version == interval) + return versionIsInInterval(Util::Version(version), interval); +} +bool Util::versionIsInInterval(const Version &version, const QString &interval) +{ + if (interval.isEmpty() || version.toString() == interval) { return true; } // Interval notation is used QRegularExpression exp( - "(?<start>[\\[\\]\\(\\)])(?<bottom>.*?)(,(?<top>.*?))?(?<end>[\\[\\]\\(\\)])"); + "(?<start>[\\[\\]\\(\\)])(?<bottom>.*?)(,(?<top>.*?))?(?<end>[\\[\\]\\(\\)]),?"); QRegularExpressionMatch match = exp.match(interval); if (match.hasMatch()) { @@ -185,11 +117,12 @@ bool Util::versionIsInInterval(const QString &version, const QString &interval) // check if in range (bottom) if (!bottom.isEmpty()) { - if ((start == '[') && !(version >= bottom)) + const auto bottomVersion = Util::Version(bottom); + if ((start == '[') && !(version >= bottomVersion)) { return false; } - else if ((start == '(') && !(version > bottom)) + else if ((start == '(') && !(version > bottomVersion)) { return false; } @@ -198,11 +131,12 @@ bool Util::versionIsInInterval(const QString &version, const QString &interval) // check if in range (top) if (!top.isEmpty()) { - if ((end == ']') && !(version <= top)) + const auto topVersion = Util::Version(top); + if ((end == ']') && !(version <= topVersion)) { return false; } - else if ((end == ')') && !(version < top)) + else if ((end == ')') && !(version < topVersion)) { return false; } diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index d3dc8f6e..a5bffcc4 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -65,9 +65,9 @@ #include "gui/pages/global/MultiMCPage.h" #include "gui/pages/global/ExternalToolsPage.h" #include "gui/pages/global/AccountListPage.h" -#include "pages/global/ProxyPage.h" -#include "pages/global/JavaPage.h" -#include "pages/global/MinecraftPage.h" +#include "gui/pages/global/ProxyPage.h" +#include "gui/pages/global/JavaPage.h" +#include "gui/pages/global/MinecraftPage.h" #include "gui/ConsoleWindow.h" #include "pagedialog/PageDialog.h" @@ -91,6 +91,7 @@ #include "logic/net/NetJob.h" #include "logic/BaseInstance.h" +#include "logic/OneSixInstance.h" #include "logic/InstanceFactory.h" #include "logic/MinecraftProcess.h" #include "logic/OneSixUpdate.h" diff --git a/gui/MainWindow.ui b/gui/MainWindow.ui index 03a07ce5..a3edf6bd 100644 --- a/gui/MainWindow.ui +++ b/gui/MainWindow.ui @@ -387,7 +387,7 @@ </action> <action name="actionEditInstance"> <property name="text"> - <string>Edit Mods</string> + <string>Edit Instance</string> </property> <property name="iconText"> <string>Edit Instance</string> diff --git a/gui/dialogs/ModEditDialogCommon.cpp b/gui/dialogs/ModEditDialogCommon.cpp index 35942374..4a2115d8 100644 --- a/gui/dialogs/ModEditDialogCommon.cpp +++ b/gui/dialogs/ModEditDialogCommon.cpp @@ -4,7 +4,7 @@ bool lastfirst(QModelIndexList &list, int &first, int &last) { - if (!list.size()) + if (list.isEmpty()) return false; first = last = list[0].row(); for (auto item : list) @@ -37,4 +37,4 @@ void showWebsiteForMod(QWidget *parentDlg, Mod &m) QObject::tr("The mod author didn't provide a website link for this mod."), QMessageBox::Warning); } -}
\ No newline at end of file +} diff --git a/gui/dialogs/NewInstanceDialog.cpp b/gui/dialogs/NewInstanceDialog.cpp index 41ae329c..80cbbeb2 100644 --- a/gui/dialogs/NewInstanceDialog.cpp +++ b/gui/dialogs/NewInstanceDialog.cpp @@ -38,15 +38,6 @@ NewInstanceDialog::NewInstanceDialog(QWidget *parent) ui->setupUi(this); resize(minimumSizeHint()); layout()->setSizeConstraint(QLayout::SetFixedSize); - /* - if (!MinecraftVersionList::getMainList().isLoaded()) - { - TaskDialog *taskDlg = new TaskDialog(this); - Task *loadTask = MinecraftVersionList::getMainList().getLoadTask(); - loadTask->setParent(taskDlg); - taskDlg->exec(loadTask); - } - */ setSelectedVersion(MMC->minecraftlist()->getLatestStable(), true); InstIconKey = "infinity"; ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey)); diff --git a/gui/dialogs/NewInstanceDialog.h b/gui/dialogs/NewInstanceDialog.h index 17045ec0..fa9012ea 100644 --- a/gui/dialogs/NewInstanceDialog.h +++ b/gui/dialogs/NewInstanceDialog.h @@ -16,6 +16,7 @@ #pragma once #include <QDialog> + #include "logic/BaseVersion.h" namespace Ui diff --git a/gui/groupview/InstanceDelegate.cpp b/gui/groupview/InstanceDelegate.cpp index 3bd77747..e49e1552 100644 --- a/gui/groupview/InstanceDelegate.cpp +++ b/gui/groupview/InstanceDelegate.cpp @@ -113,16 +113,10 @@ void drawProgressOverlay(QPainter *painter, const QStyleOptionViewItemV4 &option void drawBadges(QPainter *painter, const QStyleOptionViewItemV4 &option, BaseInstance *instance) { QList<QString> pixmaps; - for (auto flag : instance->flags()) + const BaseInstance::InstanceFlags flags = instance->flags(); + if (flags & BaseInstance::VersionBrokenFlag) { - switch (flag) - { - case BaseInstance::VersionBrokenFlag: - pixmaps.append("broken"); - break; - default: - break; - } + pixmaps.append("broken"); } // begin easter eggs @@ -160,7 +154,7 @@ void drawBadges(QPainter *painter, const QStyleOptionViewItemV4 &option, BaseIns { return; } - const QPixmap pixmap = ListViewDelegate::requestPixmap(it.next()).scaled( + const QPixmap pixmap = ListViewDelegate::requestBadgePixmap(it.next()).scaled( itemSide, itemSide, Qt::KeepAspectRatio, Qt::FastTransformation); painter->drawPixmap(option.rect.width() - x * itemSide + qMax(x - 1, 0) * spacing - itemSide, y * itemSide + qMax(y - 1, 0) * spacing, itemSide, itemSide, @@ -354,7 +348,7 @@ QSize ListViewDelegate::sizeHint(const QStyleOptionViewItem &option, return sz; } -QPixmap ListViewDelegate::requestPixmap(const QString &key) +QPixmap ListViewDelegate::requestBadgePixmap(const QString &key) { if (!m_pixmapCache.contains(key)) { diff --git a/gui/groupview/InstanceDelegate.h b/gui/groupview/InstanceDelegate.h index 9ab44864..1520cbb8 100644 --- a/gui/groupview/InstanceDelegate.h +++ b/gui/groupview/InstanceDelegate.h @@ -23,7 +23,7 @@ class ListViewDelegate : public QStyledItemDelegate public: explicit ListViewDelegate(QObject *parent = 0); - static QPixmap requestPixmap(const QString &key); + static QPixmap requestBadgePixmap(const QString &key); protected: void paint(QPainter *painter, const QStyleOptionViewItem &option, diff --git a/logic/BaseInstance.cpp b/logic/BaseInstance.cpp index 9a811577..be6ea184 100644 --- a/logic/BaseInstance.cpp +++ b/logic/BaseInstance.cpp @@ -29,6 +29,7 @@ #include <cmdutils.h> #include "logic/minecraft/MinecraftVersionList.h" #include "logic/icons/IconList.h" +#include "logic/InstanceList.h" BaseInstance::BaseInstance(BaseInstancePrivate *d_in, const QString &rootDir, SettingsObject *settings_obj, QObject *parent) @@ -143,10 +144,12 @@ QString BaseInstance::minecraftRoot() const InstanceList *BaseInstance::instList() const { - if (parent()->inherits("InstanceList")) - return (InstanceList *)parent(); - else - return NULL; + return qobject_cast<InstanceList *>(parent()); +} + +InstancePtr BaseInstance::getSharedPtr() +{ + return instList()->getInstanceById(id()); } std::shared_ptr<BaseVersionList> BaseInstance::versionList() const @@ -160,13 +163,12 @@ SettingsObject &BaseInstance::settings() const return *d->m_settings; } -QSet<BaseInstance::InstanceFlag> BaseInstance::flags() const +BaseInstance::InstanceFlags BaseInstance::flags() const { I_D(const BaseInstance); - return QSet<InstanceFlag>(d->m_flags); + return d->m_flags; } - -void BaseInstance::setFlags(const QSet<InstanceFlag> &flags) +void BaseInstance::setFlags(const InstanceFlags &flags) { I_D(BaseInstance); if (flags != d->m_flags) @@ -176,10 +178,24 @@ void BaseInstance::setFlags(const QSet<InstanceFlag> &flags) emit propertiesChanged(this); } } +void BaseInstance::setFlag(const BaseInstance::InstanceFlag flag) +{ + I_D(BaseInstance); + d->m_flags |= flag; + emit flagsChanged(); + emit propertiesChanged(this); +} +void BaseInstance::unsetFlag(const BaseInstance::InstanceFlag flag) +{ + I_D(BaseInstance); + d->m_flags &= ~flag; + emit flagsChanged(); + emit propertiesChanged(this); +} bool BaseInstance::canLaunch() const { - return !flags().contains(VersionBrokenFlag); + return !(flags() & VersionBrokenFlag); } bool BaseInstance::reload() diff --git a/logic/BaseInstance.h b/logic/BaseInstance.h index 0cd17de9..ed5840e2 100644 --- a/logic/BaseInstance.h +++ b/logic/BaseInstance.h @@ -34,6 +34,10 @@ class OneSixUpdate; class InstanceList; class BaseInstancePrivate; +// pointer for lazy people +class BaseInstance; +typedef std::shared_ptr<BaseInstance> InstancePtr; + /*! * \brief Base class for instances. * This class implements many functions that are common between instances and @@ -163,6 +167,8 @@ public: */ InstanceList *instList() const; + InstancePtr getSharedPtr(); + /*! * \brief Gets a pointer to this instance's version list. * \return A pointer to the available version list for this instance. @@ -193,11 +199,14 @@ public: enum InstanceFlag { - NoFlags = 0x00, - VersionBrokenFlag = 0x01 + VersionBrokenFlag = 0x01, + UpdateAvailable = 0x02 }; - QSet<InstanceFlag> flags() const; - void setFlags(const QSet<InstanceFlag> &flags); + Q_DECLARE_FLAGS(InstanceFlags, InstanceFlag) + InstanceFlags flags() const; + void setFlags(const InstanceFlags &flags); + void setFlag(const InstanceFlag flag); + void unsetFlag(const InstanceFlag flag); bool canLaunch() const; @@ -226,7 +235,6 @@ protected: std::shared_ptr<BaseInstancePrivate> inst_d; }; -// pointer for lazy people -typedef std::shared_ptr<BaseInstance> InstancePtr; - +Q_DECLARE_METATYPE(std::shared_ptr<BaseInstance>) Q_DECLARE_METATYPE(BaseInstance::InstanceFlag) +Q_DECLARE_OPERATORS_FOR_FLAGS(BaseInstance::InstanceFlags) diff --git a/logic/BaseInstance_p.h b/logic/BaseInstance_p.h index 77486abc..3d1a4cbe 100644 --- a/logic/BaseInstance_p.h +++ b/logic/BaseInstance_p.h @@ -31,6 +31,6 @@ public: QString m_rootDir; QString m_group; std::shared_ptr<SettingsObject> m_settings; - QSet<BaseInstance::InstanceFlag> m_flags; + BaseInstance::InstanceFlags m_flags; bool m_isRunning = false; }; diff --git a/logic/BaseVersion.h b/logic/BaseVersion.h index ed63f551..04d0a10b 100644 --- a/logic/BaseVersion.h +++ b/logic/BaseVersion.h @@ -24,6 +24,7 @@ */ struct BaseVersion { + virtual ~BaseVersion() {} /*! * A string used to identify this version in config files. * This should be unique within the version list or shenanigans will occur. diff --git a/logic/InstanceFactory.cpp b/logic/InstanceFactory.c |
