summaryrefslogtreecommitdiffstats
path: root/api/logic/minecraft/onesix
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2017-04-17 22:51:30 +0200
committerPetr Mrázek <peterix@gmail.com>2017-04-17 22:51:30 +0200
commitc4c8e99681e14e5d0e82a13cb0631107dedf96ff (patch)
treea40279027b7530b5b8ddf0bbc286d0a33dc18951 /api/logic/minecraft/onesix
parentfc28aacdea3e7331b0f5f4436e0dac2fd361c390 (diff)
downloadMultiMC-c4c8e99681e14e5d0e82a13cb0631107dedf96ff.tar
MultiMC-c4c8e99681e14e5d0e82a13cb0631107dedf96ff.tar.gz
MultiMC-c4c8e99681e14e5d0e82a13cb0631107dedf96ff.tar.lz
MultiMC-c4c8e99681e14e5d0e82a13cb0631107dedf96ff.tar.xz
MultiMC-c4c8e99681e14e5d0e82a13cb0631107dedf96ff.zip
NOISSUE jar mods as libraries, fix for customizing net.minecraft
Diffstat (limited to 'api/logic/minecraft/onesix')
-rw-r--r--api/logic/minecraft/onesix/OneSixInstance.cpp17
-rw-r--r--api/logic/minecraft/onesix/OneSixProfileStrategy.cpp24
-rw-r--r--api/logic/minecraft/onesix/OneSixVersionFormat.cpp76
-rw-r--r--api/logic/minecraft/onesix/OneSixVersionFormat.h9
-rw-r--r--api/logic/minecraft/onesix/update/LibrariesTask.cpp1
5 files changed, 97 insertions, 30 deletions
diff --git a/api/logic/minecraft/onesix/OneSixInstance.cpp b/api/logic/minecraft/onesix/OneSixInstance.cpp
index 0061be08..7e4e97b7 100644
--- a/api/logic/minecraft/onesix/OneSixInstance.cpp
+++ b/api/logic/minecraft/onesix/OneSixInstance.cpp
@@ -314,7 +314,16 @@ QStringList OneSixInstance::verboseDescription(AuthSessionPtr session)
out << "Jar Mods:";
for(auto & jarmod: jarMods)
{
- out << " " + jarmod->originalName + " (" + jarmod->name + ")";
+ auto displayname = jarmod->displayName(currentSystem);
+ auto realname = jarmod->filename(currentSystem);
+ if(displayname != realname)
+ {
+ out << " " + displayname + " (" + realname + ")";
+ }
+ else
+ {
+ out << " " + realname;
+ }
}
out << "";
}
@@ -521,8 +530,10 @@ QList< Mod > OneSixInstance::getJarMods() const
QList<Mod> mods;
for (auto jarmod : m_profile->getJarMods())
{
- QString filePath = jarmodsPath().absoluteFilePath(jarmod->name);
- mods.push_back(Mod(QFileInfo(filePath)));
+ QStringList jar, temp1, temp2, temp3;
+ jarmod->getApplicableFiles(currentSystem, jar, temp1, temp2, temp3, jarmodsPath().absolutePath());
+ // QString filePath = jarmodsPath().absoluteFilePath(jarmod->filename(currentSystem));
+ mods.push_back(Mod(QFileInfo(jar[0])));
}
return mods;
}
diff --git a/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp b/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp
index d3e137c7..b4be3356 100644
--- a/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp
+++ b/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp
@@ -248,16 +248,22 @@ bool OneSixProfileStrategy::removePatch(ProfilePatchPtr patch)
m_instance->setComponentVersion(patch->getID(), QString());
}
- auto preRemoveJarMod = [&](JarmodPtr jarMod) -> bool
+ // FIXME: we need a generic way of removing local resources, not just jar mods...
+ auto preRemoveJarMod = [&](LibraryPtr jarMod) -> bool
{
- QString fullpath = FS::PathCombine(m_instance->jarModsDir(), jarMod->name);
- QFileInfo finfo (fullpath);
+ if (!jarMod->isLocal())
+ {
+ return true;
+ }
+ QStringList jar, temp1, temp2, temp3;
+ jarMod->getApplicableFiles(currentSystem, jar, temp1, temp2, temp3, m_instance->jarmodsPath().absolutePath());
+ QFileInfo finfo (jar[0]);
if(finfo.exists())
{
- QFile jarModFile(fullpath);
+ QFile jarModFile(jar[0]);
if(!jarModFile.remove())
{
- qCritical() << "File" << fullpath << "could not be removed because:" << jarModFile.errorString();
+ qCritical() << "File" << jar[0] << "could not be removed because:" << jarModFile.errorString();
return false;
}
return true;
@@ -381,9 +387,11 @@ bool OneSixProfileStrategy::installJarMods(QStringList filepaths)
}
auto f = std::make_shared<VersionFile>();
- auto jarMod = std::make_shared<Jarmod>();
- jarMod->name = target_filename;
- jarMod->originalName = sourceInfo.completeBaseName();
+ auto jarMod = std::make_shared<Library>();
+ jarMod->setRawName(GradleSpecifier("org.multimc.jarmods:" + id + ":1"));
+ jarMod->setFilename(target_filename);
+ jarMod->setDisplayName(sourceInfo.completeBaseName());
+ jarMod->setHint("local");
f->jarMods.append(jarMod);
f->name = target_name;
f->uid = target_id;
diff --git a/api/logic/minecraft/onesix/OneSixVersionFormat.cpp b/api/logic/minecraft/onesix/OneSixVersionFormat.cpp
index c404e96f..da55d91b 100644
--- a/api/logic/minecraft/onesix/OneSixVersionFormat.cpp
+++ b/api/logic/minecraft/onesix/OneSixVersionFormat.cpp
@@ -20,6 +20,8 @@ LibraryPtr OneSixVersionFormat::libraryFromJson(const QJsonObject &libObj, const
readString(libObj, "MMC-hint", out->m_hint);
readString(libObj, "MMC-absulute_url", out->m_absoluteURL);
readString(libObj, "MMC-absoluteUrl", out->m_absoluteURL);
+ readString(libObj, "MMC-filename", out->m_filename);
+ readString(libObj, "MMC-displayname", out->m_displayname);
return out;
}
@@ -30,6 +32,10 @@ QJsonObject OneSixVersionFormat::libraryToJson(Library *library)
libRoot.insert("MMC-absoluteUrl", library->m_absoluteURL);
if (library->m_hint.size())
libRoot.insert("MMC-hint", library->m_hint);
+ if (library->m_filename.size())
+ libRoot.insert("MMC-filename", library->m_filename);
+ if (library->m_displayname.size())
+ libRoot.insert("MMC-displayname", library->m_displayname);
return libRoot;
}
@@ -96,13 +102,25 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc
}
}
- if (root.contains("+jarMods"))
+
+ if (root.contains("jarMods"))
+ {
+ for (auto libVal : requireArray(root.value("jarMods")))
+ {
+ QJsonObject libObj = requireObject(libVal);
+ // parse the jarmod
+ auto lib = OneSixVersionFormat::jarModFromJson(libObj, filename);
+ // and add to jar mods
+ out->jarMods.append(lib);
+ }
+ }
+ else if (root.contains("+jarMods")) // DEPRECATED: old style '+jarMods' are only here for backwards compatibility
{
for (auto libVal : requireArray(root.value("+jarMods")))
{
QJsonObject libObj = requireObject(libVal);
// parse the jarmod
- auto lib = OneSixVersionFormat::jarModFromJson(libObj, filename, out->name);
+ auto lib = OneSixVersionFormat::plusJarModFromJson(libObj, filename, out->name);
// and add to jar mods
out->jarMods.append(lib);
}
@@ -197,13 +215,16 @@ QJsonDocument OneSixVersionFormat::versionFileToJson(const VersionFilePtr &patch
writeString(root, "name", patch->name);
writeString(root, "uid", patch->uid);
- writeString(root, "fileId", patch->uid);
writeString(root, "version", patch->version);
writeString(root, "mcVersion", patch->dependsOnMinecraftVersion);
MojangVersionFormat::writeVersionProperties(patch.get(), root);
+ if(patch->mainJar)
+ {
+ root.insert("mainJar", libraryToJson(patch->mainJar.get()));
+ }
writeString(root, "appletClass", patch->appletClass);
writeStringList(root, "+tweakers", patch->addTweakers);
writeStringList(root, "+traits", patch->traits.toList());
@@ -214,7 +235,7 @@ QJsonDocument OneSixVersionFormat::versionFileToJson(const VersionFilePtr &patch
{
array.append(OneSixVersionFormat::libraryToJson(value.get()));
}
- root.insert("+libraries", array);
+ root.insert("libraries", array);
}
if (!patch->jarMods.isEmpty())
{
@@ -223,7 +244,7 @@ QJsonDocument OneSixVersionFormat::versionFileToJson(const VersionFilePtr &patch
{
array.append(OneSixVersionFormat::jarModtoJson(value.get()));
}
- root.insert("+jarMods", array);
+ root.insert("jarMods", array);
}
// write the contents to a json document.
{
@@ -233,32 +254,55 @@ QJsonDocument OneSixVersionFormat::versionFileToJson(const VersionFilePtr &patch
}
}
-JarmodPtr OneSixVersionFormat::jarModFromJson(const QJsonObject &libObj, const QString &filename, const QString &originalName)
+LibraryPtr OneSixVersionFormat::plusJarModFromJson(const QJsonObject &libObj, const QString &filename, const QString &originalName)
{
- JarmodPtr out(new Jarmod());
+ LibraryPtr out(new Library());
if (!libObj.contains("name"))
{
throw JSONValidationError(filename +
"contains a jarmod that doesn't have a 'name' field");
}
- out->name = libObj.value("name").toString();
- out->originalName = libObj.value("originalName").toString();
- if(out->originalName.isEmpty())
+
+ // just make up something unique on the spot for the library name.
+ auto uuid = QUuid::createUuid();
+ QString id = uuid.toString().remove('{').remove('}');
+
+
+ // filename override is the old name
+ out->setFilename(libObj.value("name").toString());
+
+ // it needs to be local, it is stored in the instance jarmods folder
+ out->setHint("local");
+
+ // read the original name if present - some versions did not set it
+ // it is the original jar mod filename before it got renamed at the point of addition
+ auto displayName = libObj.value("originalName").toString();
+ if(displayName.isEmpty())
{
auto fixed = originalName;
fixed.remove(" (jar mod)");
- out->originalName = originalName;
+ out->setDisplayName(fixed);
+ }
+ else
+ {
+ out->setDisplayName(displayName);
}
return out;
}
-QJsonObject OneSixVersionFormat::jarModtoJson(Jarmod *jarmod)
+LibraryPtr OneSixVersionFormat::jarModFromJson(const QJsonObject& libObj, const QString& filename)
+{
+ auto lib = libraryFromJson(libObj, filename);
+ return lib;
+}
+
+
+QJsonObject OneSixVersionFormat::jarModtoJson(Library *jarmod)
{
- QJsonObject out;
- writeString(out, "name", jarmod->name);
- if(!jarmod->originalName.isEmpty())
+ QJsonObject out = libraryToJson(jarmod);
+ if(!jarmod->m_displayname.isEmpty())
{
- writeString(out, "originalName", jarmod->originalName);
+ writeString(out, "originalName", jarmod->m_displayname);
}
return out;
}
diff --git a/api/logic/minecraft/onesix/OneSixVersionFormat.h b/api/logic/minecraft/onesix/OneSixVersionFormat.h
index 5696e79e..0a29a202 100644
--- a/api/logic/minecraft/onesix/OneSixVersionFormat.h
+++ b/api/logic/minecraft/onesix/OneSixVersionFormat.h
@@ -16,7 +16,10 @@ public:
static LibraryPtr libraryFromJson(const QJsonObject &libObj, const QString &filename);
static QJsonObject libraryToJson(Library *library);
- // jar mods
- static JarmodPtr jarModFromJson(const QJsonObject &libObj, const QString &filename, const QString &originalName);
- static QJsonObject jarModtoJson(Jarmod * jarmod);
+ // DEPRECATED: old 'plus' jar mods generated by the application
+ static LibraryPtr plusJarModFromJson(const QJsonObject &libObj, const QString &filename, const QString &originalName);
+
+ // new jar mods derived from libraries
+ static LibraryPtr jarModFromJson(const QJsonObject &libObj, const QString &filename);
+ static QJsonObject jarModtoJson(Library * jarmod);
};
diff --git a/api/logic/minecraft/onesix/update/LibrariesTask.cpp b/api/logic/minecraft/onesix/update/LibrariesTask.cpp
index 1b7e71d3..2cd41ded 100644
--- a/api/logic/minecraft/onesix/update/LibrariesTask.cpp
+++ b/api/logic/minecraft/onesix/update/LibrariesTask.cpp
@@ -50,6 +50,7 @@ void LibrariesTask::executeTask()
};
createJobs(profile->getLibraries());
createJobs(profile->getNativeLibraries());
+ createJobs(profile->getJarMods());
createJob(profile->getMainJar());
// FIXME: this is never filled!!!!