OgreFileSystemLayer.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __FileSystemLayer_H__
#define __FileSystemLayer_H__
#include "OgrePrerequisites.h"
#include "OgreStringVector.h"
namespace Ogre
{
class _OgreExport FileSystemLayer : public FileSystemLayerAlloc
{
public:
FileSystemLayer(const Ogre::String& subdir)
{
// determine directories to search for config files
getConfigPaths();
// prepare write location in user directory
prepareUserHome(subdir);
}
const Ogre::String getConfigFilePath(Ogre::String filename) const
{
#if OGRE_DEBUG_MODE == 1 && (OGRE_PLATFORM != OGRE_PLATFORM_APPLE && OGRE_PLATFORM != OGRE_PLATFORM_APPLE_IOS)
// add OGRE_BUILD_SUFFIX (default: "_d") to config file names
Ogre::String::size_type pos = filename.rfind('.');
if (pos != Ogre::String::npos)
filename = filename.substr(0, pos) + OGRE_BUILD_SUFFIX + filename.substr(pos);
#endif
// look for the requested file in several locations:
// 1. in the writable path (so user can provide custom files)
Ogre::String path = getWritablePath(filename);
if (fileExists(path))
return path;
// 2. in the config file search paths
for (size_t i = 0; i < mConfigPaths.size(); ++i)
{
path = mConfigPaths[i] + filename;
if (fileExists(path))
return path;
}
// 3. fallback to current working dir
return filename;
}
const Ogre::String getWritablePath(const Ogre::String& filename) const
{
return mHomePath + filename;
}
void setConfigPaths(const Ogre::StringVector &paths){
mConfigPaths = paths;
}
void setHomePath(const Ogre::String &path){
mHomePath = path;
}
bool createDirectory(const Ogre::String& name);
private:
Ogre::StringVector mConfigPaths;
Ogre::String mHomePath;
void getConfigPaths();
void prepareUserHome(const Ogre::String& subdir);
bool fileExists(const Ogre::String& path) const;
};
}
#endif
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::FileSystemLayer::setHomePath
void setHomePath(const Ogre::String &path)
Definition: OgreFileSystemLayer.h:119
OGRE_BUILD_SUFFIX
#define OGRE_BUILD_SUFFIX
Definition: OgrePlatform.h:355
Ogre::FileSystemLayer::FileSystemLayer
FileSystemLayer(const Ogre::String &subdir)
Creates a concrete platform-dependent implementation of FileSystemLayer.
Definition: OgreFileSystemLayer.h:57
Ogre::FileSystemLayer::mHomePath
Ogre::String mHomePath
Definition: OgreFileSystemLayer.h:128
Ogre::StringVector
vector< String >::type StringVector
Definition: OgreStringVector.h:45
Ogre::FileSystemLayer
Provides methods to find out where the Ogre config files are stored and where logs and settings files...
Definition: OgreFileSystemLayer.h:49
Ogre::FileSystemLayer::getConfigFilePath
const Ogre::String getConfigFilePath(Ogre::String filename) const
Search for the given config file in the user&#39;s home path.
Definition: OgreFileSystemLayer.h:74
OgrePrerequisites.h
Ogre::FileSystemLayer::setConfigPaths
void setConfigPaths(const Ogre::StringVector &paths)
Definition: OgreFileSystemLayer.h:115
OgreStringVector.h
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::FileSystemLayer::getWritablePath
const Ogre::String getWritablePath(const Ogre::String &filename) const
Find a path where the given filename can be written to.
Definition: OgreFileSystemLayer.h:110
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::FileSystemLayer::mConfigPaths
Ogre::StringVector mConfigPaths
Definition: OgreFileSystemLayer.h:127
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.