forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 2
/
list_special.c
359 lines (305 loc) · 9.66 KB
/
list_special.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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2016-2017 - Brad Parker
*
* 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 <string.h>
#include <lists/dir_list.h>
#include <lists/string_list.h>
#include <compat/strl.h>
#include <audio/audio_resampler.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_MENU
#include "menu/menu_driver.h"
#endif
#ifdef HAVE_CAMERA
#include "camera/camera_driver.h"
#endif
#ifdef HAVE_WIFI
#include "wifi/wifi_driver.h"
#endif
#ifdef HAVE_LOCATION
#include "location/location_driver.h"
#endif
#include "list_special.h"
#include "frontend/frontend_driver.h"
#include "core_info.h"
#include "gfx/video_driver.h"
#include "input/input_driver.h"
#include "audio/audio_driver.h"
#include "record/record_driver.h"
#include "configuration.h"
struct string_list *dir_list_new_special(const char *input_dir,
enum dir_list_type type, const char *filter)
{
char ext_shaders[255];
char ext_name[255];
const char *dir = NULL;
const char *exts = NULL;
bool include_dirs = false;
bool recursive = false;
settings_t *settings = config_get_ptr();
ext_shaders[0] = ext_name[0] = '\0';
(void)input_dir;
switch (type)
{
case DIR_LIST_AUTOCONFIG:
dir = input_dir;
exts = filter;
break;
case DIR_LIST_CORES:
dir = input_dir;
if (!frontend_driver_get_core_extension(ext_name, sizeof(ext_name)))
return NULL;
exts = ext_name;
break;
case DIR_LIST_CORE_INFO:
{
core_info_list_t *list = NULL;
core_info_get_list(&list);
dir = input_dir;
if (list)
exts = list->all_ext;
}
break;
case DIR_LIST_RECURSIVE:
{
core_info_list_t *list = NULL;
core_info_get_list(&list);
dir = input_dir;
if (list)
exts = list->all_ext;
recursive = true;
}
break;
case DIR_LIST_SHADERS:
{
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_VULKAN)
union string_list_elem_attr attr;
#endif
struct string_list *str_list = string_list_new();
if (!str_list)
return NULL;
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_VULKAN)
attr.i = 0;
#endif
dir = input_dir;
#ifdef HAVE_CG
string_list_append(str_list, "cg", attr);
string_list_append(str_list, "cgp", attr);
#endif
#ifdef HAVE_GLSL
string_list_append(str_list, "glsl", attr);
string_list_append(str_list, "glslp", attr);
#endif
#ifdef HAVE_VULKAN
string_list_append(str_list, "slang", attr);
string_list_append(str_list, "slangp", attr);
#endif
string_list_join_concat(ext_shaders, sizeof(ext_shaders), str_list, "|");
string_list_free(str_list);
exts = ext_shaders;
}
break;
case DIR_LIST_COLLECTIONS:
dir = input_dir;
exts = "lpl";
break;
case DIR_LIST_DATABASES:
dir = input_dir;
exts = "rdb";
break;
case DIR_LIST_PLAIN:
dir = input_dir;
exts = filter;
break;
case DIR_LIST_NONE:
default:
return NULL;
}
return dir_list_new(dir, exts, include_dirs, settings->bools.show_hidden_files,
type == DIR_LIST_CORE_INFO, recursive);
}
struct string_list *string_list_new_special(enum string_list_type type,
void *data, unsigned *len, size_t *list_size)
{
union string_list_elem_attr attr;
unsigned i;
core_info_list_t *core_info_list = NULL;
const core_info_t *core_info = NULL;
struct string_list *s = string_list_new();
if (!s || !len)
goto error;
attr.i = 0;
*len = 0;
switch (type)
{
case STRING_LIST_MENU_DRIVERS:
#ifdef HAVE_MENU
for (i = 0; menu_driver_find_handle(i); i++)
{
const char *opt = menu_driver_find_ident(i);
*len += strlen(opt) + 1;
string_list_append(s, opt, attr);
}
break;
#endif
case STRING_LIST_CAMERA_DRIVERS:
#ifdef HAVE_CAMERA
for (i = 0; camera_driver_find_handle(i); i++)
{
const char *opt = camera_driver_find_ident(i);
*len += strlen(opt) + 1;
string_list_append(s, opt, attr);
}
break;
#endif
case STRING_LIST_WIFI_DRIVERS:
#ifdef HAVE_WIFI
for (i = 0; wifi_driver_find_handle(i); i++)
{
const char *opt = wifi_driver_find_ident(i);
*len += strlen(opt) + 1;
string_list_append(s, opt, attr);
}
break;
#endif
case STRING_LIST_LOCATION_DRIVERS:
#ifdef HAVE_LOCATION
for (i = 0; location_driver_find_handle(i); i++)
{
const char *opt = location_driver_find_ident(i);
*len += strlen(opt) + 1;
string_list_append(options_l, opt, attr);
}
break;
#endif
case STRING_LIST_AUDIO_DRIVERS:
for (i = 0; audio_driver_find_handle(i); i++)
{
const char *opt = audio_driver_find_ident(i);
*len += strlen(opt) + 1;
string_list_append(s, opt, attr);
}
break;
case STRING_LIST_AUDIO_RESAMPLER_DRIVERS:
for (i = 0; audio_resampler_driver_find_handle(i); i++)
{
const char *opt = audio_resampler_driver_find_ident(i);
*len += strlen(opt) + 1;
string_list_append(s, opt, attr);
}
break;
case STRING_LIST_VIDEO_DRIVERS:
for (i = 0; video_driver_find_handle(i); i++)
{
const char *opt = video_driver_find_ident(i);
*len += strlen(opt) + 1;
string_list_append(s, opt, attr);
}
break;
case STRING_LIST_INPUT_DRIVERS:
for (i = 0; input_driver_find_handle(i); i++)
{
const char *opt = input_driver_find_ident(i);
*len += strlen(opt) + 1;
string_list_append(s, opt, attr);
}
break;
case STRING_LIST_INPUT_HID_DRIVERS:
#ifdef HAVE_HID
for (i = 0; hid_driver_find_handle(i); i++)
{
const char *opt = hid_driver_find_ident(i);
*len += strlen(opt) + 1;
string_list_append(s, opt, attr);
}
#endif
break;
case STRING_LIST_INPUT_JOYPAD_DRIVERS:
for (i = 0; joypad_driver_find_handle(i); i++)
{
const char *opt = joypad_driver_find_ident(i);
*len += strlen(opt) + 1;
string_list_append(s, opt, attr);
}
break;
case STRING_LIST_RECORD_DRIVERS:
for (i = 0; record_driver_find_handle(i); i++)
{
const char *opt = record_driver_find_ident(i);
*len += strlen(opt) + 1;
string_list_append(s, opt, attr);
}
break;
case STRING_LIST_SUPPORTED_CORES_PATHS:
core_info_get_list(&core_info_list);
core_info_list_get_supported_cores(core_info_list,
(const char*)data, &core_info, list_size);
if (!core_info)
goto error;
if (*list_size == 0)
goto error;
for (i = 0; i < *list_size; i++)
{
const core_info_t *info = (const core_info_t*)&core_info[i];
const char *opt = info->path;
if (!opt)
goto error;
*len += strlen(opt) + 1;
string_list_append(s, opt, attr);
}
break;
case STRING_LIST_SUPPORTED_CORES_NAMES:
core_info_get_list(&core_info_list);
core_info_list_get_supported_cores(core_info_list,
(const char*)data, &core_info, list_size);
if (!core_info)
goto error;
if (*list_size == 0)
goto error;
for (i = 0; i < *list_size; i++)
{
core_info_t *info = (core_info_t*)&core_info[i];
const char *opt = info->display_name;
if (!opt)
goto error;
*len += strlen(opt) + 1;
string_list_append(s, opt, attr);
}
break;
case STRING_LIST_NONE:
default:
goto error;
}
return s;
error:
string_list_free(s);
s = NULL;
return NULL;
}
const char *char_list_new_special(enum string_list_type type, void *data)
{
unsigned len = 0;
size_t list_size;
struct string_list *s = string_list_new_special(type, data, &len, &list_size);
char *options = (len > 0) ? (char*)calloc(len, sizeof(char)): NULL;
if (options && s)
string_list_join_concat(options, len, s, "|");
string_list_free(s);
s = NULL;
return options;
}