diff options
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CFileList.cpp')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CFileList.cpp | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CFileList.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CFileList.cpp new file mode 100644 index 0000000..1b8ff4f --- /dev/null +++ b/libraries/irrlicht-1.8/source/Irrlicht/CFileList.cpp | |||
@@ -0,0 +1,165 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt | ||
2 | // This file is part of the "Irrlicht Engine". | ||
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | ||
4 | |||
5 | #include "CFileList.h" | ||
6 | #include "IrrCompileConfig.h" | ||
7 | #include "irrArray.h" | ||
8 | #include "coreutil.h" | ||
9 | |||
10 | #include "os.h" | ||
11 | |||
12 | namespace irr | ||
13 | { | ||
14 | namespace io | ||
15 | { | ||
16 | |||
17 | static const io::path emptyFileListEntry; | ||
18 | |||
19 | CFileList::CFileList(const io::path& path, bool ignoreCase, bool ignorePaths) | ||
20 | : IgnorePaths(ignorePaths), IgnoreCase(ignoreCase), Path(path) | ||
21 | { | ||
22 | #ifdef _DEBUG | ||
23 | setDebugName("CFileList"); | ||
24 | #endif | ||
25 | |||
26 | Path.replace('\\', '/'); | ||
27 | } | ||
28 | |||
29 | CFileList::~CFileList() | ||
30 | { | ||
31 | Files.clear(); | ||
32 | } | ||
33 | |||
34 | u32 CFileList::getFileCount() const | ||
35 | { | ||
36 | return Files.size(); | ||
37 | } | ||
38 | |||
39 | void CFileList::sort() | ||
40 | { | ||
41 | Files.sort(); | ||
42 | } | ||
43 | |||
44 | const io::path& CFileList::getFileName(u32 index) const | ||
45 | { | ||
46 | if (index >= Files.size()) | ||
47 | return emptyFileListEntry; | ||
48 | |||
49 | return Files[index].Name; | ||
50 | } | ||
51 | |||
52 | |||
53 | //! Gets the full name of a file in the list, path included, based on an index. | ||
54 | const io::path& CFileList::getFullFileName(u32 index) const | ||
55 | { | ||
56 | if (index >= Files.size()) | ||
57 | return emptyFileListEntry; | ||
58 | |||
59 | return Files[index].FullName; | ||
60 | } | ||
61 | |||
62 | //! adds a file or folder | ||
63 | u32 CFileList::addItem(const io::path& fullPath, u32 offset, u32 size, bool isDirectory, u32 id) | ||
64 | { | ||
65 | SFileListEntry entry; | ||
66 | entry.ID = id ? id : Files.size(); | ||
67 | entry.Offset = offset; | ||
68 | entry.Size = size; | ||
69 | entry.Name = fullPath; | ||
70 | entry.Name.replace('\\', '/'); | ||
71 | entry.IsDirectory = isDirectory; | ||
72 | |||
73 | // remove trailing slash | ||
74 | if (entry.Name.lastChar() == '/') | ||
75 | { | ||
76 | entry.IsDirectory = true; | ||
77 | entry.Name[entry.Name.size()-1] = 0; | ||
78 | entry.Name.validate(); | ||
79 | } | ||
80 | |||
81 | if (IgnoreCase) | ||
82 | entry.Name.make_lower(); | ||
83 | |||
84 | entry.FullName = entry.Name; | ||
85 | |||
86 | core::deletePathFromFilename(entry.Name); | ||
87 | |||
88 | if (IgnorePaths) | ||
89 | entry.FullName = entry.Name; | ||
90 | |||
91 | //os::Printer::log(Path.c_str(), entry.FullName); | ||
92 | |||
93 | Files.push_back(entry); | ||
94 | |||
95 | return Files.size() - 1; | ||
96 | } | ||
97 | |||
98 | //! Returns the ID of a file in the file list, based on an index. | ||
99 | u32 CFileList::getID(u32 index) const | ||
100 | { | ||
101 | return index < Files.size() ? Files[index].ID : 0; | ||
102 | } | ||
103 | |||
104 | bool CFileList::isDirectory(u32 index) const | ||
105 | { | ||
106 | bool ret = false; | ||
107 | if (index < Files.size()) | ||
108 | ret = Files[index].IsDirectory; | ||
109 | |||
110 | _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; | ||
111 | return ret; | ||
112 | } | ||
113 | |||
114 | //! Returns the size of a file | ||
115 | u32 CFileList::getFileSize(u32 index) const | ||
116 | { | ||
117 | return index < Files.size() ? Files[index].Size : 0; | ||
118 | } | ||
119 | |||
120 | //! Returns the size of a file | ||
121 | u32 CFileList::getFileOffset(u32 index) const | ||
122 | { | ||
123 | return index < Files.size() ? Files[index].Offset : 0; | ||
124 | } | ||
125 | |||
126 | |||
127 | //! Searches for a file or folder within the list, returns the index | ||
128 | s32 CFileList::findFile(const io::path& filename, bool isDirectory = false) const | ||
129 | { | ||
130 | SFileListEntry entry; | ||
131 | // we only need FullName to be set for the search | ||
132 | entry.FullName = filename; | ||
133 | entry.IsDirectory = isDirectory; | ||
134 | |||
135 | // exchange | ||
136 | entry.FullName.replace('\\', '/'); | ||
137 | |||
138 | // remove trailing slash | ||
139 | if (entry.FullName.lastChar() == '/') | ||
140 | { | ||
141 | entry.IsDirectory = true; | ||
142 | entry.FullName[entry.FullName.size()-1] = 0; | ||
143 | entry.FullName.validate(); | ||
144 | } | ||
145 | |||
146 | if (IgnoreCase) | ||
147 | entry.FullName.make_lower(); | ||
148 | |||
149 | if (IgnorePaths) | ||
150 | core::deletePathFromFilename(entry.FullName); | ||
151 | |||
152 | return Files.binary_search(entry); | ||
153 | } | ||
154 | |||
155 | |||
156 | //! Returns the base path of the file list | ||
157 | const io::path& CFileList::getPath() const | ||
158 | { | ||
159 | return Path; | ||
160 | } | ||
161 | |||
162 | |||
163 | } // end namespace irr | ||
164 | } // end namespace io | ||
165 | |||