aboutsummaryrefslogtreecommitdiff
path: root/source/Irrlicht/CFileList.cpp
diff options
context:
space:
mode:
authorcutealien <cutealien@dfc29bdd-3216-0410-991c-e03cc46cb475>2020-01-03 19:05:16 +0000
committercutealien <cutealien@dfc29bdd-3216-0410-991c-e03cc46cb475>2020-01-03 19:05:16 +0000
commit2ae2a551a6290f46734307bbfdafea4b1a2cf2ba (patch)
treeba2f0b468640e44899fed3df2d4cc58795f4a003 /source/Irrlicht/CFileList.cpp
downloadirrlicht-2ae2a551a6290f46734307bbfdafea4b1a2cf2ba.tar.xz
Merging r5975 through r6036 from trunk to ogl-es branch.
GLES drivers adapted, but only did make compile-tests. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@6038 dfc29bdd-3216-0410-991c-e03cc46cb475
Diffstat (limited to 'source/Irrlicht/CFileList.cpp')
-rw-r--r--source/Irrlicht/CFileList.cpp163
1 files changed, 163 insertions, 0 deletions
diff --git a/source/Irrlicht/CFileList.cpp b/source/Irrlicht/CFileList.cpp
new file mode 100644
index 0000000..15d5410
--- /dev/null
+++ b/source/Irrlicht/CFileList.cpp
@@ -0,0 +1,163 @@
+// Copyright (C) 2002-2012 Nikolaus Gebhardt
+// This file is part of the "Irrlicht Engine".
+// For conditions of distribution and use, see copyright notice in irrlicht.h
+
+#include "CFileList.h"
+#include "IrrCompileConfig.h"
+#include "irrArray.h"
+#include "coreutil.h"
+
+#include "os.h"
+
+namespace irr
+{
+namespace io
+{
+
+static const io::path emptyFileListEntry;
+
+CFileList::CFileList(const io::path& path, bool ignoreCase, bool ignorePaths)
+ : IgnorePaths(ignorePaths), IgnoreCase(ignoreCase), Path(path)
+{
+ #ifdef _DEBUG
+ setDebugName("CFileList");
+ #endif
+
+ Path.replace('\\', '/');
+}
+
+CFileList::~CFileList()
+{
+ Files.clear();
+}
+
+u32 CFileList::getFileCount() const
+{
+ return Files.size();
+}
+
+void CFileList::sort()
+{
+ Files.sort();
+}
+
+const io::path& CFileList::getFileName(u32 index) const
+{
+ if (index >= Files.size())
+ return emptyFileListEntry;
+
+ return Files[index].Name;
+}
+
+
+//! Gets the full name of a file in the list, path included, based on an index.
+const io::path& CFileList::getFullFileName(u32 index) const
+{
+ if (index >= Files.size())
+ return emptyFileListEntry;
+
+ return Files[index].FullName;
+}
+
+//! adds a file or folder
+u32 CFileList::addItem(const io::path& fullPath, u32 offset, u32 size, bool isDirectory, u32 id)
+{
+ SFileListEntry entry;
+ entry.ID = id ? id : Files.size();
+ entry.Offset = offset;
+ entry.Size = size;
+ entry.Name = fullPath;
+ entry.Name.replace('\\', '/');
+ entry.IsDirectory = isDirectory;
+
+ // remove trailing slash
+ if (entry.Name.lastChar() == '/')
+ {
+ entry.IsDirectory = true;
+ entry.Name[entry.Name.size()-1] = 0;
+ entry.Name.validate();
+ }
+
+ if (IgnoreCase)
+ entry.Name.make_lower();
+
+ entry.FullName = entry.Name;
+
+ core::deletePathFromFilename(entry.Name);
+
+ if (IgnorePaths)
+ entry.FullName = entry.Name;
+
+ //os::Printer::log(Path.c_str(), entry.FullName);
+
+ Files.push_back(entry);
+
+ return Files.size() - 1;
+}
+
+//! Returns the ID of a file in the file list, based on an index.
+u32 CFileList::getID(u32 index) const
+{
+ return index < Files.size() ? Files[index].ID : 0;
+}
+
+bool CFileList::isDirectory(u32 index) const
+{
+ bool ret = false;
+ if (index < Files.size())
+ ret = Files[index].IsDirectory;
+
+ return ret;
+}
+
+//! Returns the size of a file
+u32 CFileList::getFileSize(u32 index) const
+{
+ return index < Files.size() ? Files[index].Size : 0;
+}
+
+u32 CFileList::getFileOffset(u32 index) const
+{
+ return index < Files.size() ? Files[index].Offset : 0;
+}
+
+
+//! Searches for a file or folder within the list, returns the index
+s32 CFileList::findFile(const io::path& filename, bool isDirectory = false) const
+{
+ SFileListEntry entry;
+ // we only need FullName to be set for the search
+ entry.FullName = filename;
+ entry.IsDirectory = isDirectory;
+
+ // exchange
+ entry.FullName.replace('\\', '/');
+
+ // remove trailing slash
+ if (entry.FullName.lastChar() == '/')
+ {
+ entry.IsDirectory = true;
+ entry.FullName[entry.FullName.size()-1] = 0;
+ entry.FullName.validate();
+ }
+
+ if (IgnoreCase)
+ entry.FullName.make_lower();
+
+ if (IgnorePaths)
+ core::deletePathFromFilename(entry.FullName);
+
+ return Files.binary_search(entry);
+}
+
+
+//! Returns the base path of the file list
+const io::path& CFileList::getPath() const
+{
+ return Path;
+}
+
+
+} // end namespace irr
+} // end namespace io
+