Skip to content

Commit

Permalink
- Be able to add an entry from a Stream to an AFS file and fixed an e…
Browse files Browse the repository at this point in the history
…xception message.
  • Loading branch information
MaikelChan committed Sep 1, 2021
1 parent 1a26756 commit 6a0e83a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
38 changes: 34 additions & 4 deletions AFSLib/AFS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,26 +362,56 @@ public void SaveToStream(Stream outputStream)
/// <summary>
/// Adds a new entry from a file.
/// </summary>
/// <param name="fileNamePath">Path to the file that will be added.</param>
/// <param name="entryName">The name of the entry.</param>
public void AddEntryFromFile(string fileNamePath, string entryName)
/// <param name="fileNamePath">Path to the file that will be added.</param>
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();
}

/// <summary>
/// Adds a new entry from a stream.
/// </summary>
/// <param name="entryName">The name of the entry.</param>
/// <param name="entryStream">Stream that contains the file that will be added.</param>
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();
}

Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 6a0e83a

Please sign in to comment.