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

Method installCustomJar_internal

launcher/minecraft/PackProfile.cpp:882–941  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

880}
881
882bool PackProfile::installCustomJar_internal(QString filepath)
883{
884 QString patchDir = FS::PathCombine(d->m_instance->instanceRoot(), "patches");
885 if(!FS::ensureFolderPathExists(patchDir))
886 {
887 return false;
888 }
889
890 QString libDir = d->m_instance->getLocalLibraryPath();
891 if (!FS::ensureFolderPathExists(libDir))
892 {
893 return false;
894 }
895
896 auto specifier = GradleSpecifier("org.multimc:customjar:1");
897 QFileInfo sourceInfo(filepath);
898 QString target_filename = specifier.getFileName();
899 QString target_id = specifier.artifactId();
900 QString target_name = sourceInfo.completeBaseName() + " (custom jar)";
901 QString finalPath = FS::PathCombine(libDir, target_filename);
902
903 QFileInfo jarInfo(finalPath);
904 if (jarInfo.exists())
905 {
906 if(!QFile::remove(finalPath))
907 {
908 return false;
909 }
910 }
911 if (!QFile::copy(filepath, finalPath))
912 {
913 return false;
914 }
915
916 auto f = std::make_shared<VersionFile>();
917 auto jarMod = std::make_shared<Library>();
918 jarMod->setRawName(specifier);
919 jarMod->setDisplayName(sourceInfo.completeBaseName());
920 jarMod->setHint("local");
921 f->mainJar = jarMod;
922 f->name = target_name;
923 f->uid = target_id;
924 QString patchFileName = FS::PathCombine(patchDir, target_id + ".json");
925
926 QFile file(patchFileName);
927 if (!file.open(QFile::WriteOnly))
928 {
929 qCritical() << "Error opening" << file.fileName()
930 << "for reading:" << file.errorString();
931 return false;
932 }
933 file.write(OneSixVersionFormat::versionFileToJson(f).toJson());
934 file.close();
935
936 appendComponent(new Component(this, f->uid, f));
937
938 scheduleSave();
939 invalidateLaunchProfile();

Callers

nothing calls this directly

Calls 15

PathCombineFunction · 0.85
ensureFolderPathExistsFunction · 0.85
GradleSpecifierClass · 0.85
copyClass · 0.85
instanceRootMethod · 0.80
getLocalLibraryPathMethod · 0.80
getFileNameMethod · 0.80
existsMethod · 0.80
setRawNameMethod · 0.80
setDisplayNameMethod · 0.80
setHintMethod · 0.80
openMethod · 0.80

Tested by

no test coverage detected