Split parsing/applying. Better error logging. Fix crash.

This commit is contained in:
Jan Dalheimer 2014-01-27 19:20:07 +01:00
parent 966f9d1206
commit f9ea3dbfde
13 changed files with 842 additions and 355 deletions

View File

@ -162,7 +162,7 @@ void OneSixModEditDialog::on_forgeBtn_clicked()
}
}
}
m_inst->reloadFullVersion(this);
m_inst->reloadVersion(this);
}
void OneSixModEditDialog::on_liteloaderBtn_clicked()
@ -184,7 +184,7 @@ void OneSixModEditDialog::on_liteloaderBtn_clicked()
}
else
{
m_inst->reloadFullVersion(this);
m_inst->reloadVersion(this);
}
}

View File

@ -21,6 +21,8 @@
#include <quazipfile.h>
#include <pathutils.h>
#include <QStringList>
#include <QRegularExpression>
#include <QRegularExpressionMatch>
#include "MultiMC.h"
#include "OneSixInstance.h"
@ -146,36 +148,71 @@ bool ForgeInstaller::add(OneSixInstance *to)
QJsonObject libObj = lib->toJson();
bool found = false;
bool equals = false;
// find an entry that matches this one
for (auto tolib : to->getFullVersion()->libraries)
for (auto tolib : to->getNonCustomVersion()->libraries)
{
if (tolib->name() != libName)
continue;
found = true;
if (tolib->toJson() == libObj)
{
equals = true;
}
// replace lib
libObj.insert("insert", QString("apply"));
break;
}
if (equals)
{
continue;
}
if (!found)
{
// add lib
QJsonObject insertObj;
insertObj.insert("before", to->getFullVersion()->libraries.at(sliding_insert_window)->rawName());
insertObj.insert(
"before",
to->getFullVersion()->libraries.at(sliding_insert_window + 1)->rawName());
libObj.insert("insert", insertObj);
sliding_insert_window++;
}
librariesPlus.append(libObj);
librariesPlus.prepend(libObj);
}
obj.insert("+libraries", librariesPlus);
obj.insert("mainClass", m_forge_version->mainClass);
obj.insert("minecraftArguments", m_forge_version->minecraftArguments);
QString args = m_forge_version->minecraftArguments;
QStringList tweakers;
{
QRegularExpression expression("--tweakClass ([a-zA-Z0-9\\.]*)");
QRegularExpressionMatch match = expression.match(args);
while (match.hasMatch())
{
tweakers.append(match.captured(1));
args.remove(match.capturedStart(), match.capturedLength());
match = expression.match(args);
}
}
if (!args.isEmpty() && args != to->getNonCustomVersion()->minecraftArguments)
{
obj.insert("minecraftArguments", args);
}
if (!tweakers.isEmpty())
{
obj.insert("+tweakers", QJsonArray::fromStringList(tweakers));
}
if (!m_forge_version->processArguments.isEmpty() &&
m_forge_version->processArguments != to->getNonCustomVersion()->processArguments)
{
obj.insert("processArguments", m_forge_version->processArguments);
}
}
QFile file(filename(to->instanceRoot()));
if (!file.open(QFile::WriteOnly))
{
QLOG_ERROR() << "Error opening" << file.fileName() << "for reading:" << file.errorString();
QLOG_ERROR() << "Error opening" << file.fileName()
<< "for reading:" << file.errorString();
return false;
}
file.write(QJsonDocument(obj).toJson());

View File

@ -55,7 +55,7 @@ slots:
setStatus(tr("Installing Forge..."));
QString forgePath = entry->getFullPath();
ForgeInstaller forge(forgePath, forgeVersion->universal_url);
if (!instance->reloadFullVersion())
if (!instance->reloadVersion())
{
emitFailed(tr("Couldn't load the version config"));
return;

View File

@ -35,13 +35,14 @@ 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));
if (QDir(instanceRoot()).exists("version.json"))
{
reloadFullVersion();
reloadVersion();
}
else
{
clearFullVersion();
clearVersion();
}
}
@ -139,6 +140,10 @@ QStringList OneSixInstance::processMinecraftArgs(MojangAccountPtr account)
I_D(OneSixInstance);
auto version = d->version;
QString args_pattern = version->minecraftArguments;
for (auto tweaker : version->tweakers)
{
args_pattern += " --tweakClass " + tweaker;
}
QMap<QString, QString> token_mapping;
// yggdrasil!
@ -287,7 +292,7 @@ bool OneSixInstance::setIntendedVersionId(QString version)
settings().set("IntendedVersion", version);
setShouldUpdate(true);
QFile::remove(PathCombine(instanceRoot(), "version.json"));
clearFullVersion();
clearVersion();
return true;
}
@ -323,28 +328,39 @@ QString OneSixInstance::currentVersionId() const
return intendedVersionId();
}
bool OneSixInstance::reloadFullVersion(QWidget *widgetParent)
bool OneSixInstance::reloadVersion(QWidget *widgetParent)
{
I_D(OneSixInstance);
bool ret = d->version->reload(widgetParent);
if (ret)
{
ret = d->nonCustomVersion->reload(widgetParent, true);
}
emit versionReloaded();
return ret;
}
void OneSixInstance::clearFullVersion()
void OneSixInstance::clearVersion()
{
I_D(OneSixInstance);
d->version->clear();
d->nonCustomVersion->clear();
emit versionReloaded();
}
std::shared_ptr<OneSixVersion> OneSixInstance::getFullVersion()
std::shared_ptr<OneSixVersion> OneSixInstance::getFullVersion() const
{
I_D(OneSixInstance);
I_D(const OneSixInstance);
return d->version;
}
std::shared_ptr<OneSixVersion> OneSixInstance::getNonCustomVersion() const
{
I_D(const OneSixInstance);
return d->nonCustomVersion;
}
QString OneSixInstance::defaultBaseJar() const
{
return "versions/" + intendedVersionId() + "/" + intendedVersionId() + ".jar";

View File

@ -52,11 +52,13 @@ public:
virtual QDialog *createModEditDialog(QWidget *parent) override;
/// reload the full version json files. return true on success!
bool reloadFullVersion(QWidget *widgetParent = 0);
bool reloadVersion(QWidget *widgetParent = 0);
/// clears all version information in preparation for an update
void clearFullVersion();
void clearVersion();
/// get the current full version info
std::shared_ptr<OneSixVersion> getFullVersion();
std::shared_ptr<OneSixVersion> getFullVersion() const;
/// gets the current version info, excluding custom.json
std::shared_ptr<OneSixVersion> getNonCustomVersion() const;
/// is the current version original, or custom?
virtual bool versionIsCustom() override;

View File

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

View File

@ -93,6 +93,10 @@ void OneSixLibrary::addNative(OpSys os, const QString &suffix)
m_is_native = true;
m_native_suffixes[os] = suffix;
}
void OneSixLibrary::clearSuffixes()
{
m_native_suffixes.clear();
}
void OneSixLibrary::setRules(QList<std::shared_ptr<Rule>> rules)
{
m_rules = rules;
@ -176,7 +180,7 @@ bool OneSixLibrary::extractTo(QString target_dir)
cooked_storage.replace("${arch}", "32");
QString origin = PathCombine("libraries", cooked_storage);
QString target_dir_cooked = PathCombine(target_dir, "32");
if(!ensureFolderPathExists(target_dir_cooked))
if (!ensureFolderPathExists(target_dir_cooked))
{
QLOG_ERROR() << "Couldn't create folder " + target_dir_cooked;
return false;
@ -191,7 +195,7 @@ bool OneSixLibrary::extractTo(QString target_dir)
cooked_storage.replace("${arch}", "64");
origin = PathCombine("libraries", cooked_storage);
target_dir_cooked = PathCombine(target_dir, "64");
if(!ensureFolderPathExists(target_dir_cooked))
if (!ensureFolderPathExists(target_dir_cooked))
{
QLOG_ERROR() << "Couldn't create folder " + target_dir_cooked;
return false;
@ -205,7 +209,7 @@ bool OneSixLibrary::extractTo(QString target_dir)
}
else
{
if(!ensureFolderPathExists(target_dir))
if (!ensureFolderPathExists(target_dir))
{
QLOG_ERROR() << "Couldn't create folder " + target_dir;
return false;
@ -230,8 +234,10 @@ QJsonObject OneSixLibrary::toJson()
libRoot.insert("MMC-hint", m_hint);
if (m_base_url != "http://" + URLConstants::AWS_DOWNLOAD_LIBRARIES &&
m_base_url != "https://" + URLConstants::AWS_DOWNLOAD_LIBRARIES &&
m_base_url != "https://" + URLConstants::LIBRARY_BASE)
m_base_url != "https://" + URLConstants::LIBRARY_BASE && !m_base_url.isEmpty())
{
libRoot.insert("url", m_base_url);
}
if (isNative() && m_native_suffixes.size())
{
QJsonObject nativeList;

View File

@ -107,6 +107,8 @@ public:
void setIsNative();
/// Attach a name suffix to the specified OS native
void addNative(OpSys os, const QString &suffix);
/// Clears all suffixes
void clearSuffixes();
/// Set the load rules
void setRules(QList<std::shared_ptr<Rule>> rules);

View File

@ -137,7 +137,7 @@ void OneSixUpdate::versionFileFinished()
{
finfo.remove();
}
inst->reloadFullVersion();
inst->reloadVersion();
jarlibStart();
}
@ -235,7 +235,7 @@ void OneSixUpdate::jarlibStart()
setStatus(tr("Getting the library files from Mojang..."));
QLOG_INFO() << m_inst->name() << ": downloading libraries";
OneSixInstance *inst = (OneSixInstance *)m_inst;
bool successful = inst->reloadFullVersion();
bool successful = inst->reloadVersion();
if (!successful)
{
emitFailed("Failed to load the version description file. It might be "

View File

@ -25,9 +25,9 @@ OneSixVersion::OneSixVersion(OneSixInstance *instance, QObject *parent)
clear();
}
bool OneSixVersion::reload(QWidget *widgetParent)
bool OneSixVersion::reload(QWidget *widgetParent, const bool excludeCustom)
{
return OneSixVersionBuilder::build(this, m_instance, widgetParent);
return OneSixVersionBuilder::build(this, m_instance, widgetParent, excludeCustom);
}
void OneSixVersion::clear()
@ -42,6 +42,7 @@ void OneSixVersion::clear()
minimumLauncherVersion = 0xDEADBEAF;
mainClass.clear();
libraries.clear();
tweakers.clear();
}
void OneSixVersion::dump() const

View File

@ -38,7 +38,7 @@ public:
virtual int columnCount(const QModelIndex &parent) const;
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
bool reload(QWidget *widgetParent);
bool reload(QWidget *widgetParent, const bool excludeCustom = false);
void clear();
void dump() const;
@ -78,6 +78,10 @@ public:
* writing)
*/
int minimumLauncherVersion = 0xDEADBEEF;
/**
* A list of all tweaker classes
*/
QStringList tweakers;
/**
* The main class to load first
*/

File diff suppressed because it is too large Load Diff

View File

@ -22,12 +22,13 @@ class OneSixInstance;
class QWidget;
class QJsonObject;
class QFileInfo;
class VersionFile;
class OneSixVersionBuilder
{
OneSixVersionBuilder();
public:
static bool build(OneSixVersion *version, OneSixInstance *instance, QWidget *widgetParent);
static bool build(OneSixVersion *version, OneSixInstance *instance, QWidget *widgetParent, const bool excludeCustom);
static bool read(OneSixVersion *version, const QJsonObject &obj);
private:
@ -35,19 +36,8 @@ private:
OneSixInstance *m_instance;
QWidget *m_widgetParent;
enum Type
{
Override,
Add,
Remove
};
bool build();
bool build(const bool excludeCustom);
bool read(const QJsonObject &obj);
void clear();
bool apply(const QJsonObject &object);
bool applyLibrary(const QJsonObject &lib, const Type type);
bool read(const QFileInfo &fileInfo, QJsonObject *out);
bool read(const QFileInfo &fileInfo, const bool requireOrder, VersionFile *out);
};