Added FileSystem class
[openstranded.git] / src / filesystem.hh
blob5fbd194c7345f6613e8f16c37c83953484a2215b
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 struct DirectoryInfo
30 std::string path;
32 DirectoryInfo(std::string path);
35 struct FileInfo
37 std::string path;
38 int error;
40 FileInfo(std::string path, int error);
42 bool
43 exists();
46 class FileSystem
48 private:
49 static std::string modName;
51 public:
53 // Initialization
55 static void
56 setModName(std::string name);
59 // Directories
61 static DirectoryInfo*
62 getUserDirectoryInfo();
64 static DirectoryInfo*
65 getGameDirectoryInfo();
67 static DirectoryInfo*
68 getModDirectoryInfo();
73 // General files
75 static FileInfo*
76 getSaveFileInfo(std::string name);
79 // GFX files
81 static FileInfo*
82 getTextureFileInfo(std::string name);
84 static FileInfo*
85 getModelFileInfo(std::string name);
87 static FileInfo*
88 getIconFileInfo(std::string name);
90 static FileInfo*
91 getSpriteFileInfo(std::string name);
93 static FileInfo*
94 getSkyFileInfo(std::string name);
99 // SFX files
101 static FileInfo*
102 getSpeechFileInfo(std::string name);
104 static FileInfo*
105 getEffectFileInfo(std::string name);
107 private:
109 * Return a vector with all files in a directory.
110 * The returned pointer to the vector needs to be freed by the
111 * calling function.
112 * @param dirPath The path of the directory
113 * @return A vector with the files of the filesystem without
114 * . and ..
116 static std::vector<std::string> *
117 getDirectoryVector(std::string dirPath);
120 * Check whether a filename string with a name and an extension
121 * exists in a vector of const char*.
122 * This method is case-insensitive on Windows and case-sensitive
123 * in all other cases. The vector for the extensions also
124 * defines a priority on which element is returned. The element
125 * with the smaller index is returned when it comes to
126 * conflicts.
127 * @param dirVector A pointer to a vector as returned by
128 * getDirectoryVector()
129 * @param extensions A vector with the extensions ordered by
130 * priority
131 * @param name The name of the file which is searched
132 * @return The matching string, "" if there is none.
134 static std::string
135 getFileNameFromDirectoryVector(std::vector<std::string> *dirVector, const std::vector<std::string> &extensions, std::string name);
138 #endif /* STRANDED_FILESYSTEM_HH */