1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #include "CFileList.h"
\r
6 #include "IrrCompileConfig.h"
\r
7 #include "irrArray.h"
\r
8 #include "coreutil.h"
\r
17 static const io::path emptyFileListEntry;
\r
19 CFileList::CFileList(const io::path& path, bool ignoreCase, bool ignorePaths)
\r
20 : IgnorePaths(ignorePaths), IgnoreCase(ignoreCase), Path(path)
\r
23 setDebugName("CFileList");
\r
26 Path.replace('\\', '/');
\r
29 CFileList::~CFileList()
\r
34 u32 CFileList::getFileCount() const
\r
36 return Files.size();
\r
39 void CFileList::sort()
\r
44 const io::path& CFileList::getFileName(u32 index) const
\r
46 if (index >= Files.size())
\r
47 return emptyFileListEntry;
\r
49 return Files[index].Name;
\r
53 //! Gets the full name of a file in the list, path included, based on an index.
\r
54 const io::path& CFileList::getFullFileName(u32 index) const
\r
56 if (index >= Files.size())
\r
57 return emptyFileListEntry;
\r
59 return Files[index].FullName;
\r
62 //! adds a file or folder
\r
63 u32 CFileList::addItem(const io::path& fullPath, u32 offset, u32 size, bool isDirectory, u32 id)
\r
65 SFileListEntry entry;
\r
66 entry.ID = id ? id : Files.size();
\r
67 entry.Offset = offset;
\r
69 entry.Name = fullPath;
\r
70 entry.Name.replace('\\', '/');
\r
71 entry.IsDirectory = isDirectory;
\r
73 // remove trailing slash
\r
74 if (entry.Name.lastChar() == '/')
\r
76 entry.IsDirectory = true;
\r
77 entry.Name[entry.Name.size()-1] = 0;
\r
78 entry.Name.validate();
\r
82 entry.Name.make_lower();
\r
84 entry.FullName = entry.Name;
\r
86 core::deletePathFromFilename(entry.Name);
\r
89 entry.FullName = entry.Name;
\r
91 //os::Printer::log(Path.c_str(), entry.FullName);
\r
93 Files.push_back(entry);
\r
95 return Files.size() - 1;
\r
98 //! Returns the ID of a file in the file list, based on an index.
\r
99 u32 CFileList::getID(u32 index) const
\r
101 return index < Files.size() ? Files[index].ID : 0;
\r
104 bool CFileList::isDirectory(u32 index) const
\r
107 if (index < Files.size())
\r
108 ret = Files[index].IsDirectory;
\r
113 //! Returns the size of a file
\r
114 u32 CFileList::getFileSize(u32 index) const
\r
116 return index < Files.size() ? Files[index].Size : 0;
\r
119 u32 CFileList::getFileOffset(u32 index) const
\r
121 return index < Files.size() ? Files[index].Offset : 0;
\r
125 //! Searches for a file or folder within the list, returns the index
\r
126 s32 CFileList::findFile(const io::path& filename, bool isDirectory = false) const
\r
128 SFileListEntry entry;
\r
129 // we only need FullName to be set for the search
\r
130 entry.FullName = filename;
\r
131 entry.IsDirectory = isDirectory;
\r
134 entry.FullName.replace('\\', '/');
\r
136 // remove trailing slash
\r
137 if (entry.FullName.lastChar() == '/')
\r
139 entry.IsDirectory = true;
\r
140 entry.FullName[entry.FullName.size()-1] = 0;
\r
141 entry.FullName.validate();
\r
145 entry.FullName.make_lower();
\r
148 core::deletePathFromFilename(entry.FullName);
\r
150 return Files.binary_search(entry);
\r
154 //! Returns the base path of the file list
\r
155 const io::path& CFileList::getPath() const
\r
161 } // end namespace irr
\r
162 } // end namespace io
\r