Use QSaveFile wherever applicable

expected.hpp was fetched from:
b803e3c07b/include/nonstd/expected.hpp
This commit is contained in:
Chocobo1
2021-09-05 12:29:32 +08:00
parent 81139c0098
commit 21f72baae2
17 changed files with 2597 additions and 88 deletions

View File

@@ -30,13 +30,11 @@
#include <fstream>
#include <libtorrent/bencode.hpp>
#include <libtorrent/create_torrent.hpp>
#include <libtorrent/file_storage.hpp>
#include <libtorrent/torrent_info.hpp>
#include <QDirIterator>
#include <QFile>
#include <QFileInfo>
#include <QHash>
@@ -209,16 +207,9 @@ void TorrentCreatorThread::run()
checkInterruptionRequested();
// create the torrent
QFile outfile {m_params.savePath};
if (!outfile.open(QIODevice::WriteOnly))
throw RuntimeError(outfile.errorString());
checkInterruptionRequested();
lt::bencode(Utils::IO::FileDeviceOutputIterator {outfile}, entry);
if (outfile.error() != QFileDevice::NoError)
throw RuntimeError(outfile.errorString());
outfile.close();
const nonstd::expected<void, QString> result = Utils::IO::saveToFile(m_params.savePath, entry);
if (!result)
throw RuntimeError(result.error());
emit updateProgress(100);
emit creationSuccess(m_params.savePath, parentPath);