mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-09-23 07:14:57 +00:00
Be smarter about volume opening
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.InstallShieldCabinet;
|
||||
using static SabreTools.Models.InstallShieldCabinet.Constants;
|
||||
|
||||
namespace UnshieldSharpInternal
|
||||
{
|
||||
@@ -168,25 +166,18 @@ namespace UnshieldSharpInternal
|
||||
/// </summary>
|
||||
private bool OpenVolume(ushort volume)
|
||||
{
|
||||
// Normalize the volume ID for odd cases
|
||||
if (volume == ushort.MinValue || volume == ushort.MaxValue)
|
||||
volume = 1;
|
||||
|
||||
_volumeFile?.Close();
|
||||
_volumeFile = _extractor.HeaderList.OpenFileForReading(volume, CABINET_SUFFIX);
|
||||
if (_volumeFile == null)
|
||||
// Read the volume from the cabinet set
|
||||
var next = _extractor.HeaderList.OpenVolume(volume, out var volumeStream);
|
||||
if (next?.VolumeHeader == null || volumeStream == null)
|
||||
{
|
||||
Console.Error.WriteLine($"Failed to open input cabinet file {volume}");
|
||||
return false;
|
||||
}
|
||||
|
||||
var commonHeader = _volumeFile.ReadType<CommonHeader>();
|
||||
if (commonHeader == default)
|
||||
return false;
|
||||
|
||||
_volumeHeader = SabreTools.Serialization.Deserializers.InstallShieldCabinet.ParseVolumeHeader(_volumeFile, _extractor.HeaderList.MajorVersion);
|
||||
if (_volumeHeader == null)
|
||||
return false;
|
||||
// Assign the next items
|
||||
_volumeFile?.Close();
|
||||
_volumeFile = volumeStream;
|
||||
_volumeHeader = next.VolumeHeader;
|
||||
|
||||
// Enable support for split archives for IS5
|
||||
if (_extractor.HeaderList.MajorVersion == 5)
|
||||
|
||||
@@ -237,23 +237,14 @@ namespace SabreTools.Serialization.Wrappers
|
||||
/// </summary>
|
||||
/// <param name="volumeId">Volume ID, 1-indexed</param>
|
||||
/// <returns>Wrapper representing the volume on success, null otherwise</returns>
|
||||
public InstallShieldCabinet? OpenVolume(ushort volumeId)
|
||||
=> OpenVolume(FilenamePattern, volumeId);
|
||||
|
||||
/// <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)
|
||||
public InstallShieldCabinet? OpenVolume(ushort volumeId, out Stream? volumeStream)
|
||||
{
|
||||
// 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);
|
||||
volumeStream = OpenFileForReading(FilenamePattern, volumeId, CABINET_SUFFIX);
|
||||
if (volumeStream == null)
|
||||
{
|
||||
Console.Error.WriteLine($"Failed to open input cabinet file {volumeId}");
|
||||
|
||||
Reference in New Issue
Block a user