From 435a9fd92d3291943053377e761f7457b15c9ac7 Mon Sep 17 00:00:00 2001 From: James King Date: Tue, 30 Aug 2022 14:40:00 +0100 Subject: [PATCH] Support for RemoteStorageLocalFileChange_t --- Facepunch.Steamworks/Generated/SteamEnums.cs | 16 ++++++- Facepunch.Steamworks/SteamRemoteStorage.cs | 48 +++++++++++++++++++ .../Structs/LocalFileChange.cs | 19 ++++++++ 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 Facepunch.Steamworks/Structs/LocalFileChange.cs diff --git a/Facepunch.Steamworks/Generated/SteamEnums.cs b/Facepunch.Steamworks/Generated/SteamEnums.cs index 4c3246b..2e0d13a 100644 --- a/Facepunch.Steamworks/Generated/SteamEnums.cs +++ b/Facepunch.Steamworks/Generated/SteamEnums.cs @@ -818,7 +818,7 @@ namespace Steamworks // // ERemoteStorageLocalFileChange // - internal enum RemoteStorageLocalFileChange : int + public enum RemoteStorageLocalFileChange : int { Invalid = 0, FileUpdated = 1, @@ -828,10 +828,22 @@ namespace Steamworks // // ERemoteStorageFilePathType // - internal enum RemoteStorageFilePathType : int + public enum RemoteStorageFilePathType : int { + /// + /// Unused. + /// Invalid = 0, + + /// + /// An absolute disk path is provided. This type of path is used for files managed via AutoCloud. + /// Absolute = 1, + + /// + /// An ISteamRemoteStorage API relative path is provided. This type of path is used for files + /// managed via the ISteamRemoteStorage API methods (FileWrite, FileRead, etc). + /// APIFilename = 2, } diff --git a/Facepunch.Steamworks/SteamRemoteStorage.cs b/Facepunch.Steamworks/SteamRemoteStorage.cs index b189861..533cca8 100644 --- a/Facepunch.Steamworks/SteamRemoteStorage.cs +++ b/Facepunch.Steamworks/SteamRemoteStorage.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; @@ -17,8 +18,34 @@ namespace Steamworks internal override void InitializeInterface( bool server ) { SetInterface( server, new ISteamRemoteStorage( server ) ); + InstallEvents( server ); } + internal static void InstallEvents( bool server ) + { + Dispatch.Install( x => + { + var count = Internal.GetLocalFileChangeCount(); + var files = new LocalFileChange[count]; + + for ( var i = 0; i < count; i++ ) + { + RemoteStorageLocalFileChange changeType = default; + RemoteStorageFilePathType filePathType = default; + + var filename = Internal.GetLocalFileChange( i, ref changeType, ref filePathType ); + + files[i] = new LocalFileChange( filename, changeType, filePathType ); + } + + OnLocalFileChange?.Invoke( files ); + }, server ); + } + + /// + /// If a Steam app is flagged for supporting dynamic Steam Cloud sync, and a sync occurs, this callback will be posted to the app if any local files changed. + /// + public static event Action OnLocalFileChange; /// /// Creates a new file, writes the bytes to the file, and then closes the file. @@ -177,6 +204,27 @@ namespace Steamworks } } + public static IDisposable FileWriteBatch() + { + Internal.BeginFileWriteBatch(); + + return new FileWriteBatchDisposable(); + } + + private sealed class FileWriteBatchDisposable : IDisposable + { + private bool _disposed; + + public void Dispose() + { + if ( _disposed ) return; + + _disposed = true; + + Internal.EndFileWriteBatch(); + } + } + public static async Task LegacyDownloadSharedFile( PublishedFileId fileId, uint priority = 1000 ) { var result = await Internal.UGCDownload( fileId.Value, priority ); diff --git a/Facepunch.Steamworks/Structs/LocalFileChange.cs b/Facepunch.Steamworks/Structs/LocalFileChange.cs new file mode 100644 index 0000000..f97ae71 --- /dev/null +++ b/Facepunch.Steamworks/Structs/LocalFileChange.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Steamworks +{ + /// + /// References a Remote Storage file that was externally changed + /// during the lifetime of the application. + /// See . + /// + /// Name of the changed file, of type + /// What happened to this file + /// Type of path to the file + public record struct LocalFileChange( + string Filename, + RemoteStorageLocalFileChange ChangeType, + RemoteStorageFilePathType PathType ); +}