diff --git a/direct/src/plugin/Sources.pp b/direct/src/plugin/Sources.pp index 678f79e092..9cbde330ad 100644 --- a/direct/src/plugin/Sources.pp +++ b/direct/src/plugin/Sources.pp @@ -14,6 +14,7 @@ handleStream.cxx handleStream.h handleStream.I \ handleStreamBuf.cxx handleStreamBuf.h \ p3d_lock.h p3d_plugin.h \ + p3d_plugin_config.h \ p3d_plugin_common.h \ p3dDownload.h p3dDownload.I \ p3dFileDownload.h p3dFileDownload.I \ @@ -64,6 +65,7 @@ handleStream.cxx handleStream.h handleStream.I \ handleStreamBuf.cxx handleStreamBuf.h \ p3d_lock.h p3d_plugin.h \ + p3d_plugin_config.h \ p3dCInstance.cxx \ p3dCInstance.h p3dCInstance.I \ p3dPythonRun.cxx p3dPythonRun.h p3dPythonRun.I diff --git a/direct/src/plugin/load_plugin.cxx b/direct/src/plugin/load_plugin.cxx index 45246a1f79..d59785ed08 100755 --- a/direct/src/plugin/load_plugin.cxx +++ b/direct/src/plugin/load_plugin.cxx @@ -15,6 +15,8 @@ #include "load_plugin.h" #include "p3d_plugin_config.h" +#include "assert.h" + #ifndef _WIN32 #include #endif @@ -62,6 +64,47 @@ get_plugin_basename() { return default_plugin_filename + dll_ext; } +//////////////////////////////////////////////////////////////////// +// Function: is_pathsep +// Description: Returns true if the indicated character is a path +// separator character (e.g. slash or backslash), false +// otherwise. +//////////////////////////////////////////////////////////////////// +static inline bool +is_pathsep(char ch) { + if (ch == '/') { + return true; + } +#ifdef _WIN32 + if (ch == '\\') { + return true; + } +#endif + return false; +} + +//////////////////////////////////////////////////////////////////// +// Function: find_extension_dot +// Description: Returns the position in the string of the dot before +// the filename extension; that is, the position of the +// rightmost dot that is right of the rightmost slash +// (or backslash, on Windows). Returns string::npos if +// there is no extension. +//////////////////////////////////////////////////////////////////// +static size_t +find_extension_dot(const string &filename) { + size_t p = filename.length(); + while (p > 0 && !is_pathsep(filename[p - 1])) { + --p; + if (filename[p] == '.') { + return p; + } + } + + return string::npos; +} + + //////////////////////////////////////////////////////////////////// // Function: load_plugin // Description: Loads the plugin and assigns all of the function @@ -83,6 +126,18 @@ load_plugin(const string &p3d_plugin_filename) { #ifdef _WIN32 assert(module == NULL); + + // On Windows, the filename passed to LoadLibrary() must have an + // extension, or a default ".DLL" will be implicitly added. If the + // file actually has no extension, we must add "." to avoid this. + + // Check whether the filename has an extension. + size_t extension_dot = find_extension_dot(filename); + if (extension_dot == string::npos) { + // No extension. + filename += "."; + } + module = LoadLibrary(filename.c_str()); if (module == NULL) { // Couldn't load the DLL. diff --git a/direct/src/plugin/p3dSession.cxx b/direct/src/plugin/p3dSession.cxx index ce59c67c51..113d1f5975 100644 --- a/direct/src/plugin/p3dSession.cxx +++ b/direct/src/plugin/p3dSession.cxx @@ -240,7 +240,7 @@ start_p3dpython() { if (p3dpython.empty()) { p3dpython = _python_root_dir + "/p3dpython"; #ifdef _WIN32 - p3dpython += ".exe" + p3dpython += ".exe"; #endif } diff --git a/direct/src/plugin/p3d_plugin_config.h.pp b/direct/src/plugin/p3d_plugin_config.h.pp index 8e34fc8d83..f296ad1a23 100644 --- a/direct/src/plugin/p3d_plugin_config.h.pp +++ b/direct/src/plugin/p3d_plugin_config.h.pp @@ -13,12 +13,12 @@ /* The filename(s) to generate output to when the plugin is running. For debugging purposes only. */ -#$[]define P3D_PLUGIN_LOGFILE1 "$[osfilename $[P3D_PLUGIN_LOGFILE1]]" -#$[]define P3D_PLUGIN_LOGFILE2 "$[osfilename $[P3D_PLUGIN_LOGFILE2]]" +#$[]define P3D_PLUGIN_LOGFILE1 "$[subst \,\\,$[osfilename $[P3D_PLUGIN_LOGFILE1]]]" +#$[]define P3D_PLUGIN_LOGFILE2 "$[subst \,\\,$[osfilename $[P3D_PLUGIN_LOGFILE2]]]" /* Temporary: the location at which p3dpython.exe can be found. Empty string for the default. */ -#$[]define P3D_PLUGIN_P3DPYTHON "$[osfilename $[P3D_PLUGIN_P3DPYTHON]]" +#$[]define P3D_PLUGIN_P3DPYTHON "$[subst \,\\,$[osfilename $[P3D_PLUGIN_P3DPYTHON]]]" /* The string that corresponds to this particular platform. */ #if $[not $[P3D_PLUGIN_PLATFORM]] diff --git a/direct/src/plugin_npapi/ppInstance.cxx b/direct/src/plugin_npapi/ppInstance.cxx index 34f04de713..408c0a0dab 100644 --- a/direct/src/plugin_npapi/ppInstance.cxx +++ b/direct/src/plugin_npapi/ppInstance.cxx @@ -47,14 +47,16 @@ PPInstance(NPMIMEType pluginType, NPP instance, uint16 mode, _got_instance_data = false; _got_window = false; - // Start the plugin DLL downloading. - string url = P3D_PLUGIN_DOWNLOAD; - url += P3D_PLUGIN_PLATFORM; - url += "/"; - url += get_plugin_basename(); - - PPDownloadRequest *req = new PPDownloadRequest(PPDownloadRequest::RT_core_dll); - browser->geturlnotify(_npp_instance, url.c_str(), NULL, req); + if (!is_plugin_loaded()) { + // Start the plugin DLL downloading. + string url = P3D_PLUGIN_DOWNLOAD; + url += P3D_PLUGIN_PLATFORM; + url += "/"; + url += get_plugin_basename(); + + PPDownloadRequest *req = new PPDownloadRequest(PPDownloadRequest::RT_core_dll); + browser->geturlnotify(_npp_instance, url.c_str(), NULL, req); + } } //////////////////////////////////////////////////////////////////// @@ -211,6 +213,7 @@ stream_as_file(NPStream *stream, const char *fname) { if (!load_plugin(filename)) { logfile << "Unable to launch core API.\n"; } + create_instance(); break; case PPDownloadRequest::RT_instance_data: diff --git a/direct/src/plugin_npapi/startup.cxx b/direct/src/plugin_npapi/startup.cxx index da0571cca1..4039c7e4f1 100644 --- a/direct/src/plugin_npapi/startup.cxx +++ b/direct/src/plugin_npapi/startup.cxx @@ -194,7 +194,7 @@ NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream, PPInstance *inst = (PPInstance *)(instance->pdata); assert(inst != NULL); - return inst->new_stream(type, stream, seekable, stype); + return inst->new_stream(type, stream, seekable != 0, stype); } ////////////////////////////////////////////////////////////////////