Improve reporting of version file errors.x
This commit is contained in:
parent
ffff2cd324
commit
b2c803a378
@ -9,7 +9,7 @@ public:
|
|||||||
MMCError(QString cause)
|
MMCError(QString cause)
|
||||||
{
|
{
|
||||||
exceptionCause = cause;
|
exceptionCause = cause;
|
||||||
QLOG_ERROR() << errorName() + ": " + cause;
|
QLOG_ERROR() << "Exception: " + cause;
|
||||||
};
|
};
|
||||||
virtual ~MMCError(){};
|
virtual ~MMCError(){};
|
||||||
virtual const char *what() const noexcept
|
virtual const char *what() const noexcept
|
||||||
@ -20,10 +20,6 @@ public:
|
|||||||
{
|
{
|
||||||
return exceptionCause;
|
return exceptionCause;
|
||||||
}
|
}
|
||||||
virtual QString errorName()
|
|
||||||
{
|
|
||||||
return "MultiMC Error";
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
QString exceptionCause;
|
QString exceptionCause;
|
||||||
};
|
};
|
@ -42,8 +42,7 @@
|
|||||||
#include "logic/LiteLoaderInstaller.h"
|
#include "logic/LiteLoaderInstaller.h"
|
||||||
#include "logic/OneSixVersionBuilder.h"
|
#include "logic/OneSixVersionBuilder.h"
|
||||||
|
|
||||||
template<typename A, typename B>
|
template <typename A, typename B> QMap<A, B> invert(const QMap<B, A> &in)
|
||||||
QMap<A, B> invert(const QMap<B, A> &in)
|
|
||||||
{
|
{
|
||||||
QMap<A, B> out;
|
QMap<A, B> out;
|
||||||
for (auto it = in.begin(); it != in.end(); ++it)
|
for (auto it = in.begin(); it != in.end(); ++it)
|
||||||
@ -96,7 +95,8 @@ OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent)
|
|||||||
m_resourcepacks->startWatching();
|
m_resourcepacks->startWatching();
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(m_inst, &OneSixInstance::versionReloaded, this, &OneSixModEditDialog::updateVersionControls);
|
connect(m_inst, &OneSixInstance::versionReloaded, this,
|
||||||
|
&OneSixModEditDialog::updateVersionControls);
|
||||||
}
|
}
|
||||||
|
|
||||||
OneSixModEditDialog::~OneSixModEditDialog()
|
OneSixModEditDialog::~OneSixModEditDialog()
|
||||||
@ -120,9 +120,30 @@ void OneSixModEditDialog::disableVersionControls()
|
|||||||
ui->removeLibraryBtn->setEnabled(false);
|
ui->removeLibraryBtn->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OneSixModEditDialog::reloadInstanceVersion()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_inst->reloadVersion();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (MMCError &e)
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this, tr("Error"), e.cause());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
QMessageBox::critical(
|
||||||
|
this, tr("Error"),
|
||||||
|
tr("Failed to load the version description file for reasons unknown."));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void OneSixModEditDialog::on_reloadLibrariesBtn_clicked()
|
void OneSixModEditDialog::on_reloadLibrariesBtn_clicked()
|
||||||
{
|
{
|
||||||
m_inst->reloadVersion();
|
reloadInstanceVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OneSixModEditDialog::on_removeLibraryBtn_clicked()
|
void OneSixModEditDialog::on_removeLibraryBtn_clicked()
|
||||||
@ -136,7 +157,7 @@ void OneSixModEditDialog::on_removeLibraryBtn_clicked()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_inst->reloadVersion();
|
reloadInstanceVersion();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,13 +184,15 @@ void OneSixModEditDialog::on_forgeBtn_clicked()
|
|||||||
// FIXME: model::isCustom();
|
// FIXME: model::isCustom();
|
||||||
if (QDir(m_inst->instanceRoot()).exists("custom.json"))
|
if (QDir(m_inst->instanceRoot()).exists("custom.json"))
|
||||||
{
|
{
|
||||||
if (QMessageBox::question(this, tr("Revert?"), tr("This action will remove your custom.json. Continue?")) != QMessageBox::Yes)
|
if (QMessageBox::question(this, tr("Revert?"),
|
||||||
|
tr("This action will remove your custom.json. Continue?")) !=
|
||||||
|
QMessageBox::Yes)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// FIXME: model::revertToBase();
|
// FIXME: model::revertToBase();
|
||||||
QDir(m_inst->instanceRoot()).remove("custom.json");
|
QDir(m_inst->instanceRoot()).remove("custom.json");
|
||||||
m_inst->reloadVersion();
|
reloadInstanceVersion();
|
||||||
}
|
}
|
||||||
VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this);
|
VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this);
|
||||||
vselect.setFilter(1, m_inst->currentVersionId());
|
vselect.setFilter(1, m_inst->currentVersionId());
|
||||||
@ -214,21 +237,25 @@ void OneSixModEditDialog::on_forgeBtn_clicked()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_inst->reloadVersion();
|
reloadInstanceVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OneSixModEditDialog::on_liteloaderBtn_clicked()
|
void OneSixModEditDialog::on_liteloaderBtn_clicked()
|
||||||
{
|
{
|
||||||
|
// FIXME: model...
|
||||||
if (QDir(m_inst->instanceRoot()).exists("custom.json"))
|
if (QDir(m_inst->instanceRoot()).exists("custom.json"))
|
||||||
{
|
{
|
||||||
if (QMessageBox::question(this, tr("Revert?"), tr("This action will remove your custom.json. Continue?")) != QMessageBox::Yes)
|
if (QMessageBox::question(this, tr("Revert?"),
|
||||||
|
tr("This action will remove your custom.json. Continue?")) !=
|
||||||
|
QMessageBox::Yes)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QDir(m_inst->instanceRoot()).remove("custom.json");
|
QDir(m_inst->instanceRoot()).remove("custom.json");
|
||||||
m_inst->reloadVersion();
|
reloadInstanceVersion();
|
||||||
}
|
}
|
||||||
VersionSelectDialog vselect(MMC->liteloaderlist().get(), tr("Select LiteLoader version"), this);
|
VersionSelectDialog vselect(MMC->liteloaderlist().get(), tr("Select LiteLoader version"),
|
||||||
|
this);
|
||||||
vselect.setFilter(1, m_inst->currentVersionId());
|
vselect.setFilter(1, m_inst->currentVersionId());
|
||||||
vselect.setEmptyString(tr("No LiteLoader versions are currently available for Minecraft ") +
|
vselect.setEmptyString(tr("No LiteLoader versions are currently available for Minecraft ") +
|
||||||
m_inst->currentVersionId());
|
m_inst->currentVersionId());
|
||||||
@ -247,7 +274,7 @@ void OneSixModEditDialog::on_liteloaderBtn_clicked()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_inst->reloadVersion();
|
reloadInstanceVersion();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -369,7 +396,8 @@ void OneSixModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previou
|
|||||||
ui->frame->updateWithMod(m);
|
ui->frame->updateWithMod(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OneSixModEditDialog::versionCurrent(const QModelIndex ¤t, const QModelIndex &previous)
|
void OneSixModEditDialog::versionCurrent(const QModelIndex ¤t,
|
||||||
|
const QModelIndex &previous)
|
||||||
{
|
{
|
||||||
if (!current.isValid())
|
if (!current.isValid())
|
||||||
{
|
{
|
||||||
|
@ -57,6 +57,8 @@ protected:
|
|||||||
bool eventFilter(QObject *obj, QEvent *ev);
|
bool eventFilter(QObject *obj, QEvent *ev);
|
||||||
bool loaderListFilter(QKeyEvent *ev);
|
bool loaderListFilter(QKeyEvent *ev);
|
||||||
bool resourcePackListFilter(QKeyEvent *ev);
|
bool resourcePackListFilter(QKeyEvent *ev);
|
||||||
|
/// FIXME: this shouldn't be necessary!
|
||||||
|
bool reloadInstanceVersion();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::OneSixModEditDialog *ui;
|
Ui::OneSixModEditDialog *ui;
|
||||||
@ -66,8 +68,6 @@ private:
|
|||||||
EnabledItemFilter *main_model;
|
EnabledItemFilter *main_model;
|
||||||
OneSixInstance *m_inst;
|
OneSixInstance *m_inst;
|
||||||
|
|
||||||
QMap<QString, int> getExistingOrder() const;
|
|
||||||
|
|
||||||
public
|
public
|
||||||
slots:
|
slots:
|
||||||
void loaderCurrent(QModelIndex current, QModelIndex previous);
|
void loaderCurrent(QModelIndex current, QModelIndex previous);
|
||||||
|
@ -15,10 +15,6 @@ class JSONValidationError : public MMCError
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
JSONValidationError(QString cause) : MMCError(cause) {};
|
JSONValidationError(QString cause) : MMCError(cause) {};
|
||||||
virtual QString errorName()
|
|
||||||
{
|
|
||||||
return "JSONValidationError";
|
|
||||||
};
|
|
||||||
virtual ~JSONValidationError() {};
|
virtual ~JSONValidationError() {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -17,7 +17,14 @@ OneSixFTBInstance::OneSixFTBInstance(const QString &rootDir, SettingsObject *set
|
|||||||
|
|
||||||
void OneSixFTBInstance::init()
|
void OneSixFTBInstance::init()
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
reloadVersion();
|
reloadVersion();
|
||||||
|
}
|
||||||
|
catch(MMCError & e)
|
||||||
|
{
|
||||||
|
// QLOG_ERROR() << "Caught exception on instance init: " << e.cause();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OneSixFTBInstance::copy(const QDir &newDir)
|
void OneSixFTBInstance::copy(const QDir &newDir)
|
||||||
|
@ -41,10 +41,18 @@ OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *settings,
|
|||||||
|
|
||||||
void OneSixInstance::init()
|
void OneSixInstance::init()
|
||||||
{
|
{
|
||||||
|
// FIXME: why is this decided here? what does this even mean?
|
||||||
if (QDir(instanceRoot()).exists("version.json"))
|
if (QDir(instanceRoot()).exists("version.json"))
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
reloadVersion();
|
reloadVersion();
|
||||||
}
|
}
|
||||||
|
catch(MMCError & e)
|
||||||
|
{
|
||||||
|
// QLOG_ERROR() << "Caught exception on instance init: " << e.cause();
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
clearVersion();
|
clearVersion();
|
||||||
@ -317,7 +325,7 @@ QString OneSixInstance::currentVersionId() const
|
|||||||
return intendedVersionId();
|
return intendedVersionId();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OneSixInstance::reloadVersion()
|
void OneSixInstance::reloadVersion()
|
||||||
{
|
{
|
||||||
I_D(OneSixInstance);
|
I_D(OneSixInstance);
|
||||||
|
|
||||||
@ -327,16 +335,15 @@ bool OneSixInstance::reloadVersion()
|
|||||||
d->vanillaVersion->reload(true, externalPatches());
|
d->vanillaVersion->reload(true, externalPatches());
|
||||||
setFlags(flags() & ~VersionBrokenFlag);
|
setFlags(flags() & ~VersionBrokenFlag);
|
||||||
emit versionReloaded();
|
emit versionReloaded();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
catch(MMCError error)
|
catch(MMCError & error)
|
||||||
{
|
{
|
||||||
d->version->clear();
|
d->version->clear();
|
||||||
d->vanillaVersion->clear();
|
d->vanillaVersion->clear();
|
||||||
setFlags(flags() | VersionBrokenFlag);
|
setFlags(flags() | VersionBrokenFlag);
|
||||||
//TODO: rethrow to show some error message(s)?
|
//TODO: rethrow to show some error message(s)?
|
||||||
emit versionReloaded();
|
emit versionReloaded();
|
||||||
return false;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,8 +53,12 @@ public:
|
|||||||
|
|
||||||
virtual QDialog *createModEditDialog(QWidget *parent) override;
|
virtual QDialog *createModEditDialog(QWidget *parent) override;
|
||||||
|
|
||||||
/// reload the full version json files. return true on success!
|
/**
|
||||||
bool reloadVersion();
|
* reload the full version json files. return true on success!
|
||||||
|
*
|
||||||
|
* throws various exceptions :3
|
||||||
|
*/
|
||||||
|
void reloadVersion();
|
||||||
/// clears all version information in preparation for an update
|
/// clears all version information in preparation for an update
|
||||||
void clearVersion();
|
void clearVersion();
|
||||||
/// get the current full version info
|
/// get the current full version info
|
||||||
|
@ -48,7 +48,7 @@ void OneSixUpdate::executeTask()
|
|||||||
QDir mcDir(m_inst->minecraftRoot());
|
QDir mcDir(m_inst->minecraftRoot());
|
||||||
if (!mcDir.exists() && !mcDir.mkpath("."))
|
if (!mcDir.exists() && !mcDir.mkpath("."))
|
||||||
{
|
{
|
||||||
emitFailed("Failed to create bin folder.");
|
emitFailed(tr("Failed to create folder for minecraft binaries."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ void OneSixUpdate::executeTask()
|
|||||||
if (targetVersion == nullptr)
|
if (targetVersion == nullptr)
|
||||||
{
|
{
|
||||||
// don't do anything if it was invalid
|
// don't do anything if it was invalid
|
||||||
emitFailed("The specified Minecraft version is invalid. Choose a different one.");
|
emitFailed(tr("The specified Minecraft version is invalid. Choose a different one."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
versionFileStart();
|
versionFileStart();
|
||||||
@ -108,20 +108,19 @@ void OneSixUpdate::versionFileFinished()
|
|||||||
QSaveFile vfile1(version1);
|
QSaveFile vfile1(version1);
|
||||||
if (!vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly))
|
if (!vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly))
|
||||||
{
|
{
|
||||||
emitFailed("Can't open " + version1 + " for writing.");
|
emitFailed(tr("Can't open %1 for writing.").arg(version1));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto data = std::dynamic_pointer_cast<ByteArrayDownload>(DlJob)->m_data;
|
auto data = std::dynamic_pointer_cast<ByteArrayDownload>(DlJob)->m_data;
|
||||||
qint64 actual = 0;
|
qint64 actual = 0;
|
||||||
if ((actual = vfile1.write(data)) != data.size())
|
if ((actual = vfile1.write(data)) != data.size())
|
||||||
{
|
{
|
||||||
emitFailed("Failed to write into " + version1 + ". Written " + actual + " out of " +
|
emitFailed(tr("Failed to write into %1. Written %2 out of %3.").arg(version1).arg(actual).arg(data.size()));
|
||||||
data.size() + '.');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!vfile1.commit())
|
if (!vfile1.commit())
|
||||||
{
|
{
|
||||||
emitFailed("Can't commit changes to " + version1);
|
emitFailed(tr("Can't commit changes to %1").arg(version1));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,14 +135,13 @@ void OneSixUpdate::versionFileFinished()
|
|||||||
{
|
{
|
||||||
finfo.remove();
|
finfo.remove();
|
||||||
}
|
}
|
||||||
inst->reloadVersion();
|
// NOTE: Version is reloaded in jarlibStart
|
||||||
|
|
||||||
jarlibStart();
|
jarlibStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OneSixUpdate::versionFileFailed()
|
void OneSixUpdate::versionFileFailed()
|
||||||
{
|
{
|
||||||
emitFailed("Failed to download the version description. Try again.");
|
emitFailed(tr("Failed to download the version description. Try again."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void OneSixUpdate::assetIndexStart()
|
void OneSixUpdate::assetIndexStart()
|
||||||
@ -180,7 +178,7 @@ void OneSixUpdate::assetIndexFinished()
|
|||||||
QString asset_fname = "assets/indexes/" + assetName + ".json";
|
QString asset_fname = "assets/indexes/" + assetName + ".json";
|
||||||
if (!AssetsUtils::loadAssetsIndexJson(asset_fname, &index))
|
if (!AssetsUtils::loadAssetsIndexJson(asset_fname, &index))
|
||||||
{
|
{
|
||||||
emitFailed("Failed to read the assets index!");
|
emitFailed(tr("Failed to read the assets index!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Md5EtagDownloadPtr> dls;
|
QList<Md5EtagDownloadPtr> dls;
|
||||||
@ -216,7 +214,7 @@ void OneSixUpdate::assetIndexFinished()
|
|||||||
|
|
||||||
void OneSixUpdate::assetIndexFailed()
|
void OneSixUpdate::assetIndexFailed()
|
||||||
{
|
{
|
||||||
emitFailed("Failed to download the assets index!");
|
emitFailed(tr("Failed to download the assets index!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void OneSixUpdate::assetsFinished()
|
void OneSixUpdate::assetsFinished()
|
||||||
@ -226,7 +224,7 @@ void OneSixUpdate::assetsFinished()
|
|||||||
|
|
||||||
void OneSixUpdate::assetsFailed()
|
void OneSixUpdate::assetsFailed()
|
||||||
{
|
{
|
||||||
emitFailed("Failed to download assets!");
|
emitFailed(tr("Failed to download assets!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void OneSixUpdate::jarlibStart()
|
void OneSixUpdate::jarlibStart()
|
||||||
@ -234,11 +232,18 @@ void OneSixUpdate::jarlibStart()
|
|||||||
setStatus(tr("Getting the library files from Mojang..."));
|
setStatus(tr("Getting the library files from Mojang..."));
|
||||||
QLOG_INFO() << m_inst->name() << ": downloading libraries";
|
QLOG_INFO() << m_inst->name() << ": downloading libraries";
|
||||||
OneSixInstance *inst = (OneSixInstance *)m_inst;
|
OneSixInstance *inst = (OneSixInstance *)m_inst;
|
||||||
bool successful = inst->reloadVersion();
|
try
|
||||||
if (!successful)
|
|
||||||
{
|
{
|
||||||
emitFailed("Failed to load the version description file. It might be "
|
inst->reloadVersion();
|
||||||
"corrupted, missing or simply too new.");
|
}
|
||||||
|
catch(MMCError & e)
|
||||||
|
{
|
||||||
|
emitFailed(e.cause());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
emitFailed(tr("Failed to load the version description file for reasons unknown."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,6 +331,5 @@ void OneSixUpdate::jarlibFailed()
|
|||||||
{
|
{
|
||||||
QStringList failed = jarlibDownloadJob->getFailedFiles();
|
QStringList failed = jarlibDownloadJob->getFailedFiles();
|
||||||
QString failed_all = failed.join("\n");
|
QString failed_all = failed.join("\n");
|
||||||
emitFailed("Failed to download the following files:\n" + failed_all +
|
emitFailed(tr("Failed to download the following files:\n%1\n\nPlease try again.").arg(failed_all));
|
||||||
"\n\nPlease try again.");
|
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,8 @@ OneSixVersionBuilder::OneSixVersionBuilder()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void OneSixVersionBuilder::build(VersionFinal *version, OneSixInstance *instance, const bool onlyVanilla, const QStringList &external)
|
void OneSixVersionBuilder::build(VersionFinal *version, OneSixInstance *instance,
|
||||||
|
const bool onlyVanilla, const QStringList &external)
|
||||||
{
|
{
|
||||||
OneSixVersionBuilder builder;
|
OneSixVersionBuilder builder;
|
||||||
builder.m_version = version;
|
builder.m_version = version;
|
||||||
@ -46,7 +47,8 @@ void OneSixVersionBuilder::build(VersionFinal *version, OneSixInstance *instance
|
|||||||
builder.buildInternal(onlyVanilla, external);
|
builder.buildInternal(onlyVanilla, external);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OneSixVersionBuilder::readJsonAndApplyToVersion(VersionFinal *version, const QJsonObject &obj)
|
void OneSixVersionBuilder::readJsonAndApplyToVersion(VersionFinal *version,
|
||||||
|
const QJsonObject &obj)
|
||||||
{
|
{
|
||||||
OneSixVersionBuilder builder;
|
OneSixVersionBuilder builder;
|
||||||
builder.m_version = version;
|
builder.m_version = version;
|
||||||
@ -62,10 +64,12 @@ void OneSixVersionBuilder::buildInternal(const bool onlyVanilla, const QStringLi
|
|||||||
QDir patches(root.absoluteFilePath("patches/"));
|
QDir patches(root.absoluteFilePath("patches/"));
|
||||||
|
|
||||||
// if we do external files, do just those.
|
// if we do external files, do just those.
|
||||||
if(!external.isEmpty()) for (auto fileName : external)
|
if (!external.isEmpty())
|
||||||
|
for (auto fileName : external)
|
||||||
{
|
{
|
||||||
QLOG_INFO() << "Reading" << fileName;
|
QLOG_INFO() << "Reading" << fileName;
|
||||||
auto file = parseJsonFile(QFileInfo(fileName), false, fileName.endsWith("pack.json"));
|
auto file =
|
||||||
|
parseJsonFile(QFileInfo(fileName), false, fileName.endsWith("pack.json"));
|
||||||
file->name = QFileInfo(fileName).fileName();
|
file->name = QFileInfo(fileName).fileName();
|
||||||
file->fileId = "org.multimc.external." + file->name;
|
file->fileId = "org.multimc.external." + file->name;
|
||||||
file->version = QString();
|
file->version = QString();
|
||||||
@ -84,11 +88,13 @@ void OneSixVersionBuilder::buildInternal(const bool onlyVanilla, const QStringLi
|
|||||||
file->version = QString();
|
file->version = QString();
|
||||||
file->applyTo(m_version);
|
file->applyTo(m_version);
|
||||||
m_version->versionFiles.append(file);
|
m_version->versionFiles.append(file);
|
||||||
// QObject::tr("The version descriptors of this instance are not compatible with the current version of MultiMC"));
|
// QObject::tr("The version descriptors of this instance are not compatible with the
|
||||||
|
// current version of MultiMC"));
|
||||||
// QObject::tr("Error while applying %1. Please check MultiMC-0.log for more info.")
|
// QObject::tr("Error while applying %1. Please check MultiMC-0.log for more info.")
|
||||||
}
|
}
|
||||||
// version.json -> patches/*.json -> user.json
|
// version.json -> patches/*.json -> user.json
|
||||||
else do
|
else
|
||||||
|
do
|
||||||
{
|
{
|
||||||
// version.json
|
// version.json
|
||||||
QLOG_INFO() << "Reading version.json";
|
QLOG_INFO() << "Reading version.json";
|
||||||
@ -99,7 +105,8 @@ void OneSixVersionBuilder::buildInternal(const bool onlyVanilla, const QStringLi
|
|||||||
file->mcVersion = m_instance->intendedVersionId();
|
file->mcVersion = m_instance->intendedVersionId();
|
||||||
file->applyTo(m_version);
|
file->applyTo(m_version);
|
||||||
m_version->versionFiles.append(file);
|
m_version->versionFiles.append(file);
|
||||||
// QObject::tr("Error while applying %1. Please check MultiMC-0.log for more info.").arg(root.absoluteFilePath("version.json")));
|
// QObject::tr("Error while applying %1. Please check MultiMC-0.log for more
|
||||||
|
// info.").arg(root.absoluteFilePath("version.json")));
|
||||||
|
|
||||||
if (onlyVanilla)
|
if (onlyVanilla)
|
||||||
break;
|
break;
|
||||||
@ -114,18 +121,19 @@ void OneSixVersionBuilder::buildInternal(const bool onlyVanilla, const QStringLi
|
|||||||
auto file = parseJsonFile(info, true);
|
auto file = parseJsonFile(info, true);
|
||||||
if (files.contains(file->order))
|
if (files.contains(file->order))
|
||||||
{
|
{
|
||||||
throw VersionBuildError(QObject::tr("%1 has the same order as %2").arg(file->fileId, files[file->order].second->fileId));
|
throw VersionBuildError(QObject::tr("%1 has the same order as %2").arg(
|
||||||
|
file->fileId, files[file->order].second->fileId));
|
||||||
}
|
}
|
||||||
files.insert(file->order, qMakePair(info.fileName(), file));
|
files.insert(file->order, qMakePair(info.fileName(), file));
|
||||||
}
|
}
|
||||||
for (auto order : files.keys())
|
for (auto order : files.keys())
|
||||||
{
|
{
|
||||||
QLOG_DEBUG() << "Applying file with order" << order;
|
QLOG_DEBUG() << "Applying file with order" << order;
|
||||||
auto & filePair = files[order];
|
auto &filePair = files[order];
|
||||||
filePair.second->applyTo(m_version);
|
filePair.second->applyTo(m_version);
|
||||||
m_version->versionFiles.append(filePair.second);
|
m_version->versionFiles.append(filePair.second);
|
||||||
}
|
}
|
||||||
} while(0);
|
} while (0);
|
||||||
|
|
||||||
// some final touches
|
// some final touches
|
||||||
finalizeVersion();
|
finalizeVersion();
|
||||||
@ -168,26 +176,30 @@ void OneSixVersionBuilder::readJsonAndApply(const QJsonObject &obj)
|
|||||||
file->applyTo(m_version);
|
file->applyTo(m_version);
|
||||||
m_version->versionFiles.append(file);
|
m_version->versionFiles.append(file);
|
||||||
// QObject::tr("Error while applying. Please check MultiMC-0.log for more info."));
|
// QObject::tr("Error while applying. Please check MultiMC-0.log for more info."));
|
||||||
// QObject::tr("The version descriptors of this instance are not compatible with the current version of MultiMC"));
|
// QObject::tr("The version descriptors of this instance are not compatible with the current
|
||||||
|
// version of MultiMC"));
|
||||||
}
|
}
|
||||||
|
|
||||||
VersionFilePtr OneSixVersionBuilder::parseJsonFile(const QFileInfo &fileInfo, const bool requireOrder, bool isFTB)
|
VersionFilePtr OneSixVersionBuilder::parseJsonFile(const QFileInfo &fileInfo,
|
||||||
|
const bool requireOrder, bool isFTB)
|
||||||
{
|
{
|
||||||
QFile file(fileInfo.absoluteFilePath());
|
QFile file(fileInfo.absoluteFilePath());
|
||||||
if (!file.open(QFile::ReadOnly))
|
if (!file.open(QFile::ReadOnly))
|
||||||
{
|
{
|
||||||
throw JSONValidationError(QObject::tr("Unable to open %1: %2").arg(file.fileName(), file.errorString()));
|
throw JSONValidationError(QObject::tr("Unable to open the version file %1: %2.")
|
||||||
|
.arg(fileInfo.fileName(), file.errorString()));
|
||||||
}
|
}
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(file.readAll(), &error);
|
QJsonDocument doc = QJsonDocument::fromJson(file.readAll(), &error);
|
||||||
if (error.error != QJsonParseError::NoError)
|
if (error.error != QJsonParseError::NoError)
|
||||||
{
|
{
|
||||||
throw JSONValidationError(QObject::tr("Unable to parse %1: %2 at %3")
|
throw JSONValidationError(QObject::tr("Unable to process the version file %1: %2 at %3.")
|
||||||
.arg(file.fileName(), error.errorString())
|
.arg(fileInfo.fileName(), error.errorString())
|
||||||
.arg(error.offset));
|
.arg(error.offset));
|
||||||
}
|
}
|
||||||
return VersionFile::fromJson(doc, file.fileName(), requireOrder, isFTB);
|
return VersionFile::fromJson(doc, file.fileName(), requireOrder, isFTB);
|
||||||
// QObject::tr("Error while reading %1. Please check MultiMC-0.log for more info.").arg(file.fileName());
|
// QObject::tr("Error while reading %1. Please check MultiMC-0.log for more
|
||||||
|
// info.").arg(file.fileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QString, int> OneSixVersionBuilder::readOverrideOrders(OneSixInstance *instance)
|
QMap<QString, int> OneSixVersionBuilder::readOverrideOrders(OneSixInstance *instance)
|
||||||
@ -211,7 +223,7 @@ QMap<QString, int> OneSixVersionBuilder::readOverrideOrders(OneSixInstance *inst
|
|||||||
// and it's valid JSON
|
// and it's valid JSON
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(orderFile.readAll(), &error);
|
QJsonDocument doc = QJsonDocument::fromJson(orderFile.readAll(), &error);
|
||||||
if (error.error != QJsonParseError::NoError )
|
if (error.error != QJsonParseError::NoError)
|
||||||
{
|
{
|
||||||
QLOG_ERROR() << "Couldn't parse" << orderFile.fileName() << ":" << error.errorString();
|
QLOG_ERROR() << "Couldn't parse" << orderFile.fileName() << ":" << error.errorString();
|
||||||
QLOG_WARN() << "Ignoring overriden order";
|
QLOG_WARN() << "Ignoring overriden order";
|
||||||
@ -231,7 +243,7 @@ QMap<QString, int> OneSixVersionBuilder::readOverrideOrders(OneSixInstance *inst
|
|||||||
out.insert(it.key(), MMCJson::ensureInteger(it.value()));
|
out.insert(it.key(), MMCJson::ensureInteger(it.value()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (JSONValidationError err)
|
catch (JSONValidationError &err)
|
||||||
{
|
{
|
||||||
QLOG_ERROR() << "Couldn't parse" << orderFile.fileName() << ": bad file format";
|
QLOG_ERROR() << "Couldn't parse" << orderFile.fileName() << ": bad file format";
|
||||||
QLOG_WARN() << "Ignoring overriden order";
|
QLOG_WARN() << "Ignoring overriden order";
|
||||||
@ -262,4 +274,3 @@ bool OneSixVersionBuilder::writeOverrideOrders(const QMap<QString, int> &order,
|
|||||||
orderFile.write(QJsonDocument(obj).toJson(QJsonDocument::Indented));
|
orderFile.write(QJsonDocument(obj).toJson(QJsonDocument::Indented));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,9 +311,7 @@ void VersionFile::applyTo(VersionFinal *version)
|
|||||||
{
|
{
|
||||||
if (minimumLauncherVersion > CURRENT_MINIMUM_LAUNCHER_VERSION)
|
if (minimumLauncherVersion > CURRENT_MINIMUM_LAUNCHER_VERSION)
|
||||||
{
|
{
|
||||||
throw VersionBuildError(
|
throw LauncherVersionError(minimumLauncherVersion, CURRENT_MINIMUM_LAUNCHER_VERSION);
|
||||||
QString("%1 is for a different launcher version (%2), current supported is %3")
|
|
||||||
.arg(filename, minimumLauncherVersion, CURRENT_MINIMUM_LAUNCHER_VERSION));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,8 +320,7 @@ void VersionFile::applyTo(VersionFinal *version)
|
|||||||
if (QRegExp(mcVersion, Qt::CaseInsensitive, QRegExp::Wildcard).indexIn(version->id) ==
|
if (QRegExp(mcVersion, Qt::CaseInsensitive, QRegExp::Wildcard).indexIn(version->id) ==
|
||||||
-1)
|
-1)
|
||||||
{
|
{
|
||||||
throw VersionBuildError(
|
throw MinecraftVersionMismatch(fileId, mcVersion, version->id);
|
||||||
QString("%1 is for a different version of Minecraft").arg(filename));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,7 +468,7 @@ void VersionFile::applyTo(VersionFinal *version)
|
|||||||
(lib->dependType == RawLibrary::Hard && ourVersion != otherVersion))
|
(lib->dependType == RawLibrary::Hard && ourVersion != otherVersion))
|
||||||
{
|
{
|
||||||
throw VersionBuildError(
|
throw VersionBuildError(
|
||||||
QString(
|
QObject::tr(
|
||||||
"Error resolving library dependencies between %1 and %2 in %3.")
|
"Error resolving library dependencies between %1 and %2 in %3.")
|
||||||
.arg(otherLib->rawName(), lib->name, filename));
|
.arg(otherLib->rawName(), lib->name, filename));
|
||||||
}
|
}
|
||||||
@ -498,7 +495,7 @@ void VersionFile::applyTo(VersionFinal *version)
|
|||||||
// it: fail
|
// it: fail
|
||||||
if (lib->dependType == RawLibrary::Hard)
|
if (lib->dependType == RawLibrary::Hard)
|
||||||
{
|
{
|
||||||
throw VersionBuildError(QString(
|
throw VersionBuildError(QObject::tr(
|
||||||
"Error resolving library dependencies between %1 and %2 in %3.")
|
"Error resolving library dependencies between %1 and %2 in %3.")
|
||||||
.arg(otherLib->rawName(), lib->name,
|
.arg(otherLib->rawName(), lib->name,
|
||||||
filename));
|
filename));
|
||||||
|
@ -13,13 +13,39 @@ class VersionBuildError : public MMCError
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
VersionBuildError(QString cause) : MMCError(cause) {};
|
VersionBuildError(QString cause) : MMCError(cause) {};
|
||||||
virtual QString errorName()
|
|
||||||
{
|
|
||||||
return "VersionBuildError";
|
|
||||||
};
|
|
||||||
virtual ~VersionBuildError() {};
|
virtual ~VersionBuildError() {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the base version file was meant for a newer version of the vanilla launcher than we support
|
||||||
|
*/
|
||||||
|
class LauncherVersionError : public VersionBuildError
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LauncherVersionError(int actual, int supported)
|
||||||
|
: VersionBuildError(QObject::tr(
|
||||||
|
"The base version file of this instance was meant for a newer (%1) "
|
||||||
|
"version of the vanilla launcher than this version of MultiMC supports (%2).")
|
||||||
|
.arg(actual)
|
||||||
|
.arg(supported)) {};
|
||||||
|
virtual ~LauncherVersionError() {};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* some patch was intended for a different version of minecraft
|
||||||
|
*/
|
||||||
|
class MinecraftVersionMismatch : public VersionBuildError
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MinecraftVersionMismatch(QString fileId, QString mcVersion, QString parentMcVersion)
|
||||||
|
: VersionBuildError(QObject::tr("The patch %1 is for a different version of Minecraft "
|
||||||
|
"(%2) than that of the instance (%3).")
|
||||||
|
.arg(fileId)
|
||||||
|
.arg(mcVersion)
|
||||||
|
.arg(parentMcVersion)) {};
|
||||||
|
virtual ~MinecraftVersionMismatch() {};
|
||||||
|
};
|
||||||
|
|
||||||
struct RawLibrary;
|
struct RawLibrary;
|
||||||
typedef std::shared_ptr<RawLibrary> RawLibraryPtr;
|
typedef std::shared_ptr<RawLibrary> RawLibraryPtr;
|
||||||
struct RawLibrary
|
struct RawLibrary
|
||||||
|
@ -112,7 +112,7 @@ std::shared_ptr<VersionFinal> VersionFinal::fromJson(const QJsonObject &obj)
|
|||||||
{
|
{
|
||||||
OneSixVersionBuilder::readJsonAndApplyToVersion(version.get(), obj);
|
OneSixVersionBuilder::readJsonAndApplyToVersion(version.get(), obj);
|
||||||
}
|
}
|
||||||
catch(MMCError err)
|
catch(MMCError & err)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user