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

Method doExport

launcher/ui/dialogs/ExportInstanceDialog.cpp:399–438  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

397}
398
399bool ExportInstanceDialog::doExport()
400{
401 auto name = FS::RemoveInvalidFilenameChars(m_instance->name());
402
403 const QString output = QFileDialog::getSaveFileName(
404 this, tr("Export %1").arg(m_instance->name()),
405 FS::PathCombine(QDir::homePath(), name + ".zip"), "Zip (*.zip)", nullptr, QFileDialog::DontConfirmOverwrite);
406 if (output.isEmpty())
407 {
408 return false;
409 }
410 if (QFile::exists(output))
411 {
412 int ret =
413 QMessageBox::question(this, tr("Overwrite?"),
414 tr("This file already exists. Do you want to overwrite it?"),
415 QMessageBox::No, QMessageBox::Yes);
416 if (ret == QMessageBox::No)
417 {
418 return false;
419 }
420 }
421
422 SaveIcon(m_instance);
423
424 auto & blocked = proxyModel->blockedPaths();
425 using std::placeholders::_1;
426 auto files = QFileInfoList();
427 if (!MMCZip::collectFileListRecursively(m_instance->instanceRoot(), nullptr, &files,
428 std::bind(&SeparatorPrefixTree<'/'>::covers, blocked, _1))) {
429 QMessageBox::warning(this, tr("Error"), tr("Unable to export instance"));
430 return false;
431 }
432 if (!MMCZip::compressDirFiles(output, m_instance->instanceRoot(), files))
433 {
434 QMessageBox::warning(this, tr("Error"), tr("Unable to export instance"));
435 return false;
436 }
437 return true;
438}
439
440void ExportInstanceDialog::done(int result)
441{

Callers

nothing calls this directly

Calls 6

PathCombineFunction · 0.85
SaveIconFunction · 0.85
isEmptyMethod · 0.80
instanceRootMethod · 0.80
nameMethod · 0.45

Tested by

no test coverage detected