diff --git a/Facepunch.Steamworks/Client/Leaderboard.cs b/Facepunch.Steamworks/Client/Leaderboard.cs index 18e45a0..6ac402b 100644 --- a/Facepunch.Steamworks/Client/Leaderboard.cs +++ b/Facepunch.Steamworks/Client/Leaderboard.cs @@ -161,10 +161,20 @@ namespace Facepunch.Steamworks return true; } + /// + /// Callback invoked by when file attachment is complete. + /// public delegate void AttachRemoteFileCallback( bool success ); + /// + /// Attempt to attach a file to the current user's leaderboard entry. + /// Can be useful for storing replays along with scores. + /// + /// True if the file attachment process has started public bool AttachRemoteFile( RemoteFile file, AttachRemoteFileCallback callback = null ) { + if ( !IsValid ) return false; + if ( file.IsShared ) { client.native.userstats.AttachLeaderboardUGC( BoardId, file.UGCHandle, ( result, error ) => diff --git a/Facepunch.Steamworks/Client/RemoteStorage.cs b/Facepunch.Steamworks/Client/RemoteStorage.cs index 2a5a19f..e067e23 100644 --- a/Facepunch.Steamworks/Client/RemoteStorage.cs +++ b/Facepunch.Steamworks/Client/RemoteStorage.cs @@ -23,7 +23,10 @@ namespace Facepunch.Steamworks } } - internal class RemoteFileWriteStream : Stream + /// + /// Stream used to write to a . + /// + public class RemoteFileWriteStream : Stream { internal readonly RemoteStorage remoteStorage; @@ -77,6 +80,9 @@ namespace Facepunch.Steamworks public override long Length => _written; public override long Position { get { return _written; } set { throw new NotImplementedException(); } } + /// + /// Close the stream without saving the file to remote storage. + /// public void Cancel() { if ( _closed ) return; @@ -85,7 +91,11 @@ namespace Facepunch.Steamworks remoteStorage.native.FileWriteStreamCancel( _handle ); } +#if NETCORE public void Close() +#else + public override void Close() +#endif { if ( _closed ) return; @@ -102,6 +112,9 @@ namespace Facepunch.Steamworks } } + /// + /// Represents a file stored in a user's Steam Cloud. + /// public class RemoteFile { internal readonly RemoteStorage remoteStorage; @@ -112,11 +125,21 @@ namespace Facepunch.Steamworks private UGCHandle_t _handle; private ulong _ownerId; + /// + /// Check if the file exists. + /// public bool Exists { get; internal set; } + + /// + /// If true, the file is available for other users to download. + /// public bool IsShared { get { return _handle.Value != 0; } } internal UGCHandle_t UGCHandle { get { return _handle; } } + /// + /// Name and path of the file. + /// public string FileName { get @@ -127,6 +150,9 @@ namespace Facepunch.Steamworks } } + /// + /// Steam ID of the file's owner. + /// public ulong OwnerId { get @@ -137,6 +163,9 @@ namespace Facepunch.Steamworks } } + /// + /// Total size of the file in bytes. + /// public int SizeInBytes { get @@ -169,11 +198,18 @@ namespace Facepunch.Steamworks _sizeInBytes = sizeInBytes; } - public Stream OpenWrite() + /// + /// Creates a used to write to this file. + /// + /// + public RemoteFileWriteStream OpenWrite() { return new RemoteFileWriteStream( remoteStorage, this ); } + /// + /// Write a byte array to this file, replacing any existing contents. + /// public void WriteAllBytes( byte[] buffer ) { using ( var stream = OpenWrite() ) @@ -182,17 +218,27 @@ namespace Facepunch.Steamworks } } + /// + /// Write a string to this file, replacing any existing contents. + /// public void WriteAllText( string text, Encoding encoding = null ) { if ( encoding == null ) encoding = Encoding.UTF8; WriteAllBytes( encoding.GetBytes( text ) ); } + /// + /// Opens a stream used to read from this file. + /// + /// public Stream OpenRead() { return new MemoryStream( ReadAllBytes(), false ); } + /// + /// Reads the entire contents of the file as a byte array. + /// public unsafe byte[] ReadAllBytes() { if ( _isUgc ) @@ -212,13 +258,24 @@ namespace Facepunch.Steamworks return buffer; } + /// + /// Reads the entire contents of the file as a string. + /// public string ReadAllText( Encoding encoding = null ) { if ( encoding == null ) encoding = Encoding.UTF8; return encoding.GetString( ReadAllBytes() ); } + /// + /// Callback invoked by when file sharing is complete. + /// public delegate void ShareCallback( bool success ); + + /// + /// Attempt to publish this file for other users to download. + /// + /// True if we have started attempting to share public bool Share( ShareCallback callback = null ) { if ( _isUgc ) return false; @@ -240,6 +297,10 @@ namespace Facepunch.Steamworks return true; } + /// + /// Delete this file from remote storage. + /// + /// True if the file could be deleted public bool Delete() { if ( !Exists ) return false; @@ -303,11 +364,17 @@ namespace Facepunch.Steamworks get { return native.IsCloudEnabledForApp(); } } + /// + /// Gets the total number of files in the current user's remote storage for the current game. + /// public int FileCount { get { return native.GetFileCount(); } } + /// + /// Gets all files in the current user's remote storage for the current game. + /// public IEnumerable Files { get @@ -317,6 +384,10 @@ namespace Facepunch.Steamworks } } + /// + /// Creates a new with the given . + /// If a file exists at that path it will be overwritten. + /// public RemoteFile CreateFile( string path ) { path = NormalizePath( path ); @@ -377,6 +448,9 @@ namespace Facepunch.Steamworks } } + /// + /// Gets whether a file exists in remote storage at the given . + /// public bool FileExists( string path ) { return native.FileExists( path );