From 4625e22a55165c314495f23e17eac183b6324e1e Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Fri, 26 Apr 2019 16:42:46 +0100 Subject: [PATCH] Ugc.Item change --- .../Facepunch.Steamworks.Test.csproj | 1 + Facepunch.Steamworks.Test/UgcTest.cs | 37 +++++++++ Facepunch.Steamworks/SteamUgc.cs | 5 ++ Facepunch.Steamworks/Structs/UgcItem.cs | 78 +++++++++++++++++++ Facepunch.Steamworks/Structs/UgcResult.cs | 69 ---------------- Facepunch.Steamworks/Structs/UgcResultPage.cs | 4 +- 6 files changed, 123 insertions(+), 71 deletions(-) create mode 100644 Facepunch.Steamworks.Test/UgcTest.cs create mode 100644 Facepunch.Steamworks/Structs/UgcItem.cs delete mode 100644 Facepunch.Steamworks/Structs/UgcResult.cs diff --git a/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj b/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj index 6b37a7a..f91329f 100644 --- a/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj +++ b/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj @@ -89,6 +89,7 @@ + diff --git a/Facepunch.Steamworks.Test/UgcTest.cs b/Facepunch.Steamworks.Test/UgcTest.cs new file mode 100644 index 0000000..65e1d18 --- /dev/null +++ b/Facepunch.Steamworks.Test/UgcTest.cs @@ -0,0 +1,37 @@ +using System; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Steamworks.Data; + +namespace Steamworks +{ + [TestClass] + [DeploymentItem( "steam_api64.dll" )] + public class UgcTest + { + [TestMethod] + public async Task Download() + { + SteamUGC.Download( 1717844711 ); + } + + [TestMethod] + public async Task GetInformation() + { + var itemInfo = await Ugc.Item.Get( 1720164672 ); + + Assert.IsTrue( itemInfo.HasValue ); + + Console.WriteLine( $"Title: {itemInfo?.Title}" ); + Console.WriteLine( $"IsInstalled: {itemInfo?.IsInstalled}" ); + Console.WriteLine( $"IsDownloading: {itemInfo?.IsDownloading}" ); + Console.WriteLine( $"IsDownloadPending: {itemInfo?.IsDownloadPending}" ); + Console.WriteLine( $"IsSubscribed: {itemInfo?.IsSubscribed}" ); + Console.WriteLine( $"NeedsUpdate: {itemInfo?.NeedsUpdate}" ); + Console.WriteLine( $"Description: {itemInfo?.Description}" ); + } + } +} diff --git a/Facepunch.Steamworks/SteamUgc.cs b/Facepunch.Steamworks/SteamUgc.cs index b9caf9f..5484eeb 100644 --- a/Facepunch.Steamworks/SteamUgc.cs +++ b/Facepunch.Steamworks/SteamUgc.cs @@ -33,5 +33,10 @@ public static async Task DeleteFileAsync( PublishedFileId fileId ) var r = await Internal.DeleteItem( fileId ); return r?.Result == Result.OK; } + + public static bool Download( PublishedFileId fileId, bool highPriority = false ) + { + return Internal.DownloadItem( fileId, highPriority ); + } } } \ No newline at end of file diff --git a/Facepunch.Steamworks/Structs/UgcItem.cs b/Facepunch.Steamworks/Structs/UgcItem.cs new file mode 100644 index 0000000..857eb33 --- /dev/null +++ b/Facepunch.Steamworks/Structs/UgcItem.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Steamworks.Data; + +using QueryType = Steamworks.Ugc.Query; + +namespace Steamworks.Ugc +{ + public struct Item + { + internal enum ItemState : int + { + None = 0, + Subscribed = 1, + LegacyItem = 2, + Installed = 4, + NeedsUpdate = 8, + Downloading = 16, + DownloadPending = 32, + } + + public PublishedFileId Id { get; internal set; } + + public string Title { get; internal set; } + public string Description { get; internal set; } + public string[] Tags { get; internal set; } + + public bool IsInstalled => (State & ItemState.Installed) == ItemState.Installed; + public bool IsDownloading => (State & ItemState.Downloading) == ItemState.Downloading; + public bool IsDownloadPending => (State & ItemState.DownloadPending) == ItemState.DownloadPending; + public bool IsSubscribed => (State & ItemState.Subscribed) == ItemState.Subscribed; + public bool NeedsUpdate => (State & ItemState.NeedsUpdate) == ItemState.NeedsUpdate; + + public bool Download( bool highPriority = false ) + { + return SteamUGC.Internal.DownloadItem( Id, highPriority ); + } + + private ItemState State => (ItemState) SteamUGC.Internal.GetItemState( Id ); + + public static async Task Get( PublishedFileId id, int maxageseconds = 60 * 30 ) + { + var result = await SteamUGC.Internal.RequestUGCDetails( id, (uint) maxageseconds ); + if ( !result.HasValue ) return null; + + return From( result.Value.Details ); + } + + internal static Item From( SteamUGCDetails_t details ) + { + var d = new Item + { + Id = details.PublishedFileId, + // FileType = details.FileType, + + Title = details.Title, + Description = details.Description, + Tags = details.Tags.Split( new[] { ',' }, StringSplitOptions.RemoveEmptyEntries ) + + }; + + return d; + } + + /// + /// A case insensitive check for tag + /// + public bool HasTag( string find ) + { + if ( Tags.Length == 0 ) return false; + + return Tags.Contains( find, StringComparer.OrdinalIgnoreCase ); + } + + } +} \ No newline at end of file diff --git a/Facepunch.Steamworks/Structs/UgcResult.cs b/Facepunch.Steamworks/Structs/UgcResult.cs deleted file mode 100644 index faf4815..0000000 --- a/Facepunch.Steamworks/Structs/UgcResult.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Linq; -using Steamworks.Data; - -namespace Steamworks.Ugc -{ - public struct Result - { - public PublishedFileId Id; - - public string Title; - public string Description; - public string[] Tags; - - - // - // TODO; - // - //internal Steamworks.Result Result; // m_eResult enum EResult - internal WorkshopFileType FileType; // m_eFileType enum EWorkshopFileType - internal uint CreatorAppID; // m_nCreatorAppID AppId_t - internal uint ConsumerAppID; // m_nConsumerAppID AppId_t - - internal ulong SteamIDOwner; // m_ulSteamIDOwner uint64 - internal uint TimeCreated; // m_rtimeCreated uint32 - internal uint TimeUpdated; // m_rtimeUpdated uint32 - internal uint TimeAddedToUserList; // m_rtimeAddedToUserList uint32 - internal RemoteStoragePublishedFileVisibility Visibility; // m_eVisibility enum ERemoteStoragePublishedFileVisibility - internal bool Banned; // m_bBanned _Bool - internal bool AcceptedForUse; // m_bAcceptedForUse _Bool - internal bool TagsTruncated; // m_bTagsTruncated _Bool - internal ulong File; // m_hFile UGCHandle_t - internal ulong PreviewFile; // m_hPreviewFile UGCHandle_t - internal string PchFileName; // m_pchFileName char [260] - internal int FileSize; // m_nFileSize int32 - internal int PreviewFileSize; // m_nPreviewFileSize int32 - internal string URL; // m_rgchURL char [256] - internal uint VotesUp; // m_unVotesUp uint32 - internal uint VotesDown; // m_unVotesDown uint32 - internal float Score; // m_flScore float - internal uint NumChildren; // m_unNumChildren uint32 - - internal static Result From( SteamUGCDetails_t details, UGCQueryHandle_t handle ) - { - var d = new Result - { - Id = details.PublishedFileId, - FileType = details.FileType, - - Title = details.Title, - Description = details.Description, - Tags = details.Tags.Split( new[] { ',' }, StringSplitOptions.RemoveEmptyEntries ) - - }; - - return d; - } - - /// - /// A case insensitive check for tag - /// - public bool HasTag( string find ) - { - if ( Tags.Length == 0 ) return false; - - return Tags.Contains( find, StringComparer.OrdinalIgnoreCase ); - } - } -} \ No newline at end of file diff --git a/Facepunch.Steamworks/Structs/UgcResultPage.cs b/Facepunch.Steamworks/Structs/UgcResultPage.cs index eec1b31..06f4f5f 100644 --- a/Facepunch.Steamworks/Structs/UgcResultPage.cs +++ b/Facepunch.Steamworks/Structs/UgcResultPage.cs @@ -12,7 +12,7 @@ public struct ResultPage : System.IDisposable public bool CachedData; - public IEnumerable Entries + public IEnumerable Entries { get { @@ -21,7 +21,7 @@ public IEnumerable Entries { if ( SteamUGC.Internal.GetQueryUGCResult( Handle, i, ref details ) ) { - yield return Result.From( details, Handle ); + yield return Item.From( details ); } } }