MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / installJarMods_internal

Method installJarMods_internal

launcher/minecraft/PackProfile.cpp:820–880  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

818}
819
820bool PackProfile::installJarMods_internal(QStringList filepaths)
821{
822 QString patchDir = FS::PathCombine(d->m_instance->instanceRoot(), "patches");
823 if(!FS::ensureFolderPathExists(patchDir))
824 {
825 return false;
826 }
827
828 if (!FS::ensureFolderPathExists(d->m_instance->jarModsDir()))
829 {
830 return false;
831 }
832
833 for(auto filepath:filepaths)
834 {
835 QFileInfo sourceInfo(filepath);
836 auto uuid = QUuid::createUuid();
837 QString id = uuid.toString().remove('{').remove('}');
838 QString target_filename = id + ".jar";
839 QString target_id = "org.multimc.jarmod." + id;
840 QString target_name = sourceInfo.completeBaseName() + " (jar mod)";
841 QString finalPath = FS::PathCombine(d->m_instance->jarModsDir(), target_filename);
842
843 QFileInfo targetInfo(finalPath);
844 if(targetInfo.exists())
845 {
846 return false;
847 }
848
849 if (!QFile::copy(sourceInfo.absoluteFilePath(),QFileInfo(finalPath).absoluteFilePath()))
850 {
851 return false;
852 }
853
854 auto f = std::make_shared<VersionFile>();
855 auto jarMod = std::make_shared<Library>();
856 jarMod->setRawName(GradleSpecifier("org.multimc.jarmods:" + id + ":1"));
857 jarMod->setFilename(target_filename);
858 jarMod->setDisplayName(sourceInfo.completeBaseName());
859 jarMod->setHint("local");
860 f->jarMods.append(jarMod);
861 f->name = target_name;
862 f->uid = target_id;
863 QString patchFileName = FS::PathCombine(patchDir, target_id + ".json");
864
865 QFile file(patchFileName);
866 if (!file.open(QFile::WriteOnly))
867 {
868 qCritical() << "Error opening" << file.fileName()
869 << "for reading:" << file.errorString();
870 return false;
871 }
872 file.write(OneSixVersionFormat::versionFileToJson(f).toJson());
873 file.close();
874
875 appendComponent(new Component(this, f->uid, f));
876 }
877 scheduleSave();

Callers

nothing calls this directly

Calls 15

PathCombineFunction · 0.85
ensureFolderPathExistsFunction · 0.85
copyClass · 0.85
GradleSpecifierClass · 0.85
instanceRootMethod · 0.80
jarModsDirMethod · 0.80
existsMethod · 0.80
setRawNameMethod · 0.80
setFilenameMethod · 0.80
setDisplayNameMethod · 0.80
setHintMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected