Fix installing forge after liteloader and then removing liteloader. Also formatting.

This commit is contained in:
Jan Dalheimer 2014-02-02 14:17:44 +01:00
parent ece826bdbc
commit cdd35910c3
8 changed files with 96 additions and 82 deletions

View File

@ -151,7 +151,7 @@ bool ForgeInstaller::add(OneSixInstance *to)
bool found = false;
bool equals = false;
// find an entry that matches this one
for (auto tolib : to->getNonCustomVersion()->libraries)
for (auto tolib : to->getVanillaVersion()->libraries)
{
if (tolib->name() != libName)
continue;
@ -194,7 +194,7 @@ bool ForgeInstaller::add(OneSixInstance *to)
match = expression.match(args);
}
}
if (!args.isEmpty() && args != to->getNonCustomVersion()->minecraftArguments)
if (!args.isEmpty() && args != to->getVanillaVersion()->minecraftArguments)
{
obj.insert("minecraftArguments", args);
}
@ -203,7 +203,7 @@ bool ForgeInstaller::add(OneSixInstance *to)
obj.insert("+tweakers", QJsonArray::fromStringList(tweakers));
}
if (!m_forge_version->processArguments.isEmpty() &&
m_forge_version->processArguments != to->getNonCustomVersion()->processArguments)
m_forge_version->processArguments != to->getVanillaVersion()->processArguments)
{
obj.insert("processArguments", m_forge_version->processArguments);
}

View File

@ -35,7 +35,7 @@ OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *settings,
d->m_settings->registerSetting("IntendedVersion", "");
d->m_settings->registerSetting("ShouldUpdate", false);
d->version.reset(new OneSixVersion(this, this));
d->nonCustomVersion.reset(new OneSixVersion(this, this));
d->vanillaVersion.reset(new OneSixVersion(this, this));
if (QDir(instanceRoot()).exists("version.json"))
{
reloadVersion();
@ -321,7 +321,7 @@ bool OneSixInstance::reloadVersion(QWidget *widgetParent)
bool ret = d->version->reload(widgetParent);
if (ret)
{
ret = d->nonCustomVersion->reload(widgetParent, true);
ret = d->vanillaVersion->reload(widgetParent, true);
}
emit versionReloaded();
return ret;
@ -331,7 +331,7 @@ void OneSixInstance::clearVersion()
{
I_D(OneSixInstance);
d->version->clear();
d->nonCustomVersion->clear();
d->vanillaVersion->clear();
emit versionReloaded();
}
@ -341,10 +341,10 @@ std::shared_ptr<OneSixVersion> OneSixInstance::getFullVersion() const
return d->version;
}
std::shared_ptr<OneSixVersion> OneSixInstance::getNonCustomVersion() const
std::shared_ptr<OneSixVersion> OneSixInstance::getVanillaVersion() const
{
I_D(const OneSixInstance);
return d->nonCustomVersion;
return d->vanillaVersion;
}
QString OneSixInstance::defaultBaseJar() const

View File

@ -57,8 +57,8 @@ public:
void clearVersion();
/// get the current full version info
std::shared_ptr<OneSixVersion> getFullVersion() const;
/// gets the current version info, excluding custom.json
std::shared_ptr<OneSixVersion> getNonCustomVersion() const;
/// gets the current version info, but only for version.json
std::shared_ptr<OneSixVersion> getVanillaVersion() const;
/// is the current version original, or custom?
virtual bool versionIsCustom() override;

View File

@ -22,7 +22,7 @@
struct OneSixInstancePrivate : public BaseInstancePrivate
{
std::shared_ptr<OneSixVersion> version;
std::shared_ptr<OneSixVersion> nonCustomVersion;
std::shared_ptr<OneSixVersion> vanillaVersion;
std::shared_ptr<ModList> loader_mod_list;
std::shared_ptr<ModList> resource_pack_list;
};

View File

@ -26,10 +26,10 @@ OneSixVersion::OneSixVersion(OneSixInstance *instance, QObject *parent)
clear();
}
bool OneSixVersion::reload(QWidget *widgetParent, const bool excludeCustom)
bool OneSixVersion::reload(QWidget *widgetParent, const bool onlyVanilla)
{
beginResetModel();
bool ret = OneSixVersionBuilder::build(this, m_instance, widgetParent, excludeCustom);
bool ret = OneSixVersionBuilder::build(this, m_instance, widgetParent, onlyVanilla);
endResetModel();
return ret;
}

View File

@ -37,7 +37,7 @@ public:
virtual int columnCount(const QModelIndex &parent) const;
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
bool reload(QWidget *widgetParent, const bool excludeCustom = false);
bool reload(QWidget *widgetParent, const bool onlyVanilla = false);
void clear();
void dump() const;

View File

@ -280,7 +280,8 @@ struct VersionFile
QJsonValue tweakersVal = root.value("tweakers");
if (!tweakersVal.isArray())
{
QLOG_ERROR() << filename << "contains a 'tweakers' field, but it's not an array";
QLOG_ERROR() << filename
<< "contains a 'tweakers' field, but it's not an array";
return out;
}
out.shouldOverwriteTweakers = true;
@ -289,7 +290,8 @@ struct VersionFile
{
if (!tweakerVal.isString())
{
QLOG_ERROR() << filename << "contains a 'tweakers' field entry that's not a string";
QLOG_ERROR() << filename
<< "contains a 'tweakers' field entry that's not a string";
return out;
}
out.overwriteTweakers.append(tweakerVal.toString());
@ -300,7 +302,8 @@ struct VersionFile
QJsonValue tweakersVal = root.value("+tweakers");
if (!tweakersVal.isArray())
{
QLOG_ERROR() << filename << "contains a '+tweakers' field, but it's not an array";
QLOG_ERROR() << filename
<< "contains a '+tweakers' field, but it's not an array";
return out;
}
QJsonArray tweakers = root.value("+tweakers").toArray();
@ -308,7 +311,8 @@ struct VersionFile
{
if (!tweakerVal.isString())
{
QLOG_ERROR() << filename << "contains a '+tweakers' field entry that's not a string";
QLOG_ERROR() << filename
<< "contains a '+tweakers' field entry that's not a string";
return out;
}
out.addTweakers.append(tweakerVal.toString());
@ -319,7 +323,8 @@ struct VersionFile
QJsonValue tweakersVal = root.value("-tweakers");
if (!tweakersVal.isArray())
{
QLOG_ERROR() << filename << "contains a '-tweakers' field, but it's not an array";
QLOG_ERROR() << filename
<< "contains a '-tweakers' field, but it's not an array";
return out;
}
out.shouldOverwriteTweakers = true;
@ -328,7 +333,8 @@ struct VersionFile
{
if (!tweakerVal.isString())
{
QLOG_ERROR() << filename << "contains a '-tweakers' field entry that's not a string";
QLOG_ERROR() << filename
<< "contains a '-tweakers' field entry that's not a string";
return out;
}
out.removeTweakers.append(tweakerVal.toString());
@ -648,7 +654,9 @@ struct VersionFile
{
const int startOfVersion = lib.name.lastIndexOf(':') + 1;
const int index = findLibrary(version->libraries, QString(lib.name).replace(startOfVersion, INT_MAX, '*'));
const int index =
findLibrary(version->libraries,
QString(lib.name).replace(startOfVersion, INT_MAX, '*'));
if (index < 0)
{
if (lib.insertType == Library::Append)
@ -665,11 +673,14 @@ struct VersionFile
auto otherLib = version->libraries.at(index);
const Util::Version ourVersion = lib.name.mid(startOfVersion, INT_MAX);
const Util::Version otherVersion = otherLib->version();
// if the existing version is a hard dependency we can either use it or fail, but we can't change it
// if the existing version is a hard dependency we can either use it or
// fail, but we can't change it
if (otherLib->dependType == OneSixLibrary::Hard)
{
// we need a higher version, or we're hard to and the versions aren't equal
if (ourVersion > otherVersion || (lib.dependType == Library::Hard && ourVersion != otherVersion))
// we need a higher version, or we're hard to and the versions aren't
// equal
if (ourVersion > otherVersion ||
(lib.dependType == Library::Hard && ourVersion != otherVersion))
{
QLOG_ERROR() << "Error resolving library dependencies between"
<< otherLib->rawName() << "and" << lib.name << "in"
@ -695,7 +706,8 @@ struct VersionFile
}
else
{
// our version is smaller than the existing version, but we require it: fail
// our version is smaller than the existing version, but we require
// it: fail
if (lib.dependType == Library::Hard)
{
QLOG_ERROR() << "Error resolving library dependencies between"
@ -753,13 +765,13 @@ OneSixVersionBuilder::OneSixVersionBuilder()
}
bool OneSixVersionBuilder::build(OneSixVersion *version, OneSixInstance *instance,
QWidget *widgetParent, const bool excludeCustom)
QWidget *widgetParent, const bool onlyVanilla)
{
OneSixVersionBuilder builder;
builder.m_version = version;
builder.m_instance = instance;
builder.m_widgetParent = widgetParent;
return builder.build(excludeCustom);
return builder.build(onlyVanilla);
}
bool OneSixVersionBuilder::read(OneSixVersion *version, const QJsonObject &obj)
@ -771,7 +783,7 @@ bool OneSixVersionBuilder::read(OneSixVersion *version, const QJsonObject &obj)
return builder.read(obj);
}
bool OneSixVersionBuilder::build(const bool excludeCustom)
bool OneSixVersionBuilder::build(const bool onlyVanilla)
{
m_version->clear();
@ -823,77 +835,79 @@ bool OneSixVersionBuilder::build(const bool excludeCustom)
if (isError)
{
QMessageBox::critical(
m_widgetParent, QObject::tr("Error"),
QObject::tr(
"Error while applying %1. Please check MultiMC-0.log for more info.")
.arg(root.absoluteFilePath("version.json")));
m_widgetParent, QObject::tr("Error"),
QObject::tr(
"Error while applying %1. Please check MultiMC-0.log for more info.")
.arg(root.absoluteFilePath("version.json")));
return false;
}
}
// patches/
if (!onlyVanilla)
{
// load all, put into map for ordering, apply in the right order
QMap<int, QPair<QString, VersionFile>> files;
for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files))
// patches/
{
QLOG_INFO() << "Reading" << info.fileName();
VersionFile file;
if (!read(info, true, &file))
// load all, put into map for ordering, apply in the right order
QMap<int, QPair<QString, VersionFile>> files;
for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files))
{
return false;
QLOG_INFO() << "Reading" << info.fileName();
VersionFile file;
if (!read(info, true, &file))
{
return false;
}
files.insert(file.order, qMakePair(info.fileName(), file));
}
files.insert(file.order, qMakePair(info.fileName(), file));
}
for (auto order : files.keys())
{
QLOG_DEBUG() << "Applying file with order" << order;
auto filePair = files[order];
bool isError = false;
filePair.second.applyTo(m_version, isError);
if (isError)
for (auto order : files.keys())
{
QMessageBox::critical(
m_widgetParent, QObject::tr("Error"),
QObject::tr(
"Error while applying %1. Please check MultiMC-0.log for more info.")
.arg(filePair.first));
return false;
QLOG_DEBUG() << "Applying file with order" << order;
auto filePair = files[order];
bool isError = false;
filePair.second.applyTo(m_version, isError);
if (isError)
{
QMessageBox::critical(
m_widgetParent, QObject::tr("Error"),
QObject::tr("Error while applying %1. Please check MultiMC-0.log "
"for more info.").arg(filePair.first));
return false;
}
}
}
}
#if 0
// user.json
if (!excludeCustom)
{
if (QFile::exists(root.absoluteFilePath("user.json")))
// user.json
{
QLOG_INFO() << "Reading user.json";
VersionFile file;
if (!read(QFileInfo(root.absoluteFilePath("user.json")), false, &file))
if (QFile::exists(root.absoluteFilePath("user.json")))
{
return false;
}
file.name = "user.json";
file.fileId = "org.multimc.user.json";
file.version = QString();
file.mcVersion = QString();
bool isError = false;
file.applyTo(m_version, isError);
if (isError)
{
QMessageBox::critical(
m_widgetParent, QObject::tr("Error"),
QObject::tr(
"Error while applying %1. Please check MultiMC-0.log for more info.")
.arg(root.absoluteFilePath("user.json")));
return false;
QLOG_INFO() << "Reading user.json";
VersionFile file;
if (!read(QFileInfo(root.absoluteFilePath("user.json")), false, &file))
{
return false;
}
file.name = "user.json";
file.fileId = "org.multimc.user.json";
file.version = QString();
file.mcVersion = QString();
bool isError = false;
file.applyTo(m_version, isError);
if (isError)
{
QMessageBox::critical(
m_widgetParent, QObject::tr("Error"),
QObject::tr(
"Error while applying %1. Please check MultiMC-0.log for more info.")
.arg(root.absoluteFilePath("user.json")));
return false;
}
}
}
}
#endif
}
}
// some final touches

View File

@ -28,7 +28,7 @@ class OneSixVersionBuilder
{
OneSixVersionBuilder();
public:
static bool build(OneSixVersion *version, OneSixInstance *instance, QWidget *widgetParent, const bool excludeCustom);
static bool build(OneSixVersion *version, OneSixInstance *instance, QWidget *widgetParent, const bool onlyVanilla);
static bool read(OneSixVersion *version, const QJsonObject &obj);
private:
@ -36,7 +36,7 @@ private:
OneSixInstance *m_instance;
QWidget *m_widgetParent;
bool build(const bool excludeCustom);
bool build(const bool onlyVanilla);
bool read(const QJsonObject &obj);
bool read(const QFileInfo &fileInfo, const bool requireOrder, VersionFile *out);