aboutsummaryrefslogtreecommitdiff
path: root/source/Irrlicht/CFileSystem.h
blob: bc04fd82c678dd054aec245de3453a677b8cd579 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// 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

#ifndef __C_FILE_SYSTEM_H_INCLUDED__
#define __C_FILE_SYSTEM_H_INCLUDED__

#include "IFileSystem.h"
#include "irrArray.h"

namespace irr
{
namespace io
{

	class CZipReader;

/*!
	FileSystem which uses normal files and one zipfile
*/
class CFileSystem : public IFileSystem
{
public:

	//! constructor
	CFileSystem();

	//! destructor
	virtual ~CFileSystem();

	//! opens a file for read access
	IReadFile* createAndOpenFile(const io::path& filename) override;

	//! Creates an IReadFile interface for accessing memory like a file.
	IReadFile* createMemoryReadFile(const void* memory, s32 len, const io::path& fileName, bool deleteMemoryWhenDropped = false) override;

	//! Creates an IReadFile interface for accessing files inside files
	IReadFile* createLimitReadFile(const io::path& fileName, IReadFile* alreadyOpenedFile, long pos, long areaSize) override;

	//! Creates an IWriteFile interface for accessing memory like a file.
	IWriteFile* createMemoryWriteFile(void* memory, s32 len, const io::path& fileName, bool deleteMemoryWhenDropped=false) override;

	//! Opens a file for write access.
	IWriteFile* createAndWriteFile(const io::path& filename, bool append=false) override;

	//! Adds an archive to the file system.
	virtual bool addFileArchive(const io::path& filename,
			bool ignoreCase = true, bool ignorePaths = true,
			E_FILE_ARCHIVE_TYPE archiveType = EFAT_UNKNOWN,
			const core::stringc& password="",
			IFileArchive** retArchive = 0) override;

	//! Adds an archive to the file system.
	virtual bool addFileArchive(IReadFile* file, bool ignoreCase=true,
			bool ignorePaths=true,
			E_FILE_ARCHIVE_TYPE archiveType=EFAT_UNKNOWN,
			const core::stringc& password="",
			IFileArchive** retArchive = 0) override;

	//! Adds an archive to the file system.
	bool addFileArchive(IFileArchive* archive) override;

	//! move the hirarchy of the filesystem. moves sourceIndex relative up or down
	bool moveFileArchive(u32 sourceIndex, s32 relative) override;

	//! Adds an external archive loader to the engine.
	void addArchiveLoader(IArchiveLoader* loader) override;

	//! Returns the total number of archive loaders added.
	u32 getArchiveLoaderCount() const override;

	//! Gets the archive loader by index.
	IArchiveLoader* getArchiveLoader(u32 index) const override;

	//! gets the file archive count
	u32 getFileArchiveCount() const override;

	//! gets an archive
	IFileArchive* getFileArchive(u32 index) override;

	//! removes an archive from the file system.
	bool removeFileArchive(u32 index) override;

	//! removes an archive from the file system.
	bool removeFileArchive(const io::path& filename) override;

	//! Removes an archive from the file system.
	bool removeFileArchive(const IFileArchive* archive) override;

	//! Returns the string of the current working directory
	const io::path& getWorkingDirectory() override;

	//! Changes the current Working Directory to the string given.
	//! The string is operating system dependent. Under Windows it will look
	//! like this: "drive:\directory\sudirectory\"
	bool changeWorkingDirectoryTo(const io::path& newDirectory) override;

	//! Converts a relative path to an absolute (unique) path, resolving symbolic links
	io::path getAbsolutePath(const io::path& filename) const override;

	//! Returns the directory a file is located in.
	/** \param filename: The file to get the directory from */
	io::path getFileDir(const io::path& filename) const override;

	//! Returns the base part of a filename, i.e. the name without the directory
	//! part. If no directory is prefixed, the full name is returned.
	/** \param filename: The file to get the basename from */
	io::path getFileBasename(const io::path& filename, bool keepExtension=true) const override;

	//! flatten a path and file name for example: "/you/me/../." becomes "/you"
	io::path& flattenFilename( io::path& directory, const io::path& root = "/" ) const override;

	//! Get the relative filename, relative to the given directory
	path getRelativeFilename(const path& filename, const path& directory) const override;

	EFileSystemType setFileListSystem(EFileSystemType listType) override;

	//! Creates a list of files and directories in the current working directory
	//! and returns it.
	IFileList* createFileList() override;

	//! Creates an empty filelist
	IFileList* createEmptyFileList(const io::path& path, bool ignoreCase, bool ignorePaths) override;

	//! determines if a file exists and would be able to be opened.
	bool existFile(const io::path& filename) const override;

private:

	//! Currently used FileSystemType
	EFileSystemType FileSystemType;
	//! WorkingDirectory for Native and Virtual filesystems
	io::path WorkingDirectory [2];
	//! currently attached ArchiveLoaders
	core::array<IArchiveLoader*> ArchiveLoader;
	//! currently attached Archives
	core::array<IFileArchive*> FileArchives;
};


} // end namespace irr
} // end namespace io

#endif