2024-12-02 11:43:04 -05:00
|
|
|
using System.IO;
|
2024-12-02 00:35:04 -05:00
|
|
|
|
|
|
|
|
namespace BinaryObjectScanner
|
|
|
|
|
{
|
|
|
|
|
internal static class Extensions
|
|
|
|
|
{
|
2024-12-02 11:43:04 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Helper to get the filesize from a path
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Size of the file path, -1 on error</returns>
|
|
|
|
|
public static long FileSize(this string? filename)
|
|
|
|
|
{
|
|
|
|
|
// Invalid filenames are ignored
|
|
|
|
|
if (string.IsNullOrEmpty(filename))
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
// Non-file paths are ignored
|
|
|
|
|
if (!File.Exists(filename))
|
|
|
|
|
return -1;
|
|
|
|
|
|
2024-12-02 11:44:57 -05:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return new FileInfo(filename).Length;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// Ignore errors
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2024-12-02 11:43:04 -05:00
|
|
|
}
|
2024-12-02 00:35:04 -05:00
|
|
|
}
|
2025-09-21 18:55:55 -04:00
|
|
|
}
|