From 1addfb29d8383786fcecb42151b9acffb3d68b25 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 8 Apr 2008 21:29:54 +0000 Subject: [PATCH] use filename path --- dtool/src/dtoolutil/load_dso.cxx | 6 ++- dtool/src/prc/configVariableSearchPath.I | 63 ++++++++++++++++++++++ dtool/src/prc/configVariableSearchPath.cxx | 9 ++-- dtool/src/prc/configVariableSearchPath.h | 10 ++++ 4 files changed, 82 insertions(+), 6 deletions(-) diff --git a/dtool/src/dtoolutil/load_dso.cxx b/dtool/src/dtoolutil/load_dso.cxx index d2b92534c6..2b951e9b94 100644 --- a/dtool/src/dtoolutil/load_dso.cxx +++ b/dtool/src/dtoolutil/load_dso.cxx @@ -20,8 +20,10 @@ static Filename resolve_dso(const DSearchPath &path, const Filename &filename) { if (filename.is_local()) { - if (path.is_empty()|| - ((path.get_num_directories()==1)&&(path.get_directory(0)=="."))) { + if ((path.get_num_directories()==1)&&(path.get_directory(0)=="")) { + // This is a special case, meaning to search in the same + // directory in which libp3dtool.dll, or the exe, was started + // from. Filename dtoolpath = ExecutionEnvironment::get_dtool_name(); DSearchPath spath(dtoolpath.get_dirname()); return spath.find_file(filename); diff --git a/dtool/src/prc/configVariableSearchPath.I b/dtool/src/prc/configVariableSearchPath.I index 390e22167b..2de09eee63 100644 --- a/dtool/src/prc/configVariableSearchPath.I +++ b/dtool/src/prc/configVariableSearchPath.I @@ -30,6 +30,59 @@ ConfigVariableSearchPath(const string &name, #else ConfigVariableBase(name, VT_search_path, string(), flags), #endif + _default_value(Filename(".")), + _local_modified(initial_invalid_cache()) +{ + // A SearchPath variable implicitly defines a default value of the empty + // string. This is just to prevent the core variable from + // complaining should anyone ask for its solitary value. + if (_core->get_default_value() == (ConfigDeclaration *)NULL) { + _core->set_default_value(""); + } + _core->set_used(); +} + +//////////////////////////////////////////////////////////////////// +// Function: ConfigVariableSearchPath::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE ConfigVariableSearchPath:: +ConfigVariableSearchPath(const string &name, + const DSearchPath &default_value, + const string &description, int flags) : +#ifdef PRC_SAVE_DESCRIPTIONS + ConfigVariableBase(name, VT_search_path, description, flags), +#else + ConfigVariableBase(name, VT_search_path, string(), flags), +#endif + _default_value(default_value), + _local_modified(initial_invalid_cache()) +{ + // A SearchPath variable implicitly defines a default value of the empty + // string. This is just to prevent the core variable from + // complaining should anyone ask for its solitary value. + if (_core->get_default_value() == (ConfigDeclaration *)NULL) { + _core->set_default_value(""); + } + _core->set_used(); +} + +//////////////////////////////////////////////////////////////////// +// Function: ConfigVariableSearchPath::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE ConfigVariableSearchPath:: +ConfigVariableSearchPath(const string &name, + const string &default_value, + const string &description, int flags) : +#ifdef PRC_SAVE_DESCRIPTIONS + ConfigVariableBase(name, VT_search_path, description, flags), +#else + ConfigVariableBase(name, VT_search_path, string(), flags), +#endif + _default_value(Filename(default_value)), _local_modified(initial_invalid_cache()) { // A SearchPath variable implicitly defines a default value of the empty @@ -74,6 +127,16 @@ get_value() const { return _cache; } +//////////////////////////////////////////////////////////////////// +// Function: ConfigVariableSearchPath::get_default_value +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE const DSearchPath &ConfigVariableSearchPath:: +get_default_value() const { + return _default_value; +} + //////////////////////////////////////////////////////////////////// // Function: ConfigVariableSearchPath::clear_local_value // Access: Published diff --git a/dtool/src/prc/configVariableSearchPath.cxx b/dtool/src/prc/configVariableSearchPath.cxx index 95d9c4e961..3b55ed01ee 100644 --- a/dtool/src/prc/configVariableSearchPath.cxx +++ b/dtool/src/prc/configVariableSearchPath.cxx @@ -46,10 +46,11 @@ reload_search_path() { _cache.append_directory(Filename::from_os_specific(expanded)); } } - _cache.append_path(_postfix); - if (_cache.is_empty()) { - // An empty search path implicitly has "." on it. - _cache.append_directory("."); + if (num_unique_references == 0) { + // An empty search path implicitly has the default value. + _cache = _default_value; } + + _cache.append_path(_postfix); } diff --git a/dtool/src/prc/configVariableSearchPath.h b/dtool/src/prc/configVariableSearchPath.h index dca36ee53d..e4b53124ae 100644 --- a/dtool/src/prc/configVariableSearchPath.h +++ b/dtool/src/prc/configVariableSearchPath.h @@ -48,10 +48,19 @@ PUBLISHED: INLINE ConfigVariableSearchPath(const string &name, const string &description = string(), int flags = 0); + INLINE ConfigVariableSearchPath(const string &name, + const DSearchPath &default_value, + const string &description, + int flags = 0); + INLINE ConfigVariableSearchPath(const string &name, + const string &default_value, + const string &description, + int flags = 0); INLINE ~ConfigVariableSearchPath(); INLINE operator const DSearchPath & () const; INLINE const DSearchPath &get_value() const; + INLINE const DSearchPath &get_default_value() const; INLINE bool clear_local_value(); @@ -77,6 +86,7 @@ PUBLISHED: private: void reload_search_path(); + DSearchPath _default_value; DSearchPath _prefix, _postfix; AtomicAdjust::Integer _local_modified;