mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-07 22:32:27 +01:00
The watch of scenery files asked three times per file, whether it is there, its time and its size, every two seconds for every source of every scenery. One look gives all three.
22 lines
645 B
C#
22 lines
645 B
C#
using System;
|
|
using StarterNG.Application.Abstractions;
|
|
|
|
namespace StarterNG.Domain.Sceneries;
|
|
|
|
/// <summary>A file as it stood, to tell whether it has been changed since.</summary>
|
|
public readonly record struct FileStamp(DateTime LastWriteUtc, long Size)
|
|
{
|
|
/// <summary>Null for one that is not there, or cannot be looked at just now.</summary>
|
|
public static FileStamp? Of(IFileSystem files, string path)
|
|
{
|
|
try
|
|
{
|
|
return files.LastWriteAndSize(path) is { } stat ? new FileStamp(stat.LastWriteUtc, stat.Size) : null;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|