mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 06:05:46 +03:00
Ugc.Item change
This commit is contained in:
parent
39705d5a2a
commit
4625e22a55
@ -89,6 +89,7 @@
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="UgcTest.cs" />
|
||||
<Compile Include="UgcEditor.cs" />
|
||||
<Compile Include="UserTest.cs" />
|
||||
<Compile Include="UserStatsTest.cs" />
|
||||
|
37
Facepunch.Steamworks.Test/UgcTest.cs
Normal file
37
Facepunch.Steamworks.Test/UgcTest.cs
Normal file
@ -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}" );
|
||||
}
|
||||
}
|
||||
}
|
@ -33,5 +33,10 @@ public static async Task<bool> 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 );
|
||||
}
|
||||
}
|
||||
}
|
78
Facepunch.Steamworks/Structs/UgcItem.cs
Normal file
78
Facepunch.Steamworks/Structs/UgcItem.cs
Normal file
@ -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<Item?> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A case insensitive check for tag
|
||||
/// </summary>
|
||||
public bool HasTag( string find )
|
||||
{
|
||||
if ( Tags.Length == 0 ) return false;
|
||||
|
||||
return Tags.Contains( find, StringComparer.OrdinalIgnoreCase );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A case insensitive check for tag
|
||||
/// </summary>
|
||||
public bool HasTag( string find )
|
||||
{
|
||||
if ( Tags.Length == 0 ) return false;
|
||||
|
||||
return Tags.Contains( find, StringComparer.OrdinalIgnoreCase );
|
||||
}
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ public struct ResultPage : System.IDisposable
|
||||
|
||||
public bool CachedData;
|
||||
|
||||
public IEnumerable<Result> Entries
|
||||
public IEnumerable<Item> Entries
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -21,7 +21,7 @@ public IEnumerable<Result> Entries
|
||||
{
|
||||
if ( SteamUGC.Internal.GetQueryUGCResult( Handle, i, ref details ) )
|
||||
{
|
||||
yield return Result.From( details, Handle );
|
||||
yield return Item.From( details );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user