mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-07-09 02:16:55 +00:00
MicrosoftCabinet model cleanup
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,6 @@
|
||||
/// <summary>
|
||||
/// Data blocks associated with this folder
|
||||
/// </summary>
|
||||
public CFDATA[]? DataBlocks { get; set; }
|
||||
public CFDATA[] DataBlocks { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,4 @@ namespace SabreTools.Data.Models.MicrosoftCabinet
|
||||
|
||||
public const uint SignatureUInt32 = 0x4643534d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
|
||||
@@ -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 == '/')
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user