GH-1856 Make MultiMC fail hard when things are missing

Things like:
* jar mods
* valid version files
This commit is contained in:
Petr Mrázek 2017-04-23 02:31:13 +02:00
parent b414bbe395
commit 3f24c4cfe5
12 changed files with 57 additions and 98 deletions

View File

@ -263,7 +263,6 @@ set(MINECRAFT_SOURCES
minecraft/Library.cpp minecraft/Library.cpp
minecraft/Library.h minecraft/Library.h
minecraft/MojangDownloadInfo.h minecraft/MojangDownloadInfo.h
minecraft/VersionBuildError.h
minecraft/VersionFile.cpp minecraft/VersionFile.cpp
minecraft/VersionFile.h minecraft/VersionFile.h
minecraft/ProfilePatch.cpp minecraft/ProfilePatch.cpp

View File

@ -279,6 +279,14 @@ bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const
qDebug() << "Adding folder " << filename.fileName() << " from " qDebug() << "Adding folder " << filename.fileName() << " from "
<< filename.absoluteFilePath(); << filename.absoluteFilePath();
} }
else
{
// Make sure we do not continue launching when something is missing or undefined...
zipOut.close();
QFile::remove(targetJarPath);
qCritical() << "Failed to add unknown mod type" << mod.filename().fileName() << "to the jar.";
return false;
}
} }
if (!mergeZipFiles(&zipOut, QFileInfo(sourceJarPath), addedFiles, metaInfFilter)) if (!mergeZipFiles(&zipOut, QFileInfo(sourceJarPath), addedFiles, metaInfFilter))

View File

@ -177,11 +177,11 @@ bool MinecraftProfile::revertToBase(int index)
ProfilePatchPtr MinecraftProfile::versionPatch(const QString &id) ProfilePatchPtr MinecraftProfile::versionPatch(const QString &id)
{ {
for (auto file : m_patches) for (auto patch : m_patches)
{ {
if (file->getID() == id) if (patch->getID() == id)
{ {
return file; return patch;
} }
} }
return nullptr; return nullptr;

View File

@ -1,6 +1,5 @@
#include "MojangVersionFormat.h" #include "MojangVersionFormat.h"
#include "onesix/OneSixVersionFormat.h" #include "onesix/OneSixVersionFormat.h"
#include "VersionBuildError.h"
#include "MojangDownloadInfo.h" #include "MojangDownloadInfo.h"
#include "Json.h" #include "Json.h"

View File

@ -5,6 +5,7 @@
#include "meta/Version.h" #include "meta/Version.h"
#include "VersionFile.h" #include "VersionFile.h"
#include "minecraft/MinecraftProfile.h"
ProfilePatch::ProfilePatch(std::shared_ptr<Meta::Version> version) ProfilePatch::ProfilePatch(std::shared_ptr<Meta::Version> version)
:m_metaVersion(version) :m_metaVersion(version)
@ -23,6 +24,10 @@ void ProfilePatch::applyTo(MinecraftProfile* profile)
{ {
vfile->applyTo(profile); vfile->applyTo(profile);
} }
else
{
profile->applyProblemSeverity(getProblemSeverity());
}
} }
std::shared_ptr<class VersionFile> ProfilePatch::getVersionFile() std::shared_ptr<class VersionFile> ProfilePatch::getVersionFile()
@ -35,8 +40,11 @@ std::shared_ptr<class VersionFile> ProfilePatch::getVersionFile()
} }
return m_metaVersion->data(); return m_metaVersion->data();
} }
else
{
return m_file; return m_file;
} }
}
std::shared_ptr<class Meta::VersionList> ProfilePatch::getVersionList() std::shared_ptr<class Meta::VersionList> ProfilePatch::getVersionList()
{ {

View File

@ -48,7 +48,6 @@ public:
void setRevertible (bool state); void setRevertible (bool state);
void setMovable (bool state); void setMovable (bool state);
const QList<PatchProblem> getProblems() override; const QList<PatchProblem> getProblems() override;
ProblemSeverity getProblemSeverity() override; ProblemSeverity getProblemSeverity() override;

View File

@ -1,41 +0,0 @@
#include "Exception.h"
class VersionBuildError : public Exception
{
public:
explicit VersionBuildError(QString cause) : Exception(cause) {}
virtual ~VersionBuildError() noexcept
{
}
};
/**
* 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() noexcept
{
}
};
/**
* files required for the version are not (yet?) present
*/
class VersionIncomplete : public VersionBuildError
{
public:
VersionIncomplete(QString missingPatch)
: VersionBuildError(QObject::tr("Version is incomplete: missing %1.")
.arg(missingPatch)) {};
virtual ~VersionIncomplete() noexcept
{
}
};

View File

@ -8,7 +8,6 @@
#include "minecraft/MinecraftProfile.h" #include "minecraft/MinecraftProfile.h"
#include "ParseUtils.h" #include "ParseUtils.h"
#include "VersionBuildError.h"
#include <Version.h> #include <Version.h>
static bool isMinecraftVersion(const QString &uid) static bool isMinecraftVersion(const QString &uid)

View File

@ -1,7 +1,6 @@
#include "FTBProfileStrategy.h" #include "FTBProfileStrategy.h"
#include "OneSixFTBInstance.h" #include "OneSixFTBInstance.h"
#include "minecraft/VersionBuildError.h"
#include <FileSystem.h> #include <FileSystem.h>
#include <QDir> #include <QDir>
@ -22,41 +21,43 @@ void FTBProfileStrategy::loadDefaultBuiltinPatches()
ProfilePatchPtr minecraftPatch; ProfilePatchPtr minecraftPatch;
{ {
std::shared_ptr< VersionFile > file;
auto mcJson = m_instance->versionsPath().absoluteFilePath(mcVersion + "/" + mcVersion + ".json"); auto mcJson = m_instance->versionsPath().absoluteFilePath(mcVersion + "/" + mcVersion + ".json");
// load up the base minecraft patch // load up the base minecraft patch
if(QFile::exists(mcJson)) if(QFile::exists(mcJson))
{ {
auto file = ProfileUtils::parseJsonFile(QFileInfo(mcJson), false); file = ProfileUtils::parseJsonFile(QFileInfo(mcJson), false);
for(auto addLib: file->libraries)
{
addLib->setHint("local");
addLib->setStoragePrefix(nativeInstance->librariesPath().absolutePath());
}
}
else
{
file = std::make_shared<VersionFile>();
file->addProblem(ProblemSeverity::Error, QObject::tr("Minecraft version is missing in the FTB data."));
}
file->uid = "net.minecraft"; file->uid = "net.minecraft";
file->name = QObject::tr("Minecraft (tracked)"); file->name = QObject::tr("Minecraft (tracked)");
if(file->version.isEmpty()) if(file->version.isEmpty())
{ {
file->version = mcVersion; file->version = mcVersion;
} }
for(auto addLib: file->libraries)
{
addLib->setHint("local");
addLib->setStoragePrefix(nativeInstance->librariesPath().absolutePath());
}
minecraftPatch = std::make_shared<ProfilePatch>(file); minecraftPatch = std::make_shared<ProfilePatch>(file);
minecraftPatch->setVanilla(true); minecraftPatch->setVanilla(true);
}
else
{
throw VersionIncomplete("net.minecraft : " + mcJson);
}
minecraftPatch->setOrder(-2); minecraftPatch->setOrder(-2);
} }
profile->appendPatch(minecraftPatch); profile->appendPatch(minecraftPatch);
ProfilePatchPtr packPatch; ProfilePatchPtr packPatch;
{ {
std::shared_ptr< VersionFile > file;
auto mcJson = m_instance->minecraftRoot() + "/pack.json"; auto mcJson = m_instance->minecraftRoot() + "/pack.json";
// load up the base minecraft patch // load up the base minecraft patch, if it's there...
if(QFile::exists(mcJson)) if(QFile::exists(mcJson))
{ {
auto file = ProfileUtils::parseJsonFile(QFileInfo(mcJson), false); file = ProfileUtils::parseJsonFile(QFileInfo(mcJson), false);
// adapt the loaded file - the FTB patch file format is different than ours. // adapt the loaded file - the FTB patch file format is different than ours.
file->minecraftVersion.clear(); file->minecraftVersion.clear();
file->mainJar = nullptr; file->mainJar = nullptr;
@ -65,6 +66,12 @@ void FTBProfileStrategy::loadDefaultBuiltinPatches()
addLib->setHint("local"); addLib->setHint("local");
addLib->setStoragePrefix(nativeInstance->librariesPath().absolutePath()); addLib->setStoragePrefix(nativeInstance->librariesPath().absolutePath());
} }
}
else
{
file = std::make_shared<VersionFile>();
file->addProblem(ProblemSeverity::Error, QObject::tr("Modpack version file is missing."));
}
file->uid = "org.multimc.ftb.pack"; file->uid = "org.multimc.ftb.pack";
file->name = QObject::tr("%1 (FTB pack)").arg(m_instance->name()); file->name = QObject::tr("%1 (FTB pack)").arg(m_instance->name());
if(file->version.isEmpty()) if(file->version.isEmpty())
@ -83,15 +90,9 @@ void FTBProfileStrategy::loadDefaultBuiltinPatches()
} }
packPatch = std::make_shared<ProfilePatch>(file); packPatch = std::make_shared<ProfilePatch>(file);
packPatch->setVanilla(true); packPatch->setVanilla(true);
}
else
{
throw VersionIncomplete("org.multimc.ftb.pack : " + mcJson);
}
packPatch->setOrder(1); packPatch->setOrder(1);
} }
profile->appendPatch(packPatch); profile->appendPatch(packPatch);
} }
void FTBProfileStrategy::load() void FTBProfileStrategy::load()

View File

@ -23,7 +23,6 @@
#include "OneSixProfileStrategy.h" #include "OneSixProfileStrategy.h"
#include "minecraft/MinecraftProfile.h" #include "minecraft/MinecraftProfile.h"
#include "minecraft/VersionBuildError.h"
#include "minecraft/launch/ModMinecraftJar.h" #include "minecraft/launch/ModMinecraftJar.h"
#include "MMCZip.h" #include "MMCZip.h"

View File

@ -2,7 +2,6 @@
#include "OneSixInstance.h" #include "OneSixInstance.h"
#include "OneSixVersionFormat.h" #include "OneSixVersionFormat.h"
#include "minecraft/VersionBuildError.h"
#include "Env.h" #include "Env.h"
#include <FileSystem.h> #include <FileSystem.h>
@ -107,10 +106,6 @@ void OneSixProfileStrategy::loadDefaultBuiltinPatches()
profilePatch = std::make_shared<ProfilePatch>(metaVersion); profilePatch = std::make_shared<ProfilePatch>(metaVersion);
profilePatch->setVanilla(true); profilePatch->setVanilla(true);
} }
if (!profilePatch)
{
throw VersionIncomplete(uid);
}
profilePatch->setOrder(order); profilePatch->setOrder(order);
profile->appendPatch(profilePatch); profile->appendPatch(profilePatch);
}; };
@ -291,6 +286,7 @@ bool OneSixProfileStrategy::customizePatch(ProfilePatchPtr patch)
{ {
return false; return false;
} }
// FIXME: get rid of this try-catch.
try try
{ {
QSaveFile jsonFile(filename); QSaveFile jsonFile(filename);
@ -311,10 +307,6 @@ bool OneSixProfileStrategy::customizePatch(ProfilePatchPtr patch)
} }
load(); load();
} }
catch (VersionIncomplete &error)
{
qDebug() << "Version was incomplete:" << error.cause();
}
catch (Exception &error) catch (Exception &error)
{ {
qWarning() << "Version could not be loaded:" << error.cause(); qWarning() << "Version could not be loaded:" << error.cause();
@ -337,14 +329,11 @@ bool OneSixProfileStrategy::revertPatch(ProfilePatchPtr patch)
} }
// just kill the file and reload // just kill the file and reload
bool result = QFile::remove(filename); bool result = QFile::remove(filename);
// FIXME: get rid of this try-catch.
try try
{ {
load(); load();
} }
catch (VersionIncomplete &error)
{
qDebug() << "Version was incomplete:" << error.cause();
}
catch (Exception &error) catch (Exception &error)
{ {
qWarning() << "Version could not be loaded:" << error.cause(); qWarning() << "Version could not be loaded:" << error.cause();

View File

@ -1,7 +1,6 @@
#include "OneSixVersionFormat.h" #include "OneSixVersionFormat.h"
#include <Json.h> #include <Json.h>
#include "minecraft/ParseUtils.h" #include "minecraft/ParseUtils.h"
#include <minecraft/VersionBuildError.h>
#include <minecraft/MojangVersionFormat.h> #include <minecraft/MojangVersionFormat.h>
using namespace Json; using namespace Json;