2017-11-05 03:25:25 +05:30
|
|
|
#include "LaunchProfile.h"
|
|
|
|
#include <Version.h>
|
|
|
|
|
|
|
|
void LaunchProfile::clear()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
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;
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static void applyString(const QString & from, QString & to)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if(from.isEmpty())
|
|
|
|
return;
|
|
|
|
to = from;
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchProfile::applyMinecraftVersion(const QString& id)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
applyString(id, this->m_minecraftVersion);
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchProfile::applyAppletClass(const QString& appletClass)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
applyString(appletClass, this->m_appletClass);
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchProfile::applyMainClass(const QString& mainClass)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
applyString(mainClass, this->m_mainClass);
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchProfile::applyMinecraftArguments(const QString& minecraftArguments)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
applyString(minecraftArguments, this->m_minecraftArguments);
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchProfile::applyMinecraftVersionType(const QString& type)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
applyString(type, this->m_minecraftVersionType);
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchProfile::applyMinecraftAssets(MojangAssetIndexInfo::Ptr assets)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if(assets)
|
|
|
|
{
|
|
|
|
m_minecraftAssets = assets;
|
|
|
|
}
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchProfile::applyTraits(const QSet<QString>& traits)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
this->m_traits.unite(traits);
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchProfile::applyTweakers(const QStringList& tweakers)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
// 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;
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchProfile::applyJarMods(const QList<LibraryPtr>& jarMods)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
this->m_jarMods.append(jarMods);
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static int findLibraryByName(QList<LibraryPtr> *haystack, const GradleSpecifier &needle)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
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;
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchProfile::applyMods(const QList<LibraryPtr>& mods)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchProfile::applyLibrary(LibraryPtr library)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if(!library->isActive())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-11-05 03:25:25 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
QList<LibraryPtr> * list = &m_libraries;
|
|
|
|
if(library->isNative())
|
|
|
|
{
|
|
|
|
list = &m_nativeLibraries;
|
|
|
|
}
|
2017-11-05 03:25:25 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
auto libraryCopy = Library::limitedCopy(library);
|
2017-11-05 03:25:25 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
// 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;
|
|
|
|
}
|
2017-11-05 03:25:25 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
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);
|
|
|
|
}
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
const LibraryPtr LaunchProfile::getMainJar() const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
return m_mainJar;
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchProfile::applyMainJar(LibraryPtr jar)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if(jar)
|
|
|
|
{
|
|
|
|
m_mainJar = jar;
|
|
|
|
}
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchProfile::applyProblemSeverity(ProblemSeverity severity)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if (m_problemSeverity < severity)
|
|
|
|
{
|
|
|
|
m_problemSeverity = severity;
|
|
|
|
}
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
const QList<PatchProblem> LaunchProfile::getProblems() const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
// FIXME: implement something that actually makes sense here
|
|
|
|
return {};
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
QString LaunchProfile::getMinecraftVersion() const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
return m_minecraftVersion;
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
QString LaunchProfile::getAppletClass() const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
return m_appletClass;
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
QString LaunchProfile::getMainClass() const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
return m_mainClass;
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
const QSet<QString> &LaunchProfile::getTraits() const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
return m_traits;
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
const QStringList & LaunchProfile::getTweakers() const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
return m_tweakers;
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
bool LaunchProfile::hasTrait(const QString& trait) const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
return m_traits.contains(trait);
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
ProblemSeverity LaunchProfile::getProblemSeverity() const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
return m_problemSeverity;
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
QString LaunchProfile::getMinecraftVersionType() const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
return m_minecraftVersionType;
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<MojangAssetIndexInfo> LaunchProfile::getMinecraftAssets() const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if(!m_minecraftAssets)
|
|
|
|
{
|
|
|
|
return std::make_shared<MojangAssetIndexInfo>("legacy");
|
|
|
|
}
|
|
|
|
return m_minecraftAssets;
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
QString LaunchProfile::getMinecraftArguments() const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
return m_minecraftArguments;
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
const QList<LibraryPtr> & LaunchProfile::getJarMods() const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
return m_jarMods;
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
const QList<LibraryPtr> & LaunchProfile::getLibraries() const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
return m_libraries;
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
const QList<LibraryPtr> & LaunchProfile::getNativeLibraries() const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
return m_nativeLibraries;
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchProfile::getLibraryFiles(
|
2018-07-15 18:21:05 +05:30
|
|
|
const QString& architecture,
|
|
|
|
QStringList& jars,
|
|
|
|
QStringList& nativeJars,
|
|
|
|
const QString& overridePath,
|
|
|
|
const QString& tempPath
|
2017-11-05 03:25:25 +05:30
|
|
|
) const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
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);
|
|
|
|
}
|
2017-11-05 03:25:25 +05:30
|
|
|
}
|