Remove all existing cover files for a game before writing a new one

This commit is contained in:
Marco Allegretti 2026-03-23 13:05:50 +01:00
parent 24400ca5e1
commit 834b3a2ab6

View file

@ -1462,15 +1462,15 @@ bool App::setCoverFromFile(Game *game, const QString &filePath)
extension = QStringLiteral("jpg"); extension = QStringLiteral("jpg");
} }
QDir coversDir(coversPath);
const QStringList existingCovers = coversDir.entryList({game->id() + QStringLiteral(".*")}, QDir::Files);
for (const QString &existing : existingCovers) {
coversDir.remove(existing);
}
QString destFileName = game->id() + QStringLiteral(".") + extension; QString destFileName = game->id() + QStringLiteral(".") + extension;
QString destPath = coversPath + QStringLiteral("/") + destFileName; QString destPath = coversPath + QStringLiteral("/") + destFileName;
// Remove existing cover if any
QFile destFile(destPath);
if (destFile.exists()) {
destFile.remove();
}
// Copy file // Copy file
if (!sourceFile.copy(destPath)) { if (!sourceFile.copy(destPath)) {
return false; return false;