InstallShieldCabinet model cleanup

This commit is contained in:
Matt Nadareski
2025-10-30 21:51:15 -04:00
parent d75a512ead
commit ec7172466b
12 changed files with 60 additions and 98 deletions

View File

@@ -11,17 +11,17 @@ namespace SabreTools.Data.Models.InstallShieldCabinet
/// <summary>
/// Common header
/// </summary>
public CommonHeader? CommonHeader { get; set; }
public CommonHeader CommonHeader { get; set; }
/// <summary>
/// Volume header
/// </summary>
public VolumeHeader? VolumeHeader { get; set; }
public VolumeHeader VolumeHeader { get; set; }
/// <summary>
/// Descriptor
/// </summary>
public Descriptor? Descriptor { get; set; }
public Descriptor Descriptor { get; set; }
#endregion
@@ -30,17 +30,17 @@ namespace SabreTools.Data.Models.InstallShieldCabinet
/// <summary>
/// Offsets to all file descriptors
/// </summary>
public uint[]? FileDescriptorOffsets { get; set; }
public uint[] FileDescriptorOffsets { get; set; }
/// <summary>
/// Directory names
/// </summary>
public string[]? DirectoryNames { get; set; }
public string[] DirectoryNames { get; set; }
/// <summary>
/// Standard file descriptors
/// </summary>
public FileDescriptor[]? FileDescriptors { get; set; }
public FileDescriptor[] FileDescriptors { get; set; }
#endregion
@@ -49,12 +49,12 @@ namespace SabreTools.Data.Models.InstallShieldCabinet
/// <summary>
/// File group offset to offset list mapping
/// </summary>
public Dictionary<long, OffsetList?>? FileGroupOffsets { get; set; }
public Dictionary<long, OffsetList?> FileGroupOffsets { get; set; }
/// <summary>
/// File groups
/// </summary>
public FileGroup[]? FileGroups { get; set; }
public FileGroup[] FileGroups { get; set; }
#endregion
@@ -63,13 +63,13 @@ namespace SabreTools.Data.Models.InstallShieldCabinet
/// <summary>
/// Component offset to offset list mapping
/// </summary>
public Dictionary<long, OffsetList?>? ComponentOffsets { get; set; }
public Dictionary<long, OffsetList?> ComponentOffsets { get; set; }
/// <summary>
/// Components
/// </summary>
public Component[]? Components { get; set; }
public Component[] Components { get; set; }
#endregion
}
}
}

View File

@@ -10,7 +10,7 @@ namespace SabreTools.Data.Models.InstallShieldCabinet
/// "ISc("
/// </summary>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]
public string? Signature;
public string Signature;
/// <summary>
/// Encoded version
@@ -32,4 +32,4 @@ namespace SabreTools.Data.Models.InstallShieldCabinet
/// </summary>
public uint DescriptorSize;
}
}
}

View File

@@ -13,7 +13,7 @@ namespace SabreTools.Data.Models.InstallShieldCabinet
/// <summary>
/// Component identifier
/// </summary>
public string? Identifier { get; set; }
public string Identifier { get; set; }
/// <summary>
/// Offset to the component descriptor
@@ -28,7 +28,7 @@ namespace SabreTools.Data.Models.InstallShieldCabinet
/// <summary>
/// Display name
/// </summary>
public string? DisplayName { get; set; }
public string DisplayName { get; set; }
/// <summary>
/// Component status
@@ -58,7 +58,7 @@ namespace SabreTools.Data.Models.InstallShieldCabinet
/// <summary>
/// Component name
/// </summary>
public string? Name { get; set; }
public string Name { get; set; }
/// <summary>
/// Offset to the CD-ROM folder
@@ -78,7 +78,7 @@ namespace SabreTools.Data.Models.InstallShieldCabinet
/// <summary>
/// Unknown GUIDs
/// </summary>
public Guid[]? Guid { get; set; } = new Guid[2];
public Guid[] Guid { get; set; } = new Guid[2];
/// <summary>
/// Offset to the component CLSID
@@ -125,7 +125,7 @@ namespace SabreTools.Data.Models.InstallShieldCabinet
/// <summary>
/// File group names
/// </summary>
public string[]? FileGroupNames { get; set; }
public string[] FileGroupNames { get; set; }
/// <summary>
/// Number of X3(?)

View File

@@ -24,4 +24,4 @@ namespace SabreTools.Data.Models.InstallShieldCabinet
// TODO: Determine how the value "71" was chosen here
public const int MAX_COMPONENT_COUNT = 71;
}
}
}

View File

@@ -95,13 +95,13 @@ namespace SabreTools.Data.Models.InstallShieldCabinet
/// Offsets to the file groups
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 71)]
public uint[]? FileGroupOffsets;
public uint[] FileGroupOffsets;
/// <summary>
/// Offsets to the components
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 71)]
public uint[]? ComponentOffsets;
public uint[] ComponentOffsets;
/// <summary>
/// Offset to the setup types
@@ -123,4 +123,4 @@ namespace SabreTools.Data.Models.InstallShieldCabinet
/// </summary>
public uint Reserved8;
}
}
}

View File

@@ -100,4 +100,4 @@ namespace SabreTools.Data.Models.InstallShieldCabinet
LINK_NEXT = 2,
LINK_BOTH = 3,
}
}
}

View File

@@ -11,7 +11,7 @@ namespace SabreTools.Data.Models.InstallShieldCabinet
/// <summary>
/// File descriptor name
/// </summary>
public string? Name { get; set; }
public string Name { get; set; }
/// <summary>
/// Directory index

View File

@@ -12,7 +12,7 @@ namespace SabreTools.Data.Models.InstallShieldCabinet
/// <summary>
/// File group name
/// </summary>
public string? Name { get; set; }
public string Name { get; set; }
/// <summary>
/// Size of the expanded data
@@ -82,6 +82,6 @@ namespace SabreTools.Data.Models.InstallShieldCabinet
/// <summary>
/// Reserved
/// </summary>
public uint[]? Reserved { get; set; } = new uint[4];
public uint[] Reserved { get; set; } = new uint[4];
}
}
}

View File

@@ -5,10 +5,10 @@ namespace SabreTools.Data.Models.InstallShieldCabinet
{
public uint NameOffset { get; set; }
public string? Name { get; set; }
public string Name { get; set; }
public uint DescriptorOffset { get; set; }
public uint NextOffset { get; set; }
}
}
}

View File

@@ -33,7 +33,7 @@ namespace SabreTools.Data.Models.InstallShieldCabinet
public uint LastFileSizeExpandedHigh { get; set; }
public uint LastFileSizeCompressed { get; set; }
public uint LastFileSizeCompressedHigh { get; set; }
}
}
}

View File

@@ -38,17 +38,10 @@ namespace SabreTools.Serialization.Wrappers
Print(builder, Model.Components);
}
private static void Print(StringBuilder builder, CommonHeader? header, int majorVersion)
private static void Print(StringBuilder builder, CommonHeader header, int majorVersion)
{
builder.AppendLine(" Common Header Information:");
builder.AppendLine(" -------------------------");
if (header == null)
{
builder.AppendLine(value: " No common header");
builder.AppendLine();
return;
}
builder.AppendLine(header.Signature, " Signature");
builder.AppendLine($" Version: {header.Version} (0x{header.Version:X}) [{majorVersion}]");
builder.AppendLine(header.VolumeInfo, " Volume info");
@@ -57,17 +50,10 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine();
}
private static void Print(StringBuilder builder, VolumeHeader? header, int majorVersion)
private static void Print(StringBuilder builder, VolumeHeader header, int majorVersion)
{
builder.AppendLine(" Volume Header Information:");
builder.AppendLine(" -------------------------");
if (header == null)
{
builder.AppendLine(value: " No volume header");
builder.AppendLine();
return;
}
if (majorVersion <= 5)
{
builder.AppendLine(header.DataOffset, " Data offset");
@@ -102,17 +88,10 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine();
}
private static void Print(StringBuilder builder, Descriptor? descriptor)
private static void Print(StringBuilder builder, Descriptor descriptor)
{
builder.AppendLine(" Descriptor Information:");
builder.AppendLine(" -------------------------");
if (descriptor == null)
{
builder.AppendLine(" No descriptor");
builder.AppendLine();
return;
}
builder.AppendLine(descriptor.StringsOffset, " Strings offset");
builder.AppendLine(descriptor.Reserved0, " Reserved 0");
builder.AppendLine(descriptor.ComponentListOffset, " Component list offset");
@@ -134,7 +113,7 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine(" File group offsets:");
builder.AppendLine(" -------------------------");
if (descriptor.FileGroupOffsets == null || descriptor.FileGroupOffsets.Length == 0)
if (descriptor.FileGroupOffsets.Length == 0)
{
builder.AppendLine(" No file group offsets");
}
@@ -150,7 +129,7 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine(" Component offsets:");
builder.AppendLine(" -------------------------");
if (descriptor.ComponentOffsets == null || descriptor.ComponentOffsets.Length == 0)
if (descriptor.ComponentOffsets.Length == 0)
{
builder.AppendLine(" No component offsets");
}
@@ -171,11 +150,11 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine();
}
private static void Print(StringBuilder builder, uint[]? entries)
private static void Print(StringBuilder builder, uint[] entries)
{
builder.AppendLine(" File Descriptor Offsets:");
builder.AppendLine(" -------------------------");
if (entries == null || entries.Length == 0)
if (entries.Length == 0)
{
builder.AppendLine(" No file descriptor offsets");
builder.AppendLine();
@@ -190,11 +169,11 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine();
}
private static void Print(StringBuilder builder, string[]? entries)
private static void Print(StringBuilder builder, string[] entries)
{
builder.AppendLine(" Directory Names:");
builder.AppendLine(" -------------------------");
if (entries == null || entries.Length == 0)
if (entries.Length == 0)
{
builder.AppendLine(" No directory names");
builder.AppendLine();
@@ -209,11 +188,11 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine();
}
private static void Print(StringBuilder builder, FileDescriptor[]? entries)
private static void Print(StringBuilder builder, FileDescriptor[] entries)
{
builder.AppendLine(" File Descriptors:");
builder.AppendLine(" -------------------------");
if (entries == null || entries.Length == 0)
if (entries.Length == 0)
{
builder.AppendLine(" No file descriptors");
builder.AppendLine();
@@ -242,11 +221,11 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine();
}
private static void Print(StringBuilder builder, Dictionary<long, OffsetList?>? entries, string name)
private static void Print(StringBuilder builder, Dictionary<long, OffsetList?> entries, string name)
{
builder.AppendLine($" {name} Offsets:");
builder.AppendLine(" -------------------------");
if (entries == null || entries.Count == 0)
if (entries.Count == 0)
{
builder.AppendLine($" No {name.ToLowerInvariant()} offsets");
builder.AppendLine();
@@ -274,11 +253,11 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine();
}
private static void Print(StringBuilder builder, FileGroup[]? entries)
private static void Print(StringBuilder builder, FileGroup[] entries)
{
builder.AppendLine(" File Groups:");
builder.AppendLine(" -------------------------");
if (entries == null || entries.Length == 0)
if (entries.Length == 0)
{
builder.AppendLine(" No file groups");
builder.AppendLine();
@@ -311,11 +290,11 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine();
}
private static void Print(StringBuilder builder, Component[]? entries)
private static void Print(StringBuilder builder, Component[] entries)
{
builder.AppendLine(" Components:");
builder.AppendLine(" -------------------------");
if (entries == null || entries.Length == 0)
if (entries.Length == 0)
{
builder.AppendLine(" No components");
builder.AppendLine();
@@ -354,7 +333,7 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine(" File group names:");
builder.AppendLine(" -------------------------");
if (entry.FileGroupNames == null || entry.FileGroupNames.Length == 0)
if (entry.FileGroupNames.Length == 0)
{
builder.AppendLine(" No file group names");
}

View File

@@ -17,39 +17,39 @@ namespace SabreTools.Serialization.Wrappers
#region Extension Properties
/// <inheritdoc cref="Cabinet.CommonHeader"/>
public CommonHeader? CommonHeader => Model.CommonHeader;
public CommonHeader CommonHeader => Model.CommonHeader;
/// <inheritdoc cref="Cabinet.Components"/>
public Component[]? Components => Model.Components;
public Component[] Components => Model.Components;
/// <summary>
/// Number of components in the cabinet set
/// </summary>
public int ComponentCount => Components?.Length ?? 0;
public int ComponentCount => Components.Length;
/// <summary>
/// Number of directories in the cabinet set
/// </summary>
public ushort DirectoryCount => Model.Descriptor?.DirectoryCount ?? 0;
public ushort DirectoryCount => Model.Descriptor.DirectoryCount;
/// <inheritdoc cref="Cabinet.DirectoryNames"/>
public string[]? DirectoryNames => Model.DirectoryNames;
public string[] DirectoryNames => Model.DirectoryNames;
/// <summary>
/// Number of files in the cabinet set
/// </summary>
public uint FileCount => Model.Descriptor?.FileCount ?? 0;
public uint FileCount => Model.Descriptor.FileCount;
/// <inheritdoc cref="Cabinet.FileDescriptors"/>
public FileDescriptor[]? FileDescriptors => Model.FileDescriptors;
public FileDescriptor[] FileDescriptors => Model.FileDescriptors;
/// <inheritdoc cref="Cabinet.FileGroups"/>
public FileGroup[]? FileGroups => Model.FileGroups;
public FileGroup[] FileGroups => Model.FileGroups;
/// <summary>
/// Number of file groups in the cabinet set
/// </summary>
public int FileGroupCount => Model.FileGroups?.Length ?? 0;
public int FileGroupCount => Model.FileGroups.Length;
/// <summary>
/// Indicates if Unicode strings are used
@@ -62,7 +62,7 @@ namespace SabreTools.Serialization.Wrappers
public int MajorVersion => Model.GetMajorVersion();
/// <inheritdoc cref="Cabinet.VolumeHeader"/>
public VolumeHeader? VolumeHeader => Model.VolumeHeader;
public VolumeHeader VolumeHeader => Model.VolumeHeader;
#endregion
@@ -170,9 +170,6 @@ namespace SabreTools.Serialization.Wrappers
/// </summary>
public string? GetDirectoryName(int index)
{
if (DirectoryNames == null)
return null;
if (index < 0 || index >= DirectoryNames.Length)
return null;
@@ -237,9 +234,6 @@ namespace SabreTools.Serialization.Wrappers
/// </summary>
public FileDescriptor? GetFileDescriptor(int index)
{
if (FileDescriptors == null)
return null;
if (index < 0 || index >= FileDescriptors.Length)
return null;
@@ -313,9 +307,6 @@ namespace SabreTools.Serialization.Wrappers
/// </summary>
public FileGroup? GetFileGroup(int index)
{
if (FileGroups == null)
return null;
if (index < 0 || index >= FileGroups.Length)
return null;
@@ -326,21 +317,13 @@ namespace SabreTools.Serialization.Wrappers
/// Get the file group at a given name, if possible
/// </summary>
public FileGroup? GetFileGroup(string name)
{
if (FileGroups == null)
return null;
return Array.Find(FileGroups, fg => fg != null && string.Equals(fg.Name, name));
}
=> Array.Find(FileGroups, fg => string.Equals(fg.Name, name));
/// <summary>
/// Get the file group for the given file index, if possible
/// </summary>
public FileGroup? GetFileGroupFromFile(int index)
{
if (FileGroups == null)
return null;
if (index < 0 || index >= FileCount)
return null;