Merge pull request #8738 from JosJuice/convert-dialog

Replace the compress/uncompress actions with a convert dialog
This commit is contained in:
JMC47
2020-04-28 12:37:17 -04:00
committed by GitHub
26 changed files with 760 additions and 430 deletions

View File

@ -6,7 +6,7 @@
#include <algorithm>
#include <cmath>
#include <future>
#include <utility>
#include <QDesktopServices>
#include <QDir>
@ -40,6 +40,7 @@
#include "DiscIO/Enums.h"
#include "DolphinQt/Config/PropertiesDialog.h"
#include "DolphinQt/ConvertDialog.h"
#include "DolphinQt/GameList/GameListModel.h"
#include "DolphinQt/GameList/GridProxyModel.h"
#include "DolphinQt/GameList/ListProxyModel.h"
@ -53,8 +54,6 @@
#include "UICommon/GameFile.h"
static bool CompressCB(const std::string&, float, void*);
GameList::GameList(QWidget* parent) : QStackedWidget(parent)
{
m_model = Settings::Instance().GetGameListModel();
@ -257,35 +256,16 @@ void GameList::ShowContextMenu(const QPoint&)
if (HasMultipleSelected())
{
bool wii_saves = true;
bool compress = false;
bool decompress = false;
for (const auto& game : GetSelectedGames())
if (std::all_of(GetSelectedGames().begin(), GetSelectedGames().end(), [](const auto& game) {
return DiscIO::IsDisc(game->GetPlatform()) && game->IsVolumeSizeAccurate();
}))
{
DiscIO::Platform platform = game->GetPlatform();
if (platform == DiscIO::Platform::GameCubeDisc || platform == DiscIO::Platform::WiiDisc)
{
const auto blob_type = game->GetBlobType();
if (blob_type == DiscIO::BlobType::GCZ)
decompress = true;
else if (blob_type == DiscIO::BlobType::PLAIN)
compress = true;
}
if (platform != DiscIO::Platform::WiiWAD && platform != DiscIO::Platform::WiiDisc)
wii_saves = false;
menu->addAction(tr("Convert Selected Files..."), this, &GameList::ConvertFile);
menu->addSeparator();
}
if (compress)
menu->addAction(tr("Compress Selected ISOs..."), this, [this] { CompressISO(false); });
if (decompress)
menu->addAction(tr("Decompress Selected ISOs..."), this, [this] { CompressISO(true); });
if (compress || decompress)
menu->addSeparator();
if (wii_saves)
if (std::all_of(GetSelectedGames().begin(), GetSelectedGames().end(),
[](const auto& game) { return DiscIO::IsWii(game->GetPlatform()); }))
{
menu->addAction(tr("Export Wii Saves"), this, &GameList::ExportWiiSave);
menu->addSeparator();
@ -306,15 +286,13 @@ void GameList::ShowContextMenu(const QPoint&)
menu->addSeparator();
}
if (platform == DiscIO::Platform::GameCubeDisc || platform == DiscIO::Platform::WiiDisc)
if (DiscIO::IsDisc(platform))
{
menu->addAction(tr("Set as &Default ISO"), this, &GameList::SetDefaultISO);
const auto blob_type = game->GetBlobType();
if (blob_type == DiscIO::BlobType::GCZ)
menu->addAction(tr("Decompress ISO..."), this, [this] { CompressISO(true); });
else if (blob_type == DiscIO::BlobType::PLAIN)
menu->addAction(tr("Compress ISO..."), this, [this] { CompressISO(false); });
if (game->IsVolumeSizeAccurate())
menu->addAction(tr("Convert File..."), this, &GameList::ConvertFile);
QAction* change_disc = menu->addAction(tr("Change &Disc"), this, &GameList::ChangeDisc);
@ -481,157 +459,14 @@ void GameList::OpenWiki()
QDesktopServices::openUrl(QUrl(url));
}
void GameList::CompressISO(bool decompress)
void GameList::ConvertFile()
{
auto files = GetSelectedGames();
const auto game = GetSelectedGame();
if (files.empty() || !game)
auto games = GetSelectedGames();
if (games.empty())
return;
bool wii_warning_given = false;
for (QMutableListIterator<std::shared_ptr<const UICommon::GameFile>> it(files); it.hasNext();)
{
auto file = it.next();
if ((file->GetPlatform() != DiscIO::Platform::GameCubeDisc &&
file->GetPlatform() != DiscIO::Platform::WiiDisc) ||
(decompress && file->GetBlobType() != DiscIO::BlobType::GCZ) ||
(!decompress && file->GetBlobType() != DiscIO::BlobType::PLAIN))
{
it.remove();
continue;
}
if (!wii_warning_given && !decompress && file->GetPlatform() == DiscIO::Platform::WiiDisc)
{
ModalMessageBox wii_warning(this);
wii_warning.setIcon(QMessageBox::Warning);
wii_warning.setWindowTitle(tr("Confirm"));
wii_warning.setText(tr("Are you sure?"));
wii_warning.setInformativeText(tr(
"Compressing a Wii disc image will irreversibly change the compressed copy by removing "
"padding data. Your disc image will still work. Continue?"));
wii_warning.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
if (wii_warning.exec() == QMessageBox::No)
return;
wii_warning_given = true;
}
}
QString dst_dir;
QString dst_path;
if (files.size() > 1)
{
dst_dir = QFileDialog::getExistingDirectory(
this,
decompress ? tr("Select where you want to save the decompressed images") :
tr("Select where you want to save the compressed images"),
QFileInfo(QString::fromStdString(game->GetFilePath())).dir().absolutePath());
if (dst_dir.isEmpty())
return;
}
else
{
dst_path = QFileDialog::getSaveFileName(
this,
decompress ? tr("Select where you want to save the decompressed image") :
tr("Select where you want to save the compressed image"),
QFileInfo(QString::fromStdString(game->GetFilePath()))
.dir()
.absoluteFilePath(
QFileInfo(QString::fromStdString(files[0]->GetFilePath())).completeBaseName())
.append(decompress ? QStringLiteral(".gcm") : QStringLiteral(".gcz")),
decompress ? tr("Uncompressed GC/Wii images (*.iso *.gcm)") :
tr("Compressed GC/Wii images (*.gcz)"));
if (dst_path.isEmpty())
return;
}
for (const auto& file : files)
{
const auto original_path = file->GetFilePath();
if (files.size() > 1)
{
dst_path =
QDir(dst_dir)
.absoluteFilePath(QFileInfo(QString::fromStdString(original_path)).completeBaseName())
.append(decompress ? QStringLiteral(".gcm") : QStringLiteral(".gcz"));
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(
decompress ? tr("Decompressing...") : tr("Compressing..."), tr("Abort"), 0, 100, this);
progress_dialog.GetRaw()->setWindowModality(Qt::WindowModal);
progress_dialog.GetRaw()->setWindowTitle(tr("Progress"));
std::future<bool> good;
if (decompress)
{
if (files.size() > 1)
{
progress_dialog.GetRaw()->setLabelText(
tr("Decompressing...") + QLatin1Char{'\n'} +
QFileInfo(QString::fromStdString(original_path)).fileName());
}
good = std::async(std::launch::async, [&] {
const bool good = DiscIO::DecompressBlobToFile(original_path, dst_path.toStdString(),
&CompressCB, &progress_dialog);
progress_dialog.Reset();
return good;
});
}
else
{
if (files.size() > 1)
{
progress_dialog.GetRaw()->setLabelText(
tr("Compressing...") + QLatin1Char{'\n'} +
QFileInfo(QString::fromStdString(original_path)).fileName());
}
good = std::async(std::launch::async, [&] {
const bool good =
DiscIO::CompressFileToBlob(original_path, dst_path.toStdString(),
file->GetPlatform() == DiscIO::Platform::WiiDisc ? 1 : 0,
16384, &CompressCB, &progress_dialog);
progress_dialog.Reset();
return good;
});
}
progress_dialog.GetRaw()->exec();
if (!good.get())
{
QErrorMessage(this).showMessage(tr("Dolphin failed to complete the requested action."));
return;
}
}
ModalMessageBox::information(this, tr("Success"),
decompress ?
tr("Successfully decompressed %n image(s).", "", files.size()) :
tr("Successfully compressed %n image(s).", "", files.size()));
ConvertDialog dialog{std::move(games), this};
dialog.exec();
}
void GameList::InstallWAD()
@ -953,17 +788,6 @@ void GameList::OnGameListVisibilityChanged()
m_grid_proxy->invalidate();
}
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();
}
void GameList::OnSectionResized(int index, int, int)
{
auto* hor_header = m_list->horizontalHeader();

View File

@ -64,7 +64,7 @@ private:
void InstallWAD();
void UninstallWAD();
void ExportWiiSave();
void CompressISO(bool decompress);
void ConvertFile();
void ChangeDisc();
void NewTag();
void DeleteTag();