forked from sahlberg/wLaunchELF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.c
2507 lines (2306 loc) · 81.5 KB
/
config.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
//---------------------------------------------------------------------------
// File name: config.c
//---------------------------------------------------------------------------
#include "launchelf.h"
#include <stdbool.h>
enum {
DEF_TIMEOUT = 10,
DEF_HIDE_PATHS = TRUE,
DEF_COLOR1 = GS_SETREG_RGBA(128, 128, 128, 0), //Backgr
DEF_COLOR2 = GS_SETREG_RGBA(64, 64, 64, 0), //Frame
DEF_COLOR3 = GS_SETREG_RGBA(96, 0, 0, 0), //Select
DEF_COLOR4 = GS_SETREG_RGBA(0, 0, 0, 0), //Text
DEF_COLOR5 = GS_SETREG_RGBA(96, 96, 0, 0), //Graph1
DEF_COLOR6 = GS_SETREG_RGBA(0, 96, 0, 0), //Graph2
DEF_COLOR7 = GS_SETREG_RGBA(224, 224, 224, 0), //Graph3
DEF_COLOR8 = GS_SETREG_RGBA(0, 0, 0, 0), //Graph4
DEF_MENU_FRAME = TRUE,
DEF_MENU = TRUE,
DEF_NUMCNF = 1,
DEF_SWAPKEYS = FALSE,
DEF_BRIGHT = 50,
DEF_POPUP_OPAQUE = FALSE,
DEF_INIT_DELAY = 0,
DEF_USBKBD_USED = 1,
DEF_SHOW_TITLES = 1,
DEF_PATHPAD_LOCK = 0,
DEF_JPGVIEW_TIMER = 5,
DEF_JPGVIEW_TRANS = 2,
DEF_JPGVIEW_FULL = 0,
DEF_PSU_HUGENAMES = 0,
DEF_PSU_DATENAMES = 0,
DEF_PSU_NOOVERWRITE = 0,
DEF_FB_NOICONS = 0,
};
static const char LK_ID[SETTING_LK_COUNT][10] = {
"auto",
"Circle",
"Cross",
"Square",
"Triangle",
"L1",
"R1",
"L2",
"R2",
"L3",
"R3",
"Start",
"Select", //Predefined for "CONFIG"
"Left", //Predefined for "LOAD CONFIG--"
"Right", //Predefined for "LOAD CONFIG++"
"ESR",
"OSDSYS"};
char PathPad[MAX_PATH_PAD][MAX_PATH];
SETTING *setting = NULL;
static SETTING *tmpsetting;
//---------------------------------------------------------------------------
// End of declarations
// Start of functions
//---------------------------------------------------------------------------
// get_CNF_string is the main CNF parser called for each CNF variable in a
// CNF file. Input and output data is handled via its pointer parameters.
// The return value flags 'false' when no variable is found. (normal at EOF)
//---------------------------------------------------------------------------
int get_CNF_string(char **CNF_p_p,
char **name_p_p,
char **value_p_p)
{
char *np, *vp, *tp = *CNF_p_p;
start_line:
while ((*tp <= ' ') && (*tp > '\0'))
tp += 1; //Skip leading whitespace, if any
if (*tp == '\0')
return false; //but exit at EOF
np = tp; //Current pos is potential name
if (*tp < 'A') //but may be a comment line
{ //We must skip a comment line
while ((*tp != '\r') && (*tp != '\n') && (*tp > '\0'))
tp += 1; //Seek line end
goto start_line; //Go back to try next line
}
while ((*tp >= 'A') || ((*tp >= '0') && (*tp <= '9')))
tp += 1; //Seek name end
if (*tp == '\0')
return false; //but exit at EOF
while ((*tp <= ' ') && (*tp > '\0'))
*tp++ = '\0'; //zero&skip post-name whitespace
if (*tp != '=')
return false; //exit (syntax error) if '=' missing
*tp++ = '\0'; //zero '=' (possibly terminating name)
while ((*tp <= ' ') && (*tp > '\0') //Skip pre-value whitespace, if any
&& (*tp != '\r') && (*tp != '\n'))
tp += 1; //but do not pass the end of the line
if (*tp == '\0')
return false; //but exit at EOF
vp = tp; //Current pos is potential value
while ((*tp != '\r') && (*tp != '\n') && (*tp != '\0'))
tp += 1; //Seek line end
if (*tp != '\0')
*tp++ = '\0'; //terminate value (passing if not EOF)
while ((*tp <= ' ') && (*tp > '\0'))
tp += 1; //Skip following whitespace, if any
*CNF_p_p = tp; //return new CNF file position
*name_p_p = np; //return found variable name
*value_p_p = vp; //return found variable value
return true; //return control to caller
} //Ends get_CNF_string
//---------------------------------------------------------------------------
int CheckMC(void)
{
int dummy, ret;
mcGetInfo(0, 0, &dummy, &dummy, &dummy);
mcSync(0, NULL, &ret);
if (-1 == ret || 0 == ret)
return 0;
mcGetInfo(1, 0, &dummy, &dummy, &dummy);
mcSync(0, NULL, &ret);
if (-1 == ret || 0 == ret)
return 1;
return -11;
}
//---------------------------------------------------------------------------
unsigned long hextoul(char *string)
{
unsigned long value;
char c;
value = 0;
while (!(((c = *string++) < '0') || (c > 'F') || ((c > '9') && (c < 'A'))))
value = value * 16 + ((c > '9') ? (c - 'A' + 10) : (c - '0'));
return value;
}
//---------------------------------------------------------------------------
//storeSkinCNF will save most cosmetic settings to a RAM area
//------------------------------
static size_t storeSkinCNF(char *cnf_buf)
{
size_t CNF_size;
sprintf(cnf_buf,
"GUI_Col_1_ABGR = %08X\r\n"
"GUI_Col_2_ABGR = %08X\r\n"
"GUI_Col_3_ABGR = %08X\r\n"
"GUI_Col_4_ABGR = %08X\r\n"
"GUI_Col_5_ABGR = %08X\r\n"
"GUI_Col_6_ABGR = %08X\r\n"
"GUI_Col_7_ABGR = %08X\r\n"
"GUI_Col_8_ABGR = %08X\r\n"
"SKIN_FILE = %s\r\n"
"GUI_SKIN_FILE = %s\r\n"
"SKIN_Brightness = %d\r\n"
"TV_mode = %d\r\n"
"Screen_Offset_X = %d\r\n"
"Screen_Offset_Y = %d\r\n"
"Popup_Opaque = %d\r\n"
"Menu_Frame = %d\r\n"
"Show_Menu = %d\r\n"
"%n", // %n causes NO output, but only a measurement
(u32)setting->color[COLOR_BACKGR], //Col_1
(u32)setting->color[COLOR_FRAME], //Col_2
(u32)setting->color[COLOR_SELECT], //Col_3
(u32)setting->color[COLOR_TEXT], //Col_4
(u32)setting->color[COLOR_GRAPH1], //Col_5
(u32)setting->color[COLOR_GRAPH2], //Col_6
(u32)setting->color[COLOR_GRAPH3], //Col_7
(u32)setting->color[COLOR_GRAPH4], //Col_8
setting->skin, //SKIN_FILE
setting->GUI_skin, //GUI_SKIN_FILE
setting->Brightness, //SKIN_Brightness
setting->TV_mode, //TV_mode
setting->screen_x, //Screen_X
setting->screen_y, //Screen_Y
setting->Popup_Opaque, //Popup_Opaque
setting->Menu_Frame, //Menu_Frame
setting->Show_Menu, //Show_Menu
&CNF_size // This variable measures the size of sprintf data
);
return CNF_size;
}
//------------------------------
//endfunc storeSkinCNF
//---------------------------------------------------------------------------
//saveSkinCNF will save most cosmetic settings to a skin CNF file
//------------------------------
static int saveSkinCNF(char *CNF)
{
int ret, fd;
char tmp[26 * MAX_PATH + 30 * MAX_PATH];
char cnf_path[MAX_PATH];
size_t CNF_size;
CNF_size = storeSkinCNF(tmp);
ret = genFixPath(CNF, cnf_path);
if ((ret < 0) || ((fd = genOpen(cnf_path, O_CREAT | O_WRONLY | O_TRUNC)) < 0)) {
return -1; //Failed open
}
ret = genWrite(fd, &tmp, CNF_size);
if (ret != CNF_size)
ret = -2; //Failed writing
genClose(fd);
return ret;
}
//-----------------------------
//endfunc saveSkinCNF
//---------------------------------------------------------------------------
//saveSkinBrowser will save most cosmetic settings to browsed skin CNF file
//------------------------------
static void saveSkinBrowser(void)
{
int tst;
char path[MAX_PATH];
char tmp[MAX_PATH];
char *p;
tst = getFilePath(path, SAVE_CNF);
if (path[0] == '\0')
goto abort;
if (!strncmp(path, "cdfs", 4))
goto abort;
drawMsg(LNG(Enter_File_Name));
tmp[0] = 0;
if (tst > 0) { //if an existing file was selected, use its name
p = strrchr(path, '/'); //find separator between path and name
if (p != NULL) {
strcpy(tmp, p + 1);
p[1] = '\0';
} else //if we got a pathname without separator, something is wrong
goto abort;
}
if ((tst >= 0) && (keyboard(tmp, 36) > 0))
strcat(path, tmp);
else {
abort:
tst = -3;
goto test;
}
tst = saveSkinCNF(path);
test:
switch (tst) {
case -1:
sprintf(tmp, "%s \"%s\".", LNG(Failed_To_Save), path);
break;
case -2:
sprintf(tmp, "%s \"%s\".", LNG(Failed_writing), path);
break;
case -3:
sprintf(tmp, "%s \"%s\".", LNG(Failed_Saving_File), path);
break;
default:
sprintf(tmp, "%s \"%s\".", LNG(Saved), path);
}
drawMsg(tmp);
}
//-----------------------------
//endfunc saveSkinBrowser
//---------------------------------------------------------------------------
//preloadCNF loads an entire CNF file into RAM it allocates
//------------------------------
char *preloadCNF(char *path)
{
int fd, tst;
size_t CNF_size;
char cnf_path[MAX_PATH];
char *RAM_p;
fd = -1;
if ((tst = genFixPath(path, cnf_path)) >= 0)
fd = genOpen(cnf_path, O_RDONLY);
if (fd < 0) {
failed_load:
return NULL;
}
CNF_size = genLseek(fd, 0, SEEK_END);
printf("CNF_size=%d\n", CNF_size);
genLseek(fd, 0, SEEK_SET);
RAM_p = (char *)memalign(64, CNF_size);
if (RAM_p == NULL) {
genClose(fd);
goto failed_load;
}
genRead(fd, RAM_p, CNF_size); //Read CNF as one long string
genClose(fd);
RAM_p[CNF_size] = '\0'; //Terminate the CNF string
return RAM_p;
}
//------------------------------
//endfunc preloadCNF
//---------------------------------------------------------------------------
//scanSkinCNF will check for most cosmetic variables of a CNF
//------------------------------
int scanSkinCNF(char *name, char *value)
{
if (!strcmp(name, "GUI_Col_1_ABGR"))
setting->color[COLOR_BACKGR] = hextoul(value);
else if (!strcmp(name, "GUI_Col_2_ABGR"))
setting->color[COLOR_FRAME] = hextoul(value);
else if (!strcmp(name, "GUI_Col_3_ABGR"))
setting->color[COLOR_SELECT] = hextoul(value);
else if (!strcmp(name, "GUI_Col_4_ABGR"))
setting->color[COLOR_TEXT] = hextoul(value);
else if (!strcmp(name, "GUI_Col_5_ABGR"))
setting->color[COLOR_GRAPH1] = hextoul(value);
else if (!strcmp(name, "GUI_Col_6_ABGR"))
setting->color[COLOR_GRAPH2] = hextoul(value);
else if (!strcmp(name, "GUI_Col_7_ABGR"))
setting->color[COLOR_GRAPH3] = hextoul(value);
else if (!strcmp(name, "GUI_Col_8_ABGR"))
setting->color[COLOR_GRAPH4] = hextoul(value);
//----------
else if (!strcmp(name, "SKIN_FILE"))
strcpy(setting->skin, value);
else if (!strcmp(name, "GUI_SKIN_FILE"))
strcpy(setting->GUI_skin, value);
else if (!strcmp(name, "SKIN_Brightness"))
setting->Brightness = atoi(value);
//----------
else if (!strcmp(name, "TV_mode"))
setting->TV_mode = atoi(value);
else if (!strcmp(name, "Screen_Offset_X"))
setting->screen_x = atoi(value);
else if (!strcmp(name, "Screen_Offset_Y"))
setting->screen_y = atoi(value);
//----------
else if (!strcmp(name, "Popup_Opaque"))
setting->Popup_Opaque = atoi(value);
else if (!strcmp(name, "Menu_Frame"))
setting->Menu_Frame = atoi(value);
else if (!strcmp(name, "Show_Menu"))
setting->Show_Menu = atoi(value);
else
return 0; //when no skin variable
return 1; //when skin variable found
}
//------------------------------
//endfunc scanSkinCNF
//---------------------------------------------------------------------------
//loadSkinCNF will load most cosmetic settings from CNF file
//------------------------------
int loadSkinCNF(char *path)
{
int var_cnt;
char *RAM_p, *CNF_p, *name, *value;
if (!(RAM_p = preloadCNF(path)))
return -1;
CNF_p = RAM_p;
for (var_cnt = 0; get_CNF_string(&CNF_p, &name, &value); var_cnt++)
scanSkinCNF(name, value);
free(RAM_p);
updateScreenMode();
if (setting->skin)
loadSkin(BACKGROUND_PIC, 0, 0);
return 0;
}
//------------------------------
//endfunc loadSkinCNF
//---------------------------------------------------------------------------
//loadSkinBrowser will load most cosmetic settings from browsed skin CNF file
//------------------------------
void loadSkinBrowser(void)
{
int tst;
char path[MAX_PATH];
char mess[MAX_PATH];
getFilePath(path, TEXT_CNF); // No Filtering, Be Careful.
tst = loadSkinCNF(path);
if (tst < 0)
sprintf(mess, "%s \"%s\".", LNG(Failed_To_Load), path);
else
sprintf(mess, "%s \"%s\".", LNG(Loaded_Config), path);
drawMsg(mess);
}
//------------------------------
//endfunc loadSkinBrowser
//---------------------------------------------------------------------------
// Save LAUNCHELF.CNF (or LAUNCHELFx.CNF with multiple pages)
// sincro: ADD save USBD_FILE string
// polo: ADD save SKIN_FILE string
// suloku: ADD save MAIN_SKIN string //dlanor: changed to GUI_SKIN_FILE
//---------------------------------------------------------------------------
void saveConfig(char *mainMsg, char *CNF)
{
int i, ret, fd;
char c[MAX_PATH], tmp[26 * MAX_PATH + 30 * MAX_PATH];
char cnf_path[MAX_PATH];
size_t CNF_size, CNF_step;
sprintf(tmp, "CNF_version = 3\r\n%n", &CNF_size); //Start CNF with version header
for (i = 0; i < SETTING_LK_COUNT; i++) { //Loop to save the ELF paths for launch keys
if ((i <= SETTING_LK_SELECT) || (setting->LK_Flag[i] != 0)) {
sprintf(tmp + CNF_size,
"LK_%s_E1 = %s\r\n"
"%n", // %n causes NO output, but only a measurement
LK_ID[i],
setting->LK_Path[i],
&CNF_step // This variable measures the size of sprintf data
);
CNF_size += CNF_step;
}
} //ends for
i = strlen(setting->Misc);
sprintf(tmp + CNF_size,
"Misc = %s\r\n"
"Misc_PS2Disc = %s\r\n"
"Misc_FileBrowser = %s\r\n"
"Misc_PS2Browser = %s\r\n"
"Misc_PS2Net = %s\r\n"
"Misc_PS2PowerOff = %s\r\n"
"Misc_HddManager = %s\r\n"
"Misc_TextEditor = %s\r\n"
"Misc_JpgViewer = %s\r\n"
"Misc_Configure = %s\r\n"
"Misc_Load_CNFprev = %s\r\n"
"Misc_Load_CNFnext = %s\r\n"
"Misc_Set_CNF_Path = %s\r\n"
"Misc_Load_CNF = %s\r\n"
"Misc_ShowFont = %s\r\n"
"Misc_Debug_Info = %s\r\n"
"Misc_About_uLE = %s\r\n"
"Misc_OSDSYS = %s\r\n"
"%n", // %n causes NO output, but only a measurement
setting->Misc,
setting->Misc_PS2Disc + i,
setting->Misc_FileBrowser + i,
setting->Misc_PS2Browser + i,
setting->Misc_PS2Net + i,
setting->Misc_PS2PowerOff + i,
setting->Misc_HddManager + i,
setting->Misc_TextEditor + i,
setting->Misc_JpgViewer + i,
setting->Misc_Configure + i,
setting->Misc_Load_CNFprev + i,
setting->Misc_Load_CNFnext + i,
setting->Misc_Set_CNF_Path + i,
setting->Misc_Load_CNF + i,
setting->Misc_ShowFont + i,
setting->Misc_Debug_Info + i,
setting->Misc_About_uLE + i,
setting->Misc_OSDSYS + i,
&CNF_step // This variable measures the size of sprintf data
);
CNF_size += CNF_step;
CNF_size += storeSkinCNF(tmp + CNF_size);
sprintf(tmp + CNF_size,
"LK_auto_Timer = %d\r\n"
"Menu_Hide_Paths = %d\r\n"
"Menu_Pages = %d\r\n"
"GUI_Swap_Keys = %d\r\n"
"USBD_FILE = %s\r\n"
"Menu_Title = %s\r\n"
"Init_Delay = %d\r\n"
"USBKBD_USED = %d\r\n"
"USBKBD_FILE = %s\r\n"
"KBDMAP_FILE = %s\r\n"
"Menu_Show_Titles = %d\r\n"
"PathPad_Lock = %d\r\n"
"CNF_Path = %s\r\n"
"USBMASS_FILE = %s\r\n"
"LANG_FILE = %s\r\n"
"FONT_FILE = %s\r\n"
"JpgView_Timer = %d\r\n"
"JpgView_Trans = %d\r\n"
"JpgView_Full = %d\r\n"
"PSU_HugeNames = %d\r\n"
"PSU_DateNames = %d\r\n"
"PSU_NoOverwrite = %d\r\n"
"FB_NoIcons = %d\r\n"
"%n", // %n causes NO output, but only a measurement
setting->timeout, //auto_Timer
setting->Hide_Paths, //Menu_Hide_Paths
setting->numCNF, //Menu_Pages
setting->swapKeys, //GUI_Swap_Keys
setting->usbd_file, //USBD_FILE
setting->Menu_Title, //Menu_Title
setting->Init_Delay, //Init_Delay
setting->usbkbd_used, //USBKBD_USED
setting->usbkbd_file, //USBKBD_FILE
setting->kbdmap_file, //KBDMAP_FILE
setting->Show_Titles, //Menu_Show_Titles
setting->PathPad_Lock, //PathPad_Lock
setting->CNF_Path, //CNF_Path
setting->usbmass_file, //USBMASS_FILE
setting->lang_file, //LANG_FILE
setting->font_file, //FONT_FILE
setting->JpgView_Timer, //JpgView_Timer
setting->JpgView_Trans, //JpgView_Trans
setting->JpgView_Full, //JpgView_Full
setting->PSU_HugeNames, //PSU_HugeNames
setting->PSU_DateNames, //PSU_DateNames
setting->PSU_NoOverwrite, //PSU_NoOverwrite
setting->FB_NoIcons, //FB_NoIcons
&CNF_step // This variable measures the size of sprintf data
);
CNF_size += CNF_step;
for (i = 0; i < SETTING_LK_BTN_COUNT; i++) { //Loop to save user defined launch key titles
if (setting->LK_Title[i][0]) { //Only save non-empty strings
sprintf(tmp + CNF_size,
"LK_%s_Title = %s\r\n"
"%n", // %n causes NO output, but only a measurement
LK_ID[i],
setting->LK_Title[i],
&CNF_step // This variable measures the size of sprintf data
);
CNF_size += CNF_step;
} //ends if
} //ends for
sprintf(tmp + CNF_size,
"PathPad_Lock = %d\r\n"
"%n", // %n causes NO output, but only a measurement
setting->PathPad_Lock, //PathPad_Lock
&CNF_step // This variable measures the size of sprintf data
);
CNF_size += CNF_step;
for (i = 0; i < MAX_PATH_PAD; i++) { //Loop to save non-empty PathPad entries
if (PathPad[i][0]) { //Only save non-empty strings
sprintf(tmp + CNF_size,
"PathPad[%02d] = %s\r\n"
"%n", // %n causes NO output, but only a measurement
i,
PathPad[i],
&CNF_step // This variable measures the size of sprintf data
);
CNF_size += CNF_step;
} //ends if
} //ends for
strcpy(c, LaunchElfDir);
strcat(c, CNF);
ret = genFixPath(c, cnf_path);
if ((ret >= 0) && ((fd = genOpen(cnf_path, O_RDONLY)) >= 0))
genClose(fd);
else { //Start of clause for failure to use LaunchElfDir
if (setting->CNF_Path[0] == 0) { //if NO CNF Path override defined
if (!strncmp(LaunchElfDir, "mc", 2))
sprintf(c, "mc%d:/SYS-CONF", LaunchElfDir[2] - '0');
else
sprintf(c, "mc%d:/SYS-CONF", CheckMC());
if ((fd = fileXioDopen(c)) >= 0) {
fileXioDclose(fd);
char strtmp[MAX_PATH] = "/";
strcat(c, strcat(strtmp, CNF));
} else {
strcpy(c, LaunchElfDir);
strcat(c, CNF);
}
}
} //End of clause for failure to use LaunchElfDir
ret = genFixPath(c, cnf_path);
if ((ret < 0) || ((fd = genOpen(cnf_path, O_CREAT | O_WRONLY | O_TRUNC)) < 0)) {
sprintf(c, "mc%d:/SYS-CONF", CheckMC());
if ((fd = fileXioDopen(c)) >= 0) {
fileXioDclose(fd);
char strtmp[MAX_PATH] = "/";
strcat(c, strcat(strtmp, CNF));
} else {
strcpy(c, LaunchElfDir);
strcat(c, CNF);
}
ret = genFixPath(c, cnf_path);
if ((fd = genOpen(cnf_path, O_CREAT | O_WRONLY | O_TRUNC)) < 0) {
sprintf(mainMsg, "%s %s", LNG(Failed_To_Save), CNF);
return;
}
}
ret = genWrite(fd, &tmp, CNF_size);
if (ret == CNF_size)
sprintf(mainMsg, "%s (%s)", LNG(Saved_Config), c);
else
sprintf(mainMsg, "%s (%s)", LNG(Failed_writing), CNF);
genClose(fd);
}
//---------------------------------------------------------------------------
void initConfig(void)
{
int i;
if (setting != NULL)
free(setting);
setting = (SETTING *)malloc(sizeof(SETTING));
sprintf(setting->Misc, "%s/", LNG_DEF(MISC));
sprintf(setting->Misc_PS2Disc, "%s/%s", LNG_DEF(MISC), LNG_DEF(PS2Disc));
sprintf(setting->Misc_FileBrowser, "%s/%s", LNG_DEF(MISC), LNG_DEF(FileBrowser));
sprintf(setting->Misc_PS2Browser, "%s/%s", LNG_DEF(MISC), LNG_DEF(PS2Browser));
sprintf(setting->Misc_PS2Net, "%s/%s", LNG_DEF(MISC), LNG_DEF(PS2Net));
sprintf(setting->Misc_PS2PowerOff, "%s/%s", LNG_DEF(MISC), LNG_DEF(PS2PowerOff));
sprintf(setting->Misc_HddManager, "%s/%s", LNG_DEF(MISC), LNG_DEF(HddManager));
sprintf(setting->Misc_TextEditor, "%s/%s", LNG_DEF(MISC), LNG_DEF(TextEditor));
sprintf(setting->Misc_JpgViewer, "%s/%s", LNG_DEF(MISC), LNG_DEF(JpgViewer));
sprintf(setting->Misc_Configure, "%s/%s", LNG_DEF(MISC), LNG_DEF(Configure));
sprintf(setting->Misc_Load_CNFprev, "%s/%s", LNG_DEF(MISC), LNG_DEF(Load_CNFprev));
sprintf(setting->Misc_Load_CNFnext, "%s/%s", LNG_DEF(MISC), LNG_DEF(Load_CNFnext));
sprintf(setting->Misc_Set_CNF_Path, "%s/%s", LNG_DEF(MISC), LNG_DEF(Set_CNF_Path));
sprintf(setting->Misc_Load_CNF, "%s/%s", LNG_DEF(MISC), LNG_DEF(Load_CNF));
sprintf(setting->Misc_ShowFont, "%s/%s", LNG_DEF(MISC), LNG_DEF(ShowFont));
sprintf(setting->Misc_Debug_Info, "%s/%s", LNG_DEF(MISC), LNG_DEF(Debug_Info));
sprintf(setting->Misc_About_uLE, "%s/%s", LNG_DEF(MISC), LNG_DEF(About_uLE));
sprintf(setting->Misc_OSDSYS, "%s/%s", LNG_DEF(MISC), LNG_DEF(OSDSYS));
for (i = 0; i < SETTING_LK_COUNT; i++) {
setting->LK_Path[i][0] = 0;
setting->LK_Title[i][0] = 0;
setting->LK_Flag[i] = 0;
}
for (i = 0; i < MAX_PATH_PAD; i++)
PathPad[i][0] = 0;
strcpy(setting->LK_Path[SETTING_LK_CIRCLE], setting->Misc_FileBrowser);
setting->LK_Flag[SETTING_LK_CIRCLE] = 1;
strcpy(setting->LK_Path[SETTING_LK_TRIANGLE], setting->Misc_About_uLE);
setting->LK_Flag[SETTING_LK_TRIANGLE] = 1;
setting->usbd_file[0] = '\0';
setting->usbmass_file[0] = '\0';
setting->usbkbd_file[0] = '\0';
setting->kbdmap_file[0] = '\0';
setting->skin[0] = '\0';
setting->GUI_skin[0] = '\0';
setting->Menu_Title[0] = '\0';
setting->CNF_Path[0] = '\0';
setting->lang_file[0] = '\0';
setting->font_file[0] = '\0';
setting->timeout = DEF_TIMEOUT;
setting->Hide_Paths = DEF_HIDE_PATHS;
setting->color[COLOR_BACKGR] = DEF_COLOR1;
setting->color[COLOR_FRAME] = DEF_COLOR2;
setting->color[COLOR_SELECT] = DEF_COLOR3;
setting->color[COLOR_TEXT] = DEF_COLOR4;
setting->color[COLOR_GRAPH1] = DEF_COLOR5;
setting->color[COLOR_GRAPH2] = DEF_COLOR6;
setting->color[COLOR_GRAPH3] = DEF_COLOR7;
setting->color[COLOR_GRAPH4] = DEF_COLOR8;
setting->screen_x = 0;
setting->screen_y = 0;
setting->Menu_Frame = DEF_MENU_FRAME;
setting->Show_Menu = DEF_MENU;
setting->numCNF = DEF_NUMCNF;
setting->swapKeys = DEF_SWAPKEYS;
setting->Brightness = DEF_BRIGHT;
setting->TV_mode = TV_mode_AUTO;
setting->Popup_Opaque = DEF_POPUP_OPAQUE;
setting->Init_Delay = DEF_INIT_DELAY;
setting->usbkbd_used = DEF_USBKBD_USED;
setting->Show_Titles = DEF_SHOW_TITLES;
setting->PathPad_Lock = DEF_PATHPAD_LOCK;
setting->JpgView_Timer = -1; //only used to detect missing variable
setting->JpgView_Trans = -1; //only used to detect missing variable
setting->JpgView_Full = DEF_JPGVIEW_FULL;
setting->PSU_HugeNames = DEF_PSU_HUGENAMES;
setting->PSU_DateNames = DEF_PSU_DATENAMES;
setting->PSU_NoOverwrite = DEF_PSU_NOOVERWRITE;
setting->FB_NoIcons = DEF_FB_NOICONS;
}
//------------------------------
//endfunc initConfig
//---------------------------------------------------------------------------
// Load LAUNCHELF.CNF (or LAUNCHELFx.CNF with multiple pages)
// sincro: ADD load USBD_FILE string
// polo: ADD load SKIN_FILE string
// suloku: ADD load MAIN_SKIN string //dlanor: changed to GUI_SKIN_FILE
// dlanor: added error flag return value 0==OK, -1==failure
//---------------------------------------------------------------------------
int loadConfig(char *mainMsg, char *CNF)
{
int i, fd, tst, len, mcport, var_cnt, CNF_version;
char tsts[20];
char path[MAX_PATH];
char cnf_path[MAX_PATH];
char *RAM_p, *CNF_p, *name, *value;
initConfig();
strcpy(path, LaunchElfDir);
strcat(path, CNF);
if (!strncmp(path, "cdrom", 5))
strcat(path, ";1");
fd = -1;
if ((tst = genFixPath(path, cnf_path)) >= 0)
fd = genOpen(cnf_path, O_RDONLY);
if (fd < 0) {
char strtmp[MAX_PATH], *p;
int pos;
p = strrchr(path, '.'); //make p point to extension
if (*(p - 1) != 'F') //is this an indexed CNF
p--; //then make p point to index
pos = (p - path);
strcpy(strtmp, path);
strcpy(strtmp + pos - 9, "LNCHELF"); //Replace LAUNCHELF with LNCHELF (for CD)
strcpy(strtmp + pos - 2, path + pos); //Add index+extension too
if ((tst = genFixPath(strtmp, cnf_path)) >= 0)
fd = genOpen(cnf_path, O_RDONLY);
if (fd < 0) {
if (!strncmp(LaunchElfDir, "mc", 2))
mcport = LaunchElfDir[2] - '0';
else
mcport = CheckMC();
if (mcport == 1 || mcport == 0) {
sprintf(strtmp, "mc%d:/SYS-CONF/", mcport);
strcpy(cnf_path, strtmp);
strcat(cnf_path, CNF);
fd = genOpen(cnf_path, O_RDONLY);
if (fd >= 0)
strcpy(LaunchElfDir, strtmp);
}
}
}
if (fd < 0) {
failed_load:
sprintf(mainMsg, "%s %s", LNG(Failed_To_Load), CNF);
return -1;
}
// This point is only reached after succefully opening CNF
genClose(fd);
if ((RAM_p = preloadCNF(cnf_path)) == NULL)
goto failed_load;
CNF_p = RAM_p;
//RA NB: in the code below, the 'LK_' variables have been implemented such that
// any _Ex suffix will be accepted, with identical results. This will need
// to be modified when more execution methods are implemented.
CNF_version = 0; // The CNF version is still unidentified
for (var_cnt = 0; get_CNF_string(&CNF_p, &name, &value); var_cnt++) { // A variable was found, now we dispose of its value.
if (!strcmp(name, "CNF_version")) {
CNF_version = atoi(value);
continue;
} else if (CNF_version == 0)
goto failed_load; // Refuse unidentified CNF
if (scanSkinCNF(name, value))
continue;
for (i = 0; i < SETTING_LK_COUNT; i++) {
sprintf(tsts, "LK_%s_E%n", LK_ID[i], &len);
if (!strncmp(name, tsts, len)) {
strcpy(setting->LK_Path[i], value);
setting->LK_Flag[i] = 1;
break;
}
}
if (i < SETTING_LK_COUNT)
continue;
//----------
//In the next group, the Misc device must be defined before its subprograms
//----------
else if (!strcmp(name, "Misc"))
sprintf(setting->Misc, "%s/", value);
else if (!strcmp(name, "Misc_PS2Disc"))
sprintf(setting->Misc_PS2Disc, "%s%s", setting->Misc, value);
else if (!strcmp(name, "Misc_FileBrowser"))
sprintf(setting->Misc_FileBrowser, "%s%s", setting->Misc, value);
else if (!strcmp(name, "Misc_PS2Browser"))
sprintf(setting->Misc_PS2Browser, "%s%s", setting->Misc, value);
else if (!strcmp(name, "Misc_PS2Net"))
sprintf(setting->Misc_PS2Net, "%s%s", setting->Misc, value);
else if (!strcmp(name, "Misc_PS2PowerOff"))
sprintf(setting->Misc_PS2PowerOff, "%s%s", setting->Misc, value);
else if (!strcmp(name, "Misc_HddManager"))
sprintf(setting->Misc_HddManager, "%s%s", setting->Misc, value);
else if (!strcmp(name, "Misc_TextEditor"))
sprintf(setting->Misc_TextEditor, "%s%s", setting->Misc, value);
else if (!strcmp(name, "Misc_JpgViewer"))
sprintf(setting->Misc_JpgViewer, "%s%s", setting->Misc, value);
else if (!strcmp(name, "Misc_Configure"))
sprintf(setting->Misc_Configure, "%s%s", setting->Misc, value);
else if (!strcmp(name, "Misc_Load_CNFprev"))
sprintf(setting->Misc_Load_CNFprev, "%s%s", setting->Misc, value);
else if (!strcmp(name, "Misc_Load_CNFnext"))
sprintf(setting->Misc_Load_CNFnext, "%s%s", setting->Misc, value);
else if (!strcmp(name, "Misc_Set_CNF_Path"))
sprintf(setting->Misc_Set_CNF_Path, "%s%s", setting->Misc, value);
else if (!strcmp(name, "Misc_Load_CNF"))
sprintf(setting->Misc_Load_CNF, "%s%s", setting->Misc, value);
else if (!strcmp(name, "Misc_ShowFont"))
sprintf(setting->Misc_ShowFont, "%s%s", setting->Misc, value);
else if (!strcmp(name, "Misc_Debug_Info"))
sprintf(setting->Misc_Debug_Info, "%s%s", setting->Misc, value);
else if (!strcmp(name, "Misc_About_uLE"))
sprintf(setting->Misc_About_uLE, "%s%s", setting->Misc, value);
else if (!strcmp(name, "Misc_OSDSYS"))
sprintf(setting->Misc_OSDSYS, "%s%s", setting->Misc, value);
//----------
else if (!strcmp(name, "LK_auto_Timer"))
setting->timeout = atoi(value);
else if (!strcmp(name, "Menu_Hide_Paths"))
setting->Hide_Paths = atoi(value);
//---------- NB: color settings moved to scanSkinCNF
else if (!strcmp(name, "Menu_Pages"))
setting->numCNF = atoi(value);
else if (!strcmp(name, "GUI_Swap_Keys"))
setting->swapKeys = atoi(value);
else if (!strcmp(name, "USBD_FILE"))
strcpy(setting->usbd_file, value);
else if (!strcmp(name, "Menu_Title")) {
strncpy(setting->Menu_Title, value, MAX_MENU_TITLE);
setting->Menu_Title[MAX_MENU_TITLE] = '\0';
} else if (!strcmp(name, "Init_Delay"))
setting->Init_Delay = atoi(value);
else if (!strcmp(name, "USBKBD_USED"))
setting->usbkbd_used = atoi(value);
else if (!strcmp(name, "USBKBD_FILE"))
strcpy(setting->usbkbd_file, value);
else if (!strcmp(name, "KBDMAP_FILE"))
strcpy(setting->kbdmap_file, value);
else if (!strcmp(name, "Menu_Show_Titles"))
setting->Show_Titles = atoi(value);
else if (!strcmp(name, "PathPad_Lock"))
setting->PathPad_Lock = atoi(value);
else if (!strcmp(name, "CNF_Path"))
strcpy(setting->CNF_Path, value);
else if (!strcmp(name, "USBMASS_FILE"))
strcpy(setting->usbmass_file, value);
else if (!strcmp(name, "LANG_FILE"))
strcpy(setting->lang_file, value);
else if (!strcmp(name, "FONT_FILE"))
strcpy(setting->font_file, value);
//----------
else if (!strcmp(name, "JpgView_Timer"))
setting->JpgView_Timer = atoi(value);
else if (!strcmp(name, "JpgView_Trans"))
setting->JpgView_Trans = atoi(value);
else if (!strcmp(name, "JpgView_Full"))
setting->JpgView_Full = atoi(value);
//----------
else if (!strcmp(name, "PSU_HugeNames"))
setting->PSU_HugeNames = atoi(value);
else if (!strcmp(name, "PSU_DateNames"))
setting->PSU_DateNames = atoi(value);
else if (!strcmp(name, "PSU_NoOverwrite"))
setting->PSU_NoOverwrite = atoi(value);
else if (!strcmp(name, "FB_NoIcons"))
setting->FB_NoIcons = atoi(value);
//----------
else {
for (i = 0; i < SETTING_LK_BTN_COUNT; i++) {
sprintf(tsts, "LK_%s_Title", LK_ID[i]);
if (!strcmp(name, tsts)) {
strncpy(setting->LK_Title[i], value, MAX_ELF_TITLE - 1);
break;
}
}
if (i < SETTING_LK_BTN_COUNT)
continue;
else if (!strncmp(name, "PathPad[", 8)) {
i = atoi(name + 8);
if (i < MAX_PATH_PAD) {
strncpy(PathPad[i], value, MAX_PATH - 1);
PathPad[i][MAX_PATH - 1] = '\0';
}
}
}
} //ends for
for (i = 0; i < SETTING_LK_BTN_COUNT; i++)
setting->LK_Title[i][MAX_ELF_TITLE - 1] = 0;
free(RAM_p);
if (setting->JpgView_Timer < 0)
setting->JpgView_Timer = DEF_JPGVIEW_TIMER;
if ((setting->JpgView_Trans < 1) || (setting->JpgView_Trans > 4))
setting->JpgView_Trans = DEF_JPGVIEW_TRANS;
sprintf(mainMsg, "%s (%s)", LNG(Loaded_Config), path);
return 0;
}
//------------------------------
//endfunc loadConfig
//---------------------------------------------------------------------------
// Polo: ADD Skin Menu with Skin preview
// suloku: ADD Main skin selection
//---------------------------------------------------------------------------
enum CONFIG_SKIN {
CONFIG_SKIN_FIRST = 1,
CONFIG_SKIN_PATH = CONFIG_SKIN_FIRST,
CONFIG_SKIN_APPLY,
CONFIG_SKIN_BRIGHTNESS,
CONFIG_SKIN_GUI_PATH,
CONFIG_SKIN_GUI_APPLY,
CONFIG_SKIN_GUI_SHOW_MENU,
CONFIG_SKIN_RETURN,
CONFIG_SKIN_COUNT,
};
static void Config_Skin(void)
{
int s, max_s = CONFIG_SKIN_COUNT - 1;
int x, y;
int len;
int event, post_event = 0;
char c[MAX_PATH];
char skinSave[MAX_PATH], GUI_Save[MAX_PATH];
int Brightness = setting->Brightness;
int current_preview = 0;
strcpy(skinSave, setting->skin);
strcpy(GUI_Save, setting->GUI_skin);
loadSkin(PREVIEW_PIC, 0, 0);
current_preview = PREVIEW_PIC;
s = CONFIG_SKIN_FIRST;
event = 1; //event = initial entry
while (1) {
//Pad response section
waitPadReady(0, 0);
if (readpad()) {
if (new_pad & PAD_UP) {
event |= 2; //event |= valid pad command
if (s != CONFIG_SKIN_FIRST)
s--;
else
s = max_s;
} else if (new_pad & PAD_DOWN) {
event |= 2; //event |= valid pad command
if (s != max_s)
s++;
else
s = CONFIG_SKIN_FIRST;
} else if (new_pad & PAD_LEFT) {
event |= 2; //event |= valid pad command
if (s != CONFIG_SKIN_FIRST)
s = CONFIG_SKIN_FIRST;
else
s = max_s;
} else if (new_pad & PAD_RIGHT) {
event |= 2; //event |= valid pad command
if (s != max_s)
s = max_s;
else
s = CONFIG_SKIN_FIRST;
} else if ((!swapKeys && new_pad & PAD_CROSS) || (swapKeys && new_pad & PAD_CIRCLE)) {
event |= 2; //event |= valid pad command
if (s == CONFIG_SKIN_PATH) { //Command == Cancel Skin Path
setting->skin[0] = '\0';
loadSkin(PREVIEW_PIC, 0, 0);
current_preview = PREVIEW_PIC;
} else if (s == CONFIG_SKIN_BRIGHTNESS) { //Command == Decrease Brightness
if ((Brightness > 0) && (testsetskin == 1)) {
Brightness--;
}
} else if (s == CONFIG_SKIN_GUI_PATH) { //Command == Cancel GUI Skin Path
setting->GUI_skin[0] = '\0';
loadSkin(PREVIEW_GUI, 0, 0);
current_preview = PREVIEW_GUI;
}
} else if ((swapKeys && new_pad & PAD_CROSS) || (!swapKeys && new_pad & PAD_CIRCLE)) {
event |= 2; //event |= valid pad command
if (s == CONFIG_SKIN_PATH) { //Command == Set Skin Path
getFilePath(setting->skin, SKIN_CNF);
loadSkin(PREVIEW_PIC, 0, 0);
current_preview = PREVIEW_PIC;
} else if (s == CONFIG_SKIN_APPLY) { //Command == Apply New Skin
GUI_active = 0;
loadSkin(BACKGROUND_PIC, 0, 0);
setting->Brightness = Brightness;
strcpy(skinSave, setting->skin);
loadSkin(PREVIEW_PIC, 0, 0);
current_preview = PREVIEW_PIC;
} else if (s == CONFIG_SKIN_BRIGHTNESS) { //Command == Increase Brightness
if ((Brightness < 100) && (testsetskin == 1)) {
Brightness++;
}
} else if (s == CONFIG_SKIN_GUI_PATH) { //Command == Set GUI Skin Path
getFilePath(setting->GUI_skin, GUI_SKIN_CNF);
loadSkin(PREVIEW_GUI, 0, 0);
current_preview = PREVIEW_GUI;
} else if (s == CONFIG_SKIN_GUI_APPLY) { //Command == Apply GUI Skin
strcpy(GUI_Save, setting->GUI_skin);