mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-03-07 19:47:04 +08:00
Don't throw exception in TorrentInfo::saveToFile()
This commit is contained in:
parent
41fc0fd084
commit
78459fcb31
@ -69,7 +69,6 @@
|
||||
#include <QUuid>
|
||||
|
||||
#include "base/algorithm.h"
|
||||
#include "base/exceptions.h"
|
||||
#include "base/global.h"
|
||||
#include "base/logger.h"
|
||||
#include "base/net/downloadmanager.h"
|
||||
@ -2317,14 +2316,11 @@ void Session::exportTorrentFile(const TorrentInfo &torrentInfo, const QString &f
|
||||
newTorrentPath = exportDir.absoluteFilePath(torrentExportFilename);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
torrentInfo.saveToFile(newTorrentPath);
|
||||
}
|
||||
catch (const RuntimeError &err)
|
||||
const nonstd::expected<void, QString> result = torrentInfo.saveToFile(newTorrentPath);
|
||||
if (!result)
|
||||
{
|
||||
LogMsg(tr("Couldn't export torrent metadata file '%1'. Reason: %2.")
|
||||
.arg(newTorrentPath, err.message()), Log::WARNING);
|
||||
.arg(newTorrentPath, result.error()), Log::WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,6 @@
|
||||
#include <QUrl>
|
||||
#include <QVector>
|
||||
|
||||
#include "base/exceptions.h"
|
||||
#include "base/global.h"
|
||||
#include "base/utils/fs.h"
|
||||
#include "base/utils/io.h"
|
||||
@ -153,10 +152,10 @@ nonstd::expected<TorrentInfo, QString> TorrentInfo::loadFromFile(const QString &
|
||||
return load(data);
|
||||
}
|
||||
|
||||
void TorrentInfo::saveToFile(const QString &path) const
|
||||
nonstd::expected<void, QString> TorrentInfo::saveToFile(const QString &path) const
|
||||
{
|
||||
if (!isValid())
|
||||
throw RuntimeError {tr("Invalid metadata")};
|
||||
return nonstd::make_unexpected(tr("Invalid metadata"));
|
||||
|
||||
try
|
||||
{
|
||||
@ -164,12 +163,14 @@ void TorrentInfo::saveToFile(const QString &path) const
|
||||
const lt::entry torrentEntry = torrentCreator.generate();
|
||||
const nonstd::expected<void, QString> result = Utils::IO::saveToFile(path, torrentEntry);
|
||||
if (!result)
|
||||
throw RuntimeError(result.error());
|
||||
return result.get_unexpected();
|
||||
}
|
||||
catch (const lt::system_error &err)
|
||||
{
|
||||
throw RuntimeError(QString::fromLocal8Bit(err.what()));
|
||||
return nonstd::make_unexpected(QString::fromLocal8Bit(err.what()));
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
bool TorrentInfo::isValid() const
|
||||
|
@ -58,7 +58,7 @@ namespace BitTorrent
|
||||
|
||||
static nonstd::expected<TorrentInfo, QString> load(const QByteArray &data) noexcept;
|
||||
static nonstd::expected<TorrentInfo, QString> loadFromFile(const QString &path) noexcept;
|
||||
void saveToFile(const QString &path) const;
|
||||
nonstd::expected<void, QString> saveToFile(const QString &path) const;
|
||||
|
||||
TorrentInfo &operator=(const TorrentInfo &other);
|
||||
|
||||
|
@ -43,7 +43,6 @@
|
||||
#include "base/bittorrent/magneturi.h"
|
||||
#include "base/bittorrent/session.h"
|
||||
#include "base/bittorrent/torrent.h"
|
||||
#include "base/exceptions.h"
|
||||
#include "base/global.h"
|
||||
#include "base/net/downloadmanager.h"
|
||||
#include "base/settingsstorage.h"
|
||||
@ -473,14 +472,11 @@ void AddNewTorrentDialog::saveTorrentFile()
|
||||
if (!path.endsWith(torrentFileExtension, Qt::CaseInsensitive))
|
||||
path += torrentFileExtension;
|
||||
|
||||
try
|
||||
{
|
||||
m_torrentInfo.saveToFile(path);
|
||||
}
|
||||
catch (const RuntimeError &err)
|
||||
const nonstd::expected<void, QString> result = m_torrentInfo.saveToFile(path);
|
||||
if (!result)
|
||||
{
|
||||
QMessageBox::critical(this, tr("I/O Error")
|
||||
, tr("Couldn't export torrent metadata file '%1'. Reason: %2.").arg(path, err.message()));
|
||||
, tr("Couldn't export torrent metadata file '%1'. Reason: %2.").arg(path, result.error()));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user