]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CFileList.cpp
Reduce IrrCompileConfig usage to files that actually need it
[irrlicht.git] / source / Irrlicht / CFileList.cpp
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
4 \r
5 #include "CFileList.h"\r
6 #include "irrArray.h"\r
7 #include "coreutil.h"\r
8 \r
9 #include "os.h"\r
10 \r
11 namespace irr\r
12 {\r
13 namespace io\r
14 {\r
15 \r
16 static const io::path emptyFileListEntry;\r
17 \r
18 CFileList::CFileList(const io::path& path, bool ignoreCase, bool ignorePaths)\r
19  : IgnorePaths(ignorePaths), IgnoreCase(ignoreCase), Path(path)\r
20 {\r
21         #ifdef _DEBUG\r
22         setDebugName("CFileList");\r
23         #endif\r
24 \r
25         Path.replace('\\', '/');\r
26 }\r
27 \r
28 CFileList::~CFileList()\r
29 {\r
30         Files.clear();\r
31 }\r
32 \r
33 u32 CFileList::getFileCount() const\r
34 {\r
35         return Files.size();\r
36 }\r
37 \r
38 void CFileList::sort()\r
39 {\r
40         Files.sort();\r
41 }\r
42 \r
43 const io::path& CFileList::getFileName(u32 index) const\r
44 {\r
45         if (index >= Files.size())\r
46                 return emptyFileListEntry;\r
47 \r
48         return Files[index].Name;\r
49 }\r
50 \r
51 \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
54 {\r
55         if (index >= Files.size())\r
56                 return emptyFileListEntry;\r
57 \r
58         return Files[index].FullName;\r
59 }\r
60 \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
63 {\r
64         SFileListEntry entry;\r
65         entry.ID   = id ? id : Files.size();\r
66         entry.Offset = offset;\r
67         entry.Size = size;\r
68         entry.Name = fullPath;\r
69         entry.Name.replace('\\', '/');\r
70         entry.IsDirectory = isDirectory;\r
71 \r
72         // remove trailing slash\r
73         if (entry.Name.lastChar() == '/')\r
74         {\r
75                 entry.IsDirectory = true;\r
76                 entry.Name[entry.Name.size()-1] = 0;\r
77                 entry.Name.validate();\r
78         }\r
79 \r
80         if (IgnoreCase)\r
81                 entry.Name.make_lower();\r
82 \r
83         entry.FullName = entry.Name;\r
84 \r
85         core::deletePathFromFilename(entry.Name);\r
86 \r
87         if (IgnorePaths)\r
88                 entry.FullName = entry.Name;\r
89 \r
90         //os::Printer::log(Path.c_str(), entry.FullName);\r
91 \r
92         Files.push_back(entry);\r
93 \r
94         return Files.size() - 1;\r
95 }\r
96 \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
99 {\r
100         return index < Files.size() ? Files[index].ID : 0;\r
101 }\r
102 \r
103 bool CFileList::isDirectory(u32 index) const\r
104 {\r
105         bool ret = false;\r
106         if (index < Files.size())\r
107                 ret = Files[index].IsDirectory;\r
108 \r
109         return ret;\r
110 }\r
111 \r
112 //! Returns the size of a file\r
113 u32 CFileList::getFileSize(u32 index) const\r
114 {\r
115         return index < Files.size() ? Files[index].Size : 0;\r
116 }\r
117 \r
118 u32 CFileList::getFileOffset(u32 index) const\r
119 {\r
120         return index < Files.size() ? Files[index].Offset : 0;\r
121 }\r
122 \r
123 \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
126 {\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
131 \r
132         // exchange\r
133         entry.FullName.replace('\\', '/');\r
134 \r
135         // remove trailing slash\r
136         if (entry.FullName.lastChar() == '/')\r
137         {\r
138                 entry.IsDirectory = true;\r
139                 entry.FullName[entry.FullName.size()-1] = 0;\r
140                 entry.FullName.validate();\r
141         }\r
142 \r
143         if (IgnoreCase)\r
144                 entry.FullName.make_lower();\r
145 \r
146         if (IgnorePaths)\r
147                 core::deletePathFromFilename(entry.FullName);\r
148 \r
149         return Files.binary_search(entry);\r
150 }\r
151 \r
152 \r
153 //! Returns the base path of the file list\r
154 const io::path& CFileList::getPath() const\r
155 {\r
156         return Path;\r
157 }\r
158 \r
159 \r
160 } // end namespace irr\r
161 } // end namespace io\r
162 \r