integrate with some more code in plugin, fix a couple of bugs

This commit is contained in:
David Rose 2009-09-25 21:41:12 +00:00
parent 3affab1849
commit 2a1299b294
6 changed files with 477 additions and 478 deletions

View File

@ -1,32 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 8.00 Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "P3DActiveX", "P3DActiveX.vcproj", "{74451B00-2D87-412B-9359-B5CA2C2FEC2A}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "P3DActiveX", "P3DActiveX.vcproj", "{74451B00-2D87-412B-9359-B5CA2C2FEC2A}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{1278896B-1978-40CC-B1A0-2D6A7450A32C} = {1278896B-1978-40CC-B1A0-2D6A7450A32C} EndProjectSection
EndProjectSection EndProject
EndProject Global
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tinyxml", "..\..\..\wintools\sdk\tinyxml\tinyxml_lib_mfc_static.vcproj", "{1278896B-1978-40CC-B1A0-2D6A7450A32C}" GlobalSection(SolutionConfiguration) = preSolution
ProjectSection(ProjectDependencies) = postProject Debug = Debug
EndProjectSection Release = Release
EndProject EndGlobalSection
Global GlobalSection(ProjectConfiguration) = postSolution
GlobalSection(SolutionConfiguration) = preSolution {74451B00-2D87-412B-9359-B5CA2C2FEC2A}.Debug.ActiveCfg = Debug|Win32
Debug = Debug {74451B00-2D87-412B-9359-B5CA2C2FEC2A}.Debug.Build.0 = Debug|Win32
Release = Release {74451B00-2D87-412B-9359-B5CA2C2FEC2A}.Release.ActiveCfg = Release|Win32
EndGlobalSection {74451B00-2D87-412B-9359-B5CA2C2FEC2A}.Release.Build.0 = Release|Win32
GlobalSection(ProjectDependencies) = postSolution EndGlobalSection
EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution
GlobalSection(ProjectConfiguration) = postSolution EndGlobalSection
{74451B00-2D87-412B-9359-B5CA2C2FEC2A}.Debug.ActiveCfg = Debug|Win32 GlobalSection(ExtensibilityAddIns) = postSolution
{74451B00-2D87-412B-9359-B5CA2C2FEC2A}.Debug.Build.0 = Debug|Win32 EndGlobalSection
{74451B00-2D87-412B-9359-B5CA2C2FEC2A}.Release.ActiveCfg = Release|Win32 EndGlobal
{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

View File

@ -1,258 +1,272 @@
<?xml version="1.0" encoding="Windows-1252"?> <?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
Version="7.10" Version="7.10"
Name="P3DActiveX" Name="P3DActiveX"
ProjectGUID="{74451B00-2D87-412B-9359-B5CA2C2FEC2A}" ProjectGUID="{74451B00-2D87-412B-9359-B5CA2C2FEC2A}"
Keyword="MFCActiveXProj"> Keyword="MFCActiveXProj">
<Platforms> <Platforms>
<Platform <Platform
Name="Win32"/> Name="Win32"/>
</Platforms> </Platforms>
<Configurations> <Configurations>
<Configuration <Configuration
Name="Debug|Win32" Name="Debug|Win32"
OutputDirectory="Debug" OutputDirectory="Debug"
IntermediateDirectory="Debug" IntermediateDirectory="Debug"
ConfigurationType="2" ConfigurationType="2"
UseOfMFC="1" UseOfMFC="2"
CharacterSet="2"> CharacterSet="2">
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
AdditionalIncludeDirectories="..\plugin;..\..\..\wintools\sdk\tinyxml" AdditionalIncludeDirectories="..\plugin;..\..\..\wintools\include;&quot;..\..\..\wintools\sdk\openssl\openssl-0.9.6d\inc32&quot;"
PreprocessorDefinitions="WIN32;_WINDOWS;_DEBUG;_USRDLL" PreprocessorDefinitions="WIN32;_WINDOWS;_DEBUG;_USRDLL"
MinimalRebuild="TRUE" MinimalRebuild="TRUE"
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
RuntimeLibrary="0" RuntimeLibrary="2"
TreatWChar_tAsBuiltInType="TRUE" TreatWChar_tAsBuiltInType="TRUE"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
Detect64BitPortabilityProblems="TRUE" Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/> DebugInformationFormat="3"/>
<Tool <Tool
Name="VCCustomBuildTool"/> Name="VCCustomBuildTool"/>
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
OutputFile="$(OutDir)/P3DActiveX.ocx" AdditionalDependencies="tinyxml.lib ssleay32.lib libeay32.lib"
LinkIncremental="1" OutputFile="$(OutDir)/P3DActiveX.ocx"
AdditionalLibraryDirectories="../../../wintools/built/lib" LinkIncremental="1"
IgnoreDefaultLibraryNames="LIBCI.LIB MSVCRTD.LIB MSVCRT.LIB" AdditionalLibraryDirectories="&quot;../../../wintools/sdk/openssl/openssl-0.9.6d/out32.dbg&quot;;../../../wintools/built/lib"
ModuleDefinitionFile=".\P3DActiveX.def" IgnoreDefaultLibraryNames="LIBCI.LIB MSVCRTD.LIB MSVCRT.LIB"
GenerateDebugInformation="TRUE" ModuleDefinitionFile=".\P3DActiveX.def"
SubSystem="2" GenerateDebugInformation="TRUE"
ImportLibrary="$(OutDir)/P3DActiveX.lib" SubSystem="2"
TargetMachine="1" ImportLibrary="$(OutDir)/P3DActiveX.lib"
FixedBaseAddress="1"/> TargetMachine="1"
<Tool FixedBaseAddress="1"/>
Name="VCMIDLTool" <Tool
PreprocessorDefinitions="_DEBUG" Name="VCMIDLTool"
MkTypLibCompatible="FALSE" PreprocessorDefinitions="_DEBUG"
TypeLibraryName="$(IntDir)/$(ProjectName).tlb" MkTypLibCompatible="FALSE"
HeaderFileName="$(ProjectName)idl.h"/> TypeLibraryName="$(IntDir)/$(ProjectName).tlb"
<Tool HeaderFileName="$(ProjectName)idl.h"/>
Name="VCPostBuildEventTool" <Tool
Description="Performing registration" Name="VCPostBuildEventTool"
CommandLine="regsvr32 /s /c &quot;$(TargetPath)&quot;"/> Description="Performing registration"
<Tool CommandLine="regsvr32 /s /c &quot;$(TargetPath)&quot;"/>
Name="VCPreBuildEventTool"/> <Tool
<Tool Name="VCPreBuildEventTool"/>
Name="VCPreLinkEventTool"/> <Tool
<Tool Name="VCPreLinkEventTool"/>
Name="VCResourceCompilerTool" <Tool
PreprocessorDefinitions="_DEBUG" Name="VCResourceCompilerTool"
Culture="1033" PreprocessorDefinitions="_DEBUG"
AdditionalIncludeDirectories="$(IntDir)"/> Culture="1033"
<Tool AdditionalIncludeDirectories="$(IntDir)"/>
Name="VCWebServiceProxyGeneratorTool"/> <Tool
<Tool Name="VCWebServiceProxyGeneratorTool"/>
Name="VCXMLDataGeneratorTool"/> <Tool
<Tool Name="VCXMLDataGeneratorTool"/>
Name="VCWebDeploymentTool"/> <Tool
<Tool Name="VCWebDeploymentTool"/>
Name="VCManagedWrapperGeneratorTool"/> <Tool
<Tool Name="VCManagedWrapperGeneratorTool"/>
Name="VCAuxiliaryManagedWrapperGeneratorTool"/> <Tool
</Configuration> Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
<Configuration </Configuration>
Name="Release|Win32" <Configuration
OutputDirectory="Release" Name="Release|Win32"
IntermediateDirectory="Release" OutputDirectory="Release"
ConfigurationType="2" IntermediateDirectory="Release"
UseOfMFC="1" ConfigurationType="2"
CharacterSet="2"> UseOfMFC="2"
<Tool CharacterSet="2">
Name="VCCLCompilerTool" <Tool
AdditionalIncludeDirectories="..\plugin;..\..\..\wintools\sdk\tinyxml" Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;_WINDOWS;NDEBUG;_USRDLL" AdditionalIncludeDirectories="..\plugin;..\..\..\wintools\include;&quot;..\..\..\wintools\sdk\openssl\openssl-0.9.6d\inc32&quot;"
RuntimeLibrary="0" PreprocessorDefinitions="WIN32;_WINDOWS;NDEBUG;_USRDLL"
TreatWChar_tAsBuiltInType="TRUE" RuntimeLibrary="2"
UsePrecompiledHeader="0" TreatWChar_tAsBuiltInType="TRUE"
WarningLevel="3" UsePrecompiledHeader="0"
Detect64BitPortabilityProblems="TRUE" WarningLevel="3"
DebugInformationFormat="3"/> Detect64BitPortabilityProblems="TRUE"
<Tool DebugInformationFormat="3"/>
Name="VCCustomBuildTool"/> <Tool
<Tool Name="VCCustomBuildTool"/>
Name="VCLinkerTool" <Tool
OutputFile="$(OutDir)/P3DActiveX.ocx" Name="VCLinkerTool"
LinkIncremental="1" AdditionalDependencies="tinyxml.lib ssleay32.lib libeay32.lib"
AdditionalLibraryDirectories="../../../wintools/built/lib" OutputFile="$(OutDir)/P3DActiveX.ocx"
IgnoreDefaultLibraryNames="LIBCI.LIB MSVCRTD.LIB MSVCRT.LIB" LinkIncremental="1"
ModuleDefinitionFile=".\P3DActiveX.def" AdditionalLibraryDirectories="&quot;../../../wintools/sdk/openssl/openssl-0.9.6d/out32&quot;;../../../wintools/built/lib"
GenerateDebugInformation="TRUE" IgnoreDefaultLibraryNames="LIBCI.LIB MSVCRTD.LIB MSVCRT.LIB"
SubSystem="2" ModuleDefinitionFile=".\P3DActiveX.def"
OptimizeReferences="2" GenerateDebugInformation="TRUE"
EnableCOMDATFolding="2" SubSystem="2"
ImportLibrary="$(OutDir)/P3DActiveX.lib" OptimizeReferences="2"
TargetMachine="1" EnableCOMDATFolding="2"
FixedBaseAddress="1"/> ImportLibrary="$(OutDir)/P3DActiveX.lib"
<Tool TargetMachine="1"
Name="VCMIDLTool" FixedBaseAddress="1"/>
PreprocessorDefinitions="NDEBUG" <Tool
MkTypLibCompatible="FALSE" Name="VCMIDLTool"
TypeLibraryName="$(IntDir)/$(ProjectName).tlb" PreprocessorDefinitions="NDEBUG"
HeaderFileName="$(ProjectName)idl.h"/> MkTypLibCompatible="FALSE"
<Tool TypeLibraryName="$(IntDir)/$(ProjectName).tlb"
Name="VCPostBuildEventTool" HeaderFileName="$(ProjectName)idl.h"/>
Description="Performing registration" <Tool
CommandLine="regsvr32 /s /c &quot;$(TargetPath)&quot;"/> Name="VCPostBuildEventTool"
<Tool Description="Performing registration"
Name="VCPreBuildEventTool"/> CommandLine="regsvr32 /s /c &quot;$(TargetPath)&quot;"/>
<Tool <Tool
Name="VCPreLinkEventTool"/> Name="VCPreBuildEventTool"/>
<Tool <Tool
Name="VCResourceCompilerTool" Name="VCPreLinkEventTool"/>
PreprocessorDefinitions="NDEBUG" <Tool
Culture="1033" Name="VCResourceCompilerTool"
AdditionalIncludeDirectories="$(IntDir)"/> PreprocessorDefinitions="NDEBUG"
<Tool Culture="1033"
Name="VCWebServiceProxyGeneratorTool"/> AdditionalIncludeDirectories="$(IntDir)"/>
<Tool <Tool
Name="VCXMLDataGeneratorTool"/> Name="VCWebServiceProxyGeneratorTool"/>
<Tool <Tool
Name="VCWebDeploymentTool"/> Name="VCXMLDataGeneratorTool"/>
<Tool <Tool
Name="VCManagedWrapperGeneratorTool"/> Name="VCWebDeploymentTool"/>
<Tool <Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/> Name="VCManagedWrapperGeneratorTool"/>
</Configuration> <Tool
</Configurations> Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
<References> </Configuration>
</References> </Configurations>
<Files> <References>
<Filter </References>
Name="Source Files" <Files>
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" <Filter
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> Name="Source Files"
<File Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
RelativePath=".\P3DActiveX.cpp"> UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
</File> <File
<File RelativePath="..\plugin\fileSpec.cxx">
RelativePath=".\P3DActiveX.idl"> </File>
</File> <File
<File RelativePath="..\plugin\find_root_dir.cxx">
RelativePath=".\P3DActiveXCtrl.cpp"> </File>
</File> <File
<File RelativePath="..\plugin\load_plugin.cxx">
RelativePath=".\P3DActiveXPropPage.cpp"> </File>
</File> <File
<File RelativePath="..\plugin\mkdir_complete.cxx">
RelativePath=".\PPBrowserObject.cpp"> </File>
</File> <File
<File RelativePath=".\P3DActiveX.cpp">
RelativePath=".\PPDownloadCallback.cpp"> </File>
</File> <File
<File RelativePath=".\P3DActiveX.idl">
RelativePath=".\PPDownloadRequest.cpp"> </File>
</File> <File
<File RelativePath=".\P3DActiveXCtrl.cpp">
RelativePath=".\PPInstance.cpp"> </File>
</File> <File
<File RelativePath=".\P3DActiveXPropPage.cpp">
RelativePath=".\PPInterface.cpp"> </File>
</File> <File
<File RelativePath=".\PPBrowserObject.cpp">
RelativePath=".\PPLogger.cpp"> </File>
</File> <File
<File RelativePath=".\PPDownloadCallback.cpp">
RelativePath=".\PPPandaObject.cpp"> </File>
</File> <File
<File RelativePath=".\PPDownloadRequest.cpp">
RelativePath=".\stdafx.cpp"> </File>
<FileConfiguration <File
Name="Debug|Win32"> RelativePath=".\PPInstance.cpp">
<Tool </File>
Name="VCCLCompilerTool" <File
UsePrecompiledHeader="1"/> RelativePath=".\PPInterface.cpp">
</FileConfiguration> </File>
<FileConfiguration <File
Name="Release|Win32"> RelativePath=".\PPLogger.cpp">
<Tool </File>
Name="VCCLCompilerTool" <File
UsePrecompiledHeader="1"/> RelativePath=".\PPPandaObject.cpp">
</FileConfiguration> </File>
</File> <File
</Filter> RelativePath=".\stdafx.cpp">
<Filter <FileConfiguration
Name="Header Files" Name="Debug|Win32">
Filter="h;hpp;hxx;hm;inl;inc;xsd" <Tool
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> Name="VCCLCompilerTool"
<File UsePrecompiledHeader="1"/>
RelativePath=".\P3DActiveX.h"> </FileConfiguration>
</File> <FileConfiguration
<File Name="Release|Win32">
RelativePath=".\P3DActiveXCtrl.h"> <Tool
</File> Name="VCCLCompilerTool"
<File UsePrecompiledHeader="1"/>
RelativePath=".\P3DActiveXPropPage.h"> </FileConfiguration>
</File> </File>
<File </Filter>
RelativePath=".\PPBrowserObject.h"> <Filter
</File> Name="Header Files"
<File Filter="h;hpp;hxx;hm;inl;inc;xsd"
RelativePath=".\PPDownloadCallback.h"> UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
</File> <File
<File RelativePath=".\P3DActiveX.h">
RelativePath=".\PPDownloadRequest.h"> </File>
</File> <File
<File RelativePath=".\P3DActiveXCtrl.h">
RelativePath=".\PPInstance.h"> </File>
</File> <File
<File RelativePath=".\P3DActiveXPropPage.h">
RelativePath=".\PPInterface.h"> </File>
</File> <File
<File RelativePath=".\PPBrowserObject.h">
RelativePath=".\PPLogger.h"> </File>
</File> <File
<File RelativePath=".\PPDownloadCallback.h">
RelativePath=".\PPPandaObject.h"> </File>
</File> <File
<File RelativePath=".\PPDownloadRequest.h">
RelativePath=".\Resource.h"> </File>
</File> <File
<File RelativePath=".\PPInstance.h">
RelativePath=".\stdafx.h"> </File>
</File> <File
</Filter> RelativePath=".\PPInterface.h">
<Filter </File>
Name="Resource Files" <File
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" RelativePath=".\PPLogger.h">
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"> </File>
<File <File
RelativePath=".\P3DActiveX.rc"> RelativePath=".\PPPandaObject.h">
</File> </File>
<File <File
RelativePath=".\P3DActiveXCtrl.bmp"> RelativePath=".\Resource.h">
</File> </File>
</Filter> <File
<File RelativePath=".\stdafx.h">
RelativePath=".\ReadMe.txt"> </File>
</File> </Filter>
</Files> <Filter
<Globals> Name="Resource Files"
<Global Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
Name="RESOURCE_FILE" UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
Value="P3DActiveX.rc"/> <File
</Globals> RelativePath=".\P3DActiveX.rc">
</VisualStudioProject> </File>
<File
RelativePath=".\P3DActiveXCtrl.bmp">
</File>
</Filter>
<File
RelativePath=".\ReadMe.txt">
</File>
</Files>
<Globals>
<Global
Name="RESOURCE_FILE"
Value="P3DActiveX.rc"/>
</Globals>
</VisualStudioProject>

View File

@ -35,36 +35,15 @@
#include "p3d_plugin_config.h" #include "p3d_plugin_config.h"
#include "get_tinyxml.h" #include "get_tinyxml.h"
#include "load_plugin.h"
#include "find_root_dir.h"
#include "mkdir_complete.h"
#define P3D_CONTENTS_FILENAME "contents.xml" #define P3D_CONTENTS_FILENAME "contents.xml"
#define P3D_DEFAULT_PLUGIN_FILENAME "p3d_plugin.dll" #define P3D_DEFAULT_PLUGIN_FILENAME "p3d_plugin.dll"
static HMODULE s_hP3DPluginDll = NULL;
static int s_instanceCount = 0; static int s_instanceCount = 0;
P3D_initialize_func *P3D_initialize;
P3D_finalize_func *P3D_finalize;
P3D_new_instance_func *P3D_new_instance;
P3D_instance_start_func *P3D_instance_start;
P3D_instance_finish_func *P3D_instance_finish;
P3D_instance_setup_window_func *P3D_instance_setup_window;
P3D_instance_get_request_func *P3D_instance_get_request;
P3D_check_request_func *P3D_check_request;
P3D_request_finish_func *P3D_request_finish;
P3D_instance_feed_url_stream_func *P3D_instance_feed_url_stream;
P3D_instance_set_browser_script_object_func *P3D_instance_set_browser_script_object;
P3D_instance_get_panda_script_object_func *P3D_instance_get_panda_script_object;
P3D_make_class_definition_func *P3D_make_class_definition;
P3D_new_undefined_object_func *P3D_new_undefined_object;
P3D_new_none_object_func *P3D_new_none_object;
P3D_new_bool_object_func *P3D_new_bool_object;
P3D_new_int_object_func *P3D_new_int_object;
P3D_new_float_object_func *P3D_new_float_object;
P3D_new_string_object_func *P3D_new_string_object;
void P3D_NofificationSync(P3D_instance *instance) void P3D_NofificationSync(P3D_instance *instance)
{ {
static bool handleRequestOnUIThread = true; static bool handleRequestOnUIThread = true;
@ -92,17 +71,17 @@ void P3D_NofificationSync(P3D_instance *instance)
PPInstance::PPInstance( CP3DActiveXCtrl& parentCtrl ) : PPInstance::PPInstance( CP3DActiveXCtrl& parentCtrl ) :
m_parentCtrl( parentCtrl ), m_p3dInstance( NULL ), m_p3dObject( NULL ), m_handleRequestOnUIThread( true ), m_isInit( false ) m_parentCtrl( parentCtrl ), m_p3dInstance( NULL ), m_p3dObject( NULL ), m_handleRequestOnUIThread( true ), m_isInit( false )
{ {
TCHAR tempFolderName[ MAX_PATH ]; // Open the logfile first.
DWORD pathLength = ::GetTempPath( MAX_PATH, tempFolderName ); m_logger.Open( );
m_logger.Open( std::string( tempFolderName ), std::string( P3D_DEFAULT_PLUGIN_LOG_FILENAME ) ); m_rootDir = find_root_dir( nout );
m_pluginLoaded = false;
} }
PPInstance::~PPInstance( ) PPInstance::~PPInstance( )
{ {
if ( m_p3dInstance ) if ( m_p3dInstance )
{ {
nout << this << ": Finishing P3D instance \n";
P3D_instance_finish( m_p3dInstance ); P3D_instance_finish( m_p3dInstance );
m_p3dInstance = NULL; m_p3dInstance = NULL;
} }
@ -111,7 +90,10 @@ PPInstance::~PPInstance( )
P3D_OBJECT_DECREF( m_p3dObject ); P3D_OBJECT_DECREF( m_p3dObject );
m_p3dObject = NULL; m_p3dObject = NULL;
} }
UnloadPlugin(); if ( m_pluginLoaded )
{
UnloadPlugin();
}
} }
int PPInstance::DownloadFile( const std::string& from, const std::string& to ) int PPInstance::DownloadFile( const std::string& from, const std::string& to )
@ -130,7 +112,33 @@ int PPInstance::DownloadFile( const std::string& from, const std::string& to )
return error; return error;
} }
int PPInstance::ReadContents( const std::string& contentsFilename, std::string& p3dDllFilename ) int PPInstance::CopyFile( const std::string& from, const std::string& to )
{
ifstream in(from.c_str(), ios::in | ios::binary);
ofstream out(to.c_str(), ios::out | ios::binary);
static const size_t buffer_size = 4096;
char buffer[buffer_size];
in.read(buffer, buffer_size);
size_t count = in.gcount();
while (count != 0) {
out.write(buffer, count);
if (out.fail()) {
return 1;
}
in.read(buffer, buffer_size);
count = in.gcount();
}
if (!in.eof()) {
return 1;
}
return 0;
}
int PPInstance::ReadContents( const std::string& contentsFilename, FileSpec& p3dDllFile )
{ {
int error(1); int error(1);
@ -149,7 +157,7 @@ int PPInstance::ReadContents( const std::string& contentsFilename, std::string&
const char *platform = xpackage->Attribute( "platform" ); const char *platform = xpackage->Attribute( "platform" );
if ( platform != NULL && !strcmp(platform, "win32") ) if ( platform != NULL && !strcmp(platform, "win32") )
{ {
p3dDllFilename += xpackage->Attribute( "filename" ); p3dDllFile.load_xml(xpackage);
error = 0; error = 0;
break; break;
} }
@ -165,132 +173,117 @@ int PPInstance::DownloadP3DComponents( std::string& p3dDllFilename )
{ {
int error(0); int error(0);
// Start off by downloading contents.xml into a local temporary
// file. We get a unique temporary filename each time; this is a
// small file and it's very important that we get the most current
// version, not an old cached version.
TCHAR tempFolderName[ MAX_PATH ]; TCHAR tempFolderName[ MAX_PATH ];
DWORD pathLength = ::GetTempPath( MAX_PATH, tempFolderName ); ::GetTempPath( MAX_PATH, tempFolderName );
TCHAR tempFileName[ MAX_PATH ];
::GetTempFileName( tempFolderName, "p3d", 0, tempFileName );
std::string localContentsFileName( tempFileName );
std::string localContentsFileName( tempFolderName, pathLength ); // We'll also get the final installation path of the contents.xml
localContentsFileName += P3D_CONTENTS_FILENAME; // file.
std::string finalContentsFileName( m_rootDir );
finalContentsFileName += "/";
finalContentsFileName += P3D_CONTENTS_FILENAME;
std::string hostUrl( PANDA_PACKAGE_HOST_URL ); std::string hostUrl( PANDA_PACKAGE_HOST_URL );
if (!hostUrl.empty() && hostUrl[hostUrl.size() - 1] != '/') { if (!hostUrl.empty() && hostUrl[hostUrl.size() - 1] != '/') {
hostUrl += '/'; hostUrl += '/';
} }
std::string remoteContentsFilename( hostUrl ); // Append a query string to the contents.xml URL to uniquify it
remoteContentsFilename += P3D_CONTENTS_FILENAME; // and ensure we don't get a cached version.
std::ostringstream strm;
strm << hostUrl << P3D_CONTENTS_FILENAME << "?" << time(NULL);
std::string remoteContentsUrl( strm.str() );
error = DownloadFile( remoteContentsFilename, localContentsFileName ); FileSpec p3dDllFile;
error = DownloadFile( remoteContentsUrl, localContentsFileName );
if ( !error ) if ( !error )
{ {
std::string p3dRemoteModuleFileName( hostUrl ); error = ReadContents( localContentsFileName, p3dDllFile );
error = ReadContents( localContentsFileName, p3dRemoteModuleFileName ); }
if ( !error )
{
std::string p3dLocalModuleFileName( tempFolderName, pathLength );
p3dLocalModuleFileName += P3D_DEFAULT_PLUGIN_FILENAME;
// Check for existance if ( error ) {
if ( ::GetFileAttributes( p3dLocalModuleFileName.c_str( ) ) == INVALID_FILE_ATTRIBUTES ) // If we couldn't download or read the contents.xml file, check
{ // to see if there's a good one on disk already, as a fallback.
error = DownloadFile( p3dRemoteModuleFileName, p3dLocalModuleFileName ); error = ReadContents( finalContentsFileName, p3dDllFile );
}
} else {
// If we have successfully read the downloaded version,
// then move the downloaded version into the final location.
mkfile_complete( finalContentsFileName, nout );
CopyFile( localContentsFileName, finalContentsFileName );
}
// We don't need the temporary file any more.
::DeleteFile( localContentsFileName.c_str() );
if ( !error )
{
// OK, at this point we have successfully read contents.xml,
// and we have a good file spec in p3dDllFile.
if ( p3dDllFile.quick_verify( m_rootDir ) )
{
// The DLL is already on-disk, and is good.
p3dDllFilename = p3dDllFile.get_pathname( m_rootDir );
}
else
{
// The DLL is not already on-disk, or it's stale.
std::string p3dLocalModuleFileName( p3dDllFile.get_pathname( m_rootDir ) );
mkfile_complete( p3dLocalModuleFileName, nout );
std::string p3dRemoteModuleUrl( hostUrl );
p3dRemoteModuleUrl += p3dDllFile.get_filename();
error = DownloadFile( p3dRemoteModuleUrl, p3dLocalModuleFileName );
if ( !error ) if ( !error )
{ {
p3dDllFilename = p3dLocalModuleFileName; error = 1;
if ( p3dDllFile.full_verify( m_rootDir ) )
{
// Downloaded successfully.
p3dDllFilename = p3dDllFile.get_pathname( m_rootDir );
error = 0;
}
} }
} }
} }
return error; return error;
} }
int PPInstance::LoadPlugin( const std::string& dllFilename ) int PPInstance::LoadPlugin( const std::string& dllFilename )
{ {
s_instanceCount += 1; if ( !m_pluginLoaded )
int error(0); {
if ( !s_hP3DPluginDll ) s_instanceCount += 1;
{ m_pluginLoaded = true;
std::string filename( dllFilename ); }
if ( filename.empty() ) int error = 0;
{ if (!is_plugin_loaded()) {
// Look for the plugin along the path.
filename = P3D_DEFAULT_PLUGIN_FILENAME;
filename += ".dll";
}
nout << "Loading " << filename << "\n"; std::string pathname = dllFilename;
s_hP3DPluginDll = LoadLibrary( filename.c_str() ); #ifdef P3D_PLUGIN_P3D_PLUGIN
nout << "got " << s_hP3DPluginDll << "\n"; // This is a convenience macro for development. If defined and
if ( s_hP3DPluginDll == NULL ) // nonempty, it indicates the name of the plugin DLL that we will
{ // actually run, even after downloading a possibly different
// Couldn't load the DLL. // (presumably older) version. Its purpose is to simplify iteration
nout << "Error loading " << filename << " :" << GetLastError() << "\n"; // on the plugin DLL.
return false; string override_filename = P3D_PLUGIN_P3D_PLUGIN;
} if (!override_filename.empty()) {
pathname = override_filename;
char buffer[MAX_PATH]; }
if ( GetModuleFileName( s_hP3DPluginDll, buffer, MAX_PATH ) != 0 ) #endif // P3D_PLUGIN_P3D_PLUGIN
{
if ( GetLastError() != 0 ) nout << "Attempting to load core API from " << pathname << "\n";
{ if (!load_plugin(pathname, "", "", true, "", "", "", false, nout)) {
filename = buffer; nout << "Unable to launch core API in " << pathname << "\n";
} error = 1;
} }
// Now get all of the function pointers.
P3D_initialize = (P3D_initialize_func *)GetProcAddress(s_hP3DPluginDll, "P3D_initialize");
P3D_finalize = (P3D_finalize_func *)GetProcAddress(s_hP3DPluginDll, "P3D_finalize");
P3D_new_instance = (P3D_new_instance_func *)GetProcAddress(s_hP3DPluginDll, "P3D_new_instance");
P3D_instance_start = (P3D_instance_start_func *)GetProcAddress(s_hP3DPluginDll, "P3D_instance_start");
P3D_instance_finish = (P3D_instance_finish_func *)GetProcAddress(s_hP3DPluginDll, "P3D_instance_finish");
P3D_instance_setup_window = (P3D_instance_setup_window_func *)GetProcAddress(s_hP3DPluginDll, "P3D_instance_setup_window");
P3D_instance_get_request = (P3D_instance_get_request_func *)GetProcAddress(s_hP3DPluginDll, "P3D_instance_get_request");
P3D_check_request = (P3D_check_request_func *)GetProcAddress(s_hP3DPluginDll, "P3D_check_request");
P3D_request_finish = (P3D_request_finish_func *)GetProcAddress(s_hP3DPluginDll, "P3D_request_finish");
P3D_instance_feed_url_stream = (P3D_instance_feed_url_stream_func *)GetProcAddress(s_hP3DPluginDll, "P3D_instance_feed_url_stream");
P3D_instance_set_browser_script_object = (P3D_instance_set_browser_script_object_func *)GetProcAddress(s_hP3DPluginDll, "P3D_instance_set_browser_script_object");
P3D_instance_get_panda_script_object = (P3D_instance_get_panda_script_object_func *)GetProcAddress(s_hP3DPluginDll, "P3D_instance_get_panda_script_object");
P3D_make_class_definition = (P3D_make_class_definition_func *)GetProcAddress(s_hP3DPluginDll, "P3D_make_class_definition");
P3D_new_undefined_object = (P3D_new_undefined_object_func *)GetProcAddress(s_hP3DPluginDll, "P3D_new_undefined_object");
P3D_new_none_object = (P3D_new_none_object_func *)GetProcAddress(s_hP3DPluginDll, "P3D_new_none_object");
P3D_new_bool_object = (P3D_new_bool_object_func *)GetProcAddress(s_hP3DPluginDll, "P3D_new_bool_object");
P3D_new_int_object = (P3D_new_int_object_func *)GetProcAddress(s_hP3DPluginDll, "P3D_new_int_object");
P3D_new_float_object = (P3D_new_float_object_func *)GetProcAddress(s_hP3DPluginDll, "P3D_new_float_object");
P3D_new_string_object = (P3D_new_string_object_func *)GetProcAddress(s_hP3DPluginDll, "P3D_new_string_object");
// Ensure that all of the function pointers have been found.
if (P3D_initialize == NULL ||
P3D_finalize == NULL ||
P3D_new_instance == NULL ||
P3D_instance_finish == NULL ||
P3D_instance_get_request == NULL ||
P3D_check_request == NULL ||
P3D_request_finish == NULL ||
P3D_instance_get_panda_script_object == NULL ||
P3D_instance_set_browser_script_object == NULL ||
P3D_instance_feed_url_stream == NULL ||
P3D_make_class_definition == NULL ||
P3D_new_none_object == NULL ||
P3D_new_bool_object == NULL ||
P3D_new_int_object == NULL ||
P3D_new_float_object == NULL ||
P3D_new_string_object == NULL )
{
return ( error = 1 );
}
// Successfully loaded.
nout << "Initializing P3D P3D_API_VERSION=" << P3D_API_VERSION << "\n";
if ( !P3D_initialize( P3D_API_VERSION, "", "", true, "", "", "", false ) )
{
// Oops, failure to initialize.
nout << "Error initializing P3D: " << GetLastError() << "\n";
::FreeLibrary( s_hP3DPluginDll );
s_hP3DPluginDll = NULL;
return ( error = 1 );
}
} }
return error ; return error ;
@ -299,29 +292,22 @@ int PPInstance::LoadPlugin( const std::string& dllFilename )
int PPInstance::UnloadPlugin() int PPInstance::UnloadPlugin()
{ {
int error( 0 ); int error( 0 );
assert( s_instanceCount > 0 );
s_instanceCount -= 1;
if ( s_instanceCount == 0 && s_hP3DPluginDll != NULL ) if ( m_pluginLoaded )
{ {
nout << "Finalizing P3D\n"; m_pluginLoaded = false;
P3D_finalize(); assert( s_instanceCount > 0 );
m_isInit = false; s_instanceCount -= 1;
nout << "Unloading P3D dll " << s_hP3DPluginDll << "\n"; if ( s_instanceCount == 0 && is_plugin_loaded() )
if ( !::FreeLibrary( s_hP3DPluginDll ) )
{ {
nout << "Error unloading P3D dll :" << GetLastError << "\n"; unload_plugin();
error = 1; m_isInit = false;
// This pointer is no longer valid and must be reset for next
// time.
PPBrowserObject::clear_class_definition();
} }
else
{
s_hP3DPluginDll = NULL;
}
// This pointer is no longer valid and must be reset for next
// time.
PPBrowserObject::clear_class_definition();
} }
return error; return error;
} }

View File

@ -21,6 +21,7 @@
#include "p3d_plugin.h" #include "p3d_plugin.h"
#include "PPDownloadCallback.h" #include "PPDownloadCallback.h"
#include "PPLogger.h" #include "PPLogger.h"
#include "fileSpec.h"
#define WM_PY_LAUNCHED (WM_USER + 1) #define WM_PY_LAUNCHED (WM_USER + 1)
#define WM_PROGRESS (WM_USER + 2) #define WM_PROGRESS (WM_USER + 2)
@ -67,7 +68,8 @@ protected:
PPInstance( const PPInstance& ); PPInstance( const PPInstance& );
int DownloadFile( const std::string& from, const std::string& to ); int DownloadFile( const std::string& from, const std::string& to );
int ReadContents( const std::string& contentsFilename, std::string& p3dDllFilename ); int CopyFile( const std::string& from, const std::string& to );
int ReadContents( const std::string& contentsFilename, FileSpec& p3dDllFile );
void HandleRequest( P3D_request *request ); void HandleRequest( P3D_request *request );
static void HandleRequestGetUrl( void *data ); static void HandleRequestGetUrl( void *data );
@ -78,4 +80,7 @@ protected:
bool m_handleRequestOnUIThread; bool m_handleRequestOnUIThread;
bool m_isInit; bool m_isInit;
bool m_pluginLoaded;
std::string m_rootDir;
}; };

View File

@ -89,45 +89,50 @@ int PPLogger::CreateNewFile(const std::string& dirname, const std::string& filen
return error; return error;
} }
void PPLogger::Open( const std::string& logdir, const std::string& filename ) void PPLogger::Open( )
{ {
if ( !m_isOpen ) if (!m_isOpen) {
{ // Note that this logfile name may not be specified at runtime. It
int error = CreateNewFile( logdir, filename ); // must be compiled in if it is specified at all.
// Note that this logfile name may not be specified at runtime. It
// must be compiled in if it is specified at all.
std::string logBasename = filename; std::string log_basename;
#ifdef P3D_PLUGIN_LOG_BASENAME1
#ifdef P3D_DEFAULT_PLUGIN_LOG_FILENAME log_basename = P3D_PLUGIN_LOG_BASENAME1;
if ( logBasename.empty( ) )
{
logBasename = P3D_DEFAULT_PLUGIN_LOG_FILENAME;
}
#endif #endif
if ( !logBasename.empty( ) )
{
// Get the log directory.
std::string logDirectory = logdir;
if ( logDirectory.empty( ) )
{
char buffer[MAX_PATH];
if ( GetTempPath( MAX_PATH, buffer ) != 0 )
{
logDirectory = buffer;
}
}
// Construct the full logfile pathname.
std::string logPathname = logDirectory;
logPathname += logBasename;
m_logfile.open( logPathname.c_str( ) ); if (!log_basename.empty()) {
m_logfile.setf( std::ios::unitbuf ); // Get the log directory.
std::string log_directory;
#ifdef P3D_PLUGIN_LOG_DIRECTORY
log_directory = P3D_PLUGIN_LOG_DIRECTORY;
#endif
if (log_directory.empty()) {
static const size_t buffer_size = MAX_PATH;
char buffer[buffer_size];
if (GetTempPath(buffer_size, buffer) != 0) {
log_directory = buffer;
} }
}
// If we didn't have a logfile name compiled in, we throw away log // Ensure that the log directory ends with a slash.
// output by the simple expedient of never actually opening the if (!log_directory.empty() && log_directory[log_directory.size() - 1] != '/') {
// ofstream. if (log_directory[log_directory.size() - 1] != '\\')
m_isOpen = true; log_directory += "/";
}
// Construct the full logfile pathname.
std::string log_pathname = log_directory;
log_pathname += log_basename;
log_pathname += ".log";
m_logfile.clear();
m_logfile.open(log_pathname.c_str());
m_logfile.setf(std::ios::unitbuf);
} }
// If we didn't have a logfile name compiled in, we throw away log
// output by the simple expedient of never actually opening the
// ofstream.
m_isOpen = true;
}
} }

View File

@ -26,7 +26,7 @@ public:
PPLogger( ); PPLogger( );
virtual ~PPLogger( ); virtual ~PPLogger( );
void Open( const std::string& logdir, const std::string& logbasename ); void Open( );
static std::ofstream& Log( ) { return m_logfile; } static std::ofstream& Log( ) { return m_logfile; }
protected: protected: