Panda3D
|
The name of a file, such as a texture file or an Egg file. More...
#include "filename.h"
Public Types | |
enum | Flags { F_type = 0x0f, F_binary = 0x10, F_text = 0x20, F_pattern = 0x40 } |
enum | Type { T_general = 0x00, T_dso = 0x01, T_executable = 0x02 } |
Public Member Functions | |
Filename (const char *filename) | |
Filename (const string &filename="") | |
Filename (const wstring &filename) | |
Filename (const Filename ©) | |
Filename (const Filename &dirname, const Filename &basename) | |
This constructor composes the filename out of a directory part and a basename part. More... | |
bool | __nonzero__ () const |
Returns true if the Filename is valid (not empty), or false if it is an empty string. More... | |
bool | atomic_compare_and_exchange_contents (string &orig_contents, const string &old_contents, const string &new_contents) const |
Uses native file-locking mechanisms to atomically replace the contents of a (small) file with the specified contents, assuming it hasn't changed since the last time the file was read. More... | |
bool | atomic_read_contents (string &contents) const |
Uses native file-locking mechanisms to atomically read the contents of a (small) file. More... | |
const char * | c_str () const |
bool | chdir () const |
Changes directory to the specified location. More... | |
int | compare_timestamps (const Filename &other, bool this_missing_is_old=true, bool other_missing_is_old=true) const |
Returns a number less than zero if the file named by this object is older than the given file, zero if they have the same timestamp, or greater than zero if this one is newer. More... | |
int | compare_to (const Filename &other) const |
bool | copy_to (const Filename &other) const |
Copies the file to the indicated new filename, by reading the contents and writing it to the new file. More... | |
bool | empty () const |
bool | exists () const |
Returns true if the filename exists on the disk, false otherwise. More... | |
void | extract_components (vector_string &components) const |
Extracts out the individual directory components of the path into a series of strings. More... | |
int | find_on_searchpath (const DSearchPath &searchpath) |
Performs the reverse of the resolve_filename() operation: assuming that the current filename is fully-specified pathname (i.e. More... | |
time_t | get_access_timestamp () const |
Returns a time_t value that represents the time the file was last accessed, if this information is available. More... | |
string | get_basename () const |
Returns the basename part of the filename. More... | |
string | get_basename_wo_extension () const |
Returns the basename part of the filename, without the file extension. More... | |
string | get_dirname () const |
Returns the directory part of the filename. More... | |
string | get_extension () const |
Returns the file extension. More... | |
streamsize | get_file_size () const |
Returns the size of the file in bytes, or 0 if there is an error. More... | |
Filename | get_filename_index (int index) const |
If the pattern flag is set for this Filename and the filename string actually includes a sequence of hash marks, then this returns a new Filename with the sequence of hash marks replaced by the indicated index number. More... | |
string | get_fullpath () const |
Returns the entire filename: directory, basename, extension. More... | |
wstring | get_fullpath_w () const |
Returns the entire filename as a wide-character string. More... | |
string | get_fullpath_wo_extension () const |
Returns the full filename–directory and basename parts–except for the extension. More... | |
int | get_hash () const |
Returns a hash code that attempts to be mostly unique for different Filenames. More... | |
string | get_hash_to_end () const |
Returns the part of the filename beginning at the hash sequence (if any), and continuing to the end of the filename. More... | |
bool | get_pattern () const |
Returns the flag indicating whether this is a filename pattern. More... | |
time_t | get_timestamp () const |
Returns a time_t value that represents the time the file was last modified, to within whatever precision the operating system records this information (on a Windows95 system, for instance, this may only be accurate to within 2 seconds). More... | |
Type | get_type () const |
Returns the type of the file represented by the filename, as previously set by set_type(). More... | |
bool | has_hash () const |
Returns true if the filename is indicated to be a filename pattern (that is, set_pattern(true) was called), and the filename pattern did include a sequence of hash marks, or false if it was not a filename pattern or did not include hash marks. More... | |
bool | is_binary () const |
Returns true if the Filename has been indicated to represent a binary file via a previous call to set_binary(). More... | |
bool | is_binary_or_text () const |
Returns true either is_binary() or is_text() is true; that is, that the filename has been specified as either binary or text. More... | |
bool | is_directory () const |
Returns true if the filename exists and is a directory name, false otherwise. More... | |
bool | is_executable () const |
Returns true if the filename exists and is executable. More... | |
bool | is_fully_qualified () const |
Returns true if the filename is fully qualified, e.g. More... | |
bool | is_local () const |
Returns true if the filename is local, e.g. More... | |
bool | is_regular_file () const |
Returns true if the filename exists and is the name of a regular file (i.e. More... | |
bool | is_text () const |
Returns true if the Filename has been indicated to represent a text file via a previous call to set_text(). More... | |
bool | is_writable () const |
Returns true if the filename exists and is either a directory or a regular file that can be written to, or false otherwise. More... | |
size_t | length () const |
void | make_absolute () |
Converts the filename to a fully-qualified pathname from the root (if it is a relative pathname), and then standardizes it (see standardize()). More... | |
void | make_absolute (const Filename &start_directory) |
Converts the filename to a fully-qualified filename from the root (if it is a relative filename), and then standardizes it (see standardize()). More... | |
bool | make_canonical () |
Converts this filename to a canonical name by replacing the directory part with the fully-qualified directory part. More... | |
bool | make_dir () const |
Creates all the directories in the path to the file specified in the filename, except for the basename itself. More... | |
bool | make_relative_to (Filename directory, bool allow_backups=true) |
Adjusts this filename, which must be a fully-specified pathname beginning with a slash, to make it a relative filename, relative to the fully-specified directory indicated (which must also begin with, and may or may not end with, a slash–a terminating slash is ignored). More... | |
bool | make_true_case () |
On a case-insensitive operating system (e.g. More... | |
bool | mkdir () const |
Creates the directory named by this filename. More... | |
bool | open_append (ofstream &stream) const |
Opens the indicated ofstream for writing the file, if possible. More... | |
bool | open_read (ifstream &stream) const |
Opens the indicated ifstream for reading the file, if possible. More... | |
bool | open_read_append (fstream &stream) const |
Opens the indicated ifstream for reading and writing the file, if possible; writes are appended to the end of the file. More... | |
bool | open_read_write (fstream &stream, bool truncate=false) const |
Opens the indicated fstream for read/write access to the file, if possible. More... | |
bool | open_write (ofstream &stream, bool truncate=true) const |
Opens the indicated ifstream for writing the file, if possible. More... | |
operator const string & () const | |
bool | operator!= (const string &other) const |
Filename | operator+ (const string &other) const |
Returns a new Filename representing the concatenation of the two filenames. More... | |
void | operator+= (const string &other) |
Appends the other filename onto the end of this one. More... | |
Filename | operator/ (const Filename &other) const |
Returns a new Filename that is composed of the other filename added to the end of this filename, with an intervening slash added if necessary. More... | |
bool | operator< (const string &other) const |
Filename & | operator= (const string &filename) |
Filename & | operator= (const wstring &filename) |
Filename & | operator= (const char *filename) |
Filename & | operator= (const Filename ©) |
bool | operator== (const string &other) const |
char | operator[] (int n) const |
void | output (ostream &out) const |
bool | rename_to (const Filename &other) const |
Renames the file to the indicated new filename. More... | |
bool | resolve_filename (const DSearchPath &searchpath, const string &default_extension=string()) |
Searches the given search path for the filename. More... | |
bool | rmdir () const |
The inverse of mkdir(): this removes the directory named by this Filename, if it is in fact a directory. More... | |
bool | scan_directory (vector_string &contents) const |
Attempts to open the named filename as if it were a directory and looks for the non-hidden files within the directory. More... | |
void | set_basename (const string &s) |
Replaces the basename part of the filename. More... | |
void | set_basename_wo_extension (const string &s) |
Replaces the basename part of the filename, without the file extension. More... | |
void | set_binary () |
Indicates that the filename represents a binary file. More... | |
void | set_dirname (const string &s) |
Replaces the directory part of the filename. More... | |
void | set_extension (const string &s) |
Replaces the file extension. More... | |
void | set_fullpath (const string &s) |
Replaces the entire filename: directory, basename, extension. More... | |
void | set_fullpath_wo_extension (const string &s) |
Replaces the full filename–directory and basename parts–except for the extension. More... | |
void | set_hash_to_end (const string &s) |
Replaces the part of the filename from the beginning of the hash sequence to the end of the filename. More... | |
void | set_pattern (bool pattern) |
Sets the flag indicating whether this is a filename pattern. More... | |
void | set_text () |
Indicates that the filename represents a text file. More... | |
void | set_type (Type type) |
Sets the type of the file represented by the filename. More... | |
void | standardize () |
Converts the filename to standard form by replacing consecutive slashes with a single slash, removing a trailing slash if present, and backing up over ../ sequences within the filename where possible. More... | |
string | substr (size_t begin, size_t end=string::npos) const |
string | to_os_generic () const |
This is similar to to_os_specific(), but it is designed to generate a filename that can be understood on as many platforms as possible. More... | |
string | to_os_long_name () const |
This is the opposite of to_os_short_name(): it returns the "long name" of the filename, if the filename exists. More... | |
string | to_os_short_name () const |
This works like to_os_generic(), but it returns the "short name" version of the filename, if it exists, or the original filename otherwise. More... | |
string | to_os_specific () const |
Converts the filename from our generic Unix-like convention (forward slashes starting with the root at '/') to the corresponding filename in the local operating system (slashes in the appropriate direction, starting with the root at C:\, for instance). More... | |
wstring | to_os_specific_w () const |
The wide-string variant on to_os_specific(). More... | |
bool | touch () const |
Updates the modification time of the file to the current time. More... | |
bool | unlink () const |
Permanently deletes the file associated with the filename, if possible. More... | |
Static Public Member Functions | |
static Filename | binary_filename (const Filename &filename) |
static Filename | binary_filename (const string &filename) |
static Filename | dso_filename (const string &filename) |
static Filename | executable_filename (const string &filename) |
static Filename | expand_from (const string &user_string, Type type=T_general) |
Returns the same thing as from_os_specific(), but embedded environment variable references (e.g. More... | |
static Filename | from_os_specific (const string &os_specific, Type type=T_general) |
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon). More... | |
static Filename | from_os_specific_w (const wstring &os_specific, Type type=T_general) |
The wide-string variant of from_os_specific(). More... | |
static TypeHandle | get_class_type () |
static const Filename & | get_common_appdata_directory () |
Returns a path to a system-defined directory appropriate for creating a subdirectory for storing application-specific data, common to all users. More... | |
static TextEncoder::Encoding | get_filesystem_encoding () |
Specifies the default encoding to be used for all subsequent Filenames objects. More... | |
static const Filename & | get_home_directory () |
Returns a path to the user's home directory, if such a thing makes sense in the current OS, or to the nearest equivalent. More... | |
static const Filename & | get_temp_directory () |
Returns a path to a system-defined temporary directory. More... | |
static const Filename & | get_user_appdata_directory () |
Returns a path to a system-defined directory appropriate for creating a subdirectory for storing application-specific data, specific to the current user. More... | |
static void | init_type () |
static Filename | pattern_filename (const string &filename) |
Constructs a filename that represents a sequence of numbered files. More... | |
static void | set_filesystem_encoding (TextEncoder::Encoding encoding) |
Specifies the default encoding to be used for all subsequent Filenames. More... | |
static Filename | temporary (const string &dirname, const string &prefix, const string &suffix=string(), Type type=T_general) |
Generates a temporary filename within the indicated directory, using the indicated prefix. More... | |
static Filename | text_filename (const Filename &filename) |
static Filename | text_filename (const string &filename) |
The name of a file, such as a texture file or an Egg file.
Stores the full pathname, and includes functions for extracting out the directory prefix part and the file extension and stuff.
A Filename is also aware of the mapping between the Unix-like filename convention we use internally, and the local OS's specific filename convention, and it knows how to perform basic OS-specific I/O, like testing for file existence and searching a searchpath, as well as the best way to open an fstream for reading or writing.
Definition at line 44 of file filename.h.
This constructor composes the filename out of a directory part and a basename part.
It will insert an intervening '/' if necessary.
Definition at line 297 of file filename.cxx.
References from_os_specific(), and get_fullpath().
|
inline |
Returns true if the Filename is valid (not empty), or false if it is an empty string.
This implements the Python equivalent to operator bool. Defining an actual operator bool method for C++ use would work too, but it seems to cause too many ambiguities for the C++ compiler, so we use this Python-only approach instead.
Definition at line 742 of file filename.I.
References set_filesystem_encoding().
Referenced by is_fully_qualified().
bool Filename::atomic_compare_and_exchange_contents | ( | string & | orig_contents, |
const string & | old_contents, | ||
const string & | new_contents | ||
) | const |
Uses native file-locking mechanisms to atomically replace the contents of a (small) file with the specified contents, assuming it hasn't changed since the last time the file was read.
This is designed to be similar to AtomicAdjust::compare_and_exchange(). The method writes new_contents to the file, completely replacing the original contents; but only if the original contents exactly matched old_contents. If the file was modified, returns true. If, however, the original contents of the file did not exactly match old_contents, then the file is not modified, and false is returned. In either case, orig_contents is filled with the original contents of the file.
If the file does not exist, it is implicitly created, and its original contents are empty.
If an I/O error occurs on write, some of the file may or may not have been written, and false is returned.
Expressed in pseudo-code, the logic is:
orig_contents = file.read(); if (orig_contents == old_contents) { file.write(new_contents); return true; } return false;
The operation is guaranteed to be atomic only if the only operations that read and write to this file are atomic_compare_and_exchange_contents() and atomic_read_contents().
Definition at line 2906 of file filename.cxx.
References atomic_read_contents(), to_os_specific(), and to_os_specific_w().
Referenced by VirtualFileMountSystem::atomic_compare_and_exchange_contents(), and get_hash().
bool Filename::atomic_read_contents | ( | string & | contents | ) | const |
Uses native file-locking mechanisms to atomically read the contents of a (small) file.
This is the only way to read a file protected by atomic_compare_and_exchange_contents(), and be confident that the read operation is actually atomic with respect to that method.
If the file does not exist, it is implicitly created, and its contents are empty.
If the file is read successfully, fills its contents in the indicated string, and returns true. If the file cannot be read, returns false.
Definition at line 3049 of file filename.cxx.
References chdir(), ExecutionEnvironment::get_cwd(), get_dirname(), get_fullpath(), get_pattern(), set_dirname(), to_os_specific(), and to_os_specific_w().
Referenced by atomic_compare_and_exchange_contents(), and VirtualFileMountSystem::atomic_read_contents().
bool Filename::chdir | ( | ) | const |
Changes directory to the specified location.
Returns true if successful, false if failure.
Definition at line 2535 of file filename.cxx.
References to_os_specific(), to_os_specific_w(), and unlink().
Referenced by atomic_read_contents(), and touch().
int Filename::compare_timestamps | ( | const Filename & | other, |
bool | this_missing_is_old = true , |
||
bool | other_missing_is_old = true |
||
) | const |
Returns a number less than zero if the file named by this object is older than the given file, zero if they have the same timestamp, or greater than zero if this one is newer.
If this_missing_is_old is true, it indicates that a missing file will be treated as if it were older than any other file; otherwise, a missing file will be treated as if it were newer than any other file. Similarly for other_missing_is_old.
Definition at line 1521 of file filename.cxx.
References get_filename_index(), get_timestamp(), to_os_specific(), and to_os_specific_w().
Referenced by DestTextureImage::copy_if_stale(), TextureImage::get_preferred_source(), is_executable(), TextureImage::is_newer_than(), EggReader::pre_process_egg_file(), and PaletteImage::update_image().
bool Filename::copy_to | ( | const Filename & | other | ) | const |
Copies the file to the indicated new filename, by reading the contents and writing it to the new file.
Returns true if successful, false on failure. The copy is always binary, regardless of the filename settings.
Definition at line 2680 of file filename.cxx.
References make_dir(), open_read(), open_write(), and unlink().
Referenced by VirtualFileMountSystem::copy_file(), and rename_to().
bool Filename::exists | ( | ) | const |
Returns true if the filename exists on the disk, false otherwise.
If the type is indicated to be executable, this also tests that the file has execute permission.
Definition at line 1356 of file filename.cxx.
References get_filename_index(), is_regular_file(), to_os_specific(), and to_os_specific_w().
Referenced by SomethingToEgg::add_merge_externals_options(), Multifile::add_subfile(), Multifile::compare_subfile(), CVSCopy::continue_after_error(), ImageFile::exists(), DSearchPath::find_all_files(), DSearchPath::find_file(), WithOutputFile::get_output_filename(), EggPalettize::handle_args(), VirtualFileMountSystem::has_file(), CVSCopy::import(), is_executable(), BamCache::list_index(), GlobPattern::match_files(), VirtualFileSystem::mount(), open_read_append(), Multifile::open_read_write(), open_read_write(), open_write(), EggReader::pre_process_egg_file(), ImageFile::read(), EggFile::read_egg(), Palettizer::read_stale_eggs(), resolve_filename(), CVSSourceDirectory::scan(), WinGraphicsWindow::static_window_proc(), temporary(), to_os_long_name(), ImageFile::unlink(), PaletteImage::update_filename(), Multifile::update_subfile(), and ImageFile::write().
|
static |
Returns the same thing as from_os_specific(), but embedded environment variable references (e.g.
"$DMODELS/foo.txt") are expanded out. It also automatically elevates the file to its true case if needed.
Definition at line 418 of file filename.cxx.
References ExecutionEnvironment::expand_string(), from_os_specific(), make_true_case(), and temporary().
Referenced by from_os_specific_w(), ConfigVariableFilename::get_default_value(), and ConfigVariableFilename::get_word().
void Filename::extract_components | ( | vector_string & | components | ) | const |
Extracts out the individual directory components of the path into a series of strings.
get_basename() will be the last component stored in the vector. Note that no distinction is made by this method between a leading slash and no leading slash, but you can call is_local() to differentiate the two cases.
Definition at line 914 of file filename.cxx.
References standardize().
Referenced by PathReplace::full_convert_path(), and set_hash_to_end().
int Filename::find_on_searchpath | ( | const DSearchPath & | searchpath | ) |
Performs the reverse of the resolve_filename() operation: assuming that the current filename is fully-specified pathname (i.e.
beginning with '/'), look on the indicated search path for a directory under which the file can be found. When found, adjust the Filename to be relative to the indicated directory name.
Returns the index of the directory on the searchpath at which the file was found, or -1 if it was not found.
Definition at line 1820 of file filename.cxx.
References DSearchPath::get_directory(), DSearchPath::get_num_directories(), make_absolute(), make_relative_to(), and scan_directory().
Referenced by Texture::finalize(), make_relative_to(), and SpeedTreeNode::InstanceList::write_datagram().
|
static |
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).
Use this function to create a Filename from an externally-given filename string. Use to_os_specific() again later to reconvert it back to the local operating system's conventions.
This function will do the right thing even if the filename is partially local conventions and partially Panda conventions; e.g. some backslashes and some forward slashes.
Definition at line 332 of file filename.cxx.
References from_os_specific_w(), and set_type().
Referenced by SpeedTreeNode::add_from_stf(), DaeMaterials::add_material_instance(), SomethingToEgg::add_merge_externals_options(), PfmTrans::add_transform_options(), DSearchPath::append_path(), MayaShader::bind_uvsets(), AssimpLoader::build_graph(), DCFile::clear(), MayaToEggConverter::clear(), PandaIOSystem::ComparePaths(), CVSCopy::continue_after_error(), MaxToEggConverter::convert(), MayaPview::creator(), PandaIOSystem::Exists(), expand_from(), Filename(), XFileMaterial::fill_material(), STBasicTerrain::fill_vertices(), SoftToEggConverter::FindClosestTriVert(), from_os_specific_w(), ExecutionEnvironment::get_cwd(), AudioManager::get_dls_pathname(), ProgramBase::get_exec_command(), VirtualFileSystem::get_global_ptr(), get_home_directory(), WithOutputFile::get_output_filename(), MayaShaderColorDef::get_panda_uvset_name(), WindowFramework::load_models(), PandaIOSystem::Open(), PandaFramework::open_framework(), ProgramBase::parse_command_line(), EggReader::pre_process_egg_file(), PfmBba::process_pfm(), ConfigPageManager::reload_implicit_pages(), RocketRenderInterface::render(), RocketFileInterface::RocketFileInterface(), FltExternalReference::set_ref_filename(), temporary(), and FltTexture::write_attr_data().
|
static |
The wide-string variant of from_os_specific().
Returns a new Filename, converted from an os-specific wide-character string.
Definition at line 401 of file filename.cxx.
References expand_from(), from_os_specific(), get_filesystem_encoding(), TextEncoder::get_text(), TextEncoder::set_encoding(), and TextEncoder::set_wtext().
Referenced by MaxToEggConverter::convert(), from_os_specific(), get_common_appdata_directory(), ExecutionEnvironment::get_cwd(), get_home_directory(), get_temp_directory(), get_user_appdata_directory(), and make_true_case().
time_t Filename::get_access_timestamp | ( | ) | const |
Returns a time_t value that represents the time the file was last accessed, if this information is available.
See also get_timestamp(), which returns the last modification time.
Definition at line 1636 of file filename.cxx.
References get_file_size(), get_filename_index(), to_os_specific(), and to_os_specific_w().
Referenced by get_timestamp().
|
inline |
Returns the basename part of the filename.
This is everything in the filename after the rightmost slash, including any extensions.
Definition at line 436 of file filename.I.
References get_fullpath_wo_extension().
Referenced by GraphicsPipeSelection::add_pipe_type(), EggCharacterCollection::check_errors(), CVSCopy::continue_after_error(), Texture::ensure_loader_type(), Texture::finalize(), BamCache::flush_index(), PathReplace::full_convert_path(), ConfigVariableFilename::get_basename(), get_dirname(), TexturePool::get_global_ptr(), EggPalettize::handle_args(), CVSCopy::import(), OpenALAudioManager::is_valid(), VirtualFile::ls(), VirtualFileSystem::parse_option(), EggMultiBase::post_process_egg_files(), EggReader::pre_process_egg_file(), PfmTrans::process_pfm(), EggFile::read_egg(), CVSSourceTree::scan(), STBasicTerrain::setup_terrain(), PathReplace::store_path(), LoaderFileTypeStf::supports_compressed(), LoaderFileTypeSrt::supports_compressed(), TextureReference::update_egg(), PartBundle::write(), and EggFile::write_texture_refs().
|
inline |
Returns the basename part of the filename, without the file extension.
Definition at line 460 of file filename.I.
References get_extension().
Referenced by EggSaver::add_node(), Texture::adjust_this_size(), MayaShader::bind_uvsets(), XFileToEggConverter::convert_file(), SoftToEggConverter::convert_file(), MayaToEggConverter::convert_file(), Texture::ensure_loader_type(), TextureReference::from_egg(), ConfigVariableFilename::get_basename_wo_extension(), ProgramBase::get_exec_command(), get_fullpath_wo_extension(), EggTexture::is_equivalent_to(), BamCache::list_index(), WindowFramework::load_model(), Texture::load_related(), ProgramBase::parse_command_line(), PfmTrans::process_pfm(), EggGroupNode::rebuild_vertex_pools(), ProgramBase::show_usage(), EggTexture::sorts_less_than(), PartBundle::write(), ParametricCurveCollection::write_egg(), ParametricCurve::write_egg(), and ProgramBase::write_man_page().
|
static |
Returns a path to a system-defined directory appropriate for creating a subdirectory for storing application-specific data, common to all users.
Definition at line 662 of file filename.cxx.
References AtomicAdjustDummyImpl::compare_and_exchange_ptr(), from_os_specific_w(), ExecutionEnvironment::get_cwd(), AtomicAdjustDummyImpl::get_ptr(), is_directory(), make_canonical(), set_basename(), set_dirname(), and set_fullpath().
Referenced by ExecutionEnvironment::get_cwd(), and get_user_appdata_directory().
|
inline |
Returns the directory part of the filename.
This is everything in the filename up to, but not including the rightmost slash.
Definition at line 424 of file filename.I.
References get_basename().
Referenced by SpeedTreeNode::add_from_stf(), DaeMaterials::add_material_instance(), SomethingToEgg::add_merge_externals_options(), atomic_read_contents(), Shader::compile_parameter(), CVSCopy::continue_after_error(), MaxToEggConverter::convert(), FltHeader::convert_path(), SoftToEggConverter::convert_soft(), MayaPview::creator(), Texture::finalize(), ExecutionEnvironment::get_cwd(), ConfigVariableFilename::get_dirname(), get_fullpath_w(), EggPalettize::handle_args(), EggTexture::is_equivalent_to(), FilenameUnifier::make_canonical(), make_dir(), VirtualFileSystem::parse_option(), EggMultiBase::post_process_egg_files(), EggReader::pre_process_egg_file(), PaletteGroup::prepare(), EggFile::read_egg(), rename_to(), Multifile::repack(), LoaderFileTypePandatool::resolve_filename(), FilenameUnifier::set_txa_filename(), STBasicTerrain::setup_terrain(), EggTexture::sorts_less_than(), and SpeedTreeNode::InstanceList::write_datagram().
|
inline |
Returns the file extension.
This is everything after the rightmost dot, if there is one, or the empty string if there is not.
Definition at line 477 of file filename.I.
References set_binary().
Referenced by Texture::adjust_this_size(), FmodAudioSound::FmodAudioSound(), get_basename_wo_extension(), ConfigVariableFilename::get_extension(), TexturePool::get_global_ptr(), WithOutputFile::get_output(), WithOutputFile::get_output_filename(), EggTexture::is_equivalent_to(), is_executable(), BamCache::list_index(), MovieTypeRegistry::load_audio_types(), WindowFramework::load_model(), VirtualFileSimple::open_read_file(), VirtualFileSimple::open_write_file(), VirtualFileSystem::parse_option(), PaletteGroup::prepare(), VirtualFileSimple::read_file(), VirtualFileSystem::resolve_filename(), resolve_filename(), EggTexture::sorts_less_than(), ShaderPool::write(), XFile::write(), MayaApi::write(), FontPool::write(), VirtualFileSimple::write_file(), and FltHeader::write_flt().
streamsize Filename::get_file_size | ( | ) | const |
Returns the size of the file in bytes, or 0 if there is an error.
Definition at line 1665 of file filename.cxx.
References get_filename_index(), resolve_filename(), to_os_specific(), and to_os_specific_w().
Referenced by get_access_timestamp(), VirtualFileMountSystem::get_file_size(), and VirtualFileMountSystem::get_system_info().
Filename Filename::get_filename_index | ( | int | index | ) | const |
If the pattern flag is set for this Filename and the filename string actually includes a sequence of hash marks, then this returns a new Filename with the sequence of hash marks replaced by the indicated index number.
If the pattern flag is not set for this Filename or it does not contain a sequence of hash marks, this quietly returns the original filename.
Definition at line 873 of file filename.cxx.
References set_fullpath(), set_hash_to_end(), and set_pattern().
Referenced by compare_timestamps(), Texture::ensure_loader_type(), exists(), get_access_timestamp(), get_file_size(), get_timestamp(), is_directory(), is_executable(), is_regular_file(), is_writable(), VirtualFileSystem::parse_option(), and set_extension().
|
inlinestatic |
Specifies the default encoding to be used for all subsequent Filenames objects.
See set_filesystem_encoding().
Definition at line 778 of file filename.I.
Referenced by from_os_specific_w(), ExecutionEnvironment::get_cwd(), get_fullpath_w(), pattern_filename(), scan_directory(), set_filesystem_encoding(), to_os_long_name(), to_os_short_name(), and to_os_specific_w().
|
inline |
Returns the entire filename: directory, basename, extension.
This is the same thing returned by the string typecast operator.
Definition at line 398 of file filename.I.
References get_fullpath_w().
Referenced by atomic_read_contents(), MayaPview::doIt(), Filename(), VirtualFileSimple::get_filename(), ConfigVariableFilename::get_fullpath(), get_fullpath_w(), TexturePool::get_global_ptr(), CVSCopy::import(), make_canonical(), make_dir(), make_relative_to(), operator/(), VirtualFileSystem::parse_option(), Multifile::read_subfile(), VirtualFileSystem::scan_mount_points(), BamCache::set_root(), to_os_specific(), SpeedTreeNode::InstanceList::write_datagram(), and TextureImage::write_scale_info().
|
inline |
Returns the entire filename as a wide-character string.
Definition at line 409 of file filename.I.
References get_dirname(), get_filesystem_encoding(), get_fullpath(), TextEncoder::get_wtext(), TextEncoder::set_encoding(), and TextEncoder::set_text().
Referenced by get_fullpath(), and make_true_case().
|
inline |
Returns the full filename–directory and basename parts–except for the extension.
Definition at line 448 of file filename.I.
References get_basename_wo_extension().
Referenced by get_basename(), ConfigVariableFilename::get_fullpath_wo_extension(), and ImageFile::set_filename().
int Filename::get_hash | ( | ) | const |
Returns a hash code that attempts to be mostly unique for different Filenames.
Definition at line 2835 of file filename.cxx.
References atomic_compare_and_exchange_contents().
Referenced by rmdir().
|
inline |
Returns the part of the filename beginning at the hash sequence (if any), and continuing to the end of the filename.
Definition at line 652 of file filename.I.
References is_local().
Referenced by has_hash().
|
static |
Returns a path to the user's home directory, if such a thing makes sense in the current OS, or to the nearest equivalent.
This may or may not be directly writable by the application.
Definition at line 488 of file filename.cxx.
References AtomicAdjustDummyImpl::compare_and_exchange_ptr(), from_os_specific(), from_os_specific_w(), ExecutionEnvironment::get_cwd(), AtomicAdjustDummyImpl::get_ptr(), get_temp_directory(), is_directory(), and make_canonical().
Referenced by ExecutionEnvironment::get_cwd(), get_user_appdata_directory(), and temporary().
|
inline |
Returns the flag indicating whether this is a filename pattern.
See set_pattern().
Definition at line 624 of file filename.I.
References has_hash().
Referenced by atomic_read_contents(), make_dir(), make_true_case(), open_append(), open_read(), open_read_append(), open_read_write(), open_write(), rename_to(), scan_directory(), set_pattern(), to_os_generic(), to_os_long_name(), to_os_short_name(), to_os_specific(), touch(), and unlink().
|
static |
Returns a path to a system-defined temporary directory.
Definition at line 556 of file filename.cxx.
References AtomicAdjustDummyImpl::compare_and_exchange_ptr(), from_os_specific_w(), ExecutionEnvironment::get_cwd(), AtomicAdjustDummyImpl::get_ptr(), get_user_appdata_directory(), is_directory(), make_canonical(), set_basename(), and set_dirname().
Referenced by ExecutionEnvironment::get_cwd(), get_home_directory(), and temporary().
time_t Filename::get_timestamp | ( | ) | const |
Returns a time_t value that represents the time the file was last modified, to within whatever precision the operating system records this information (on a Windows95 system, for instance, this may only be accurate to within 2 seconds).
If the timestamp cannot be determined, either because it is not supported by the operating system or because there is some error (such as file not found), returns 0.
Definition at line 1605 of file filename.cxx.
References get_access_timestamp(), get_filename_index(), to_os_specific(), and to_os_specific_w().
Referenced by compare_timestamps(), VirtualFileMountSystem::get_timestamp(), and Multifile::open_read_write().
|
inline |
Returns the type of the file represented by the filename, as previously set by set_type().
Definition at line 583 of file filename.I.
References set_pattern().
Referenced by BamCache::list_index(), VirtualFileSystem::parse_option(), set_type(), and to_os_specific().
|
static |
Returns a path to a system-defined directory appropriate for creating a subdirectory for storing application-specific data, specific to the current user.
Definition at line 609 of file filename.cxx.
References AtomicAdjustDummyImpl::compare_and_exchange_ptr(), from_os_specific_w(), get_common_appdata_directory(), ExecutionEnvironment::get_cwd(), get_home_directory(), AtomicAdjustDummyImpl::get_ptr(), is_directory(), make_canonical(), set_basename(), and set_dirname().
Referenced by ExecutionEnvironment::get_cwd(), and get_temp_directory().
|
inline |
Returns true if the filename is indicated to be a filename pattern (that is, set_pattern(true) was called), and the filename pattern did include a sequence of hash marks, or false if it was not a filename pattern or did not include hash marks.
If this is true, then get_filename_index() will return a different filename each time.
Definition at line 640 of file filename.I.
References get_hash_to_end().
Referenced by Texture::ensure_loader_type(), and get_pattern().
|
inline |
Returns true if the Filename has been indicated to represent a binary file via a previous call to set_binary().
It is possible that neither is_binary() nor is_text() will be true, if neither set_binary() nor set_text() was ever called.
Definition at line 521 of file filename.I.
References is_binary_or_text().
Referenced by Multifile::compare_subfile(), and set_text().
|
inline |
Returns true either is_binary() or is_text() is true; that is, that the filename has been specified as either binary or text.
If this is false, the filename has not been specified.
Definition at line 534 of file filename.I.
References is_text().
Referenced by Multifile::add_subfile(), is_binary(), open_append(), open_read(), open_read_append(), open_read_write(), open_write(), and Multifile::update_subfile().
bool Filename::is_directory | ( | ) | const |
Returns true if the filename exists and is a directory name, false otherwise.
Definition at line 1456 of file filename.cxx.
References get_filename_index(), is_executable(), to_os_specific(), and to_os_specific_w().
Referenced by get_common_appdata_directory(), get_home_directory(), MayaShaderColorDef::get_panda_uvset_name(), get_temp_directory(), get_user_appdata_directory(), VirtualFileMountSystem::is_directory(), is_writable(), VirtualFileSystem::mount(), and ConfigPageManager::reload_implicit_pages().
bool Filename::is_executable | ( | ) | const |
Returns true if the filename exists and is executable.
Definition at line 1487 of file filename.cxx.
References compare_timestamps(), exists(), get_extension(), get_filename_index(), and to_os_specific().
Referenced by is_directory(), and ConfigPageManager::reload_implicit_pages().
|
inline |
Returns true if the filename is fully qualified, e.g.
begins with a slash. This is almost, but not quite, the same thing as !is_local(). It's not exactly the same because a special case is made for filenames that begin with a single dot followed by a slash–these are considered to be fully qualified (they are explicitly relative to the current directory, and do not refer to a filename on a search path somewhere).
Definition at line 682 of file filename.I.
References __nonzero__().
Referenced by DSearchPath::find_all_files(), VirtualFileSystem::find_all_files(), VirtualFileSystem::find_file(), DSearchPath::find_file(), PathReplace::full_convert_path(), is_local(), WindowFramework::load_model(), PathReplace::match_path(), EggData::resolve_egg_filename(), and WinGraphicsWindow::static_window_proc().
|
inline |
Returns true if the filename is local, e.g.
does not begin with a slash, or false if the filename is fully specified from the root.
Definition at line 664 of file filename.I.
References is_fully_qualified().
Referenced by STBasicTerrain::fill_vertices(), DSearchPath::find_all_files(), VirtualFileSystem::find_all_files(), VirtualFileSystem::find_file(), DSearchPath::find_file(), EggGroupNode::force_filenames(), PathReplace::full_convert_path(), TexturePool::get_global_ptr(), get_hash_to_end(), EggGroupNode::has_absolute_pathnames(), make_absolute(), GlobPattern::match_files(), PathReplace::match_path(), VirtualFileSystem::parse_option(), VirtualFileSystem::resolve_filename(), resolve_filename(), VirtualFileSystem::scan_mount_points(), BamCache::set_root(), BamCache::store(), and PathReplace::store_path().
bool Filename::is_regular_file | ( | ) | const |
Returns true if the filename exists and is the name of a regular file (i.e.
not a directory or device), false otherwise.
Definition at line 1389 of file filename.cxx.
References get_filename_index(), is_writable(), to_os_specific(), and to_os_specific_w().
Referenced by exists(), VirtualFileMountSystem::is_regular_file(), LoaderFileTypeStf::supports_compressed(), and LoaderFileTypeSrt::supports_compressed().
|
inline |
Returns true if the Filename has been indicated to represent a text file via a previous call to set_text().
It is possible that neither is_binary() nor is_text() will be true, if neither set_binary() nor set_text() was ever called.
Definition at line 548 of file filename.I.
References set_type().
Referenced by Multifile::add_subfile(), Multifile::compare_subfile(), is_binary_or_text(), VirtualFileMount::make_virtual_file(), open_append(), open_read(), open_read_append(), open_read_write(), open_write(), VirtualFileSystem::parse_option(), and Multifile::update_subfile().
bool Filename::is_writable | ( | ) | const |
Returns true if the filename exists and is either a directory or a regular file that can be written to, or false otherwise.
Definition at line 1422 of file filename.cxx.
References get_filename_index(), is_directory(), to_os_specific(), and to_os_specific_w().
Referenced by is_regular_file(), and VirtualFileMountSystem::is_writable().
void Filename::make_absolute | ( | ) |
Converts the filename to a fully-qualified pathname from the root (if it is a relative pathname), and then standardizes it (see standardize()).
This is sometimes a little problematic, since it may convert the file to its 'true' absolute pathname, which could be an ugly NFS-named file, irrespective of symbolic links (e.g. /.automount/dimbo/root/usr2/fit/people/drose instead of /fit/people/drose); besides being ugly, filenames like this may not be consistent across multiple different platforms.
Definition at line 1019 of file filename.cxx.
References ExecutionEnvironment::get_cwd(), is_local(), and standardize().
Referenced by BamCacheRecord::add_dependent_file(), SpeedTreeNode::add_from_stf(), Texture::finalize(), find_on_searchpath(), EggFile::from_command_line(), PathReplace::full_convert_path(), FilenameUnifier::get_bam_filename(), ExecutionEnvironment::get_cwd(), BamCache::set_root(), standardize(), PathReplace::store_path(), and SpeedTreeNode::InstanceList::write_datagram().
void Filename::make_absolute | ( | const Filename & | start_directory | ) |
Converts the filename to a fully-qualified filename from the root (if it is a relative filename), and then standardizes it (see standardize()).
This flavor accepts a specific starting directory that the filename is known to be relative to.
Definition at line 1037 of file filename.cxx.
References is_local(), make_canonical(), and standardize().
bool Filename::make_canonical | ( | ) |
Converts this filename to a canonical name by replacing the directory part with the fully-qualified directory part.
This is done by changing to that directory and calling getcwd().
This has the effect of (a) converting relative paths to absolute paths (but see make_absolute() if this is the only effect you want), and (b) always resolving a given directory name to the same string, even if different symbolic links are traversed, and (c) changing nice symbolic-link paths like /fit/people/drose to ugly NFS automounter names like /hosts/dimbo/usr2/fit/people/drose. This can be troubling, but sometimes this is exactly what you want, particularly if you're about to call make_relative_to() between two filenames.
The return value is true if successful, or false on failure (usually because the directory name does not exist or cannot be chdir'ed into).
Definition at line 1072 of file filename.cxx.
References ExecutionEnvironment::get_cwd(), get_fullpath(), and make_true_case().
Referenced by DaeMaterials::add_material_instance(), PandaIOSystem::ComparePaths(), get_common_appdata_directory(), get_home_directory(), get_temp_directory(), get_user_appdata_directory(), make_absolute(), FilenameUnifier::make_canonical(), ConfigPageManager::reload_implicit_pages(), and CVSSourceTree::restore_cwd().
bool Filename::make_dir | ( | ) | const |
Creates all the directories in the path to the file specified in the filename, except for the basename itself.
This assumes that the Filename contains the name of a file, not a directory name; it ensures that the directory containing the file exists.
However, if the filename ends in a slash, it assumes the Filename represents the name of a directory, and creates all the paths.
Definition at line 2730 of file filename.cxx.
References get_dirname(), get_fullpath(), get_pattern(), mkdir(), to_os_specific(), and to_os_specific_w().
Referenced by copy_to(), WithOutputFile::get_output(), Extractor::step(), ImageFile::write(), and EggFile::write_egg().
bool Filename::make_relative_to | ( | Filename | directory, |
bool | allow_backups = true |
||
) |
Adjusts this filename, which must be a fully-specified pathname beginning with a slash, to make it a relative filename, relative to the fully-specified directory indicated (which must also begin with, and may or may not end with, a slash–a terminating slash is ignored).
This only performs a string comparsion, so it may be wise to call make_canonical() on both filenames before calling make_relative_to().
If allow_backups is false, the filename will only be adjusted to be made relative if it is already somewhere within or below the indicated directory. If allow_backups is true, it will be adjusted in all cases, even if this requires putting a series of ../ characters before the filename–unless it would have to back all the way up to the root.
Returns true if the file was adjusted, false if it was not.
Definition at line 1766 of file filename.cxx.
References find_on_searchpath(), get_fullpath(), and standardize().
Referenced by DaeMaterials::add_material_instance(), Texture::finalize(), find_on_searchpath(), PathReplace::full_convert_path(), FilenameUnifier::make_bam_filename(), FilenameUnifier::make_egg_filename(), FilenameUnifier::make_user_filename(), resolve_filename(), BamCache::set_root(), VirtualFile::simple_read_file(), BamCache::store(), PathReplace::store_path(), and SpeedTreeNode::InstanceList::write_datagram().
bool Filename::make_true_case | ( | ) |
On a case-insensitive operating system (e.g.
Windows), this method looks up the file in the file system and resets the Filename to represent the actual case of the file as it exists on the disk. The return value is true if the file exists and the conversion can be made, or false if there is some error.
On a case-sensitive operating system, this method does nothing and always returns true.
An empty filename is considered to exist in this case.
Definition at line 1120 of file filename.cxx.
References from_os_specific_w(), get_fullpath_w(), get_pattern(), to_os_specific(), to_os_specific_w(), and TextEncoder::unicode_tolower().
Referenced by expand_from(), ExecutionEnvironment::get_cwd(), AudioManager::get_dls_pathname(), VirtualFileMountSystem::has_file(), make_canonical(), and ConfigPageManager::reload_implicit_pages().
bool Filename::mkdir | ( | ) | const |
Creates the directory named by this filename.
Unlike make_dir(), this assumes that the Filename contains the directory name itself. Also, parent directories are not automatically created; this function fails if any parent directory is missing.
Definition at line 2789 of file filename.cxx.
References rmdir(), to_os_specific(), and to_os_specific_w().
Referenced by make_dir(), and VirtualFileMountSystem::make_directory().
bool Filename::open_append | ( | ofstream & | stream | ) | const |
Opens the indicated ofstream for writing the file, if possible.
Returns true if successful, false otherwise. This requires the setting of the set_text()/set_binary() flags to open the file appropriately as indicated; it is an error to call open_read() without first calling one of set_text() or set_binary().
Definition at line 2101 of file filename.cxx.
References get_pattern(), is_binary_or_text(), is_text(), open_read_write(), to_os_specific(), and to_os_specific_w().
Referenced by MultiplexStream::add_file(), VirtualFileMountSystem::open_append_file(), open_read_append(), open_write(), and touch().
bool Filename::open_read | ( | ifstream & | stream | ) | const |
Opens the indicated ifstream for reading the file, if possible.
Returns true if successful, false otherwise. This requires the setting of the set_text()/set_binary() flags to open the file appropriately as indicated; it is an error to call open_read() without first calling one of set_text() or set_binary().
Definition at line 2003 of file filename.cxx.
References get_pattern(), is_binary_or_text(), is_text(), open_write(), to_os_specific(), and to_os_specific_w().
Referenced by Multifile::compare_subfile(), CVSCopy::continue_after_error(), DatagramOutputFile::copy_datagram(), copy_to(), open_read_append(), VirtualFileMountSystem::open_read_file(), FfmpegVirtualFile::open_subfile(), QtessInputFile::read(), InterrogateDatabase::read(), FltTexture::read_attr_data(), ConfigPageManager::reload_implicit_pages(), scan_directory(), and Extractor::set_multifile().
bool Filename::open_read_append | ( | fstream & | stream | ) | const |
Opens the indicated ifstream for reading and writing the file, if possible; writes are appended to the end of the file.
Returns true if successful, false otherwise. This requires the setting of the set_text()/set_binary() flags to open the file appropriately as indicated; it is an error to call open_read() without first calling one of set_text() or set_binary().
Definition at line 2196 of file filename.cxx.
References exists(), get_pattern(), is_binary_or_text(), is_text(), open_append(), open_read(), open_read_write(), open_write(), to_os_specific(), to_os_specific_w(), and touch().
Referenced by VirtualFileMountSystem::open_read_append_file(), and open_read_write().
bool Filename::open_read_write | ( | fstream & | stream, |
bool | truncate = false |
||
) | const |
Opens the indicated fstream for read/write access to the file, if possible.
Returns true if successful, false otherwise. This requires the setting of the set_text()/set_binary() flags to open the file appropriately as indicated; it is an error to call open_read_write() without first calling one of set_text() or set_binary().
Definition at line 2143 of file filename.cxx.
References exists(), get_pattern(), is_binary_or_text(), is_text(), open_read_append(), to_os_specific(), to_os_specific_w(), and touch().
Referenced by open_append(), open_read_append(), Multifile::open_read_write(), and VirtualFileMountSystem::open_read_write_file().
bool Filename::open_write | ( | ofstream & | stream, |
bool | truncate = true |
||
) | const |
Opens the indicated ifstream for writing the file, if possible.
Returns true if successful, false otherwise. This requires the setting of the set_text()/set_binary() flags to open the file appropriately as indicated; it is an error to call open_read() without first calling one of set_text() or set_binary().
If truncate is true, the file is truncated to zero length upon opening it, if it already exists. Otherwise, the file is kept at its original length.
Definition at line 2045 of file filename.cxx.
References exists(), get_pattern(), is_binary_or_text(), is_text(), open_append(), to_os_specific(), and to_os_specific_w().
Referenced by Notify::config_initialized(), CVSCopy::continue_after_error(), copy_to(), VirtualFileMountSystem::create_file(), WithOutputFile::get_output(), open_read(), open_read_append(), Multifile::open_write(), VirtualFileMountSystem::open_write_file(), PfmBba::process_pfm(), PfmTrans::process_pfm(), Multifile::repack(), DatagramInputFile::save_datagram(), DownloadDb::set_server_multifile_hash(), Extractor::step(), XFile::write(), PfmFile::write(), DCFile::write(), FltTexture::write_attr_data(), ParametricCurveCollection::write_egg(), ParametricCurve::write_egg(), and FltHeader::write_flt().
|
inline |
Returns a new Filename representing the concatenation of the two filenames.
Definition at line 372 of file filename.I.
References operator/().
Referenced by operator+=().
|
inline |
Appends the other filename onto the end of this one.
This does not introduce an intervening slash, but see the Filename constructor that takes two parameters.
Definition at line 358 of file filename.I.
References operator+().
Referenced by pattern_filename().
Returns a new Filename that is composed of the other filename added to the end of this filename, with an intervening slash added if necessary.
Definition at line 386 of file filename.I.
References get_fullpath().
Referenced by operator+().
|
inlinestatic |
Constructs a filename that represents a sequence of numbered files.
See set_pattern().
Definition at line 179 of file filename.I.
References get_filesystem_encoding(), TextEncoder::get_text(), operator+=(), TextEncoder::set_encoding(), set_pattern(), and TextEncoder::set_wtext().
Referenced by Texture::ensure_loader_type().
bool Filename::rename_to | ( | const Filename & | other | ) | const |
Renames the file to the indicated new filename.
If the new filename is in a different directory, this will perform a move. Returns true if successful, false on failure.
Definition at line 2577 of file filename.cxx.
References copy_to(), get_dirname(), get_pattern(), set_binary(), temporary(), to_os_specific(), to_os_specific_w(), and unlink().
Referenced by EggPalettize::handle_args(), VirtualFileMountSystem::rename_file(), Multifile::repack(), and unlink().
bool Filename::resolve_filename | ( | const DSearchPath & | searchpath, |
const string & | default_extension = string() |
||
) |
Searches the given search path for the filename.
If it is found, updates the filename to the full pathname found and returns true; otherwise, returns false.
Definition at line 1699 of file filename.cxx.
References exists(), DSearchPath::find_file(), get_extension(), is_local(), make_relative_to(), and set_extension().
Referenced by SpeedTreeNode::add_from_stf(), get_file_size(), EggReader::pre_process_egg_file(), LoaderFileTypePandatool::resolve_filename(), and WinGraphicsWindow::static_window_proc().
bool Filename::rmdir | ( | ) | const |
The inverse of mkdir(): this removes the directory named by this Filename, if it is in fact a directory.
Definition at line 2808 of file filename.cxx.
References get_hash(), to_os_specific(), and to_os_specific_w().
Referenced by VirtualFileMountSystem::delete_file(), and mkdir().
bool Filename::scan_directory | ( | vector_string & | contents | ) | const |
Attempts to open the named filename as if it were a directory and looks for the non-hidden files within the directory.
Fills the given vector up with the sorted list of filenames that are local to this directory.
It is the user's responsibility to ensure that the contents vector is empty before making this call; otherwise, the new files will be appended to it.
Returns true on success, false if the directory could not be read for some reason.
Definition at line 1854 of file filename.cxx.
References get_filesystem_encoding(), get_pattern(), TextEncoder::get_text(), open_read(), TextEncoder::set_encoding(), TextEncoder::set_wtext(), and to_os_specific_w().
Referenced by find_on_searchpath(), GlobPattern::match_files(), ConfigPageManager::reload_implicit_pages(), CVSSourceDirectory::scan(), and VirtualFileMountSystem::scan_directory().
void Filename::set_basename | ( | const string & | s | ) |
Replaces the basename part of the filename.
This is everything in the filename after the rightmost slash, including any extensions.
Definition at line 779 of file filename.cxx.
References set_fullpath_wo_extension().
Referenced by get_common_appdata_directory(), get_temp_directory(), get_user_appdata_directory(), and set_dirname().
void Filename::set_basename_wo_extension | ( | const string & | s | ) |
Replaces the basename part of the filename, without the file extension.
Definition at line 813 of file filename.cxx.
References set_extension().
Referenced by BamCache::list_index(), Texture::load_related(), and set_fullpath_wo_extension().
|
inline |
Indicates that the filename represents a binary file.
This is primarily relevant to the read_file() and write_file() methods, so they can set the appropriate flags to the OS.
Definition at line 494 of file filename.I.
References set_text().
Referenced by Multifile::add_subfile(), Multifile::compare_subfile(), CVSCopy::continue_after_error(), VirtualFileMountSystem::create_file(), Multifile::extract_subfile(), FmodAudioSound::FmodAudioSound(), get_extension(), TexturePool::get_global_ptr(), WithOutputFile::get_output(), VirtualFileMount::make_virtual_file(), DatagramInputFile::open(), DatagramOutputFile::open(), IffInputFile::open_read(), Multifile::open_read(), VirtualFileSimple::open_read_file(), Multifile::open_read_write(), FfmpegVirtualFile::open_subfile(), FfmpegVirtualFile::open_vfs(), Multifile::open_write(), VirtualFileSimple::open_write_file(), VirtualFileSystem::parse_option(), VirtualFileSimple::read_file(), FltHeader::read_flt(), ConfigPageManager::reload_implicit_pages(), rename_to(), Multifile::repack(), DatagramInputFile::save_datagram(), DownloadDb::set_server_multifile_hash(), set_type(), Extractor::step(), BamCache::store(), Multifile::update_subfile(), XFile::write(), FltTexture::write_attr_data(), VirtualFileSimple::write_file(), and FltHeader::write_flt().
void Filename::set_dirname | ( | const string & | s | ) |
Replaces the directory part of the filename.
This is everything in the filename up to, but not including the rightmost slash.
Definition at line 726 of file filename.cxx.
References set_basename().
Referenced by atomic_read_contents(), get_common_appdata_directory(), get_temp_directory(), get_user_appdata_directory(), EggPalettize::handle_args(), FilenameUnifier::make_canonical(), EggReader::pre_process_egg_file(), and set_fullpath().
void Filename::set_extension | ( | const string & | s | ) |
Replaces the file extension.
This is everything after the rightmost dot, if there is one, or the empty string if there is not.
Definition at line 837 of file filename.cxx.
References get_filename_index().
Referenced by MayaPview::doIt(), EggPalettize::handle_args(), SomethingToEggConverter::handle_external_reference(), EggReader::pre_process_egg_file(), PfmBba::process_pfm(), VirtualFileSystem::resolve_filename(), resolve_filename(), set_basename_wo_extension(), ImageFile::set_filename(), BamCache::set_root(), and BamCache::store().
|
inlinestatic |
Specifies the default encoding to be used for all subsequent Filenames.
This is used to represent wide-character (Unicode) filenames internally. On non-Windows-based systems, the encoded filename is also passed to the underlying operating system.
Definition at line 766 of file filename.I.
References get_filesystem_encoding().
Referenced by __nonzero__().
void Filename::set_fullpath | ( | const string & | s | ) |
Replaces the entire filename: directory, basename, extension.
This can also be achieved with the assignment operator.
Definition at line 714 of file filename.cxx.
References set_dirname().
Referenced by MayaToEggConverter::clear(), get_common_appdata_directory(), and get_filename_index().
void Filename::set_fullpath_wo_extension | ( | const string & | s | ) |
Replaces the full filename–directory and basename parts–except for the extension.
Definition at line 793 of file filename.cxx.
References set_basename_wo_extension().
Referenced by set_basename().
void Filename::set_hash_to_end | ( | const string & | s | ) |
Replaces the part of the filename from the beginning of the hash sequence to the end of the filename.
Definition at line 895 of file filename.cxx.
References extract_components().
Referenced by get_filename_index().
|
inline |
Sets the flag indicating whether this is a filename pattern.
When this is true, the filename is understood to be a placeholder for a numbered sequence of filename, such as an image sequence. In this case, a sequence of one or more hash characters ("#") should appear in the filename string; these characters will be filled in with the corresponding number (or more) of digits representing the sequence number. Sequence numbers always begin counting at 0.
When this is true, methods like has_hash() and get_hash_to_end() and get_filename_index() may be called. Methods like is_exists() will implicitly test for existance of filename sequence 0.
Definition at line 606 of file filename.I.
References get_pattern().
Referenced by get_filename_index(), TexturePool::get_global_ptr(), get_type(), and pattern_filename().
|
inline |
Indicates that the filename represents a text file.
This is primarily relevant to the read_file() and write_file() methods, so they can set the appropriate flags to the OS.
Definition at line 507 of file filename.I.
References is_binary().
Referenced by MultiplexStream::add_file(), Multifile::compare_subfile(), Notify::config_initialized(), WithOutputFile::get_output(), VirtualFileMount::make_virtual_file(), VirtualFileSystem::parse_option(), DXFFile::process(), PfmTrans::process_pfm(), PfmBba::process_pfm(), XFile::read(), DCFile::read(), EggData::read(), InterrogateDatabase::read(), ConfigPageManager::reload_implicit_pages(), set_binary(), DCFile::write(), EggData::write_egg(), ParametricCurveCollection::write_egg(), and ParametricCurve::write_egg().
|
inline |
Sets the type of the file represented by the filename.
This is useful for to_os_specific(), resolve_filename(), test_existence(), and all such real-world access functions. It helps the Filename know how to map the internal filename to the OS-specific filename (for instance, maybe executables should have an .exe extension).
Definition at line 564 of file filename.I.
References get_type(), and set_binary().
Referenced by from_os_specific(), is_text(), VirtualFileSystem::parse_option(), and temporary().
void Filename::standardize | ( | ) |
Converts the filename to standard form by replacing consecutive slashes with a single slash, removing a trailing slash if present, and backing up over ../ sequences within the filename where possible.
Definition at line 945 of file filename.cxx.
References make_absolute().
Referenced by extract_components(), make_absolute(), make_relative_to(), VirtualFileSystem::parse_option(), Multifile::read_subfile(), ImageFile::set_filename(), and to_os_specific().
|
static |
Generates a temporary filename within the indicated directory, using the indicated prefix.
If the directory is empty, a system-defined directory is chosen instead.
The generated filename did not exist when the Filename checked, but since it does not specifically create the file, it is possible that another process could simultaneously create a file by the same name.
Definition at line 439 of file filename.cxx.
References exists(), from_os_specific(), get_home_directory(), get_temp_directory(), and set_type().
Referenced by MayaPview::doIt(), expand_from(), BamCache::flush_index(), EggPalettize::handle_args(), rename_to(), Multifile::repack(), and DatagramInputFile::save_datagram().
string Filename::to_os_generic | ( | ) | const |
This is similar to to_os_specific(), but it is designed to generate a filename that can be understood on as many platforms as possible.
Since Windows can usually understand a forward-slash-delimited filename, this means it does the same thing as to_os_specific(), but it uses forward slashes instead of backslashes.
This method has a pretty limited use; it should generally be used for writing file references to a file that might be read on any operating system.
Definition at line 1261 of file filename.cxx.
References get_pattern(), to_os_short_name(), and to_os_specific().
Referenced by DaeMaterials::add_material_instance(), MayaApi::read(), MayaShaderColorDef::reset_maya_texture(), FltExternalReference::set_ref_filename(), FltTexture::set_texture_filename(), to_os_specific_w(), and MayaApi::write().
string Filename::to_os_long_name | ( | ) | const |
This is the opposite of to_os_short_name(): it returns the "long name" of the filename, if the filename exists.
On non-Windows platforms, this returns the same thing as to_os_specific().
Definition at line 1322 of file filename.cxx.
References exists(), get_filesystem_encoding(), get_pattern(), TextEncoder::get_text(), TextEncoder::set_encoding(), TextEncoder::set_wtext(), to_os_specific(), and to_os_specific_w().
Referenced by to_os_short_name().
string Filename::to_os_short_name | ( | ) | const |
This works like to_os_generic(), but it returns the "short name" version of the filename, if it exists, or the original filename otherwise.
On Windows platforms, this returns the 8.3 filename version of the given filename, if the file exists, and the same thing as to_os_specific() otherwise. On non-Windows platforms, this always returns the same thing as to_os_specific().
Definition at line 1285 of file filename.cxx.
References get_filesystem_encoding(), get_pattern(), TextEncoder::get_text(), TextEncoder::set_encoding(), TextEncoder::set_wtext(), to_os_long_name(), to_os_specific(), and to_os_specific_w().
Referenced by to_os_generic().
string Filename::to_os_specific | ( | ) | const |
Converts the filename from our generic Unix-like convention (forward slashes starting with the root at '/') to the corresponding filename in the local operating system (slashes in the appropriate direction, starting with the root at C:\, for instance).
Returns the string representing the converted filename, but does not change the Filename itself.
See also from_os_specific().
Definition at line 1196 of file filename.cxx.
References get_fullpath(), get_pattern(), get_type(), standardize(), and to_os_specific_w().
Referenced by GraphicsPipeSelection::add_pipe_type(), XFileNode::add_TextureFilename(), atomic_compare_and_exchange_contents(), atomic_read_contents(), chdir(), compare_timestamps(), Notify::config_initialized(), DAEToEggConverter::convert_file(), exists(), FmodAudioSound::FmodAudioSound(), get_access_timestamp(), ExecutionEnvironment::get_cwd(), get_file_size(), TexturePool::get_global_ptr(), get_timestamp(), LoaderFileTypeRegistry::get_type_from_extension(), is_directory(), is_executable(), is_regular_file(), is_writable(), MovieTypeRegistry::load_audio_types(), MovieTypeRegistry::load_movie_library(), MovieTypeRegistry::load_video_types(), make_dir(), make_true_case(), mkdir(), open_append(), open_read(), open_read_append(), open_read_write(), open_write(), MayaApi::read(), ConfigPageManager::reload_implicit_pages(), rename_to(), CVSSourceTree::restore_cwd(), rmdir(), SpeedTreeNode::set_terrain(), WinGraphicsWindow::static_window_proc(), STTree::STTree(), CVSSourceTree::temp_chdir(), to_os_generic(), to_os_long_name(), to_os_short_name(), to_os_specific_w(), touch(), unlink(), MayaApi::write(), and SpeedTreeNode::write_error().
wstring Filename::to_os_specific_w | ( | ) | const |
The wide-string variant on to_os_specific().
Definition at line 1238 of file filename.cxx.
References get_filesystem_encoding(), TextEncoder::get_wtext(), TextEncoder::set_encoding(), TextEncoder::set_text(), to_os_generic(), and to_os_specific().
Referenced by atomic_compare_and_exchange_contents(), atomic_read_contents(), chdir(), compare_timestamps(), exists(), get_access_timestamp(), get_file_size(), get_timestamp(), is_directory(), is_regular_file(), is_writable(), make_dir(), make_true_case(), mkdir(), open_append(), open_read(), open_read_append(), open_read_write(), open_write(), rename_to(), rmdir(), scan_directory(), to_os_long_name(), to_os_short_name(), to_os_specific(), touch(), and unlink().
bool Filename::touch | ( | ) | const |
Updates the modification time of the file to the current time.
If the file does not already exist, it will be created. Returns true if successful, false if there is an error.
Definition at line 2454 of file filename.cxx.
References chdir(), get_pattern(), open_append(), to_os_specific(), and to_os_specific_w().
Referenced by open_read_append(), open_read_write(), and PhysxKitchen::set_cooking_params().
bool Filename::unlink | ( | ) | const |
Permanently deletes the file associated with the filename, if possible.
Returns true if successful, false if failure (for instance, because the file did not exist, or because permissions were inadequate).
Definition at line 2554 of file filename.cxx.
References get_pattern(), rename_to(), to_os_specific(), and to_os_specific_w().
Referenced by chdir(), CVSCopy::continue_after_error(), copy_to(), VirtualFileMountSystem::delete_file(), MayaPview::doIt(), EggPalettize::handle_args(), Palettizer::read_stale_eggs(), rename_to(), Multifile::repack(), ImageFile::unlink(), PaletteImage::update_filename(), and ImageFile::write().