diff --git a/Facepunch.Steamworks.Test/Client/WorkshopTest.cs b/Facepunch.Steamworks.Test/Client/WorkshopTest.cs index 6107a0c..7794a20 100644 --- a/Facepunch.Steamworks.Test/Client/WorkshopTest.cs +++ b/Facepunch.Steamworks.Test/Client/WorkshopTest.cs @@ -433,6 +433,21 @@ public void CreatePublish() item.Tags.Add( "Apple" ); item.Tags.Add( "Banana" ); + // Make a folder + var testFolder = new System.IO.DirectoryInfo("BlahBlah"); + if (!testFolder.Exists) testFolder.Create(); + + item.Folder = testFolder.FullName; + + // Upload a file of random bytes + var rand = new Random(); + var testFile = new byte[1024 * 1024 * 32]; + rand.NextBytes(testFile); + System.IO.File.WriteAllBytes( testFolder.FullName + "/testfile1.bin", testFile); + + + Console.WriteLine(item.Folder); + try { item.Publish(); @@ -440,7 +455,11 @@ public void CreatePublish() while ( item.Publishing ) { client.Update(); - Thread.Sleep( 100 ); + Thread.Sleep( 10 ); + + Console.WriteLine("Progress: " + item.Progress); + Console.WriteLine("BytesUploaded: " + item.BytesUploaded); + Console.WriteLine("BytesTotal: " + item.BytesTotal); } Assert.IsFalse( item.Publishing ); @@ -469,6 +488,8 @@ public void CreatePublish() { Console.WriteLine( "Deleting: {0}", item.Id ); item.Delete(); + + System.IO.File.Delete(testFolder.FullName + "/testfile.bin"); } } } diff --git a/Facepunch.Steamworks/Interfaces/Workshop.Editor.cs b/Facepunch.Steamworks/Interfaces/Workshop.Editor.cs index e57d2fa..15b0d4d 100644 --- a/Facepunch.Steamworks/Interfaces/Workshop.Editor.cs +++ b/Facepunch.Steamworks/Interfaces/Workshop.Editor.cs @@ -43,56 +43,54 @@ public double Progress { get { - if ( !Publishing ) return 1.0; - if ( CreateItem != null ) return 0.0; - if ( SubmitItemUpdate == null ) return 1.0; + var bt = BytesTotal; + if (bt == 0) return 0; - ulong b = 0; - ulong t = 0; - - workshop.steamworks.native.ugc.GetItemUpdateProgress( UpdateHandle, out b, out t ); - - if ( t == 0 ) - return 0; - - return (double)b / (double) t; + return (double)BytesUploaded / (double)bt; } } + private int bytesUploaded = 0; + public int BytesUploaded { get { - if ( !Publishing ) return 0; - if ( CreateItem != null ) return 0; - if ( SubmitItemUpdate == null ) return 0; + if ( !Publishing ) return bytesUploaded; + if (UpdateHandle == 0) return bytesUploaded; ulong b = 0; ulong t = 0; workshop.steamworks.native.ugc.GetItemUpdateProgress( UpdateHandle, out b, out t ); - return (int) b; + bytesUploaded = Math.Max( bytesUploaded, (int) b ); + return (int)bytesUploaded; } } + private int bytesTotal = 0; + public int BytesTotal { get { - if ( !Publishing ) return 0; - if ( CreateItem != null ) return 0; - if ( SubmitItemUpdate == null ) return 0; + if ( !Publishing ) return bytesTotal; + if (UpdateHandle == 0 ) return bytesTotal; ulong b = 0; ulong t = 0; workshop.steamworks.native.ugc.GetItemUpdateProgress( UpdateHandle, out b, out t ); - return (int)t; + bytesTotal = Math.Max(bytesTotal, (int)t); + return (int)bytesTotal; } } public void Publish() { + bytesUploaded = 0; + bytesTotal = 0; + Publishing = true; Error = null; @@ -117,6 +115,7 @@ private void OnItemCreated( SteamNative.CreateItemResult_t obj, bool Failed ) { NeedToAgreeToWorkshopLegal = obj.UserNeedsToAcceptWorkshopLegalAgreement; CreateItem.Dispose(); + CreateItem = null; if ( obj.Result == SteamNative.Result.OK && !Failed ) { @@ -188,6 +187,7 @@ private void OnChangesSubmitted( SteamNative.SubmitItemUpdateResult_t obj, bool if ( Failed ) throw new System.Exception( "CreateItemResult_t Failed" ); + UpdateHandle = 0; SubmitItemUpdate = null; NeedToAgreeToWorkshopLegal = obj.UserNeedsToAcceptWorkshopLegalAgreement; Publishing = false;