Remove useless PathProcessor helper class

This commit is contained in:
Matt Nadareski
2025-09-24 09:43:27 -04:00
parent b6acde9145
commit 842a0c3daf
7 changed files with 75 additions and 41 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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;
}
}
}
}

View File

@@ -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

View File

@@ -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];