CopyToStream needs some work

This commit is contained in:
Matt Nadareski
2024-07-15 21:34:17 -04:00
parent a2e10f789b
commit e29610de4b
13 changed files with 35 additions and 32 deletions

View File

@@ -744,7 +744,10 @@ namespace SabreTools.DatTools
{ {
BaseArchive? archive = BaseArchive.Create(file); BaseArchive? archive = BaseArchive.Create(file);
if (archive != null) if (archive != null)
(stream, _) = archive.CopyToStream(datItem.GetName() ?? datItem.GetStringFieldValue(Models.Metadata.DatItem.TypeKey).AsEnumValue<ItemType>().AsStringValue() ?? string.Empty); {
ItemType itemType = datItem.GetStringFieldValue(Models.Metadata.DatItem.TypeKey).AsEnumValue<ItemType>();
(stream, _) = archive.CopyToStream(datItem.GetName() ?? itemType.AsStringValue() ?? string.Empty);
}
} }
// Otherwise, just open the filestream // Otherwise, just open the filestream
else else

View File

@@ -130,9 +130,9 @@ namespace SabreTools.FileTypes.Archives
public override string? CopyToFile(string entryName, string outDir) public override string? CopyToFile(string entryName, string outDir)
{ {
// Try to extract a stream using the given information // Try to extract a stream using the given information
(MemoryStream? ms, string? realEntry) = CopyToStream(entryName); (Stream? ms, string? realEntry) = CopyToStream(entryName);
// If the memory stream and the entry name are both non-null, we write to file // If the stream and the entry name are both non-null, we write to file
if (ms != null && realEntry != null) if (ms != null && realEntry != null)
{ {
realEntry = Path.Combine(outDir, realEntry); realEntry = Path.Combine(outDir, realEntry);
@@ -170,9 +170,9 @@ namespace SabreTools.FileTypes.Archives
} }
/// <inheritdoc/> /// <inheritdoc/>
public override (MemoryStream?, string?) CopyToStream(string entryName) public override (Stream?, string?) CopyToStream(string entryName)
{ {
MemoryStream? ms = new(); var ms = new MemoryStream();
string? realEntry; string? realEntry;
// If we have an invalid file // If we have an invalid file

View File

@@ -49,7 +49,7 @@ namespace SabreTools.FileTypes.Archives
} }
/// <inheritdoc/> /// <inheritdoc/>
public override (MemoryStream, string) CopyToStream(string entryName) public override (Stream?, string?) CopyToStream(string entryName)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@@ -49,7 +49,7 @@ namespace SabreTools.FileTypes.Archives
} }
/// <inheritdoc/> /// <inheritdoc/>
public override (MemoryStream, string) CopyToStream(string entryName) public override (Stream?, string?) CopyToStream(string entryName)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@@ -96,9 +96,9 @@ namespace SabreTools.FileTypes.Archives
public override string? CopyToFile(string entryName, string outDir) public override string? CopyToFile(string entryName, string outDir)
{ {
// Try to extract a stream using the given information // Try to extract a stream using the given information
(MemoryStream? ms, string? realEntry) = CopyToStream(entryName); (Stream? ms, string? realEntry) = CopyToStream(entryName);
// If the memory stream and the entry name are both non-null, we write to file // If the stream and the entry name are both non-null, we write to file
if (ms != null && realEntry != null) if (ms != null && realEntry != null)
{ {
realEntry = Path.Combine(outDir, realEntry); realEntry = Path.Combine(outDir, realEntry);
@@ -134,10 +134,10 @@ namespace SabreTools.FileTypes.Archives
} }
/// <inheritdoc/> /// <inheritdoc/>
public override (MemoryStream?, string?) CopyToStream(string entryName) public override (Stream?, string?) CopyToStream(string entryName)
{ {
#if NET462_OR_GREATER || NETCOREAPP #if NET462_OR_GREATER || NETCOREAPP
MemoryStream? ms = new(); var ms = new MemoryStream();
string? realEntry = null; string? realEntry = null;
// If we have an invalid file // If we have an invalid file

View File

@@ -183,9 +183,9 @@ namespace SabreTools.FileTypes.Archives
public override string? CopyToFile(string entryName, string outDir) public override string? CopyToFile(string entryName, string outDir)
{ {
// Try to extract a stream using the given information // Try to extract a stream using the given information
(MemoryStream? ms, string? realEntry) = CopyToStream(entryName); (Stream? ms, string? realEntry) = CopyToStream(entryName);
// If the memory stream and the entry name are both non-null, we write to file // If the stream and the entry name are both non-null, we write to file
if (ms != null && realEntry != null) if (ms != null && realEntry != null)
{ {
realEntry = Path.Combine(outDir, realEntry); realEntry = Path.Combine(outDir, realEntry);
@@ -221,9 +221,9 @@ namespace SabreTools.FileTypes.Archives
} }
/// <inheritdoc/> /// <inheritdoc/>
public override (MemoryStream?, string?) CopyToStream(string entryName) public override (Stream?, string?) CopyToStream(string entryName)
{ {
MemoryStream? ms = new(); var ms = new MemoryStream();
string? realEntry = null; string? realEntry = null;
// If we have an invalid file // If we have an invalid file

View File

@@ -97,9 +97,9 @@ namespace SabreTools.FileTypes.Archives
public override string? CopyToFile(string entryName, string outDir) public override string? CopyToFile(string entryName, string outDir)
{ {
// Try to extract a stream using the given information // Try to extract a stream using the given information
(MemoryStream? ms, string? realEntry) = CopyToStream(entryName); (Stream? ms, string? realEntry) = CopyToStream(entryName);
// If the memory stream and the entry name are both non-null, we write to file // If the stream and the entry name are both non-null, we write to file
if (ms != null && realEntry != null) if (ms != null && realEntry != null)
{ {
realEntry = Path.Combine(outDir, realEntry); realEntry = Path.Combine(outDir, realEntry);
@@ -135,10 +135,10 @@ namespace SabreTools.FileTypes.Archives
} }
/// <inheritdoc/> /// <inheritdoc/>
public override (MemoryStream?, string?) CopyToStream(string entryName) public override (Stream?, string?) CopyToStream(string entryName)
{ {
#if NET462_OR_GREATER || NETCOREAPP #if NET462_OR_GREATER || NETCOREAPP
MemoryStream? ms = new(); var ms = new MemoryStream();
string? realEntry = null; string? realEntry = null;
try try

View File

@@ -114,9 +114,9 @@ namespace SabreTools.FileTypes.Archives
public override string? CopyToFile(string entryName, string outDir) public override string? CopyToFile(string entryName, string outDir)
{ {
// Try to extract a stream using the given information // Try to extract a stream using the given information
(MemoryStream? ms, string? realEntry) = CopyToStream(entryName); (Stream? ms, string? realEntry) = CopyToStream(entryName);
// If the memory stream and the entry name are both non-null, we write to file // If the stream and the entry name are both non-null, we write to file
if (ms != null && realEntry != null) if (ms != null && realEntry != null)
{ {
realEntry = Path.Combine(outDir, realEntry); realEntry = Path.Combine(outDir, realEntry);
@@ -152,10 +152,10 @@ namespace SabreTools.FileTypes.Archives
} }
/// <inheritdoc/> /// <inheritdoc/>
public override (MemoryStream?, string?) CopyToStream(string entryName) public override (Stream?, string?) CopyToStream(string entryName)
{ {
#if NET462_OR_GREATER || NETCOREAPP #if NET462_OR_GREATER || NETCOREAPP
MemoryStream? ms = new(); var ms = new MemoryStream();
string? realEntry; string? realEntry;
try try

View File

@@ -49,7 +49,7 @@ namespace SabreTools.FileTypes.Archives
} }
/// <inheritdoc/> /// <inheritdoc/>
public override (MemoryStream, string) CopyToStream(string entryName) public override (Stream?, string?) CopyToStream(string entryName)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@@ -158,9 +158,9 @@ namespace SabreTools.FileTypes.Archives
public override string? CopyToFile(string entryName, string outDir) public override string? CopyToFile(string entryName, string outDir)
{ {
// Try to extract a stream using the given information // Try to extract a stream using the given information
(MemoryStream? ms, string? realEntry) = CopyToStream(entryName); (Stream? ms, string? realEntry) = CopyToStream(entryName);
// If the memory stream and the entry name are both non-null, we write to file // If the stream and the entry name are both non-null, we write to file
if (ms != null && realEntry != null) if (ms != null && realEntry != null)
{ {
realEntry = Path.Combine(outDir, realEntry); realEntry = Path.Combine(outDir, realEntry);
@@ -196,9 +196,9 @@ namespace SabreTools.FileTypes.Archives
} }
/// <inheritdoc/> /// <inheritdoc/>
public override (MemoryStream?, string?) CopyToStream(string entryName) public override (Stream?, string?) CopyToStream(string entryName)
{ {
MemoryStream? ms = new(); var ms = new MemoryStream();
string? realEntry = null; string? realEntry = null;
try try

View File

@@ -49,7 +49,7 @@ namespace SabreTools.FileTypes.Archives
} }
/// <inheritdoc/> /// <inheritdoc/>
public override (MemoryStream, string) CopyToStream(string entryName) public override (Stream?, string?) CopyToStream(string entryName)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@@ -121,7 +121,7 @@ namespace SabreTools.FileTypes
public override abstract string? CopyToFile(string entryName, string outDir); public override abstract string? CopyToFile(string entryName, string outDir);
/// <inheritdoc/> /// <inheritdoc/>
public override abstract (MemoryStream?, string?) CopyToStream(string entryName); public override abstract (Stream?, string?) CopyToStream(string entryName);
#endregion #endregion

View File

@@ -210,9 +210,9 @@ namespace SabreTools.FileTypes
/// </summary> /// </summary>
/// <param name="entryName">Name of the entry to be extracted</param> /// <param name="entryName">Name of the entry to be extracted</param>
/// <returns>MemoryStream representing the entry, null on error</returns> /// <returns>MemoryStream representing the entry, null on error</returns>
public virtual (MemoryStream?, string?) CopyToStream(string entryName) public virtual (Stream?, string?) CopyToStream(string entryName)
{ {
MemoryStream ms = new(); var ms = new MemoryStream();
string? realentry = null; string? realentry = null;
// If we have an invalid filename // If we have an invalid filename