Added documentation for the new Leaderboard and RemoteStorage members

This commit is contained in:
James King 2017-05-16 09:30:28 +01:00
parent 788145c265
commit 836f6e285c
2 changed files with 86 additions and 2 deletions

View File

@ -161,10 +161,20 @@ public bool AddScore( bool onlyIfBeatsOldScore, int score, int[] subscores = nul
return true; return true;
} }
/// <summary>
/// Callback invoked by <see cref="Leaderboard.AttachRemoteFile"/> when file attachment is complete.
/// </summary>
public delegate void AttachRemoteFileCallback( bool success ); public delegate void AttachRemoteFileCallback( bool success );
/// <summary>
/// Attempt to attach a <see cref="RemoteStorage"/> file to the current user's leaderboard entry.
/// Can be useful for storing replays along with scores.
/// </summary>
/// <returns>True if the file attachment process has started</returns>
public bool AttachRemoteFile( RemoteFile file, AttachRemoteFileCallback callback = null ) public bool AttachRemoteFile( RemoteFile file, AttachRemoteFileCallback callback = null )
{ {
if ( !IsValid ) return false;
if ( file.IsShared ) if ( file.IsShared )
{ {
client.native.userstats.AttachLeaderboardUGC( BoardId, file.UGCHandle, ( result, error ) => client.native.userstats.AttachLeaderboardUGC( BoardId, file.UGCHandle, ( result, error ) =>

View File

@ -23,7 +23,10 @@ public RemoteStorage RemoteStorage
} }
} }
internal class RemoteFileWriteStream : Stream /// <summary>
/// Stream used to write to a <see cref="RemoteFile"/>.
/// </summary>
public class RemoteFileWriteStream : Stream
{ {
internal readonly RemoteStorage remoteStorage; internal readonly RemoteStorage remoteStorage;
@ -77,6 +80,9 @@ public override unsafe void Write( byte[] buffer, int offset, int count )
public override long Length => _written; public override long Length => _written;
public override long Position { get { return _written; } set { throw new NotImplementedException(); } } public override long Position { get { return _written; } set { throw new NotImplementedException(); } }
/// <summary>
/// Close the stream without saving the file to remote storage.
/// </summary>
public void Cancel() public void Cancel()
{ {
if ( _closed ) return; if ( _closed ) return;
@ -85,7 +91,11 @@ public void Cancel()
remoteStorage.native.FileWriteStreamCancel( _handle ); remoteStorage.native.FileWriteStreamCancel( _handle );
} }
#if NETCORE
public void Close() public void Close()
#else
public override void Close()
#endif
{ {
if ( _closed ) return; if ( _closed ) return;
@ -102,6 +112,9 @@ protected override void Dispose( bool disposing )
} }
} }
/// <summary>
/// Represents a file stored in a user's Steam Cloud.
/// </summary>
public class RemoteFile public class RemoteFile
{ {
internal readonly RemoteStorage remoteStorage; internal readonly RemoteStorage remoteStorage;
@ -112,11 +125,21 @@ public class RemoteFile
private UGCHandle_t _handle; private UGCHandle_t _handle;
private ulong _ownerId; private ulong _ownerId;
/// <summary>
/// Check if the file exists.
/// </summary>
public bool Exists { get; internal set; } public bool Exists { get; internal set; }
/// <summary>
/// If true, the file is available for other users to download.
/// </summary>
public bool IsShared { get { return _handle.Value != 0; } } public bool IsShared { get { return _handle.Value != 0; } }
internal UGCHandle_t UGCHandle { get { return _handle; } } internal UGCHandle_t UGCHandle { get { return _handle; } }
/// <summary>
/// Name and path of the file.
/// </summary>
public string FileName public string FileName
{ {
get get
@ -127,6 +150,9 @@ public string FileName
} }
} }
/// <summary>
/// Steam ID of the file's owner.
/// </summary>
public ulong OwnerId public ulong OwnerId
{ {
get get
@ -137,6 +163,9 @@ public ulong OwnerId
} }
} }
/// <summary>
/// Total size of the file in bytes.
/// </summary>
public int SizeInBytes public int SizeInBytes
{ {
get get
@ -169,11 +198,18 @@ internal RemoteFile( RemoteStorage r, string name, ulong ownerId, int sizeInByte
_sizeInBytes = sizeInBytes; _sizeInBytes = sizeInBytes;
} }
public Stream OpenWrite() /// <summary>
/// Creates a <see cref="RemoteFileWriteStream"/> used to write to this file.
/// </summary>
/// <returns></returns>
public RemoteFileWriteStream OpenWrite()
{ {
return new RemoteFileWriteStream( remoteStorage, this ); return new RemoteFileWriteStream( remoteStorage, this );
} }
/// <summary>
/// Write a byte array to this file, replacing any existing contents.
/// </summary>
public void WriteAllBytes( byte[] buffer ) public void WriteAllBytes( byte[] buffer )
{ {
using ( var stream = OpenWrite() ) using ( var stream = OpenWrite() )
@ -182,17 +218,27 @@ public void WriteAllBytes( byte[] buffer )
} }
} }
/// <summary>
/// Write a string to this file, replacing any existing contents.
/// </summary>
public void WriteAllText( string text, Encoding encoding = null ) public void WriteAllText( string text, Encoding encoding = null )
{ {
if ( encoding == null ) encoding = Encoding.UTF8; if ( encoding == null ) encoding = Encoding.UTF8;
WriteAllBytes( encoding.GetBytes( text ) ); WriteAllBytes( encoding.GetBytes( text ) );
} }
/// <summary>
/// Opens a stream used to read from this file.
/// </summary>
/// <returns></returns>
public Stream OpenRead() public Stream OpenRead()
{ {
return new MemoryStream( ReadAllBytes(), false ); return new MemoryStream( ReadAllBytes(), false );
} }
/// <summary>
/// Reads the entire contents of the file as a byte array.
/// </summary>
public unsafe byte[] ReadAllBytes() public unsafe byte[] ReadAllBytes()
{ {
if ( _isUgc ) if ( _isUgc )
@ -212,13 +258,24 @@ public unsafe byte[] ReadAllBytes()
return buffer; return buffer;
} }
/// <summary>
/// Reads the entire contents of the file as a string.
/// </summary>
public string ReadAllText( Encoding encoding = null ) public string ReadAllText( Encoding encoding = null )
{ {
if ( encoding == null ) encoding = Encoding.UTF8; if ( encoding == null ) encoding = Encoding.UTF8;
return encoding.GetString( ReadAllBytes() ); return encoding.GetString( ReadAllBytes() );
} }
/// <summary>
/// Callback invoked by <see cref="RemoteFile.Share"/> when file sharing is complete.
/// </summary>
public delegate void ShareCallback( bool success ); public delegate void ShareCallback( bool success );
/// <summary>
/// Attempt to publish this file for other users to download.
/// </summary>
/// <returns>True if we have started attempting to share</returns>
public bool Share( ShareCallback callback = null ) public bool Share( ShareCallback callback = null )
{ {
if ( _isUgc ) return false; if ( _isUgc ) return false;
@ -240,6 +297,10 @@ public bool Share( ShareCallback callback = null )
return true; return true;
} }
/// <summary>
/// Delete this file from remote storage.
/// </summary>
/// <returns>True if the file could be deleted</returns>
public bool Delete() public bool Delete()
{ {
if ( !Exists ) return false; if ( !Exists ) return false;
@ -303,11 +364,17 @@ public bool IsCloudEnabledForApp
get { return native.IsCloudEnabledForApp(); } get { return native.IsCloudEnabledForApp(); }
} }
/// <summary>
/// Gets the total number of files in the current user's remote storage for the current game.
/// </summary>
public int FileCount public int FileCount
{ {
get { return native.GetFileCount(); } get { return native.GetFileCount(); }
} }
/// <summary>
/// Gets all files in the current user's remote storage for the current game.
/// </summary>
public IEnumerable<RemoteFile> Files public IEnumerable<RemoteFile> Files
{ {
get get
@ -317,6 +384,10 @@ public IEnumerable<RemoteFile> Files
} }
} }
/// <summary>
/// Creates a new <see cref="RemoteFile"/> with the given <paramref name="path"/>.
/// If a file exists at that path it will be overwritten.
/// </summary>
public RemoteFile CreateFile( string path ) public RemoteFile CreateFile( string path )
{ {
path = NormalizePath( path ); path = NormalizePath( path );
@ -377,6 +448,9 @@ private void UpdateFiles()
} }
} }
/// <summary>
/// Gets whether a file exists in remote storage at the given <paramref name="path"/>.
/// </summary>
public bool FileExists( string path ) public bool FileExists( string path )
{ {
return native.FileExists( path ); return native.FileExists( path );