Add FileTimestamp property to RemoteStorage.File.

This commit is contained in:
Jhett Black 2017-12-23 14:48:44 +10:00
parent 1ccea72a13
commit 3085ec266c
3 changed files with 23 additions and 3 deletions

View File

@ -78,7 +78,8 @@ namespace Facepunch.Steamworks.Test
foreach ( var file in client.RemoteStorage.Files ) foreach ( var file in client.RemoteStorage.Files )
{ {
Console.WriteLine( $"- {file.FileName} ({file.SizeInBytes} bytes)" ); DateTime t = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(file.FileTimestamp);
Console.WriteLine( $"- {file.FileName} ({file.SizeInBytes} bytes), modified {t:O}" );
} }
} }
} }

View File

@ -19,6 +19,7 @@ namespace Facepunch.Steamworks
private readonly bool _isUgc; private readonly bool _isUgc;
private string _fileName; private string _fileName;
private int _sizeInBytes = -1; private int _sizeInBytes = -1;
private long _timestamp = 0;
private UGCHandle_t _handle; private UGCHandle_t _handle;
private ulong _ownerId; private ulong _ownerId;
@ -84,6 +85,21 @@ namespace Facepunch.Steamworks
internal set { _sizeInBytes = value; } internal set { _sizeInBytes = value; }
} }
/// <summary>
/// Date modified timestamp in epoch format.
/// </summary>
public long FileTimestamp
{
get
{
if ( _timestamp != 0 ) return _timestamp;
if (_isUgc) throw new NotImplementedException();
_timestamp = remoteStorage.native.GetFileTimestamp(FileName);
return _timestamp;
}
internal set { _timestamp = value; }
}
internal RemoteFile( RemoteStorage r, UGCHandle_t handle ) internal RemoteFile( RemoteStorage r, UGCHandle_t handle )
{ {
Exists = true; Exists = true;
@ -94,7 +110,7 @@ namespace Facepunch.Steamworks
_handle = handle; _handle = handle;
} }
internal RemoteFile( RemoteStorage r, string name, ulong ownerId, int sizeInBytes = -1 ) internal RemoteFile( RemoteStorage r, string name, ulong ownerId, int sizeInBytes = -1, long timestamp = 0 )
{ {
remoteStorage = r; remoteStorage = r;
@ -102,6 +118,7 @@ namespace Facepunch.Steamworks
_fileName = name; _fileName = name;
_ownerId = ownerId; _ownerId = ownerId;
_sizeInBytes = sizeInBytes; _sizeInBytes = sizeInBytes;
_timestamp = timestamp;
} }
/// <summary> /// <summary>

View File

@ -177,16 +177,18 @@ namespace Facepunch.Steamworks
{ {
int size; int size;
var name = NormalizePath( native.GetFileNameAndSize( i, out size ) ); var name = NormalizePath( native.GetFileNameAndSize( i, out size ) );
var timestamp = native.GetFileTimestamp(name);
var existing = _files.FirstOrDefault( x => x.FileName == name ); var existing = _files.FirstOrDefault( x => x.FileName == name );
if ( existing == null ) if ( existing == null )
{ {
existing = new RemoteFile( this, name, client.SteamId, size ); existing = new RemoteFile( this, name, client.SteamId, size, timestamp );
_files.Add( existing ); _files.Add( existing );
} }
else else
{ {
existing.SizeInBytes = size; existing.SizeInBytes = size;
existing.FileTimestamp = timestamp;
} }
existing.Exists = true; existing.Exists = true;