mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-05-06 20:43:36 +00:00
Remove useless PathProcessor helper class
This commit is contained in:
@@ -41,8 +41,21 @@ namespace SabreTools.Serialization.Deserializers
|
||||
/// <inheritdoc/>
|
||||
public virtual TModel? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return Deserialize(stream);
|
||||
try
|
||||
{
|
||||
// If we don't have a file
|
||||
if (string.IsNullOrEmpty(path) || !File.Exists(path))
|
||||
return default;
|
||||
|
||||
// Open the file for deserialization
|
||||
using var stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
return Deserialize(stream);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// TODO: Handle logging the exception
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -42,8 +42,21 @@ namespace SabreTools.Serialization.Deserializers
|
||||
/// <inheritdoc cref="Deserialize(string?)"/>
|
||||
public MetadataFile? Deserialize(string? path, bool quotes)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return Deserialize(stream, quotes);
|
||||
try
|
||||
{
|
||||
// If we don't have a file
|
||||
if (string.IsNullOrEmpty(path) || !File.Exists(path))
|
||||
return default;
|
||||
|
||||
// Open the file for deserialization
|
||||
using var stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
return Deserialize(stream, quotes);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// TODO: Handle logging the exception
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -41,8 +41,21 @@ namespace SabreTools.Serialization.Deserializers
|
||||
/// <inheritdoc cref="Deserialize(string?)"/>
|
||||
public Models.Hashfile.Hashfile? Deserialize(string? path, HashType hash)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return Deserialize(stream, hash);
|
||||
try
|
||||
{
|
||||
// If we don't have a file
|
||||
if (string.IsNullOrEmpty(path) || !File.Exists(path))
|
||||
return default;
|
||||
|
||||
// Open the file for deserialization
|
||||
using var stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
return Deserialize(stream, hash);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// TODO: Handle logging the exception
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -56,8 +56,21 @@ namespace SabreTools.Serialization.Deserializers
|
||||
/// <returns>Filled object on success, null on error</returns>
|
||||
public T? Deserialize(string? path, Encoding encoding)
|
||||
{
|
||||
using var data = PathProcessor.OpenStream(path);
|
||||
return Deserialize(data, encoding);
|
||||
try
|
||||
{
|
||||
// If we don't have a file
|
||||
if (string.IsNullOrEmpty(path) || !File.Exists(path))
|
||||
return default;
|
||||
|
||||
// Open the file for deserialization
|
||||
using var stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
return Deserialize(stream, encoding);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// TODO: Handle logging the exception
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
using System.IO;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
internal class PathProcessor
|
||||
{
|
||||
/// <summary>
|
||||
/// Opens a path as a stream in a safe manner, decompressing if needed
|
||||
/// </summary>
|
||||
/// <param name="path">Path to open as a stream</param>
|
||||
/// <returns>Stream representing the file, null on error</returns>
|
||||
public static Stream? OpenStream(string? path)
|
||||
{
|
||||
try
|
||||
{
|
||||
// If we don't have a file
|
||||
if (string.IsNullOrEmpty(path) || !File.Exists(path))
|
||||
return null;
|
||||
|
||||
// Open the file for deserialization
|
||||
return File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// TODO: Handle logging the exception
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,8 +49,21 @@ namespace SabreTools.Serialization.Deserializers
|
||||
/// <inheritdoc cref="Deserialize(string?)"/>
|
||||
public MetadataFile? Deserialize(string? path, char delim)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return Deserialize(stream, delim);
|
||||
try
|
||||
{
|
||||
// If we don't have a file
|
||||
if (string.IsNullOrEmpty(path) || !File.Exists(path))
|
||||
return default;
|
||||
|
||||
// Open the file for deserialization
|
||||
using var stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
return Deserialize(stream, delim);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// TODO: Handle logging the exception
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -588,7 +588,6 @@ namespace SabreTools.Serialization.Printers
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: If more sections added, model this after the Export Table
|
||||
for (int i = 0; i < table.DebugDirectoryTable.Length; i++)
|
||||
{
|
||||
var entry = table.DebugDirectoryTable[i];
|
||||
|
||||
Reference in New Issue
Block a user