MCPcopy Create free account
hub / github.com/MultiMC/Launcher / extractSubDir

Method extractSubDir

launcher/MMCZip.cpp:211–255  ·  view source on GitHub ↗

ours

Source from the content-addressed store, hash-verified

209
210// ours
211nonstd::optional<QStringList> MMCZip::extractSubDir(QuaZip *zip, const QString & subdir, const QString &target)
212{
213 QDir directory(target);
214 QStringList extracted;
215
216 qDebug() << "Extracting subdir" << subdir << "from" << zip->getZipName() << "to" << target;
217 auto numEntries = zip->getEntriesCount();
218 if(numEntries < 0) {
219 qWarning() << "Failed to enumerate files in archive";
220 return nonstd::nullopt;
221 }
222 else if(numEntries == 0) {
223 qDebug() << "Extracting empty archives seems odd...";
224 return extracted;
225 }
226 else if (!zip->goToFirstFile())
227 {
228 qWarning() << "Failed to seek to first file in zip";
229 return nonstd::nullopt;
230 }
231
232 do
233 {
234 QString name = zip->getCurrentFileName();
235 if(!name.startsWith(subdir))
236 {
237 continue;
238 }
239 name.remove(0, subdir.size());
240 QString absFilePath = directory.absoluteFilePath(name);
241 if(name.isEmpty())
242 {
243 absFilePath += "/";
244 }
245 if (!JlCompress::extractFile(zip, "", absFilePath))
246 {
247 qWarning() << "Failed to extract file" << name << "to" << absFilePath;
248 JlCompress::removeFile(extracted);
249 return nonstd::nullopt;
250 }
251 extracted.append(absFilePath);
252 qDebug() << "Extracted file" << name;
253 } while (zip->goToNextFile());
254 return extracted;
255}
256
257// ours
258bool MMCZip::extractRelFile(QuaZip *zip, const QString &file, const QString &target)

Callers

nothing calls this directly

Calls 4

isEmptyMethod · 0.80
appendMethod · 0.80
removeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected