NOISSUE split out the LaunchProfile out of the ComponentList

This commit is contained in:
Petr Mrázek
2017-11-04 22:55:25 +01:00
parent 3470158943
commit 17c8f31a09
16 changed files with 493 additions and 422 deletions

View File

@ -35,7 +35,6 @@ ComponentList::ComponentList(MinecraftInstance * instance)
: QAbstractListModel()
{
m_instance = instance;
clear();
}
ComponentList::~ComponentList()
@ -50,22 +49,6 @@ void ComponentList::reload()
endResetModel();
}
void ComponentList::clear()
{
m_minecraftVersion.clear();
m_minecraftVersionType.clear();
m_minecraftAssets.reset();
m_minecraftArguments.clear();
m_tweakers.clear();
m_mainClass.clear();
m_appletClass.clear();
m_libraries.clear();
m_traits.clear();
m_jarMods.clear();
m_mainJar.reset();
m_problemSeverity = ProblemSeverity::None;
}
void ComponentList::clearPatches()
{
beginResetModel();
@ -365,290 +348,22 @@ bool ComponentList::reapplyPatches()
{
try
{
clear();
m_profile.reset(new LaunchProfile);
for(auto file: m_patches)
{
qDebug() << "Applying" << file->getID() << (file->getProblemSeverity() == ProblemSeverity::Error ? "ERROR" : "GOOD");
file->applyTo(this);
file->applyTo(m_profile.get());
}
}
catch (Exception & error)
{
clear();
m_profile.reset();
qWarning() << "Couldn't apply profile patches because: " << error.cause();
return false;
}
return true;
}
static void applyString(const QString & from, QString & to)
{
if(from.isEmpty())
return;
to = from;
}
void ComponentList::applyMinecraftVersion(const QString& id)
{
applyString(id, this->m_minecraftVersion);
}
void ComponentList::applyAppletClass(const QString& appletClass)
{
applyString(appletClass, this->m_appletClass);
}
void ComponentList::applyMainClass(const QString& mainClass)
{
applyString(mainClass, this->m_mainClass);
}
void ComponentList::applyMinecraftArguments(const QString& minecraftArguments)
{
applyString(minecraftArguments, this->m_minecraftArguments);
}
void ComponentList::applyMinecraftVersionType(const QString& type)
{
applyString(type, this->m_minecraftVersionType);
}
void ComponentList::applyMinecraftAssets(MojangAssetIndexInfo::Ptr assets)
{
if(assets)
{
m_minecraftAssets = assets;
}
}
void ComponentList::applyTraits(const QSet<QString>& traits)
{
this->m_traits.unite(traits);
}
void ComponentList::applyTweakers(const QStringList& tweakers)
{
// if the applied tweakers override an existing one, skip it. this effectively moves it later in the sequence
QStringList newTweakers;
for(auto & tweaker: m_tweakers)
{
if (tweakers.contains(tweaker))
{
continue;
}
newTweakers.append(tweaker);
}
// then just append the new tweakers (or moved original ones)
newTweakers += tweakers;
m_tweakers = newTweakers;
}
void ComponentList::applyJarMods(const QList<LibraryPtr>& jarMods)
{
this->m_jarMods.append(jarMods);
}
static int findLibraryByName(QList<LibraryPtr> *haystack, const GradleSpecifier &needle)
{
int retval = -1;
for (int i = 0; i < haystack->size(); ++i)
{
if (haystack->at(i)->rawName().matchName(needle))
{
// only one is allowed.
if (retval != -1)
return -1;
retval = i;
}
}
return retval;
}
void ComponentList::applyMods(const QList<LibraryPtr>& mods)
{
QList<LibraryPtr> * list = &m_mods;
for(auto & mod: mods)
{
auto modCopy = Library::limitedCopy(mod);
// find the mod by name.
const int index = findLibraryByName(list, mod->rawName());
// mod not found? just add it.
if (index < 0)
{
list->append(modCopy);
return;
}
auto existingLibrary = list->at(index);
// if we are higher it means we should update
if (Version(mod->version()) > Version(existingLibrary->version()))
{
list->replace(index, modCopy);
}
}
}
void ComponentList::applyLibrary(LibraryPtr library)
{
if(!library->isActive())
{
return;
}
QList<LibraryPtr> * list = &m_libraries;
if(library->isNative())
{
list = &m_nativeLibraries;
}
auto libraryCopy = Library::limitedCopy(library);
// find the library by name.
const int index = findLibraryByName(list, library->rawName());
// library not found? just add it.
if (index < 0)
{
list->append(libraryCopy);
return;
}
auto existingLibrary = list->at(index);
// if we are higher it means we should update
if (Version(library->version()) > Version(existingLibrary->version()))
{
list->replace(index, libraryCopy);
}
}
const LibraryPtr ComponentList::getMainJar() const
{
return m_mainJar;
}
void ComponentList::applyMainJar(LibraryPtr jar)
{
if(jar)
{
m_mainJar = jar;
}
}
void ComponentList::applyProblemSeverity(ProblemSeverity severity)
{
if (m_problemSeverity < severity)
{
m_problemSeverity = severity;
}
}
QString ComponentList::getMinecraftVersion() const
{
return m_minecraftVersion;
}
QString ComponentList::getAppletClass() const
{
return m_appletClass;
}
QString ComponentList::getMainClass() const
{
return m_mainClass;
}
const QSet<QString> &ComponentList::getTraits() const
{
return m_traits;
}
const QStringList & ComponentList::getTweakers() const
{
return m_tweakers;
}
bool ComponentList::hasTrait(const QString& trait) const
{
return m_traits.contains(trait);
}
ProblemSeverity ComponentList::getProblemSeverity() const
{
return m_problemSeverity;
}
QString ComponentList::getMinecraftVersionType() const
{
return m_minecraftVersionType;
}
std::shared_ptr<MojangAssetIndexInfo> ComponentList::getMinecraftAssets() const
{
if(!m_minecraftAssets)
{
return std::make_shared<MojangAssetIndexInfo>("legacy");
}
return m_minecraftAssets;
}
QString ComponentList::getMinecraftArguments() const
{
return m_minecraftArguments;
}
const QList<LibraryPtr> & ComponentList::getJarMods() const
{
return m_jarMods;
}
const QList<LibraryPtr> & ComponentList::getLibraries() const
{
return m_libraries;
}
const QList<LibraryPtr> & ComponentList::getNativeLibraries() const
{
return m_nativeLibraries;
}
void ComponentList::getLibraryFiles(const QString& architecture, QStringList& jars, QStringList& nativeJars, const QString& overridePath, const QString& tempPath) const
{
QStringList native32, native64;
jars.clear();
nativeJars.clear();
for (auto lib : getLibraries())
{
lib->getApplicableFiles(currentSystem, jars, nativeJars, native32, native64, overridePath);
}
// NOTE: order is important here, add main jar last to the lists
if(m_mainJar)
{
// FIXME: HACK!! jar modding is weird and unsystematic!
if(m_jarMods.size())
{
QDir tempDir(tempPath);
jars.append(tempDir.absoluteFilePath("minecraft.jar"));
}
else
{
m_mainJar->getApplicableFiles(currentSystem, jars, nativeJars, native32, native64, overridePath);
}
}
for (auto lib : getNativeLibraries())
{
lib->getApplicableFiles(currentSystem, jars, nativeJars, native32, native64, overridePath);
}
if(architecture == "32")
{
nativeJars.append(native32);
}
else if(architecture == "64")
{
nativeJars.append(native64);
}
}
void ComponentList::installJarMods(QStringList selectedFiles)
{
installJarMods_internal(selectedFiles);
@ -1122,4 +837,14 @@ bool ComponentList::installCustomJar_internal(QString filepath)
saveCurrentOrder();
reapplyPatches();
return true;
}
}
std::shared_ptr<LaunchProfile> ComponentList::getProfile() const
{
return m_profile;
}
void ComponentList::clearProfile()
{
m_profile.reset();
}