summaryrefslogtreecommitdiffstats
path: root/logic
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2014-09-06 18:16:56 +0200
committerPetr Mrázek <peterix@gmail.com>2014-09-06 19:03:05 +0200
commit20cb97a35af5097e9d3b2062c0dfcb5f2e5fff5c (patch)
tree56bf51e681f2e73590a549499bd83d7b505c39f8 /logic
parent36efcf8d3c0cbd7823fc65569cfc2b011435db2c (diff)
downloadMultiMC-20cb97a35af5097e9d3b2062c0dfcb5f2e5fff5c.tar
MultiMC-20cb97a35af5097e9d3b2062c0dfcb5f2e5fff5c.tar.gz
MultiMC-20cb97a35af5097e9d3b2062c0dfcb5f2e5fff5c.tar.lz
MultiMC-20cb97a35af5097e9d3b2062c0dfcb5f2e5fff5c.tar.xz
MultiMC-20cb97a35af5097e9d3b2062c0dfcb5f2e5fff5c.zip
Sync from quickmods
Diffstat (limited to 'logic')
-rw-r--r--logic/BaseInstance.cpp34
-rw-r--r--logic/BaseInstance.h22
-rw-r--r--logic/BaseInstance_p.h2
-rw-r--r--logic/BaseVersion.h1
-rw-r--r--logic/InstanceFactory.cpp18
-rw-r--r--logic/InstanceFactory.h2
-rw-r--r--logic/LegacyFTBInstance.cpp2
-rw-r--r--logic/LegacyInstance.cpp2
-rw-r--r--logic/MMCJson.cpp65
-rw-r--r--logic/MMCJson.h50
-rw-r--r--logic/OneSixFTBInstance.cpp2
-rw-r--r--logic/OneSixInstance.cpp11
-rw-r--r--logic/OneSixInstance.h7
-rw-r--r--logic/forge/ForgeInstaller.h4
-rw-r--r--logic/forge/ForgeVersion.h2
-rw-r--r--logic/java/JavaCheckerJob.h12
-rw-r--r--logic/liteloader/LiteLoaderInstaller.h5
-rw-r--r--logic/liteloader/LiteLoaderVersionList.h2
-rw-r--r--logic/minecraft/InstanceVersion.cpp8
-rw-r--r--logic/minecraft/InstanceVersion.h6
-rw-r--r--logic/minecraft/MinecraftVersionList.cpp13
-rw-r--r--logic/minecraft/OneSixLibrary.h1
-rw-r--r--logic/minecraft/VersionBuilder.cpp5
-rw-r--r--logic/minecraft/VersionFile.cpp10
-rw-r--r--logic/net/ByteArrayDownload.cpp26
-rw-r--r--logic/net/ByteArrayDownload.h4
-rw-r--r--logic/net/CacheDownload.cpp24
-rw-r--r--logic/net/CacheDownload.h2
-rw-r--r--logic/net/NetAction.h3
-rw-r--r--logic/net/NetJob.h20
-rw-r--r--logic/tasks/ProgressProvider.h4
-rw-r--r--logic/tasks/SequentialTask.cpp45
-rw-r--r--logic/tasks/SequentialTask.h5
-rw-r--r--logic/tasks/Task.cpp14
-rw-r--r--logic/tasks/Task.h6
-rw-r--r--logic/tools/BaseExternalTool.h2
-rw-r--r--logic/tools/JProfiler.cpp2
-rw-r--r--logic/tools/JProfiler.h2
-rw-r--r--logic/tools/JVisualVM.cpp2
-rw-r--r--logic/tools/JVisualVM.h2
-rw-r--r--logic/tools/MCEditTool.cpp2
-rw-r--r--logic/tools/MCEditTool.h2
42 files changed, 294 insertions, 159 deletions
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.cpp
index f0f7ffb3..e1cc64df 100644
--- a/logic/InstanceFactory.cpp
+++ b/logic/InstanceFactory.cpp
@@ -52,19 +52,19 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(InstancePtr &inst,
// FIXME: replace with a map lookup, where instance classes register their types
if (inst_type == "OneSix" || inst_type == "Nostalgia")
{
- inst.reset(new OneSixInstance(instDir, m_settings, this));
+ inst.reset(new OneSixInstance(instDir, m_settings));
}
else if (inst_type == "Legacy")
{
- inst.reset(new LegacyInstance(instDir, m_settings, this));
+ inst.reset(new LegacyInstance(instDir, m_settings));
}
else if (inst_type == "LegacyFTB")
{
- inst.reset(new LegacyFTBInstance(instDir, m_settings, this));
+ inst.reset(new LegacyFTBInstance(instDir, m_settings));
}
else if (inst_type == "OneSixFTB")
{
- inst.reset(new OneSixFTBInstance(instDir, m_settings, this));
+ inst.reset(new OneSixFTBInstance(instDir, m_settings));
}
else
{
@@ -82,11 +82,15 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance(InstancePtr &in
QLOG_DEBUG() << instDir.toUtf8();
if (!rootDir.exists() && !rootDir.mkpath("."))
{
+ QLOG_ERROR() << "Can't create instance folder" << instDir;
return InstanceFactory::CantCreateDir;
}
auto mcVer = std::dynamic_pointer_cast<MinecraftVersion>(version);
if (!mcVer)
+ {
+ QLOG_ERROR() << "Can't create instance for non-existing MC version";
return InstanceFactory::NoSuchVersion;
+ }
auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg"));
m_settings->registerSetting("InstanceType", "Legacy");
@@ -94,7 +98,7 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance(InstancePtr &in
if (type == NormalInst)
{
m_settings->set("InstanceType", "OneSix");
- inst.reset(new OneSixInstance(instDir, m_settings, this));
+ inst.reset(new OneSixInstance(instDir, m_settings));
inst->setIntendedVersionId(version->descriptor());
inst->setShouldUseCustomBaseJar(false);
}
@@ -103,14 +107,14 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance(InstancePtr &in
if(mcVer->usesLegacyLauncher())
{
m_settings->set("InstanceType", "LegacyFTB");
- inst.reset(new LegacyFTBInstance(instDir, m_settings, this));
+ inst.reset(new LegacyFTBInstance(instDir, m_settings));
inst->setIntendedVersionId(version->descriptor());
inst->setShouldUseCustomBaseJar(false);
}
else
{
m_settings->set("InstanceType", "OneSixFTB");
- inst.reset(new OneSixFTBInstance(instDir, m_settings, this));
+ inst.reset(new OneSixFTBInstance(instDir, m_settings));
inst->setIntendedVersionId(version->descriptor());
inst->setShouldUseCustomBaseJar(false);
}
diff --git a/logic/InstanceFactory.h b/logic/InstanceFactory.h
index 32a31080..3a4a55a8 100644
--- a/logic/InstanceFactory.h
+++ b/logic/InstanceFactory.h
@@ -26,7 +26,7 @@ struct BaseVersion;
class BaseInstance;
/*!
- * The \bInstanceFactory\b is a singleton that manages loading and creating instances.
+ * The \b InstanceFactory\b is a singleton that manages loading and creating instances.
*/
class InstanceFactory : public QObject
{
diff --git a/logic/LegacyFTBInstance.cpp b/logic/LegacyFTBInstance.cpp
index 73a1f73d..06bef948 100644
--- a/logic/LegacyFTBInstance.cpp
+++ b/logic/LegacyFTBInstance.cpp
@@ -7,7 +7,7 @@ LegacyFTBInstance::LegacyFTBInstance(const QString &rootDir, SettingsObject *set
QString LegacyFTBInstance::getStatusbarDescription()
{
- if (flags().contains(VersionBrokenFlag))
+ if (flags() & VersionBrokenFlag)
{
return "Legacy FTB: " + intendedVersionId() + " (broken)";
}
diff --git a/logic/LegacyInstance.cpp b/logic/LegacyInstance.cpp
index 0239a325..eede7070 100644
--- a/logic/LegacyInstance.cpp
+++ b/logic/LegacyInstance.cpp
@@ -287,7 +287,7 @@ QString LegacyInstance::defaultCustomBaseJar() const
QString LegacyInstance::getStatusbarDescription()
{
- if (flags().contains(VersionBrokenFlag))
+ if (flags() & VersionBrokenFlag)
{
return tr("Legacy : %1 (broken)").arg(intendedVersionId());
}
diff --git a/logic/MMCJson.cpp b/logic/MMCJson.cpp
index 8de88b6b..23af4fff 100644
--- a/logic/MMCJson.cpp
+++ b/logic/MMCJson.cpp
@@ -1,13 +1,26 @@
#include "MMCJson.h"
+
#include <QString>
+#include <QUrl>
#include <QStringList>
#include <math.h>
+QJsonDocument MMCJson::parseDocument(const QByteArray &data, const QString &what)
+{
+ QJsonParseError error;
+ QJsonDocument doc = QJsonDocument::fromJson(data, &error);
+ if (error.error != QJsonParseError::NoError)
+ {
+ throw JSONValidationError(what + " is not valid JSON: " + error.errorString() + " at " + error.offset);
+ }
+ return doc;
+}
+
bool MMCJson::ensureBoolean(const QJsonValue val, const QString what)
{
if (!val.isBool())
throw JSONValidationError(what + " is not boolean");
- return val.isBool();
+ return val.toBool();
}
QJsonValue MMCJson::ensureExists(QJsonValue val, const QString what)
@@ -24,6 +37,15 @@ QJsonArray MMCJson::ensureArray(const QJsonValue val, const QString what)
return val.toArray();
}
+QJsonArray MMCJson::ensureArray(const QJsonDocument &val, const QString &what)
+{
+ if (!val.isArray())
+ {
+ throw JSONValidationError(what + " is not an array");
+ }
+ return val.array();
+}
+
double MMCJson::ensureDouble(const QJsonValue val, const QString what)
{
if (!val.isDouble())
@@ -60,9 +82,36 @@ QString MMCJson::ensureString(const QJsonValue val, const QString what)
return val.toString();
}
+QUrl MMCJson::ensureUrl(const QJsonValue &val, const QString &what)
+{
+ const QUrl url = QUrl(ensureString(val, what));
+ if (!url.isValid())
+ {
+ throw JSONValidationError(what + " is not an url");
+ }
+ return url;
+}
+
+QJsonDocument MMCJson::parseFile(const QString &filename, const QString &what)
+{
+ QFile f(filename);
+ if (!f.open(QFile::ReadOnly))
+ {
+ throw FileOpenError(f);
+ }
+ return parseDocument(f.readAll(), what);
+}
+
+int MMCJson::ensureInteger(const QJsonValue val, QString what, const int def)
+{
+ if (val.isUndefined())
+ return def;
+ return ensureInteger(val, what);
+}
+
void MMCJson::writeString(QJsonObject &to, QString key, QString value)
{
- if(value.size())
+ if (!value.isEmpty())
{
to.insert(key, value);
}
@@ -70,7 +119,7 @@ void MMCJson::writeString(QJsonObject &to, QString key, QString value)
void MMCJson::writeStringList(QJsonObject &to, QString key, QStringList values)
{
- if(values.size())
+ if (!values.isEmpty())
{
QJsonArray array;
for(auto value: values)
@@ -81,3 +130,13 @@ void MMCJson::writeStringList(QJsonObject &to, QString key, QStringList values)
}
}
+QStringList MMCJson::ensureStringList(const QJsonValue val, QString what)
+{
+ const QJsonArray array = ensureArray(val, what);
+ QStringList out;
+ for (const auto value : array)
+ {
+ out.append(ensureString(value));
+ }
+ return out;
+}
diff --git a/logic/MMCJson.h b/logic/MMCJson.h
index 8408f29b..dc0b4224 100644
--- a/logic/MMCJson.h
+++ b/logic/MMCJson.h
@@ -9,17 +9,29 @@
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonArray>
+#include <QFile>
+#include <memory>
#include "MMCError.h"
class JSONValidationError : public MMCError
{
public:
- JSONValidationError(QString cause) : MMCError(cause) {};
- virtual ~JSONValidationError() noexcept {}
+ JSONValidationError(QString cause) : MMCError(cause) {}
+};
+class FileOpenError : public MMCError
+{
+public:
+ FileOpenError(const QFile &file) : MMCError(QObject::tr("Error opening %1: %2").arg(file.fileName(), file.errorString())) {}
};
namespace MMCJson
{
+/// parses the data into a json document. throws if there's a parse error
+QJsonDocument parseDocument(const QByteArray &data, const QString &what);
+
+/// tries to open and then parses the specified file. throws if there's an error
+QJsonDocument parseFile(const QString &filename, const QString &what);
+
/// make sure the value exists. throw otherwise.
QJsonValue ensureExists(QJsonValue val, const QString what = "value");
@@ -27,39 +39,63 @@ QJsonValue ensureExists(QJsonValue val, const QString what = "value");
QJsonObject ensureObject(const QJsonValue val, const QString what = "value");
/// make sure the document is converted into an object. throw otherwise.
-QJsonObject ensureObject(const QJsonDocument val, const QString what = "value");
+QJsonObject ensureObject(const QJsonDocument val, const QString what = "document");
/// make sure the value is converted into an array. throw otherwise.
QJsonArray ensureArray(const QJsonValue val, QString what = "value");
+/// make sure the document is converted into an array. throw otherwise.
+QJsonArray ensureArray(const QJsonDocument &val, const QString &what = "document");
+
/// make sure the value is converted into a string. throw otherwise.
QString ensureString(const QJsonValue val, QString what = "value");
+/// make sure the value is converted into a string that's parseable as an url. throw otherwise.
+QUrl ensureUrl(const QJsonValue &val, const QString &what = "value");
+
/// make sure the value is converted into a boolean. throw otherwise.
bool ensureBoolean(const QJsonValue val, QString what = "value");
/// make sure the value is converted into an integer. throw otherwise.
int ensureInteger(const QJsonValue val, QString what = "value");
+/// make sure the value is converted into an integer. throw otherwise. this version will return the default value if the field is undefined.
+int ensureInteger(const QJsonValue val, QString what, const int def);
+
/// make sure the value is converted into a double precision floating number. throw otherwise.
double ensureDouble(const QJsonValue val, QString what = "value");
+QStringList ensureStringList(const QJsonValue val, QString what);
+
void writeString(QJsonObject & to, QString key, QString value);
-void writeStringList (QJsonObject & to, QString key, QStringList values);
+void writeStringList(QJsonObject & to, QString key, QStringList values);
template <typename T>
-void writeObjectList (QJsonObject & to, QString key, QList<T> values)
+void writeObjectList(QJsonObject & to, QString key, QList<std::shared_ptr<T>> values)
{
- if(values.size())
+ if (!values.isEmpty())
{
QJsonArray array;
- for(auto value: values)
+ for (auto value: values)
{
array.append(value->toJson());
}
to.insert(key, array);
}
}
+template <typename T>
+void writeObjectList(QJsonObject & to, QString key, QList<T> values)
+{
+ if (!values.isEmpty())
+ {
+ QJsonArray array;
+ for (auto value: values)
+ {
+ array.append(value.toJson());
+ }
+ to.insert(key, array);
+ }
+}
}
diff --git a/logic/OneSixFTBInstance.cpp b/logic/OneSixFTBInstance.cpp
index 8dfd3051..903c4437 100644
--- a/logic/OneSixFTBInstance.cpp
+++ b/logic/OneSixFTBInstance.cpp
@@ -118,7 +118,7 @@ bool OneSixFTBInstance::providesVersionFile() const
QString OneSixFTBInstance::getStatusbarDescription()
{
- if (flags().contains(VersionBrokenFlag))
+ if (flags() & VersionBrokenFlag)
{
return "OneSix FTB: " + intendedVersionId() + " (broken)";
}
diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp
index 82d4e480..00d8a9db 100644
--- a/logic/OneSixInstance.cpp
+++ b/logic/OneSixInstance.cpp
@@ -418,7 +418,7 @@ void OneSixInstance::reloadVersion()
try
{
d->version->reload(externalPatches());
- d->m_flags.remove(VersionBrokenFlag);
+ unsetFlag(VersionBrokenFlag);
emit versionReloaded();
}
catch (VersionIncomplete &error)
@@ -427,7 +427,7 @@ void OneSixInstance::reloadVersion()
catch (MMCError &error)
{
d->version->clear();
- d->m_flags.insert(VersionBrokenFlag);
+ setFlag(VersionBrokenFlag);
// TODO: rethrow to show some error message(s)?
emit versionReloaded();
throw;
@@ -464,7 +464,7 @@ QString OneSixInstance::getStatusbarDescription()
{
traits.append(tr("custom"));
}
- if (flags().contains(VersionBrokenFlag))
+ if (flags() & VersionBrokenFlag)
{
traits.append(tr("broken"));
}
@@ -569,3 +569,8 @@ QStringList OneSixInstance::extraArguments() const
}
return list;
}
+
+std::shared_ptr<OneSixInstance> OneSixInstance::getSharedPtr()
+{
+ return std::dynamic_pointer_cast<OneSixInstance>(BaseInstance::getSharedPtr());
+}
diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h
index 75caef1f..f7b01608 100644
--- a/logic/OneSixInstance.h
+++ b/logic/OneSixInstance.h
@@ -96,8 +96,11 @@ public:
virtual bool providesVersionFile() const;
bool reload() override;
+
virtual QStringList extraArguments() const override;
-
+
+ std::shared_ptr<OneSixInstance> getSharedPtr();
+
signals:
void versionReloaded();
@@ -105,3 +108,5 @@ private:
QStringList processMinecraftArgs(AuthSessionPtr account);
QDir reconstructAssets(std::shared_ptr<InstanceVersion> version);
};
+
+Q_DECLARE_METATYPE(std::shared_ptr<OneSixInstance>)
diff --git a/logic/forge/ForgeInstaller.h b/logic/forge/ForgeInstaller.h
index 1c7452d7..655fbc89 100644
--- a/logic/forge/ForgeInstaller.h
+++ b/logic/forge/ForgeInstaller.h
@@ -29,11 +29,11 @@ class ForgeInstaller : public BaseInstaller
friend class ForgeInstallTask;
public:
ForgeInstaller();
- virtual ~ForgeInstaller(){};
+ virtual ~ForgeInstaller(){}
virtual ProgressProvider *createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent) override;
+ virtual QString id() const override { return "net.minecraftforge"; }
protected:
- virtual QString id() const override { return "net.minecraftforge"; }
void prepare(const QString &filename, const QString &universalUrl);
bool add(OneSixInstance *to) override;
bool addLegacy(OneSixInstance *to);
diff --git a/logic/forge/ForgeVersion.h b/logic/forge/ForgeVersion.h
index c7adc572..e3c1aab9 100644
--- a/logic/forge/ForgeVersion.h
+++ b/logic/forge/ForgeVersion.h
@@ -38,3 +38,5 @@ struct ForgeVersion : public BaseVersion
QString installer_filename;
bool is_recommended = false;
};
+
+Q_DECLARE_METATYPE(ForgeVersionPtr)
diff --git a/logic/java/JavaCheckerJob.h b/logic/java/JavaCheckerJob.h
index 132a92d4..4b79611b 100644
--- a/logic/java/JavaCheckerJob.h
+++ b/logic/java/JavaCheckerJob.h
@@ -59,22 +59,10 @@ public:
{
return javacheckers.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();
diff --git a/logic/liteloader/LiteLoaderInstaller.h b/logic/liteloader/LiteLoaderInstaller.h
index 43ad6b83..b3336bbd 100644
--- a/logic/liteloader/LiteLoaderInstaller.h
+++ b/logic/liteloader/LiteLoaderInstaller.h
@@ -28,13 +28,10 @@ public:
void prepare(LiteLoaderVersionPtr version);
bool add(OneSixInstance *to) override;
+ virtual QString id() const override { return "com.mumfrey.liteloader"; }
ProgressProvider *createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent) override;
private:
- virtual QString id() const override
- {
- return "com.mumfrey.liteloader";
- }
LiteLoaderVersionPtr m_version;
};
diff --git a/logic/liteloader/LiteLoaderVersionList.h b/logic/liteloader/LiteLoaderVersionList.h
index 91ed077c..5eecd926 100644
--- a/logic/liteloader/LiteLoaderVersionList.h
+++ b/logic/liteloader/LiteLoaderVersionList.h
@@ -111,3 +111,5 @@ protected:
CacheDownloadPtr listDownload;
LiteLoaderVersionList *m_list;
};
+
+Q_DECLARE_METATYPE(LiteLoaderVersionPtr)
diff --git a/logic/minecraft/InstanceVersion.cpp b/logic/minecraft/InstanceVersion.cpp
index c345e1fb..a243ebf4 100644
--- a/logic/minecraft/InstanceVersion.cpp
+++ b/logic/minecraft/InstanceVersion.cpp
@@ -264,6 +264,14 @@ QList<std::shared_ptr<OneSixLibrary> > InstanceVersion::getActiveNormalLibs()
{
if (lib->isActive() && !lib->isNative())
{
+ for (auto other : output)
+ {
+ if (other->rawName() == lib->rawName())
+ {
+ QLOG_WARN() << "Multiple libraries with name" << lib->rawName() << "in library list!";
+ continue;
+ }
+ }
output.append(lib);
}
}
diff --git a/logic/minecraft/InstanceVersion.h b/logic/minecraft/InstanceVersion.h
index 6b69ab47..664e4242 100644
--- a/logic/minecraft/InstanceVersion.h
+++ b/logic/minecraft/InstanceVersion.h
@@ -140,10 +140,10 @@ public:
QString appletClass;
/// the list of libs - both active and inactive, native and java
- QList<std::shared_ptr<OneSixLibrary>> libraries;
-
+ QList<OneSixLibraryPtr> libraries;
+
/// same, but only vanilla.
- QList<std::shared_ptr<OneSixLibrary>> vanillaLibraries;
+ QList<OneSixLibraryPtr> vanillaLibraries;
/// traits, collected from all the version files (version files can only add)
QSet<QString> traits;
diff --git a/logic/minecraft/MinecraftVersionList.cpp b/logic/minecraft/MinecraftVersionList.cpp
index bde2170b..598fecdb 100644
--- a/logic/minecraft/MinecraftVersionList.cpp
+++ b/logic/minecraft/MinecraftVersionList.cpp
@@ -116,15 +116,10 @@ void MinecraftVersionList::loadBuiltinList()
{
QLOG_INFO() << "Loading builtin version list.";
// grab the version list data from internal resources.
- QResource versionList(":/versions/minecraft.json");
- QFile filez(versionList.absoluteFilePath());
- filez.open(QIODevice::ReadOnly);
- auto data = filez.readAll();
-
- // parse the data as json
- QJsonParseError jsonError;
- QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError);
- QJsonObject root = jsonDoc.object();
+ const QJsonDocument doc =
+ MMCJson::parseFile(":/versions/minecraft.json",
+ "builtin version list");
+ const QJsonObject root = doc.object();
// parse all the versions
for (const auto version : MMCJson::ensureArray(root.value("versions")))
diff --git a/logic/minecraft/OneSixLibrary.h b/logic/minecraft/OneSixLibrary.h
index 2f60405a..1d2ac0cb 100644
--- a/logic/minecraft/OneSixLibrary.h
+++ b/logic/minecraft/OneSixLibrary.h
@@ -48,5 +48,4 @@ public:
/// Constructor
OneSixLibrary(RawLibraryPtr base);
static OneSixLibraryPtr fromRawLibrary(RawLibraryPtr lib);
-
};
diff --git a/logic/minecraft/VersionBuilder.cpp b/logic/minecraft/VersionBuilder.cpp
index dbaf5257..09f761a4 100644
--- a/logic/minecraft/VersionBuilder.cpp
+++ b/logic/minecraft/VersionBuilder.cpp
@@ -288,6 +288,11 @@ static const int currentOrderFileVersion = 1;
bool VersionBuilder::readOverrideOrders(OneSixInstance *instance, PatchOrder &order)
{
QFile orderFile(instance->instanceRoot() + "/order.json");
+ if (!orderFile.exists())
+ {
+ QLOG_WARN() << "Order file doesn't exist. Ignoring.";
+ return false;
+ }
if (!orderFile.open(QFile::ReadOnly))
{
QLOG_ERROR() << "Couldn't open" << orderFile.fileName()
diff --git a/logic/minecraft/VersionFile.cpp b/logic/minecraft/VersionFile.cpp
index 778c5a27..311271fe 100644
--- a/logic/minecraft/VersionFile.cpp
+++ b/logic/minecraft/VersionFile.cpp
@@ -22,8 +22,7 @@ int findLibraryByName(QList<OneSixLibraryPtr> haystack, const GradleSpecifier &n
int retval = -1;
for (int i = 0; i < haystack.size(); ++i)
{
-
- if(haystack.at(i)->rawName().matchName(needle))
+ if (haystack.at(i)->rawName().matchName(needle))
{
// only one is allowed.
if (retval != -1)
@@ -67,7 +66,7 @@ VersionFilePtr VersionFile::fromJson(const QJsonDocument &doc, const QString &fi
out->mcVersion = root.value("mcVersion").toString();
out->filename = filename;
- auto readString = [root](const QString & key, QString & variable)
+ auto readString = [root](const QString &key, QString &variable)
{
if (root.contains(key))
{
@@ -75,15 +74,14 @@ VersionFilePtr VersionFile::fromJson(const QJsonDocument &doc, const QString &fi
}
};
- auto readStringRet = [root](const QString & key)->QString
+ auto readStringRet = [root](const QString &key) -> QString
{
if (root.contains(key))
{
return ensureString(root.value(key));
}
return QString();
- }
- ;
+ };
// FIXME: This should be ignored when applying.
if (!isFTB)
diff --git a/logic/net/ByteArrayDownload.cpp b/logic/net/ByteArrayDownload.cpp
index 27d2a250..a8d1d330 100644
--- a/logic/net/ByteArrayDownload.cpp
+++ b/logic/net/ByteArrayDownload.cpp
@@ -53,16 +53,42 @@ void ByteArrayDownload::downloadError(QNetworkReply::NetworkError error)
QLOG_ERROR() << "Error getting URL:" << m_url.toString().toLocal8Bit()
<< "Network error: " << error;
m_status = Job_Failed;
+ m_errorString = m_reply->errorString();
}
void ByteArrayDownload::downloadFinished()
{
+ if (m_followRedirects)
+ {
+ QVariant redirect = m_reply->header(QNetworkRequest::LocationHeader);
+ QString redirectURL;
+ if(redirect.isValid())
+ {
+ redirectURL = redirect.toString();
+ }
+ // FIXME: This is a hack for https://bugreports.qt-project.org/browse/QTBUG-41061
+ else if(m_reply->hasRawHeader("Location"))
+ {
+ auto data = m_reply->rawHeader("Location");
+ if(data.size() > 2 && data[0] == '/' && data[1] == '/')
+ redirectURL = m_reply->url().scheme() + ":" + data;
+ }
+ if (!redirectURL.isEmpty())
+ {
+ m_url = QUrl(redirect.toString());
+ QLOG_INFO() << "Following redirect to " << m_url.toString();
+ start();
+ return;
+ }
+ }
+
// if the download succeeded
if (m_status != Job_Failed)
{
// nothing went wrong...
m_status = Job_Finished;
m_data = m_reply->readAll();
+ m_content_type = m_reply->header(QNetworkRequest::ContentTypeHeader).toString();
m_reply.reset();
emit succeeded(m_index_within_job);
return;
diff --git a/logic/net/ByteArrayDownload.h b/logic/net/ByteArrayDownload.h
index 76e2e279..85ed2dab 100644
--- a/logic/net/ByteArrayDownload.h
+++ b/logic/net/ByteArrayDownload.h
@@ -31,6 +31,10 @@ public:
/// if not saving to file, downloaded data is placed here
QByteArray m_data;
+ QString m_errorString;
+
+ bool m_followRedirects = false;
+
public
slots:
virtual void start();
diff --git a/logic/net/CacheDownload.cpp b/logic/net/CacheDownload.cpp
index d2a9bdee..6d937e30 100644
--- a/logic/net/CacheDownload.cpp
+++ b/logic/net/CacheDownload.cpp
@@ -101,6 +101,30 @@ void CacheDownload::downloadError(QNetworkReply::NetworkError error)
}
void CacheDownload::downloadFinished()
{
+ if (m_followRedirects)
+ {
+ QVariant redirect = m_reply->header(QNetworkRequest::LocationHeader);
+ QString redirectURL;
+ if(redirect.isValid())
+ {
+ redirectURL = redirect.toString();
+ }
+ // FIXME: This is a hack for https://bugreports.qt-project.org/browse/QTBUG-41061
+ else if(m_reply->hasRawHeader("Location"))
+ {
+ auto data = m_reply->rawHeader("Location");
+ if(data.size() > 2 && data[0] == '/' && data[1] == '/')
+ redirectURL = m_reply->url().scheme() + ":" + data;
+ }
+ if (!redirectURL.isEmpty())
+ {
+ m_url = QUrl(redirect.toString());
+ QLOG_INFO() << "Following redirect to " << m_url.toString();
+ start();
+ return;
+ }
+ }
+
// if the download succeeded
if (m_status == Job_Failed)
{
diff --git a/logic/net/CacheDownload.h b/logic/net/CacheDownload.h
index d446d23e..9eb69fcd 100644
--- a/logic/net/CacheDownload.h
+++ b/logic/net/CacheDownload.h
@@ -36,6 +36,8 @@ private:
bool wroteAnyData = false;
public:
+ bool m_followRedirects = false;
+
explicit CacheDownload(QUrl url, MetaEntryPtr entry);
static CacheDownloadPtr make(QUrl url, MetaEntryPtr entry)
{
diff --git a/logic/net/NetAction.h b/logic/net/NetAction.h
index 97c96e5d..fdd69eec 100644
--- a/logic/net/NetAction.h
+++ b/logic/net/NetAction.h
@@ -55,6 +55,9 @@ public:
/// the network reply
std::shared_ptr<QNetworkReply> m_reply;
+ /// the content of the content-type header
+ QString m_content_type;
+
/// source URL
QUrl m_url;
diff --git a/logic/net/NetJob.h b/logic/net/NetJob.h
index d05e7b6f..8fc04d06 100644
--- a/logic/net/NetJob.h
+++ b/logic/net/NetJob.h
@@ -30,8 +30,8 @@ class NetJob : public ProgressProvider
{
Q_OBJECT
public:
- explicit NetJob(QString job_name) : ProgressProvider(), m_job_name(job_name) {};
- virtual ~NetJob() {};
+ explicit NetJob(QString job_name) : ProgressProvider(), m_job_name(job_name) {}
+ virtual ~NetJob() {}
template <typename T> bool addNetAction(T action)
{
NetActionPtr base = std::static_pointer_cast<NetAction>(action);
@@ -62,7 +62,10 @@ public:
{
return downloads[index];
}
- ;
+ const NetActionPtr at(const int index)
+ {
+ return downloads.at(index);
+ }
NetActionPtr first()
{
if (downloads.size())
@@ -73,21 +76,10 @@ 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;
}
- ;
QStringList getFailedFiles();
signals:
void started();
diff --git a/logic/tasks/ProgressProvider.h b/logic/tasks/ProgressProvider.h
index dcb71139..f6928e1c 100644
--- a/logic/tasks/ProgressProvider.h
+++ b/logic/tasks/ProgressProvider.h
@@ -32,9 +32,7 @@ signals:
void status(QString status);
public:
- virtual ~ProgressProvider() {};
- virtual QString getStatus() const = 0;
- virtual void getProgress(qint64 &current, qint64 &total) = 0;
+ virtual ~ProgressProvider() {}
virtual bool isRunning() const = 0;
public
slots:
diff --git a/logic/tasks/SequentialTask.cpp b/logic/tasks/SequentialTask.cpp
index e0f8fcdd..e08206f8 100644
--- a/logic/tasks/SequentialTask.cpp
+++ b/logic/tasks/SequentialTask.cpp
@@ -1,31 +1,7 @@
#include "SequentialTask.h"
-SequentialTask::SequentialTask(QObject *parent) :
- Task(parent), m_currentIndex(-1)
+SequentialTask::SequentialTask(QObject *parent) : Task(parent), m_currentIndex(-1)
{
-
-}
-
-QString SequentialTask::getStatus() const
-{
- if (m_queue.isEmpty() || m_currentIndex >= m_queue.size())
- {
- return QString();
- }
- return m_queue.at(m_currentIndex)->getStatus();
-}
-
-void SequentialTask::getProgress(qint64 &current, qint64 &total)
-{
- current = 0;
- total = 0;
- for (int i = 0; i < m_queue.size(); ++i)
- {
- qint64 subCurrent, subTotal;
- m_queue.at(i)->getProgress(subCurrent, subTotal);
- current += subCurrent;
- total += subTotal;
- }
}
void SequentialTask::addTask(std::shared_ptr<ProgressProvider> task)
@@ -55,10 +31,9 @@ void SequentialTask::startNext()
std::shared_ptr<ProgressProvider> next = m_queue[m_currentIndex];
connect(next.get(), SIGNAL(failed(QString)), this, SLOT(subTaskFailed(QString)));
connect(next.get(), SIGNAL(status(QString)), this, SLOT(subTaskStatus(QString)));
- connect(next.get(), SIGNAL(progress(qint64,qint64)), this, SLOT(subTaskProgress()));
+ connect(next.get(), SIGNAL(progress(qint64, qint64)), this, SLOT(subTaskProgress(qint64, qint64)));
connect(next.get(), SIGNAL(succeeded()), this, SLOT(startNext()));
next->start();
- emit status(getStatus());
}
void SequentialTask::subTaskFailed(const QString &msg)
@@ -69,16 +44,16 @@ void SequentialTask::subTaskStatus(const QString &msg)
{
setStatus(msg);
}
-void SequentialTask::subTaskProgress()
+void SequentialTask::subTaskProgress(qint64 current, qint64 total)
{
- qint64 current, total;
- getProgress(current, total);
- if (total == 0)
+ if(total == 0)
{
setProgress(0);
+ return;
}
- else
- {
- setProgress(100 * current / total);
- }
+ auto dcurrent = (double) current;
+ auto dtotal = (double) total;
+ auto partial = ((dcurrent / dtotal) * 100.0f)/* / double(m_queue.size())*/;
+ // auto bigpartial = double(m_currentIndex) * 100.0f / double(m_queue.size());
+ setProgress(partial);
}
diff --git a/logic/tasks/SequentialTask.h b/logic/tasks/SequentialTask.h
index c405dca3..f1fe9c72 100644
--- a/logic/tasks/SequentialTask.h
+++ b/logic/tasks/SequentialTask.h
@@ -11,9 +11,6 @@ class SequentialTask : public Task
public:
explicit SequentialTask(QObject *parent = 0);
- virtual QString getStatus() const;
- virtual void getProgress(qint64 &current, qint64 &total);
-
void addTask(std::shared_ptr<ProgressProvider> task);
protected:
@@ -24,7 +21,7 @@ slots:
void startNext();
void subTaskFailed(const QString &msg);
void subTaskStatus(const QString &msg);
- void subTaskProgress();
+ void subTaskProgress(qint64 current, qint64 total);
private:
QQueue<std::shared_ptr<ProgressProvider> > m_queue;
diff --git a/logic/tasks/Task.cpp b/logic/tasks/Task.cpp
index c980d6b3..f7a99cdf 100644
--- a/logic/tasks/Task.cpp
+++ b/logic/tasks/Task.cpp
@@ -20,29 +20,16 @@ Task::Task(QObject *parent) : ProgressProvider(parent)
{
}
-QString Task::getStatus() const
-{
- return m_statusString;
-}
-
void Task::setStatus(const QString &new_status)
{
- m_statusString = new_status;
emit status(new_status);
}
void Task::setProgress(int new_progress)
{
- m_progress = new_progress;
emit progress(new_progress, 100);
}
-void Task::getProgress(qint64 &current, qint64 &total)
-{
- current = m_progress;
- total = 100;
-}
-
void Task::start()
{
m_running = true;
@@ -61,6 +48,7 @@ void Task::emitFailed(QString reason)
void Task::emitSucceeded()
{
+ if (!m_running) { return; } // Don't succeed twice.
m_running = false;
m_succeeded = true;
QLOG_INFO() << "Task succeeded";
diff --git a/logic/tasks/Task.h b/logic/tasks/Task.h
index 063eeeda..e6b09262 100644
--- a/logic/tasks/Task.h
+++ b/logic/tasks/Task.h
@@ -26,8 +26,6 @@ public:
explicit Task(QObject *parent = 0);
virtual ~Task() {};
- virtual QString getStatus() const;
- virtual void getProgress(qint64 &current, qint64 &total);
virtual bool isRunning() const;
/*!
@@ -50,6 +48,7 @@ slots:
protected:
virtual void executeTask() = 0;
+protected slots:
virtual void emitSucceeded();
virtual void emitFailed(QString reason);
@@ -59,9 +58,8 @@ slots:
void setProgress(int progress);
protected:
- QString m_statusString;
- int m_progress = 0;
bool m_running = false;
bool m_succeeded = false;
QString m_failReason = "";
};
+
diff --git a/logic/tools/BaseExternalTool.h b/logic/tools/BaseExternalTool.h
index 7672bf10..5f112970 100644
--- a/logic/tools/BaseExternalTool.h
+++ b/logic/tools/BaseExternalTool.h
@@ -43,7 +43,7 @@ public:
virtual QString name() const = 0;
- virtual void registerSettings(SettingsObject *settings) = 0;
+ virtual void registerSettings(std::shared_ptr<SettingsObject> settings) = 0;
virtual BaseExternalTool *createTool(InstancePtr instance, QObject *parent = 0) = 0;
diff --git a/logic/tools/JProfiler.cpp b/logic/tools/JProfiler.cpp
index 988a875a..2134984e 100644
--- a/logic/tools/JProfiler.cpp
+++ b/logic/tools/JProfiler.cpp
@@ -40,7 +40,7 @@ void JProfiler::beginProfilingImpl(MinecraftProcess *process)
m_profilerProcess = profiler;
}
-void JProfilerFactory::registerSettings(SettingsObject *settings)
+void JProfilerFactory::registerSettings(std::shared_ptr<SettingsObject> settings)
{
settings->registerSetting("JProfilerPath");
settings->registerSetting("JProfilerPort", 42042);
diff --git a/logic/tools/JProfiler.h b/logic/tools/JProfiler.h
index b3fa6ec7..3085511b 100644
--- a/logic/tools/JProfiler.h
+++ b/logic/tools/JProfiler.h
@@ -16,7 +16,7 @@ class JProfilerFactory : public BaseProfilerFactory
{
public:
QString name() const override { return "JProfiler"; }
- void registerSettings(SettingsObject *settings) override;
+ void registerSettings(std::shared_ptr<SettingsObject> settings) override;
BaseExternalTool *createTool(InstancePtr instance, QObject *parent = 0) override;
bool check(QString *error) override;
bool check(const QString &path, QString *error) override;
diff --git a/logic/tools/JVisualVM.cpp b/logic/tools/JVisualVM.cpp
index 09ab1762..33e271b4 100644
--- a/logic/tools/JVisualVM.cpp
+++ b/logic/tools/JVisualVM.cpp
@@ -37,7 +37,7 @@ void JVisualVM::beginProfilingImpl(MinecraftProcess *process)
m_profilerProcess = profiler;
}
-void JVisualVMFactory::registerSettings(SettingsObject *settings)
+void JVisualVMFactory::registerSettings(std::shared_ptr<SettingsObject> settings)
{
QString defaultValue = QStandardPaths::findExecutable("jvisualvm");
if (defaultValue.isNull())
diff --git a/logic/tools/JVisualVM.h b/logic/tools/JVisualVM.h
index dffdde36..a646c681 100644
--- a/logic/tools/JVisualVM.h
+++ b/logic/tools/JVisualVM.h
@@ -16,7 +16,7 @@ class JVisualVMFactory : public BaseProfilerFactory
{
public:
QString name() const override { return "JVisualVM"; }
- void registerSettings(SettingsObject *settings) override;
+ void registerSettings(std::shared_ptr<SettingsObject> settings) override;
BaseExternalTool *createTool(InstancePtr instance, QObject *parent = 0) override;
bool check(QString *error) override;
bool check(const QString &path, QString *error) override;
diff --git a/logic/tools/MCEditTool.cpp b/logic/tools/MCEditTool.cpp
index 91643585..1c7d9cd2 100644
--- a/logic/tools/MCEditTool.cpp
+++ b/logic/tools/MCEditTool.cpp
@@ -43,7 +43,7 @@ void MCEditTool::runImpl()
#endif
}
-void MCEditFactory::registerSettings(SettingsObject *settings)
+void MCEditFactory::registerSettings(std::shared_ptr<SettingsObject> settings)
{
settings->registerSetting("MCEditPath");
}
diff --git a/logic/tools/MCEditTool.h b/logic/tools/MCEditTool.h
index 9985bde1..810caf25 100644
--- a/logic/tools/MCEditTool.h
+++ b/logic/tools/MCEditTool.h
@@ -16,7 +16,7 @@ class MCEditFactory : public BaseDetachedToolFactory
{
public:
QString name() const override { return "MCEdit"; }
- void registerSettings(SettingsObject *settings) override;
+ void registerSettings(std::shared_ptr<SettingsObject> settings) override;
BaseExternalTool *createTool(InstancePtr instance, QObject *parent = 0) override;
bool check(QString *error) override;
bool check(const QString &path, QString *error) override;