mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
CopyToStream needs some work
This commit is contained in:
@@ -744,7 +744,10 @@ namespace SabreTools.DatTools
|
||||
{
|
||||
BaseArchive? archive = BaseArchive.Create(file);
|
||||
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
|
||||
else
|
||||
|
||||
@@ -130,9 +130,9 @@ namespace SabreTools.FileTypes.Archives
|
||||
public override string? CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
realEntry = Path.Combine(outDir, realEntry);
|
||||
@@ -170,9 +170,9 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream?, string?) CopyToStream(string entryName)
|
||||
public override (Stream?, string?) CopyToStream(string entryName)
|
||||
{
|
||||
MemoryStream? ms = new();
|
||||
var ms = new MemoryStream();
|
||||
string? realEntry;
|
||||
|
||||
// If we have an invalid file
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream, string) CopyToStream(string entryName)
|
||||
public override (Stream?, string?) CopyToStream(string entryName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream, string) CopyToStream(string entryName)
|
||||
public override (Stream?, string?) CopyToStream(string entryName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -96,9 +96,9 @@ namespace SabreTools.FileTypes.Archives
|
||||
public override string? CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
realEntry = Path.Combine(outDir, realEntry);
|
||||
@@ -134,10 +134,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream?, string?) CopyToStream(string entryName)
|
||||
public override (Stream?, string?) CopyToStream(string entryName)
|
||||
{
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
MemoryStream? ms = new();
|
||||
var ms = new MemoryStream();
|
||||
string? realEntry = null;
|
||||
|
||||
// If we have an invalid file
|
||||
|
||||
@@ -183,9 +183,9 @@ namespace SabreTools.FileTypes.Archives
|
||||
public override string? CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
realEntry = Path.Combine(outDir, realEntry);
|
||||
@@ -221,9 +221,9 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <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;
|
||||
|
||||
// If we have an invalid file
|
||||
|
||||
@@ -97,9 +97,9 @@ namespace SabreTools.FileTypes.Archives
|
||||
public override string? CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
realEntry = Path.Combine(outDir, realEntry);
|
||||
@@ -135,10 +135,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream?, string?) CopyToStream(string entryName)
|
||||
public override (Stream?, string?) CopyToStream(string entryName)
|
||||
{
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
MemoryStream? ms = new();
|
||||
var ms = new MemoryStream();
|
||||
string? realEntry = null;
|
||||
|
||||
try
|
||||
|
||||
@@ -114,9 +114,9 @@ namespace SabreTools.FileTypes.Archives
|
||||
public override string? CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
realEntry = Path.Combine(outDir, realEntry);
|
||||
@@ -152,10 +152,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream?, string?) CopyToStream(string entryName)
|
||||
public override (Stream?, string?) CopyToStream(string entryName)
|
||||
{
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
MemoryStream? ms = new();
|
||||
var ms = new MemoryStream();
|
||||
string? realEntry;
|
||||
|
||||
try
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream, string) CopyToStream(string entryName)
|
||||
public override (Stream?, string?) CopyToStream(string entryName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -158,9 +158,9 @@ namespace SabreTools.FileTypes.Archives
|
||||
public override string? CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
realEntry = Path.Combine(outDir, realEntry);
|
||||
@@ -196,9 +196,9 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <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;
|
||||
|
||||
try
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream, string) CopyToStream(string entryName)
|
||||
public override (Stream?, string?) CopyToStream(string entryName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace SabreTools.FileTypes
|
||||
public override abstract string? CopyToFile(string entryName, string outDir);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override abstract (MemoryStream?, string?) CopyToStream(string entryName);
|
||||
public override abstract (Stream?, string?) CopyToStream(string entryName);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -210,9 +210,9 @@ namespace SabreTools.FileTypes
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <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;
|
||||
|
||||
// If we have an invalid filename
|
||||
|
||||
Reference in New Issue
Block a user