OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreFileSystemLayer.h
Go to the documentation of this file.
1 /*
2  -----------------------------------------------------------------------------
3  This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5  For the latest info, see http://www.ogre3d.org/
6 
7  Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9  Permission is hereby granted, free of charge, to any person obtaining a copy
10  of this software and associated documentation files (the "Software"), to deal
11  in the Software without restriction, including without limitation the rights
12  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  copies of the Software, and to permit persons to whom the Software is
14  furnished to do so, subject to the following conditions:
15 
16  The above copyright notice and this permission notice shall be included in
17  all copies or substantial portions of the Software.
18 
19  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25  THE SOFTWARE.
26  -----------------------------------------------------------------------------
27  */
28 #ifndef __FileSystemLayer_H__
29 #define __FileSystemLayer_H__
30 
31 #include "OgrePrerequisites.h"
32 #include "OgreStringVector.h"
33 
34 namespace Ogre
35 {
50  {
51  public:
58  {
59  // determine directories to search for config files
60  getConfigPaths();
61  // prepare write location in user directory
62  prepareUserHome(subdir);
63  }
64 
75  {
76  #if OGRE_DEBUG_MODE == 1 && (OGRE_PLATFORM != OGRE_PLATFORM_APPLE && OGRE_PLATFORM != OGRE_PLATFORM_APPLE_IOS)
77  // add OGRE_BUILD_SUFFIX (default: "_d") to config file names
78  Ogre::String::size_type pos = filename.rfind('.');
79  if (pos != Ogre::String::npos)
80  filename = filename.substr(0, pos) + OGRE_BUILD_SUFFIX + filename.substr(pos);
81  #endif
82 
83  // look for the requested file in several locations:
84 
85  // 1. in the writable path (so user can provide custom files)
86  Ogre::String path = getWritablePath(filename);
87  if (fileExists(path))
88  return path;
89 
90  // 2. in the config file search paths
91  for (size_t i = 0; i < mConfigPaths.size(); ++i)
92  {
93  path = mConfigPaths[i] + filename;
94  if (fileExists(path))
95  return path;
96  }
97 
98  // 3. fallback to current working dir
99  return filename;
100  }
101 
110  const Ogre::String getWritablePath(const Ogre::String& filename) const
111  {
112  return mHomePath + filename;
113  }
114 
115  void setConfigPaths(const Ogre::StringVector &paths){
116  mConfigPaths = paths;
117  }
118 
119  void setHomePath(const Ogre::String &path){
120  mHomePath = path;
121  }
122 
124  bool createDirectory(const Ogre::String& name);
125 
126  private:
129 
131  void getConfigPaths();
132 
134  void prepareUserHome(const Ogre::String& subdir);
135 
137  bool fileExists(const Ogre::String& path) const;
138  };
139 
140 }
141 
142 
143 #endif
const Ogre::String getWritablePath(const Ogre::String &filename) const
Find a path where the given filename can be written to.
Provides methods to find out where the Ogre config files are stored and where logs and settings files...
#define _OgreExport
Definition: OgrePlatform.h:255
FileSystemLayer(const Ogre::String &subdir)
Creates a concrete platform-dependent implementation of FileSystemLayer.
void setHomePath(const Ogre::String &path)
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
vector< String >::type StringVector
#define OGRE_BUILD_SUFFIX
Definition: OgrePlatform.h:359
Ogre::StringVector mConfigPaths
void setConfigPaths(const Ogre::StringVector &paths)
_StringBase String
Definition: OgreCommon.h:53
const Ogre::String getConfigFilePath(Ogre::String filename) const
Search for the given config file in the user's home path.