Qt: Disallow copying cover when source == destination

Closes #6159.
This commit is contained in:
Stenzek 2023-09-09 13:24:31 +10:00 committed by Connor McLaughlin
parent abe64ae8fb
commit 96f0d65f7d
1 changed files with 11 additions and 5 deletions

View File

@ -2294,14 +2294,24 @@ void MainWindow::startGameListEntry(const GameList::Entry* entry, std::optional<
void MainWindow::setGameListEntryCoverImage(const GameList::Entry* entry)
{
const QString filename(
const QString filename = QDir::toNativeSeparators(
QFileDialog::getOpenFileName(this, tr("Select Cover Image"), QString(), tr("All Cover Image Types (*.jpg *.jpeg *.png)")));
if (filename.isEmpty())
return;
const QString old_filename = QString::fromStdString(GameList::GetCoverImagePathForEntry(entry));
const QString new_filename = QString::fromStdString(GameList::GetNewCoverImagePathForEntry(entry, filename.toUtf8().constData()));
if (new_filename.isEmpty())
return;
if (!old_filename.isEmpty())
{
if (QFileInfo(old_filename) == QFileInfo(filename))
{
QMessageBox::critical(this, tr("Copy Error"), tr("You must select a different file to the current cover image."));
return;
}
if (QMessageBox::question(this, tr("Cover Already Exists"),
tr("A cover image for this game already exists, do you wish to replace it?"), QMessageBox::Yes,
QMessageBox::No) != QMessageBox::Yes)
@ -2310,10 +2320,6 @@ void MainWindow::setGameListEntryCoverImage(const GameList::Entry* entry)
}
}
const QString new_filename(QString::fromStdString(GameList::GetNewCoverImagePathForEntry(entry, filename.toUtf8().constData())));
if (new_filename.isEmpty())
return;
if (QFile::exists(new_filename) && !QFile::remove(new_filename))
{
QMessageBox::critical(this, tr("Copy Error"), tr("Failed to remove existing cover '%1'").arg(new_filename));