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.
This commit is contained in:
Petr Mrázek
2017-08-07 00:46:29 +02:00
parent 117bfef151
commit 8cf88ffc58
16 changed files with 147 additions and 52 deletions

View File

@ -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");

View File

@ -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;

View File

@ -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;
}

View File

@ -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();

View File

@ -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;