Facepunch.Steamworks/Facepunch.Steamworks/SteamUgc.cs

87 lines
2.1 KiB
C#
Raw Normal View History

2019-04-17 18:41:06 +03:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Steamworks.Data;
namespace Steamworks
{
/// <summary>
/// Functions for accessing and manipulating Steam user information.
/// This is also where the APIs for Steam Voice are exposed.
/// </summary>
public static class SteamUGC
{
static ISteamUGC _internal;
internal static ISteamUGC Internal
{
get
{
if ( _internal == null )
{
_internal = new ISteamUGC();
2019-05-06 23:19:00 +03:00
_internal.Init();
2019-04-17 18:41:06 +03:00
}
return _internal;
}
}
2019-04-29 14:55:38 +03:00
internal static void Shutdown()
{
_internal = null;
}
2019-04-26 16:54:47 +03:00
public static async Task<bool> DeleteFileAsync( PublishedFileId fileId )
{
var r = await Internal.DeleteItem( fileId );
return r?.Result == Result.OK;
}
2019-04-26 18:42:46 +03:00
public static bool Download( PublishedFileId fileId, bool highPriority = false )
{
return Internal.DownloadItem( fileId, highPriority );
}
2019-05-08 11:40:28 +03:00
/// <summary>
/// Utility function to fetch a single item. Internally this uses Ugc.FileQuery -
/// which you can use to query multiple items if you need to.
/// </summary>
2019-05-08 13:18:56 +03:00
public static async Task<Ugc.Item?> QueryFileAsync( PublishedFileId fileId )
2019-05-08 11:40:28 +03:00
{
var result = await Ugc.Query.All
.WithFileId( fileId )
2019-05-08 11:40:28 +03:00
.GetPageAsync( 1 );
if ( !result.HasValue || result.Value.ResultCount != 1 )
return null;
var item = result.Value.Entries.First();
result.Value.Dispose();
return item;
}
public static async Task<bool> StartPlaytimeTracking(PublishedFileId fileId)
{
var result = await Internal.StartPlaytimeTracking(new[] {fileId}, 1);
return result.Value.Result == Result.OK;
}
public static async Task<bool> StopPlaytimeTracking(PublishedFileId fileId)
{
var result = await Internal.StopPlaytimeTracking(new[] {fileId}, 1);
return result.Value.Result == Result.OK;
}
public static async Task<bool> StopPlaytimeTrackingForAllItems()
{
var result = await Internal.StopPlaytimeTrackingForAllItems();
return result.Value.Result == Result.OK;
}
2019-04-17 18:41:06 +03:00
}
}