diff --git a/Facepunch.Steamworks.Test/UgcEditor.cs b/Facepunch.Steamworks.Test/UgcEditor.cs index 4031a78..1548721 100644 --- a/Facepunch.Steamworks.Test/UgcEditor.cs +++ b/Facepunch.Steamworks.Test/UgcEditor.cs @@ -30,10 +30,23 @@ public async Task CreateFile() } + class ProgressBar : IProgress + { + float Value = 0; + + public void Report( float value ) + { + if ( Value >= value ) return; + + Value = value; + + Console.WriteLine( value ); + } + } + [TestMethod] public async Task UploadBigFile() { - var created = Ugc.Editor.NewCommunityFile .WithTitle( "Unit Test Upload Item" ) .WithDescription( "This item was created by Facepunch Steamworks unit tests.\n\n" + @@ -60,9 +73,7 @@ public async Task UploadBigFile() try { - var done = await created.SubmitAsync(); - - // TODO - Upload Progress + var done = await created.SubmitAsync( new ProgressBar() ); Assert.IsTrue( done.Success ); Console.WriteLine( "item.Id: {0}", done.FileId ); diff --git a/Facepunch.Steamworks/Structs/UgcEditor.cs b/Facepunch.Steamworks/Structs/UgcEditor.cs index fc22829..40c33ac 100644 --- a/Facepunch.Steamworks/Structs/UgcEditor.cs +++ b/Facepunch.Steamworks/Structs/UgcEditor.cs @@ -52,10 +52,12 @@ internal Editor( WorkshopFileType filetype ) : this() public Editor WithContent( string folderName ) { return WithContent( new System.IO.DirectoryInfo( folderName ) ); } - public async Task SubmitAsync() + public async Task SubmitAsync( IProgress progress = null ) { var result = default( PublishResult ); - + + progress?.Report( 0 ); + // // Item Create // @@ -77,10 +79,9 @@ public async Task SubmitAsync() fileId = created.Value.PublishedFileId; result.NeedsWorkshopAgreement = created.Value.UserNeedsToAcceptWorkshopLegalAgreement; result.FileId = fileId; - - await Task.Delay( 500 ); } + result.FileId = fileId; // @@ -99,7 +100,56 @@ public async Task SubmitAsync() result.Result = Steamworks.Result.Fail; - var updated = await SteamUGC.Internal.SubmitItemUpdate( handle, "" ); + var updating = SteamUGC.Internal.SubmitItemUpdate( handle, "" ); + + while ( !updating.IsCompleted ) + { + if ( progress != null ) + { + ulong total = 0; + ulong processed = 0; + + var r = SteamUGC.Internal.GetItemUpdateProgress( handle, ref processed, ref total ); + + switch ( r ) + { + case ItemUpdateStatus.PreparingConfig: + { + progress?.Report( 0.1f ); + break; + } + + case ItemUpdateStatus.PreparingContent: + { + progress?.Report( 0.2f ); + break; + } + case ItemUpdateStatus.UploadingContent: + { + var uploaded = total > 0 ? ((float)processed / (float)total) : 0.0f; + progress?.Report( 0.2f + uploaded * 0.7f ); + break; + } + case ItemUpdateStatus.UploadingPreviewFile: + { + progress?.Report( 8f ); + break; + } + case ItemUpdateStatus.CommittingChanges: + { + progress?.Report( 1 ); + break; + } + } + } + + await Task.Delay( 1000 / 60 ); + } + + progress?.Report( 1 ); + + var updated = updating.Result; + if ( !updated.HasValue ) return result; result.Result = updated.Value.Result;