From a2ddbb2846d55d183341e1f29e08b50fc7a63e75 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 1 Sep 2025 06:26:42 +0100 Subject: [PATCH] [ARC] Implement Stat. --- Aaru.Archives/Arc/Files.cs | 42 +++++++++++++++++++++++++++++- Aaru.Archives/Arc/Unimplemented.cs | 4 --- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/Aaru.Archives/Arc/Files.cs b/Aaru.Archives/Arc/Files.cs index aa4e5c69c..a6f4f3214 100644 --- a/Aaru.Archives/Arc/Files.cs +++ b/Aaru.Archives/Arc/Files.cs @@ -1,6 +1,7 @@ using System; -using System.IO; using Aaru.CommonTypes.Enums; +using Aaru.CommonTypes.Structs; +using FileAttributes = System.IO.FileAttributes; namespace Aaru.Archives; @@ -90,5 +91,44 @@ public sealed partial class Arc return ErrorNumber.NoError; } + /// + public ErrorNumber Stat(int entryNumber, out FileEntryInfo stat) + { + stat = null; + + if(!Opened) return ErrorNumber.NotOpened; + + if(entryNumber < 0 || entryNumber >= _entries.Count) return ErrorNumber.OutOfRange; + + Entry entry = _entries[entryNumber]; + + stat = new FileEntryInfo + { + Attributes = CommonTypes.Structs.FileAttributes.None, + Blocks = entry.Uncompressed / 512, + BlockSize = 512, + Length = entry.Uncompressed, + LastWriteTime = entry.LastWriteTime, + LastWriteTimeUtc = entry.LastWriteTime + }; + + if(entry.Attributes.HasFlag(FileAttributes.Directory)) + stat.Attributes |= CommonTypes.Structs.FileAttributes.Directory; + + if(entry.Attributes.HasFlag(FileAttributes.Archive)) + stat.Attributes |= CommonTypes.Structs.FileAttributes.Archive; + + if(entry.Attributes.HasFlag(FileAttributes.Hidden)) + stat.Attributes |= CommonTypes.Structs.FileAttributes.Hidden; + + if(entry.Attributes.HasFlag(FileAttributes.ReadOnly)) + stat.Attributes |= CommonTypes.Structs.FileAttributes.ReadOnly; + + if(entry.Attributes.HasFlag(FileAttributes.System)) + stat.Attributes |= CommonTypes.Structs.FileAttributes.System; + + return ErrorNumber.NoError; + } + #endregion } \ No newline at end of file diff --git a/Aaru.Archives/Arc/Unimplemented.cs b/Aaru.Archives/Arc/Unimplemented.cs index 83d0119f8..37c03b310 100644 --- a/Aaru.Archives/Arc/Unimplemented.cs +++ b/Aaru.Archives/Arc/Unimplemented.cs @@ -1,7 +1,6 @@ using System; using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Interfaces; -using Aaru.CommonTypes.Structs; namespace Aaru.Archives; @@ -9,9 +8,6 @@ public sealed partial class Arc { #region IArchive Members - /// - public ErrorNumber Stat(int entryNumber, out FileEntryInfo stat) => throw new NotImplementedException(); - /// public ErrorNumber GetEntry(int entryNumber, out IFilter filter) => throw new NotImplementedException();