From 20b9f2b42a3b58b6081af271774fbcc34025dccb Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 25 Jul 2021 19:11:59 +0200 Subject: NOISSUE Flatten gui and logic libraries into MultiMC --- launcher/net/ByteArraySink.h | 62 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 launcher/net/ByteArraySink.h (limited to 'launcher/net/ByteArraySink.h') diff --git a/launcher/net/ByteArraySink.h b/launcher/net/ByteArraySink.h new file mode 100644 index 00000000..20e6764c --- /dev/null +++ b/launcher/net/ByteArraySink.h @@ -0,0 +1,62 @@ +#pragma once + +#include "Sink.h" + +namespace Net { +/* + * Sink object for downloads that uses an external QByteArray it doesn't own as a target. + */ +class ByteArraySink : public Sink +{ +public: + ByteArraySink(QByteArray *output) + :m_output(output) + { + // nil + }; + + virtual ~ByteArraySink() + { + // nil + } + +public: + JobStatus init(QNetworkRequest & request) override + { + m_output->clear(); + if(initAllValidators(request)) + return Job_InProgress; + return Job_Failed; + }; + + JobStatus write(QByteArray & data) override + { + m_output->append(data); + if(writeAllValidators(data)) + return Job_InProgress; + return Job_Failed; + } + + JobStatus abort() override + { + m_output->clear(); + failAllValidators(); + return Job_Failed; + } + + JobStatus finalize(QNetworkReply &reply) override + { + if(finalizeAllValidators(reply)) + return Job_Finished; + return Job_Failed; + } + + bool hasLocalData() override + { + return false; + } + +private: + QByteArray * m_output; +}; +} -- cgit