TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::FileSystem Class Reference

#include <FileSystem.h>

Classes

class  Dir
 
class  Entry
 
class  ListSettings
 

Public Member Functions

void setCacheLifetime (float t)
 

Static Public Member Functions

static void init ()
 
static void cleanup ()
 
static bool inZipfile (const std::string &path, std::string &zipfile)
 
static void clearCache (const std::string &path="")
 
static FILE * fopen (const char *filename, const char *mode)
 
static void fclose (FILE *f)
 
static bool inZipfile (const std::string &path)
 
static void removeFile (const std::string &path)
 Delete this file. No effect if path does not exist. More...
 
static bool isZipfile (const std::string &path)
 
static float cacheLifetime ()
 
static void createDirectory (const std::string &path)
 
static std::string currentDirectory ()
 
static void copyFile (const std::string &srcPath, const std::string &dstPath)
 
static bool exists (const std::string &f, bool trustCache=true, bool caseSensitive=true)
 
static bool isDirectory (const std::string &path)
 
static bool isFile (const std::string &path)
 
static std::string resolve (const std::string &path, const std::string &cwd=currentDirectory())
 
static bool isNewer (const std::string &src, const std::string &dst)
 
static int64 size (const std::string &path)
 
static void list (const std::string &spec, Array< std::string > &result, const ListSettings &listSettings=ListSettings())
 
static void getFiles (const std::string &spec, Array< std::string > &result, bool includeParentPath=false)
 
static void getDirectories (const std::string &spec, Array< std::string > &result, bool includeParentPath=false)
 
static void markFileUsed (const std::string &filename)
 
static const Set< std::string > & usedFiles ()
 

Private Types

enum  Type { UNKNOWN, FILE_TYPE, DIR_TYPE }
 

Private Member Functions

DirgetContents (const std::string &path, bool forceUpdate)
 
 FileSystem ()
 
bool _inZipfile (const std::string &path, std::string &zipfile)
 
void _clearCache (const std::string &path)
 
bool _inZipfile (const std::string &path)
 
void _setCacheLifetime (float t)
 
float _cacheLifetime () const
 
void _createDirectory (const std::string &path)
 
bool _exists (const std::string &f, bool trustCache=true, bool caseSensitive=true)
 
bool _isDirectory (const std::string &path)
 
bool _isFile (const std::string &path)
 
void _copyFile (const std::string &srcPath, const std::string &dstPath)
 
std::string _resolve (const std::string &path, const std::string &cwd=currentDirectory())
 
bool _isNewer (const std::string &src, const std::string &dst)
 
std::string _currentDirectory ()
 
int64 _size (const std::string &path)
 
void listHelper (const std::string &shortSpec, const std::string &parentPath, Array< std::string > &result, const ListSettings &settings)
 
void _list (const std::string &spec, Array< std::string > &result, const ListSettings &listSettings=ListSettings())
 
bool _isZipfile (const std::string &path)
 
void _getFiles (const std::string &spec, Array< std::string > &result, bool includeParentPath=false)
 
void _getDirectories (const std::string &spec, Array< std::string > &result, bool includeParentPath=false)
 
FILE * _fopen (const char *filename, const char *mode)
 
void _removeFile (const std::string &path)
 Delete this file. No effect if path does not exist. More...
 

Static Private Member Functions

static FileSysteminstance ()
 

Private Attributes

Array< std::string > m_winDrive
 
float m_cacheLifetime
 
Table< std::string, Dirm_cache
 

Static Private Attributes

static GMutex mutex
 

Detailed Description

OS-independent file system layer that optimizes the performance of queries by caching and prefetching.

This class uses the following definitions:

  • "file" = document that can be opened for reading or writing
  • "directory" = folder containing files and other directories
  • "node" = file or directory
  • "path" = string identifying a (see the FSPath class)
  • "zipfile" = a compressed file storing an archive of files and directories in the zip format

In G3D, Zipfiles are transparently treated as if they were directories, provided:

  • The zipfile name contains an extension (e.g., map.pk3, files.zip)
  • There are no nested zipfiles

All FileSystem routines invoke FilePath::expandEnvironmentVariables if the input contains a '$'.

The extension requirement allows G3D to quickly identify whether a path could enter a zipfile without forcing it to open all parent directories for reading.

See also
FilePath

Member Enumeration Documentation

enum G3D::FileSystem::Type
private
Enumerator
UNKNOWN 

Not yet checked

FILE_TYPE 
DIR_TYPE 
86  {
88  UNKNOWN,
89  FILE_TYPE,
90  DIR_TYPE
91  };
Definition: FileSystem.h:90
Definition: FileSystem.h:89
Definition: FileSystem.h:88

Constructor & Destructor Documentation

G3D::FileSystem::FileSystem ( )
private

Don't allow public construction.

69 : m_cacheLifetime(10) {}
float m_cacheLifetime
Definition: FileSystem.h:84

+ Here is the caller graph for this function:

Member Function Documentation

float G3D::FileSystem::_cacheLifetime ( ) const
inlineprivate

A cache is used to optimize repeated calls. A cache entry is considered valid for this many seconds after it has been checked.

168  {
169  return m_cacheLifetime;
170  }
float m_cacheLifetime
Definition: FileSystem.h:84

+ Here is the caller graph for this function:

void G3D::FileSystem::_clearCache ( const std::string &  path)
private

Clears old cache entries so that exists() and list() will reflect recent changes to the file system.

Parameters
pathClear only path and its subdirectories ("" means clear the entire cache)
337  {
338  const std::string& path = FilePath::expandEnvironmentVariables(_path);
339 
340  if ((path == "") || FilePath::isRoot(path)) {
341  m_cache.clear();
342  } else {
343  Array<std::string> keys;
344  m_cache.getKeys(keys);
345 
346  const std::string& prefix =
347 # ifdef G3D_WINDOWS
349 # else
351 # endif
352  const std::string& prefixSlash = prefix + "/";
353 
354  for (int k = 0; k < keys.size(); ++k) {
355  const std::string& key = keys[k];
356  if ((key == prefix) || beginsWith(key, prefixSlash)) {
357  m_cache.remove(keys[k]);
358  }
359  }
360  }
361 }
bool beginsWith(const std::string &test, const std::string &pattern)
Returns true if the test string begins with the pattern string.
Definition: stringutils.cpp:81
static std::string expandEnvironmentVariables(const std::string &path)
Replaces $VAR and patterns with the corresponding environment variable. Throws std::string if the en...
Definition: FileSystem.cpp:949
Table< std::string, Dir > m_cache
Definition: FileSystem.h:133
static bool isRoot(const std::string &f)
Definition: FileSystem.cpp:698
static std::string removeTrailingSlash(const std::string &f)
Definition: FileSystem.cpp:736
std::string toLower(const std::string &x)
Definition: stringutils.cpp:223
std::string _resolve(const std::string &path, const std::string &cwd=currentDirectory())
Definition: FileSystem.cpp:508
static std::string canonicalize(std::string x)
Definition: FileSystem.cpp:832

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::FileSystem::_copyFile ( const std::string &  srcPath,
const std::string &  dstPath 
)
private

Parameters
srcPathMust name a file.
dstPathMust not contain a zipfile.

Flushes the cache.

424  {
425  const std::string& source = FilePath::expandEnvironmentVariables(_source);
426  const std::string& dest = FilePath::expandEnvironmentVariables(_dest);
427 # ifdef G3D_WINDOWS
428  // TODO: handle case where srcPath is in a zipfile
429  CopyFileA(source.c_str(), dest.c_str(), FALSE);
431 # else
432  // Read it all in, then dump it out
433  BinaryInput in(source, G3D_LITTLE_ENDIAN);
434  BinaryOutput out(dest, G3D_LITTLE_ENDIAN);
435  out.writeBytes(in.getCArray(), in.size());
436  out.commit(false);
437 # endif
438 }
static std::string expandEnvironmentVariables(const std::string &path)
Replaces $VAR and patterns with the corresponding environment variable. Throws std::string if the en...
Definition: FileSystem.cpp:949
void _clearCache(const std::string &path)
Definition: FileSystem.cpp:337
static std::string parent(const std::string &path)
Definition: FileSystem.cpp:795
std::string _resolve(const std::string &path, const std::string &cwd=currentDirectory())
Definition: FileSystem.cpp:508
Definition: System.h:50

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::FileSystem::_createDirectory ( const std::string &  path)
private

Creates the directory named, including any subdirectories that do not already exist.

The directory must not be inside a zipfile.

Flushes the cache.

369  {
370  const std::string& dir = FilePath::expandEnvironmentVariables(_dir);
371 
372  if (dir == "") {
373  return;
374  }
375 
376  std::string d = _resolve(dir);
377 
378  // Add a trailing / if there isn't one.
379  switch (d[d.size() - 1]) {
380  case '/':
381  case '\\':
382  break;
383 
384  default:
385  d += "/";
386  }
387 
388  // If it already exists, do nothing
390  return;
391  }
392 
393  // Parse the name apart
394  std::string root, base, ext;
395  Array<std::string> path;
396 
397  std::string lead;
398  FilePath::parse(d, root, path, base, ext);
399  debugAssert(base == "");
400  debugAssert(ext == "");
401 
402  // Begin with an extra period so "c:\" becomes "c:\.\" after
403  // appending a path and "c:" becomes "c:.\", not root: "c:\"
404  std::string p = root + ".";
405 
406  // Create any intermediate that doesn't exist
407  for (int i = 0; i < path.size(); ++i) {
408  p += "/" + path[i];
409  if (! _exists(p)) {
410  // Windows only requires one argument to mkdir,
411  // where as unix also requires the permissions.
412 # ifndef G3D_WINDOWS
413  mkdir(p.c_str(), 0777);
414 # else
415  _mkdir(p.c_str());
416 # endif
417  }
418  }
419 
421 }
static std::string expandEnvironmentVariables(const std::string &path)
Replaces $VAR and patterns with the corresponding environment variable. Throws std::string if the en...
Definition: FileSystem.cpp:949
static void parse(const std::string &filename, std::string &drive, Array< std::string > &path, std::string &base, std::string &ext)
Definition: FileSystem.cpp:838
void _clearCache(const std::string &path)
Definition: FileSystem.cpp:337
static std::string parent(const std::string &path)
Definition: FileSystem.cpp:795
#define debugAssert(exp)
Definition: debugAssert.h:160
static std::string removeTrailingSlash(const std::string &f)
Definition: FileSystem.cpp:736
std::string _resolve(const std::string &path, const std::string &cwd=currentDirectory())
Definition: FileSystem.cpp:508
bool _exists(const std::string &f, bool trustCache=true, bool caseSensitive=true)
Definition: FileSystem.cpp:441

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string G3D::FileSystem::_currentDirectory ( )
private

The current working directory (cwd). Only ends in a slash if this is the root of the file system.

542  {
543  static const int N = 2048;
544  char buffer[N];
545 
546  (void)_getcwd(buffer, N);
547  return std::string(buffer);
548 }
#define _getcwd
Definition: FileSystem.cpp:37

+ Here is the caller graph for this function:

bool G3D::FileSystem::_exists ( const std::string &  f,
bool  trustCache = true,
bool  caseSensitive = true 
)
private

Returns true if a node named f exists.

Parameters
fIf f contains wildcards, the function returns true if any file matches those wildcards. Wildcards may only appear in the base or ext, not the path. Environment variables beginning with dollar signs (e.g., in "$G3DDATA/cubemap"), with optional parens ("$(G3DDATA)") are automatically expanded in f. Default share names on Windows (e.g., "\\mycomputer\c$") are correctly distinguished from empty environment variables.
trustCacheIf true, uses the cache for optimizing repeated calls in the same parent directory.
caseSensitiveIf true, the match must have exactly the same case for the base and extension. If false, case is ignored. The default on Windows is false and the default on other operating systems is true.
441  {
442  const std::string& f = FilePath::expandEnvironmentVariables(_f);
443 
444  if (FilePath::isRoot(f)) {
445 # ifdef G3D_WINDOWS
446  const std::string& winname = toLower(f.substr(0, 1)) + ":\\";
447  return _drives().contains(winname);
448 # else
449  return true;
450 # endif
451  }
452 
453  const std::string& path = FilePath::removeTrailingSlash(f);
454  const std::string& parentPath = FilePath::parent(path);
455 
456  const bool forceUpdate = ! trustCache;
457  const Dir& entry = getContents(parentPath, forceUpdate);
458 
460  if (! entry.exists) {
461  // The directory didn't exist, so neither do its contents
462  return false;
463  }
464 
465  const std::string& pattern = FilePath::baseExt(path);
466 
467  // See if any element of entry matches the wild card
468  for (int i = 0; i < entry.nodeArray.size(); ++i) {
469  if (FilePath::matches(entry.nodeArray[i].name, pattern, caseSensitive)) {
470  return true;
471  }
472  }
473 
474  // Could not find a match
475  return false;
476 
477  } else {
478  return entry.exists && entry.contains(FilePath::baseExt(path), caseSensitive);
479  }
480 }
static std::string expandEnvironmentVariables(const std::string &path)
Replaces $VAR and patterns with the corresponding environment variable. Throws std::string if the en...
Definition: FileSystem.cpp:949
static std::string baseExt(const std::string &path)
Definition: FileSystem.cpp:765
static bool containsWildcards(const std::string &p)
Definition: FileSystem.cpp:813
static bool isRoot(const std::string &f)
Definition: FileSystem.cpp:698
static std::string parent(const std::string &path)
Definition: FileSystem.cpp:795
static std::string removeTrailingSlash(const std::string &f)
Definition: FileSystem.cpp:736
std::string toLower(const std::string &x)
Definition: stringutils.cpp:223
static bool matches(const std::string &path, const std::string &pattern, bool caseSensitive=true)
Definition: FileSystem.cpp:818
Dir & getContents(const std::string &path, bool forceUpdate)
Definition: FileSystem.cpp:147

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

FILE * G3D::FileSystem::_fopen ( const char *  filename,
const char *  mode 
)
private

Same as the C standard library fopen, but updates the file cache to acknowledge the new file on a write operation.

321  {
322  const std::string& filename = FilePath::canonicalize(FilePath::expandEnvironmentVariables(_filename));
323 
324  for (const char* m = mode; *m != '\0'; ++m) {
325  if (*m == 'w') {
326  // Purge the cache entry for the parent of this directory
328  break;
329  }
330  }
331 
332  markFileUsed(filename);
333  return ::fopen(filename.c_str(), mode);
334 }
static std::string expandEnvironmentVariables(const std::string &path)
Replaces $VAR and patterns with the corresponding environment variable. Throws std::string if the en...
Definition: FileSystem.cpp:949
void _clearCache(const std::string &path)
Definition: FileSystem.cpp:337
static std::string parent(const std::string &path)
Definition: FileSystem.cpp:795
std::string _resolve(const std::string &path, const std::string &cwd=currentDirectory())
Definition: FileSystem.cpp:508
static std::string canonicalize(std::string x)
Definition: FileSystem.cpp:832
static void markFileUsed(const std::string &filename)
Definition: FileSystem.cpp:553

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::FileSystem::_getDirectories ( const std::string &  spec,
Array< std::string > &  result,
bool  includeParentPath = false 
)
inlineprivate

list() directories

226  {
227  ListSettings set;
228  set.includeParentPath = includeParentPath;
229  set.directories = true;
230  set.files = false;
231  return list(spec, result, set);
232  }
static void list(const std::string &spec, Array< std::string > &result, const ListSettings &listSettings=ListSettings())
Definition: FileSystem.h:479

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::FileSystem::_getFiles ( const std::string &  spec,
Array< std::string > &  result,
bool  includeParentPath = false 
)
inlineprivate

list() files

217  {
218  ListSettings set;
219  set.includeParentPath = includeParentPath;
220  set.directories = false;
221  set.files = true;
222  return list(spec, result, set);
223  }
static void list(const std::string &spec, Array< std::string > &result, const ListSettings &listSettings=ListSettings())
Definition: FileSystem.h:479

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool G3D::FileSystem::_inZipfile ( const std::string &  path,
std::string &  zipfile 
)
private

Returns true if some sub-path of path is a zipfile.

If the path itself is a zipfile, returns false.

Parameters
zipfileThe part of path that was the zipfile
261  {
262  const std::string& path = FilePath::expandEnvironmentVariables(_path);
263 
264  // Reject trivial cases before parsing
265 
266  // Look at all sub-paths containing periods.
267  // For each, ask if it is a zipfile.
268  size_t current = 0;
269  current = path.find('.', current);
270 
271  while (current != std::string::npos) {
272  // xxxxx/foo.zip/yyyyy
273  current = path.find('.', current);
274 
275  // Look forward for the next slash
276  size_t s = findSlash(path, current);
277 
278  if (s == std::string::npos) {
279  // No more slashes
280  return false;
281  }
282 
283  z = path.substr(0, s);
284  if (_isZipfile(z)) {
285  return true;
286  }
287 
288  current = s + 1;
289  }
290 
291  z = "";
292  return false;
293 }
static std::string expandEnvironmentVariables(const std::string &path)
Replaces $VAR and patterns with the corresponding environment variable. Throws std::string if the en...
Definition: FileSystem.cpp:949
G3D::int16 z
Definition: Vector3int16.h:46
size_t findSlash(const std::string &f, size_t start=0)
Definition: stringutils.h:34
bool _isZipfile(const std::string &path)
Definition: FileSystem.cpp:296

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool G3D::FileSystem::_inZipfile ( const std::string &  path)
inlineprivate

Returns true if some sub-path of path is a zipfile.

If the path itself is a zipfile, returns false.

Parameters
zipfileThe part of path that was the zipfile
158  {
159  std::string ignore;
160  return inZipfile(path, ignore);
161  }
static bool inZipfile(const std::string &path, std::string &zipfile)
Definition: FileSystem.h:264

+ Here is the call graph for this function:

bool G3D::FileSystem::_isDirectory ( const std::string &  path)
private

Known bug: does not work inside zipfiles

483  {
484  const std::string& filename = FilePath::expandEnvironmentVariables(_filename);
485  // TODO: work with zipfiles and cache
486  struct _stat st;
487  const bool exists = _stat(FilePath::removeTrailingSlash(filename).c_str(), &st) != -1;
488  return exists && ((st.st_mode & S_IFDIR) != 0);
489 }
#define _stat
Definition: FileSystem.cpp:38
static std::string expandEnvironmentVariables(const std::string &path)
Replaces $VAR and patterns with the corresponding environment variable. Throws std::string if the en...
Definition: FileSystem.cpp:949
static bool exists(const std::string &f, bool trustCache=true, bool caseSensitive=true)
Definition: FileSystem.h:401
static std::string removeTrailingSlash(const std::string &f)
Definition: FileSystem.cpp:736

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool G3D::FileSystem::_isFile ( const std::string &  path)
inlineprivate

Known bug: does not work inside zipfiles

188  {
189  return ! isDirectory(path);
190  }
static bool isDirectory(const std::string &path)
Definition: FileSystem.h:416

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool G3D::FileSystem::_isNewer ( const std::string &  src,
const std::string &  dst 
)
private

Returns true if dst does not exist or src is newer than dst, according to their time stamps.

Known bug: does not work inside zipfiles.

565  {
566  const std::string& src = FilePath::expandEnvironmentVariables(_src);
567  const std::string& dst = FilePath::expandEnvironmentVariables(_dst);
568 
569  // TODO: work with cache and zipfiles
570  struct _stat sts;
571  bool sexists = _stat(src.c_str(), &sts) != -1;
572 
573  struct _stat dts;
574  bool dexists = _stat(dst.c_str(), &dts) != -1;
575 
576  return sexists && ((! dexists) || (sts.st_mtime > dts.st_mtime));
577 }
#define _stat
Definition: FileSystem.cpp:38
static std::string expandEnvironmentVariables(const std::string &path)
Replaces $VAR and patterns with the corresponding environment variable. Throws std::string if the en...
Definition: FileSystem.cpp:949

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool G3D::FileSystem::_isZipfile ( const std::string &  path)
private

Returns true if path is a file that is a zipfile. Note that G3D requires zipfiles to have some extension, although it is not required to be "zip"

296  {
297  const std::string& filename = FilePath::canonicalize(FilePath::expandEnvironmentVariables(_filename));
298 
299 
300 
301  FILE* f = fopen(FilePath::removeTrailingSlash(filename).c_str(), "r");
302  if (f == NULL) {
303  return false;
304  }
305  uint8 header[4];
306  (void)fread(header, 4, 1, f);
307 
308  const uint8 zipHeader[4] = {0x50, 0x4b, 0x03, 0x04};
309  for (int i = 0; i < 4; ++i) {
310  if (header[i] != zipHeader[i]) {
311  fclose(f);
312  return false;
313  }
314  }
315 
316  fclose(f);
317  return true;
318 }
static std::string expandEnvironmentVariables(const std::string &path)
Replaces $VAR and patterns with the corresponding environment variable. Throws std::string if the en...
Definition: FileSystem.cpp:949
static void fclose(FILE *f)
Definition: FileSystem.h:290
arena_t NULL
Definition: jemalloc_internal.h:624
static std::string removeTrailingSlash(const std::string &f)
Definition: FileSystem.cpp:736
static std::string canonicalize(std::string x)
Definition: FileSystem.cpp:832
static FILE * fopen(const char *filename, const char *mode)
Definition: FileSystem.h:282
uint8_t uint8
Definition: Define.h:152

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::FileSystem::_list ( const std::string &  spec,
Array< std::string > &  result,
const ListSettings listSettings = ListSettings() 
)
private

Appends all nodes matching spec to the result array.

Wildcards can only appear to the right of the last slash in spec.

The names will not contain parent paths unless includePath == true. These may be relative to the current directory unless spec is fully qualified (can be done with resolveFilename).

665  {
666  const std::string& spec = FilePath::expandEnvironmentVariables(_spec);
667 
668  const std::string& shortSpec = FilePath::baseExt(spec);
669  const std::string& parentPath = FilePath::parent(spec);
670 
671  listHelper(shortSpec, parentPath, result, settings);
672 }
static std::string expandEnvironmentVariables(const std::string &path)
Replaces $VAR and patterns with the corresponding environment variable. Throws std::string if the en...
Definition: FileSystem.cpp:949
static std::string baseExt(const std::string &path)
Definition: FileSystem.cpp:765
static std::string parent(const std::string &path)
Definition: FileSystem.cpp:795
void listHelper(const std::string &shortSpec, const std::string &parentPath, Array< std::string > &result, const ListSettings &settings)
Definition: FileSystem.cpp:617

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::FileSystem::_removeFile ( const std::string &  path)
private

Delete this file. No effect if path does not exist.

Parameters
pathMay contain wildcards. May not be inside a zipfile.
492  {
493  alwaysAssertM(! inZipfile(path), "Cannot invoke removeFile() on files inside zipfiles.");
494  Array<std::string> files;
495  getFiles(path, files, true);
496 
497  for (int i = 0; i < files.size(); ++i) {
498  const std::string& filename = files[i];
499  int retval = ::remove(filename.c_str());
500  (void)retval;
501  }
502 
503  // Remove from cache
505 }
void _clearCache(const std::string &path)
Definition: FileSystem.cpp:337
static std::string parent(const std::string &path)
Definition: FileSystem.cpp:795
static bool inZipfile(const std::string &path, std::string &zipfile)
Definition: FileSystem.h:264
static void getFiles(const std::string &spec, Array< std::string > &result, bool includeParentPath=false)
Definition: FileSystem.h:488
#define alwaysAssertM(exp, message)
Definition: debugAssert.h:165

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string G3D::FileSystem::_resolve ( const std::string &  path,
const std::string &  cwd = currentDirectory() 
)
private

Fully qualifies a filename.

The filename may contain wildcards, in which case the wildcards will be preserved in the returned value.

Parameters
cwdThe directory to treat as the "current" directory when resolving a relative path. The default value is the actual current directory. (G3D::Any::sourceDirectory is a common alternative)
508  {
509  const std::string& filename = FilePath::expandEnvironmentVariables(_filename);
510  const std::string& cwd = FilePath::expandEnvironmentVariables(_cwd);
511 
512  if (filename.size() >= 1) {
513  if (isSlash(filename[0])) {
514  // Already resolved
515  return filename;
516  } else {
517 
518  #ifdef G3D_WINDOWS
519  if ((filename.size() >= 2) && (filename[1] == ':')) {
520  // There is a drive spec on the front.
521  if ((filename.size() >= 3) && isSlash(filename[2])) {
522  // Already fully qualified
523  return filename;
524  } else {
525  // The drive spec is relative to the
526  // working directory on that drive.
527  debugAssertM(false, "Files of the form d:path are"
528  " not supported (use a fully qualified"
529  " name).");
530  return filename;
531  }
532  }
533  #endif
534  }
535  }
536 
537  // Prepend the working directory.
538  return FilePath::concat(cwd, filename);
539 }
static std::string expandEnvironmentVariables(const std::string &path)
Replaces $VAR and patterns with the corresponding environment variable. Throws std::string if the en...
Definition: FileSystem.cpp:949
static std::string concat(const std::string &a, const std::string &b)
Definition: FileSystem.cpp:743
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
bool isSlash(const unsigned char c)
Definition: stringutils.h:175

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::FileSystem::_setCacheLifetime ( float  t)
private

Set the cacheLifetime().

Parameters
tin seconds
364  {
365  m_cacheLifetime = t;
366 }
float m_cacheLifetime
Definition: FileSystem.h:84

+ Here is the caller graph for this function:

int64 G3D::FileSystem::_size ( const std::string &  path)
private

Returns the length of the file in bytes, or -1 if the file could not be opened.

580  {
581  const std::string& filename = FilePath::canonicalize(FilePath::expandEnvironmentVariables(_filename));
582 
583  struct stat64 st;
584  int result = stat64(filename.c_str(), &st);
585 
586  if (result == -1) {
587 #if _HAVE_ZIP /* G3DFIX: Use ZIP-library only if defined */
588  std::string zip, contents;
589  if (zipfileExists(filename, zip, contents)) {
590  int64 requiredMem;
591 
592  struct zip *z = zip_open( zip.c_str(), ZIP_CHECKCONS, NULL );
593  debugAssertM(z != NULL, zip + ": zip open failed.");
594  {
595  struct zip_stat info;
596  zip_stat_init( &info ); // Docs unclear if zip_stat_init is required.
597  int success = zip_stat( z, contents.c_str(), ZIP_FL_NOCASE, &info );
598  (void) success;
599  debugAssertM(success == 0, zip + ": " + contents + ": zip stat failed.");
600  requiredMem = info.size;
601  }
602  zip_close(z);
603  return requiredMem;
604  } else {
605 #endif
606  return -1;
607 #if _HAVE_ZIP /* G3DFIX: Use ZIP-library only if defined */
608  }
609 #endif
610  }
611 
612  return st.st_size;
613 }
static std::string expandEnvironmentVariables(const std::string &path)
Replaces $VAR and patterns with the corresponding environment variable. Throws std::string if the en...
Definition: FileSystem.cpp:949
int64_t int64
Definition: Define.h:145
arena_t NULL
Definition: jemalloc_internal.h:624
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
G3D::int16 z
Definition: Vector3int16.h:46
static std::string canonicalize(std::string x)
Definition: FileSystem.cpp:832
bool zipfileExists(const std::string &filename, std::string &outZipfile, std::string &outInternalFile)
Definition: fileutils.cpp:335

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static float G3D::FileSystem::cacheLifetime ( )
inlinestatic

A cache is used to optimize repeated calls. A cache entry is considered valid for this many seconds after it has been checked.

341  {
342  mutex.lock();
343  float f = instance()._cacheLifetime();
344  mutex.unlock();
345  return f;
346  }
float _cacheLifetime() const
Definition: FileSystem.h:168
void lock()
Definition: GThread.cpp:248
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256
static FileSystem & instance()
Definition: FileSystem.cpp:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::FileSystem::cleanup ( )
static

Destroy the common instance.

62  {
63  if (common != NULL) {
64  delete common;
65  common = NULL;
66  }
67 }
arena_t NULL
Definition: jemalloc_internal.h:624
static FileSystem * common
Definition: FileSystem.cpp:45
static void G3D::FileSystem::clearCache ( const std::string &  path = "")
inlinestatic

Clears old cache entries so that exists() and list() will reflect recent changes to the file system.

Parameters
pathClear only path and its subdirectories ("" means clear the entire cache)
273  {
274  mutex.lock();
275  instance()._clearCache(path);
276  mutex.unlock();
277  }
void lock()
Definition: GThread.cpp:248
void _clearCache(const std::string &path)
Definition: FileSystem.cpp:337
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256
static FileSystem & instance()
Definition: FileSystem.cpp:49

+ Here is the call graph for this function:

static void G3D::FileSystem::copyFile ( const std::string &  srcPath,
const std::string &  dstPath 
)
inlinestatic
Parameters
srcPathMust name a file.
dstPathMust not contain a zipfile.

Flushes the cache.

378  {
379  mutex.lock();
380  instance()._copyFile(srcPath, dstPath);
381  mutex.unlock();
382  }
void lock()
Definition: GThread.cpp:248
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256
void _copyFile(const std::string &srcPath, const std::string &dstPath)
Definition: FileSystem.cpp:424
static FileSystem & instance()
Definition: FileSystem.cpp:49

+ Here is the call graph for this function:

static void G3D::FileSystem::createDirectory ( const std::string &  path)
inlinestatic

Creates the directory named, including any subdirectories that do not already exist.

The directory must not be inside a zipfile.

Flushes the cache.

356  {
357  mutex.lock();
358  instance()._createDirectory(path);
359  mutex.unlock();
360  }
void lock()
Definition: GThread.cpp:248
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256
void _createDirectory(const std::string &path)
Definition: FileSystem.cpp:369
static FileSystem & instance()
Definition: FileSystem.cpp:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static std::string G3D::FileSystem::currentDirectory ( )
inlinestatic

The current working directory (cwd). Only ends in a slash if this is the root of the file system.

364  {
365  mutex.lock();
366  const std::string& s = instance()._currentDirectory();
367  mutex.unlock();
368  return s;
369  }
void lock()
Definition: GThread.cpp:248
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256
static FileSystem & instance()
Definition: FileSystem.cpp:49
std::string _currentDirectory()
Definition: FileSystem.cpp:542

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool G3D::FileSystem::exists ( const std::string &  f,
bool  trustCache = true,
bool  caseSensitive = true 
)
inlinestatic

Returns true if a node named f exists.

Parameters
fIf f contains wildcards, the function returns true if any file matches those wildcards. Wildcards may only appear in the base or ext, not the path. Environment variables beginning with dollar signs (e.g., in "$G3DDATA/cubemap"), with optional parens ("$(G3DDATA)") are automatically expanded in f. Default share names on Windows (e.g., "\\mycomputer\c$") are correctly distinguished from empty environment variables.
trustCacheIf true, uses the cache for optimizing repeated calls in the same parent directory.
caseSensitiveIf true, the match must have exactly the same case for the base and extension. If false, case is ignored. The default on Windows is false and the default on other operating systems is true.
407  {
408  mutex.lock();
409  bool e = instance()._exists(f, trustCache, caseSensitive);
410  mutex.unlock();
411  return e;
412  }
void lock()
Definition: GThread.cpp:248
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256
bool _exists(const std::string &f, bool trustCache=true, bool caseSensitive=true)
Definition: FileSystem.cpp:441
static FileSystem & instance()
Definition: FileSystem.cpp:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void G3D::FileSystem::fclose ( FILE *  f)
inlinestatic
290  {
291  mutex.lock();
292  ::fclose(f);
293  mutex.unlock();
294  }
void lock()
Definition: GThread.cpp:248
static void fclose(FILE *f)
Definition: FileSystem.h:290
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static FILE* G3D::FileSystem::fopen ( const char *  filename,
const char *  mode 
)
inlinestatic

Same as the C standard library fopen, but updates the file cache to acknowledge the new file on a write operation.

282  {
283  mutex.lock();
284  FILE* f = instance()._fopen(filename, mode);
285  mutex.unlock();
286  return f;
287  }
void lock()
Definition: GThread.cpp:248
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256
static FileSystem & instance()
Definition: FileSystem.cpp:49
FILE * _fopen(const char *filename, const char *mode)
Definition: FileSystem.cpp:321

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

FileSystem::Dir & G3D::FileSystem::getContents ( const std::string &  path,
bool  forceUpdate 
)
private

Update the cache entry for path if it is not already present.

Parameters
forceUpdateIf true, always override the current cache value.
147  {
148  const std::string& key =
149 # if defined(G3D_WINDOWS)
151 # else
153 # endif
154 
155  RealTime now = System::time();
156  Dir& dir = m_cache.getCreate(key);
157 
158  if ((now > dir.lastChecked + cacheLifetime()) || forceUpdate) {
159  dir = Dir();
160 
161  // Out of date: update
162  dir.lastChecked = now;
163 # ifdef G3D_WINDOWS
164  // On windows, we have to use GetFileAttributes (http://msdn.microsoft.com/en-us/library/aa364944(v=vs.85).aspx) instead of
165  // stat in order to work with network shares
166  const DWORD st = GetFileAttributesA(key.c_str());
167  const bool exists = (st != INVALID_FILE_ATTRIBUTES);
168  const bool isDirectory = (st & FILE_ATTRIBUTE_DIRECTORY) != 0;
169 # else
170  struct _stat st;
171  const bool exists = _stat(key.c_str(), &st) != -1;
172  const bool isDirectory = (st.st_mode & S_IFDIR) != 0;
173 # endif
174 
175  // Does this path exist on the real filesystem?
176  if (exists && isDirectory) {
177 
178  // Is this path actually a directory?
179  if (isDirectory) {
180  dir.exists = true;
181  // Update contents
182 # ifdef G3D_WINDOWS
183  const std::string& filespec = FilePath::concat(key, "*");
184  struct _finddata_t fileinfo;
185  intptr_t handle = _findfirst(filespec.c_str(), &fileinfo);
186  debugAssert(handle != -1);
187  int result = 0;
188  do {
189  if ((strcmp(fileinfo.name, ".") != 0) && (strcmp(fileinfo.name, "..") != 0)) {
190  Entry& e = dir.nodeArray.next();
191  e.name = fileinfo.name;
192  if ((fileinfo.attrib & _A_SUBDIR) != 0) {
193  e.type = DIR_TYPE;
194  } else {
195  e.type = FILE_TYPE;
196  }
197  }
198 
199  result = _findnext(handle, &fileinfo);
200  } while (result == 0);
201  _findclose(handle);
202 
203 # else
204  DIR* listing = opendir(key.c_str());
205  debugAssertM(listing, "opendir failed on '" + key + "'");
206  struct dirent* entry = readdir(listing);
207  while (entry != NULL) {
208  if ((strcmp(entry->d_name, "..") != 0) && (strcmp(entry->d_name, ".") != 0)) {
209  Entry& e = dir.nodeArray.next();
210  e.name = entry->d_name;
211 
212 # ifdef _DIRENT_HAVE_D_TYPE
213  // Not all POSIX systems support this field
214  // http://www.delorie.com/gnu/docs/glibc/libc_270.html
215  switch (entry->d_type) {
216  case DT_DIR:
217  e.type = DIR_TYPE;
218  break;
219 
220  case DT_REG:
221  e.type = FILE_TYPE;
222  break;
223 
224  case DT_UNKNOWN:
225  default:
226  e.type = UNKNOWN;
227  break;
228  }
229 # endif
230  }
231  entry = readdir(listing);
232  }
233  closedir(listing);
234  listing = NULL;
235  entry = NULL;
236 # endif
237  }
238 
239  } else {
240  std::string zip;
241 
242  if (exists && isZipfile(path)) {
243  // This is a zipfile; get its root
244  dir.isZipfile = true;
245  dir.computeZipListing(path, "");
246 
247  } else if (inZipfile(path, zip)) {
248 
249  // There is a zipfile somewhere in the path. Does
250  // the rest of the path exist inside the zipfile?
251  dir.inZipfile = true;
252  dir.computeZipListing(zip, path.substr(zip.length() + 1));
253  }
254  }
255  }
256 
257  return dir;
258 }
#define _stat
Definition: FileSystem.cpp:38
static bool isZipfile(const std::string &path)
Definition: FileSystem.h:323
Definition: FileSystem.h:90
static std::string concat(const std::string &a, const std::string &b)
Definition: FileSystem.cpp:743
arena_t NULL
Definition: jemalloc_internal.h:624
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
double RealTime
Definition: G3DGameUnits.h:27
Table< std::string, Dir > m_cache
Definition: FileSystem.h:133
static bool exists(const std::string &f, bool trustCache=true, bool caseSensitive=true)
Definition: FileSystem.h:401
Entry
Definition: boss_headless_horseman.cpp:50
#define debugAssert(exp)
Definition: debugAssert.h:160
static float cacheLifetime()
Definition: FileSystem.h:341
static std::string removeTrailingSlash(const std::string &f)
Definition: FileSystem.cpp:736
std::string toLower(const std::string &x)
Definition: stringutils.cpp:223
unsigned int DWORD
Definition: CascPort.h:139
static bool isDirectory(const std::string &path)
Definition: FileSystem.h:416
static std::string canonicalize(std::string x)
Definition: FileSystem.cpp:832
static std::string resolve(const std::string &path, const std::string &cwd=currentDirectory())
Definition: FileSystem.h:440
static RealTime time()
Definition: System.cpp:934
_W64 signed int intptr_t
Definition: stdint.h:118
Definition: FileSystem.h:89
static bool inZipfile(const std::string &path, std::string &zipfile)
Definition: FileSystem.h:264
Definition: FileSystem.h:88

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void G3D::FileSystem::getDirectories ( const std::string &  spec,
Array< std::string > &  result,
bool  includeParentPath = false 
)
inlinestatic

list() directories

496  {
497  mutex.lock();
498  instance()._getDirectories(spec, result, includeParentPath);
499  mutex.unlock();
500  }
void lock()
Definition: GThread.cpp:248
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256
static FileSystem & instance()
Definition: FileSystem.cpp:49
void _getDirectories(const std::string &spec, Array< std::string > &result, bool includeParentPath=false)
Definition: FileSystem.h:226

+ Here is the call graph for this function:

static void G3D::FileSystem::getFiles ( const std::string &  spec,
Array< std::string > &  result,
bool  includeParentPath = false 
)
inlinestatic

list() files

488  {
489  mutex.lock();
490  instance()._getFiles(spec, result, includeParentPath);
491  mutex.unlock();
492  }
void lock()
Definition: GThread.cpp:248
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256
static FileSystem & instance()
Definition: FileSystem.cpp:49
void _getFiles(const std::string &spec, Array< std::string > &result, bool includeParentPath=false)
Definition: FileSystem.h:217

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::FileSystem::init ( )
static

Create the common instance.

55  {
56  if (common == NULL) {
57  common = new FileSystem();
58  }
59 }
arena_t NULL
Definition: jemalloc_internal.h:624
static FileSystem * common
Definition: FileSystem.cpp:45
FileSystem()
Definition: FileSystem.cpp:69

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

FileSystem & G3D::FileSystem::instance ( )
staticprivate
49  {
50  init();
51  return *common;
52 }
static void init()
Definition: FileSystem.cpp:55
static FileSystem * common
Definition: FileSystem.cpp:45

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool G3D::FileSystem::inZipfile ( const std::string &  path,
std::string &  zipfile 
)
inlinestatic

Returns true if some sub-path of path is a zipfile.

If the path itself is a zipfile, returns false.

Parameters
zipfileThe part of path that was the zipfile
264  {
265  mutex.lock();
266  bool b = instance()._inZipfile(path, zipfile);
267  mutex.unlock();
268  return b;
269  }
void lock()
Definition: GThread.cpp:248
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256
static FileSystem & instance()
Definition: FileSystem.cpp:49
bool _inZipfile(const std::string &path, std::string &zipfile)
Definition: FileSystem.cpp:261

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool G3D::FileSystem::inZipfile ( const std::string &  path)
inlinestatic

Returns true if some sub-path of path is a zipfile.

If the path itself is a zipfile, returns false.

300  {
301  mutex.lock();
302  bool b = instance()._inZipfile(path);
303  mutex.unlock();
304  return b;
305  }
void lock()
Definition: GThread.cpp:248
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256
static FileSystem & instance()
Definition: FileSystem.cpp:49
bool _inZipfile(const std::string &path, std::string &zipfile)
Definition: FileSystem.cpp:261

+ Here is the call graph for this function:

bool efsw::Platform::FileSystem::isDirectory ( const std::string &  path)
inlinestatic

Known bug: does not work inside zipfiles

416  {
417  mutex.lock();
418  bool b = instance()._isDirectory(path);
419  mutex.unlock();
420  return b;
421  }
bool _isDirectory(const std::string &path)
Definition: FileSystem.cpp:483
void lock()
Definition: GThread.cpp:248
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256
static FileSystem & instance()
Definition: FileSystem.cpp:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool G3D::FileSystem::isFile ( const std::string &  path)
inlinestatic

Known bug: does not work inside zipfiles

425  {
426  mutex.lock();
427  bool b = instance()._isFile(path);
428  mutex.unlock();
429  return b;
430  }
bool _isFile(const std::string &path)
Definition: FileSystem.h:188
void lock()
Definition: GThread.cpp:248
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256
static FileSystem & instance()
Definition: FileSystem.cpp:49

+ Here is the call graph for this function:

static bool G3D::FileSystem::isNewer ( const std::string &  src,
const std::string &  dst 
)
inlinestatic

Returns true if dst does not exist or src is newer than dst, according to their time stamps.

Known bug: does not work inside zipfiles.

453  {
454  mutex.lock();
455  bool b = instance()._isNewer(src, dst);
456  mutex.unlock();
457  return b;
458  }
bool _isNewer(const std::string &src, const std::string &dst)
Definition: FileSystem.cpp:565
void lock()
Definition: GThread.cpp:248
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256
static FileSystem & instance()
Definition: FileSystem.cpp:49

+ Here is the call graph for this function:

static bool G3D::FileSystem::isZipfile ( const std::string &  path)
inlinestatic

Returns true if path is a file that is a zipfile. Note that G3D requires zipfiles to have some extension, although it is not required to be "zip"

323  {
324  mutex.lock();
325  bool b = instance()._isZipfile(path);
326  mutex.unlock();
327  return b;
328  }
void lock()
Definition: GThread.cpp:248
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256
bool _isZipfile(const std::string &path)
Definition: FileSystem.cpp:296
static FileSystem & instance()
Definition: FileSystem.cpp:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void G3D::FileSystem::list ( const std::string &  spec,
Array< std::string > &  result,
const ListSettings listSettings = ListSettings() 
)
inlinestatic

Appends all nodes matching spec to the result array.

Wildcards can only appear to the right of the last slash in spec.

The names will not contain parent paths unless includePath == true. These may be relative to the current directory unless spec is fully qualified (can be done with resolveFilename).

480  {
481  mutex.lock();
482  instance()._list(spec, result, listSettings);
483  mutex.unlock();
484  }
void lock()
Definition: GThread.cpp:248
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256
void _list(const std::string &spec, Array< std::string > &result, const ListSettings &listSettings=ListSettings())
Definition: FileSystem.cpp:665
static FileSystem & instance()
Definition: FileSystem.cpp:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::FileSystem::listHelper ( const std::string &  shortSpec,
const std::string &  parentPath,
Array< std::string > &  result,
const ListSettings settings 
)
private

Called from list()

620  {
621 
622  Dir& dir = getContents(parentPath, false);
623 
624  if (! dir.exists) {
625  return;
626  }
627 
628  for (int i = 0; i < dir.nodeArray.size(); ++i) {
629  Entry& entry = dir.nodeArray[i];
630  // See if it matches the spec
631  if (FilePath::matches(entry.name, shortSpec, settings.caseSensitive)) {
632 
633  if ((entry.type == UNKNOWN) &&
634  (! (settings.files && settings.directories) ||
635  settings.recursive)) {
636  // Update the type: it is unknown and we'll need to branch onit below
637  entry.type = isDirectory(FilePath::concat(parentPath, entry.name)) ? DIR_TYPE : FILE_TYPE;
638  }
639 
640  if ((settings.files && settings.directories) ||
641  (settings.files && (entry.type == FILE_TYPE)) ||
642  (settings.directories && (entry.type == DIR_TYPE))) {
643 
644  if (settings.includeParentPath) {
645  result.append(FilePath::concat(parentPath, entry.name));
646  } else {
647  result.append(entry.name);
648  }
649  }
650  } // match
651 
652  if (settings.recursive) {
653  if (entry.type == UNKNOWN) {
654  entry.type = isDirectory(FilePath::concat(parentPath, entry.name)) ? DIR_TYPE : FILE_TYPE;
655  }
656 
657  if (entry.type == DIR_TYPE) {
658  listHelper(shortSpec, FilePath::concat(parentPath, entry.name), result, settings);
659  }
660  }
661  } // for
662 }
Definition: FileSystem.h:90
static std::string concat(const std::string &a, const std::string &b)
Definition: FileSystem.cpp:743
Entry
Definition: boss_headless_horseman.cpp:50
static bool matches(const std::string &path, const std::string &pattern, bool caseSensitive=true)
Definition: FileSystem.cpp:818
static bool isDirectory(const std::string &path)
Definition: FileSystem.h:416
Definition: FileSystem.h:89
Definition: FileSystem.h:88
void listHelper(const std::string &shortSpec, const std::string &parentPath, Array< std::string > &result, const ListSettings &settings)
Definition: FileSystem.cpp:617
void append(const T &value)
Definition: Array.h:583
Dir & getContents(const std::string &path, bool forceUpdate)
Definition: FileSystem.cpp:147

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::FileSystem::markFileUsed ( const std::string &  filename)
static

Adds filename to usedFiles(). This is called automatically by open() and all G3D routines that open files.

553  {
554  mutex.lock();
555  _filesUsed.insert(filename);
556  mutex.unlock();
557 }
void lock()
Definition: GThread.cpp:248
static Set< std::string > _filesUsed
Definition: FileSystem.cpp:551
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256
bool insert(const T &member)
Definition: Set.h:62

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void G3D::FileSystem::removeFile ( const std::string &  path)
inlinestatic

Delete this file. No effect if path does not exist.

Parameters
pathMay contain wildcards. May not be inside a zipfile.
314  {
315  mutex.lock();
316  instance()._removeFile(path);
317  mutex.unlock();
318  }
void _removeFile(const std::string &path)
Delete this file. No effect if path does not exist.
Definition: FileSystem.cpp:492
void lock()
Definition: GThread.cpp:248
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256
static FileSystem & instance()
Definition: FileSystem.cpp:49

+ Here is the call graph for this function:

static std::string G3D::FileSystem::resolve ( const std::string &  path,
const std::string &  cwd = currentDirectory() 
)
inlinestatic

Fully qualifies a filename.

The filename may contain wildcards, in which case the wildcards will be preserved in the returned value.

Parameters
cwdThe directory to treat as the "current" directory when resolving a relative path. The default value is the actual current directory. (G3D::Any::sourceDirectory is a common alternative)
440  {
441  mutex.lock();
442  const std::string& s = instance()._resolve(path, cwd);
443  mutex.unlock();
444  return s;
445  }
void lock()
Definition: GThread.cpp:248
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256
std::string _resolve(const std::string &path, const std::string &cwd=currentDirectory())
Definition: FileSystem.cpp:508
static FileSystem & instance()
Definition: FileSystem.cpp:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::FileSystem::setCacheLifetime ( float  t)
inline

Set the cacheLifetime().

Parameters
tin seconds
333  {
334  mutex.lock();
336  mutex.unlock();
337  }
void _setCacheLifetime(float t)
Definition: FileSystem.cpp:364
void lock()
Definition: GThread.cpp:248
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256
static FileSystem & instance()
Definition: FileSystem.cpp:49

+ Here is the call graph for this function:

static int64 G3D::FileSystem::size ( const std::string &  path)
inlinestatic

Returns the length of the file in bytes, or -1 if the file could not be opened.

462  {
463  mutex.lock();
464  int64 i = instance()._size(path);
465  mutex.unlock();
466  return i;
467  }
void lock()
Definition: GThread.cpp:248
int64_t int64
Definition: Define.h:145
static GMutex mutex
Definition: FileSystem.h:143
void unlock()
Definition: GThread.cpp:256
int64 _size(const std::string &path)
Definition: FileSystem.cpp:580
static FileSystem & instance()
Definition: FileSystem.cpp:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const Set< std::string > & G3D::FileSystem::usedFiles ( )
static

All files that have been marked by markFileUsed(). GApp automatically prints this list to log.txt. It is useful for finding the dependencies of your program automatically.

560  {
561  return _filesUsed;
562 }
static Set< std::string > _filesUsed
Definition: FileSystem.cpp:551

Member Data Documentation

Table<std::string, Dir> G3D::FileSystem::m_cache
private

Maps path names (without trailing slashes, except for the file system root) to contents. On Windows, all paths are lowercase

float G3D::FileSystem::m_cacheLifetime
private
Array<std::string> G3D::FileSystem::m_winDrive
private

Drive letters. Only used on windows, but defined on all platforms to help avoid breaking the Windows build when compiling on another platform.

GMutex G3D::FileSystem::mutex
staticprivate

The documentation for this class was generated from the following files: