summaryrefslogtreecommitdiffstats
path: root/api/logic/minecraft
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2017-08-07 00:46:29 +0200
committerPetr Mrázek <peterix@gmail.com>2017-08-07 00:46:29 +0200
commit8cf88ffc580310e2e814d097358ff783cd5c4416 (patch)
tree4ed75860253ffa667af38664b4fd10e6d7bc29de /api/logic/minecraft
parent117bfef151c2083085025c32f96461f1c97dbec3 (diff)
downloadMultiMC-8cf88ffc580310e2e814d097358ff783cd5c4416.tar
MultiMC-8cf88ffc580310e2e814d097358ff783cd5c4416.tar.gz
MultiMC-8cf88ffc580310e2e814d097358ff783cd5c4416.tar.lz
MultiMC-8cf88ffc580310e2e814d097358ff783cd5c4416.tar.xz
MultiMC-8cf88ffc580310e2e814d097358ff783cd5c4416.zip
GH-1314 add UI for custom minecraft jar addition
Also changes the text of the jar mod addition button. It should be clearer what it does and hopefully will not confuse as many people.
Diffstat (limited to 'api/logic/minecraft')
-rw-r--r--api/logic/minecraft/MinecraftProfile.cpp6
-rw-r--r--api/logic/minecraft/MinecraftProfile.h3
-rw-r--r--api/logic/minecraft/ProfileStrategy.h3
-rw-r--r--api/logic/minecraft/ftb/FTBProfileStrategy.cpp5
-rw-r--r--api/logic/minecraft/ftb/FTBProfileStrategy.h15
-rw-r--r--api/logic/minecraft/onesix/OneSixInstance.cpp7
-rw-r--r--api/logic/minecraft/onesix/OneSixInstance.h3
-rw-r--r--api/logic/minecraft/onesix/OneSixProfileStrategy.cpp64
-rw-r--r--api/logic/minecraft/onesix/OneSixProfileStrategy.h15
-rw-r--r--api/logic/minecraft/onesix/update/FMLLibrariesTask.cpp6
10 files changed, 108 insertions, 19 deletions
diff --git a/api/logic/minecraft/MinecraftProfile.cpp b/api/logic/minecraft/MinecraftProfile.cpp
index 4c1ab818..f6e39f45 100644
--- a/api/logic/minecraft/MinecraftProfile.cpp
+++ b/api/logic/minecraft/MinecraftProfile.cpp
@@ -664,6 +664,12 @@ void MinecraftProfile::installJarMods(QStringList selectedFiles)
m_strategy->installJarMods(selectedFiles);
}
+void MinecraftProfile::installCustomJar(QString selectedFile)
+{
+ m_strategy->installCustomJar(selectedFile);
+}
+
+
/*
* TODO: get rid of this. Get rid of all order numbers.
*/
diff --git a/api/logic/minecraft/MinecraftProfile.h b/api/logic/minecraft/MinecraftProfile.h
index 192c77f9..e81ba499 100644
--- a/api/logic/minecraft/MinecraftProfile.h
+++ b/api/logic/minecraft/MinecraftProfile.h
@@ -58,6 +58,9 @@ public:
/// install more jar mods
void installJarMods(QStringList selectedFiles);
+ /// install more jar mods
+ void installCustomJar(QString selectedFile);
+
/// DEPRECATED, remove ASAP
int getFreeOrderNumber();
diff --git a/api/logic/minecraft/ProfileStrategy.h b/api/logic/minecraft/ProfileStrategy.h
index 26bdf661..09a09f24 100644
--- a/api/logic/minecraft/ProfileStrategy.h
+++ b/api/logic/minecraft/ProfileStrategy.h
@@ -23,6 +23,9 @@ public:
/// install a list of jar mods into the instance
virtual bool installJarMods(QStringList filepaths) = 0;
+ /// install a custom jar (replaces the one from the Minecraft component)
+ virtual bool installCustomJar(QString filepath) = 0;
+
/// remove any files or records that constitute the version patch
virtual bool removePatch(ProfilePatchPtr jarMod) = 0;
diff --git a/api/logic/minecraft/ftb/FTBProfileStrategy.cpp b/api/logic/minecraft/ftb/FTBProfileStrategy.cpp
index 9fa4e6a1..d5df7848 100644
--- a/api/logic/minecraft/ftb/FTBProfileStrategy.cpp
+++ b/api/logic/minecraft/ftb/FTBProfileStrategy.cpp
@@ -118,6 +118,11 @@ bool FTBProfileStrategy::installJarMods(QStringList filepaths)
return false;
}
+bool FTBProfileStrategy::installCustomJar(QString filepath)
+{
+ return false;
+}
+
bool FTBProfileStrategy::customizePatch(ProfilePatchPtr patch)
{
return false;
diff --git a/api/logic/minecraft/ftb/FTBProfileStrategy.h b/api/logic/minecraft/ftb/FTBProfileStrategy.h
index 522af098..4637d04b 100644
--- a/api/logic/minecraft/ftb/FTBProfileStrategy.h
+++ b/api/logic/minecraft/ftb/FTBProfileStrategy.h
@@ -9,13 +9,14 @@ 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 customizePatch (ProfilePatchPtr patch) override;
- virtual bool revertPatch (ProfilePatchPtr patch) override;
+ void load() override;
+ bool resetOrder() override;
+ bool saveOrder(ProfileUtils::PatchOrder order) override;
+ bool installJarMods(QStringList filepaths) override;
+ bool installCustomJar(QString filepath) override;
+ bool customizePatch (ProfilePatchPtr patch) override;
+ bool revertPatch (ProfilePatchPtr patch) override;
protected:
- virtual void loadDefaultBuiltinPatches() override;
+ void loadDefaultBuiltinPatches() override;
};
diff --git a/api/logic/minecraft/onesix/OneSixInstance.cpp b/api/logic/minecraft/onesix/OneSixInstance.cpp
index 107da04f..34253f02 100644
--- a/api/logic/minecraft/onesix/OneSixInstance.cpp
+++ b/api/logic/minecraft/onesix/OneSixInstance.cpp
@@ -637,11 +637,16 @@ QString OneSixInstance::jarModsDir() const
return FS::PathCombine(instanceRoot(), "jarmods");
}
-QString OneSixInstance::libDir() const
+QString OneSixInstance::FMLlibDir() const
{
return FS::PathCombine(minecraftRoot(), "lib");
}
+QString OneSixInstance::customLibrariesDir() const
+{
+ return FS::PathCombine(instanceRoot(), "libraries");
+}
+
QString OneSixInstance::worldDir() const
{
return FS::PathCombine(minecraftRoot(), "saves");
diff --git a/api/logic/minecraft/onesix/OneSixInstance.h b/api/logic/minecraft/onesix/OneSixInstance.h
index bf12160e..0cb4340b 100644
--- a/api/logic/minecraft/onesix/OneSixInstance.h
+++ b/api/logic/minecraft/onesix/OneSixInstance.h
@@ -48,7 +48,8 @@ public:
QString texturePacksDir() const;
QString loaderModsDir() const;
QString coreModsDir() const;
- QString libDir() const;
+ QString FMLlibDir() const;
+ QString customLibrariesDir() const;
QString worldDir() const;
virtual QString instanceConfigFolder() const override;
diff --git a/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp b/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp
index ef2a7294..39dd8343 100644
--- a/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp
+++ b/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp
@@ -405,3 +405,67 @@ bool OneSixProfileStrategy::installJarMods(QStringList filepaths)
return true;
}
+bool OneSixProfileStrategy::installCustomJar(QString filepath)
+{
+ QString patchDir = FS::PathCombine(m_instance->instanceRoot(), "patches");
+ if(!FS::ensureFolderPathExists(patchDir))
+ {
+ return false;
+ }
+
+ QString libDir = m_instance->customLibrariesDir();
+ if (!FS::ensureFolderPathExists(libDir))
+ {
+ return false;
+ }
+
+ auto specifier = GradleSpecifier("org.multimc:customjar:1");
+ QFileInfo sourceInfo(filepath);
+ QString target_filename = specifier.getFileName();
+ QString target_id = specifier.artifactId();
+ QString target_name = sourceInfo.completeBaseName() + " (custom jar)";
+ QString finalPath = FS::PathCombine(libDir, target_filename);
+
+ QFileInfo jarInfo(finalPath);
+ if (jarInfo.exists())
+ {
+ if(!QFile::remove(finalPath))
+ {
+ return false;
+ }
+ }
+ if (!QFile::copy(filepath, finalPath))
+ {
+ return false;
+ }
+
+ auto f = std::make_shared<VersionFile>();
+ auto jarMod = std::make_shared<Library>();
+ jarMod->setRawName(specifier);
+ jarMod->setDisplayName(sourceInfo.completeBaseName());
+ jarMod->setHint("local");
+ f->mainJar = jarMod;
+ f->name = target_name;
+ f->uid = target_id;
+ f->order = profile->getFreeOrderNumber();
+ QString patchFileName = FS::PathCombine(patchDir, target_id + ".json");
+
+ QFile file(patchFileName);
+ if (!file.open(QFile::WriteOnly))
+ {
+ qCritical() << "Error opening" << file.fileName()
+ << "for reading:" << file.errorString();
+ return false;
+ }
+ file.write(OneSixVersionFormat::versionFileToJson(f, true).toJson());
+ file.close();
+
+ auto patch = std::make_shared<ProfilePatch>(f, patchFileName);
+ patch->setMovable(true);
+ patch->setRemovable(true);
+ profile->appendPatch(patch);
+
+ profile->saveCurrentOrder();
+ profile->reapplyPatches();
+ return true;
+}
diff --git a/api/logic/minecraft/onesix/OneSixProfileStrategy.h b/api/logic/minecraft/onesix/OneSixProfileStrategy.h
index 96c1ba7b..e4eee4b2 100644
--- a/api/logic/minecraft/onesix/OneSixProfileStrategy.h
+++ b/api/logic/minecraft/onesix/OneSixProfileStrategy.h
@@ -8,13 +8,14 @@ class OneSixProfileStrategy : public ProfileStrategy
public:
OneSixProfileStrategy(OneSixInstance * instance);
virtual ~OneSixProfileStrategy() {};
- 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;
- virtual bool customizePatch(ProfilePatchPtr patch) override;
- virtual bool revertPatch(ProfilePatchPtr patch) override;
+ void load() override;
+ bool resetOrder() override;
+ bool saveOrder(ProfileUtils::PatchOrder order) override;
+ bool installJarMods(QStringList filepaths) override;
+ bool installCustomJar(QString filepath) override;
+ bool removePatch(ProfilePatchPtr patch) override;
+ bool customizePatch(ProfilePatchPtr patch) override;
+ bool revertPatch(ProfilePatchPtr patch) override;
protected:
virtual void loadDefaultBuiltinPatches();
diff --git a/api/logic/minecraft/onesix/update/FMLLibrariesTask.cpp b/api/logic/minecraft/onesix/update/FMLLibrariesTask.cpp
index 42148e67..13310e92 100644
--- a/api/logic/minecraft/onesix/update/FMLLibrariesTask.cpp
+++ b/api/logic/minecraft/onesix/update/FMLLibrariesTask.cpp
@@ -45,7 +45,7 @@ void FMLLibrariesTask::executeTask()
// now check the lib folder inside the instance for files.
for (auto &lib : libList)
{
- QFileInfo libInfo(FS::PathCombine(inst->libDir(), lib.filename));
+ QFileInfo libInfo(FS::PathCombine(inst->FMLlibDir(), lib.filename));
if (libInfo.exists())
continue;
fmlLibsToProcess.append(lib);
@@ -95,13 +95,13 @@ void FMLLibrariesTask::fmllibsFinished()
{
progress(index, fmlLibsToProcess.size());
auto entry = metacache->resolveEntry("fmllibs", lib.filename);
- auto path = FS::PathCombine(inst->libDir(), lib.filename);
+ auto path = FS::PathCombine(inst->FMLlibDir(), lib.filename);
if (!FS::ensureFilePathExists(path))
{
emitFailed(tr("Failed creating FML library folder inside the instance."));
return;
}
- if (!QFile::copy(entry->getFullPath(), FS::PathCombine(inst->libDir(), lib.filename)))
+ if (!QFile::copy(entry->getFullPath(), FS::PathCombine(inst->FMLlibDir(), lib.filename)))
{
emitFailed(tr("Failed copying Forge/FML library: %1.").arg(lib.filename));
return;