mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-31 03:50:20 -07:00
Don't throw exception in TorrentInfo::saveToFile()
This commit is contained in:
parent
41fc0fd084
commit
78459fcb31
4 changed files with 13 additions and 20 deletions
|
@ -69,7 +69,6 @@
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
|
||||||
#include "base/algorithm.h"
|
#include "base/algorithm.h"
|
||||||
#include "base/exceptions.h"
|
|
||||||
#include "base/global.h"
|
#include "base/global.h"
|
||||||
#include "base/logger.h"
|
#include "base/logger.h"
|
||||||
#include "base/net/downloadmanager.h"
|
#include "base/net/downloadmanager.h"
|
||||||
|
@ -2317,14 +2316,11 @@ void Session::exportTorrentFile(const TorrentInfo &torrentInfo, const QString &f
|
||||||
newTorrentPath = exportDir.absoluteFilePath(torrentExportFilename);
|
newTorrentPath = exportDir.absoluteFilePath(torrentExportFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
const nonstd::expected<void, QString> result = torrentInfo.saveToFile(newTorrentPath);
|
||||||
{
|
if (!result)
|
||||||
torrentInfo.saveToFile(newTorrentPath);
|
|
||||||
}
|
|
||||||
catch (const RuntimeError &err)
|
|
||||||
{
|
{
|
||||||
LogMsg(tr("Couldn't export torrent metadata file '%1'. Reason: %2.")
|
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 <QUrl>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
#include "base/exceptions.h"
|
|
||||||
#include "base/global.h"
|
#include "base/global.h"
|
||||||
#include "base/utils/fs.h"
|
#include "base/utils/fs.h"
|
||||||
#include "base/utils/io.h"
|
#include "base/utils/io.h"
|
||||||
|
@ -153,10 +152,10 @@ nonstd::expected<TorrentInfo, QString> TorrentInfo::loadFromFile(const QString &
|
||||||
return load(data);
|
return load(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentInfo::saveToFile(const QString &path) const
|
nonstd::expected<void, QString> TorrentInfo::saveToFile(const QString &path) const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
if (!isValid())
|
||||||
throw RuntimeError {tr("Invalid metadata")};
|
return nonstd::make_unexpected(tr("Invalid metadata"));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -164,12 +163,14 @@ void TorrentInfo::saveToFile(const QString &path) const
|
||||||
const lt::entry torrentEntry = torrentCreator.generate();
|
const lt::entry torrentEntry = torrentCreator.generate();
|
||||||
const nonstd::expected<void, QString> result = Utils::IO::saveToFile(path, torrentEntry);
|
const nonstd::expected<void, QString> result = Utils::IO::saveToFile(path, torrentEntry);
|
||||||
if (!result)
|
if (!result)
|
||||||
throw RuntimeError(result.error());
|
return result.get_unexpected();
|
||||||
}
|
}
|
||||||
catch (const lt::system_error &err)
|
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
|
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> load(const QByteArray &data) noexcept;
|
||||||
static nonstd::expected<TorrentInfo, QString> loadFromFile(const QString &path) 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);
|
TorrentInfo &operator=(const TorrentInfo &other);
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,6 @@
|
||||||
#include "base/bittorrent/magneturi.h"
|
#include "base/bittorrent/magneturi.h"
|
||||||
#include "base/bittorrent/session.h"
|
#include "base/bittorrent/session.h"
|
||||||
#include "base/bittorrent/torrent.h"
|
#include "base/bittorrent/torrent.h"
|
||||||
#include "base/exceptions.h"
|
|
||||||
#include "base/global.h"
|
#include "base/global.h"
|
||||||
#include "base/net/downloadmanager.h"
|
#include "base/net/downloadmanager.h"
|
||||||
#include "base/settingsstorage.h"
|
#include "base/settingsstorage.h"
|
||||||
|
@ -473,14 +472,11 @@ void AddNewTorrentDialog::saveTorrentFile()
|
||||||
if (!path.endsWith(torrentFileExtension, Qt::CaseInsensitive))
|
if (!path.endsWith(torrentFileExtension, Qt::CaseInsensitive))
|
||||||
path += torrentFileExtension;
|
path += torrentFileExtension;
|
||||||
|
|
||||||
try
|
const nonstd::expected<void, QString> result = m_torrentInfo.saveToFile(path);
|
||||||
{
|
if (!result)
|
||||||
m_torrentInfo.saveToFile(path);
|
|
||||||
}
|
|
||||||
catch (const RuntimeError &err)
|
|
||||||
{
|
{
|
||||||
QMessageBox::critical(this, tr("I/O Error")
|
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…
Add table
Add a link
Reference in a new issue