Table of Contents

Class DownloadManager

Namespace
CapCognition.Maui.Core.Shared
Assembly
CapCognition.Maui.Core.dll

Use this class to download files from the internet and store them in a local cache directory.

public class DownloadManager
Inheritance
DownloadManager
Inherited Members

Constructors

DownloadManager(string)

Creates a new instance of the DownloadManager.

public DownloadManager(string cacheDirectoryName)

Parameters

cacheDirectoryName string

The subdirectory name to use to store the downloaded files

Fields

CacheDirectoryName

Returns the name of the cache subdirectory.

public readonly string CacheDirectoryName

Field Value

string

Properties

Files

Returns all files that are managed by the DownloadManager.

public DownloadManagerFile[] Files { get; }

Property Value

DownloadManagerFile[]

MaximumFileSizeInBytes

Optional maximum size for a single downloaded or copied file. Null disables the size limit.

public long? MaximumFileSizeInBytes { get; set; }

Property Value

long?

Methods

AddFile(DownloadManagerFile)

Adds a file to the download manager.

public void AddFile(DownloadManagerFile file)

Parameters

file DownloadManagerFile

AddFile(Stream, string, Func<string>?)

Adds a file from a stream

public void AddFile(Stream stream, string filename, Func<string>? decryptionPWFunc = null)

Parameters

stream Stream

the file to save locally

filename string
decryptionPWFunc Func<string>

A function to return the password to decrypt the downloaded file, If null no decryption is used

AddFile(Stream, string, Func<string>?, string?)

Adds and validates a file from a stream.

public void AddFile(Stream stream, string filename, Func<string>? decryptionPWFunc, string? hash)

Parameters

stream Stream

The file to save locally.

filename string

The local file name.

decryptionPWFunc Func<string>

A function returning the decryption password, or null for an unencrypted stream.

hash string

SHA-256 hash of the source stream.

AddFile(string, string?, Func<string>?)

Adds a file to the download manager.

public void AddFile(string uri, string? hash = null, Func<string>? decryptionPWFunc = null)

Parameters

uri string

Url of the file to download

hash string

SHA-256 hash of the downloaded source file (the encrypted file when decryption is enabled). If null, no hash validation is used.

decryptionPWFunc Func<string>

A function to return the password to decrypt the downloaded file, If null no decryption is used

AllFilesDownloaded()

Checks if all files are downloaded and valid.

public bool AllFilesDownloaded()

Returns

bool

ClearAll(bool)

Clears all files from the download manager.

public void ClearAll(bool deleteFromFileSystem = false)

Parameters

deleteFromFileSystem bool

If true, the file is deleted as well from the cache

DeleteAllFilesExcept(string, List<string>)

Delete all files in the cache directory that match the deletePattern.

public void DeleteAllFilesExcept(string deletePattern, List<string> exceptFiles)

Parameters

deletePattern string

Delete pattern

exceptFiles List<string>

Except filenames

DownloadAllFiles()

Downloads all files.

public bool DownloadAllFiles()

Returns

bool

DownloadAllFilesAsync(CancellationToken)

Downloads all files asynchronously.

public Task<bool> DownloadAllFilesAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task<bool>

RemoveFile(DownloadManagerFile, bool)

Removes a file from the download manager.

public void RemoveFile(DownloadManagerFile file, bool deleteFromFileSystem = false)

Parameters

file DownloadManagerFile

The file to be removed

deleteFromFileSystem bool

If true, the file is deleted as well from the cache

Events

DownloadProgressEvt

Raised during the download of a file to report the progress.

public event DownloadManager.ProgressDelegate? DownloadProgressEvt

Event Type

DownloadManager.ProgressDelegate