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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
/***************************************************************************
* Copyright (C) 2005-2019 by the FIFE team *
* http://www.fifengine.net *
* This file is part of FIFE. *
* *
* FIFE is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef FIFE_VFS_VFS_H
#define FIFE_VFS_VFS_H
// Standard C++ library includes
#include <string>
#include <vector>
#include <set>
// 3rd party library includes
#include <boost/shared_ptr.hpp>
// FIFE includes
// These includes are split up in two parts, separated by one empty line
// First block: files included from the FIFE root src directory
// Second block: files included from the same folder
#include "util/base/singleton.h"
namespace FIFE {
class RawData;
class VFSSourceProvider;
class VFSSource;
/** the main VFS (virtual file system) class
*
* The VFS is intended to provide transparent and portable access to files.
* @note The VFS searches for a provider in the order they are added to the
* VFS. Since the VFSHostSystem is added first, this implies, that host filesystem
* files will override whatever might be in other VFS Sources (e.g. the DAT files)
*
* @note All filenames have to be @b lowercase. The VFS will convert them to lowercase
* and emit a warning. This is done to avoid problems with filesystems which are not
* case sensitive.
*/
class VFS : public DynamicSingleton<VFS>{
public:
/** Constructor
* Called by the Engine on startup. Never create one yourself.
*/
VFS();
/** Destructor
*/
virtual ~VFS();
void cleanup();
/** add new VFSSourceProvider
*
* @note VFS assumes ownership over the given provider - so don't do anything with it
* after you call this function, especialy don't delete it!
* @param provider the new provider
*/
void addProvider(VFSSourceProvider* provider);
/** tries to create a new VFSSource for the given file
*
* all currently known VFSSourceProviders are tried until one succeeds - if no provider succeeds 0 is returned
* @param path the archive-file
* @return the new VFSSource or 0 if no provider was succesfull or the file was already used as source
*/
VFSSource* createSource(const std::string& path);
/** create a new Source and add it to VFS
* @see VFSSource* createSource(const std::string& file)
*/
void addNewSource(const std::string& path);
/** Add a new VFSSource */
void addSource(VFSSource* source);
/** remove a VFSSource */
void removeSource(VFSSource* source);
void removeSource(const std::string& path);
/** Check if the given file exists
*
* @param file the filename
* @return true if it exists, false if not
*/
bool exists(const std::string& file) const;
/** Check if the given path is a directory
*
* @param path to check
* @return true if it is a directory, false if not
*/
bool isDirectory(const std::string& path) const;
/** Open a file
*
* @param path the file to open
* @return the opened file; delete this when done.
* @throws NotFound if the file cannot be found
*/
RawData* open(const std::string& path);
/** Get a filelist of the given directory
*
* @param path the directory
* @return the filelist
*/
std::set<std::string> listFiles(const std::string& path) const;
/** List the files of a given directory matching a regex
*
* The whole string has to match the regex, this means if you want all files that end with .map don't search for
* "\.map" but ".*\.map" (and escape the \)
*
* @param path the directory
* @param filterregex the regex the files have to match
* @return the filelist
*/
std::set<std::string> listFiles(const std::string& path, const std::string& filterregex) const;
/** Get a directorylist of the given directory
*
* @param path the directory
* @return the directorylist
*/
std::set<std::string> listDirectories(const std::string& path) const;
/** List the subdirectorys of a given directory matching a regex
*
* @param path the directory
* @param filterregex the regex the files have to match
* @return the filelist
*/
std::set<std::string> listDirectories(const std::string& path, const std::string& filterregex) const;
/** Checks if a source is already present in a provider
*
* @param path the directory
* @return true if the source is present, false if not
*/
bool hasSource(const std::string& path) const;
private:
typedef std::vector<VFSSourceProvider*> type_providers;
type_providers m_providers;
typedef std::vector<VFSSource*> type_sources;
type_sources m_sources;
std::set<std::string> filterList(const std::set<std::string>& list, const std::string& fregex) const;
VFSSource* getSourceForFile(const std::string& file) const;
};
}
#endif
|