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,10 +1,5 @@
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
{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 ProjectSection(ProjectDependencies) = postProject
EndProjectSection EndProjectSection
EndProject EndProject
@ -13,17 +8,11 @@ Global
Debug = Debug Debug = Debug
Release = Release Release = Release
EndGlobalSection EndGlobalSection
GlobalSection(ProjectDependencies) = postSolution
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution GlobalSection(ProjectConfiguration) = postSolution
{74451B00-2D87-412B-9359-B5CA2C2FEC2A}.Debug.ActiveCfg = Debug|Win32 {74451B00-2D87-412B-9359-B5CA2C2FEC2A}.Debug.ActiveCfg = Debug|Win32
{74451B00-2D87-412B-9359-B5CA2C2FEC2A}.Debug.Build.0 = 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.ActiveCfg = Release|Win32
{74451B00-2D87-412B-9359-B5CA2C2FEC2A}.Release.Build.0 = 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 EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection EndGlobalSection

View File

@ -15,16 +15,16 @@
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"
@ -34,9 +34,10 @@
Name="VCCustomBuildTool"/> Name="VCCustomBuildTool"/>
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="tinyxml.lib ssleay32.lib libeay32.lib"
OutputFile="$(OutDir)/P3DActiveX.ocx" OutputFile="$(OutDir)/P3DActiveX.ocx"
LinkIncremental="1" LinkIncremental="1"
AdditionalLibraryDirectories="../../../wintools/built/lib" AdditionalLibraryDirectories="&quot;../../../wintools/sdk/openssl/openssl-0.9.6d/out32.dbg&quot;;../../../wintools/built/lib"
IgnoreDefaultLibraryNames="LIBCI.LIB MSVCRTD.LIB MSVCRT.LIB" IgnoreDefaultLibraryNames="LIBCI.LIB MSVCRTD.LIB MSVCRT.LIB"
ModuleDefinitionFile=".\P3DActiveX.def" ModuleDefinitionFile=".\P3DActiveX.def"
GenerateDebugInformation="TRUE" GenerateDebugInformation="TRUE"
@ -79,13 +80,13 @@
OutputDirectory="Release" OutputDirectory="Release"
IntermediateDirectory="Release" IntermediateDirectory="Release"
ConfigurationType="2" ConfigurationType="2"
UseOfMFC="1" UseOfMFC="2"
CharacterSet="2"> CharacterSet="2">
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\plugin;..\..\..\wintools\sdk\tinyxml" AdditionalIncludeDirectories="..\plugin;..\..\..\wintools\include;&quot;..\..\..\wintools\sdk\openssl\openssl-0.9.6d\inc32&quot;"
PreprocessorDefinitions="WIN32;_WINDOWS;NDEBUG;_USRDLL" PreprocessorDefinitions="WIN32;_WINDOWS;NDEBUG;_USRDLL"
RuntimeLibrary="0" RuntimeLibrary="2"
TreatWChar_tAsBuiltInType="TRUE" TreatWChar_tAsBuiltInType="TRUE"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
@ -95,9 +96,10 @@
Name="VCCustomBuildTool"/> Name="VCCustomBuildTool"/>
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="tinyxml.lib ssleay32.lib libeay32.lib"
OutputFile="$(OutDir)/P3DActiveX.ocx" OutputFile="$(OutDir)/P3DActiveX.ocx"
LinkIncremental="1" LinkIncremental="1"
AdditionalLibraryDirectories="../../../wintools/built/lib" AdditionalLibraryDirectories="&quot;../../../wintools/sdk/openssl/openssl-0.9.6d/out32&quot;;../../../wintools/built/lib"
IgnoreDefaultLibraryNames="LIBCI.LIB MSVCRTD.LIB MSVCRT.LIB" IgnoreDefaultLibraryNames="LIBCI.LIB MSVCRTD.LIB MSVCRT.LIB"
ModuleDefinitionFile=".\P3DActiveX.def" ModuleDefinitionFile=".\P3DActiveX.def"
GenerateDebugInformation="TRUE" GenerateDebugInformation="TRUE"
@ -145,6 +147,18 @@
Name="Source Files" Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath="..\plugin\fileSpec.cxx">
</File>
<File
RelativePath="..\plugin\find_root_dir.cxx">
</File>
<File
RelativePath="..\plugin\load_plugin.cxx">
</File>
<File
RelativePath="..\plugin\mkdir_complete.cxx">
</File>
<File <File
RelativePath=".\P3DActiveX.cpp"> RelativePath=".\P3DActiveX.cpp">
</File> </File>

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 )
{ {
std::string filename( dllFilename ); s_instanceCount += 1;
m_pluginLoaded = true;
}
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;
}
#endif // P3D_PLUGIN_P3D_PLUGIN
char buffer[MAX_PATH]; nout << "Attempting to load core API from " << pathname << "\n";
if ( GetModuleFileName( s_hP3DPluginDll, buffer, MAX_PATH ) != 0 ) if (!load_plugin(pathname, "", "", true, "", "", "", false, nout)) {
{ nout << "Unable to launch core API in " << pathname << "\n";
if ( GetLastError() != 0 ) error = 1;
{ }
filename = buffer;
}
}
// 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;
}
else
{
s_hP3DPluginDll = NULL;
}
// This pointer is no longer valid and must be reset for next // This pointer is no longer valid and must be reset for next
// time. // time.
PPBrowserObject::clear_class_definition(); 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: