From 4cef93c95ea78a95f9f8a713bb3e8bad686a7fb8 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 23 Apr 2024 15:27:07 -0400 Subject: [PATCH] Port some accessors from UnshieldSharp --- .../Wrappers/InstallShieldCabinet.cs | 117 +++++++++++++++++- 1 file changed, 114 insertions(+), 3 deletions(-) diff --git a/SabreTools.Serialization/Wrappers/InstallShieldCabinet.cs b/SabreTools.Serialization/Wrappers/InstallShieldCabinet.cs index f4ad13f9..5f548d01 100644 --- a/SabreTools.Serialization/Wrappers/InstallShieldCabinet.cs +++ b/SabreTools.Serialization/Wrappers/InstallShieldCabinet.cs @@ -1,8 +1,10 @@ using System.IO; +using System.Linq; +using SabreTools.Models.InstallShieldCabinet; namespace SabreTools.Serialization.Wrappers { - public partial class InstallShieldCabinet : WrapperBase + public partial class InstallShieldCabinet : WrapperBase { #region Descriptive Properties @@ -41,14 +43,14 @@ namespace SabreTools.Serialization.Wrappers #region Constructors /// - public InstallShieldCabinet(Models.InstallShieldCabinet.Cabinet? model, byte[]? data, int offset) + public InstallShieldCabinet(Cabinet? model, byte[]? data, int offset) : base(model, data, offset) { // All logic is handled by the base class } /// - public InstallShieldCabinet(Models.InstallShieldCabinet.Cabinet? model, Stream? data) + public InstallShieldCabinet(Cabinet? model, Stream? data) : base(model, data) { // All logic is handled by the base class @@ -101,5 +103,114 @@ namespace SabreTools.Serialization.Wrappers } #endregion + + #region Accessors + + /// + /// Get the component name at a given index, if possible + /// + public string? GetComponentName(int index) + { + if (Model.Components == null) + return null; + + if (index < 0 || index >= Model.Components.Length) + return null; + + var component = Model.Components[index]; + if (component?.Identifier == null) + return null; + + return component.Identifier.Replace('\\', '/'); + } + + /// + /// Get the directory name at a given index, if possible + /// + public string? GetDirectoryName(int index) + { + if (Model.DirectoryNames == null) + return null; + + if (index < 0 || index >= Model.DirectoryNames.Length) + return null; + + return Model.DirectoryNames[index]; + } + + /// + /// Get the file descriptor at a given index, if possible + /// + public FileDescriptor? GetFileDescriptor(int index) + { + if (Model.FileDescriptors == null) + return null; + + if (index < 0 || index >= Model.FileDescriptors.Length) + return null; + + return Model.FileDescriptors[index]; + } + + /// + /// Get the file group at a given index, if possible + /// + public FileGroup? GetFileGroup(int index) + { + if (Model.FileGroups == null) + return null; + + if (index < 0 || index >= Model.FileGroups.Length) + return null; + + return Model.FileGroups[index]; + } + + /// + /// Get the file group at a given name, if possible + /// + public FileGroup? GetFileGroup(string name) + { + if (Model.FileGroups == null) + return null; + + 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 + /// + public string? GetFileGroupName(int index) + { + if (Model.FileGroups == null) + return null; + + if (index < 0 || index >= Model.FileGroups.Length) + return null; + + var fileGroup = Model.FileGroups[index]; + if (fileGroup == null) + return null; + + return fileGroup.Name; + } + + #endregion } }