MCPcopy Create free account
hub / github.com/FreesmTeam/FreesmLauncher / createModdedJar

Function createModdedJar

launcher/MMCZip.cpp:143–227  ·  view source on GitHub ↗

ours

Source from the content-addressed store, hash-verified

141#if defined(LAUNCHER_APPLICATION)
142// ours
143bool 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;

Callers 1

executeTaskMethod · 0.85

Calls 13

deletePathFunction · 0.85
mergeZipFilesFunction · 0.85
compressDirFilesFunction · 0.85
QFileInfoClass · 0.85
openMethod · 0.80
enabledMethod · 0.80
fileinfoMethod · 0.80
closeMethod · 0.80
insertMethod · 0.80
filePathMethod · 0.80
typeMethod · 0.45

Tested by

no test coverage detected