-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathretroarch-phoenix.cpp
2009 lines (1702 loc) · 58.8 KB
/
retroarch-phoenix.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
#include <phoenix.hpp>
#include <cstdlib>
#ifndef _WIN32
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/poll.h>
#include <fcntl.h>
#include <signal.h>
#else
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#include "config_file.hpp"
#include <utility>
#include <functional>
#include "settings.hpp"
#include "dynamic.h"
#include "libretro.h"
#ifdef _WIN32
#include "updater.hpp"
#endif
using namespace nall;
using namespace phoenix;
namespace Internal
{
extern "C"
{
bool environ_cb(unsigned cmd, void *data);
}
static bool *load_no_rom;
bool environ_cb(unsigned cmd, void *data)
{
switch (cmd)
{
case RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME:
*load_no_rom = *(const bool*)data;
break;
default:
return false;
}
return true;
}
static lstring split_strings(const char *text, unsigned size)
{
lstring list;
unsigned ptr = 0;
list.append(text);
for (;;)
{
while (text[ptr] && ptr < size)
ptr++;
ptr++;
if (ptr >= size)
break;
list.append(&text[ptr]);
}
return list;
}
#ifndef _WIN32
static volatile sig_atomic_t child_quit;
static volatile sig_atomic_t status;
static volatile sig_atomic_t abnormal_quit;
static bool async;
static pid_t child_pid;
extern "C"
{
static void sigchld_handle(int);
}
static void sigchld_handle(int)
{
if (async)
while (waitpid(-1, NULL, WNOHANG) > 0) print("Reaped zombie ...\n");
else
{
int pstatus;
waitpid(child_pid, &pstatus, 0);
status = WEXITSTATUS(pstatus);
child_quit = 1;
abnormal_quit = !WIFEXITED(pstatus);
}
}
#endif
}
class LogWindow : public ToggleWindow
{
public:
LogWindow() : ToggleWindow("RetroArch || Log window")
{
label.setText("RetroArch output:");
layout.append(label, 0, 0);
layout.append(box, ~0, ~0);
select_all.setText("Select all");
copy_all.setText("Copy all");
clear_all.setText("Clear all");
hbox.append(select_all, 0, 0);
hbox.append(copy_all, 0, 0);
hbox.append(clear_all, 0, 0);
layout.append(hbox);
select_all.onTick = [this] { box.selectAll(); };
copy_all.onTick = [this] { box.copyAll(); };
clear_all.onTick = [this] { log = ""; box.setText(log); };
box.setEditable(false);
layout.setMargin(5);
auto minimum = layout.minimumGeometry();
setGeometry({128, 128, max(300u, minimum.width), max(300u, minimum.height)});
append(layout);
}
void push(const char *text) { log.append(text); box.setText(log); }
void push(const lstring &list)
{
foreach (str, list)
log.append(str);
box.setText(log);
}
// Push strings which are split by NUL. text[size] needs to be NUL.
void push(const char *text, unsigned size)
{
push(Internal::split_strings(text, size));
}
void clear() { log = ""; box.setText(log); }
private:
VerticalLayout layout;
TextEdit box;
Label label;
HorizontalLayout hbox;
Button select_all;
Button copy_all;
Button clear_all;
string log;
};
class Remote : public ToggleWindow
{
public:
Remote() : ToggleWindow("RetroArch || Remote"), logger(0)
{
save_state.setText("Save state");
load_state.setText("Load state");
fast_forward.setText("Fast forward toggle");
fullscreen_toggle.setText("Fullscreen toggle");
quit.setText("Quit");
state_slot_plus.setText("State/movie slot (+)");
state_slot_minus.setText("State/movie slot (-)");
movie_record_toggle.setText("Movie record toggle");
pause_toggle.setText("Pause toggle");
frameadvance.setText("Frame advance");
reset.setText("Reset");
cheat_index_plus.setText("Cheat index (+)");
cheat_index_minus.setText("Cheat index (-)");
cheat_toggle.setText("Cheat toggle");
screenshot.setText("Screenshot");
dsp_config.setText("DSP config");
vol_up.setText("Volume (+)");
vol_down.setText("Volume (-)");
mute.setText("Mute audio");
shader.setText("Set shader ...");
log.setText("Show log");
save_state.onTick = [this] { send_cmd("SAVE_STATE\n"); };
load_state.onTick = [this] { send_cmd("LOAD_STATE\n"); };
fast_forward.onTick = [this] { send_cmd("FAST_FORWARD\n"); };
fullscreen_toggle.onTick = [this] { send_cmd("FULLSCREEN_TOGGLE\n"); };
quit.onTick = [this] { send_cmd("QUIT\n"); };
state_slot_plus.onTick = [this] { send_cmd("STATE_SLOT_PLUS\n"); };
state_slot_minus.onTick = [this] { send_cmd("STATE_SLOT_MINUS\n"); };
movie_record_toggle.onTick = [this] { send_cmd("MOVIE_RECORD_TOGGLE\n"); };
pause_toggle.onTick = [this] { send_cmd("PAUSE_TOGGLE\n"); };
frameadvance.onTick = [this] { send_cmd("FRAMEADVANCE\n"); };
reset.onTick = [this] { send_cmd("RESET\n"); };
cheat_index_plus.onTick = [this] { send_cmd("CHEAT_INDEX_PLUS\n"); };
cheat_index_minus.onTick = [this] { send_cmd("CHEAT_INDEX_MINUS\n"); };
cheat_toggle.onTick = [this] { send_cmd("CHEAT_TOGGLE\n"); };
screenshot.onTick = [this] { send_cmd("SCREENSHOT\n"); };
dsp_config.onTick = [this] { send_cmd("DSP_CONFIG\n"); };
vol_up.onTick = [this] { send_cmd("VOLUME_UP\n"); };
vol_down .onTick = [this] { send_cmd("VOLUME_DOWN\n"); };
mute.onTick = [this] { send_cmd("MUTE\n"); };
shader.onTick = [this] { send_arg_cmd("SET_SHADER"); };
log.onTick = [this] { if (logger) logger->show(); };
const int remote_button_w = 180;
vbox[0].append(quit, remote_button_w, 0);
vbox[1].append(shader, remote_button_w, 0);
vbox[1].append(log, remote_button_w, 0);
vbox[2].append(load_state, remote_button_w, 0);
vbox[2].append(save_state, remote_button_w, 0);
vbox[2].append(state_slot_plus, remote_button_w, 0);
vbox[2].append(state_slot_minus, remote_button_w, 0);
vbox[2].append(cheat_index_plus, remote_button_w, 0);
vbox[2].append(cheat_index_minus, remote_button_w, 0);
vbox[2].append(cheat_toggle, remote_button_w, 0);
vbox[2].append(reset, remote_button_w, 0);
vbox[3].append(pause_toggle, remote_button_w, 0);
vbox[3].append(frameadvance, remote_button_w, 0);
vbox[3].append(fast_forward, remote_button_w, 0);
vbox[3].append(fullscreen_toggle, remote_button_w, 0);
vbox[4].append(movie_record_toggle, remote_button_w, 0);
vbox[4].append(screenshot, remote_button_w, 0);
vbox[4].append(dsp_config, remote_button_w, 0);
vbox[4].append(vol_up, remote_button_w, 0);
vbox[4].append(vol_down, remote_button_w, 0);
vbox[4].append(mute, remote_button_w, 0);
foreach(v, vbox)
layout.append(v);
auto minimum = layout.minimumGeometry();
setGeometry({100, 100, minimum.width, minimum.height});
append(layout);
}
// Comment out to test "remote".
//void show() {}
#ifdef _WIN32
void set_handle(HANDLE file) { this->handle = file; }
void send_cmd(const char *cmd) { DWORD written; WriteFile(handle, cmd, strlen(cmd), &written, NULL); }
#else
void set_fd(int fd) { this->fd = fd; }
void send_cmd(const char *cmd) { write(fd, cmd, strlen(cmd)); }
#endif
void send_arg_cmd(const char *cmd)
{
string file = OS::fileLoad(Window::None, "", "XML shader, Cg shader, Cg-meta shader (*.shader,*.cg,*.cgp)");
if (file.length() == 0)
return;
string cmd_str = { cmd, " ", file, "\n" };
send_cmd(cmd_str);
}
LogWindow *logger;
private:
#ifdef _WIN32
HANDLE handle;
#else
int fd;
#endif
VerticalLayout vbox[5];
HorizontalLayout layout;
Button save_state, load_state;
Button fast_forward, fullscreen_toggle, quit, state_slot_plus, state_slot_minus;
Button movie_record_toggle, pause_toggle, frameadvance, reset;
Button cheat_index_plus, cheat_index_minus, cheat_toggle, screenshot, dsp_config, vol_up, vol_down;
Button mute;
Button shader, log;
};
class MainWindow : public Window
{
public:
MainWindow(const nall::string &libretro_path) :
input(configs.cli), general(configs.gui, configs.cli), video(configs.cli), audio(configs.cli), ext_rom(configs.gui),
m_cli_path(libretro_path), load_no_rom(false), m_cli_custom_path(libretro_path.length())
{
setTitle("RetroArch || Phoenix");
setIcon("/usr/share/icons/retroarch-phoenix.png");
init_menu();
onClose = []() { OS::quit(); };
init_main_frame();
vbox.setMargin(5);
auto minimum = vbox.minimumGeometry();
setGeometry({256, 256, max(750u, minimum.width), minimum.height});
append(vbox);
setMenuVisible();
setStatusVisible();
forked_timer.onTimeout = [this]() { this->forked_event(); };
forked_timer.setInterval(100);
init_config();
setVisible();
remote.logger = &log_win;
}
~MainWindow()
{
save_controllers();
}
private:
VerticalLayout vbox;
Menu file_menu, settings_menu, help_menu;
#ifdef _WIN32
Menu updater_menu;
#endif
Button start_btn;
Input input;
General general;
Video video;
Audio audio;
Remote remote;
ExtROM ext_rom;
#ifdef _WIN32
Updater updater;
#endif
string m_cli_path;
bool m_cli_custom_path;
bool load_no_rom;
struct netplay
{
netplay() : file(0)
{
port.setText("55435");
frames.setText("0");
enable_label.setText("Netplay:");
enable.setText("Enable");
server.setText("Server");
client.setText("Client");
spectate.setText("Spectate mode");
host_label.setText("Host IP:");
port_label.setText("TCP/UDP Port:");
frames_label.setText("Delay frames:");
nick_label.setText("Nickname:");
server.setChecked();
RadioBox::group(server, client);
hlayout[0].append(enable_label, 100, 0);
hlayout[0].append(enable, 80, 0, 0);
hlayout[0].append(server, 70, 20);
hlayout[0].append(client, 70, 20);
hlayout[0].append(spectate, 150, 20);
hlayout[1].append(host_label, 80, 0, 20);
hlayout[1].append(host, 200, 0, 20);
hlayout[1].append(port_label, 120, 0, 20);
hlayout[1].append(port, 100, 0);
hlayout[2].append(frames_label, 80, 0, 20);
hlayout[2].append(frames, 60, 0, 160);
hlayout[2].append(nick_label, 120, 0, 20);
hlayout[2].append(nick, 150, 0);
nick.onChange = [this] {
if (file)
file->set(file_key, nick.text());
};
}
void setConfig(ConfigFile &config_file, const string &opt)
{
file = &config_file;
file_key = opt;
}
HorizontalLayout hlayout[3];
RadioBox server, client;
Label port_label, host_label, frames_label, nick_label;
LineEdit port;
LineEdit host;
LineEdit frames;
LineEdit nick;
CheckBox enable;
CheckBox spectate;
Label enable_label;
ConfigFile *file;
string file_key;
} net;
struct
{
ConfigFile gui, cli;
} configs;
LogWindow log_win;
struct entry
{
HorizontalLayout hlayout;
Label label;
LineEdit edit;
Button button;
Button clear;
string filter;
string short_filter;
bool save_file;
string default_start_path;
ConfigFile *conf;
string config_key;
function<void (const string&)> cb;
entry(bool preapply = true) : conf(NULL), cb(&entry::dummy)
{
button.setText("Browse ...");
clear.setText("Clear");
save_file = false;
if (preapply)
apply_layout();
button.onTick = [this]() {
string start_path;
string path;
path = this->getPath();
if (path.length() > 0)
{
char buf[1024];
nall::strlcpy(buf, path, sizeof(buf));
char *delim = strrchr(buf, '/');
if (!delim)
delim = strrchr(buf, '\\');
if (delim)
{
*delim = '\0';
start_path = buf;
}
else
start_path = ".";
}
else if (default_start_path.length() > 0)
start_path = default_start_path;
else
{
const char *path = std::getenv("HOME");
if (path)
start_path = path;
}
string file;
if (save_file)
{
file = OS::fileSave(Window::None, start_path, filter);
if (file.length() > 0 && !file.endswith(short_filter))
file.append(short_filter);
}
else
file = OS::fileLoad(Window::None, start_path, filter);
if (file.length() > 0)
{
edit.setText(file);
if (short_filter.length() > 0 && !file.endswith(short_filter))
{
MessageWindow::warning(Window::None,
{"Filename extension does not match with the expected extension: \"",
short_filter, "\""});
}
}
if (conf)
conf->set(config_key, this->getPath());
cb(this->getPath());
};
clear.onTick = [this]() {
edit.setText("");
if (conf)
conf->set(config_key, string(""));
cb("");
};
//edit.setEditable(false);
}
~entry()
{
saveConfig();
}
void saveConfig()
{
if (conf)
conf->set(config_key, getPath());
}
void setFilter(const string& _filter, const string& _short_filter = "")
{
filter = _filter;
short_filter = _short_filter;
}
void setLabel(const string& name) { label.setText(name); }
void setPath(const string& name) { edit.setText(name.length() > 0 ? name : string("")); cb(this->getPath()); }
void setConfig(ConfigFile& file, const string& key, const function<void (const string&)>& _cb = &entry::dummy)
{
conf = &file;
config_key = key;
cb = _cb;
}
void setStartPath(const string& _start_path) { default_start_path = _start_path; }
string getPath() { return edit.text(); }
HorizontalLayout& layout() { return hlayout; }
private:
static void dummy(const string&) {}
void apply_layout()
{
hlayout.append(label, 150, 0);
hlayout.append(edit, ~0, 0);
hlayout.append(clear, 0, 0);
hlayout.append(button, 0, 0);
}
} rom, config, retroarch, libretro, record_config;
struct bsv_entry : entry
{
bsv_entry(bool enable = true) : entry(false)
{
if (enable)
{
disabled.setText("Disabled");
enable_playback.setText("Playback");
enable_record.setText("Record");
RadioBox::group(disabled, enable_playback, enable_record);
enable_load.setText("Load SRAM");
enable_save.setText("Save SRAM");
hlayout.append(label, 150, 0);
hlayout.append(edit, ~0, 0);
hlayout.append(clear, 0, 0);
hlayout.append(button, 0, 0);
opts_label.setText("BSV options:");
hlayout_opt.append(opts_label, 150, 0);
hlayout_opt.append(disabled, 0, 0, 8);
hlayout_opt.append(enable_playback, 0, 0, 8);
hlayout_opt.append(enable_record, 0, 0, 38);
hlayout_opt.append(enable_load, 0, 0, 8);
hlayout_opt.append(enable_save, 0, 0);
save_file = true;
disabled.onTick = [this] { this->save_file = true; };
enable_playback.onTick = [this] { this->save_file = false; };
enable_record.onTick = [this] { this->save_file = true; };
disabled.setChecked();
}
}
bool is_playback() { return enable_playback.checked(); }
bool is_record() { return enable_record.checked(); }
bool load_sram() { return enable_load.checked(); }
bool save_sram() { return enable_save.checked(); }
HorizontalLayout hlayout_opt;
HorizontalLayout& layout_opt() { return hlayout_opt; }
RadioBox disabled;
RadioBox enable_playback;
RadioBox enable_record;
CheckBox enable_load;
CheckBox enable_save;
Label opts_label;
} bsv_movie;
struct record_entry : entry
{
record_entry() : entry(false)
{
enable_tick.setText("Enable");
hlayout.append(label, 150, 0);
hlayout.append(edit, ~0, 0, 5);
dim_label.setText("Dimensions:");
hlayout.append(dim_label, 0, 0, 3);
hlayout.append(dim_edit, 80, 0, 5);
hlayout.append(enable_tick, 80, 0);
hlayout.append(clear, 0, 0);
hlayout.append(button, 0, 0);
}
bool is_enabled() { return enable_tick.checked(); }
CheckBox enable_tick;
Label dim_label;
LineEdit dim_edit;
} record;
enum rom_type
{
Normal,
SGB,
Sufami,
BSX,
BSX_Slot
};
struct rom_type_box
{
rom_type_box()
{
box.append("Normal ROM");
box.append("Super GameBoy");
box.append("Sufami Turbo");
box.append("BSX");
box.append("BSX slotted");
allow_patches.setText("Check for ROM patches");
allow_patches.setChecked();
allow_patches.onTick = [this] { file->set("allow_patches", allow_patches.checked()); };
label.setText("ROM type:");
hlayout.append(label, 150, 0);
hlayout.append(box, 200, 0, 30);
hlayout.append(allow_patches, 0, 0);
}
void setConfig(ConfigFile &conf)
{
file = &conf;
}
enum rom_type type()
{
static const enum rom_type types[] = {Normal, SGB, Sufami, BSX, BSX_Slot};
return types[box.selection()];
}
bool allow_patch() { return allow_patches.checked(); }
void allow_patch(bool allow) { allow_patches.setChecked(allow); }
HorizontalLayout& layout() { return hlayout; }
private:
ComboBox box;
Label label;
HorizontalLayout hlayout;
CheckBox allow_patches;
ConfigFile *file;
} rom_type;
#ifdef _WIN32
// Windows is completely batshit retarded and the relative path might "change" by going into the file manager, so we have to manually figure out the full path. :)
static string basedir()
{
char dir_path[MAX_PATH];
GetModuleFileNameA(GetModuleHandle(0), dir_path, sizeof(dir_path));
char *split = strrchr(dir_path, '\\');
if (!split) split = strrchr(dir_path, '/');
if (split) split[1] = '\0';
return dir_path;
}
static string gui_config_path()
{
string dir = basedir();
// If we have retroarch-phoenix.cfg in same directory, use that ...
WIN32_FIND_DATAA data;
string gui_path = {dir, "\\retroarch-phoenix.cfg"};
HANDLE find_file = FindFirstFileA(gui_path, &data);
if (find_file != INVALID_HANDLE_VALUE)
{
FindClose(find_file);
return gui_path;
}
const char *path = std::getenv("APPDATA");
if (path)
return {path, "\\phoenix.cfg"};
else
return gui_path;
}
string cli_config_path()
{
string tmp;
if (configs.gui.get("config_path", tmp))
return tmp;
else
{
string dir = basedir();
// If we have retroarch.cfg in same directory, use that ...
WIN32_FIND_DATAA data;
string cli_path = {dir, "\\retroarch.cfg"};
HANDLE find_file = FindFirstFileA(cli_path, &data);
if (find_file != INVALID_HANDLE_VALUE)
{
FindClose(find_file);
return cli_path;
}
const char *path = std::getenv("APPDATA");
if (path)
return {path, "\\retroarch.cfg"};
else
{
char dir[256];
GetCurrentDirectoryA(sizeof(dir), dir);
return {dir, "\\retroarch.cfg"};
}
}
}
#elif defined(__APPLE__)
static string gui_config_path()
{
string gui_path;
const char *home = std::getenv("HOME");
if (home)
{
gui_path = home;
gui_path.append("/.retroarch_phoenix.cfg");
}
else
gui_path = "/etc/retroarch_phoenix.cfg";
return gui_path;
}
string cli_config_path()
{
const char *path = std::getenv("HOME");
string cli_path;
string tmp;
if (configs.gui.get("config_path", tmp))
cli_path = tmp;
else
{
if (path)
{
cli_path = path;
cli_path.append("/.retroarch.cfg");
}
else
cli_path = "/etc/retroarch.cfg";
}
return cli_path;
}
#else
static string gui_config_path()
{
string gui_path;
const char *path = std::getenv("XDG_CONFIG_HOME");
const char *home_path = std::getenv("HOME");
if (path)
{
string dir = {path, "/retroarch"};
mkdir(dir, 0755);
gui_path = path;
gui_path.append("/retroarch/phoenix.cfg");
}
else if (home_path)
{
gui_path = home_path;
gui_path.append("/.retroarch_phoenix.cfg");
}
else
gui_path = "/etc/retroarch_phoenix.cfg";
return gui_path;
}
string cli_config_path()
{
const char *path = std::getenv("XDG_CONFIG_HOME");
const char *home_path = std::getenv("HOME");
string cli_path;
string tmp;
if (configs.gui.get("config_path", tmp))
{
cli_path = tmp;
}
else
{
if (path)
{
string dir = {path, "/retroarch"};
mkdir(dir, 0644);
cli_path = path;
cli_path.append("/retroarch/retroarch.cfg");
}
else if (home_path)
{
cli_path = home_path;
cli_path.append("/.retroarch.cfg");
}
else
cli_path = "/etc/retroarch.cfg";
}
return cli_path;
}
#endif
void init_controllers()
{
string tmp;
if (configs.gui.get("controller_1", tmp))
{
if (tmp == "gamepad")
settings.gamepad_1.setChecked();
else if (tmp == "dualanalog")
settings.dualanalog_1.setChecked();
else if (tmp == "mouse")
settings.mouse_1.setChecked();
else if (tmp == "none")
settings.none_1.setChecked();
}
if (configs.gui.get("controller_2", tmp))
{
if (tmp == "gamepad")
settings.gamepad_2.setChecked();
else if (tmp == "dualanalog")
settings.dualanalog_2.setChecked();
else if (tmp == "mouse")
settings.mouse_2.setChecked();
else if (tmp == "scope")
settings.scope_2.setChecked();
else if (tmp == "justifier")
settings.justifier_2.setChecked();
else if (tmp == "justifiers")
settings.justifiers_2.setChecked();
else if (tmp == "none")
settings.none_2.setChecked();
}
}
void save_controllers()
{
if (settings.gamepad_1.checked())
configs.gui.set("controller_1", string("gamepad"));
else if (settings.mouse_1.checked())
configs.gui.set("controller_1", string("mouse"));
else if (settings.none_1.checked())
configs.gui.set("controller_1", string("none"));
else if (settings.dualanalog_1.checked())
configs.gui.set("controller_1", string("dualanalog"));
if (settings.gamepad_2.checked())
configs.gui.set("controller_2", string("gamepad"));
else if (settings.mouse_2.checked())
configs.gui.set("controller_2", string("mouse"));
else if (settings.none_2.checked())
configs.gui.set("controller_2", string("none"));
else if (settings.dualanalog_2.checked())
configs.gui.set("controller_2", string("dualanalog"));
else if (settings.scope_2.checked())
configs.gui.set("controller_2", string("scope"));
else if (settings.justifier_2.checked())
configs.gui.set("controller_2", string("justifier"));
else if (settings.justifiers_2.checked())
configs.gui.set("controller_2", string("justifiers"));
}
void save_config()
{
nall::string current_conf = config.getPath();
char buf[1024];
nall::strlcpy(buf, current_conf, sizeof(buf));
char *delim = strrchr(buf, '/');
if (!delim)
delim = strrchr(buf, '\\');
nall::string start_path;
if (delim)
{
*delim = '\0';
start_path = buf;
}
else
start_path = ".";
string file = OS::fileSave(Window::None, start_path, "Config File (*.cfg)");
if (file.length() > 0 && !file.endswith(".cfg"))
file.append(".cfg");
if (file.length() > 0)
{
configs.cli.write(file);
configs.cli.replace_path(file);
config.setPath(file);
}
}
void init_config()
{
string tmp;
string gui_path = gui_config_path();
configs.gui = ConfigFile(gui_path);
if (configs.gui.get("retroarch_path", tmp)) retroarch.setPath(tmp);
retroarch.setConfig(configs.gui, "retroarch_path");
if (configs.gui.get("last_movie", tmp)) bsv_movie.setPath(tmp);
bsv_movie.setConfig(configs.gui, "last_movie");
if (configs.gui.get("record_path", tmp)) record.setPath(tmp);
record.setConfig(configs.gui, "record_path");
if (configs.gui.get("record_config_path", tmp)) record_config.setPath(tmp);
record_config.setConfig(configs.gui, "record_config_path");
if (configs.gui.get("nickname", tmp)) net.nick.setText(tmp);
net.setConfig(configs.gui, "nickname");
if (configs.gui.get("config_path", tmp)) config.setPath(tmp);
config.setConfig(configs.gui, "config_path", {&MainWindow::reload_cli_config, this});
libretro.setConfig(configs.cli, "libretro_path",
[this](const string& path) {
update_rom_filter(path);
});
init_controllers();
bool patches;
if (configs.gui.get("allow_patches", patches))
rom_type.allow_patch(patches);
rom_type.setConfig(configs.gui);
if (!m_cli_custom_path)
m_cli_path = cli_config_path();
print("Loading CLI path: ", m_cli_path, "\n");
configs.cli = ConfigFile(m_cli_path);
config.setPath(m_cli_path);
rom.setConfig(configs.cli, "phoenix_last_rom");
init_cli_config();
}
void reload_cli_config(const string& path)
{
print("Reloading config: ", path, "\n");
if (path.length() > 0)
{
configs.cli = ConfigFile(path);
m_cli_path = path;
}
else
{
m_cli_path = cli_config_path();
configs.cli = ConfigFile(m_cli_path);
}
init_cli_config();
}
void init_cli_config()
{
string tmp;
if (configs.cli.get("libretro_path", tmp))
libretro.setPath(tmp);
else