Skip to content

Commit

Permalink
Update CDBuilder.cs
Browse files Browse the repository at this point in the history
Adding Progress
  • Loading branch information
modz2014 authored May 8, 2024
1 parent b2900c2 commit de30a4f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 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,7 @@ public BuildFileInfo AddFile(string name, byte[] content)
var fi = new BuildFileInfo(nameElements[nameElements.Length - 1].ToString(), dir, content);
AddFile(fi);
dir.Add(fi);
UpdateProgress(_files.Count, _files.Count + _dirs.Count);
return fi;
}

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

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

Expand Down Expand Up @@ -635,4 +649,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);
}
}

0 comments on commit de30a4f

Please sign in to comment.