Progress - will do for now

This commit is contained in:
Garry Newman 2019-04-26 15:40:27 +01:00
parent e275b209b3
commit 39705d5a2a
2 changed files with 70 additions and 9 deletions

View File

@ -30,10 +30,23 @@ public async Task CreateFile()
}
class ProgressBar : IProgress<float>
{
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 );

View File

@ -52,10 +52,12 @@ internal Editor( WorkshopFileType filetype ) : this()
public Editor WithContent( string folderName ) { return WithContent( new System.IO.DirectoryInfo( folderName ) ); }
public async Task<PublishResult> SubmitAsync()
public async Task<PublishResult> SubmitAsync( IProgress<float> progress = null )
{
var result = default( PublishResult );
progress?.Report( 0 );
//
// Item Create
//
@ -77,10 +79,9 @@ public async Task<PublishResult> 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<PublishResult> 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;