mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-06-29 01:54:20 +03:00
Remove std::unique_ptr from ByteArraySink
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
(cherry picked from commit 1ac986b7c8)
This commit is contained in:
parent
4e4990bf8d
commit
4af3cdff01
5 changed files with 17 additions and 23 deletions
|
|
@ -45,17 +45,12 @@ namespace Net {
|
|||
*/
|
||||
class ByteArraySink : public Sink {
|
||||
public:
|
||||
ByteArraySink(std::unique_ptr<QByteArray> output) : m_output(std::move(output)) {}
|
||||
|
||||
virtual ~ByteArraySink() = default;
|
||||
|
||||
public:
|
||||
auto init(QNetworkRequest& request) -> Task::State override
|
||||
{
|
||||
if (m_output)
|
||||
m_output->clear();
|
||||
else
|
||||
qWarning() << "ByteArraySink did not initialize the buffer because it's not addressable";
|
||||
m_output.clear();
|
||||
if (initAllValidators(request))
|
||||
return Task::State::Running;
|
||||
m_fail_reason = "Failed to initialize validators";
|
||||
|
|
@ -64,10 +59,7 @@ class ByteArraySink : public Sink {
|
|||
|
||||
auto write(QByteArray& data) -> Task::State override
|
||||
{
|
||||
if (m_output)
|
||||
m_output->append(data);
|
||||
else
|
||||
qWarning() << "ByteArraySink did not write the buffer because it's not addressable";
|
||||
m_output.append(data);
|
||||
if (writeAllValidators(data))
|
||||
return Task::State::Running;
|
||||
m_fail_reason = "Failed to write validators";
|
||||
|
|
@ -91,7 +83,9 @@ class ByteArraySink : public Sink {
|
|||
|
||||
auto hasLocalData() -> bool override { return false; }
|
||||
|
||||
QByteArray* output() { return &m_output; }
|
||||
|
||||
protected:
|
||||
std::unique_ptr<QByteArray> m_output;
|
||||
QByteArray m_output;
|
||||
};
|
||||
} // namespace Net
|
||||
|
|
|
|||
|
|
@ -70,8 +70,9 @@ auto Download::makeByteArray(QUrl url, Options options) -> std::pair<Download::P
|
|||
dl->setObjectName(QString("BYTES:") + url.toString());
|
||||
dl->m_options = options;
|
||||
|
||||
auto response = new QByteArray();
|
||||
dl->m_sink = std::make_unique<ByteArraySink>(std::unique_ptr<QByteArray>{ response });
|
||||
auto sink = std::make_unique<ByteArraySink>();
|
||||
QByteArray* response = sink->output();
|
||||
dl->m_sink = std::move(sink);
|
||||
|
||||
return { dl, response };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,11 +119,11 @@ auto PasteUpload::Sink::finalize(QNetworkReply& reply) -> Task::State
|
|||
|
||||
switch (m_d->m_paste_type) {
|
||||
case PasteUpload::NullPointer:
|
||||
m_d->m_pasteLink = QString::fromUtf8(*m_output).trimmed();
|
||||
m_d->m_pasteLink = QString::fromUtf8(*output()).trimmed();
|
||||
break;
|
||||
case PasteUpload::Hastebin: {
|
||||
QJsonParseError jsonError;
|
||||
auto doc = QJsonDocument::fromJson(*m_output, &jsonError);
|
||||
auto doc = QJsonDocument::fromJson(*output(), &jsonError);
|
||||
if (jsonError.error != QJsonParseError::NoError) {
|
||||
qDebug() << "hastebin server did not reply with JSON" << jsonError.errorString();
|
||||
m_fail_reason =
|
||||
|
|
@ -144,7 +144,7 @@ auto PasteUpload::Sink::finalize(QNetworkReply& reply) -> Task::State
|
|||
}
|
||||
case PasteUpload::Mclogs: {
|
||||
QJsonParseError jsonError;
|
||||
auto doc = QJsonDocument::fromJson(*m_output, &jsonError);
|
||||
auto doc = QJsonDocument::fromJson(*output(), &jsonError);
|
||||
if (jsonError.error != QJsonParseError::NoError) {
|
||||
qDebug() << "mclogs server did not reply with JSON" << jsonError.errorString();
|
||||
m_fail_reason =
|
||||
|
|
@ -171,7 +171,7 @@ auto PasteUpload::Sink::finalize(QNetworkReply& reply) -> Task::State
|
|||
}
|
||||
case PasteUpload::PasteGG:
|
||||
QJsonParseError jsonError;
|
||||
auto doc = QJsonDocument::fromJson(*m_output, &jsonError);
|
||||
auto doc = QJsonDocument::fromJson(*output(), &jsonError);
|
||||
if (jsonError.error != QJsonParseError::NoError) {
|
||||
qDebug() << "pastegg server did not reply with JSON" << jsonError.errorString();
|
||||
m_fail_reason =
|
||||
|
|
@ -214,6 +214,5 @@ PasteUpload::PasteUpload(const QString& log, QString url, PasteType pasteType) :
|
|||
else
|
||||
m_url = m_baseUrl + base.endpointPath;
|
||||
|
||||
m_response = new QByteArray();
|
||||
m_sink.reset(new Sink(this, std::unique_ptr<QByteArray>{ m_response }));
|
||||
m_sink.reset(new Sink(this));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ class PasteUpload : public Net::NetRequest {
|
|||
|
||||
class Sink : public Net::ByteArraySink {
|
||||
public:
|
||||
Sink(PasteUpload* p, std::unique_ptr<QByteArray> output) : Net::ByteArraySink(std::move(output)), m_d(p) {};
|
||||
Sink(PasteUpload* p) : m_d(p) {};
|
||||
virtual ~Sink() = default;
|
||||
|
||||
public:
|
||||
|
|
@ -94,5 +94,4 @@ class PasteUpload : public Net::NetRequest {
|
|||
QString m_pasteLink;
|
||||
QString m_baseUrl;
|
||||
const PasteType m_paste_type;
|
||||
QByteArray* m_response;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -56,8 +56,9 @@ std::pair<Upload::Ptr, QByteArray*> Upload::makeByteArray(QUrl url, QByteArray m
|
|||
auto up = makeShared<Upload>();
|
||||
up->m_url = std::move(url);
|
||||
|
||||
auto response = new QByteArray();
|
||||
up->m_sink = std::make_unique<ByteArraySink>(std::unique_ptr<QByteArray>{ response });
|
||||
auto sink = std::make_unique<ByteArraySink>();
|
||||
QByteArray* response = sink->output();
|
||||
up->m_sink = std::move(sink);
|
||||
|
||||
up->m_post_data = std::move(m_post_data);
|
||||
return { up, response };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue