1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine".
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
5
#include "CMountPointReader.h"
7
#ifdef __IRR_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_
18
CArchiveLoaderMount::CArchiveLoaderMount( io::IFileSystem* fs)
22
setDebugName("CArchiveLoaderMount");
27
//! returns true if the file maybe is able to be loaded by this class
28
bool CArchiveLoaderMount::isALoadableFileFormat(const io::path& filename) const
30
io::path fname(filename);
31
deletePathFromFilename(fname);
35
IFileList* list = FileSystem->createFileList();
39
// check if name is found as directory
40
if (list->findFile(filename, true))
47
//! Check to see if the loader can create archives of this type.
48
bool CArchiveLoaderMount::isALoadableFileFormat(E_FILE_ARCHIVE_TYPE fileType) const
50
return fileType == EFAT_FOLDER;
53
//! Check if the file might be loaded by this class
54
bool CArchiveLoaderMount::isALoadableFileFormat(io::IReadFile* file) const
59
//! Creates an archive from the filename
60
IFileArchive* CArchiveLoaderMount::createArchive(const io::path& filename, bool ignoreCase, bool ignorePaths) const
62
IFileArchive *archive = 0;
64
EFileSystemType current = FileSystem->setFileListSystem(FILESYSTEM_NATIVE);
66
const io::path save = FileSystem->getWorkingDirectory();
67
io::path fullPath = FileSystem->getAbsolutePath(filename);
68
FileSystem->flattenFilename(fullPath);
70
if (FileSystem->changeWorkingDirectoryTo(fullPath))
72
archive = new CMountPointReader(FileSystem, fullPath, ignoreCase, ignorePaths);
75
FileSystem->changeWorkingDirectoryTo(save);
76
FileSystem->setFileListSystem(current);
81
//! creates/loads an archive from the file.
82
//! \return Pointer to the created archive. Returns 0 if loading failed.
83
IFileArchive* CArchiveLoaderMount::createArchive(io::IReadFile* file, bool ignoreCase, bool ignorePaths) const
88
//! compatible Folder Architecture
89
CMountPointReader::CMountPointReader(IFileSystem * parent, const io::path& basename, bool ignoreCase, bool ignorePaths)
90
: CFileList(basename, ignoreCase, ignorePaths), Parent(parent)
92
//! ensure CFileList path ends in a slash
93
if (Path.lastChar() != '/' )
96
const io::path& work = Parent->getWorkingDirectory();
98
Parent->changeWorkingDirectoryTo(basename);
100
Parent->changeWorkingDirectoryTo(work);
106
//! returns the list of files
107
const IFileList* CMountPointReader::getFileList() const
112
void CMountPointReader::buildDirectory()
114
IFileList * list = Parent->createFileList();
118
const u32 size = list->getFileCount();
119
for (u32 i=0; i < size; ++i)
121
io::path full = list->getFullFileName(i);
122
full = full.subString(Path.size(), full.size() - Path.size());
124
if (!list->isDirectory(i))
126
addItem(full, list->getFileOffset(i), list->getFileSize(i), false, RealFileNames.size());
127
RealFileNames.push_back(list->getFullFileName(i));
131
const io::path rel = list->getFileName(i);
132
RealFileNames.push_back(list->getFullFileName(i));
134
io::path pwd = Parent->getWorkingDirectory();
135
if (pwd.lastChar() != '/')
139
if ( rel != "." && rel != ".." )
141
addItem(full, 0, 0, true, 0);
142
Parent->changeWorkingDirectoryTo(pwd);
144
Parent->changeWorkingDirectoryTo("..");
152
//! opens a file by index
153
IReadFile* CMountPointReader::createAndOpenFile(u32 index)
155
if (index >= Files.size())
158
return createReadFile(RealFileNames[Files[index].ID]);
161
//! opens a file by file name
162
IReadFile* CMountPointReader::createAndOpenFile(const io::path& filename)
164
s32 index = findFile(filename, false);
166
return createAndOpenFile(index);
175
#endif // __IRR_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_