mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-02-04 17:50:43 +03:00
Fixed ugc validation/redownload
This commit is contained in:
parent
22e963250e
commit
d42996142f
@ -44,6 +44,7 @@ namespace Steamworks
|
|||||||
SteamParties.InstallEvents();
|
SteamParties.InstallEvents();
|
||||||
SteamNetworkingSockets.InstallEvents();
|
SteamNetworkingSockets.InstallEvents();
|
||||||
SteamInput.InstallEvents();
|
SteamInput.InstallEvents();
|
||||||
|
SteamUGC.InstallEvents();
|
||||||
|
|
||||||
if ( asyncCallbacks )
|
if ( asyncCallbacks )
|
||||||
{
|
{
|
||||||
|
@ -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 static void Shutdown()
|
||||||
{
|
{
|
||||||
_internal = null;
|
_internal = null;
|
||||||
|
@ -198,7 +198,9 @@ namespace Steamworks.Ugc
|
|||||||
{
|
{
|
||||||
get
|
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 downloaded = 0;
|
||||||
ulong total = 0;
|
ulong total = 0;
|
||||||
@ -266,26 +268,66 @@ namespace Steamworks.Ugc
|
|||||||
ct = new CancellationTokenSource( TimeSpan.FromSeconds( 60 ) ).Token;
|
ct = new CancellationTokenSource( TimeSpan.FromSeconds( 60 ) ).Token;
|
||||||
|
|
||||||
progress?.Invoke( 0 );
|
progress?.Invoke( 0 );
|
||||||
|
await Task.Delay( milisecondsUpdateDelay );
|
||||||
|
|
||||||
var subResult = await SteamUGC.Internal.SubscribeItem( _id );
|
//Subscribe
|
||||||
if ( subResult?.Result != Result.OK )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
var downloading = Download( true );
|
|
||||||
if ( !downloading )
|
|
||||||
return State.HasFlag( ItemState.Installed );
|
|
||||||
|
|
||||||
while ( true )
|
|
||||||
{
|
{
|
||||||
if ( ct.IsCancellationRequested )
|
var subResult = await SteamUGC.Internal.SubscribeItem( _id );
|
||||||
break;
|
if ( subResult?.Result != Result.OK )
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
progress?.Invoke( DownloadAmount );
|
progress?.Invoke( 0.1f );
|
||||||
|
await Task.Delay( milisecondsUpdateDelay );
|
||||||
|
|
||||||
if ( !IsDownloading && State.HasFlag( ItemState.Installed ) )
|
//Try to start downloading
|
||||||
break;
|
{
|
||||||
|
if ( Download( true ) == false )
|
||||||
|
return State.HasFlag( ItemState.Installed );
|
||||||
|
|
||||||
await Task.Delay( milisecondsUpdateDelay );
|
//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( 0.2f + DownloadAmount * 0.8f );
|
||||||
|
|
||||||
|
if ( !IsDownloading && State.HasFlag( ItemState.Installed ) )
|
||||||
|
break;
|
||||||
|
|
||||||
|
await Task.Delay( milisecondsUpdateDelay );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return State.HasFlag( ItemState.Installed );
|
return State.HasFlag( ItemState.Installed );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user