MicrosoftCabinet model cleanup

This commit is contained in:
Matt Nadareski
2025-10-30 22:07:29 -04:00
parent 97702ab3d5
commit b7c3c094ae
9 changed files with 25 additions and 34 deletions

View File

@@ -60,6 +60,6 @@
/// CFFILE.szName field, but the _A_NAME_IS_UTF attribute is not set, the characters SHOULD be
/// interpreted according to the current location.
/// </summary>
public string? Name { get; set; }
public string Name { get; set; }
}
}

View File

@@ -51,6 +51,6 @@
/// <summary>
/// Data blocks associated with this folder
/// </summary>
public CFDATA[]? DataBlocks { get; set; }
public CFDATA[] DataBlocks { get; set; }
}
}

View File

@@ -11,7 +11,7 @@
/// Contains the characters "M", "S", "C", and "F" (bytes 0x4D, 0x53, 0x43,
/// 0x46). This field is used to ensure that the file is a cabinet (.cab) file.
/// </summary>
public string? Signature { get; set; }
public string Signature { get; set; }
/// <summary>
/// Reserved field; MUST be set to 0 (zero).

View File

@@ -12,16 +12,16 @@
/// <summary>
/// Cabinet header
/// </summary>
public CFHEADER? Header { get; set; }
public CFHEADER Header { get; set; }
/// <summary>
/// One or more CFFOLDER entries
/// </summary>
public CFFOLDER[]? Folders { get; set; }
public CFFOLDER[] Folders { get; set; }
/// <summary>
/// A series of one or more cabinet file (CFFILE) entries
/// </summary>
public CFFILE[]? Files { get; set; }
public CFFILE[] Files { get; set; }
}
}

View File

@@ -8,4 +8,4 @@ namespace SabreTools.Data.Models.MicrosoftCabinet
public const uint SignatureUInt32 = 0x4643534d;
}
}
}

View File

@@ -75,7 +75,7 @@ namespace SabreTools.Data.Models.MicrosoftCabinet
/// <summary>
/// Indicates that the folder index is actually zero, but that
/// extraction of this file would have to begin with the cabinet named in the
/// CFHEADER.szCabinetPrev field.
/// CFHEADER.szCabinetPrev field.
/// </summary>
CONTINUED_FROM_PREV = 0xFFFD,

View File

@@ -87,7 +87,7 @@ namespace SabreTools.Serialization.Wrappers
private MicrosoftCabinet? OpenNext(string? filename)
{
// Ignore invalid archives
if (Header == null || string.IsNullOrEmpty(filename))
if (string.IsNullOrEmpty(filename))
return null;
// Normalize the filename
@@ -115,7 +115,7 @@ namespace SabreTools.Serialization.Wrappers
private MicrosoftCabinet? OpenPrevious(string? filename)
{
// Ignore invalid archives
if (Header == null || string.IsNullOrEmpty(filename))
if (string.IsNullOrEmpty(filename))
return null;
// Normalize the filename
@@ -222,7 +222,7 @@ namespace SabreTools.Serialization.Wrappers
byte[] fileData = blockStream.ReadBytes((int)file.FileSize);
// Ensure directory separators are consistent
string filename = file.Name!;
string filename = file.Name;
if (Path.DirectorySeparatorChar == '\\')
filename = filename.Replace('/', '\\');
else if (Path.DirectorySeparatorChar == '/')

View File

@@ -23,17 +23,10 @@ namespace SabreTools.Serialization.Wrappers
Print(builder, Model.Files);
}
private static void Print(StringBuilder builder, CFHEADER? header)
private static void Print(StringBuilder builder, CFHEADER header)
{
builder.AppendLine(" Header Information:");
builder.AppendLine(" -------------------------");
if (header == null)
{
builder.AppendLine(" No header");
builder.AppendLine();
return;
}
builder.AppendLine(header.Signature, " Signature");
builder.AppendLine(header.Reserved1, " Reserved 1");
builder.AppendLine(header.CabinetSize, " Cabinet size");
@@ -83,11 +76,11 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine();
}
private static void Print(StringBuilder builder, CFFOLDER[]? entries)
private static void Print(StringBuilder builder, CFFOLDER[] entries)
{
builder.AppendLine(" Folders:");
builder.AppendLine(" -------------------------");
if (entries == null || entries.Length == 0)
if (entries.Length == 0)
{
builder.AppendLine(" No folders");
builder.AppendLine();
@@ -108,7 +101,7 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine(" Data Blocks");
builder.AppendLine(" -------------------------");
if (entry.DataBlocks == null || entry.DataBlocks.Length == 0)
if (entry.DataBlocks.Length == 0)
{
builder.AppendLine(" No data blocks");
continue;
@@ -130,11 +123,11 @@ namespace SabreTools.Serialization.Wrappers
builder.AppendLine();
}
private static void Print(StringBuilder builder, CFFILE[]? entries)
private static void Print(StringBuilder builder, CFFILE[] entries)
{
builder.AppendLine(" Files:");
builder.AppendLine(" -------------------------");
if (entries == null || entries.Length == 0)
if (entries.Length == 0)
{
builder.AppendLine(" No files");
builder.AppendLine();

View File

@@ -17,25 +17,25 @@ namespace SabreTools.Serialization.Wrappers
#region Extension Properties
/// <inheritdoc cref="Cabinet.Files"/>
public CFFILE[]? Files => Model.Files;
public CFFILE[] Files => Model.Files;
/// <inheritdoc cref="CFHEADER.FileCount"/>
public int FileCount => Header?.FileCount ?? 0;
public int FileCount => Header.FileCount;
/// <inheritdoc cref="Cabinet.Folders"/>
public CFFOLDER[]? Folders => Model.Folders;
public CFFOLDER[] Folders => Model.Folders;
/// <inheritdoc cref="CFHEADER.FolderCount"/>
public int FolderCount => Header?.FolderCount ?? 0;
public int FolderCount => Header.FolderCount;
/// <inheritdoc cref="Cabinet.Header"/>
public CFHEADER? Header => Model.Header;
public CFHEADER Header => Model.Header;
/// <inheritdoc cref="CFHEADER.CabinetNext"/>
public string? CabinetNext => Header?.CabinetNext;
public string? CabinetNext => Header.CabinetNext;
/// <inheritdoc cref="CFHEADER.CabinetPrev"/>
public string? CabinetPrev => Header?.CabinetPrev;
public string? CabinetPrev => Header.CabinetPrev;
#endregion
@@ -162,7 +162,7 @@ namespace SabreTools.Serialization.Wrappers
return file.FolderIndex switch
{
FolderIndex.CONTINUED_FROM_PREV => 0,
FolderIndex.CONTINUED_TO_NEXT => (Header?.FolderCount ?? 1) - 1,
FolderIndex.CONTINUED_TO_NEXT => Header.FolderCount - 1,
FolderIndex.CONTINUED_PREV_AND_NEXT => 0,
_ => (int)file.FolderIndex,
};
@@ -199,8 +199,6 @@ namespace SabreTools.Serialization.Wrappers
for (int i = 0; i < dataBlocks.Length; i++)
{
var db = dataBlocks[i];
if (db.CompressedData == null)
continue;
// Get the data to be processed
byte[] blockData = db.CompressedData;