diff --git a/AFSLib/AFS.cs b/AFSLib/AFS.cs index 7911f9c..fd0e65d 100644 --- a/AFSLib/AFS.cs +++ b/AFSLib/AFS.cs @@ -362,26 +362,56 @@ public void SaveToStream(Stream outputStream) /// /// Adds a new entry from a file. /// - /// Path to the file that will be added. /// The name of the entry. - public void AddEntryFromFile(string fileNamePath, string entryName) + /// Path to the file that will be added. + public void AddEntry(string entryName, string fileNamePath) { - if (string.IsNullOrEmpty(fileNamePath)) + if (entryName == null) { throw new ArgumentNullException(nameof(entryName)); } + if (string.IsNullOrEmpty(fileNamePath)) + { + throw new ArgumentNullException(nameof(fileNamePath)); + } + if (!File.Exists(fileNamePath)) { throw new FileNotFoundException($"File \"{fileNamePath}\" has not been found.", fileNamePath); } + entries.Add(new FileEntry(this, fileNamePath, entryName)); + UpdateEntriesNames(); + } + + /// + /// Adds a new entry from a stream. + /// + /// The name of the entry. + /// Stream that contains the file that will be added. + public void AddEntry(string entryName, Stream entryStream) + { if (entryName == null) { throw new ArgumentNullException(nameof(entryName)); } - entries.Add(new FileEntry(this, fileNamePath, entryName)); + if (entryStream == null) + { + throw new ArgumentNullException(nameof(entryStream)); + } + + StreamEntryInfo info = new StreamEntryInfo() + { + Offset = 0, + Name = entryName, + Size = (uint)entryStream.Length, + LastWriteTime = DateTime.Now, + Unknown = (uint)entryStream.Length + }; + + entries.Add(new StreamEntry(this, entryStream, info)); UpdateEntriesNames(); } diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e35de2c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,16 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +## [1.0.1] - 2021-09-01 +### Added +- Be able to add an entry from a Stream to an AFS file. +### Fixed +- Fixed an exception message. + +## [1.0.0] - 2021-09-01 +- Initial release. \ No newline at end of file