Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding progress tracking for files and directories #10

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion Library/DiscUtils.Iso9660/CDBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ public sealed class CDBuilder : StreamBuilder, IFileSystemBuilder
private readonly List<BuildFileInfo> _files;
private readonly BuildDirectoryInfo _rootDirectory;

// Define a delegate for progress reporting
public delegate void ProgressHandler(int currentProgress, int totalItems);
public event ProgressHandler ProgressChanged;

// Method for updating progress
private void UpdateProgress(int currentProgress, int totalItems)
{
ProgressChanged?.Invoke(currentProgress, totalItems);
}


/// <summary>
/// Initializes a new instance of the CDBuilder class.
/// </summary>
Expand Down Expand Up @@ -203,6 +214,9 @@ public BuildFileInfo AddFile(string name, byte[] content)
var fi = new BuildFileInfo(nameElements[nameElements.Length - 1].ToString(), dir, content);
AddFile(fi);
dir.Add(fi);
int currentFilesCount = _files.Count;
int currentItemsCount = currentFilesCount + _dirs.Count;
UpdateProgress(currentFilesCount, currentItemsCount);
return fi;
}

Expand All @@ -227,6 +241,9 @@ public BuildFileInfo AddFile(string name, string sourcePath)
var fi = new BuildFileInfo(nameElements[nameElements.Length - 1].ToString(), dir, sourcePath);
AddFile(fi);
dir.Add(fi);
int currentFilesCount = _files.Count;
int currentItemsCount = currentFilesCount + _dirs.Count;
UpdateProgress(currentFilesCount, currentItemsCount);
return fi;
}

Expand Down Expand Up @@ -256,6 +273,9 @@ public BuildFileInfo AddFile(string name, Stream source)
var fi = new BuildFileInfo(nameElements[nameElements.Length - 1].ToString(), dir, source);
AddFile(fi);
dir.Add(fi);
int currentFilesCount = _files.Count;
int currentItemsCount = currentFilesCount + _dirs.Count;
UpdateProgress(currentFilesCount, currentItemsCount);
return fi;
}

Expand Down Expand Up @@ -635,4 +655,4 @@ void IFileSystemBuilder.AddFile(string name, string sourcePath, DateTime creatio
bool IFileSystemBuilder.Exists(string path) => GetFile(path) != null;

public IFileSystem GenerateFileSystem() => new CDReader(Build(), UseJoliet);
}
}
Loading