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

Public Member Functions

bool contains (const std::string &child, bool caseSensitive=true) const
 
void computeZipListing (const std::string &zipfile, const std::string &pathInsideZipfile)
 
 Dir ()
 

Public Attributes

bool exists
 
bool isZipfile
 
bool inZipfile
 
Array< EntrynodeArray
 
double lastChecked
 

Constructor & Destructor Documentation

G3D::FileSystem::Dir::Dir ( )
inline
128 : exists(false), isZipfile(false), inZipfile(false), lastChecked(0) {}
bool isZipfile
Definition: FileSystem.h:108
bool exists
Definition: FileSystem.h:106
bool inZipfile
Definition: FileSystem.h:109
double lastChecked
Definition: FileSystem.h:115

Member Function Documentation

void G3D::FileSystem::Dir::computeZipListing ( const std::string &  zipfile,
const std::string &  pathInsideZipfile 
)

Compute the contents of nodeArray from this zipfile.

88  {
89 #if _HAVE_ZIP /* G3DFIX: Use ZIP-library only if defined */
90  const std::string& pathInsideZipfile = FilePath::canonicalize(_pathInsideZipfile);
91  struct zip* z = zip_open( FilePath::removeTrailingSlash(zipfile).c_str(), ZIP_CHECKCONS, NULL );
92  debugAssert(z);
93 
94  int count = zip_get_num_files( z );
95  Set<std::string> alreadyAdded;
96  for (int i = 0; i < count; ++i) {
97  struct zip_stat info;
98  zip_stat_init( &info ); // TODO: Docs unclear if zip_stat_init is required.
99  zip_stat_index( z, i, ZIP_FL_NOCASE, &info );
100 
101  // Fully-qualified name of a file inside zipfile
102  std::string name = FilePath::canonicalize(info.name);
103 
104  if (beginsWith(name, pathInsideZipfile)) {
105  // We found something inside the directory we were looking for,
106  // so the directory itself must exist
107  exists = true;
108 
109  // For building the cached directory listing, extract only elements that do not contain
110  // additional subdirectories.
111 
112  size_t start = pathInsideZipfile.size();
113  if ((name.length() > start) && isSlash(name[start])) {
114  ++start;
115  }
116 
117  size_t end = findSlash(name, start);
118  if (end == std::string::npos) {
119  // There are no more slashes; add this name
120  name = name.substr(start);
121  if (alreadyAdded.insert(name)) {
122  Entry& e = nodeArray.next();
123  e.name = name;
124  e.type = FILE_TYPE;
125  }
126  } else {
127  // There are more slashes, indicating that this is a directory
128  name = name.substr(start, end);
129  if (alreadyAdded.insert(name)) {
130  Entry& e = nodeArray.next();
131  e.name = FilePath::removeTrailingSlash(name);
132  e.type = DIR_TYPE;
133  }
134  }
135  }
136  }
137 
138  zip_close(z);
139  z = NULL;
140 #else
141  (void)zipfile;
142  (void)_pathInsideZipfile;
143 #endif
144 }
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
Definition: FileSystem.h:90
Array< Entry > nodeArray
Definition: FileSystem.h:112
arena_t NULL
Definition: jemalloc_internal.h:624
bool exists
Definition: FileSystem.h:106
Entry
Definition: boss_headless_horseman.cpp:50
bool isSlash(const unsigned char c)
Definition: stringutils.h:175
#define debugAssert(exp)
Definition: debugAssert.h:160
G3D::int16 z
Definition: Vector3int16.h:46
static std::string removeTrailingSlash(const std::string &f)
Definition: FileSystem.cpp:736
static std::string canonicalize(std::string x)
Definition: FileSystem.cpp:832
size_t findSlash(const std::string &f, size_t start=0)
Definition: stringutils.h:34
Definition: FileSystem.h:89

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool G3D::FileSystem::Dir::contains ( const std::string &  child,
bool  caseSensitive = true 
) const
73  {
74 
75  for (int i = 0; i < nodeArray.size(); ++i) {
76  if (caseSensitive) {
77  if (f == nodeArray[i].name) {
78  return true;
79  }
80  } else if (stricmp(f.c_str(), nodeArray[i].name.c_str()) == 0) {
81  return true;
82  }
83  }
84  return false;
85 }
Array< Entry > nodeArray
Definition: FileSystem.h:112
#define stricmp
Definition: FileSystem.cpp:39

+ Here is the caller graph for this function:

Member Data Documentation

bool G3D::FileSystem::Dir::exists

If false, this path did not exist (even inside a zipfile) when last checked, or it is not a directory.

bool G3D::FileSystem::Dir::inZipfile
bool G3D::FileSystem::Dir::isZipfile
double G3D::FileSystem::Dir::lastChecked

When this entry was last updated

Array<Entry> G3D::FileSystem::Dir::nodeArray

Files and directories


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