mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-28 15:45:29 +03:00
Merge pull request #333 from kamyker/ws-download-progress
SubscribeDownloadAsync for workshop item
This commit is contained in:
commit
32fbf63644
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Steamworks.Data;
|
using Steamworks.Data;
|
||||||
|
|
||||||
@ -254,6 +255,42 @@ public async Task<bool> Subscribe ()
|
|||||||
return result?.Result == Result.OK;
|
return result?.Result == Result.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allows the user to subscribe to this item and wait for it to be downloaded
|
||||||
|
/// If CancellationToken is default then there is 60 seconds timeout
|
||||||
|
/// Progress will be set to 0-1
|
||||||
|
/// </summary>
|
||||||
|
public async Task<bool> SubscribeDownloadAsync( Action<float> progress = null, CancellationToken ct = default, int milisecondsUpdateDelay = 60 )
|
||||||
|
{
|
||||||
|
if ( ct == default )
|
||||||
|
ct = new CancellationTokenSource( TimeSpan.FromSeconds( 60 ) ).Token;
|
||||||
|
|
||||||
|
progress?.Invoke( 0 );
|
||||||
|
|
||||||
|
var subResult = await SteamUGC.Internal.SubscribeItem( _id );
|
||||||
|
if ( subResult?.Result != Result.OK )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var downloading = Download( true );
|
||||||
|
if ( !downloading )
|
||||||
|
return State.HasFlag( ItemState.Installed );
|
||||||
|
|
||||||
|
while ( true )
|
||||||
|
{
|
||||||
|
if ( ct.IsCancellationRequested )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
progress?.Invoke( DownloadAmount );
|
||||||
|
|
||||||
|
if ( !IsDownloading )
|
||||||
|
break;
|
||||||
|
|
||||||
|
await Task.Delay( milisecondsUpdateDelay );
|
||||||
|
}
|
||||||
|
|
||||||
|
return State.HasFlag( ItemState.Installed );
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows the user to unsubscribe from this item
|
/// Allows the user to unsubscribe from this item
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user