windowsisms

This commit is contained in:
David Rose 2009-06-24 00:04:04 +00:00
parent a65ac4fc0c
commit 0cce656d0b
6 changed files with 73 additions and 13 deletions

View File

@ -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

View File

@ -15,6 +15,8 @@
#include "load_plugin.h"
#include "p3d_plugin_config.h"
#include "assert.h"
#ifndef _WIN32
#include <dlfcn.h>
#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.

View File

@ -240,7 +240,7 @@ start_p3dpython() {
if (p3dpython.empty()) {
p3dpython = _python_root_dir + "/p3dpython";
#ifdef _WIN32
p3dpython += ".exe"
p3dpython += ".exe";
#endif
}

View File

@ -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]]

View File

@ -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:

View File

@ -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);
}
////////////////////////////////////////////////////////////////////