DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
FileDownloader.h
Go to the documentation of this file.
1
3
4#pragma once
5#include "Common.h"
6#include "System/Object.h"
7#include "System/String.h"
8#include "System/EventArgs.h"
10#include "System/SmartPointer.h"
11#include "System/IO/Stream.h"
15
16namespace DotNetDupe {
17 namespace System {
18 namespace IO {
19 class FileStream;
20 }
21 namespace Net {
22 namespace Http {
23
38
53
57 public:
64 DownloadProgressChangedEventArgs(long long llBytesReceived, long long llTotalBytesToReceive,
65 double dProgressPercentage, double dDownloadRateBytesPerSec,
66 DownloadStatus status)
67 : m_llBytesReceived(llBytesReceived),
68 m_llTotalBytesToReceive(llTotalBytesToReceive),
69 m_dProgressPercentage(dProgressPercentage),
70 m_dDownloadRateBytesPerSec(dDownloadRateBytesPerSec),
71 m_status(status) {}
72
74 long long GetBytesReceived() const { return m_llBytesReceived; }
76 long long GetTotalBytesToReceive() const { return m_llTotalBytesToReceive; }
78 double GetProgressPercentage() const { return m_dProgressPercentage; }
80 double GetDownloadRateBytesPerSec() const { return m_dDownloadRateBytesPerSec; }
82 DownloadStatus GetStatus() const { return m_status; }
83
84 private:
85 long long m_llBytesReceived;
86 long long m_llTotalBytesToReceive;
87 double m_dProgressPercentage;
88 double m_dDownloadRateBytesPerSec;
89 DownloadStatus m_status;
90 };
91
95 public:
100 DownloadCompletedEventArgs(bool bSuccess, bool bCancelled, const String& sError)
101 : m_bSuccess(bSuccess),
102 m_bCancelled(bCancelled),
103 m_sError(sError) {}
104
106 bool IsSuccess() const { return m_bSuccess; }
108 bool IsCancelled() const { return m_bCancelled; }
110 String GetError() const { return m_sError; }
111
112 private:
113 bool m_bSuccess;
114 bool m_bCancelled;
115 String m_sError;
116 };
117
122 class FileDownloader : public Object {
123 private:
124 struct Impl;
125 SmartPointer<Impl> m_pImpl;
126
127 public:
132
136 DOTNETDUPE_API FileDownloader(const String& sUrl, const String& sDestinationPath);
139
142 DOTNETDUPE_API bool Start();
143
145 DOTNETDUPE_API void Pause();
146
149 DOTNETDUPE_API bool Resume();
150
154
158
162
165 DOTNETDUPE_API void SetUserAgent(const String& sUserAgent);
166 };
167
168 }
169 }
170 }
171}
Defines common cross-platform macros, export decorators, and fundamental types.
#define DOTNETDUPE_API
Platform-specific linkage decoration for exporting or importing library symbols.
Definition Common.h:20
Represents the base class for classes that contain event data.
Represents the method that will handle an event when the event provides data.
Provides a base class for sending HTTP requests and receiving HTTP responses mirroring ....
Represents an HTTP request message adhering to RFC 9110 and RFC 9112.
Represents an HTTP response message adhering to RFC 9110 and RFC 9112.
Base object class for DotNetDupe mirroring .NET System.Object.
Provides reference-counted and weak pointer memory management primitives ensuring zero raw ownership.
High-performance UTF-8 / UTF-16 string manipulation class mirroring .NET System.String.
Represents a collection of keys and values.
Definition Dictionary.h:66
EventArgs()
Initializes a new instance of the EventArgs class.
Definition EventArgs.cpp:7
Represents the method that will handle an event when the event provides data.
Provides a Stream for a file, supporting both synchronous read and write operations.
Definition FileStream.h:16
bool IsCancelled() const
Indicates whether the download was intentionally cancelled.
bool IsSuccess() const
Indicates whether the file was successfully downloaded.
String GetError() const
Gets error information if an exception occurred during transfer.
DownloadCompletedEventArgs(bool bSuccess, bool bCancelled, const String &sError)
Initializes completion event arguments.
double GetProgressPercentage() const
Gets progress percentage between 0.0 and 100.0.
long long GetTotalBytesToReceive() const
Gets the total size in bytes expected to receive.
double GetDownloadRateBytesPerSec() const
Gets the current download rate in bytes per second.
DownloadProgressChangedEventArgs(long long llBytesReceived, long long llTotalBytesToReceive, double dProgressPercentage, double dDownloadRateBytesPerSec, DownloadStatus status)
Initializes a new instance with current metrics snapshot.
long long GetBytesReceived() const
Gets the total bytes received so far.
DownloadStatus GetStatus() const
Gets the current download status.
bool Resume()
Resumes a paused download using HTTP Range headers if supported.
void SetUserAgent(const String &sUserAgent)
Overrides the default User-Agent request header string.
FileDownloader(const String &sUrl, const String &sDestinationPath)
Initializes a new instance of FileDownloader with source URL and destination path.
DownloadProgress GetProgress() const
Queries instantaneous download telemetry metrics.
void Pause()
Suspends byte streaming without deleting partially received data.
EventHandler< DownloadCompletedEventArgs > & DownloadCompleted
Multicast event triggered when transfer completes or terminates.
DownloadStatus GetStatus() const
Queries current operational status.
EventHandler< DownloadProgressChangedEventArgs > & DownloadProgressChanged
Multicast event triggered when chunk progress occurs.
void AddHeaders(const Collections::Generic::Dictionary< String, String > &headers)
Appends custom HTTP request headers to outgoing requests.
bool Start()
Begins the asynchronous download on a background worker thread.
Supports all classes in the DotNetDupe class hierarchy.
Definition Object.h:18
A unified smart pointer that supports both unique and shared ownership semantics.
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
Definition String.h:74
DownloadStatus
State machine values representing the lifecycle of an ongoing file download.
@ Completed
Transfer finished successfully and file was verified.
@ Downloading
Transfer is actively receiving bytes over the network.
@ Failed
Transfer encountered an unrecoverable network or disk I/O failure.
@ Paused
Transfer is temporarily suspended.
@ NotStarted
Transfer has not been initiated.
Snapshot of download telemetry metrics including transferred bytes and bandwidth speed.
long long DownloadedBytes
Number of bytes written to local destination file.
double DownloadRateBytesPerSec
Instantaneous transfer speed in bytes per second.
DownloadStatus Status
Current lifecycle state of the download task.
long long TotalBytes
Total expected length in bytes from HTTP Content-Length header, or 0 if chunked.
long long RemainingBytes
Estimated remaining bytes.