From 3085ec266cea680c9ec36f3c9ac062b6258eaab5 Mon Sep 17 00:00:00 2001 From: Jhett Black Date: Sat, 23 Dec 2017 14:48:44 +1000 Subject: [PATCH] Add FileTimestamp property to RemoteStorage.File. --- .../Client/RemoteStorageTest.cs | 3 ++- .../Client/RemoteStorage.File.cs | 19 ++++++++++++++++++- Facepunch.Steamworks/Client/RemoteStorage.cs | 4 +++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Facepunch.Steamworks.Test/Client/RemoteStorageTest.cs b/Facepunch.Steamworks.Test/Client/RemoteStorageTest.cs index 08f7f8b..3b8c587 100644 --- a/Facepunch.Steamworks.Test/Client/RemoteStorageTest.cs +++ b/Facepunch.Steamworks.Test/Client/RemoteStorageTest.cs @@ -78,7 +78,8 @@ public void WriteFiles() 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}" ); } } } diff --git a/Facepunch.Steamworks/Client/RemoteStorage.File.cs b/Facepunch.Steamworks/Client/RemoteStorage.File.cs index 58b93ae..80851d5 100644 --- a/Facepunch.Steamworks/Client/RemoteStorage.File.cs +++ b/Facepunch.Steamworks/Client/RemoteStorage.File.cs @@ -19,6 +19,7 @@ public class RemoteFile private readonly bool _isUgc; private string _fileName; private int _sizeInBytes = -1; + private long _timestamp = 0; private UGCHandle_t _handle; private ulong _ownerId; @@ -84,6 +85,21 @@ public int SizeInBytes internal set { _sizeInBytes = value; } } + /// + /// Date modified timestamp in epoch format. + /// + 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 ) { Exists = true; @@ -94,7 +110,7 @@ internal RemoteFile( RemoteStorage r, UGCHandle_t 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; @@ -102,6 +118,7 @@ internal RemoteFile( RemoteStorage r, string name, ulong ownerId, int sizeInByte _fileName = name; _ownerId = ownerId; _sizeInBytes = sizeInBytes; + _timestamp = timestamp; } /// diff --git a/Facepunch.Steamworks/Client/RemoteStorage.cs b/Facepunch.Steamworks/Client/RemoteStorage.cs index 7110d31..0330afa 100644 --- a/Facepunch.Steamworks/Client/RemoteStorage.cs +++ b/Facepunch.Steamworks/Client/RemoteStorage.cs @@ -177,16 +177,18 @@ private void UpdateFiles() { int size; var name = NormalizePath( native.GetFileNameAndSize( i, out size ) ); + var timestamp = native.GetFileTimestamp(name); var existing = _files.FirstOrDefault( x => x.FileName == name ); if ( existing == null ) { - existing = new RemoteFile( this, name, client.SteamId, size ); + existing = new RemoteFile( this, name, client.SteamId, size, timestamp ); _files.Add( existing ); } else { existing.SizeInBytes = size; + existing.FileTimestamp = timestamp; } existing.Exists = true;