diff options
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CMountPointReader.cpp')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CMountPointReader.cpp | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CMountPointReader.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CMountPointReader.cpp new file mode 100644 index 0000000..e78c3ff --- /dev/null +++ b/libraries/irrlicht-1.8/source/Irrlicht/CMountPointReader.cpp | |||
@@ -0,0 +1,175 @@ | |||
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 "CMountPointReader.h" | ||
6 | |||
7 | #ifdef __IRR_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_ | ||
8 | |||
9 | #include "CReadFile.h" | ||
10 | #include "os.h" | ||
11 | |||
12 | namespace irr | ||
13 | { | ||
14 | namespace io | ||
15 | { | ||
16 | |||
17 | //! Constructor | ||
18 | CArchiveLoaderMount::CArchiveLoaderMount( io::IFileSystem* fs) | ||
19 | : FileSystem(fs) | ||
20 | { | ||
21 | #ifdef _DEBUG | ||
22 | setDebugName("CArchiveLoaderMount"); | ||
23 | #endif | ||
24 | } | ||
25 | |||
26 | |||
27 | //! returns true if the file maybe is able to be loaded by this class | ||
28 | bool CArchiveLoaderMount::isALoadableFileFormat(const io::path& filename) const | ||
29 | { | ||
30 | io::path fname(filename); | ||
31 | deletePathFromFilename(fname); | ||
32 | |||
33 | if (!fname.size()) | ||
34 | return true; | ||
35 | IFileList* list = FileSystem->createFileList(); | ||
36 | bool ret = false; | ||
37 | if (list) | ||
38 | { | ||
39 | // check if name is found as directory | ||
40 | if (list->findFile(filename, true)) | ||
41 | ret=true; | ||
42 | list->drop(); | ||
43 | } | ||
44 | return ret; | ||
45 | } | ||
46 | |||
47 | //! Check to see if the loader can create archives of this type. | ||
48 | bool CArchiveLoaderMount::isALoadableFileFormat(E_FILE_ARCHIVE_TYPE fileType) const | ||
49 | { | ||
50 | return fileType == EFAT_FOLDER; | ||
51 | } | ||
52 | |||
53 | //! Check if the file might be loaded by this class | ||
54 | bool CArchiveLoaderMount::isALoadableFileFormat(io::IReadFile* file) const | ||
55 | { | ||
56 | return false; | ||
57 | } | ||
58 | |||
59 | //! Creates an archive from the filename | ||
60 | IFileArchive* CArchiveLoaderMount::createArchive(const io::path& filename, bool ignoreCase, bool ignorePaths) const | ||
61 | { | ||
62 | IFileArchive *archive = 0; | ||
63 | |||
64 | EFileSystemType current = FileSystem->setFileListSystem(FILESYSTEM_NATIVE); | ||
65 | |||
66 | const io::path save = FileSystem->getWorkingDirectory(); | ||
67 | io::path fullPath = FileSystem->getAbsolutePath(filename); | ||
68 | FileSystem->flattenFilename(fullPath); | ||
69 | |||
70 | if (FileSystem->changeWorkingDirectoryTo(fullPath)) | ||
71 | { | ||
72 | archive = new CMountPointReader(FileSystem, fullPath, ignoreCase, ignorePaths); | ||
73 | } | ||
74 | |||
75 | FileSystem->changeWorkingDirectoryTo(save); | ||
76 | FileSystem->setFileListSystem(current); | ||
77 | |||
78 | return archive; | ||
79 | } | ||
80 | |||
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 | ||
84 | { | ||
85 | return 0; | ||
86 | } | ||
87 | |||
88 | //! compatible Folder Architecture | ||
89 | CMountPointReader::CMountPointReader(IFileSystem * parent, const io::path& basename, bool ignoreCase, bool ignorePaths) | ||
90 | : CFileList(basename, ignoreCase, ignorePaths), Parent(parent) | ||
91 | { | ||
92 | //! ensure CFileList path ends in a slash | ||
93 | if (Path.lastChar() != '/' ) | ||
94 | Path.append('/'); | ||
95 | |||
96 | const io::path& work = Parent->getWorkingDirectory(); | ||
97 | |||
98 | Parent->changeWorkingDirectoryTo(basename); | ||
99 | buildDirectory(); | ||
100 | Parent->changeWorkingDirectoryTo(work); | ||
101 | |||
102 | sort(); | ||
103 | } | ||
104 | |||
105 | |||
106 | //! returns the list of files | ||
107 | const IFileList* CMountPointReader::getFileList() const | ||
108 | { | ||
109 | return this; | ||
110 | } | ||
111 | |||
112 | void CMountPointReader::buildDirectory() | ||
113 | { | ||
114 | IFileList * list = Parent->createFileList(); | ||
115 | if (!list) | ||
116 | return; | ||
117 | |||
118 | const u32 size = list->getFileCount(); | ||
119 | for (u32 i=0; i < size; ++i) | ||
120 | { | ||
121 | io::path full = list->getFullFileName(i); | ||
122 | full = full.subString(Path.size(), full.size() - Path.size()); | ||
123 | |||
124 | if (!list->isDirectory(i)) | ||
125 | { | ||
126 | addItem(full, list->getFileOffset(i), list->getFileSize(i), false, RealFileNames.size()); | ||
127 | RealFileNames.push_back(list->getFullFileName(i)); | ||
128 | } | ||
129 | else | ||
130 | { | ||
131 | const io::path rel = list->getFileName(i); | ||
132 | RealFileNames.push_back(list->getFullFileName(i)); | ||
133 | |||
134 | io::path pwd = Parent->getWorkingDirectory(); | ||
135 | if (pwd.lastChar() != '/') | ||
136 | pwd.append('/'); | ||
137 | pwd.append(rel); | ||
138 | |||
139 | if ( rel != "." && rel != ".." ) | ||
140 | { | ||
141 | addItem(full, 0, 0, true, 0); | ||
142 | Parent->changeWorkingDirectoryTo(pwd); | ||
143 | buildDirectory(); | ||
144 | Parent->changeWorkingDirectoryTo(".."); | ||
145 | } | ||
146 | } | ||
147 | } | ||
148 | |||
149 | list->drop(); | ||
150 | } | ||
151 | |||
152 | //! opens a file by index | ||
153 | IReadFile* CMountPointReader::createAndOpenFile(u32 index) | ||
154 | { | ||
155 | if (index >= Files.size()) | ||
156 | return 0; | ||
157 | |||
158 | return createReadFile(RealFileNames[Files[index].ID]); | ||
159 | } | ||
160 | |||
161 | //! opens a file by file name | ||
162 | IReadFile* CMountPointReader::createAndOpenFile(const io::path& filename) | ||
163 | { | ||
164 | s32 index = findFile(filename, false); | ||
165 | if (index != -1) | ||
166 | return createAndOpenFile(index); | ||
167 | else | ||
168 | return 0; | ||
169 | } | ||
170 | |||
171 | |||
172 | } // io | ||
173 | } // irr | ||
174 | |||
175 | #endif // __IRR_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_ | ||