Merge pull request #353 from kamyker/ugc-dl-validation

Fixed ugc validation/redownload
This commit is contained in:
Garry Newman 2020-01-21 22:30:09 +00:00 committed by GitHub
commit 8dc011964f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 16 deletions

View File

@ -44,6 +44,7 @@ namespace Steamworks
SteamParties.InstallEvents();
SteamNetworkingSockets.InstallEvents();
SteamInput.InstallEvents();
SteamUGC.InstallEvents();
if ( asyncCallbacks )
{

View File

@ -29,6 +29,16 @@ namespace Steamworks
}
}
internal static void InstallEvents()
{
DownloadItemResult_t.Install( x => OnDownloadItemResult?.Invoke( x.Result ) );
}
/// <summary>
/// Posted after Download call
/// </summary>
public static event Action<Result> OnDownloadItemResult;
internal static void Shutdown()
{
_internal = null;

View File

@ -198,7 +198,9 @@ namespace Steamworks.Ugc
{
get
{
if ( !NeedsUpdate ) return 1;
//changed from NeedsUpdate as it's false when validating and redownloading ugc
//possibly similar properties should also be changed
if ( !IsDownloading ) return 1;
ulong downloaded = 0;
ulong total = 0;
@ -266,27 +268,67 @@ namespace Steamworks.Ugc
ct = new CancellationTokenSource( TimeSpan.FromSeconds( 60 ) ).Token;
progress?.Invoke( 0 );
await Task.Delay( milisecondsUpdateDelay );
//Subscribe
{
var subResult = await SteamUGC.Internal.SubscribeItem( _id );
if ( subResult?.Result != Result.OK )
return false;
}
var downloading = Download( true );
if ( !downloading )
progress?.Invoke( 0.1f );
await Task.Delay( milisecondsUpdateDelay );
//Try to start downloading
{
if ( Download( true ) == false )
return State.HasFlag( ItemState.Installed );
//Steam docs about Download:
//If the return value is true then register and wait
//for the Callback DownloadItemResult_t before calling
//GetItemInstallInfo or accessing the workshop item on disk.
//Wait for DownloadItemResult_t
{
var downloadStarted = false;
Action<Result> onDownloadStarted = null;
onDownloadStarted = r =>
{
SteamUGC.OnDownloadItemResult -= onDownloadStarted;
downloadStarted = true;
};
SteamUGC.OnDownloadItemResult += onDownloadStarted;
while ( downloadStarted == false )
{
if ( ct.IsCancellationRequested )
break;
await Task.Delay( milisecondsUpdateDelay );
}
}
}
progress?.Invoke( 0.2f );
await Task.Delay( milisecondsUpdateDelay );
//Wait for downloading completion
{
while ( true )
{
if ( ct.IsCancellationRequested )
break;
progress?.Invoke( DownloadAmount );
progress?.Invoke( 0.2f + DownloadAmount * 0.8f );
if ( !IsDownloading && State.HasFlag( ItemState.Installed ) )
break;
await Task.Delay( milisecondsUpdateDelay );
}
}
return State.HasFlag( ItemState.Installed );
}