| 880 | } |
| 881 | |
| 882 | bool 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(); |
nothing calls this directly
no test coverage detected