forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.c
1154 lines (985 loc) · 44.5 KB
/
settings.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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
*
* 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 "general.h"
#include "conf/config_file.h"
#include "conf/config_file_macros.h"
#include "compat/strl.h"
#include "config.def.h"
#include "file.h"
#include "input/input_common.h"
#include "frontend/frontend.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <ctype.h>
struct settings g_settings;
struct global g_extern;
struct defaults g_defaults;
const char *config_get_default_audio()
{
switch (AUDIO_DEFAULT_DRIVER)
{
case AUDIO_ALSA:
return "alsa";
case AUDIO_ALSATHREAD:
return "alsathread";
case AUDIO_AL:
return "openal";
case AUDIO_SDL:
return "sdl";
case AUDIO_PULSE:
return "pulse";
case AUDIO_NULL:
return "null";
default:
return NULL;
}
}
const char *config_get_default_audio_resampler()
{
switch (AUDIO_DEFAULT_RESAMPLER_DRIVER)
{
case AUDIO_RESAMPLER_CC:
return "cc";
case AUDIO_RESAMPLER_SINC:
default:
return "sinc";
}
}
const char *config_get_default_video()
{
switch (VIDEO_DEFAULT_DRIVER)
{
case VIDEO_GL:
return "gl";
case VIDEO_XVIDEO:
return "xvideo";
case VIDEO_SDL:
return "sdl";
case VIDEO_NULL:
return "null";
case VIDEO_EXYNOS:
return "exynos";
default:
return NULL;
}
}
const char *config_get_default_input()
{
switch (INPUT_DEFAULT_DRIVER)
{
case INPUT_SDL:
return "sdl";
case INPUT_X:
return "x";
case INPUT_WAYLAND:
return "wayland";
case INPUT_XINPUT:
return "xinput";
case INPUT_LINUXRAW:
return "linuxraw";
case INPUT_UDEV:
return "udev";
case INPUT_NULL:
return "null";
default:
return NULL;
}
}
#ifdef HAVE_MENU
const char *config_get_default_menu()
{
switch (MENU_DEFAULT_DRIVER)
{
case MENU_RGUI:
return "rgui";
case MENU_RMENU:
return "rmenu";
default:
return "NULL";
}
}
#endif
void config_set_defaults()
{
unsigned i, j;
const char *def_video = config_get_default_video();
const char *def_audio = config_get_default_audio();
const char *def_audio_resampler = config_get_default_audio_resampler();
const char *def_input = config_get_default_input();
#ifdef HAVE_MENU
const char *def_menu = config_get_default_menu();
#endif
if (def_video)
strlcpy(g_settings.video.driver, def_video, sizeof(g_settings.video.driver));
if (def_audio)
strlcpy(g_settings.audio.driver, def_audio, sizeof(g_settings.audio.driver));
if (def_audio_resampler)
strlcpy(g_settings.audio.resampler, def_audio_resampler, sizeof(g_settings.audio.resampler));
if (def_input)
strlcpy(g_settings.input.driver, def_input, sizeof(g_settings.input.driver));
#ifdef HAVE_MENU
if (def_menu)
strlcpy(g_settings.menu.driver, def_menu, sizeof(g_settings.menu.driver));
#endif
g_settings.load_dummy_on_core_shutdown = load_dummy_on_core_shutdown;
g_settings.video.scale = scale;
g_settings.video.fullscreen = g_extern.force_fullscreen ? true : fullscreen;
g_settings.video.windowed_fullscreen = windowed_fullscreen;
g_settings.video.monitor_index = monitor_index;
g_settings.video.fullscreen_x = fullscreen_x;
g_settings.video.fullscreen_y = fullscreen_y;
g_settings.video.vsync = vsync;
g_settings.video.hard_sync = hard_sync;
g_settings.video.hard_sync_frames = hard_sync_frames;
g_settings.video.black_frame_insertion = black_frame_insertion;
g_settings.video.swap_interval = swap_interval;
g_settings.video.threaded = video_threaded;
if (g_defaults.settings.video_threaded_enable != video_threaded)
g_settings.video.threaded = g_defaults.settings.video_threaded_enable;
g_settings.video.shared_context = video_shared_context;
g_settings.video.smooth = video_smooth;
g_settings.video.force_aspect = force_aspect;
g_settings.video.scale_integer = scale_integer;
g_settings.video.crop_overscan = crop_overscan;
g_settings.video.aspect_ratio = aspect_ratio;
g_settings.video.aspect_ratio_auto = aspect_ratio_auto; // Let implementation decide if automatic, or 1:1 PAR.
g_settings.video.aspect_ratio_idx = aspect_ratio_idx;
g_settings.video.shader_enable = shader_enable;
g_settings.video.allow_rotate = allow_rotate;
g_settings.video.font_enable = font_enable;
g_settings.video.font_size = font_size;
g_settings.video.msg_pos_x = message_pos_offset_x;
g_settings.video.msg_pos_y = message_pos_offset_y;
g_settings.video.msg_color_r = ((message_color >> 16) & 0xff) / 255.0f;
g_settings.video.msg_color_g = ((message_color >> 8) & 0xff) / 255.0f;
g_settings.video.msg_color_b = ((message_color >> 0) & 0xff) / 255.0f;
g_settings.video.refresh_rate = refresh_rate;
if (g_defaults.settings.video_refresh_rate > 0.0 && g_defaults.settings.video_refresh_rate != refresh_rate)
g_settings.video.refresh_rate = g_defaults.settings.video_refresh_rate;
g_settings.video.post_filter_record = post_filter_record;
g_settings.video.gpu_record = gpu_record;
g_settings.video.gpu_screenshot = gpu_screenshot;
g_settings.video.rotation = ORIENTATION_NORMAL;
g_settings.audio.enable = audio_enable;
g_settings.audio.out_rate = out_rate;
g_settings.audio.block_frames = 0;
if (audio_device)
strlcpy(g_settings.audio.device, audio_device, sizeof(g_settings.audio.device));
if (!g_defaults.settings.out_latency)
g_defaults.settings.out_latency = out_latency;
g_settings.audio.latency = g_defaults.settings.out_latency;
g_settings.audio.sync = audio_sync;
g_settings.audio.rate_control = rate_control;
g_settings.audio.rate_control_delta = rate_control_delta;
g_settings.audio.volume = audio_volume;
g_extern.audio_data.volume_db = g_settings.audio.volume;
g_extern.audio_data.volume_gain = db_to_gain(g_settings.audio.volume);
g_settings.rewind_enable = rewind_enable;
g_settings.rewind_buffer_size = rewind_buffer_size;
g_settings.rewind_granularity = rewind_granularity;
g_settings.slowmotion_ratio = slowmotion_ratio;
g_settings.fastforward_ratio = fastforward_ratio;
g_settings.pause_nonactive = pause_nonactive;
g_settings.autosave_interval = autosave_interval;
g_settings.block_sram_overwrite = block_sram_overwrite;
g_settings.savestate_auto_index = savestate_auto_index;
g_settings.savestate_auto_save = savestate_auto_save;
g_settings.savestate_auto_load = savestate_auto_load;
g_settings.network_cmd_enable = network_cmd_enable;
g_settings.network_cmd_port = network_cmd_port;
g_settings.pipe_cmd_enable = pipe_cmd_enable;
g_settings.content_history_size = default_content_history_size;
g_settings.libretro_log_level = libretro_log_level;
#ifdef HAVE_MENU
g_settings.menu_show_start_screen = menu_show_start_screen;
#endif
rarch_assert(sizeof(g_settings.input.binds[0]) >= sizeof(retro_keybinds_1));
rarch_assert(sizeof(g_settings.input.binds[1]) >= sizeof(retro_keybinds_rest));
memcpy(g_settings.input.binds[0], retro_keybinds_1, sizeof(retro_keybinds_1));
for (i = 1; i < MAX_PLAYERS; i++)
memcpy(g_settings.input.binds[i], retro_keybinds_rest, sizeof(retro_keybinds_rest));
for (i = 0; i < MAX_PLAYERS; i++)
{
for (j = 0; j < RARCH_BIND_LIST_END; j++)
{
g_settings.input.autoconf_binds[i][j].joykey = NO_BTN;
g_settings.input.autoconf_binds[i][j].joyaxis = AXIS_NONE;
}
}
memset(g_settings.input.autoconfigured, 0, sizeof(g_settings.input.autoconfigured));
// Verify that binds are in proper order.
for (i = 0; i < MAX_PLAYERS; i++)
for (j = 0; j < RARCH_BIND_LIST_END; j++)
if (g_settings.input.binds[i][j].valid)
rarch_assert(j == g_settings.input.binds[i][j].id);
g_settings.input.axis_threshold = axis_threshold;
g_settings.input.netplay_client_swap_input = netplay_client_swap_input;
g_settings.input.turbo_period = turbo_period;
g_settings.input.turbo_duty_cycle = turbo_duty_cycle;
g_settings.input.autodetect_enable = input_autodetect_enable;
*g_settings.input.keyboard_layout = '\0';
for (i = 0; i < MAX_PLAYERS; i++)
{
g_settings.input.joypad_map[i] = i;
g_settings.input.analog_dpad_mode[i] = ANALOG_DPAD_NONE;
if (!g_extern.has_set_libretro_device[i])
g_settings.input.libretro_device[i] = RETRO_DEVICE_JOYPAD;
}
g_extern.console.screen.viewports.custom_vp.width = 0;
g_extern.console.screen.viewports.custom_vp.height = 0;
g_extern.console.screen.viewports.custom_vp.x = 0;
g_extern.console.screen.viewports.custom_vp.y = 0;
// Make sure settings from other configs carry over into defaults for another config.
if (!g_extern.has_set_save_path)
*g_extern.savefile_dir = '\0';
if (!g_extern.has_set_state_path)
*g_extern.savestate_dir = '\0';
*g_settings.libretro_info_path = '\0';
if (!g_extern.has_set_libretro_directory)
*g_settings.libretro_directory = '\0';
*g_settings.core_options_path = '\0';
*g_settings.content_history_path = '\0';
*g_settings.cheat_database = '\0';
*g_settings.cheat_settings_path = '\0';
*g_settings.screenshot_directory = '\0';
*g_settings.system_directory = '\0';
*g_settings.extraction_directory = '\0';
*g_settings.input.autoconfig_dir = '\0';
*g_settings.content_directory = '\0';
*g_settings.assets_directory = '\0';
*g_settings.video.shader_path = '\0';
*g_settings.video.shader_dir = '\0';
*g_settings.video.filter_dir = '\0';
*g_settings.video.filter_path = '\0';
*g_settings.audio.filter_dir = '\0';
*g_settings.audio.dsp_plugin = '\0';
#ifdef HAVE_MENU
*g_settings.menu_content_directory = '\0';
*g_settings.menu_config_directory = '\0';
#endif
g_settings.core_specific_config = default_core_specific_config;
g_settings.user_language = 0;
if (default_filter_dir)
fill_pathname_expand_special(g_settings.video.filter_dir, default_filter_dir, sizeof(g_settings.video.filter_dir));
if (default_dsp_filter_dir)
fill_pathname_expand_special(g_settings.audio.filter_dir, default_dsp_filter_dir, sizeof(g_settings.audio.filter_dir));
if (*g_defaults.audio_filter_dir)
strlcpy(g_settings.audio.filter_dir, g_defaults.audio_filter_dir, sizeof(g_settings.audio.filter_dir));
if (*g_defaults.assets_dir)
strlcpy(g_settings.assets_directory, g_defaults.assets_dir, sizeof(g_settings.assets_directory));
if (*g_defaults.core_dir)
fill_pathname_expand_special(g_settings.libretro_directory, g_defaults.core_dir, sizeof(g_settings.libretro_directory));
if (*g_defaults.core_path)
strlcpy(g_settings.libretro, g_defaults.core_path, sizeof(g_settings.libretro));
if (*g_defaults.core_info_dir)
fill_pathname_expand_special(g_settings.libretro_info_path, g_defaults.core_info_dir, sizeof(g_settings.libretro_info_path));
#ifdef HAVE_MENU
if (*g_defaults.menu_config_dir)
strlcpy(g_settings.menu_config_directory, g_defaults.menu_config_dir, sizeof(g_settings.menu_config_directory));
#endif
if (*g_defaults.shader_dir)
fill_pathname_expand_special(g_settings.video.shader_dir, g_defaults.shader_dir, sizeof(g_settings.video.shader_dir));
if (!g_extern.has_set_state_path && *g_defaults.savestate_dir)
strlcpy(g_extern.savestate_dir, g_defaults.savestate_dir, sizeof(g_extern.savestate_dir));
if (!g_extern.has_set_save_path && *g_defaults.sram_dir)
strlcpy(g_extern.savefile_dir, g_defaults.sram_dir, sizeof(g_extern.savefile_dir));
if (*g_defaults.system_dir)
strlcpy(g_settings.system_directory, g_defaults.system_dir, sizeof(g_settings.system_directory));
if (*g_defaults.screenshot_dir)
strlcpy(g_settings.screenshot_directory, g_defaults.screenshot_dir, sizeof(g_settings.screenshot_directory));
if (*g_defaults.config_path)
fill_pathname_expand_special(g_extern.config_path, g_defaults.config_path, sizeof(g_extern.config_path));
g_settings.config_save_on_exit = config_save_on_exit;
/* Avoid reloading config on every content load */
g_extern.block_config_read = default_block_config_read;
}
static void parse_config_file();
static void config_load_core_specific()
{
*g_extern.core_specific_config_path = '\0';
if (!*g_settings.libretro
#ifdef HAVE_DYNAMIC
|| g_extern.libretro_dummy
#endif
)
return;
#ifdef HAVE_MENU
if (*g_settings.menu_config_directory)
{
path_resolve_realpath(g_settings.menu_config_directory, sizeof(g_settings.menu_config_directory));
strlcpy(g_extern.core_specific_config_path, g_settings.menu_config_directory, sizeof(g_extern.core_specific_config_path));
}
else
#endif
{
// Use original config file's directory as a fallback.
fill_pathname_basedir(g_extern.core_specific_config_path, g_extern.config_path, sizeof(g_extern.core_specific_config_path));
}
fill_pathname_dir(g_extern.core_specific_config_path, g_settings.libretro, ".cfg", sizeof(g_extern.core_specific_config_path));
if (g_settings.core_specific_config)
{
char tmp[PATH_MAX];
strlcpy(tmp, g_settings.libretro, sizeof(tmp));
RARCH_LOG("Loading core-specific config from: %s.\n", g_extern.core_specific_config_path);
if (!config_load_file(g_extern.core_specific_config_path, true))
RARCH_WARN("Core-specific config not found, reusing last config.\n");
// Force some parameters which are implied when using core specific configs.
// Don't have the core config file overwrite the libretro path.
strlcpy(g_settings.libretro, tmp, sizeof(g_settings.libretro));
// This must be true for core specific configs.
g_settings.core_specific_config = true;
}
}
void config_load()
{
// Flush out per-core configs before loading a new config.
if (*g_extern.core_specific_config_path && g_settings.config_save_on_exit && g_settings.core_specific_config)
config_save_file(g_extern.core_specific_config_path);
if (!g_extern.block_config_read)
{
config_set_defaults();
parse_config_file();
}
// Per-core config handling.
config_load_core_specific();
}
static config_file_t *open_default_config_file()
{
config_file_t *conf = NULL;
char conf_path[PATH_MAX];
const char *xdg = getenv("XDG_CONFIG_HOME");
const char *home = getenv("HOME");
// XDG_CONFIG_HOME falls back to $HOME/.config.
if (xdg)
fill_pathname_join(conf_path, xdg, "retroarch/retroarch.cfg", sizeof(conf_path));
else if (home)
fill_pathname_join(conf_path, home, ".config/retroarch/retroarch.cfg", sizeof(conf_path));
if (xdg || home)
{
RARCH_LOG("Looking for config in: \"%s\".\n", conf_path);
conf = config_file_new(conf_path);
}
// Fallback to $HOME/.retroarch.cfg.
if (!conf && home)
{
fill_pathname_join(conf_path, home, ".retroarch.cfg", sizeof(conf_path));
RARCH_LOG("Looking for config in: \"%s\".\n", conf_path);
conf = config_file_new(conf_path);
}
// Try to create a new config file.
if (!conf && (home || xdg))
{
// XDG_CONFIG_HOME falls back to $HOME/.config.
if (xdg)
fill_pathname_join(conf_path, xdg, "retroarch/retroarch.cfg", sizeof(conf_path));
else if (home)
fill_pathname_join(conf_path, home, ".config/retroarch/retroarch.cfg", sizeof(conf_path));
char basedir[PATH_MAX];
fill_pathname_basedir(basedir, conf_path, sizeof(basedir));
if (path_mkdir(basedir))
{
#ifndef GLOBAL_CONFIG_DIR
#define GLOBAL_CONFIG_DIR "/etc"
#endif
char skeleton_conf[PATH_MAX];
fill_pathname_join(skeleton_conf, GLOBAL_CONFIG_DIR, "retroarch.cfg", sizeof(skeleton_conf));
conf = config_file_new(skeleton_conf);
if (conf)
RARCH_WARN("Using skeleton config \"%s\" as base for a new config file.\n", skeleton_conf);
else
conf = config_file_new(NULL);
bool saved = false;
if (conf)
{
config_set_bool(conf, "config_save_on_exit", true); // Since this is a clean config file, we can safely use config_save_on_exit.
saved = config_file_write(conf, conf_path);
}
if (saved)
RARCH_WARN("Created new config file in: \"%s\".\n", conf_path); // WARN here to make sure user has a good chance of seeing it.
else
{
RARCH_ERR("Failed to create new config file in: \"%s\".\n", conf_path);
config_file_free(conf);
conf = NULL;
}
}
}
if (conf)
strlcpy(g_extern.config_path, conf_path, sizeof(g_extern.config_path));
return conf;
}
static void config_read_keybinds_conf(config_file_t *conf);
static void parse_config_file()
{
bool ret;
if (*g_extern.config_path)
{
RARCH_LOG("Loading config from: %s.\n", g_extern.config_path);
ret = config_load_file(g_extern.config_path, false);
}
else
{
RARCH_LOG("Loading default config.\n");
ret = config_load_file(NULL, false);
if (*g_extern.config_path)
RARCH_LOG("Found default config: %s.\n", g_extern.config_path);
}
if (!ret)
{
RARCH_ERR("Couldn't find config at path: \"%s\"\n", g_extern.config_path);
}
}
bool config_load_file(const char *path, bool set_defaults)
{
unsigned i;
config_file_t *conf = NULL;
if (path)
{
conf = config_file_new(path);
if (!conf)
return false;
}
else
conf = open_default_config_file();
if (conf == NULL)
return true;
if (set_defaults)
config_set_defaults();
char *save;
char tmp_append_path[PATH_MAX]; // Don't destroy append_config_path.
strlcpy(tmp_append_path, g_extern.append_config_path, sizeof(tmp_append_path));
const char *extra_path = strtok_r(tmp_append_path, ",", &save);
while (extra_path)
{
RARCH_LOG("Appending config \"%s\"\n", extra_path);
bool ret = config_append_file(conf, extra_path);
if (!ret)
RARCH_ERR("Failed to append config \"%s\"\n", extra_path);
extra_path = strtok_r(NULL, ";", &save);
}
if (g_extern.verbosity)
{
RARCH_LOG_OUTPUT("=== Config ===\n");
config_file_dump_all(conf);
RARCH_LOG_OUTPUT("=== Config end ===\n");
}
char tmp_str[PATH_MAX];
CONFIG_GET_FLOAT(video.scale, "video_scale");
CONFIG_GET_INT(video.fullscreen_x, "video_fullscreen_x");
CONFIG_GET_INT(video.fullscreen_y, "video_fullscreen_y");
if (!g_extern.force_fullscreen)
CONFIG_GET_BOOL(video.fullscreen, "video_fullscreen");
CONFIG_GET_BOOL(video.windowed_fullscreen, "video_windowed_fullscreen");
CONFIG_GET_INT(video.monitor_index, "video_monitor_index");
CONFIG_GET_BOOL(video.vsync, "video_vsync");
CONFIG_GET_BOOL(video.hard_sync, "video_hard_sync");
CONFIG_GET_INT(video.hard_sync_frames, "video_hard_sync_frames");
if (g_settings.video.hard_sync_frames > 3)
g_settings.video.hard_sync_frames = 3;
CONFIG_GET_BOOL(video.black_frame_insertion, "video_black_frame_insertion");
CONFIG_GET_INT(video.swap_interval, "video_swap_interval");
g_settings.video.swap_interval = max(g_settings.video.swap_interval, 1);
g_settings.video.swap_interval = min(g_settings.video.swap_interval, 4);
CONFIG_GET_BOOL(video.threaded, "video_threaded");
CONFIG_GET_BOOL(video.shared_context, "video_shared_context");
CONFIG_GET_BOOL(video.smooth, "video_smooth");
CONFIG_GET_BOOL(video.force_aspect, "video_force_aspect");
CONFIG_GET_BOOL(video.scale_integer, "video_scale_integer");
CONFIG_GET_BOOL(video.crop_overscan, "video_crop_overscan");
CONFIG_GET_FLOAT(video.aspect_ratio, "video_aspect_ratio");
CONFIG_GET_INT(video.aspect_ratio_idx, "aspect_ratio_index");
CONFIG_GET_BOOL(video.aspect_ratio_auto, "video_aspect_ratio_auto");
CONFIG_GET_FLOAT(video.refresh_rate, "video_refresh_rate");
CONFIG_GET_PATH(video.shader_path, "video_shader");
CONFIG_GET_BOOL(video.shader_enable, "video_shader_enable");
CONFIG_GET_BOOL(video.allow_rotate, "video_allow_rotate");
CONFIG_GET_PATH(video.font_path, "video_font_path");
CONFIG_GET_FLOAT(video.font_size, "video_font_size");
CONFIG_GET_BOOL(video.font_enable, "video_font_enable");
CONFIG_GET_FLOAT(video.msg_pos_x, "video_message_pos_x");
CONFIG_GET_FLOAT(video.msg_pos_y, "video_message_pos_y");
CONFIG_GET_INT(video.rotation, "video_rotation");
CONFIG_GET_INT(state_slot, "state_slot");
CONFIG_GET_INT_EXTERN(console.screen.viewports.custom_vp.x, "custom_viewport_x");
CONFIG_GET_INT_EXTERN(console.screen.viewports.custom_vp.y, "custom_viewport_y");
CONFIG_GET_INT_EXTERN(console.screen.viewports.custom_vp.width, "custom_viewport_width");
CONFIG_GET_INT_EXTERN(console.screen.viewports.custom_vp.height, "custom_viewport_height");
unsigned msg_color = 0;
if (config_get_hex(conf, "video_message_color", &msg_color))
{
g_settings.video.msg_color_r = ((msg_color >> 16) & 0xff) / 255.0f;
g_settings.video.msg_color_g = ((msg_color >> 8) & 0xff) / 255.0f;
g_settings.video.msg_color_b = ((msg_color >> 0) & 0xff) / 255.0f;
}
CONFIG_GET_BOOL(video.post_filter_record, "video_post_filter_record");
CONFIG_GET_BOOL(video.gpu_record, "video_gpu_record");
CONFIG_GET_BOOL(video.gpu_screenshot, "video_gpu_screenshot");
#ifdef HAVE_DYLIB
CONFIG_GET_PATH(video.filter_path, "video_filter");
#endif
CONFIG_GET_PATH(video.shader_dir, "video_shader_dir");
if (!strcmp(g_settings.video.shader_dir, "default"))
*g_settings.video.shader_dir = '\0';
CONFIG_GET_PATH(video.filter_dir, "video_filter_dir");
if (!strcmp(g_settings.video.filter_dir, "default"))
*g_settings.video.filter_dir = '\0';
CONFIG_GET_PATH(audio.filter_dir, "audio_filter_dir");
if (!strcmp(g_settings.audio.filter_dir, "default"))
*g_settings.audio.filter_dir = '\0';
CONFIG_GET_FLOAT(input.axis_threshold, "input_axis_threshold");
CONFIG_GET_BOOL(input.netplay_client_swap_input, "netplay_client_swap_input");
for (i = 0; i < MAX_PLAYERS; i++)
{
char buf[64];
snprintf(buf, sizeof(buf), "input_player%u_joypad_index", i + 1);
CONFIG_GET_INT(input.joypad_map[i], buf);
snprintf(buf, sizeof(buf), "input_player%u_analog_dpad_mode", i + 1);
CONFIG_GET_INT(input.analog_dpad_mode[i], buf);
if (!g_extern.has_set_libretro_device[i])
{
snprintf(buf, sizeof(buf), "input_libretro_device_p%u", i + 1);
CONFIG_GET_INT(input.libretro_device[i], buf);
}
}
// Audio settings.
CONFIG_GET_BOOL(audio.enable, "audio_enable");
CONFIG_GET_INT(audio.out_rate, "audio_out_rate");
CONFIG_GET_INT(audio.block_frames, "audio_block_frames");
CONFIG_GET_STRING(audio.device, "audio_device");
CONFIG_GET_INT(audio.latency, "audio_latency");
CONFIG_GET_BOOL(audio.sync, "audio_sync");
CONFIG_GET_BOOL(audio.rate_control, "audio_rate_control");
CONFIG_GET_FLOAT(audio.rate_control_delta, "audio_rate_control_delta");
CONFIG_GET_FLOAT(audio.volume, "audio_volume");
CONFIG_GET_STRING(audio.resampler, "audio_resampler");
g_extern.audio_data.volume_db = g_settings.audio.volume;
g_extern.audio_data.volume_gain = db_to_gain(g_settings.audio.volume);
CONFIG_GET_STRING(video.driver, "video_driver");
CONFIG_GET_STRING(menu.driver, "menu_driver");
CONFIG_GET_STRING(video.gl_context, "video_gl_context");
CONFIG_GET_STRING(audio.driver, "audio_driver");
CONFIG_GET_PATH(audio.dsp_plugin, "audio_dsp_plugin");
CONFIG_GET_STRING(input.driver, "input_driver");
CONFIG_GET_STRING(input.joypad_driver, "input_joypad_driver");
CONFIG_GET_STRING(input.keyboard_layout, "input_keyboard_layout");
if (!g_extern.has_set_libretro)
CONFIG_GET_PATH(libretro, "libretro_path");
if (!g_extern.has_set_libretro_directory)
CONFIG_GET_PATH(libretro_directory, "libretro_directory");
// Safe-guard against older behavior.
if (path_is_directory(g_settings.libretro))
{
RARCH_WARN("\"libretro_path\" is a directory, using this for \"libretro_directory\" instead.\n");
strlcpy(g_settings.libretro_directory, g_settings.libretro, sizeof(g_settings.libretro_directory));
*g_settings.libretro = '\0';
}
CONFIG_GET_BOOL(fps_show, "fps_show");
CONFIG_GET_BOOL(load_dummy_on_core_shutdown, "load_dummy_on_core_shutdown");
CONFIG_GET_PATH(libretro_info_path, "libretro_info_path");
CONFIG_GET_PATH(core_options_path, "core_options_path");
CONFIG_GET_PATH(screenshot_directory, "screenshot_directory");
if (*g_settings.screenshot_directory)
{
if (!strcmp(g_settings.screenshot_directory, "default"))
*g_settings.screenshot_directory = '\0';
else if (!path_is_directory(g_settings.screenshot_directory))
{
RARCH_WARN("screenshot_directory is not an existing directory, ignoring ...\n");
*g_settings.screenshot_directory = '\0';
}
}
CONFIG_GET_PATH(extraction_directory, "extraction_directory");
CONFIG_GET_PATH(content_directory, "content_directory");
CONFIG_GET_PATH(assets_directory, "assets_directory");
if (!strcmp(g_settings.content_directory, "default"))
*g_settings.content_directory = '\0';
if (!strcmp(g_settings.assets_directory, "default"))
*g_settings.assets_directory = '\0';
#ifdef HAVE_MENU
CONFIG_GET_PATH(menu_content_directory, "rgui_browser_directory");
if (!strcmp(g_settings.menu_content_directory, "default"))
*g_settings.menu_content_directory = '\0';
CONFIG_GET_PATH(menu_config_directory, "rgui_config_directory");
if (!strcmp(g_settings.menu_config_directory, "default"))
*g_settings.menu_config_directory = '\0';
CONFIG_GET_BOOL(menu_show_start_screen, "rgui_show_start_screen");
#endif
CONFIG_GET_INT(libretro_log_level, "libretro_log_level");
if (!g_extern.has_set_verbosity)
CONFIG_GET_BOOL_EXTERN(verbosity, "log_verbosity");
CONFIG_GET_BOOL_EXTERN(perfcnt_enable, "perfcnt_enable");
CONFIG_GET_BOOL(rewind_enable, "rewind_enable");
int buffer_size = 0;
if (config_get_int(conf, "rewind_buffer_size", &buffer_size))
g_settings.rewind_buffer_size = buffer_size * UINT64_C(1000000);
CONFIG_GET_INT(rewind_granularity, "rewind_granularity");
CONFIG_GET_FLOAT(slowmotion_ratio, "slowmotion_ratio");
if (g_settings.slowmotion_ratio < 1.0f)
g_settings.slowmotion_ratio = 1.0f;
CONFIG_GET_FLOAT(fastforward_ratio, "fastforward_ratio");
CONFIG_GET_BOOL(pause_nonactive, "pause_nonactive");
CONFIG_GET_INT(autosave_interval, "autosave_interval");
CONFIG_GET_PATH(cheat_database, "cheat_database_path");
CONFIG_GET_PATH(cheat_settings_path, "cheat_settings_path");
CONFIG_GET_BOOL(block_sram_overwrite, "block_sram_overwrite");
CONFIG_GET_BOOL(savestate_auto_index, "savestate_auto_index");
CONFIG_GET_BOOL(savestate_auto_save, "savestate_auto_save");
CONFIG_GET_BOOL(savestate_auto_load, "savestate_auto_load");
CONFIG_GET_BOOL(network_cmd_enable, "network_cmd_enable");
CONFIG_GET_INT(network_cmd_port, "network_cmd_port");
CONFIG_GET_BOOL(pipe_cmd_enable, "pipe_cmd_enable");
CONFIG_GET_PATH(pipe_cmd_name, "pipe_cmd_name");
fill_pathname_resolve_relative(g_settings.content_history_path, g_extern.config_path, ".retroarch-game-history.txt", sizeof(g_settings.content_history_path));
CONFIG_GET_PATH(content_history_path, "game_history_path");
CONFIG_GET_INT(content_history_size, "game_history_size");
CONFIG_GET_INT(input.turbo_period, "input_turbo_period");
CONFIG_GET_INT(input.turbo_duty_cycle, "input_duty_cycle");
CONFIG_GET_BOOL(input.autodetect_enable, "input_autodetect_enable");
CONFIG_GET_PATH(input.autoconfig_dir, "joypad_autoconfig_dir");
if (!g_extern.has_set_username)
CONFIG_GET_PATH(username, "netplay_nickname");
CONFIG_GET_INT(user_language, "user_language");
#ifdef HAVE_NETPLAY
if (!g_extern.has_set_netplay_mode)
CONFIG_GET_BOOL_EXTERN(netplay_is_spectate, "netplay_spectator_mode_enable");
if (!g_extern.has_set_netplay_mode)
CONFIG_GET_BOOL_EXTERN(netplay_is_client, "netplay_mode");
if (!g_extern.has_set_netplay_ip_address)
CONFIG_GET_PATH_EXTERN(netplay_server, "netplay_ip_address");
if (!g_extern.has_set_netplay_delay_frames)
CONFIG_GET_INT_EXTERN(netplay_sync_frames, "netplay_delay_frames");
if (!g_extern.has_set_netplay_ip_port)
CONFIG_GET_INT_EXTERN(netplay_port, "netplay_ip_port");
#endif
CONFIG_GET_BOOL(config_save_on_exit, "config_save_on_exit");
if (!g_extern.has_set_save_path && config_get_path(conf, "savefile_directory", tmp_str, sizeof(tmp_str)))
{
if (!strcmp(tmp_str, "default"))
strlcpy(g_extern.savefile_dir, g_defaults.sram_dir, sizeof(g_extern.savefile_dir));
else if (path_is_directory(tmp_str))
{
strlcpy(g_extern.savefile_dir, tmp_str, sizeof(g_extern.savefile_dir));
strlcpy(g_extern.savefile_name, tmp_str, sizeof(g_extern.savefile_name));
fill_pathname_dir(g_extern.savefile_name, g_extern.basename, ".srm", sizeof(g_extern.savefile_name));
}
else
RARCH_WARN("savefile_directory is not a directory, ignoring ...\n");
}
if (!g_extern.has_set_state_path && config_get_path(conf, "savestate_directory", tmp_str, sizeof(tmp_str)))
{
if (!strcmp(tmp_str, "default"))
strlcpy(g_extern.savestate_dir, g_defaults.savestate_dir, sizeof(g_extern.savestate_dir));
else if (path_is_directory(tmp_str))
{
strlcpy(g_extern.savestate_dir, tmp_str, sizeof(g_extern.savestate_dir));
strlcpy(g_extern.savestate_name, tmp_str, sizeof(g_extern.savestate_name));
fill_pathname_dir(g_extern.savestate_name, g_extern.basename, ".state", sizeof(g_extern.savestate_name));
}
else
RARCH_WARN("savestate_directory is not a directory, ignoring ...\n");
}
if (!config_get_path(conf, "system_directory", g_settings.system_directory, sizeof(g_settings.system_directory)))
{
RARCH_WARN("system_directory is not set in config. Assuming system directory is same folder as game: \"%s\".\n",
g_settings.system_directory);
}
if (!strcmp(g_settings.system_directory, "default"))
*g_settings.system_directory = '\0';
config_read_keybinds_conf(conf);
CONFIG_GET_BOOL(core_specific_config, "core_specific_config");
config_file_free(conf);
return true;
}
static void read_keybinds_keyboard(config_file_t *conf, unsigned player, unsigned index,
struct retro_keybind *bind)
{
if (input_config_bind_map[index].valid && input_config_bind_map[index].base)
{
const char *prefix = input_config_get_prefix(player, input_config_bind_map[index].meta);
if (prefix)
input_config_parse_key(conf, prefix, input_config_bind_map[index].base, bind);
}
}
static void read_keybinds_button(config_file_t *conf, unsigned player, unsigned index,
struct retro_keybind *bind)
{
if (input_config_bind_map[index].valid && input_config_bind_map[index].base)
{
const char *prefix = input_config_get_prefix(player, input_config_bind_map[index].meta);
if (prefix)
input_config_parse_joy_button(conf, prefix, input_config_bind_map[index].base, bind);
}
}
static void read_keybinds_axis(config_file_t *conf, unsigned player, unsigned index,
struct retro_keybind *bind)
{
if (input_config_bind_map[index].valid && input_config_bind_map[index].base)
{
const char *prefix = input_config_get_prefix(player, input_config_bind_map[index].meta);
if (prefix)
input_config_parse_joy_axis(conf, prefix, input_config_bind_map[index].base, bind);
}
}
static void read_keybinds_player(config_file_t *conf, unsigned player)
{
unsigned i;
for (i = 0; input_config_bind_map[i].valid; i++)
{
struct retro_keybind *bind = &g_settings.input.binds[player][i];
if (!bind->valid)
continue;
read_keybinds_keyboard(conf, player, i, bind);
read_keybinds_button(conf, player, i, bind);
read_keybinds_axis(conf, player, i, bind);
}
}
static void config_read_keybinds_conf(config_file_t *conf)
{
unsigned i;
for (i = 0; i < MAX_PLAYERS; i++)
read_keybinds_player(conf, i);
}
bool config_read_keybinds(const char *path)
{
config_file_t *conf = config_file_new(path);
if (!conf)
return false;
config_read_keybinds_conf(conf);
config_file_free(conf);
return true;
}
static void save_keybind_key(config_file_t *conf, const char *prefix, const char *base,
const struct retro_keybind *bind)
{
char key[64];
snprintf(key, sizeof(key), "%s_%s", prefix, base);
char btn[64];
input_translate_rk_to_str(bind->key, btn, sizeof(btn));
config_set_string(conf, key, btn);
}
static void save_keybind_hat(config_file_t *conf, const char *key, const struct retro_keybind *bind)
{
unsigned hat = GET_HAT(bind->joykey);
const char *dir = NULL;
switch (GET_HAT_DIR(bind->joykey))
{
case HAT_UP_MASK:
dir = "up";
break;
case HAT_DOWN_MASK:
dir = "down";
break;
case HAT_LEFT_MASK:
dir = "left";
break;
case HAT_RIGHT_MASK:
dir = "right";
break;
default:
rarch_assert(0);
}
char config[16];
snprintf(config, sizeof(config), "h%u%s", hat, dir);
config_set_string(conf, key, config);
}
static void save_keybind_joykey(config_file_t *conf, const char *prefix, const char *base,
const struct retro_keybind *bind)
{
char key[64];
snprintf(key, sizeof(key), "%s_%s_btn", prefix, base);
if (bind->joykey == NO_BTN)
config_set_string(conf, key, "nul");
else if (GET_HAT_DIR(bind->joykey))
save_keybind_hat(conf, key, bind);
else
config_set_uint64(conf, key, bind->joykey);
}
static void save_keybind_axis(config_file_t *conf, const char *prefix, const char *base,
const struct retro_keybind *bind)
{
char key[64];
snprintf(key, sizeof(key), "%s_%s_axis", prefix, base);
unsigned axis = 0;
char dir = '\0';
if (bind->joyaxis == AXIS_NONE)
config_set_string(conf, key, "nul");
else if (AXIS_NEG_GET(bind->joyaxis) != AXIS_DIR_NONE)
{
dir = '-';
axis = AXIS_NEG_GET(bind->joyaxis);
}
else if (AXIS_POS_GET(bind->joyaxis) != AXIS_DIR_NONE)
{
dir = '+';
axis = AXIS_POS_GET(bind->joyaxis);
}
if (dir)
{
char config[16];
snprintf(config, sizeof(config), "%c%u", dir, axis);
config_set_string(conf, key, config);
}
}
static void save_keybind(config_file_t *conf, const char *prefix, const char *base,
const struct retro_keybind *bind)
{
if (!bind->valid)
return;
save_keybind_key(conf, prefix, base, bind);
save_keybind_joykey(conf, prefix, base, bind);
save_keybind_axis(conf, prefix, base, bind);
}
static void save_keybinds_player(config_file_t *conf, unsigned player)
{
unsigned i = 0;