+++ /dev/null
-/*\r
-* Copyright (c) 2007-2010 SlimDX Group\r
-* \r
-* Permission is hereby granted, free of charge, to any person obtaining a copy\r
-* of this software and associated documentation files (the "Software"), to deal\r
-* in the Software without restriction, including without limitation the rights\r
-* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-* copies of the Software, and to permit persons to whom the Software is\r
-* furnished to do so, subject to the following conditions:\r
-* \r
-* The above copyright notice and this permission notice shall be included in\r
-* all copies or substantial portions of the Software.\r
-* \r
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
-* THE SOFTWARE.\r
-*/\r
-#include "stdafx.h"\r
-\r
-#include "../Utilities.h"\r
-#include "../DataStream.h"\r
-#include "../InternalHelpers.h"\r
-#include "../SlimDXException.h"\r
-\r
-#include "Include.h"\r
-\r
-using namespace System;\r
-using namespace System::IO;\r
-using namespace System::Collections::Generic;\r
-using namespace System::Runtime::InteropServices;\r
-\r
-namespace SlimDX\r
-{\r
-namespace Direct3D9\r
-{\r
- IncludeShim::IncludeShim( Include^ wrappedInterface )\r
- {\r
- m_WrappedInterface = wrappedInterface;\r
- m_Frames = gcnew Dictionary<IntPtr, IncludeFrame>();\r
- }\r
-\r
- IncludeShim::~IncludeShim()\r
- {\r
- for each( IncludeFrame frame in m_Frames->Values )\r
- frame.Close();\r
- }\r
-\r
- HRESULT IncludeShim::Open( D3DXINCLUDE_TYPE includeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID* ppData, UINT* pBytes )\r
- {\r
- try\r
- {\r
- Stream^ stream = nullptr;\r
- Stream^ parentStream = nullptr;\r
-\r
- IntPtr parentPtr( const_cast<void*>( pParentData ) );\r
- if( m_Frames->ContainsKey( parentPtr ) )\r
- parentStream = m_Frames->default[parentPtr].Stream;\r
-\r
- m_WrappedInterface->Open( static_cast<IncludeType>( includeType ), gcnew String(pFileName), parentStream, stream );\r
- if( stream == nullptr )\r
- return E_FAIL;\r
-\r
- if(stream->GetType() == DataStream::typeid)\r
- {\r
- // Magic shortcut if we happen to get a DataStream\r
- DataStream^ data = safe_cast<DataStream^>( stream );\r
- *ppData = data->PositionPointer;\r
- *pBytes = static_cast<UINT>( data->Length );\r
-\r
- m_Frames->Add( IntPtr( const_cast<void*>( *ppData ) ), IncludeFrame( stream, GCHandle() ) );\r
- }\r
- else\r
- {\r
- // Read the stream into a byte array and pin it\r
- array<Byte>^ data = Utilities::ReadStream( stream, NULL );\r
- GCHandle handle = GCHandle::Alloc( data, GCHandleType::Pinned );\r
- *ppData = handle.AddrOfPinnedObject().ToPointer();\r
- *pBytes = data->Length;\r
-\r
- m_Frames->Add( IntPtr( const_cast<void*>( *ppData ) ), IncludeFrame( stream, handle ) );\r
- }\r
-\r
- return S_OK;\r
- }\r
- catch( SlimDXException^ ex)\r
- {\r
- return ex->ResultCode.Code;\r
- }\r
- catch( Exception^ )\r
- {\r
- return E_FAIL;\r
- }\r
- }\r
-\r
- HRESULT IncludeShim::Close( LPCVOID pData )\r
- {\r
- try\r
- {\r
- IncludeFrame frame;\r
- IntPtr data(const_cast<void*>(pData));\r
- if (m_Frames->TryGetValue(data, frame))\r
- {\r
- m_Frames->Remove(data);\r
- m_WrappedInterface->Close(frame.Stream);\r
- frame.Close();\r
- }\r
-\r
- return S_OK;\r
- }\r
- catch( SlimDXException^ ex)\r
- {\r
- return ex->ResultCode.Code;\r
- }\r
- catch( Exception^ )\r
- {\r
- return E_FAIL;\r
- }\r
- }\r
-\r
- void IncludeFrame::Close()\r
- {\r
- if( m_stream != nullptr )\r
- delete m_stream;\r
- if( m_handle.IsAllocated )\r
- m_handle.Free();\r
- }\r
-}\r
-}
\ No newline at end of file