2020-04-04 21:18:15 +00:00
|
|
|
// Copyright 2020 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "DolphinQt/ConvertDialog.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
2020-04-11 11:06:45 +00:00
|
|
|
#include <functional>
|
2020-04-04 21:18:15 +00:00
|
|
|
#include <future>
|
2020-04-10 15:40:07 +00:00
|
|
|
#include <memory>
|
2020-04-04 21:18:15 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2020-04-11 11:06:45 +00:00
|
|
|
#include <QCheckBox>
|
2020-04-04 21:18:15 +00:00
|
|
|
#include <QComboBox>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QGridLayout>
|
2020-04-11 12:43:47 +00:00
|
|
|
#include <QGroupBox>
|
2020-04-04 21:18:15 +00:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QList>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QString>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
#include "Common/Assert.h"
|
2020-04-10 13:14:03 +00:00
|
|
|
#include "Common/Logging/Log.h"
|
2020-04-04 21:18:15 +00:00
|
|
|
#include "DiscIO/Blob.h"
|
2020-04-10 15:40:07 +00:00
|
|
|
#include "DiscIO/ScrubbedBlob.h"
|
2020-04-17 18:38:33 +00:00
|
|
|
#include "DiscIO/WIABlob.h"
|
2020-04-04 21:18:15 +00:00
|
|
|
#include "DolphinQt/QtUtils/ModalMessageBox.h"
|
|
|
|
#include "DolphinQt/QtUtils/ParallelProgressDialog.h"
|
|
|
|
#include "UICommon/GameFile.h"
|
2020-04-10 13:14:03 +00:00
|
|
|
#include "UICommon/UICommon.h"
|
2020-04-04 21:18:15 +00:00
|
|
|
|
|
|
|
static bool CompressCB(const std::string& text, float percent, void* ptr)
|
|
|
|
{
|
|
|
|
if (ptr == nullptr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto* progress_dialog = static_cast<ParallelProgressDialog*>(ptr);
|
|
|
|
|
|
|
|
progress_dialog->SetValue(percent * 100);
|
|
|
|
return !progress_dialog->WasCanceled();
|
|
|
|
}
|
|
|
|
|
|
|
|
ConvertDialog::ConvertDialog(QList<std::shared_ptr<const UICommon::GameFile>> files,
|
|
|
|
QWidget* parent)
|
|
|
|
: QDialog(parent), m_files(std::move(files))
|
|
|
|
{
|
|
|
|
ASSERT(!m_files.empty());
|
|
|
|
|
|
|
|
setWindowTitle(tr("Convert"));
|
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
|
|
|
|
|
|
QGridLayout* grid_layout = new QGridLayout;
|
|
|
|
grid_layout->setColumnStretch(1, 1);
|
|
|
|
|
|
|
|
m_format = new QComboBox;
|
2020-06-17 10:44:16 +00:00
|
|
|
m_format->addItem(QStringLiteral("ISO"), static_cast<int>(DiscIO::BlobType::PLAIN));
|
|
|
|
m_format->addItem(QStringLiteral("GCZ"), static_cast<int>(DiscIO::BlobType::GCZ));
|
2020-04-13 20:04:16 +00:00
|
|
|
m_format->addItem(QStringLiteral("WIA"), static_cast<int>(DiscIO::BlobType::WIA));
|
2020-05-04 10:41:14 +00:00
|
|
|
m_format->addItem(QStringLiteral("RVZ"), static_cast<int>(DiscIO::BlobType::RVZ));
|
2020-06-17 10:44:16 +00:00
|
|
|
if (std::all_of(m_files.begin(), m_files.end(),
|
|
|
|
[](const auto& file) { return file->GetBlobType() == DiscIO::BlobType::PLAIN; }))
|
|
|
|
{
|
|
|
|
m_format->setCurrentIndex(m_format->count() - 1);
|
|
|
|
}
|
2020-04-04 21:18:15 +00:00
|
|
|
grid_layout->addWidget(new QLabel(tr("Format:")), 0, 0);
|
|
|
|
grid_layout->addWidget(m_format, 0, 1);
|
|
|
|
|
2020-04-10 13:14:03 +00:00
|
|
|
m_block_size = new QComboBox;
|
|
|
|
grid_layout->addWidget(new QLabel(tr("Block Size:")), 1, 0);
|
|
|
|
grid_layout->addWidget(m_block_size, 1, 1);
|
|
|
|
|
2020-04-17 18:38:33 +00:00
|
|
|
m_compression = new QComboBox;
|
|
|
|
grid_layout->addWidget(new QLabel(tr("Compression:")), 2, 0);
|
|
|
|
grid_layout->addWidget(m_compression, 2, 1);
|
|
|
|
|
|
|
|
m_compression_level = new QComboBox;
|
|
|
|
grid_layout->addWidget(new QLabel(tr("Compression Level:")), 3, 0);
|
|
|
|
grid_layout->addWidget(m_compression_level, 3, 1);
|
|
|
|
|
2020-04-11 11:06:45 +00:00
|
|
|
m_scrub = new QCheckBox;
|
2020-04-17 18:38:33 +00:00
|
|
|
grid_layout->addWidget(new QLabel(tr("Remove Junk Data (Irreversible):")), 4, 0);
|
|
|
|
grid_layout->addWidget(m_scrub, 4, 1);
|
2020-04-11 11:06:45 +00:00
|
|
|
|
2020-04-04 21:18:15 +00:00
|
|
|
QPushButton* convert_button = new QPushButton(tr("Convert"));
|
|
|
|
|
2020-04-11 12:43:47 +00:00
|
|
|
QVBoxLayout* options_layout = new QVBoxLayout;
|
|
|
|
options_layout->addLayout(grid_layout);
|
|
|
|
options_layout->addWidget(convert_button);
|
|
|
|
QGroupBox* options_group = new QGroupBox(tr("Options"));
|
|
|
|
options_group->setLayout(options_layout);
|
|
|
|
|
2020-05-04 10:41:14 +00:00
|
|
|
QLabel* info_text = new QLabel(
|
|
|
|
tr("ISO: A simple and robust format which is supported by many programs. It takes up more "
|
|
|
|
"space than any other format.\n\n"
|
|
|
|
"GCZ: A basic compressed format which is compatible with most versions of Dolphin and "
|
|
|
|
"some other programs. It can't efficiently compress junk data (unless removed) or "
|
|
|
|
"encrypted Wii data.\n\n"
|
2020-06-21 19:16:10 +00:00
|
|
|
"WIA: An advanced compressed format which is compatible with Dolphin 5.0-12188 and later, "
|
2020-05-04 10:41:14 +00:00
|
|
|
"and a few other programs. It can efficiently compress encrypted Wii data, but not junk "
|
|
|
|
"data (unless removed).\n\n"
|
2020-06-21 19:16:10 +00:00
|
|
|
"RVZ: An advanced compressed format which is compatible with Dolphin 5.0-12188 and later. "
|
2020-05-04 10:41:14 +00:00
|
|
|
"It can efficiently compress both junk data and encrypted Wii data."));
|
2020-04-11 12:43:47 +00:00
|
|
|
info_text->setWordWrap(true);
|
|
|
|
|
|
|
|
QVBoxLayout* info_layout = new QVBoxLayout;
|
|
|
|
info_layout->addWidget(info_text);
|
|
|
|
QGroupBox* info_group = new QGroupBox(tr("Info"));
|
|
|
|
info_group->setLayout(info_layout);
|
|
|
|
|
2020-04-04 21:18:15 +00:00
|
|
|
QVBoxLayout* main_layout = new QVBoxLayout;
|
2020-04-11 12:43:47 +00:00
|
|
|
main_layout->addWidget(options_group);
|
|
|
|
main_layout->addWidget(info_group);
|
2020-04-04 21:18:15 +00:00
|
|
|
|
|
|
|
setLayout(main_layout);
|
|
|
|
|
2020-04-10 13:14:03 +00:00
|
|
|
connect(m_format, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
|
|
|
&ConvertDialog::OnFormatChanged);
|
2020-04-17 18:38:33 +00:00
|
|
|
connect(m_compression, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
|
|
|
&ConvertDialog::OnCompressionChanged);
|
2020-04-04 21:18:15 +00:00
|
|
|
connect(convert_button, &QPushButton::clicked, this, &ConvertDialog::Convert);
|
2020-04-10 13:14:03 +00:00
|
|
|
|
|
|
|
OnFormatChanged();
|
2020-04-17 18:38:33 +00:00
|
|
|
OnCompressionChanged();
|
2020-04-04 21:18:15 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 13:14:03 +00:00
|
|
|
void ConvertDialog::AddToBlockSizeComboBox(int size)
|
|
|
|
{
|
|
|
|
m_block_size->addItem(QString::fromStdString(UICommon::FormatSize(size, 0)), size);
|
2020-05-13 14:43:59 +00:00
|
|
|
|
|
|
|
// Select 128 KiB by default, or if it is not available, the size closest to it.
|
|
|
|
// This code assumes that sizes get added to the combo box in increasing order.
|
|
|
|
constexpr int DEFAULT_SIZE = 0x20000;
|
|
|
|
if (size <= DEFAULT_SIZE)
|
|
|
|
m_block_size->setCurrentIndex(m_block_size->count() - 1);
|
2020-04-10 13:14:03 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 13:34:50 +00:00
|
|
|
void ConvertDialog::AddToCompressionComboBox(const QString& name,
|
|
|
|
DiscIO::WIARVZCompressionType type)
|
2020-04-17 18:38:33 +00:00
|
|
|
{
|
|
|
|
m_compression->addItem(name, static_cast<int>(type));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConvertDialog::AddToCompressionLevelComboBox(int level)
|
|
|
|
{
|
|
|
|
m_compression_level->addItem(QString::number(level), level);
|
|
|
|
}
|
|
|
|
|
2020-04-10 13:14:03 +00:00
|
|
|
void ConvertDialog::OnFormatChanged()
|
|
|
|
{
|
|
|
|
// Because DVD timings are emulated as if we can't read less than an entire ECC block at once
|
|
|
|
// (32 KiB - 0x8000), there is little reason to use a block size smaller than that.
|
|
|
|
constexpr int MIN_BLOCK_SIZE = 0x8000;
|
|
|
|
|
|
|
|
// For performance reasons, blocks shouldn't be too large.
|
|
|
|
// 2 MiB (0x200000) was picked because it is the smallest block size supported by WIA.
|
|
|
|
constexpr int MAX_BLOCK_SIZE = 0x200000;
|
|
|
|
|
|
|
|
const DiscIO::BlobType format = static_cast<DiscIO::BlobType>(m_format->currentData().toInt());
|
|
|
|
|
|
|
|
m_block_size->clear();
|
2020-04-17 18:38:33 +00:00
|
|
|
m_compression->clear();
|
|
|
|
|
|
|
|
// Populate m_block_size
|
2020-04-10 13:14:03 +00:00
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
case DiscIO::BlobType::GCZ:
|
|
|
|
{
|
|
|
|
// In order for versions of Dolphin prior to 5.0-11893 to be able to convert a GCZ file
|
|
|
|
// to ISO without messing up the final part of the file in some way, the file size
|
|
|
|
// must be an integer multiple of the block size (fixed in 3aa463c) and must not be
|
|
|
|
// an integer multiple of the block size multiplied by 32 (fixed in 26b21e3).
|
|
|
|
|
|
|
|
const auto block_size_ok = [this](int block_size) {
|
|
|
|
return std::all_of(m_files.begin(), m_files.end(), [block_size](const auto& file) {
|
|
|
|
constexpr u64 BLOCKS_PER_BUFFER = 32;
|
|
|
|
const u64 file_size = file->GetVolumeSize();
|
|
|
|
return file_size % block_size == 0 && file_size % (block_size * BLOCKS_PER_BUFFER) != 0;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Add all block sizes in the normal range that do not cause problems
|
|
|
|
for (int block_size = MIN_BLOCK_SIZE; block_size <= MAX_BLOCK_SIZE; block_size *= 2)
|
|
|
|
{
|
|
|
|
if (block_size_ok(block_size))
|
|
|
|
AddToBlockSizeComboBox(block_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we didn't find a good block size, pick the block size which was hardcoded
|
|
|
|
// in older versions of Dolphin. That way, at least we're not worse than older versions.
|
|
|
|
if (m_block_size->count() == 0)
|
|
|
|
{
|
|
|
|
constexpr int FALLBACK_BLOCK_SIZE = 0x4000;
|
|
|
|
if (!block_size_ok(FALLBACK_BLOCK_SIZE))
|
|
|
|
{
|
|
|
|
ERROR_LOG(MASTER_LOG, "Failed to find a block size which does not cause problems "
|
|
|
|
"when decompressing using an old version of Dolphin");
|
|
|
|
}
|
|
|
|
AddToBlockSizeComboBox(FALLBACK_BLOCK_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2020-04-13 20:04:16 +00:00
|
|
|
case DiscIO::BlobType::WIA:
|
|
|
|
m_block_size->setEnabled(true);
|
|
|
|
|
|
|
|
// This is the smallest block size supported by WIA. For performance, larger sizes are avoided.
|
|
|
|
AddToBlockSizeComboBox(0x200000);
|
|
|
|
|
2020-05-04 22:43:32 +00:00
|
|
|
break;
|
|
|
|
case DiscIO::BlobType::RVZ:
|
|
|
|
m_block_size->setEnabled(true);
|
|
|
|
|
|
|
|
for (int block_size = MIN_BLOCK_SIZE; block_size <= MAX_BLOCK_SIZE; block_size *= 2)
|
|
|
|
AddToBlockSizeComboBox(block_size);
|
|
|
|
|
2020-04-13 20:04:16 +00:00
|
|
|
break;
|
2020-04-10 13:14:03 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2020-06-17 10:47:49 +00:00
|
|
|
|
2020-04-17 18:38:33 +00:00
|
|
|
// Populate m_compression
|
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
case DiscIO::BlobType::GCZ:
|
|
|
|
m_compression->setEnabled(true);
|
2020-05-17 13:34:50 +00:00
|
|
|
AddToCompressionComboBox(QStringLiteral("Deflate"), DiscIO::WIARVZCompressionType::None);
|
2020-04-17 18:38:33 +00:00
|
|
|
break;
|
|
|
|
case DiscIO::BlobType::WIA:
|
2020-05-04 10:41:14 +00:00
|
|
|
case DiscIO::BlobType::RVZ:
|
2020-04-17 18:38:33 +00:00
|
|
|
{
|
|
|
|
m_compression->setEnabled(true);
|
|
|
|
|
|
|
|
// i18n: %1 is the name of a compression method (e.g. LZMA)
|
|
|
|
const QString slow = tr("%1 (slow)");
|
|
|
|
|
2020-05-17 13:34:50 +00:00
|
|
|
AddToCompressionComboBox(tr("No Compression"), DiscIO::WIARVZCompressionType::None);
|
|
|
|
|
2020-05-04 16:21:49 +00:00
|
|
|
if (format == DiscIO::BlobType::WIA)
|
2020-05-17 13:34:50 +00:00
|
|
|
AddToCompressionComboBox(QStringLiteral("Purge"), DiscIO::WIARVZCompressionType::Purge);
|
|
|
|
|
|
|
|
AddToCompressionComboBox(slow.arg(QStringLiteral("bzip2")),
|
|
|
|
DiscIO::WIARVZCompressionType::Bzip2);
|
|
|
|
|
|
|
|
AddToCompressionComboBox(slow.arg(QStringLiteral("LZMA")), DiscIO::WIARVZCompressionType::LZMA);
|
|
|
|
|
|
|
|
AddToCompressionComboBox(slow.arg(QStringLiteral("LZMA2")),
|
|
|
|
DiscIO::WIARVZCompressionType::LZMA2);
|
|
|
|
|
2020-05-04 14:01:56 +00:00
|
|
|
if (format == DiscIO::BlobType::RVZ)
|
|
|
|
{
|
2020-07-05 10:52:59 +00:00
|
|
|
// i18n: %1 is the name of a compression method (e.g. Zstandard)
|
|
|
|
const QString recommended = tr("%1 (recommended)");
|
|
|
|
|
|
|
|
AddToCompressionComboBox(recommended.arg(QStringLiteral("Zstandard")),
|
|
|
|
DiscIO::WIARVZCompressionType::Zstd);
|
2020-05-04 14:01:56 +00:00
|
|
|
m_compression->setCurrentIndex(m_compression->count() - 1);
|
|
|
|
}
|
2020-04-17 18:38:33 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
m_compression->setEnabled(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-06-17 10:47:49 +00:00
|
|
|
m_block_size->setEnabled(m_block_size->count() > 1);
|
2020-04-17 18:38:33 +00:00
|
|
|
m_compression->setEnabled(m_compression->count() > 1);
|
2020-05-10 17:21:05 +00:00
|
|
|
|
2020-07-04 13:06:05 +00:00
|
|
|
const bool scrubbing_allowed =
|
|
|
|
format != DiscIO::BlobType::RVZ &&
|
|
|
|
std::none_of(m_files.begin(), m_files.end(), std::mem_fn(&UICommon::GameFile::IsDatelDisc));
|
|
|
|
|
|
|
|
m_scrub->setEnabled(scrubbing_allowed);
|
|
|
|
if (!scrubbing_allowed)
|
2020-05-10 17:21:05 +00:00
|
|
|
m_scrub->setChecked(false);
|
2020-04-17 18:38:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConvertDialog::OnCompressionChanged()
|
|
|
|
{
|
|
|
|
m_compression_level->clear();
|
|
|
|
|
2020-05-04 14:01:56 +00:00
|
|
|
const auto compression_type =
|
2020-05-17 13:34:50 +00:00
|
|
|
static_cast<DiscIO::WIARVZCompressionType>(m_compression->currentData().toInt());
|
2020-04-17 18:38:33 +00:00
|
|
|
|
2020-05-04 14:01:56 +00:00
|
|
|
const std::pair<int, int> range = DiscIO::GetAllowedCompressionLevels(compression_type);
|
2020-04-17 18:38:33 +00:00
|
|
|
|
2020-05-04 14:01:56 +00:00
|
|
|
for (int i = range.first; i <= range.second; ++i)
|
|
|
|
{
|
|
|
|
AddToCompressionLevelComboBox(i);
|
|
|
|
if (i == 5)
|
|
|
|
m_compression_level->setCurrentIndex(m_compression_level->count() - 1);
|
2020-04-17 18:38:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_compression_level->setEnabled(m_compression_level->count() > 1);
|
2020-04-10 13:14:03 +00:00
|
|
|
}
|
|
|
|
|
2020-04-11 11:06:45 +00:00
|
|
|
bool ConvertDialog::ShowAreYouSureDialog(const QString& text)
|
|
|
|
{
|
|
|
|
ModalMessageBox warning(this);
|
|
|
|
warning.setIcon(QMessageBox::Warning);
|
|
|
|
warning.setWindowTitle(tr("Confirm"));
|
|
|
|
warning.setText(tr("Are you sure?"));
|
|
|
|
warning.setInformativeText(text);
|
|
|
|
warning.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
|
|
|
|
|
|
|
return warning.exec() == QMessageBox::Yes;
|
|
|
|
}
|
|
|
|
|
2020-04-04 21:18:15 +00:00
|
|
|
void ConvertDialog::Convert()
|
|
|
|
{
|
|
|
|
const DiscIO::BlobType format = static_cast<DiscIO::BlobType>(m_format->currentData().toInt());
|
2020-04-10 13:14:03 +00:00
|
|
|
const int block_size = m_block_size->currentData().toInt();
|
2020-05-17 13:34:50 +00:00
|
|
|
const DiscIO::WIARVZCompressionType compression =
|
|
|
|
static_cast<DiscIO::WIARVZCompressionType>(m_compression->currentData().toInt());
|
2020-04-17 18:38:33 +00:00
|
|
|
const int compression_level = m_compression_level->currentData().toInt();
|
2020-04-11 11:06:45 +00:00
|
|
|
const bool scrub = m_scrub->isChecked();
|
2020-04-04 21:18:15 +00:00
|
|
|
|
2020-04-11 11:06:45 +00:00
|
|
|
if (scrub && format == DiscIO::BlobType::PLAIN)
|
|
|
|
{
|
|
|
|
if (!ShowAreYouSureDialog(tr("Removing junk data does not save any space when converting to "
|
|
|
|
"ISO (unless you package the ISO file in a compressed file format "
|
|
|
|
"such as ZIP afterwards). Do you want to continue anyway?")))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-04-04 21:18:15 +00:00
|
|
|
|
2020-04-11 11:06:45 +00:00
|
|
|
if (!scrub && format == DiscIO::BlobType::GCZ &&
|
|
|
|
std::any_of(m_files.begin(), m_files.end(), [](const auto& file) {
|
|
|
|
return file->GetPlatform() == DiscIO::Platform::WiiDisc && !file->IsDatelDisc();
|
2020-04-04 21:18:15 +00:00
|
|
|
}))
|
|
|
|
{
|
2020-04-11 11:06:45 +00:00
|
|
|
if (!ShowAreYouSureDialog(tr("Converting Wii disc images to GCZ without removing junk data "
|
|
|
|
"does not save any noticeable amount of space compared to "
|
|
|
|
"converting to ISO. Do you want to continue anyway?")))
|
|
|
|
{
|
2020-04-04 21:18:15 +00:00
|
|
|
return;
|
2020-04-11 11:06:45 +00:00
|
|
|
}
|
2020-04-04 21:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString extension;
|
|
|
|
QString filter;
|
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
case DiscIO::BlobType::PLAIN:
|
|
|
|
extension = QStringLiteral(".iso");
|
|
|
|
filter = tr("Uncompressed GC/Wii images (*.iso *.gcm)");
|
|
|
|
break;
|
|
|
|
case DiscIO::BlobType::GCZ:
|
|
|
|
extension = QStringLiteral(".gcz");
|
2020-04-13 20:04:16 +00:00
|
|
|
filter = tr("GCZ GC/Wii images (*.gcz)");
|
|
|
|
break;
|
|
|
|
case DiscIO::BlobType::WIA:
|
|
|
|
extension = QStringLiteral(".wia");
|
|
|
|
filter = tr("WIA GC/Wii images (*.wia)");
|
2020-04-04 21:18:15 +00:00
|
|
|
break;
|
2020-05-04 10:41:14 +00:00
|
|
|
case DiscIO::BlobType::RVZ:
|
|
|
|
extension = QStringLiteral(".rvz");
|
|
|
|
filter = tr("RVZ GC/Wii images (*.rvz)");
|
|
|
|
break;
|
2020-04-04 21:18:15 +00:00
|
|
|
default:
|
|
|
|
ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString dst_dir;
|
|
|
|
QString dst_path;
|
|
|
|
|
|
|
|
if (m_files.size() > 1)
|
|
|
|
{
|
|
|
|
dst_dir = QFileDialog::getExistingDirectory(
|
|
|
|
this, tr("Select where you want to save the converted images"),
|
|
|
|
QFileInfo(QString::fromStdString(m_files[0]->GetFilePath())).dir().absolutePath());
|
|
|
|
|
|
|
|
if (dst_dir.isEmpty())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dst_path = QFileDialog::getSaveFileName(
|
|
|
|
this, tr("Select where you want to save the converted image"),
|
|
|
|
QFileInfo(QString::fromStdString(m_files[0]->GetFilePath()))
|
|
|
|
.dir()
|
|
|
|
.absoluteFilePath(
|
|
|
|
QFileInfo(QString::fromStdString(m_files[0]->GetFilePath())).completeBaseName())
|
|
|
|
.append(extension),
|
|
|
|
filter);
|
|
|
|
|
|
|
|
if (dst_path.isEmpty())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto& file : m_files)
|
|
|
|
{
|
|
|
|
const auto original_path = file->GetFilePath();
|
|
|
|
if (m_files.size() > 1)
|
|
|
|
{
|
|
|
|
dst_path =
|
|
|
|
QDir(dst_dir)
|
|
|
|
.absoluteFilePath(QFileInfo(QString::fromStdString(original_path)).completeBaseName())
|
|
|
|
.append(extension);
|
|
|
|
QFileInfo dst_info = QFileInfo(dst_path);
|
|
|
|
if (dst_info.exists())
|
|
|
|
{
|
|
|
|
ModalMessageBox confirm_replace(this);
|
|
|
|
confirm_replace.setIcon(QMessageBox::Warning);
|
|
|
|
confirm_replace.setWindowTitle(tr("Confirm"));
|
|
|
|
confirm_replace.setText(tr("The file %1 already exists.\n"
|
|
|
|
"Do you wish to replace it?")
|
|
|
|
.arg(dst_info.fileName()));
|
|
|
|
confirm_replace.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
|
|
|
|
|
|
|
if (confirm_replace.exec() == QMessageBox::No)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ParallelProgressDialog progress_dialog(tr("Converting..."), tr("Abort"), 0, 100, this);
|
|
|
|
progress_dialog.GetRaw()->setWindowModality(Qt::WindowModal);
|
|
|
|
progress_dialog.GetRaw()->setWindowTitle(tr("Progress"));
|
|
|
|
|
|
|
|
if (m_files.size() > 1)
|
|
|
|
{
|
|
|
|
progress_dialog.GetRaw()->setLabelText(
|
|
|
|
tr("Converting...") + QLatin1Char{'\n'} +
|
|
|
|
QFileInfo(QString::fromStdString(original_path)).fileName());
|
|
|
|
}
|
|
|
|
|
2020-04-10 15:40:07 +00:00
|
|
|
std::unique_ptr<DiscIO::BlobReader> blob_reader;
|
2020-04-11 11:06:45 +00:00
|
|
|
bool scrub_current_file = scrub;
|
2020-04-04 21:18:15 +00:00
|
|
|
|
2020-04-10 15:40:07 +00:00
|
|
|
if (scrub_current_file)
|
2020-04-04 21:18:15 +00:00
|
|
|
{
|
2020-04-10 15:40:07 +00:00
|
|
|
blob_reader = DiscIO::ScrubbedBlob::Create(original_path);
|
|
|
|
if (!blob_reader)
|
|
|
|
{
|
|
|
|
const int result =
|
|
|
|
ModalMessageBox::warning(this, tr("Question"),
|
|
|
|
tr("Failed to remove junk data from file \"%1\".\n\n"
|
|
|
|
"Would you like to convert it without removing junk data?")
|
|
|
|
.arg(QString::fromStdString(original_path)),
|
|
|
|
QMessageBox::Ok | QMessageBox::Abort);
|
|
|
|
|
|
|
|
if (result == QMessageBox::Ok)
|
|
|
|
scrub_current_file = false;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
2020-04-04 21:18:15 +00:00
|
|
|
}
|
2020-04-10 15:40:07 +00:00
|
|
|
|
|
|
|
if (!scrub_current_file)
|
|
|
|
blob_reader = DiscIO::CreateBlobReader(original_path);
|
|
|
|
|
|
|
|
if (!blob_reader)
|
2020-04-04 21:18:15 +00:00
|
|
|
{
|
2020-06-16 08:39:40 +00:00
|
|
|
ModalMessageBox::critical(
|
|
|
|
this, tr("Error"),
|
2020-04-10 15:40:07 +00:00
|
|
|
tr("Failed to open the input file \"%1\".").arg(QString::fromStdString(original_path)));
|
2020-06-16 08:35:00 +00:00
|
|
|
return;
|
2020-04-04 21:18:15 +00:00
|
|
|
}
|
2020-04-10 15:40:07 +00:00
|
|
|
else
|
2020-04-04 21:18:15 +00:00
|
|
|
{
|
2020-06-25 14:44:02 +00:00
|
|
|
std::future<bool> success;
|
2020-04-10 15:40:07 +00:00
|
|
|
|
2020-05-04 10:41:14 +00:00
|
|
|
switch (format)
|
2020-04-10 15:40:07 +00:00
|
|
|
{
|
2020-05-04 10:41:14 +00:00
|
|
|
case DiscIO::BlobType::PLAIN:
|
2020-06-25 14:44:02 +00:00
|
|
|
success = std::async(std::launch::async, [&] {
|
2020-04-10 15:40:07 +00:00
|
|
|
const bool good =
|
|
|
|
DiscIO::ConvertToPlain(blob_reader.get(), original_path, dst_path.toStdString(),
|
|
|
|
&CompressCB, &progress_dialog);
|
|
|
|
progress_dialog.Reset();
|
|
|
|
return good;
|
|
|
|
});
|
2020-05-04 10:41:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DiscIO::BlobType::GCZ:
|
2020-06-25 14:44:02 +00:00
|
|
|
success = std::async(std::launch::async, [&] {
|
2020-04-10 15:40:07 +00:00
|
|
|
const bool good =
|
|
|
|
DiscIO::ConvertToGCZ(blob_reader.get(), original_path, dst_path.toStdString(),
|
2020-04-10 13:14:03 +00:00
|
|
|
file->GetPlatform() == DiscIO::Platform::WiiDisc ? 1 : 0,
|
|
|
|
block_size, &CompressCB, &progress_dialog);
|
2020-04-10 15:40:07 +00:00
|
|
|
progress_dialog.Reset();
|
|
|
|
return good;
|
|
|
|
});
|
2020-05-04 10:41:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DiscIO::BlobType::WIA:
|
|
|
|
case DiscIO::BlobType::RVZ:
|
2020-06-25 14:44:02 +00:00
|
|
|
success = std::async(std::launch::async, [&] {
|
2020-05-17 13:34:50 +00:00
|
|
|
const bool good = DiscIO::ConvertToWIAOrRVZ(
|
|
|
|
blob_reader.get(), original_path, dst_path.toStdString(),
|
|
|
|
format == DiscIO::BlobType::RVZ, compression, compression_level, block_size,
|
|
|
|
&CompressCB, &progress_dialog);
|
2020-04-13 20:04:16 +00:00
|
|
|
progress_dialog.Reset();
|
|
|
|
return good;
|
|
|
|
});
|
2020-05-04 10:41:14 +00:00
|
|
|
break;
|
2020-06-25 14:34:43 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
ASSERT(false);
|
|
|
|
break;
|
2020-04-13 20:04:16 +00:00
|
|
|
}
|
2020-04-10 15:40:07 +00:00
|
|
|
|
|
|
|
progress_dialog.GetRaw()->exec();
|
2020-06-25 14:44:02 +00:00
|
|
|
if (!success.get())
|
2020-04-10 15:40:07 +00:00
|
|
|
{
|
2020-06-16 08:39:40 +00:00
|
|
|
ModalMessageBox::critical(this, tr("Error"),
|
|
|
|
tr("Dolphin failed to complete the requested action."));
|
2020-04-10 15:40:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-04-04 21:18:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ModalMessageBox::information(this, tr("Success"),
|
|
|
|
tr("Successfully converted %n image(s).", "", m_files.size()));
|
|
|
|
|
|
|
|
close();
|
|
|
|
}
|