forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 2
/
dirs.c
313 lines (273 loc) · 7.66 KB
/
dirs.c
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2017 - Daniel De Matteis
*
* RetroArch 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 Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch 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 RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <retro_miscellaneous.h>
#include <compat/strl.h>
#include <file/file_path.h>
#include <lists/dir_list.h>
#include <lists/string_list.h>
#include <string/stdstring.h>
#include <retro_assert.h>
#include <retro_stat.h>
#include "dirs.h"
#include "command.h"
#include "configuration.h"
#include "command.h"
#include "defaults.h"
#include "list_special.h"
#include "file_path_special.h"
#include "msg_hash.h"
#include "paths.h"
#include "content.h"
#include "retroarch.h"
#include "verbosity.h"
struct rarch_dir_list
{
struct string_list *list;
size_t ptr;
};
static struct rarch_dir_list dir_shader_list;
static char dir_system[PATH_MAX_LENGTH] = {0};
static char dir_savefile[PATH_MAX_LENGTH] = {0};
static char current_savefile_dir[PATH_MAX_LENGTH] = {0};
static char current_savestate_dir[PATH_MAX_LENGTH] = {0};
static char dir_savestate[PATH_MAX_LENGTH] = {0};
/* init functions */
bool dir_init_shader(void)
{
unsigned i;
struct rarch_dir_list *dir_list = (struct rarch_dir_list*)&dir_shader_list;
settings_t *settings = config_get_ptr();
if (!*settings->paths.directory_video_shader)
return false;
dir_list->list = dir_list_new_special(
settings->paths.directory_video_shader, DIR_LIST_SHADERS, NULL);
if (!dir_list->list || dir_list->list->size == 0)
{
command_event(CMD_EVENT_SHADER_DIR_DEINIT, NULL);
return false;
}
dir_list->ptr = 0;
dir_list_sort(dir_list->list, false);
for (i = 0; i < dir_list->list->size; i++)
RARCH_LOG("%s \"%s\"\n",
msg_hash_to_str(MSG_FOUND_SHADER),
dir_list->list->elems[i].data);
return true;
}
/* free functions */
bool dir_free_shader(void)
{
struct rarch_dir_list *dir_list =
(struct rarch_dir_list*)&dir_shader_list;
dir_list_free(dir_list->list);
dir_list->list = NULL;
dir_list->ptr = 0;
return true;
}
/* check functions */
/**
* dir_check_shader:
* @pressed_next : was next shader key pressed?
* @pressed_previous : was previous shader key pressed?
*
* Checks if any one of the shader keys has been pressed for this frame:
* a) Next shader index.
* b) Previous shader index.
*
* Will also immediately apply the shader.
**/
void dir_check_shader(bool pressed_next, bool pressed_prev)
{
struct rarch_dir_list *dir_list = (struct rarch_dir_list*)&dir_shader_list;
if (!dir_list || !dir_list->list)
return;
if (pressed_next)
{
dir_list->ptr = (dir_list->ptr + 1) %
dir_list->list->size;
}
else if (pressed_prev)
{
if (dir_list->ptr == 0)
dir_list->ptr = dir_list->list->size - 1;
else
dir_list->ptr--;
}
else
return;
command_set_shader(dir_list->list->elems[dir_list->ptr].data);
}
/* empty functions */
bool dir_is_empty(enum rarch_dir_type type)
{
switch (type)
{
case RARCH_DIR_SYSTEM:
return string_is_empty(dir_savefile);
case RARCH_DIR_SAVEFILE:
return string_is_empty(dir_savefile);
case RARCH_DIR_CURRENT_SAVEFILE:
return string_is_empty(current_savefile_dir);
case RARCH_DIR_SAVESTATE:
return string_is_empty(dir_savestate);
case RARCH_DIR_CURRENT_SAVESTATE:
return string_is_empty(current_savestate_dir);
case RARCH_DIR_NONE:
break;
}
return false;
}
/* get size functions */
size_t dir_get_size(enum rarch_dir_type type)
{
switch (type)
{
case RARCH_DIR_SYSTEM:
return sizeof(dir_system);
case RARCH_DIR_SAVESTATE:
return sizeof(dir_savestate);
case RARCH_DIR_CURRENT_SAVESTATE:
return sizeof(current_savestate_dir);
case RARCH_DIR_SAVEFILE:
return sizeof(dir_savefile);
case RARCH_DIR_CURRENT_SAVEFILE:
return sizeof(current_savefile_dir);
case RARCH_DIR_NONE:
break;
}
return 0;
}
/* clear functions */
void dir_clear(enum rarch_dir_type type)
{
switch (type)
{
case RARCH_DIR_SAVEFILE:
*dir_savefile = '\0';
break;
case RARCH_DIR_CURRENT_SAVEFILE:
*current_savefile_dir = '\0';
break;
case RARCH_DIR_SAVESTATE:
*dir_savestate = '\0';
break;
case RARCH_DIR_CURRENT_SAVESTATE:
*current_savestate_dir = '\0';
break;
case RARCH_DIR_SYSTEM:
*dir_system = '\0';
break;
case RARCH_DIR_NONE:
break;
}
}
void dir_clear_all(void)
{
dir_clear(RARCH_DIR_SYSTEM);
dir_clear(RARCH_DIR_SAVEFILE);
dir_clear(RARCH_DIR_SAVESTATE);
}
/* get ptr functions */
char *dir_get_ptr(enum rarch_dir_type type)
{
switch (type)
{
case RARCH_DIR_SAVEFILE:
return dir_savefile;
case RARCH_DIR_CURRENT_SAVEFILE:
return current_savefile_dir;
case RARCH_DIR_SAVESTATE:
return dir_savestate;
case RARCH_DIR_CURRENT_SAVESTATE:
return current_savestate_dir;
case RARCH_DIR_SYSTEM:
return dir_system;
case RARCH_DIR_NONE:
break;
}
return NULL;
}
const char *dir_get(enum rarch_dir_type type)
{
switch (type)
{
case RARCH_DIR_SAVEFILE:
return dir_savefile;
case RARCH_DIR_CURRENT_SAVEFILE:
return current_savefile_dir;
case RARCH_DIR_SAVESTATE:
return dir_savestate;
case RARCH_DIR_CURRENT_SAVESTATE:
return current_savestate_dir;
case RARCH_DIR_SYSTEM:
return dir_system;
case RARCH_DIR_NONE:
break;
}
return NULL;
}
void dir_set(enum rarch_dir_type type, const char *path)
{
switch (type)
{
case RARCH_DIR_CURRENT_SAVEFILE:
strlcpy(current_savefile_dir, path,
sizeof(current_savefile_dir));
break;
case RARCH_DIR_SAVEFILE:
strlcpy(dir_savefile, path,
sizeof(dir_savefile));
break;
case RARCH_DIR_CURRENT_SAVESTATE:
strlcpy(current_savestate_dir, path,
sizeof(current_savestate_dir));
break;
case RARCH_DIR_SAVESTATE:
strlcpy(dir_savestate, path,
sizeof(dir_savestate));
break;
case RARCH_DIR_SYSTEM:
strlcpy(dir_system, path,
sizeof(dir_system));
break;
case RARCH_DIR_NONE:
break;
}
}
static void check_defaults_dir_create_dir(const char *path)
{
char new_path[PATH_MAX_LENGTH];
new_path[0] = '\0';
fill_pathname_expand_special(new_path,
path, sizeof(new_path));
if (path_is_directory(new_path))
return;
path_mkdir(new_path);
}
void dir_check_defaults(void)
{
unsigned i;
/* early return for people with a custom folder setup
so it doesn't create unnecessary directories
*/
if (path_file_exists("custom.ini"))
return;
for (i = 0; i < DEFAULT_DIR_LAST; i++)
{
const char *dir_path = g_defaults.dirs[i];
if (!string_is_empty(dir_path))
check_defaults_dir_create_dir(dir_path);
}
}