Merge pull request #94 from jhett12321/master

Add FileTimestamp property to RemoteStorage.File.
This commit is contained in:
Garry Newman 2018-07-24 10:14:36 +01:00 committed by GitHub
commit 438127288a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 3 deletions

View File

@ -77,7 +77,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}" );
}
}
}

View File

@ -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; }
}
/// <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 )
{
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;
}
/// <summary>

View File

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