Custom root_dir functionality

This commit is contained in:
rdb 2009-12-26 20:08:36 +00:00
parent a03449d433
commit 2891b585b0
6 changed files with 44 additions and 35 deletions

View File

@ -322,7 +322,7 @@ load_plugin(const string &p3d_plugin_filename,
if (!P3D_initialize(P3D_API_VERSION, contents_filename.c_str(),
host_url.c_str(), verify_contents, platform.c_str(),
log_directory.c_str(), log_basename.c_str(),
trusted_environment, console_environment)) {
trusted_environment, console_environment, NULL)) {
// Oops, failure to initialize.
logfile
<< "Failed to initialize plugin (passed API version "

View File

@ -188,7 +188,7 @@ initialize(int api_version, const string &contents_filename,
const string &host_url, bool verify_contents,
const string &platform, const string &log_directory,
const string &log_basename, bool trusted_environment,
bool console_environment) {
bool console_environment, const string &root_dir) {
_api_version = api_version;
_host_url = host_url;
_verify_contents = verify_contents;
@ -221,11 +221,14 @@ initialize(int api_version, const string &contents_filename,
_log_basename = "p3dcore";
}
_root_dir = find_root_dir();
if (_root_dir.empty()) {
cerr << "Could not find root directory.\n";
return false;
if (root_dir.empty()) {
_root_dir = find_root_dir();
if (_root_dir.empty()) {
cerr << "Could not find root directory.\n";
return false;
}
} else {
_root_dir = root_dir;
}
// Allow the caller (e.g. panda3d.exe) to specify a log directory.

View File

@ -57,7 +57,8 @@ public:
const string &log_directory,
const string &log_basename,
bool trusted_environment,
bool console_environment);
bool console_environment,
const string &root_dir = "");
inline bool is_initialized() const;
inline void reconsider_runtime_environment();

View File

@ -36,9 +36,9 @@ LOCK _api_lock;
bool
P3D_initialize(int api_version, const char *contents_filename,
const char *host_url, bool verify_contents,
const char *platform,
const char *log_directory, const char *log_basename,
bool trusted_environment, bool console_environment) {
const char *platform, const char *log_directory,
const char *log_basename, bool trusted_environment,
bool console_environment, const char *root_dir) {
if (api_version < 10 || api_version > P3D_API_VERSION) {
// Can't accept an incompatible version.
return false;
@ -69,12 +69,17 @@ P3D_initialize(int api_version, const char *contents_filename,
if (log_basename == NULL) {
log_basename = "";
}
if (P3D_API_VERSION < 12 || root_dir == NULL) {
root_dir = "";
}
P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
bool result = inst_mgr->initialize(api_version, contents_filename, host_url,
verify_contents, platform,
log_directory, log_basename,
trusted_environment, console_environment);
trusted_environment, console_environment,
root_dir);
RELEASE_LOCK(_api_lock);
return result;
}

View File

@ -79,7 +79,7 @@ extern "C" {
(below). This number will be incremented whenever there are changes
to any of the interface specifications defined in this header
file. */
#define P3D_API_VERSION 11
#define P3D_API_VERSION 12
/************************ GLOBAL FUNCTIONS **************************/
@ -143,7 +143,8 @@ P3D_initialize_func(int api_version, const char *contents_filename,
const char *host_url, bool verify_contents,
const char *platform,
const char *log_directory, const char *log_basename,
bool trusted_environment, bool console_environment);
bool trusted_environment, bool console_environment,
const char *root_dir);
/* This function should be called to unload the core API. It will
release all internally-allocated memory and return the core API to

View File

@ -138,43 +138,42 @@ run_embedded(int read_offset, int argc, char *argv[]) {
read_offset = read.tellg();
read.close();
// Initialize the plugin
if (!P3D_initialize(P3D_API_VERSION, NULL,
_host_url.c_str(), _verify_contents, _this_platform.c_str(),
_log_dirname.c_str(), _log_basename.c_str(),
!_enable_security, _console_environment)) {
// Oops, failure to initialize.
cerr << "Failed to initialize plugin (wrong API version?)\n";
return 1;
}
// Set the super-mirror URL
Filename super_mirror (f);
super_mirror = Filename(super_mirror.get_dirname());
// Find the root directory
Filename root_dir (f);
root_dir = Filename(root_dir.get_dirname());
#ifdef __APPLE__
super_mirror = Filename(super_mirror.get_dirname(), "Resources");
root_dir = Filename(root_dir.get_dirname(), "Resources");
#endif
if (Filename(super_mirror, "contents.xml").exists()) {
string path = super_mirror.to_os_generic();
if (Filename(root_dir, "contents.xml").exists()) {
string path = root_dir.to_os_generic();
if (!path.empty() && path[0] != '/') {
// On Windows, a leading drive letter must be preceded by an
// additional slash.
path = "/" + path;
}
path = "file://" + path;
P3D_set_super_mirror(path.c_str());
}
#if !defined(_WIN32) && !defined(__APPLE__)
else { // On Unix, we should try to find it in the share directory under the prefix.
super_mirror = Filename(super_mirror.get_dirname(), "share/" + f.get_basename());
if (Filename(super_mirror, "contents.xml").exists()) {
string path = super_mirror.to_os_generic();
root_dir = Filename(root_dir.get_dirname(), "share/" + f.get_basename());
if (Filename(root_dir, "contents.xml").exists()) {
string path = root_dir.to_os_generic();
path = "file://" + path;
P3D_set_super_mirror(path.c_str());
}
}
#endif
// Initialize the plugin
if (!P3D_initialize(P3D_API_VERSION, NULL,
_host_url.c_str(), _verify_contents, _this_platform.c_str(),
_log_dirname.c_str(), _log_basename.c_str(),
!_enable_security, _console_environment,
root_dir.c_str())) {
// Oops, failure to initialize.
cerr << "Failed to initialize plugin (wrong API version?)\n";
return 1;
}
// Create a plugin instance and run the program
P3D_instance *inst = create_instance
(f, true, _win_x, _win_y, _win_width, _win_height,