25 _path_store = PS_keep;
49 bool got_match =
false;
53 Entries::const_iterator ei;
54 for (ei = _entries.begin(); ei != _entries.end(); ++ei) {
55 const Entry &entry = (*ei);
57 if (entry.try_match(orig_filename, new_filename)) {
65 if (vfs->
exists(new_filename)) {
76 if (_path_store == PS_keep) {
96 pandatoolbase_cat.error()
97 <<
"File does not exist: " << match <<
"\n";
98 }
else if (pandatoolbase_cat.is_debug()) {
99 pandatoolbase_cat.debug()
100 <<
"File does not exist: " << match <<
"\n";
111 pandatoolbase_cat.error()
112 <<
"Absolute pathname: " << orig_filename <<
"\n";
113 }
else if (pandatoolbase_cat.is_debug()) {
114 pandatoolbase_cat.debug()
115 <<
"Absolute pathname: " << orig_filename <<
"\n";
120 if (_path_store != PS_keep) {
121 Filename new_filename = orig_filename;
134 pandatoolbase_cat.error()
135 <<
"File does not exist: " << orig_filename <<
"\n";
136 }
else if (pandatoolbase_cat.is_debug()) {
137 pandatoolbase_cat.debug()
138 <<
"File does not exist: " << orig_filename <<
"\n";
140 return orig_filename;
150 if (orig_filename.empty()) {
151 return orig_filename;
160 copy_this_file(filename);
163 switch (_path_store) {
207 bool got_match =
false;
211 Entries::const_iterator ei;
212 for (ei = _entries.begin(); ei != _entries.end(); ++ei) {
213 const Entry &entry = (*ei);
215 if (entry.try_match(orig_filename, new_filename)) {
218 match = new_filename;
223 if (vfs->
exists(new_filename)) {
224 resolved_path = new_filename;
225 goto calculate_output_path;
235 resolved_path = new_filename;
236 goto calculate_output_path;
249 pandatoolbase_cat.error()
250 <<
"File does not exist: " << match <<
"\n";
251 }
else if (pandatoolbase_cat.is_debug()) {
252 pandatoolbase_cat.debug()
253 <<
"File does not exist: " << match <<
"\n";
256 resolved_path = match;
257 goto calculate_output_path;
265 pandatoolbase_cat.error()
266 <<
"Absolute pathname: " << orig_filename <<
"\n";
267 }
else if (pandatoolbase_cat.is_debug()) {
268 pandatoolbase_cat.debug()
269 <<
"Absolute pathname: " << orig_filename <<
"\n";
275 Filename new_filename = orig_filename;
280 match = orig_filename;
281 resolved_path = new_filename;
282 goto calculate_output_path;
290 pandatoolbase_cat.error()
291 <<
"File does not exist: " << orig_filename <<
"\n";
292 }
else if (pandatoolbase_cat.is_debug()) {
293 pandatoolbase_cat.debug()
294 <<
"File does not exist: " << orig_filename <<
"\n";
296 match = orig_filename;
297 resolved_path = orig_filename;
301 calculate_output_path:
304 if (copy_this_file(resolved_path)) {
305 match = resolved_path;
309 switch (_path_store) {
311 if (resolved_path.empty())
312 output_path = resolved_path;
314 output_path = resolved_path;
321 if (resolved_path.empty())
322 output_path = resolved_path;
324 output_path = resolved_path;
330 if (resolved_path.empty())
331 output_path = resolved_path;
333 output_path = resolved_path;
357 write(std::ostream &out,
int indent_level)
const {
358 Entries::const_iterator ei;
359 for (ei = _entries.begin(); ei != _entries.end(); ++ei) {
361 <<
"-pr " << (*ei)._orig_prefix <<
"=" 362 << (*ei)._replacement_prefix <<
"\n";
365 for (
int i = 0; i < num_directories; i++) {
370 <<
"-ps " << _path_store <<
"\n";
373 switch (_path_store) {
377 <<
"-pd " << _path_directory <<
"\n";
385 <<
"-pc " << _copy_into_directory <<
"\n";
400 copy_this_file(
Filename &filename) {
401 if (_copy_into_directory.
is_local()) {
402 _copy_into_directory =
Filename(_path_directory, _copy_into_directory);
405 Copied::iterator ci = _orig_to_target.find(filename);
406 if (ci != _orig_to_target.end()) {
409 if (filename != (*ci).second) {
410 filename = (*ci).second;
417 ci = _target_to_orig.find(target_filename);
418 if (ci != _target_to_orig.end()) {
419 if ((*ci).second != filename) {
421 pandatoolbase_cat.error()
422 <<
"Filename conflict! Both " << (*ci).second <<
" and " 423 << filename <<
" map to " << target_filename <<
"\n";
427 _orig_to_target[filename] = filename;
431 _orig_to_target[filename] = target_filename;
432 _target_to_orig[target_filename] = filename;
437 if (!vfs->
copy_file(filename, target_filename)) {
439 pandatoolbase_cat.error()
440 <<
"Cannot copy file from " << filename <<
" to " << target_filename
442 _orig_to_target[filename] = filename;
446 filename = target_filename;
454 Entry(
const std::string &orig_prefix,
const std::string &replacement_prefix) :
455 _orig_prefix(orig_prefix),
456 _replacement_prefix(replacement_prefix)
459 if (_orig_prefix.length() > 1 &&
460 _orig_prefix[_orig_prefix.length() - 1] ==
'/') {
461 _orig_prefix = _orig_prefix.substr(0, _orig_prefix.length() - 1);
463 if (_replacement_prefix.length() > 1 &&
464 _replacement_prefix[_replacement_prefix.length() - 1] ==
'/') {
465 _replacement_prefix = _replacement_prefix.substr(0, _replacement_prefix.length() - 1);
471 vector_string components;
473 vector_string::const_iterator ci;
474 for (ci = components.begin(); ci != components.end(); ++ci) {
475 _orig_components.push_back(Component(*ci));
484 bool PathReplace::Entry::
486 if (_is_local != filename.
is_local()) {
489 vector_string components;
491 size_t mi = r_try_match(components, 0, 0);
498 std::string result = _replacement_prefix;
499 while (mi < components.size()) {
500 if (!result.empty()) {
503 result += components[mi];
506 new_filename = result;
518 size_t PathReplace::Entry::
519 r_try_match(
const vector_string &components,
size_t oi,
size_t ci)
const {
520 if (oi >= _orig_components.size()) {
524 if (ci >= components.size()) {
532 const Component &orig_component = _orig_components[oi];
533 if (orig_component._double_star) {
536 size_t mi = r_try_match(components, oi, ci + 1);
542 return r_try_match(components, oi + 1, ci);
547 if (orig_component._orig_prefix.matches(components[ci])) {
549 return r_try_match(components, oi + 1, ci + 1);
bool copy_file(const Filename &orig_filename, const Filename &new_filename)
Attempts to copy the contents of the indicated file to the indicated file.
Filename match_path(const Filename &orig_filename, const DSearchPath &additional_path=DSearchPath())
Looks for a match for the given filename among all the replacement patterns, and returns the first ma...
A hierarchy of directories and files that appears to be one continuous file system,...
void full_convert_path(const Filename &orig_filename, const DSearchPath &additional_path, Filename &resolved_path, Filename &output_path)
Converts the input path into two different forms: A resolved path, and an output path.
bool resolve_filename(Filename &filename, const DSearchPath &searchpath, const std::string &default_extension=std::string()) const
Searches the given search path for the filename.
bool make_directory_full(const Filename &filename)
Attempts to create a directory within the file system.
bool is_fully_qualified() const
Returns true if the filename is fully qualified, e.g.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_num_directories
Returns the number of directories on the search list.
bool exists(const Filename &filename) const
Convenience function; returns true if the named file exists.
The name of a file, such as a texture file or an Egg file.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
void extract_components(vector_string &components) const
Extracts out the individual directory components of the path into a series of strings.
bool is_local() const
Returns true if the filename is local, e.g.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool make_relative_to(Filename directory, bool allow_backups=true)
Adjusts this filename, which must be a fully-specified pathname beginning with a slash,...
std::string get_basename() const
Returns the basename part of the filename.
void make_absolute()
Converts the filename to a fully-qualified pathname from the root (if it is a relative pathname),...
get_directory
Returns the nth directory on the search list.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class stores a list of directories that can be searched, in order, to locate a particular file.
Filename store_path(const Filename &orig_filename)
Given a path to an existing filename, converts it as specified in the _path_store and or _path_direct...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.