Cleanup, native classes disposable

This commit is contained in:
Garry Newman 2016-10-25 16:37:48 +01:00
parent 4b4f405a79
commit c37ea38107
37 changed files with 830 additions and 136 deletions

View File

@ -92,10 +92,100 @@ public void Dispose()
{
if ( client != null )
{
client.Dispose();
client = null;
}
api.SteamAPI_Shutdown();
if ( user != null )
{
user.Dispose();
user = null;
}
if ( utils != null )
{
utils.Dispose();
utils = null;
}
if ( networking != null )
{
networking.Dispose();
networking = null;
}
if ( gameServerStats != null )
{
gameServerStats.Dispose();
gameServerStats = null;
}
if ( http != null )
{
http.Dispose();
http = null;
}
if ( inventory != null )
{
inventory.Dispose();
inventory = null;
}
if ( ugc != null )
{
ugc.Dispose();
ugc = null;
}
if ( apps != null )
{
apps.Dispose();
apps = null;
}
if ( gameServer != null )
{
gameServer.Dispose();
gameServer = null;
}
if ( friends != null )
{
friends.Dispose();
friends = null;
}
if ( servers != null )
{
servers.Dispose();
servers = null;
}
if ( userstats != null )
{
userstats.Dispose();
userstats = null;
}
if ( screenshots != null )
{
screenshots.Dispose();
screenshots = null;
}
if ( remoteStorage != null )
{
remoteStorage.Dispose();
remoteStorage = null;
}
if ( api != null )
{
api.SteamAPI_Shutdown();
api.Dispose();
api = null;
}
}
}
}

View File

@ -5,7 +5,7 @@ namespace SteamNative
{
internal static partial class Platform
{
public interface Interface
public interface Interface : IDisposable
{
// Implementation should return true if _ptr is non null
bool IsValid { get; }

View File

@ -10,10 +10,21 @@ public class Linux32 : Interface
internal IntPtr _ptr;
public bool IsValid { get{ return _ptr != null; } }
//
// Constructor sets pointer to native class
//
public Linux32( IntPtr pointer )
{
_ptr = pointer;
}
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
_ptr = IntPtr.Zero;
}
public virtual HSteamPipe /*(HSteamPipe)*/ ISteamClient_CreateSteamPipe()
{
if ( _ptr == null ) throw new System.Exception( "ISteamClient _ptr is null!" );

View File

@ -10,10 +10,21 @@ public class Linux64 : Interface
internal IntPtr _ptr;
public bool IsValid { get{ return _ptr != null; } }
//
// Constructor sets pointer to native class
//
public Linux64( IntPtr pointer )
{
_ptr = pointer;
}
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
_ptr = IntPtr.Zero;
}
public virtual HSteamPipe /*(HSteamPipe)*/ ISteamClient_CreateSteamPipe()
{
if ( _ptr == null ) throw new System.Exception( "ISteamClient _ptr is null!" );

View File

@ -10,10 +10,21 @@ public class Mac : Interface
internal IntPtr _ptr;
public bool IsValid { get{ return _ptr != null; } }
//
// Constructor sets pointer to native class
//
public Mac( IntPtr pointer )
{
_ptr = pointer;
}
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
_ptr = IntPtr.Zero;
}
public virtual HSteamPipe /*(HSteamPipe)*/ ISteamClient_CreateSteamPipe()
{
if ( _ptr == null ) throw new System.Exception( "ISteamClient _ptr is null!" );

View File

@ -10,10 +10,21 @@ public class Win32 : Interface
internal IntPtr _ptr;
public bool IsValid { get{ return _ptr != null; } }
//
// Constructor sets pointer to native class
//
public Win32( IntPtr pointer )
{
_ptr = pointer;
}
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
_ptr = IntPtr.Zero;
}
public virtual HSteamPipe /*(HSteamPipe)*/ ISteamClient_CreateSteamPipe()
{
if ( _ptr == null ) throw new System.Exception( "ISteamClient _ptr is null!" );

View File

@ -10,10 +10,21 @@ public class Win64 : Interface
internal IntPtr _ptr;
public bool IsValid { get{ return _ptr != null; } }
//
// Constructor sets pointer to native class
//
public Win64( IntPtr pointer )
{
_ptr = pointer;
}
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
_ptr = IntPtr.Zero;
}
public virtual HSteamPipe /*(HSteamPipe)*/ ISteamClient_CreateSteamPipe()
{
if ( _ptr == null ) throw new System.Exception( "ISteamClient _ptr is null!" );

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamApi
public unsafe class SteamApi : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamApi( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamApi( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// HSteamPipe
public HSteamPipe SteamAPI_GetHSteamPipe()
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamAppList
public unsafe class SteamAppList : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamAppList( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamAppList( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// int
public int GetAppBuildId( AppId_t nAppID /*AppId_t*/ )
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamApps
public unsafe class SteamApps : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamApps( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamApps( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// bool
// with: Detect_StringFetch False
public bool BGetDLCDataByIndex( int iDLC /*int*/, ref AppId_t pAppID /*AppId_t **/, out bool pbAvailable /*bool **/, out string pchName /*char **/ )

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamClient
public unsafe class SteamClient : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamClient( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamClient( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// bool
public bool BReleaseSteamPipe( HSteamPipe hSteamPipe /*HSteamPipe*/ )
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamController
public unsafe class SteamController : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamController( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamController( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// void
public void ActivateActionSet( ControllerHandle_t controllerHandle /*ControllerHandle_t*/, ControllerActionSetHandle_t actionSetHandle /*ControllerActionSetHandle_t*/ )
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamFriends
public unsafe class SteamFriends : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamFriends( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamFriends( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// void
public void ActivateGameOverlay( string pchDialog /*const char **/ )
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamGameServer
public unsafe class SteamGameServer : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamGameServer( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamGameServer( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// SteamAPICall_t
public SteamAPICall_t AssociateWithClan( CSteamID steamIDClan /*class CSteamID*/ )
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamGameServerStats
public unsafe class SteamGameServerStats : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamGameServerStats( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamGameServerStats( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// bool
public bool ClearUserAchievement( CSteamID steamIDUser /*class CSteamID*/, string pchName /*const char **/ )
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamHTMLSurface
public unsafe class SteamHTMLSurface : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamHTMLSurface( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamHTMLSurface( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// void
public void AddHeader( HHTMLBrowser unBrowserHandle /*HHTMLBrowser*/, string pchKey /*const char **/, string pchValue /*const char **/ )
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamHTTP
public unsafe class SteamHTTP : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamHTTP( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamHTTP( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// HTTPCookieContainerHandle
public HTTPCookieContainerHandle CreateCookieContainer( bool bAllowResponsesToModify /*bool*/ )
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamInventory
public unsafe class SteamInventory : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamInventory( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamInventory( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// bool
public bool AddPromoItem( ref SteamInventoryResult_t pResultHandle /*SteamInventoryResult_t **/, SteamItemDef_t itemDef /*SteamItemDef_t*/ )
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamMatchmaking
public unsafe class SteamMatchmaking : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamMatchmaking( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamMatchmaking( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// int
public int AddFavoriteGame( AppId_t nAppID /*AppId_t*/, uint nIP /*uint32*/, ushort nConnPort /*uint16*/, ushort nQueryPort /*uint16*/, uint unFlags /*uint32*/, uint rTime32LastPlayedOnServer /*uint32*/ )
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamMatchmakingServers
public unsafe class SteamMatchmakingServers : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamMatchmakingServers( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamMatchmakingServers( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// void
public void CancelQuery( HServerListRequest hRequest /*HServerListRequest*/ )
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamMusic
public unsafe class SteamMusic : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamMusic( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamMusic( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// bool
public bool BIsEnabled()
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamMusicRemote
public unsafe class SteamMusicRemote : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamMusicRemote( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamMusicRemote( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// bool
public bool BActivationSuccess( bool bValue /*bool*/ )
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamNetworking
public unsafe class SteamNetworking : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamNetworking( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamNetworking( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// bool
public bool AcceptP2PSessionWithUser( CSteamID steamIDRemote /*class CSteamID*/ )
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamRemoteStorage
public unsafe class SteamRemoteStorage : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamRemoteStorage( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamRemoteStorage( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// SteamAPICall_t
public SteamAPICall_t CommitPublishedFileUpdate( PublishedFileUpdateHandle_t updateHandle /*PublishedFileUpdateHandle_t*/ )
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamScreenshots
public unsafe class SteamScreenshots : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamScreenshots( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamScreenshots( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// ScreenshotHandle
public ScreenshotHandle AddScreenshotToLibrary( string pchFilename /*const char **/, string pchThumbnailFilename /*const char **/, int nWidth /*int*/, int nHeight /*int*/ )
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamUGC
public unsafe class SteamUGC : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamUGC( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamUGC( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// bool
public bool AddExcludedTag( UGCQueryHandle_t handle /*UGCQueryHandle_t*/, string pTagName /*const char **/ )
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamUnifiedMessages
public unsafe class SteamUnifiedMessages : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamUnifiedMessages( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamUnifiedMessages( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// bool
public bool GetMethodResponseData( ClientUnifiedMessageHandle hHandle /*ClientUnifiedMessageHandle*/, IntPtr pResponseBuffer /*void **/, uint unResponseBufferSize /*uint32*/, bool bAutoRelease /*bool*/ )
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamUser
public unsafe class SteamUser : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamUser( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamUser( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// void
public void AdvertiseGame( CSteamID steamIDGameServer /*class CSteamID*/, uint unIPServer /*uint32*/, ushort usPortServer /*uint16*/ )
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamUserStats
public unsafe class SteamUserStats : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamUserStats( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamUserStats( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// SteamAPICall_t
public SteamAPICall_t AttachLeaderboardUGC( SteamLeaderboard_t hSteamLeaderboard /*SteamLeaderboard_t*/, UGCHandle_t hUGC /*UGCHandle_t*/ )
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamUtils
public unsafe class SteamUtils : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamUtils( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamUtils( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// bool
public bool BOverlayNeedsPresent()
{

View File

@ -3,10 +3,16 @@
namespace SteamNative
{
public unsafe class SteamVideo
public unsafe class SteamVideo : IDisposable
{
//
// Holds a platform specific implentation
//
internal Platform.Interface _pi;
//
// Constructor decides which implementation to use based on current platform
//
public SteamVideo( IntPtr pointer )
{
if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );
@ -16,8 +22,23 @@ public SteamVideo( IntPtr pointer )
else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );
}
//
// Class is invalid if we don't have a valid implementation
//
public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }
//
// When shutting down clear all the internals to avoid accidental use
//
public virtual void Dispose()
{
if ( _pi != null )
{
_pi.Dispose();
_pi = null;
}
}
// void
public void GetVideoURL( AppId_t unVideoAppID /*AppId_t*/ )
{

View File

@ -8,9 +8,6 @@ namespace Generator
{
public partial class CodeWriter
{
bool LargePack;
private void PlatformClass( string type, string libraryName, bool LargePack )
@ -18,43 +15,54 @@ private void PlatformClass( string type, string libraryName, bool LargePack )
this.LargePack = LargePack;
StartBlock( $"internal static partial class Platform" );
StartBlock( $"public class {type} : Interface" );
WriteLine( "internal IntPtr _ptr;" );
WriteLine( "public bool IsValid { get{ return _ptr != null; } }" );
WriteLine();
//
// Constructor
//
StartBlock( $"public {type}( IntPtr pointer )" );
WriteLine( "_ptr = pointer;" );
EndBlock();
foreach ( var c in def.methods.GroupBy( x => x.ClassName ) )
{
PlatformClass( c.Key, c.ToArray() );
}
StartBlock( $"public class {type} : Interface" );
{
WriteLine( "internal IntPtr _ptr;" );
WriteLine( "public bool IsValid { get{ return _ptr != null; } }" );
WriteLine();
StartBlock( $"internal static unsafe class Native" );
foreach ( var c in def.methods.GroupBy( x => x.ClassName ) )
{
InteropClass( libraryName, c.Key, c.ToArray() );
}
EndBlock();
WriteLine( "//" );
WriteLine( "// Constructor sets pointer to native class" );
WriteLine( "//" );
StartBlock( $"public {type}( IntPtr pointer )" );
{
WriteLine( "_ptr = pointer;" );
}
EndBlock();
EndBlock();
WriteLine( "//" );
WriteLine( "// When shutting down clear all the internals to avoid accidental use" );
WriteLine( "//" );
StartBlock( $"public virtual void Dispose()" );
{
WriteLine( "_ptr = IntPtr.Zero;" );
}
EndBlock();
WriteLine();
foreach ( var c in def.methods.GroupBy( x => x.ClassName ) )
{
PlatformClass( c.Key, c.ToArray() );
}
StartBlock( $"internal static unsafe class Native" );
{
foreach ( var c in def.methods.GroupBy( x => x.ClassName ) )
{
InteropClass( libraryName, c.Key, c.ToArray() );
}
}
EndBlock();
}
EndBlock();
}
EndBlock();
}
private void PlatformClass( string className, SteamApiDefinition.MethodDef[] methodDef )
{
if ( className == "ISteamMatchmakingPingResponse" ) return;
if ( className == "ISteamMatchmakingServerListResponse" ) return;
if ( className == "ISteamMatchmakingPlayersResponse" ) return;
if ( className == "ISteamMatchmakingRulesResponse" ) return;
if ( className == "ISteamMatchmakingPingResponse" ) return;
if ( ShouldIgnoreClass( className ) ) return;
LastMethodName = "";
foreach ( var m in methodDef )
@ -169,11 +177,7 @@ private void InteropClassMethod( string library, string classname, SteamApiDefin
private void InteropClass( string libraryName, string className, SteamApiDefinition.MethodDef[] methodDef )
{
if ( className == "ISteamMatchmakingPingResponse" ) return;
if ( className == "ISteamMatchmakingServerListResponse" ) return;
if ( className == "ISteamMatchmakingPlayersResponse" ) return;
if ( className == "ISteamMatchmakingRulesResponse" ) return;
if ( className == "ISteamMatchmakingPingResponse" ) return;
if ( ShouldIgnoreClass( className ) ) return;
StartBlock( $"internal static unsafe class {className}" );

View File

@ -260,7 +260,7 @@ public void ToFolder( string folder )
}
{
Classes( $"{folder}SteamNative." );
Class( $"{folder}SteamNative." );
}
}

View File

@ -8,72 +8,7 @@ namespace Generator
{
public partial class CodeWriter
{
void Classes( string targetName )
{
foreach ( var g in def.methods.GroupBy( x => x.ClassName ) )
{
if ( g.Key == "ISteamMatchmakingPingResponse" ) continue;
if ( g.Key == "ISteamMatchmakingServerListResponse" ) continue;
if ( g.Key == "ISteamMatchmakingPlayersResponse" ) continue;
if ( g.Key == "ISteamMatchmakingRulesResponse" ) continue;
if ( g.Key == "ISteamMatchmakingPingResponse" ) continue;
if ( g.Key == "ISteamMatchmakingPingResponse" ) continue;
if ( g.Key == "SteamApi" )
{
sb = new StringBuilder();
Header();
Class( "SteamApi", g.OrderBy( x => x.Name ).ToArray() );
Footer();
System.IO.File.WriteAllText( $"{targetName}SteamApi.cs", sb.ToString() );
return;
}
sb = new StringBuilder();
Header();
Class( g.Key, g.OrderBy( x => x.Name ).ToArray() );
Footer();
System.IO.File.WriteAllText( $"{targetName}{g.Key.Substring( 1 )}.cs", sb.ToString() );
}
}
private void Class( string classname, SteamApiDefinition.MethodDef[] methodDef )
{
var GenerateClassName = classname;
if ( classname[0] == 'I' ) GenerateClassName = classname.Substring( 1 );
StartBlock( $"public unsafe class {GenerateClassName}" );
WriteLine( "internal Platform.Interface _pi;" );
WriteLine();
//
// Constructor
//
StartBlock( $"public {GenerateClassName}( IntPtr pointer )" );
WriteLine( "if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );" );
WriteLine( "else if ( Platform.IsWindows32 ) _pi = new Platform.Win32( pointer );" );
WriteLine( "else if ( Platform.IsLinux32 ) _pi = new Platform.Linux32( pointer );" );
WriteLine( "else if ( Platform.IsLinux64 ) _pi = new Platform.Linux64( pointer );" );
WriteLine( "else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );" );
EndBlock();
WriteLine();
WriteLine( "public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }" );
WriteLine();
LastMethodName = "";
foreach ( var m in methodDef )
ClassMethod( classname, m );
EndBlock();
}
string LastMethodName;
List<string> BeforeLines;
List<string> AfterLines;
string ReturnType;
@ -81,6 +16,81 @@ private void Class( string classname, SteamApiDefinition.MethodDef[] methodDef )
SteamApiDefinition.MethodDef MethodDef;
string ClassName;
//
// Output a class into a file
//
void Class( string FileName )
{
foreach ( var g in def.methods.GroupBy( x => x.ClassName ) )
{
if ( ShouldIgnoreClass( g.Key ) ) continue;
sb = new StringBuilder();
Header();
Class( g.Key, g.OrderBy( x => x.Name ).ToArray() );
Footer();
System.IO.File.WriteAllText( $"{FileName}{InterfaceNameToClass(g.Key)}.cs", sb.ToString() );
}
}
private void Class( string classname, SteamApiDefinition.MethodDef[] methodDef )
{
StartBlock( $"public unsafe class {InterfaceNameToClass(classname)} : IDisposable" );
{
WriteLine( "//" );
WriteLine( "// Holds a platform specific implentation" );
WriteLine( "//" );
WriteLine( "internal Platform.Interface _pi;" );
WriteLine();
WriteLine( "//" );
WriteLine( "// Constructor decides which implementation to use based on current platform" );
WriteLine( "//" );
StartBlock( $"public {InterfaceNameToClass( classname )}( IntPtr pointer )" );
{
WriteLine( "if ( Platform.IsWindows64 ) _pi = new Platform.Win64( pointer );" );
WriteLine( "else if ( Platform.IsWindows32 ) _pi = new Platform.Win32( pointer );" );
WriteLine( "else if ( Platform.IsLinux32 ) _pi = new Platform.Linux32( pointer );" );
WriteLine( "else if ( Platform.IsLinux64 ) _pi = new Platform.Linux64( pointer );" );
WriteLine( "else if ( Platform.IsOsx ) _pi = new Platform.Mac( pointer );" );
}
EndBlock();
WriteLine();
WriteLine( "//" );
WriteLine( "// Class is invalid if we don't have a valid implementation" );
WriteLine( "//" );
WriteLine( "public bool IsValid{ get{ return _pi != null && _pi.IsValid; } }" );
WriteLine();
WriteLine( "//" );
WriteLine( "// When shutting down clear all the internals to avoid accidental use" );
WriteLine( "//" );
StartBlock( $"public virtual void Dispose()" );
{
StartBlock( " if ( _pi != null )" );
{
WriteLine( "_pi.Dispose();" );
WriteLine( "_pi = null;" );
}
EndBlock();
}
EndBlock();
WriteLine();
//
// Methods
//
foreach ( var m in methodDef )
{
ClassMethod( classname, m );
}
}
EndBlock();
}
private void ClassMethod( string classname, SteamApiDefinition.MethodDef m )
{
var argList = BuildArguments( m.Params );

View File

@ -15,7 +15,7 @@ void PlatformInterface()
{
StartBlock( $"internal static partial class Platform" );
{
StartBlock( $"public interface Interface" );
StartBlock( $"public interface Interface : IDisposable" );
{
WriteLine( "// Implementation should return true if _ptr is non null" );
WriteLine( "bool IsValid { get; } " );
@ -24,11 +24,7 @@ void PlatformInterface()
foreach ( var m in def.methods.OrderBy( x => x.ClassName ) )
{
if ( m.ClassName == "ISteamMatchmakingPingResponse" ) continue;
if ( m.ClassName == "ISteamMatchmakingServerListResponse" ) continue;
if ( m.ClassName == "ISteamMatchmakingPlayersResponse" ) continue;
if ( m.ClassName == "ISteamMatchmakingRulesResponse" ) continue;
if ( m.ClassName == "ISteamMatchmakingPingResponse" ) continue;
if ( ShouldIgnoreClass( m.ClassName ) ) continue;
PlatformInterfaceMethod( m );
}

View File

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Generator
{
public partial class CodeWriter
{
static string[] IgnoredClasses = new string[]
{
"ISteamMatchmakingPingResponse",
"ISteamMatchmakingServerListResponse",
"ISteamMatchmakingPlayersResponse",
"ISteamMatchmakingRulesResponse",
"ISteamMatchmakingPingResponse",
};
public static bool ShouldIgnoreClass( string name )
{
return IgnoredClasses.Contains( name );
}
public string InterfaceNameToClass( string name )
{
if ( name[0] == 'I' )
name = name.Substring( 1 );
return name;
}
}
}

View File

@ -48,11 +48,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Argument.cs" />
<Compile Include="CodeWriter\CodeWriter.Classes.cs" />
<Compile Include="CodeWriter\Class.cs" />
<Compile Include="CodeWriter.cs" />
<Compile Include="CodeWriter.Enum.cs" />
<Compile Include="CodeWriter.Struct.cs" />
<Compile Include="CodeWriter.Types.cs" />
<Compile Include="CodeWriter\Utility.cs" />
<Compile Include="CodeWriter\Interface.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />