20#ifndef HEADER_FILE_MANAGER_HPP
21#define HEADER_FILE_MANAGER_HPP
36 namespace io {
class IFileSystem; }
40#include "io/xml_node.hpp"
41#include "utils/no_copy.hpp"
45 std::string m_texture_search_path;
46 std::string m_container_id;
49 m_texture_search_path(path), m_container_id(container_id)
65 GFX, GRANDPRIX, GUI_ICON, GUI_SCREEN, GUI_DIALOG,
66 REPLAY, SHADER, SKIN, TTF, TRANSLATION, BUILTIN_ASSETS=TRANSLATION,
67 LIBRARY, MODEL, MUSIC, SFX, TEXTURE, SCRIPT, ASSET_MAX = SCRIPT,
110 std::vector<TextureSearchPath> m_texture_search_path;
112 std::vector<std::string>
115 bool findFile(std::string& full_path,
116 const std::string& fname,
117 const std::vector<std::string>& search_path)
119 bool findFile(std::string& full_path,
120 const std::string& fname,
121 const std::vector<TextureSearchPath>& search_path)
123 void makePath(std::string& path,
const std::string& dir,
124 const std::string& fname)
const;
133 void addAssetsSearchPath();
135#if !defined(WIN32) && !defined(__APPLE__)
137 const char *dir_name,
138 const char *fallback1,
139 const char *fallback2=NULL);
146 void reinitAfterDownloadAssets();
150 io::IXMLReader *createXMLReader(
const std::string &filename);
164 bool removeFile(
const std::string &name)
const;
169 bool copyFile(
const std::string &source,
const std::string &dest);
171 std::string getAssetChecked(
AssetType type,
const std::string& name,
172 bool abort_on_error=
false)
const;
174 std::string
getAsset(
const std::string &name)
const;
182 std::string
searchMusic(
const std::string& file_name)
const;
184 std::string
searchModel(
const std::string& file_name)
const;
187 bool fileExists(
const std::string& path)
const;
191 bool fileExists(
const char *prefix,
const std::string& path)
const
193 return fileExists(std::string(prefix) + path);
196 bool searchTextureContainerId(std::string& container_id,
197 const std::string& file_name)
const;
202 void listFiles (std::set<std::string>& result,
203 const std::string& dir,
204 bool make_full_path=
false)
const;
214 bool fileIsNewer(
const std::string& f1,
const std::string& f2)
const;
225 m_music_search_path.push_back(path);
238 std::string getShadersDir()
const
243 const std::string& getSTKAssetsDownloadDir()
const
246 const std::string& getCertBundleLocation()
const
class handling files and paths
Definition: file_manager.hpp:59
static void addRootDirs(const std::string &roots)
Adds paths to the list of stk root directories.
Definition: file_manager.cpp:553
bool fileExists(const std::string &path) const
Returns true if the specified file exists.
Definition: file_manager.cpp:533
void checkAndCreateReplayDir()
Creates the directories for replay recorded.
Definition: file_manager.cpp:1157
bool moveDirectoryInto(std::string source, std::string target)
Move the source directory into the target directory location.
Definition: file_manager.cpp:1628
void resetSubdir()
Reset subdirectories to initial state, for example after download assets.
Definition: file_manager.cpp:277
std::string getAssetDirectory(AssetType type) const
Returns the directory of an asset.
Definition: file_manager.hpp:177
void listFiles(std::set< std::string > &result, const std::string &dir, bool make_full_path=false) const
Returns a list of files in a given directory.
Definition: file_manager.cpp:1466
bool removeFile(const std::string &name) const
Removes the specified file.
Definition: file_manager.cpp:1508
io::IFileSystem * m_file_system
Handle to irrlicht's file systems.
Definition: file_manager.hpp:75
void popTextureSearchPath()
Removes the last added texture search path from the list of paths.
Definition: file_manager.cpp:693
std::vector< std::string > m_subdir_name
The names of the various subdirectories of the asset types.
Definition: file_manager.hpp:72
bool removeDirectory(const std::string &name) const
Removes a directory (including all files contained).
Definition: file_manager.cpp:1534
std::string checkAndCreateLinuxDir(const char *env_name, const char *dir_name, const char *fallback1, const char *fallback2=NULL)
Find a directory to use for remaining unix variants.
Definition: file_manager.cpp:1245
std::string getAsset(AssetType type, const std::string &name) const
Returns the full path of a file of the given asset class.
Definition: file_manager.cpp:798
std::string m_addons_dir
Directory where addons are stored.
Definition: file_manager.hpp:81
static void setStdoutDir(const std::string &dir)
Sets the directory for the stdout log file.
Definition: file_manager.cpp:1328
static std::string m_stdout_filename
Name of stdout file.
Definition: file_manager.hpp:87
bool copyFile(const std::string &source, const std::string &dest)
Copies the file source to dest.
Definition: file_manager.cpp:1583
std::string searchTexture(const std::string &fname) const
Returns the full path of a texture file name by searching in all directories currently in the texture...
Definition: file_manager.cpp:862
static std::string m_stdout_dir
Directory of stdout file.
Definition: file_manager.hpp:90
std::string searchMusic(const std::string &file_name) const
Returns the full path of a music file by searching all music search paths.
Definition: file_manager.cpp:1404
void popModelSearchPath()
Removes the last added model search path from the list of paths.
Definition: file_manager.cpp:706
irr::io::IFileSystem * getFileSystem()
Returns the irrlicht file system.
Definition: file_manager.hpp:219
void pushModelSearchPath(const std::string &path)
Adds a model search path to the list of model search paths.
Definition: file_manager.cpp:635
void pushTextureSearchPath(const std::string &path, const std::string &container_id)
Adds a texture search path to the list of texture search paths.
Definition: file_manager.cpp:664
void checkAndCreateAddonsDir()
Creates the directories for the addons data.
Definition: file_manager.cpp:1090
bool checkAndCreateDirectoryP(const std::string &path)
If the directory specified in path does not exist, it is created recursively (mkdir -p style).
Definition: file_manager.cpp:930
bool fileIsNewer(const std::string &f1, const std::string &f2) const
Returns true if the first file is newer than the second.
Definition: file_manager.cpp:1615
void discoverPaths()
Detects where the assets are stored.
Definition: file_manager.cpp:303
FileManager()
The constructor of the file manager creates an irrlicht file system and detects paths for the user co...
Definition: file_manager.cpp:140
std::string m_user_config_dir
Directory where user config files are stored.
Definition: file_manager.hpp:78
std::string m_cached_textures_dir
Directory where resized textures are cached.
Definition: file_manager.hpp:99
std::string m_screenshot_dir
Directory to store screenshots in.
Definition: file_manager.hpp:93
std::string getAddonsFile(const std::string &name)
Returns the full path of a file in the addons directory.
Definition: file_manager.cpp:1386
std::string m_gp_dir
Directory where user-defined grand prix are stored.
Definition: file_manager.hpp:102
std::string searchModel(const std::string &file_name) const
Returns the full path of a model file by searching all model search paths.
Definition: file_manager.cpp:1430
XMLNode * createXMLTree(const std::string &filename)
Reads in a XML file and converts it into a XMLNode tree.
Definition: file_manager.cpp:573
void checkAndCreateGPDir()
Creates the directories for user-defined grand prix.
Definition: file_manager.cpp:1208
bool checkAndCreateDirectory(const std::string &path)
If the directory specified in path does not exist, it is created.
Definition: file_manager.cpp:906
std::string getScreenshotDir() const
Returns the directory in which screenshots should be stored.
Definition: file_manager.cpp:823
void redirectOutput()
Redirects output to go into files in the user's config directory instead of to the console.
Definition: file_manager.cpp:1343
std::string getCachedTexturesDir() const
Returns the directory in which resized textures should be cached.
Definition: file_manager.cpp:839
std::string getReplayDir() const
Returns the directory in which replay file should be stored.
Definition: file_manager.cpp:831
std::string m_replay_dir
Directory to store replays in.
Definition: file_manager.hpp:96
void checkAndCreateCachedTexturesDir()
Creates the directories for cached textures.
Definition: file_manager.cpp:1183
void checkAndCreateScreenshotDir()
Creates the directories for screenshots.
Definition: file_manager.cpp:1131
AssetType
The various asset types (and directories) STK might request.
Definition: file_manager.hpp:63
void pushMusicSearchPath(const std::string &path)
Adds a directory to the music search path (or stack).
Definition: file_manager.hpp:223
static void setStdoutName(const std::string &name)
Sets the name for the stdout log file.
Definition: file_manager.cpp:1319
void popMusicSearchPath()
Removes the last added directory from the music search path.
Definition: file_manager.cpp:719
std::vector< std::string > getMusicDirs() const
Returns the list of all directories in which music files are searched.
Definition: file_manager.cpp:893
std::string m_cert_bundle_location
Location of the certificate bundle.
Definition: file_manager.hpp:105
std::string m_stk_assets_download_dir
Mobile stk specific to download stk-assets in the first.
Definition: file_manager.hpp:108
static const std::string & getStdoutName()
Returns the name of the stdout file for log messages.
Definition: file_manager.hpp:200
void checkAndCreateConfigDir()
Checks if the config directory exists, and it not, tries to create it.
Definition: file_manager.cpp:964
std::string getShader(const std::string &name) const
Returns the full path to a shader (this function could be modified later to allow track-specific shad...
Definition: file_manager.hpp:232
static bool isDirectory(const std::string &path)
Returns true if the given name is a directory.
Definition: file_manager.cpp:1447
std::string getUserConfigFile(const std::string &fname) const
Returns the full path of the config directory.
Definition: file_manager.cpp:1394
std::string getGPDir() const
Returns the directory in which user-defined grand prix should be stored.
Definition: file_manager.cpp:847
const std::string & getAddonsDir() const
Returns the directory for addon files.
Definition: file_manager.cpp:1377
void checkAndCreateDirForAddons(const std::string &dir)
Creates a directory for an addon.
Definition: file_manager.cpp:1492
io::path createAbsoluteFilename(const std::string &f)
In order to add and later remove paths we have to specify the absolute filename (and replace '\' with...
Definition: file_manager.cpp:624
bool fileExists(const char *prefix, const std::string &path) const
Convenience function to save some typing in the file manager constructor.
Definition: file_manager.hpp:191
void init()
This function is used to initialise the file-manager after reading in the user configuration data.
Definition: file_manager.cpp:419
XMLNode * createXMLTreeFromString(const std::string &content)
Reads in XML from a string and converts it into a XMLNode tree.
Definition: file_manager.cpp:594
static std::vector< std::string > m_root_dirs
The list of all root directories.
Definition: file_manager.hpp:84
bool findFile(std::string &full_path, const std::string &fname, const std::vector< std::string > &search_path) const
Tries to find the specified file in any of the given search paths.
Definition: file_manager.cpp:735
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
utility class used to parse XML files
Definition: xml_node.hpp:48
Definition: file_manager.hpp:44