From 41276e3d7e5381067941838b23ec63dc77590388 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 23 Apr 2024 15:38:21 -0400 Subject: [PATCH] Port more helpers --- .../Wrappers/InstallShieldCabinet.cs | 102 +++++++++++++++--- 1 file changed, 85 insertions(+), 17 deletions(-) diff --git a/SabreTools.Serialization/Wrappers/InstallShieldCabinet.cs b/SabreTools.Serialization/Wrappers/InstallShieldCabinet.cs index 5f548d01..d5b2da59 100644 --- a/SabreTools.Serialization/Wrappers/InstallShieldCabinet.cs +++ b/SabreTools.Serialization/Wrappers/InstallShieldCabinet.cs @@ -104,7 +104,7 @@ namespace SabreTools.Serialization.Wrappers #endregion - #region Accessors + #region Component /// /// Get the component name at a given index, if possible @@ -124,6 +124,10 @@ namespace SabreTools.Serialization.Wrappers return component.Identifier.Replace('\\', '/'); } + #endregion + + #region Directory + /// /// Get the directory name at a given index, if possible /// @@ -138,6 +142,66 @@ namespace SabreTools.Serialization.Wrappers return Model.DirectoryNames[index]; } + /// + /// Get the directory index for the given file index + /// + /// Directory index if found, UInt32.MaxValue on error + public uint GetFileDirectoryIndex(int index) + { + FileDescriptor? descriptor = GetFileDescriptor(index); + if (descriptor != null) + return descriptor.DirectoryIndex; + else + return uint.MaxValue; + } + + #endregion + + #region File + + /// + /// Returns if the file at a given index is marked as valid + /// + public bool FileIsValid(int index) + { + if (Model.Descriptor == null) + return false; + + if (index < 0 || index > Model.Descriptor.FileCount) + return false; + + FileDescriptor? descriptor = GetFileDescriptor(index); + if (descriptor == null) + return false; + +#if NET20 || NET35 + if ((descriptor.Flags & FileFlags.FILE_INVALID) != 0) +#else + if (descriptor.Flags.HasFlag(FileFlags.FILE_INVALID)) +#endif + return false; + + if (descriptor.NameOffset == default) + return false; + + if (descriptor.DataOffset == default) + return false; + + return true; + } + + /// + /// Get the reported expanded file size for a given index + /// + public ulong GetExpandedFileSize(int index) + { + FileDescriptor? descriptor = GetFileDescriptor(index); + if (descriptor != null) + return descriptor.ExpandedSize; + else + return 0; + } + /// /// Get the file descriptor at a given index, if possible /// @@ -152,6 +216,26 @@ namespace SabreTools.Serialization.Wrappers return Model.FileDescriptors[index]; } + /// + /// Get the file name at a given index, if possible + /// + public string? GetFileName(int index) + { + var descriptor = GetFileDescriptor(index); +#if NET20 || NET35 + if (descriptor == null || (descriptor.Flags & FileFlags.FILE_INVALID) != 0) +#else + if (descriptor == null || descriptor.Flags.HasFlag(FileFlags.FILE_INVALID)) +#endif + return null; + + return descriptor.Name; + } + + #endregion + + #region File Group + /// /// Get the file group at a given index, if possible /// @@ -177,22 +261,6 @@ namespace SabreTools.Serialization.Wrappers return Model.FileGroups.FirstOrDefault(fg => fg != null && string.Equals(fg.Name, name)); } - /// - /// Get the file name at a given index, if possible - /// - public string? GetFileName(int index) - { - var descriptor = GetFileDescriptor(index); -#if NET20 || NET35 - if (descriptor == null || (descriptor.Flags & FileFlags.FILE_INVALID) != 0) -#else - if (descriptor == null || descriptor.Flags.HasFlag(FileFlags.FILE_INVALID)) -#endif - return null; - - return descriptor.Name; - } - /// /// Get the file group name at a given index, if possible ///