Ensure file name is valid when exporting torrents

Closes #19275.
Closes #19329.
This commit is contained in:
Chocobo1 2023-08-03 12:38:56 +08:00
parent 8376707379
commit 80bb19701c

View file

@ -818,7 +818,8 @@ void TransferListWidget::exportTorrent()
bool hasError = false; bool hasError = false;
for (const BitTorrent::Torrent *torrent : torrents) for (const BitTorrent::Torrent *torrent : torrents)
{ {
const Path filePath = savePath / Path(torrent->name() + u".torrent"); const QString validName = Utils::Fs::toValidFileName(torrent->name(), u"_"_s);
const Path filePath = savePath / Path(validName + u".torrent");
if (filePath.exists()) if (filePath.exists())
{ {
LogMsg(errorMsg.arg(torrent->name(), filePath.toString(), tr("A file with the same name already exists")) , Log::WARNING); LogMsg(errorMsg.arg(torrent->name(), filePath.toString(), tr("A file with the same name already exists")) , Log::WARNING);