From 93d5012ebe584e85ad717df68ea39bd177fe2327 Mon Sep 17 00:00:00 2001 From: Arkady Trestman Date: Tue, 15 Sep 2009 21:42:46 +0000 Subject: [PATCH] adjusted code to load P3D data file location relative to the ActiveX hosting page --- direct/src/plugin_activex/P3DActiveX.sln | 53 +- direct/src/plugin_activex/P3DActiveX.vcproj | 519 +++++++++---------- direct/src/plugin_activex/P3DActiveXCtrl.cpp | 30 +- direct/src/plugin_activex/P3DActiveXCtrl.h | 2 + direct/src/plugin_activex/PPInstance.cpp | 48 +- direct/src/plugin_activex/PPInstance.h | 6 +- direct/src/plugin_activex/PPPandaObject.cpp | 8 +- 7 files changed, 352 insertions(+), 314 deletions(-) diff --git a/direct/src/plugin_activex/P3DActiveX.sln b/direct/src/plugin_activex/P3DActiveX.sln index 5263bf1e8b..888984fe2e 100644 --- a/direct/src/plugin_activex/P3DActiveX.sln +++ b/direct/src/plugin_activex/P3DActiveX.sln @@ -1,21 +1,32 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "P3DActiveX", "P3DActiveX.vcproj", "{74451B00-2D87-412B-9359-B5CA2C2FEC2A}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release - EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {74451B00-2D87-412B-9359-B5CA2C2FEC2A}.Debug.ActiveCfg = Debug|Win32 - {74451B00-2D87-412B-9359-B5CA2C2FEC2A}.Debug.Build.0 = Debug|Win32 - {74451B00-2D87-412B-9359-B5CA2C2FEC2A}.Release.ActiveCfg = Release|Win32 - {74451B00-2D87-412B-9359-B5CA2C2FEC2A}.Release.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution - EndGlobalSection -EndGlobal +Microsoft Visual Studio Solution File, Format Version 8.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "P3DActiveX", "P3DActiveX.vcproj", "{74451B00-2D87-412B-9359-B5CA2C2FEC2A}" + ProjectSection(ProjectDependencies) = postProject + {1278896B-1978-40CC-B1A0-2D6A7450A32C} = {1278896B-1978-40CC-B1A0-2D6A7450A32C} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tinyxml", "..\..\..\wintools\sdk\tinyxml\tinyxml_lib_mfc_static.vcproj", "{1278896B-1978-40CC-B1A0-2D6A7450A32C}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + Debug = Debug + Release = Release + EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {74451B00-2D87-412B-9359-B5CA2C2FEC2A}.Debug.ActiveCfg = Debug|Win32 + {74451B00-2D87-412B-9359-B5CA2C2FEC2A}.Debug.Build.0 = Debug|Win32 + {74451B00-2D87-412B-9359-B5CA2C2FEC2A}.Release.ActiveCfg = Release|Win32 + {74451B00-2D87-412B-9359-B5CA2C2FEC2A}.Release.Build.0 = Release|Win32 + {1278896B-1978-40CC-B1A0-2D6A7450A32C}.Debug.ActiveCfg = Debug|Win32 + {1278896B-1978-40CC-B1A0-2D6A7450A32C}.Debug.Build.0 = Debug|Win32 + {1278896B-1978-40CC-B1A0-2D6A7450A32C}.Release.ActiveCfg = Release|Win32 + {1278896B-1978-40CC-B1A0-2D6A7450A32C}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/direct/src/plugin_activex/P3DActiveX.vcproj b/direct/src/plugin_activex/P3DActiveX.vcproj index e729fb73d5..764c62c6dc 100644 --- a/direct/src/plugin_activex/P3DActiveX.vcproj +++ b/direct/src/plugin_activex/P3DActiveX.vcproj @@ -1,260 +1,259 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/direct/src/plugin_activex/P3DActiveXCtrl.cpp b/direct/src/plugin_activex/P3DActiveXCtrl.cpp index 740373248a..91be8a99e0 100644 --- a/direct/src/plugin_activex/P3DActiveXCtrl.cpp +++ b/direct/src/plugin_activex/P3DActiveXCtrl.cpp @@ -23,6 +23,7 @@ #include "Mshtml.h" #include "atlconv.h" +#include "comutil.h" #include @@ -284,15 +285,38 @@ int CP3DActiveXCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) { return ( error = -1 ); } - std::string p3dDllFilename, p3dFilename; - error = m_instance.DownloadP3DComponents( p3dDllFilename, p3dFilename ); + CComPtr pOleContainer; + HRESULT hr = m_spClientSite->GetContainer( &pOleContainer ); + if ( FAILED( hr ) || !pOleContainer ) + { + return ( error = -1 ); + } + CComPtr pHtml2Doc; + hr = pOleContainer->QueryInterface( IID_IHTMLDocument, ( void** )&pHtml2Doc ); + if ( FAILED( hr ) || !pHtml2Doc ) + { + return ( error = -1 ); + } + BSTR url; + hr = pHtml2Doc->get_URL( &url ); + if ( FAILED( hr ) || !url ) + { + return ( error = -1 ); + } + m_hostingPageUrl = url; + m_hostingPageUrl.Replace( '\\', '/' ); + + ::SysFreeString( url ); + + std::string p3dDllFilename; + error = m_instance.DownloadP3DComponents( p3dDllFilename ); if ( !error && !( p3dDllFilename.empty() ) ) { error = m_instance.LoadPlugin( p3dDllFilename ); if ( !error ) { m_pPandaObject = new PPandaObject( this, NULL ); - m_instance.Start( p3dFilename ); + m_instance.Start( m_instance.GetP3DFilename( ) ); } } return 0; diff --git a/direct/src/plugin_activex/P3DActiveXCtrl.h b/direct/src/plugin_activex/P3DActiveXCtrl.h index 56ca08436c..7cb07c1629 100644 --- a/direct/src/plugin_activex/P3DActiveXCtrl.h +++ b/direct/src/plugin_activex/P3DActiveXCtrl.h @@ -80,6 +80,8 @@ public: // ActiveX properties std::vector< std::pair < CString, CString > > m_parameters; + CString m_hostingPageUrl; + protected: HRESULT ExchangeProperties( CPropExchange* pPropBag ); diff --git a/direct/src/plugin_activex/PPInstance.cpp b/direct/src/plugin_activex/PPInstance.cpp index 7b4065e0da..a37ebf94e8 100644 --- a/direct/src/plugin_activex/PPInstance.cpp +++ b/direct/src/plugin_activex/PPInstance.cpp @@ -33,14 +33,12 @@ #include "PPBrowserObject.h" #include "PPDownloadRequest.h" -#include "p3d_plugin_config.h" #include "get_tinyxml.h" #define P3D_CONTENTS_FILENAME "contents.xml" -//#define P3D_FILE_BASE_URL "http://www.ddrose.com/~drose/plugin/" -//#define P3D_FILE_BASE_URL "file:///C:/temp/" -#define P3D_FILE_BASE_URL "file:///C:/cygwin/home/drose/" +#define P3D_BASE_URL "http://www.ddrose.com/~drose/p3d_7/" +//#define P3D_BASE_URL "file:///C:/p3dstage/" #define P3D_DEFAULT_PLUGIN_FILENAME "p3d_plugin.dll" @@ -160,7 +158,7 @@ int PPInstance::ReadContents( const std::string& contentsFilename, std::string& return error; } -int PPInstance::DownloadP3DComponents( std::string& p3dDllFilename, std::string& p3dFilename ) +int PPInstance::DownloadP3DComponents( std::string& p3dDllFilename ) { int error(0); @@ -170,10 +168,7 @@ int PPInstance::DownloadP3DComponents( std::string& p3dDllFilename, std::string& std::string localContentsFileName( tempFolderName, pathLength ); localContentsFileName += P3D_CONTENTS_FILENAME; - std::string hostUrl( PANDA_PACKAGE_HOST_URL ); - if (!hostUrl.empty() && hostUrl[hostUrl.size() - 1] != '/') { - hostUrl += '/'; - } + std::string hostUrl( P3D_BASE_URL ); std::string remoteContentsFilename( hostUrl ); remoteContentsFilename += P3D_CONTENTS_FILENAME; @@ -196,19 +191,6 @@ int PPInstance::DownloadP3DComponents( std::string& p3dDllFilename, std::string& if ( !error ) { p3dDllFilename = p3dLocalModuleFileName; - - std::string p3dLocalFilename( tempFolderName ); - p3dLocalFilename += GetP3DFilename( ); - - std::string p3dRemoteFilename( P3D_FILE_BASE_URL ); - p3dRemoteFilename += GetP3DFilename( ); - - // Check for existance - if ( ::GetFileAttributes( p3dLocalFilename.c_str( ) ) == INVALID_FILE_ATTRIBUTES ) - { - error = DownloadFile( p3dRemoteFilename, p3dLocalFilename ); - } - p3dFilename = p3dLocalFilename; } } } @@ -360,8 +342,12 @@ int PPInstance::Start( const std::string& p3dFilename ) P3D_instance_setup_window( m_p3dInstance, P3D_WT_embedded, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, parent_window ); - nout << "Starting new P3D instance " << p3dFilename << "\n"; - if ( !P3D_instance_start( m_p3dInstance, true, p3dFilename.c_str() ) ) + std::string p3dRemoteFilename( GetHostUrl() ); + p3dRemoteFilename += p3dFilename; + + nout << "Starting new P3D instance " << p3dRemoteFilename << "\n"; + + if ( !P3D_instance_start( m_p3dInstance, false, p3dRemoteFilename.c_str() ) ) { nout << "Error starting P3D instance: " << GetLastError() << "\n"; } @@ -369,13 +355,21 @@ int PPInstance::Start( const std::string& p3dFilename ) return 1; } -CString PPInstance::GetP3DFilename( ) +std::string PPInstance::GetHostUrl( ) { - CString p3dFilename; + CString hostingPageLocation = m_parentCtrl.m_hostingPageUrl.Left( m_parentCtrl.m_hostingPageUrl.ReverseFind( '/' ) );; + std::string p3dRemoteFilename( hostingPageLocation ); + p3dRemoteFilename += "/"; + return p3dRemoteFilename; +} + +std::string PPInstance::GetP3DFilename( ) +{ + std::string p3dFilename; for ( UINT i = 0; i < m_parentCtrl.m_parameters.size(); i++ ) { std::pair< CString, CString > keyAndValue = m_parentCtrl.m_parameters[ i ]; - if ( keyAndValue.first == "src" ) + if ( keyAndValue.first == "data" ) { p3dFilename = keyAndValue.second; } diff --git a/direct/src/plugin_activex/PPInstance.h b/direct/src/plugin_activex/PPInstance.h index 19009f5187..6e17e473dd 100644 --- a/direct/src/plugin_activex/PPInstance.h +++ b/direct/src/plugin_activex/PPInstance.h @@ -43,13 +43,16 @@ public: PPInstance( CP3DActiveXCtrl& parentCtrl ); virtual ~PPInstance( ); - int DownloadP3DComponents( std::string& p3dDllFilename, std::string& p3dFileName ); + int DownloadP3DComponents( std::string& p3dDllFilename ); int LoadPlugin( const std::string& dllFilename ); int UnloadPlugin( void ); int Start( const std::string& p3dFileName ); + std::string GetHostUrl( ); + std::string GetP3DFilename( ); + static void HandleRequestLoop(); HWND m_parentWnd; @@ -63,7 +66,6 @@ protected: int DownloadFile( const std::string& from, const std::string& to ); int ReadContents( const std::string& contentsFilename, std::string& p3dDllFilename ); - CString GetP3DFilename( ); void HandleRequest( P3D_request *request ); static void HandleRequestGetUrl( void *data ); diff --git a/direct/src/plugin_activex/PPPandaObject.cpp b/direct/src/plugin_activex/PPPandaObject.cpp index bb6d7bc98d..345e926a54 100644 --- a/direct/src/plugin_activex/PPPandaObject.cpp +++ b/direct/src/plugin_activex/PPPandaObject.cpp @@ -16,7 +16,7 @@ #include "PPPandaObject.h" PPandaObject::PPandaObject( PPInterface* interfac, P3D_object* p3dObject ) : - m_interface( interfac), m_p3dObject( p3dObject ), m_refs( 0 ), m_ptinfo( NULL ) + m_interface( interfac ), m_p3dObject( p3dObject ), m_refs( 0 ), m_ptinfo( NULL ) { if ( m_p3dObject ) { @@ -64,7 +64,9 @@ STDMETHODIMP PPandaObject::GetIDsOfNames( UNUSED(lcid); if(!IsEqualIID(riid, IID_NULL)) + { return DISP_E_UNKNOWNINTERFACE; + } for ( UINT i = 0; i < cNames; i++ ) { @@ -137,6 +139,10 @@ STDMETHODIMP PPandaObject::Invoke( { return DISP_E_UNKNOWNINTERFACE; } + if ( !m_interface ) + { + return E_FAIL; + } CString& name( m_idsOfNames[dispidMember] ); HRESULT hr( S_OK );