Event Handling

Show launching progress to user

When you want to show progress to users, add event handlers. CmlLib.Core uses only two event handlers. DownloadFileChangedHandler is used when the file being downloaded changes. (ex: file counts) ProgressChangedEventHandler is used when the progress of the file currently being downloaded changes. (ex: byte progress)

Example

// add event handlers
var launcher = new CMLauncher(new MinecraftPath());
launcher.FileChanged += Launcher_FileChanged;
launcher.ProgressChanged += Launcher_ProgressChanged;
// event handler
private void Launcher_FileChanged(DownloadFileChangedEventArgs e)
{
    Console.WriteLine("FileKind: " + e.FileKind.ToString());
    Console.WriteLine("FileName: " + e.FileName);
    Console.WriteLine("TotalFileCount: " + e.TotalFileCount);
    Console.WriteLine("ProgressedFiles: " + e.ProgressedFileCount);
}

private void Launcher_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
{
    Console.WriteLine("{0}%", e.ProgressPercentage);
}

DownloadFileChangedEventHandler

public delegate void DownloadFileChangedHandler(DownloadFileChangedEventArgs e);

Represents the method that will handle download progress events.

DownloadFileChangedEventArgs contains the download progress.

DownloadFileChangedEventArgs

Represents the download progress data of IDownloader.

Source Code

Properties

FileKind

Type: MFile

Specifies the type of file currently being downloaded.

FileName

Type: string

The name of the file currently being downloaded. Note: if FileKind is equal to MFile.Resource, this property would be an empty string.

Source

Type: object

The source of event. You can determine what object raised the event. Example:

if (e.Source is IFileChecker)
{
    // raised by IFileChecker
    // game file checking
}
else if (e.Source is IDownloader)
{
    // raised by IDownloader
    // file downloading
}
else
{
    // etc (MForge, or )
}

TotalFileCount;

Type: int

The total number of files to download.

ProgressedFileCount;

Type: int

The number of files already downloaded.

ProgressChangedEventHandler

docs.microsoft.com

MFile

Indicates the game file type.

public enum MFile { Runtime, Library, Resource, Minecraft };

Fields

Runtime

Java runtime. CMLauncher.CheckJRE() raises FileChange event with this type.

Library

Libraries (GAME_DIR/libraries)

Resource

Resources and assets (GAME_DIR/assets)

Minecraft

Minecraft jar file (GAME_DIR/versions)

Last updated