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 "irrArray.h"
\r
7 #include "coreutil.h"
\r
16 static const io::path emptyFileListEntry;
\r
18 CFileList::CFileList(const io::path& path, bool ignoreCase, bool ignorePaths)
\r
19 : IgnorePaths(ignorePaths), IgnoreCase(ignoreCase), Path(path)
\r
22 setDebugName("CFileList");
\r
25 Path.replace('\\', '/');
\r
28 CFileList::~CFileList()
\r
33 u32 CFileList::getFileCount() const
\r
35 return Files.size();
\r
38 void CFileList::sort()
\r
43 const io::path& CFileList::getFileName(u32 index) const
\r
45 if (index >= Files.size())
\r
46 return emptyFileListEntry;
\r
48 return Files[index].Name;
\r
52 //! Gets the full name of a file in the list, path included, based on an index.
\r
53 const io::path& CFileList::getFullFileName(u32 index) const
\r
55 if (index >= Files.size())
\r
56 return emptyFileListEntry;
\r
58 return Files[index].FullName;
\r
61 //! adds a file or folder
\r
62 u32 CFileList::addItem(const io::path& fullPath, u32 offset, u32 size, bool isDirectory, u32 id)
\r
64 SFileListEntry entry;
\r
65 entry.ID = id ? id : Files.size();
\r
66 entry.Offset = offset;
\r
68 entry.Name = fullPath;
\r
69 entry.Name.replace('\\', '/');
\r
70 entry.IsDirectory = isDirectory;
\r
72 // remove trailing slash
\r
73 if (entry.Name.lastChar() == '/')
\r
75 entry.IsDirectory = true;
\r
76 entry.Name[entry.Name.size()-1] = 0;
\r
77 entry.Name.validate();
\r
81 entry.Name.make_lower();
\r
83 entry.FullName = entry.Name;
\r
85 core::deletePathFromFilename(entry.Name);
\r
88 entry.FullName = entry.Name;
\r
90 //os::Printer::log(Path.c_str(), entry.FullName);
\r
92 Files.push_back(entry);
\r
94 return Files.size() - 1;
\r
97 //! Returns the ID of a file in the file list, based on an index.
\r
98 u32 CFileList::getID(u32 index) const
\r
100 return index < Files.size() ? Files[index].ID : 0;
\r
103 bool CFileList::isDirectory(u32 index) const
\r
106 if (index < Files.size())
\r
107 ret = Files[index].IsDirectory;
\r
112 //! Returns the size of a file
\r
113 u32 CFileList::getFileSize(u32 index) const
\r
115 return index < Files.size() ? Files[index].Size : 0;
\r
118 u32 CFileList::getFileOffset(u32 index) const
\r
120 return index < Files.size() ? Files[index].Offset : 0;
\r
124 //! Searches for a file or folder within the list, returns the index
\r
125 s32 CFileList::findFile(const io::path& filename, bool isDirectory = false) const
\r
127 SFileListEntry entry;
\r
128 // we only need FullName to be set for the search
\r
129 entry.FullName = filename;
\r
130 entry.IsDirectory = isDirectory;
\r
133 entry.FullName.replace('\\', '/');
\r
135 // remove trailing slash
\r
136 if (entry.FullName.lastChar() == '/')
\r
138 entry.IsDirectory = true;
\r
139 entry.FullName[entry.FullName.size()-1] = 0;
\r
140 entry.FullName.validate();
\r
144 entry.FullName.make_lower();
\r
147 core::deletePathFromFilename(entry.FullName);
\r
149 return Files.binary_search(entry);
\r
153 //! Returns the base path of the file list
\r
154 const io::path& CFileList::getPath() const
\r
160 } // end namespace irr
\r
161 } // end namespace io
\r