/
fe_settings.cpp
4284 lines (3573 loc) · 101 KB
/
fe_settings.cpp
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
/*
*
* Attract-Mode frontend
* Copyright (C) 2013-16 Andrew Mickelson
*
* This file is part of Attract-Mode.
*
* Attract-Mode 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.
*
* Attract-Mode 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 Attract-Mode. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "fe_util.hpp"
#include "fe_settings.hpp"
#include "fe_present.hpp"
#include "image_loader.hpp"
#include "zip.hpp"
#include <iostream>
#include <sstream>
#include "nowide/fstream.hpp"
#include <cstring>
#include <iomanip>
#include <algorithm>
#include <stdlib.h>
#include <cctype>
#include <SFML/System/Clock.hpp>
#include <SFML/Config.hpp>
#ifndef NO_MOVIE
#include "media.hpp" // for FeMedia::is_supported_media(), get/set_current_decoder()
#endif
#if defined(SFML_SYSTEM_WINDOWS)
const char *FE_DEFAULT_CFG_PATH = "./";
#elif defined(SFML_SYSTEM_MACOS)
const char *FE_DEFAULT_CFG_PATH = "$HOME/.attract/";
#elif defined(SFML_SYSTEM_ANDROID)
const char *FE_DEFAULT_CFG_PATH = "$HOME/";
#else
const char *FE_DEFAULT_CFG_PATH = "$HOME/.attract/";
#endif
const char *FE_ART_EXTENSIONS[] =
{
".png",
".jpg",
".jpeg",
".bmp",
".tga",
NULL
};
#ifdef DATA_PATH
const char *FE_DATA_PATH = DATA_PATH;
#else
const char *FE_DATA_PATH = NULL;
#endif
const char *FE_CFG_FILE = "attract.cfg";
const char *FE_STATE_FILE = "attract.am";
const char *FE_SCREENSAVER_FILE = "screensaver.nut";
const char *FE_PLUGIN_FILE = "plugin.nut";
const char *FE_LOADER_FILE = "loader.nut";
const char *FE_EMULATOR_INIT_FILE = "init.nut";
const char *FE_INTRO_FILE = "intro.nut";
const char *FE_LAYOUT_FILE_BASE = "layout";
const char *FE_LAYOUT_FILE_EXTENSION = ".nut";
const char *FE_LANGUAGE_FILE_EXTENSION = ".msg";
const char *FE_PLUGIN_FILE_EXTENSION = FE_LAYOUT_FILE_EXTENSION;
const char *FE_GAME_EXTRA_FILE_EXTENSION = ".cfg";
const char *FE_GAME_OVERVIEW_FILE_EXTENSION = ".txt";
const char *FE_LAYOUT_SUBDIR = "layouts/";
const char *FE_SOUND_SUBDIR = "sounds/";
const char *FE_SCREENSAVER_SUBDIR = "screensaver/";
const char *FE_PLUGIN_SUBDIR = "plugins/";
const char *FE_LANGUAGE_SUBDIR = "language/";
const char *FE_MODULES_SUBDIR = "modules/";
const char *FE_LOADER_SUBDIR = "loader/";
const char *FE_INTRO_SUBDIR = "intro/";
const char *FE_SCRAPER_SUBDIR = "scraper/";
const char *FE_MENU_ART_SUBDIR = "menu-art/";
const char *FE_OVERVIEW_SUBDIR = "overview/";
const char *FE_EMULATOR_SCRIPT_SUBDIR = "emulators/script/";
const char *FE_LIST_DEFAULT = "default-display.cfg";
const char *FE_FILTER_DEFAULT = "default-filter.cfg";
const char *FE_CFG_YES_STR = "yes";
const char *FE_CFG_NO_STR = "no";
const std::string FE_EMPTY_STRING;
bool internal_resolve_config_file(
const std::string &config_path,
std::string &result,
const char *subdir,
const std::string &name )
{
std::string path;
path = config_path;
if ( subdir ) path += subdir;
path += name;
if ( file_exists( path ) )
{
result = path;
return true;
}
if ( FE_DATA_PATH != NULL )
{
path = FE_DATA_PATH;
if ( subdir ) path += subdir;
path += name;
if ( file_exists( path ) )
{
result = path;
return true;
}
}
return false;
}
int find_idx_in_vec( int idx, const std::vector<int> &vec )
{
int i=0;
for ( i=0; i < (int)vec.size() - 1; i++ )
{
if ( idx <= vec[i] )
break;
}
return i;
}
FeLanguage::FeLanguage( const std::string &l )
: language( l )
{
}
const char *FeSettings::windowModeTokens[] =
{
"default",
"fullscreen",
"window",
"window_no_border",
NULL
};
const char *FeSettings::windowModeDispTokens[] =
{
"Fill Screen (Default)",
"Fullscreen Mode",
"Window",
"Window (No Border)",
NULL
};
const char *FeSettings::screenRotationTokens[] =
{
"none",
"right",
"flip",
"left",
NULL
};
const char *FeSettings::screenRotationDispTokens[] =
{
"None (Default)",
"Right",
"Flip",
"Left",
NULL
};
const char *FeSettings::antialiasingTokens[] =
{
"0",
"2",
"4",
"8",
NULL
};
const char *FeSettings::antialiasingDispTokens[] =
{
"None (Default)",
"MSAA x2",
"MSAA x4",
"MSAA x8",
NULL
};
const char *FeSettings::anisotropicTokens[] =
{
"0",
"2",
"4",
"8",
"16",
NULL
};
const char *FeSettings::anisotropicDispTokens[] =
{
"None (Default)",
"x2",
"x4",
"x8",
"x16",
NULL
};
const char *FeSettings::filterWrapTokens[] =
{
"default",
"jump_to_next_display",
"no_wrap",
NULL
};
const char *FeSettings::filterWrapDispTokens[] =
{
"Wrap within Display (Default)",
"Jump to Next Display",
"No Wrap",
NULL
};
const char *FeSettings::startupTokens[] =
{
"default",
"launch_last_game",
"displays_menu",
NULL
};
const char *FeSettings::startupDispTokens[] =
{
"Show Last Selection (Default)",
"Launch Last Game",
"Show Displays Menu",
NULL
};
FeSettings::FeSettings( const std::string &config_path )
: m_rl( m_config_path ),
m_inputmap(),
m_saver_params( FeLayoutInfo::ScreenSaver ),
m_intro_params( FeLayoutInfo::Intro ),
m_current_layout_params( FeLayoutInfo::Layout ),
m_display_menu_per_display_params( FeLayoutInfo::Menu ),
m_current_display( -1 ),
m_current_config_object( NULL ),
m_ssaver_time( 600 ),
m_last_launch_display( 0 ),
m_last_launch_filter( 0 ),
m_last_launch_rom( 0 ),
m_last_launch_clone( -1 ),
m_clone_index( -1 ),
m_joy_thresh( 75 ),
m_mouse_thresh( 10 ),
m_current_search_index( 0 ),
m_current_display_index( 0 ),
m_displays_menu_exit( true ),
m_hide_brackets( false ),
m_group_clones( false ),
m_startup_mode( ShowLastSelection ),
m_confirm_favs( true ),
m_confirm_exit( true ),
m_track_usage( true ),
m_multimon( false ),
#if defined(SFML_SYSTEM_LINUX) || defined(FORCE_FULLSCREEN)
m_window_mode( Fullscreen ),
#else
m_window_mode( Default ),
#endif
m_screen_rotation( RotateNone ),
m_antialiasing( 0 ),
m_anisotropic( 0 ),
m_smooth_images( true ),
m_filter_wrap_mode( WrapWithinDisplay ),
m_selection_max_step( 128 ),
m_selection_speed( 40 ),
m_image_cache_mbytes( 100 ),
#ifdef SFML_SYSTEM_MACOS
m_move_mouse_on_launch( false ), // hotcorners
#else
m_move_mouse_on_launch( true ),
#endif
m_scrape_snaps( true ),
m_scrape_marquees( true ),
m_scrape_flyers( false ),
m_scrape_wheels( true ),
m_scrape_fanart( false ),
m_scrape_vids( false ),
m_scrape_overview( true ),
#ifdef SFML_SYSTEM_WINDOWS
m_hide_console( false ),
#endif
m_power_saving( false ),
m_loaded_game_extras( false ),
m_present_state( Layout_Showing ),
m_ui_font_size( 0 )
{
if ( config_path.empty() )
m_config_path = absolute_path( clean_path(FE_DEFAULT_CFG_PATH) );
else
m_config_path = absolute_path( clean_path( config_path, true ) );
// absolute_path can drop the trailing slash
if (
#ifdef SFML_SYSTEM_WINDOWS
(m_config_path[m_config_path.size()-1] != '\\') &&
#endif
(m_config_path[m_config_path.size()-1] != '/') )
m_config_path += '/';
}
void FeSettings::clear()
{
m_current_config_object=NULL;
m_current_display = -1;
m_displays.clear();
m_rl.clear_emulators();
m_plugins.clear();
}
void FeSettings::load()
{
FeLog() << "\nload()" << std::endl;
clear();
std::string load_language( "en" );
std::string filename = m_config_path + FE_CFG_FILE;
if (( FE_DATA_PATH != NULL ) && ( !directory_exists( FE_DATA_PATH ) ))
{
FeLog() << "Warning: Attract-Mode was compiled to look for its default configuration files in: "
<< FE_DATA_PATH << ", which is not available." << std::endl;
}
if ( load_from_file( filename ) == false )
{
FeLog() << "Config file not found: " << filename << std::endl;
}
else
{
FeLog() << "Config: " << filename << std::endl;
if ( m_language.empty() )
m_language = "en";
load_language = m_language;
}
// Load language strings now.
//
// If we didn't find a config file, then we leave m_language empty but load the english language strings
// now. The user will be prompted (using the english strings) to select a language and then launched
// straight into configuration mode.
//
// If a config file was found but it didn't specify a language, then we use the english language (this
// preserves the previous behaviour for config files created in an earlier version)
//
internal_load_language( load_language );
//
// Initialize the regular expression used when sorting by title now...
//
std::string rex_str;
get_translation( "_sort_regexp", rex_str );
FeRomListSorter::init_title_rex( rex_str );
load_state();
// TODO: check if it can be moved outside load()
FeLog() << " m_current_display_index = m_current_display " << m_current_display_index << " = " << m_current_display << std::endl;
m_current_display_index = m_current_display;
if ( get_startup_mode() == ShowDisplaysMenu )
m_current_display = -1;
init_display();
// Make sure we have some keyboard mappings
//
m_inputmap.initialize_mappings();
// If no menu prompt is configured, default to calling it "Displays Menu" (in current language)
//
if ( m_menu_prompt.empty() )
get_translation( "Displays Menu", m_menu_prompt );
}
const char *FeSettings::configSettingStrings[] =
{
"language",
"exit_command",
"exit_message",
"ui_font_size",
"screen_saver_timeout",
"displays_menu_exit",
"hide_brackets",
"group_clones",
"startup_mode",
"confirm_favourites",
"confirm_exit",
"mouse_threshold",
"joystick_threshold",
"window_mode",
"screen_rotation",
"anti_aliasing",
"anisotropic",
"filter_wrap_mode",
"track_usage",
"multiple_monitors",
"smooth_images",
"selection_max_step",
"selection_speed_ms",
"move_mouse_on_launch",
"scrape_snaps",
"scrape_marquees",
"scrape_flyers",
"scrape_wheels",
"scrape_fanart",
"scrape_videos",
"scrape_overview",
"thegamesdb_key",
"power_saving",
#ifdef SFML_SYSTEM_WINDOWS
"hide_console",
#endif
"video_decoder",
"menu_prompt",
"menu_layout",
"image_cache_mbytes",
NULL
};
const char *FeSettings::otherSettingStrings[] =
{
"display",
"sound",
"input_map",
"general",
"plugin",
FeLayoutInfo::indexStrings[0], // "saver_config"
FeLayoutInfo::indexStrings[1], // "layout_config"
FeLayoutInfo::indexStrings[2], // "intro_config"
FeLayoutInfo::indexStrings[3], // "menu_config"
NULL
};
int FeSettings::process_setting( const std::string &setting,
const std::string &value,
const std::string &fn )
{
if (( setting.compare( otherSettingStrings[0] ) == 0 ) // list
|| ( setting.compare( "list" ) == 0 )) // for backwards compatability. As of 1.5, "list" became "display"
{
m_displays.push_back( FeDisplayInfo( value ) );
m_current_config_object = &m_displays.back();
}
else if ( setting.compare( otherSettingStrings[1] ) == 0 ) // sound
m_current_config_object = &m_sounds;
else if ( setting.compare( otherSettingStrings[2] ) == 0 ) // input_map
m_current_config_object = &m_inputmap;
else if ( setting.compare( otherSettingStrings[3] ) == 0 ) // general
m_current_config_object = NULL;
else if ( setting.compare( otherSettingStrings[4] ) == 0 ) // plugin
{
FePlugInfo new_plug( value );
m_plugins.push_back( new_plug );
m_current_config_object = &m_plugins.back();
}
else if ( setting.compare( otherSettingStrings[5] ) == 0 ) // saver_config
m_current_config_object = &m_saver_params;
else if ( setting.compare( otherSettingStrings[6] ) == 0 ) // layout_config
{
for ( std::vector< FeLayoutInfo >::iterator itr=m_layout_params.begin();
itr != m_layout_params.end(); ++itr )
{
if ( value.compare( (*itr).get_name() ) == 0 )
{
// If a duplicate, replace existing
(*itr).clear_params();
m_current_config_object = &(*itr);
return 0;
}
}
// Add new layout info
FeLayoutInfo new_entry( value );
m_layout_params.push_back( new_entry );
m_current_config_object = &m_layout_params.back();
}
else if ( setting.compare( otherSettingStrings[7] ) == 0 ) // intro_config
m_current_config_object = &m_intro_params;
else if ( setting.compare( otherSettingStrings[8] ) == 0 ) // menu_config
m_current_config_object = &m_display_menu_per_display_params;
else
{
int i=0;
while ( configSettingStrings[i] != NULL )
{
if ( setting.compare( configSettingStrings[i] ) == 0 )
{
if ( set_info( i, value ) == false )
{
const char **valid = NULL;
switch ( i )
{
case WindowMode:
valid = windowModeTokens;
break;
case ScreenRotation:
valid = screenRotationTokens;
break;
case FilterWrapMode:
valid = filterWrapTokens;
break;
case StartupMode:
valid = startupTokens;
break;
default:
break;
}
invalid_setting( fn,
configSettingStrings[i],
value, valid, NULL, "value" );
return 1;
}
return 0;
}
i++;
}
// if we get this far, then none of the settings associated with
// this object were found, pass to the current child object
if ( m_current_config_object != NULL )
return m_current_config_object->process_setting( setting, value, fn );
else
{
// <=2.4.1 there was an "accelerate_selection" boolean that if false
// disabled the selection acceleration (the same result as setting
// selection_max_step = 0)
//
if ( setting.compare( "accelerate_selection" ) == 0 )
{
if ( config_str_to_bool( value ) )
m_selection_max_step = 128; // set to default max step
else
m_selection_max_step = 0;
return 0;
}
invalid_setting( fn,
"general", setting, otherSettingStrings, configSettingStrings );
return 1;
}
}
return 0;
}
void FeSettings::init_display()
{
FeLog() << "\ninit_display()" << std::endl;
m_loaded_game_extras = false;
//
// Setting new_index to negative causes us to do the 'Displays Menu' w/ custom layout
//
if ( m_current_display < 0 )
{
m_rl.init_as_empty_list();
FeRomInfoListType &l = m_rl.get_list();
construct_display_maps();
for ( unsigned int i=0; i<m_display_menu.size(); i++ )
{
FeDisplayInfo *p = &(m_displays[m_display_menu[i]]);
FeRomInfo rom( p->get_info( FeDisplayInfo::Name ) );
rom.set_info( FeRomInfo::Title, p->get_info( FeDisplayInfo::Name ) );
rom.set_info( FeRomInfo::Emulator, "@" );
l.push_back( rom );
}
if ( m_displays_menu_exit )
{
std::string exit_str;
get_exit_message( exit_str );
FeRomInfo rom( exit_str );
rom.set_info( FeRomInfo::Title, exit_str );
rom.set_info( FeRomInfo::Emulator, "@exit" );
rom.set_info( FeRomInfo::AltRomname, "exit" );
l.push_back( rom );
}
FeDisplayInfo empty( "" );
m_rl.create_filters( empty );
// we want to keep m_current_search_index through the set_search_value() call
int temp_idx = m_current_search_index;
set_search_rule( "" );
m_current_search_index = temp_idx;
FeLog() << " m_current_search_index = m_current_display_index " << m_current_search_index << " = " << m_current_display_index << std::endl;
m_current_search_index = m_current_display_index; // This needs to be here
// Setup m_current_layout_params with all the parameters for our current layout, including
// the 'per_display' layout parameters that are stored separately but that get merged in here
//
m_current_layout_params = get_layout_config( m_menu_layout );
m_current_layout_params.merge_params( m_display_menu_per_display_params );
return;
}
set_search_rule( "" );
const std::string &romlist_name = m_displays[m_current_display].get_info(FeDisplayInfo::Romlist);
if ( romlist_name.empty() )
{
m_rl.init_as_empty_list();
construct_display_maps();
return;
}
FeLog() << std::endl << "*** Initializing display: '" << get_current_display_title() << "'" << std::endl;
std::string list_path( m_config_path );
list_path += FE_ROMLIST_SUBDIR;
// Check for a romlist in the data path if there isn't one that matches in the
// config directory
//
if (( !file_exists( list_path + romlist_name + FE_ROMLIST_FILE_EXTENSION ) )
&& ( FE_DATA_PATH != NULL ))
{
std::string temp = FE_DATA_PATH;
temp += FE_ROMLIST_SUBDIR;
if ( file_exists( temp + romlist_name + FE_ROMLIST_FILE_EXTENSION ) )
list_path = temp;
}
if ( m_rl.load_romlist( list_path,
romlist_name,
m_displays[m_current_display],
m_group_clones,
m_track_usage ) == false )
FeLog() << "Error opening romlist: " << romlist_name << std::endl;
// Setup m_current_layout_params with all the parameters for our current layout, including
// the 'per_display' layout parameters that are stored separately but that get merged in here
//
m_current_layout_params = get_layout_config(
m_displays[ m_current_display ].get_info( FeDisplayInfo::Layout ) );
m_current_layout_params.merge_params(
m_displays[ m_current_display ].get_layout_per_display_params() );
//
// Construct our display index views here, for lack of a better spot
//
// Do this here so that index views are rebuilt on a forced reset of
// the display (which happens when settings get changed for example)
//
construct_display_maps();
m_path_cache.clear();
}
void FeSettings::construct_display_maps()
{
m_display_cycle.clear();
m_display_menu.clear();
for ( unsigned int i=0; i<m_displays.size(); i++ )
{
if ( m_displays[i].show_in_cycle() )
m_display_cycle.push_back( i );
if ( m_displays[i].show_in_menu() )
m_display_menu.push_back( i );
}
}
void FeSettings::save_state()
{
int display_idx = m_current_display;
// If we have a display stack we save the entry at the bottom of the stack as the
// 'current' display
//
if ( !m_display_stack.empty() )
display_idx = m_display_stack.front();
if ( display_idx < 0 )
{
FeLog() << " display_idx = m_current_search_index " << display_idx << " = " << m_current_search_index << std::endl;
display_idx = m_current_search_index;
}
m_rl.save_state();
std::string filename( m_config_path );
confirm_directory( m_config_path, FE_EMPTY_STRING );
filename += FE_STATE_FILE;
nowide::ofstream outfile( filename.c_str() );
if ( outfile.is_open() )
{
outfile << display_idx << ";"
<< m_last_launch_display << "," << m_last_launch_filter
<< "," << m_last_launch_rom;
if ( m_last_launch_clone >= 0 )
outfile << "," << m_last_launch_clone;
outfile << ";" << m_menu_layout_file << std::endl;
for ( std::vector<FeDisplayInfo>::const_iterator itl=m_displays.begin();
itl != m_displays.end(); ++itl )
outfile << (*itl).state_as_output() << std::endl;
outfile.close();
}
}
void FeSettings::load_state()
{
if ( m_displays.empty() )
{
m_current_display = -1;
return;
}
std::string filename( m_config_path );
filename += FE_STATE_FILE;
nowide::ifstream myfile( filename.c_str() );
std::string line;
if ( myfile.is_open() && myfile.good() )
{
getline( myfile, line );
size_t pos=0;
std::string tok;
token_helper( line, pos, tok, ";" );
m_current_display = as_int( tok );
token_helper( line, pos, tok, ";" );
int i=0;
size_t pos2=0;
while (( pos2 < tok.size() ) && ( i < 3 ))
{
std::string tok2;
token_helper( tok, pos2, tok2, "," );
int temp = as_int( tok2 );
switch (i)
{
case 0: m_last_launch_display = temp; break;
case 1: m_last_launch_filter = temp; break;
case 2: m_last_launch_rom = temp; break;
case 3: m_last_launch_clone = temp; break;
}
i++;
}
token_helper( line, pos, tok, ";" );
m_menu_layout_file = tok;
for ( std::vector<FeDisplayInfo>::iterator itl=m_displays.begin();
itl != m_displays.end(); ++itl )
{
if ( myfile.good() )
{
getline( myfile, line );
(*itl).process_state( line );
}
}
}
// bound checking on the current list state
if ( m_current_display >= (int)m_displays.size() )
m_current_display = m_displays.size() - 1;
if ( m_current_display < 0 )
m_current_display = 0;
// bound checking on the last launch state
if ( m_last_launch_display >= (int)m_displays.size() )
m_last_launch_display = m_displays.size() - 1;
if ( m_last_launch_display < 0 )
m_last_launch_display = 0;
if ( m_last_launch_filter >= m_displays[ m_last_launch_display ].get_filter_count() )
m_last_launch_filter = m_displays[ m_last_launch_display ].get_filter_count() - 1;
if ( m_last_launch_filter < 0 )
m_last_launch_filter = 0;
// confirm loaded state points to layout files that actually exist (and reset if it doesn't)
for ( std::vector<FeDisplayInfo>::iterator itr = m_displays.begin(); itr != m_displays.end(); ++itr )
{
std::string file = (*itr).get_current_layout_file();
if ( !file.empty() )
{
std::string path;
get_layout_dir( (*itr).get_info( FeDisplayInfo::Layout ), path );
std::string fn = path + file + FE_LAYOUT_FILE_EXTENSION ;
if ( !file_exists( fn ) )
{
FeDebug() << "Resetting saved layout file since the file does not actually exist. Display: "
<< (*itr).get_info( FeDisplayInfo::Name )
<< ", file: " << fn << :: std::endl;
(*itr).set_current_layout_file( "" );
}
}
}
if ( !m_menu_layout_file.empty() )
{
std::string path;
get_layout_dir( m_menu_layout, path );
std::string fn = path + m_menu_layout_file + FE_LAYOUT_FILE_EXTENSION ;
if ( !file_exists( fn ) )
{
FeDebug() << "Resetting Displays Menu layout file (file doesn't exist): " << fn << :: std::endl;
m_menu_layout_file = "";
}
}
}
FeInputMap::Command FeSettings::map_input( const sf::Event &e )
{
return m_inputmap.map_input( e, m_mousecap_rect, m_joy_thresh );
}
FeInputMap::Command FeSettings::input_conflict_check( const FeInputMapEntry &e )
{
return m_inputmap.input_conflict_check( e );
}
void FeSettings::get_input_config_metrics( sf::IntRect &mousecap_rect, int &joy_thresh )
{
mousecap_rect = m_mousecap_rect;
joy_thresh = m_joy_thresh;
}
FeInputMap::Command FeSettings::get_default_command( FeInputMap::Command c )
{
return m_inputmap.get_default_command( c );
}
void FeSettings::set_default_command( FeInputMap::Command c, FeInputMap::Command v )
{
m_inputmap.set_default_command( c, v );
}
bool FeSettings::get_current_state( FeInputMap::Command c )
{
return m_inputmap.get_current_state( c, m_joy_thresh );
}
void FeSettings::init_mouse_capture( int window_x, int window_y )
{
int radius = window_x * m_mouse_thresh / 400;
int centre_x = window_x / 2;
int centre_y = window_y / 2;
m_mousecap_rect.left = centre_x - radius;
m_mousecap_rect.top = centre_y - radius;
m_mousecap_rect.width = radius * 2;
m_mousecap_rect.height = radius * 2;
}
bool FeSettings::test_mouse_reset( int mouse_x, int mouse_y ) const
{
return (( m_inputmap.has_mouse_moves() ) && ( !m_mousecap_rect.contains( mouse_x, mouse_y ) ));
}
int FeSettings::get_filter_index_from_offset( int offset ) const
{
if ( m_current_display < 0 )
return 0;
int f_count = m_displays[m_current_display].get_filter_count();
if ( f_count == 0 )
return 0;
int off = abs( offset ) % f_count;
int retval = get_current_filter_index();
if ( offset < 0 )
retval -= off;
else
retval += off;
if ( retval < 0 )
retval += f_count;
if ( retval >= f_count )
retval -= f_count;
return retval;
}
int FeSettings::get_filter_count() const
{
if ( m_current_display < 0 )
return 1;
return m_displays[m_current_display].get_filter_count();
}
int FeSettings::get_filter_size( int filter_index ) const
{
if ( !m_current_search.empty()
&& ( get_current_filter_index() == filter_index ))
return m_current_search.size();
return m_rl.filter_size( filter_index );
}
int FeSettings::get_rom_index( int filter_index, int offset ) const
{
FeLog() << "\nget_rom_index()" << std::endl;
int retval, rl_size;
if ( m_current_display < 0 )
{
// FeLog() << " retval = m_current_search_index " << retval << " = " << m_current_search_index << std::endl;
// retval = m_current_search_index; //dupa
FeLog() << " retval = m_current_display_index " << retval << " = " << m_current_display_index << std::endl;
retval = m_current_display_index;
rl_size = m_rl.filter_size( filter_index );
}
else if ( !m_current_search.empty()
&& ( get_current_filter_index() == filter_index ))
{
FeLog() << " retval = m_current_search_index " << retval << " = " << m_current_search_index << std::endl;
retval = m_current_search_index;
rl_size = m_current_search.size();
}
else
{
retval = m_displays[m_current_display].get_rom_index( filter_index );
rl_size = m_rl.filter_size( filter_index );
}
// keep in bounds
if ( retval >= rl_size )
retval = rl_size - 1;
if ( retval < 0 )
retval = 0;
// apply the offset
if ( rl_size > 0 )
{
int off = abs( offset ) % rl_size;
if ( offset < 0 )
retval -= off;
else
retval += off;