-
Notifications
You must be signed in to change notification settings - Fork 183
/
filefinder.h
266 lines (234 loc) · 6.94 KB
/
filefinder.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
* This file is part of EasyRPG Player.
*
* EasyRPG Player is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EasyRPG Player is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _FILEFINDER_H_
#define _FILEFINDER_H_
// Headers
#include "system.h"
#include <string>
#include <cstdio>
#include <ios>
#include <unordered_map>
#include <vector>
#ifdef PSP2
# include <psp2/types.h>
# define Offset SceOff
#else
# define Offset off_t
#endif
/**
* FileFinder contains helper methods for finding case
* insensitive files paths.
*/
namespace FileFinder {
/**
* Adds RTP paths to the file finder
*
* @param warn_no_rtp_found Emits a warning on screen when no RTP was found.
*/
void InitRtpPaths(bool warn_no_rtp_found = true);
/**
* Quits FileFinder.
*/
void Quit();
/**
* { case lowered path, real path }
*/
typedef std::unordered_map<std::string, std::string> string_map;
/**
* { case lowered directory name, non directory file list }
*/
typedef std::unordered_map<std::string, string_map> sub_members_type;
struct DirectoryTree {
std::string directory_path;
string_map files, directories;
sub_members_type sub_members;
}; // struct DirectoryTree
/**
* Finds an image file.
* Searches through the current RPG Maker game and the RTP directories.
*
* @param dir directory to check.
* @param name image file name to check.
* @return path to file.
*/
std::string FindImage(const std::string& dir, const std::string& name);
/**
* Finds a file.
* Searches through the current RPG Maker game and the RTP directories.
*
* @param dir directory to check.
* @param name file name to check.
* @return path to file.
*/
std::string FindDefault(const std::string& dir, const std::string& name);
/**
* Finds a file.
* Searches through the current RPG Maker game and the RTP directories.
*
* @param name the path and name.
* @return path to file.
*/
std::string FindDefault(const std::string& name);
/**
* Finds a file in a subdirectory of a custom directory tree.
*
* @param tree Project tree to search
* @param dir directory to check
* @param name the path and name
* @return path to file.
*/
std::string FindDefault(const DirectoryTree& tree, const std::string& dir, const std::string& name);
/**
* Finds a file from the root of a custom project tree.
*
* @param tree Project tree to search
* @param name the path and name
* @return path to file.
*/
std::string FindDefault(const DirectoryTree& tree, const std::string& name);
/**
* Finds a music file.
* Searches through the Music folder of the current RPG Maker game and
* the RTP directories.
*
* @param name the music path and name.
* @return path to file.
*/
std::string FindMusic(const std::string& name);
/**
* Finds a sound file.
* Searches through the Sound folder of the current RPG Maker game and
* the RTP directories.
*
* @param name the sound path and name.
* @return path to file.
*/
std::string FindSound(const std::string& name);
/**
* Finds a font file.
* Searches through the current RPG Maker game and the RTP directories.
*
* @param name the font name.
* @return path to file.
*/
std::string FindFont(const std::string& name);
/**
* Opens a file specified by a UTF-8 string.
*
* @param name_utf8 filename in UTF-8.
* @param mode ("r", "w", etc).
* @return FILE*.
*/
FILE* fopenUTF8(const std::string& name_utf8, char const* mode);
/**
* Creates stream from UTF-8 file name.
*
* @param name UTF-8 string file name.
* @param m stream mode.
* @return NULL if open failed.
*/
std::shared_ptr<std::fstream> openUTF8(const std::string& name, std::ios_base::openmode m);
struct Directory {
std::string base;
string_map files;
string_map directories;
}; // struct Directory
/**
* Checks whether passed file is directory.
* This function is case sensitve on some platform.
*
* @param file file to check.
* @return true if file is directory, otherwise false.
*/
bool IsDirectory(std::string const& file);
/**
* Checks whether passed file exists.
* This function is case sensitve on some platform.
*
* @param file file to check
* @return true if file exists, otherwise false.
*/
bool Exists(std::string const& file);
/**
* Appends name to directory.
*
* @param dir base directory.
* @param name file name to be appended to dir.
* @return combined path
*/
std::string MakePath(std::string const& dir, std::string const& name);
/**
* Converts a path to the canonical equivalent.
* This generates a path that does not contain ".." or "." directories.
*
* @param path Path to normalize
* @param initial_deepness How deep the passed path is relative to the game root
* @return canonical path
*/
std::string MakeCanonical(std::string const& path, int initial_deepness);
/**
* Splits a path in it's components.
*
* @param path Path to split
* @return Vector containing path components
*/
std::vector<std::string> SplitPath(std::string const& path);
/**
* GetDirectoryMembers member listing mode.
*/
enum Mode {
ALL, /**< list files and directory */
FILES, /**< list only non-directory files */
DIRECTORIES, /**< list only directories */
RECURSIVE /**< list non-directory files recursively */
};
/**
* Lists directory members.
*
* @param dir directory to list members.
* @param m member listing mode.
* @param parent name of current relative folder (used if m is RECURSIVE)
* @return member list.
*/
Directory GetDirectoryMembers(std::string const& dir, Mode m = ALL, std::string const& parent = "");
/**
* Sets the directory tree that is used for executing the current RPG Maker
* game.
*
* @param directory_tree Directory tree to use.
*/
void SetDirectoryTree(std::shared_ptr<DirectoryTree> directory_tree);
/**
* Gets the directory tree that is used by the current game.
*
* @return directory tree
*/
const std::shared_ptr<DirectoryTree> GetDirectoryTree();
const std::shared_ptr<DirectoryTree> CreateSaveDirectoryTree();
std::shared_ptr<DirectoryTree> CreateDirectoryTree(std::string const& p, bool recursive = true);
bool IsValidProject(DirectoryTree const& dir);
bool IsRPG2kProject(DirectoryTree const& dir);
bool IsEasyRpgProject(DirectoryTree const& dir);
/**
* Checks whether the save directory contains any savegame with name
* SaveXX.lsd (XX from 00 to 15).
*
* @return If directory tree contains a savegame
*/
bool HasSavegame();
} // namespace FileFinder
#endif