ours
| 141 | #if defined(LAUNCHER_APPLICATION) |
| 142 | // ours |
| 143 | bool createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<Mod*>& mods) |
| 144 | { |
| 145 | QuaZip zipOut(targetJarPath); |
| 146 | zipOut.setUtf8Enabled(true); |
| 147 | if (!zipOut.open(QuaZip::mdCreate)) { |
| 148 | FS::deletePath(targetJarPath); |
| 149 | qCritical() << "Failed to open the minecraft.jar for modding"; |
| 150 | return false; |
| 151 | } |
| 152 | // Files already added to the jar. |
| 153 | // These files will be skipped. |
| 154 | QSet<QString> addedFiles; |
| 155 | |
| 156 | // Modify the jar |
| 157 | // This needs to be done in reverse-order to ensure we respect the loading order of components |
| 158 | for (auto i = mods.crbegin(); i != mods.crend(); i++) { |
| 159 | const auto* mod = *i; |
| 160 | // do not merge disabled mods. |
| 161 | if (!mod->enabled()) |
| 162 | continue; |
| 163 | if (mod->type() == ResourceType::ZIPFILE) { |
| 164 | if (!mergeZipFiles(&zipOut, mod->fileinfo(), addedFiles)) { |
| 165 | zipOut.close(); |
| 166 | FS::deletePath(targetJarPath); |
| 167 | qCritical() << "Failed to add" << mod->fileinfo().fileName() << "to the jar."; |
| 168 | return false; |
| 169 | } |
| 170 | } else if (mod->type() == ResourceType::SINGLEFILE) { |
| 171 | // FIXME: buggy - does not work with addedFiles |
| 172 | auto filename = mod->fileinfo(); |
| 173 | if (!JlCompress::compressFile(&zipOut, filename.absoluteFilePath(), filename.fileName())) { |
| 174 | zipOut.close(); |
| 175 | FS::deletePath(targetJarPath); |
| 176 | qCritical() << "Failed to add" << mod->fileinfo().fileName() << "to the jar."; |
| 177 | return false; |
| 178 | } |
| 179 | addedFiles.insert(filename.fileName()); |
| 180 | } else if (mod->type() == ResourceType::FOLDER) { |
| 181 | // untested, but seems to be unused / not possible to reach |
| 182 | // FIXME: buggy - does not work with addedFiles |
| 183 | auto filename = mod->fileinfo(); |
| 184 | QString what_to_zip = filename.absoluteFilePath(); |
| 185 | QDir dir(what_to_zip); |
| 186 | dir.cdUp(); |
| 187 | QString parent_dir = dir.absolutePath(); |
| 188 | auto files = QFileInfoList(); |
| 189 | collectFileListRecursively(what_to_zip, nullptr, &files, nullptr); |
| 190 | |
| 191 | for (auto e : files) { |
| 192 | if (addedFiles.contains(e.filePath())) |
| 193 | files.removeAll(e); |
| 194 | } |
| 195 | |
| 196 | if (!compressDirFiles(&zipOut, parent_dir, files)) { |
| 197 | zipOut.close(); |
| 198 | FS::deletePath(targetJarPath); |
| 199 | qCritical() << "Failed to add" << mod->fileinfo().fileName() << "to the jar."; |
| 200 | return false; |
no test coverage detected