Introduced FileSystem and Out classes
[openstranded.git] / src / filesystem.hh
bloba506816c2ca19cd0223aa622e1a57000b5397eb6
1 /*
2 * This file defines functions to look up file paths.
4 * Copyright (C) 2009 David Kolossa
6 * This file is part of OpenStranded.
8 * OpenStranded is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * OpenStranded is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with OpenStranded. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef STRANDED_FILESYSTEM_HH
23 #define STRANDED_FILESYSTEM_HH
25 #include <string>
26 #include <vector>
28 enum GfxType
30 GFX_NONE,
31 GFX_TEXTURE,
32 GFX_MODEL,
33 GFX_ICON,
34 GFX_SPRITE,
35 GFX_SKY
38 enum SfxType
40 SFX_NONE,
41 SFX_SPEECH,
42 SFX_EFFECT
45 struct DirectoryInfo
47 std::string path;
49 DirectoryInfo(std::string path);
52 struct FileInfo
54 std::string path;
55 int error;
57 FileInfo(std::string path, int error);
59 bool
60 exists();
63 class FileSystem
65 private:
66 static std::string modName;
68 public:
70 // Initialization
72 static void
73 setModName(std::string name);
75 static bool
76 initUserDirectory();
79 // Directories
81 static DirectoryInfo*
82 getUserDirectoryInfo();
84 static DirectoryInfo*
85 getGameDirectoryInfo();
87 static DirectoryInfo*
88 getModDirectoryInfo();
93 // General files
95 static FileInfo*
96 getSaveFileInfo(std::string name);
98 static FileInfo*
99 getMapFileInfo(std::string name);
102 // GFX files, wrappers for getGameFileInfo()
104 static FileInfo*
105 getGfxFileInfo(std::string name, GfxType type);
107 static FileInfo*
108 getTextureFileInfo(std::string name);
110 static FileInfo*
111 getModelFileInfo(std::string name);
113 static FileInfo*
114 getIconFileInfo(std::string name);
116 static FileInfo*
117 getSpriteFileInfo(std::string name);
119 static FileInfo*
120 getSkyFileInfo(std::string name);
125 // SFX files
127 static FileInfo*
128 getSfxFileInfo(std::string name, SfxType type);
130 static FileInfo*
131 getSpeechFileInfo(std::string name);
133 static FileInfo*
134 getEffectFileInfo(std::string name);
136 private:
138 * Return a vector with all files in a directory.
139 * The returned pointer to the vector needs to be freed by the
140 * calling function.
141 * @param dirPath The path of the directory
142 * @return A vector with the files of the filesystem without
143 * . and ..
145 static std::vector<std::string> *
146 getDirectoryVector(std::string dirPath);
149 * Check whether a filename string with a name and an extension
150 * exists in a vector of const char*.
151 * This method is case-insensitive on Windows and case-sensitive
152 * in all other cases. The vector for the extensions also
153 * defines a priority on which element is returned. The element
154 * with the smaller index is returned when it comes to
155 * conflicts.
156 * @param dirVector A pointer to a vector as returned by
157 * getDirectoryVector()
158 * @param extensions A vector with the extensions ordered by
159 * priority
160 * @param name The name of the file which is searched
161 * @return The matching string, "" if there is none.
163 static std::string
164 getFileNameFromDirectoryVector(std::vector<std::string> *dirVector, const std::vector<std::string> &extensions, std::string name);
167 * Check whether name has a directory in it and extract it.
168 * For example: "path/to/file" returns "path/to/".
169 * A simple "file" would return "".
171 static std::string
172 getDirectoryPart(std::string name);
175 * The reverse of getDirectoryPart(), this returns the file part.
176 * For example: "path/to/file" returns "file".
177 * "path/to/directory/" returns "".
179 static std::string
180 getFilePart(std::string name);
183 #endif /* STRANDED_FILESYSTEM_HH */