GH-856 add profile strategy for FTB packs
This commit is contained in:
parent
dc84ac3682
commit
865b200571
@ -557,6 +557,8 @@ SET(MULTIMC_SOURCES
|
||||
logic/ftb/OneSixFTBInstance.cpp
|
||||
logic/ftb/LegacyFTBInstance.h
|
||||
logic/ftb/LegacyFTBInstance.cpp
|
||||
logic/ftb/FTBProfileStrategy.h
|
||||
logic/ftb/FTBProfileStrategy.cpp
|
||||
|
||||
# the screenshots feature
|
||||
logic/screenshots/Screenshot.h
|
||||
|
163
logic/ftb/FTBProfileStrategy.cpp
Normal file
163
logic/ftb/FTBProfileStrategy.cpp
Normal file
@ -0,0 +1,163 @@
|
||||
#include "logic/ftb/FTBProfileStrategy.h"
|
||||
#include "logic/minecraft/VersionBuildError.h"
|
||||
#include "logic/ftb/OneSixFTBInstance.h"
|
||||
#include "logic/minecraft/MinecraftVersionList.h"
|
||||
|
||||
#include "MultiMC.h"
|
||||
|
||||
#include <pathutils.h>
|
||||
#include <QDir>
|
||||
#include <QUuid>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
|
||||
FTBProfileStrategy::FTBProfileStrategy(OneSixFTBInstance* instance) : OneSixProfileStrategy(instance)
|
||||
{
|
||||
}
|
||||
|
||||
void FTBProfileStrategy::loadDefaultBuiltinPatches()
|
||||
{
|
||||
auto mcVersion = m_instance->intendedVersionId();
|
||||
|
||||
ProfilePatchPtr minecraftPatch;
|
||||
{
|
||||
auto mcJson = m_instance->versionsPath().absoluteFilePath(mcVersion + "/" + mcVersion + ".json");
|
||||
// load up the base minecraft patch
|
||||
if(QFile::exists(mcJson))
|
||||
{
|
||||
auto file = ProfileUtils::parseJsonFile(QFileInfo(mcJson), false);
|
||||
file->fileId = "net.minecraft";
|
||||
file->name = "Minecraft (FTB tracked)";
|
||||
if(file->version.isEmpty())
|
||||
{
|
||||
file->version = mcVersion;
|
||||
}
|
||||
minecraftPatch = std::dynamic_pointer_cast<ProfilePatch>(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw VersionIncomplete("net.minecraft");
|
||||
}
|
||||
minecraftPatch->setOrder(-2);
|
||||
}
|
||||
profile->appendPatch(minecraftPatch);
|
||||
|
||||
ProfilePatchPtr packPatch;
|
||||
{
|
||||
auto mcJson = m_instance->minecraftRoot() + "/pack.json";
|
||||
// load up the base minecraft patch
|
||||
if(QFile::exists(mcJson))
|
||||
{
|
||||
auto file = ProfileUtils::parseJsonFile(QFileInfo(mcJson), false, true);
|
||||
file->fileId = "org.multimc.ftb.pack";
|
||||
file->name = QString("%1 (FTB tracked)").arg(m_instance->name());
|
||||
if(file->version.isEmpty())
|
||||
{
|
||||
file->version = mcVersion;
|
||||
}
|
||||
minecraftPatch = std::dynamic_pointer_cast<ProfilePatch>(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw VersionIncomplete("org.multimc.ftb.pack");
|
||||
}
|
||||
minecraftPatch->setOrder(1);
|
||||
}
|
||||
profile->appendPatch(minecraftPatch);
|
||||
|
||||
}
|
||||
|
||||
void FTBProfileStrategy::loadUserPatches()
|
||||
{
|
||||
// load all patches, put into map for ordering, apply in the right order
|
||||
ProfileUtils::PatchOrder userOrder;
|
||||
ProfileUtils::readOverrideOrders(PathCombine(m_instance->instanceRoot(), "order.json"), userOrder);
|
||||
QDir patches(PathCombine(m_instance->instanceRoot(),"patches"));
|
||||
|
||||
// first, load things by sort order.
|
||||
for (auto id : userOrder)
|
||||
{
|
||||
// ignore builtins
|
||||
if (id == "net.minecraft")
|
||||
continue;
|
||||
if (id == "org.lwjgl")
|
||||
continue;
|
||||
// parse the file
|
||||
QString filename = patches.absoluteFilePath(id + ".json");
|
||||
QFileInfo finfo(filename);
|
||||
if(!finfo.exists())
|
||||
{
|
||||
QLOG_INFO() << "Patch file " << filename << " was deleted by external means...";
|
||||
continue;
|
||||
}
|
||||
QLOG_INFO() << "Reading" << filename << "by user order";
|
||||
auto file = ProfileUtils::parseJsonFile(finfo, false);
|
||||
// sanity check. prevent tampering with files.
|
||||
if (file->fileId != id)
|
||||
{
|
||||
throw VersionBuildError(
|
||||
QObject::tr("load id %1 does not match internal id %2").arg(id, file->fileId));
|
||||
}
|
||||
profile->appendPatch(file);
|
||||
}
|
||||
// now load the rest by internal preference.
|
||||
QMap<int, QPair<QString, VersionFilePtr>> files;
|
||||
for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files))
|
||||
{
|
||||
// parse the file
|
||||
QLOG_INFO() << "Reading" << info.fileName();
|
||||
auto file = ProfileUtils::parseJsonFile(info, true);
|
||||
// ignore builtins
|
||||
if (file->fileId == "net.minecraft")
|
||||
continue;
|
||||
if (file->fileId == "org.lwjgl")
|
||||
continue;
|
||||
// do not load what we already loaded in the first pass
|
||||
if (userOrder.contains(file->fileId))
|
||||
continue;
|
||||
if (files.contains(file->order))
|
||||
{
|
||||
// FIXME: do not throw?
|
||||
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));
|
||||
}
|
||||
for (auto order : files.keys())
|
||||
{
|
||||
auto &filePair = files[order];
|
||||
profile->appendPatch(filePair.second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FTBProfileStrategy::load()
|
||||
{
|
||||
profile->clearPatches();
|
||||
|
||||
loadDefaultBuiltinPatches();
|
||||
loadUserPatches();
|
||||
|
||||
profile->finalize();
|
||||
}
|
||||
|
||||
bool FTBProfileStrategy::saveOrder(ProfileUtils::PatchOrder order)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FTBProfileStrategy::resetOrder()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FTBProfileStrategy::removePatch(ProfilePatchPtr patch)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FTBProfileStrategy::installJarMods(QStringList filepaths)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
21
logic/ftb/FTBProfileStrategy.h
Normal file
21
logic/ftb/FTBProfileStrategy.h
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "../minecraft/ProfileStrategy.h"
|
||||
#include "../minecraft/OneSixProfileStrategy.h"
|
||||
|
||||
class OneSixFTBInstance;
|
||||
|
||||
class FTBProfileStrategy : public OneSixProfileStrategy
|
||||
{
|
||||
public:
|
||||
FTBProfileStrategy(OneSixFTBInstance * instance);
|
||||
virtual ~FTBProfileStrategy() {};
|
||||
virtual void load() override;
|
||||
virtual bool resetOrder() override;
|
||||
virtual bool saveOrder(ProfileUtils::PatchOrder order) override;
|
||||
virtual bool installJarMods(QStringList filepaths) override;
|
||||
virtual bool removePatch(ProfilePatchPtr patch) override;
|
||||
|
||||
protected:
|
||||
void loadDefaultBuiltinPatches();
|
||||
void loadUserPatches();
|
||||
};
|
@ -1,4 +1,5 @@
|
||||
#include "OneSixFTBInstance.h"
|
||||
#include "FTBProfileStrategy.h"
|
||||
|
||||
#include "logic/minecraft/MinecraftProfile.h"
|
||||
#include "logic/minecraft/OneSixLibrary.h"
|
||||
@ -109,19 +110,16 @@ QDir OneSixFTBInstance::versionsPath() const
|
||||
return QDir(MMC->settings()->get("FTBRoot").toString() + "/versions");
|
||||
}
|
||||
|
||||
/*
|
||||
QStringList OneSixFTBInstance::externalPatches() const
|
||||
{
|
||||
return QStringList() << versionsPath().absoluteFilePath(intendedVersionId() + "/" + intendedVersionId() + ".json")
|
||||
<< minecraftRoot() + "/pack.json";
|
||||
}
|
||||
*/
|
||||
|
||||
bool OneSixFTBInstance::providesVersionFile() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void OneSixFTBInstance::createProfile()
|
||||
{
|
||||
m_version.reset(new MinecraftProfile(new FTBProfileStrategy(this)));
|
||||
}
|
||||
|
||||
QString OneSixFTBInstance::getStatusbarDescription()
|
||||
{
|
||||
if (flags() & VersionBrokenFlag)
|
||||
|
@ -14,6 +14,8 @@ public:
|
||||
|
||||
void copy(const QDir &newDir) override;
|
||||
|
||||
virtual void createProfile();
|
||||
|
||||
virtual QString getStatusbarDescription();
|
||||
|
||||
virtual std::shared_ptr<Task> doUpdate() override;
|
||||
@ -23,7 +25,4 @@ public:
|
||||
QDir librariesPath() const override;
|
||||
QDir versionsPath() const override;
|
||||
bool providesVersionFile() const override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<OneSixLibrary> m_forge;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user