diff --git a/Facepunch.Steamworks.Test/Client/Workshop.cs b/Facepunch.Steamworks.Test/Client/Workshop.cs index 0b45c10..b1b6eb4 100644 --- a/Facepunch.Steamworks.Test/Client/Workshop.cs +++ b/Facepunch.Steamworks.Test/Client/Workshop.cs @@ -129,5 +129,63 @@ namespace Facepunch.Steamworks.Test } } + [TestMethod] + public void QueryFile() + { + using ( var client = new Facepunch.Steamworks.Client( 252490 ) ) + { + Assert.IsTrue( client.IsValid ); + + using ( var Query = client.Workshop.CreateQuery() ) + { + Query.FileId.Add( 751993251 ); + Query.Run(); + + Assert.IsTrue( Query.IsRunning ); + + Query.Block(); + + Assert.IsFalse( Query.IsRunning ); + Assert.AreEqual( Query.TotalResults, 1 ); + Assert.AreEqual( Query.Items.Length, 1 ); + + Console.WriteLine( "Query.TotalResults: {0}", Query.TotalResults ); + Console.WriteLine( "Query.Items.Length: {0}", Query.Items.Length ); + + Assert.AreEqual( Query.Items[0].Id, 751993251 ); + } + } + } + + [TestMethod] + public void QueryFiles() + { + using ( var client = new Facepunch.Steamworks.Client( 252490 ) ) + { + Assert.IsTrue( client.IsValid ); + + using ( var Query = client.Workshop.CreateQuery() ) + { + Query.FileId.Add( 751993251 ); + Query.FileId.Add( 747266909 ); + Query.Run(); + + Assert.IsTrue( Query.IsRunning ); + + Query.Block(); + + Assert.IsFalse( Query.IsRunning ); + Assert.AreEqual( Query.TotalResults, 2 ); + Assert.AreEqual( Query.Items.Length, 2 ); + + Console.WriteLine( "Query.TotalResults: {0}", Query.TotalResults ); + Console.WriteLine( "Query.Items.Length: {0}", Query.Items.Length ); + + Assert.IsTrue( Query.Items.Any( x => x.Id == 751993251 ) ); + Assert.IsTrue( Query.Items.Any( x => x.Id == 747266909 ) ); + } + } + } + } } diff --git a/Facepunch.Steamworks/Interfaces/Workshop.cs b/Facepunch.Steamworks/Interfaces/Workshop.cs index d90b4e7..753ddbd 100644 --- a/Facepunch.Steamworks/Interfaces/Workshop.cs +++ b/Facepunch.Steamworks/Interfaces/Workshop.cs @@ -128,7 +128,7 @@ namespace Facepunch.Steamworks public int Page { get; set; } = 1; internal Workshop workshop; - public void Run() + public unsafe void Run() { if ( Callback != null ) return; @@ -136,7 +136,21 @@ namespace Facepunch.Steamworks if ( Page <= 0 ) throw new System.Exception( "Page should be 1 or above" ); - Handle = workshop.ugc.CreateQueryAllUGCRequest( (uint)Order, (uint)QueryType, UploaderAppId, AppId,( uint)Page ); + if ( FileId.Count != 0 ) + { + var fileArray = FileId.ToArray(); + + fixed ( ulong* array = fileArray ) + { + Handle = workshop.ugc.CreateQueryUGCDetailsRequest( (IntPtr) array, (uint)fileArray.Length ); + } + } + else + { + Handle = workshop.ugc.CreateQueryAllUGCRequest( (uint)Order, (uint)QueryType, UploaderAppId, AppId, (uint)Page ); + } + + if ( !string.IsNullOrEmpty( SearchText ) ) workshop.ugc.SetSearchText( Handle, SearchText ); @@ -195,6 +209,11 @@ namespace Facepunch.Steamworks /// public List ExcludeTags { get; set; } = new List(); + /// + /// If you're querying for a particular file or files, add them to this. + /// + public List FileId { get; set; } = new List(); + /// /// Don't call this in production! /// diff --git a/Facepunch.Steamworks/Interop/steam_api_interop.cs b/Facepunch.Steamworks/Interop/steam_api_interop.cs index c8e6f9b..a0022f8 100644 --- a/Facepunch.Steamworks/Interop/steam_api_interop.cs +++ b/Facepunch.Steamworks/Interop/steam_api_interop.cs @@ -976,7 +976,7 @@ namespace Valve.Interop [DllImportAttribute( Config.LibraryName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SteamAPI_ISteamUGC_CreateQueryAllUGCRequest" )] internal static extern ulong SteamAPI_ISteamUGC_CreateQueryAllUGCRequest( IntPtr instancePtr, uint eQueryType, uint eMatchingeMatchingUGCTypeFileType, uint nCreatorAppID, uint nConsumerAppID, uint unPage ); [DllImportAttribute( Config.LibraryName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SteamAPI_ISteamUGC_CreateQueryUGCDetailsRequest" )] - internal static extern ulong SteamAPI_ISteamUGC_CreateQueryUGCDetailsRequest( IntPtr instancePtr, ref ulong pvecPublishedFileID, uint unNumPublishedFileIDs ); + internal static unsafe extern ulong SteamAPI_ISteamUGC_CreateQueryUGCDetailsRequest( IntPtr instancePtr, IntPtr pvecPublishedFileID, uint unNumPublishedFileIDs ); [DllImportAttribute( Config.LibraryName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SteamAPI_ISteamUGC_SendQueryUGCRequest" )] internal static extern ulong SteamAPI_ISteamUGC_SendQueryUGCRequest( IntPtr instancePtr, ulong handle ); [DllImportAttribute( Config.LibraryName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SteamAPI_ISteamUGC_GetQueryUGCResult" )] @@ -2173,7 +2173,7 @@ namespace Valve.Steamworks internal abstract IntPtr GetIntPtr(); internal abstract ulong CreateQueryUserUGCRequest( uint unAccountID, uint eListType, uint eMatchingUGCType, uint eSortOrder, uint nCreatorAppID, uint nConsumerAppID, uint unPage ); internal abstract ulong CreateQueryAllUGCRequest( uint eQueryType, uint eMatchingeMatchingUGCTypeFileType, uint nCreatorAppID, uint nConsumerAppID, uint unPage ); - internal abstract ulong CreateQueryUGCDetailsRequest( ref ulong pvecPublishedFileID, uint unNumPublishedFileIDs ); + internal abstract ulong CreateQueryUGCDetailsRequest( IntPtr pvecPublishedFileID, uint unNumPublishedFileIDs ); internal abstract ulong SendQueryUGCRequest( ulong handle ); internal abstract bool GetQueryUGCResult( ulong handle, uint index, ref SteamUGCDetails_t pDetails ); internal abstract bool GetQueryUGCPreviewURL( ulong handle, uint index, out string pchURL ); @@ -5631,11 +5631,10 @@ namespace Valve.Steamworks ulong result = NativeEntrypoints.SteamAPI_ISteamUGC_CreateQueryAllUGCRequest(m_pSteamUGC,eQueryType,eMatchingeMatchingUGCTypeFileType,nCreatorAppID,nConsumerAppID,unPage); return result; } - internal override ulong CreateQueryUGCDetailsRequest( ref ulong pvecPublishedFileID, uint unNumPublishedFileIDs ) + internal override ulong CreateQueryUGCDetailsRequest( IntPtr pvecPublishedFileID, uint unNumPublishedFileIDs ) { CheckIfUsable(); - pvecPublishedFileID = 0; - ulong result = NativeEntrypoints.SteamAPI_ISteamUGC_CreateQueryUGCDetailsRequest(m_pSteamUGC,ref pvecPublishedFileID,unNumPublishedFileIDs); + ulong result = NativeEntrypoints.SteamAPI_ISteamUGC_CreateQueryUGCDetailsRequest(m_pSteamUGC, pvecPublishedFileID,unNumPublishedFileIDs); return result; } internal override ulong SendQueryUGCRequest( ulong handle )