mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-04-21 21:59:47 +00:00
Add IS-CAB OpenVolume helper
This commit is contained in:
@@ -233,6 +233,39 @@ namespace SabreTools.Serialization.Wrappers
|
||||
return set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open the numbered cabinet set volume
|
||||
/// </summary>
|
||||
/// <param name="pattern">Filename pattern for matching cabinet files</param>
|
||||
/// <param name="volumeId">Volume ID, 1-indexed</param>
|
||||
/// <returns>Wrapper representing the volume on success, null otherwise</returns>
|
||||
public static InstallShieldCabinet? OpenVolume(string? pattern, ushort volumeId)
|
||||
{
|
||||
// Normalize the volume ID for odd cases
|
||||
if (volumeId == ushort.MinValue || volumeId == ushort.MaxValue)
|
||||
volumeId = 1;
|
||||
|
||||
// Try to open the file as a stream
|
||||
var volumeStream = OpenFileForReading(pattern, volumeId, CABINET_SUFFIX);
|
||||
if (volumeStream == null)
|
||||
{
|
||||
Console.Error.WriteLine($"Failed to open input cabinet file {volumeId}");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Try to parse the stream into a cabinet
|
||||
var volume = Create(volumeStream);
|
||||
if (volume == null)
|
||||
{
|
||||
Console.Error.WriteLine($"Failed to open input cabinet file {volumeId}");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set the volume ID and return
|
||||
volume.VolumeID = volumeId;
|
||||
return volume;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open a cabinet file for reading
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user