forked from NeeeeB/GameList_Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathF_Main.pas
4059 lines (3548 loc) · 140 KB
/
F_Main.pas
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
unit F_Main;
interface
uses
Winapi.Windows, Winapi.Messages, Winapi.ShellAPI,
System.SysUtils, System.Variants, System.Classes, System.IniFiles, System.Generics.Collections,
System.RegularExpressions, System.UITypes, System.ImageList, System.StrUtils, System.IOUtils,
System.SyncObjs,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Styles, Vcl.Themes, Vcl.ImgList,
Vcl.ExtCtrls, Vcl.Imaging.pngimage, Vcl.Imaging.jpeg, Vcl.Menus, Vcl.ComCtrls, Vcl.StdCtrls,
Xml.omnixmldom, Xml.xmldom, Xml.XMLIntf, Xml.XMLDoc, Xml.Win.msxmldom,
F_MoreInfos, F_About, F_Help, F_ConfigureSSH, U_gnugettext, U_Resources, U_Game,
F_ConfigureNetwork, F_AdvNameEditor, U_DownloadThread,
IdURI,
Vcl.OleCtrls, WMPLib_TLB, System.Net.URLClient,
System.Net.HttpClient, System.Net.HttpClientComponent;
type
TMediaInfo = class
FileExt: string;
FileLink: string;
end;
TFrm_Editor = class(TForm)
Pnl_Background: TPanel;
Pgc_Editor: TPageControl;
Tbs_Main: TTabSheet;
Tbs_Scrape: TTabSheet;
Lbl_NbGamesFound: TLabel;
Lbl_SelectSystem: TLabel;
Lbl_Filter: TLabel;
Img_Logo: TImage;
Img_System: TImage;
Lbl_Name: TLabel;
Lbl_Region: TLabel;
Lbl_Date: TLabel;
Lbl_Players: TLabel;
Lbl_Rating: TLabel;
Lbl_KidGame: TLabel;
Lbl_Hidden: TLabel;
Lbl_Favorite: TLabel;
Lbl_Publisher: TLabel;
Lbl_Developer: TLabel;
Lbl_Genre: TLabel;
Lbl_Description: TLabel;
Lbl_Search: TLabel;
Cbx_Systems: TComboBox;
Lbx_Games: TListBox;
Mmo_Description: TMemo;
Edt_Rating: TEdit;
Edt_ReleaseDate: TEdit;
Edt_Developer: TEdit;
Edt_Publisher: TEdit;
Edt_Genre: TEdit;
Edt_NbPlayers: TEdit;
Edt_Name: TEdit;
Btn_SaveChanges: TButton;
Btn_ChangeImage: TButton;
Btn_SetDefaultPicture: TButton;
Btn_ChangeAll: TButton;
Cbx_Filter: TComboBox;
Edt_Region: TEdit;
Btn_MoreInfos: TButton;
Btn_Delete: TButton;
ProgressBar: TProgressBar;
Btn_RemovePicture: TButton;
Cbx_KidGame: TComboBox;
Cbx_Hidden: TComboBox;
Cbx_Favorite: TComboBox;
Edt_RomPath: TEdit;
Edt_Search: TEdit;
Chk_ListByRom: TCheckBox;
Chk_FullRomName: TCheckBox;
XMLDoc: TXMLDocument;
OpenDialog: TFileOpenDialog;
MainMenu: TMainMenu;
Mnu_File: TMenuItem;
Mnu_Choosefolder: TMenuItem;
Mnu_Quit: TMenuItem;
Mnu_Actions: TMenuItem;
Mnu_System: TMenuItem;
Mnu_LowerCase: TMenuItem;
Mnu_UpperCase: TMenuItem;
Mnu_RemoveRegion: TMenuItem;
Mnu_DeleteOrphans: TMenuItem;
Mnu_DeleteDuplicates: TMenuItem;
Mnu_ExportTxt: TMenuItem;
Mnu_Game: TMenuItem;
Mnu_GaLowerCase: TMenuItem;
Mnu_GaUpperCase: TMenuItem;
Mnu_Selection: TMenuItem;
Mnu_SetHidden: TMenuItem;
Mnu_SetNoHidden: TMenuItem;
Mnu_SetFavorite: TMenuItem;
Mnu_SetNoFavorite: TMenuItem;
Mnu_NameEditor: TMenuItem;
Mnu_Options: TMenuItem;
Mnu_General: TMenuItem;
Mnu_GodMode: TMenuItem;
Mnu_DeleteWoPrompt: TMenuItem;
Mnu_AutoHash: TMenuItem;
Mnu_PiPrompts: TMenuItem;
Mnu_ShowTips: TMenuItem;
Mnu_Genesis: TMenuItem;
N3: TMenuItem;
Mnu_NetWork: TMenuItem;
Mnu_ConfigureNetwork: TMenuItem;
N2: TMenuItem;
Mnu_SSH: TMenuItem;
Mnu_ConfigSSH: TMenuItem;
N1: TMenuItem;
Mnu_Theme: TMenuItem;
Mnu_Theme1: TMenuItem;
Mnu_Theme2: TMenuItem;
Mnu_Theme3: TMenuItem;
Mnu_Theme4: TMenuItem;
Mnu_Theme5: TMenuItem;
Mnu_Theme6: TMenuItem;
Mnu_Theme9: TMenuItem;
Mnu_Theme10: TMenuItem;
Mnu_Theme11: TMenuItem;
Mnu_Theme12: TMenuItem;
Mnu_Theme13: TMenuItem;
Mnu_Theme15: TMenuItem;
Mnu_Theme16: TMenuItem;
Mnu_Theme17: TMenuItem;
N4: TMenuItem;
Mnu_Language: TMenuItem;
Mnu_Lang1: TMenuItem;
Mnu_Lang2: TMenuItem;
Mnu_Lang3: TMenuItem;
Mnu_Lang4: TMenuItem;
Mnu_Lang5: TMenuItem;
Mnu_Help: TMenuItem;
Mnu_About: TMenuItem;
OpenFile: TOpenDialog;
Img_List: TImageList;
SaveDialog: TSaveDialog;
Pnl_Top: TPanel;
Scl_Pictures: TScrollBox;
Img_ScreenScraper: TImage;
Btn_Scrape: TButton;
Img_Loading: TImage;
Mmo_ScrapeDescription: TMemo;
Lbl_ScrapeDescription: TLabel;
Lbl_ScrapeGenre: TLabel;
Edt_ScrapeGenre: TEdit;
Lbl_ScrapeDeveloper: TLabel;
Edt_ScrapeDeveloper: TEdit;
Lbl_ScrapePublisher: TLabel;
Edt_ScrapePublisher: TEdit;
Lbl_ScrapeRating: TLabel;
Edt_ScrapeRating: TEdit;
Lbl_ScrapePlayers: TLabel;
Edt_ScrapePlayers: TEdit;
Lbl_ScrapeDate: TLabel;
Edt_ScrapeDate: TEdit;
Edt_ScrapeRegion: TEdit;
Lbl_ScrapeRegion: TLabel;
Edt_ScrapeName: TEdit;
Lbl_ScrapeName: TLabel;
Img_ScrapeBackground: TImage;
Img_Scrape: TImage;
Btn_ScrapeSave: TButton;
Edt_ScrapeRomPath: TEdit;
Btn_ScrapeLower: TButton;
Btn_ScrapeUpper: TButton;
Chk_ScrapePicture: TCheckBox;
Chk_ScrapeVideo: TCheckBox;
Chk_ScrapeInfos: TCheckBox;
Chk_ManualCRC: TCheckBox;
Edt_ManualCRC: TEdit;
Chk_Box2D: TCheckBox;
Chk_Box3D: TCheckBox;
Chk_Mix1: TCheckBox;
Chk_Mix2: TCheckBox;
Chk_Screenshot: TCheckBox;
Chk_Title: TCheckBox;
Chk_ArcadeBox: TCheckBox;
Chk_Wheel: TCheckBox;
Chk_Video: TCheckBox;
Mnu_Reload: TMenuItem;
Pgc_Media: TPageControl;
Tbs_Picture: TTabSheet;
Tbs_Video: TTabSheet;
Img_Game: TImage;
Img_BackGround: TImage;
Btn_ChangeVideo: TButton;
Btn_RemoveVideo: TButton;
Img_BackgroundVideo: TImage;
Net_HTTPClient: TNetHTTPClient;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Cbx_SystemsChange(Sender: TObject);
procedure Lbx_GamesClick(Sender: TObject);
procedure Mnu_QuitClick(Sender: TObject);
procedure Mnu_ChoosefolderClick(Sender: TObject);
procedure Btn_SaveChangesClick(Sender: TObject);
procedure FieldChange(Sender: TObject);
procedure Mmo_DescriptionKeyPress(Sender: TObject; var Key: Char);
procedure Btn_ChangeImageClick(Sender: TObject);
procedure Btn_SetDefaultPictureClick(Sender: TObject);
procedure Cbx_FilterChange(Sender: TObject);
procedure Btn_ChangeAllClick(Sender: TObject);
procedure Btn_MoreInfosClick(Sender: TObject);
procedure Mnu_GodModeClick(Sender: TObject);
procedure Mnu_AutoHashClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Btn_DeleteClick(Sender: TObject);
procedure Mnu_DeleteWoPromptClick(Sender: TObject);
procedure ChangeCaseClick(Sender: TObject);
procedure ChangeCaseGameClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Btn_RemovePictureClick(Sender: TObject);
procedure Mnu_AboutClick(Sender: TObject);
procedure Mnu_RemoveRegionClick(Sender: TObject);
procedure Mnu_ThemeClick(Sender: TObject);
procedure Mnu_GenesisClick(Sender: TObject);
procedure Mnu_HelpClick(Sender: TObject);
procedure Mnu_ShowTipsClick(Sender: TObject);
procedure Mnu_PiPromptsClick(Sender: TObject);
procedure Mnu_ConfigSSHClick(Sender: TObject);
procedure Mnu_LangClick(Sender: TObject);
procedure Edt_SearchChange(Sender: TObject);
procedure Mnu_DeleteOrphansClick(Sender: TObject);
procedure Mnu_DeleteDuplicatesClick(Sender: TObject);
procedure Btn_ScrapeClick(Sender: TObject);
procedure Mnu_ConfigureNetworkClick(Sender: TObject);
procedure Mnu_SetHiddenClick(Sender: TObject);
procedure Mnu_SetNoHiddenClick(Sender: TObject);
procedure Mnu_SetFavoriteClick(Sender: TObject);
procedure Mnu_SetNoFavoriteClick(Sender: TObject);
procedure Chk_ListByRomClick(Sender: TObject);
procedure Mnu_NameEditorClick(Sender: TObject);
procedure Mnu_ExportTxtClick(Sender: TObject);
procedure Chk_FullRomNameClick(Sender: TObject);
procedure Tbs_ScrapeShow(Sender: TObject);
procedure Tbs_ScrapeHide(Sender: TObject);
procedure FormMouseWheelDown(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
procedure FormMouseWheelUp(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
procedure ImgScrapedClick(Sender: TObject);
procedure Btn_ScrapeSaveClick(Sender: TObject);
procedure Btn_ScrapeUpperClick(Sender: TObject);
procedure Btn_ScrapeLowerClick(Sender: TObject);
procedure Chk_ScrapeClick(Sender: TObject);
procedure Chk_ManualCRCClick(Sender: TObject);
procedure Mnu_ReloadClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Pgc_MediaChange(Sender: TObject);
procedure Btn_ChangeVideoClick(Sender: TObject);
procedure Btn_RemoveVideoClick(Sender: TObject);
private
FThemeNumber, FLanguage: Integer;
FRootPath: string;
FCurrentFolder: string;
FImageFolder: string;
FVideoFolder: string;
FVideoScrapeLink: string;
FIsLoading: Boolean;
FGodMode, FAutoHash, FDelWoPrompt, FGenesisLogo,
FShowTips, FFolderIsOnPi, FPiPrompts, FSysIsRecal,
FPiLoadedOnce: Boolean;
FRecalLogin, FRecalPwd, FRetroLogin, FRetroPwd: string;
FSSLogin, FSSPwd: string;
FScrapedGame: TGame;
FIsWine: Boolean;
GSystemList: TObjectDictionary<string,TObjectList<TGame>>;
Wmp_Video: TWindowsMediaPlayer;
FPrevWinControl: TWinControl;
//Pour le scrape
FPictureLinks: TObjectList<TMediaInfo>;
FInfosList: TStringList;
FMaxThreads, FThreadCount, FStartCount: Integer;
FTempXmlPath: string;
procedure LoadFromIni;
procedure SaveToIni;
procedure BuildSystemsList( aReload : Boolean = False );
procedure LoadGamesList( const aSystem: string );
procedure LoadGame( aGame: TGame );
procedure ClearAllFields;
procedure SaveBatchChangesToGamelist;
procedure SaveChangesToGamelist( aScrape, aSaveVideo, aSavePic, aSaveInfos: Boolean );
procedure EnableControls( aValue: Boolean );
procedure EnableComponents( aValue: Boolean );
procedure CheckIfChangesToSave;
procedure ChangeImage( const aPath: string; aGame: TGame );
procedure ChangeVideo( const aPath: string; aGame: TGame );
procedure LoadSystemLogo( const aPictureName: string );
procedure DeleteGame( aGame: TGame; reloadGameList: Boolean = True );
procedure DeleteGamePicture;
procedure DeleteGameVideo;
procedure StartGameVideo( const aPath: string );
procedure StopGameVideo;
procedure CheckMenuItem( aNumber: Integer; aLang: Boolean = False );
procedure RemoveRegionFromGameName( aGame: TGame; aStartPos: Integer );
procedure ConvertFieldsCase( aGame: TGame; aUnique: Boolean = False;
aUp: Boolean = False );
procedure StopOrStartES( aStop, aRecal: Boolean );
procedure DeleteDuplicates( const aSystem: string );
procedure ReloadIni;
procedure SetFavOrHidden( aFav, aValue: Boolean );
procedure TransformGamesNames( aRemChars, aAddChars, aChangecase: Boolean;
aNbStart, aNbEnd, aCaseIndex: Integer;
const aStringStart, aStringEnd : string );
procedure ExportToTxt;
procedure CreateWindowsMediaPlayer;
function IsRunningUnderWine: Boolean;
function getSystemKind: TSystemKind;
function getCurrentFolderName: string;
function GetCurrentLogoName: string;
function GetCurrentSystemId: string;
function GetCountryEnum( const aShortName: string ): TCountryName;
function BuildGamesList( const aPathToFile: string ): TObjectList<TGame>;
function FormatDateFromString( const aDate: string; aIso: Boolean = False ): string;
function GetThemeEnum( aNumber: Integer ): TThemeName;
function GetLangEnum( aNumber: Integer ): TLangName;
function GetPhysicalRomPath( const aRomPath: string ): string;
function GetPhysicalMediaPath( const aPath: string ): string;
function MyMessageDlg( const Msg: string; DlgTypt: TmsgDlgType; button: TMsgDlgButtons;
Caption: array of string; dlgcaption: string ): Integer;
//Méthodes relatives à l'onglet de scrape
procedure ClearScrapeMedia;
procedure ParseXml;
procedure DisplayPictures;
procedure FillFields;
procedure EnableScrapeComponents( aValue: Boolean );
procedure GetPictures;
procedure GetPicture( aMedia: TMediaInfo );
procedure ThreadTerminated( Sender: TObject );
procedure EmptyScrapeFields;
procedure ConvertScrapeToUpOrLow( aUp: Boolean = False );
procedure UpdateVideo( aGame: TGame );
procedure SaveLinkToFile( aLink, aPath: string );
function GetGameXml( const aSysId: string; aGame: TGame ): Boolean;
function GetFileSize( const aPath: string ): string;
public
FProxyServer, FProxyUser,
FProxyPwd, FProxyPort: string;
FProxyUse: Boolean;
FImgList: TObjectList<TImage>;
procedure WarnUser( const aMessage: string );
procedure WarnUserWithSafeUrl( const aMessage, aMessage2, aUrl: string );
function SetFocusedControl( Control: TWinControl ): Boolean; override;
end;
var
Frm_Editor: TFrm_Editor;
//lock pour le compteur de threads (empêche l'accés concurrent)
CounterGuard: TCriticalSection;
implementation
{$R *.dfm}
function TFrm_Editor.IsRunningUnderWine: Boolean;
var
Handle: THandle;
begin
Handle := GetModuleHandle('ntdll.dll');
Result := (Handle <> 0) and (GetProcAddress(Handle, 'wine_get_version') <> nil);
end;
function TFrm_Editor.SetFocusedControl(Control: TWinControl): Boolean;
begin
if ( Control = Btn_SaveChanges ) and ( ActiveControl is TEdit ) then
FPrevWinControl := ActiveControl;
Result:= inherited SetFocusedControl(Control);
end;
function TFrm_Editor.GetPhysicalRomPath( const aRomPath: string ): string;
begin
Result:= FRootPath + FCurrentFolder + aRomPath;
Result:= StringReplace( Result, '/', '\', [rfReplaceAll] );
end;
function TFrm_Editor.GetPhysicalMediaPath( const aPath: string ): string;
begin
if aPath.IsEmpty then Result:= ''
else begin
Result:= FRootPath + FCurrentFolder + aPath;
Result:= StringReplace( Result, '/', '\', [rfReplaceAll] );
end;
end;
//Formate correctement la date depuis la string récupérée du xml
//ou renvoie une date format Iso pour sauvegarde selon l'appel (aIso)
function TFrm_Editor.FormatDateFromString( const aDate: string; aIso: Boolean = False ): string;
var
FullStr, Day, Month, Year: string;
DayInt, MonthInt, YearInt: Integer;
begin
FullStr:= aDate;
Result:= '';
//si on formate pour affichage et que la chaine passée
//répond au critère
if ( not aIso ) and ( FullStr.Contains( Cst_DateSuffix ) ) then begin
SetLength( FullStr, 8 );
Day:= Copy( FullStr, 7, 2 );
Month:= Copy( FullStr, 5, 2 );
Year:= Copy( FullStr, 1, 4 );
if ( TryStrToInt( Day, DayInt ) ) and ( DayInt > 0 ) then
Result:= Result + Day + '/';
if ( TryStrToInt( Month, MonthInt ) ) and ( MonthInt > 0 ) then
Result:= Result + Month + '/';
if ( TryStrToInt( Year, YearInt ) ) and ( YearInt > 0 ) then
Result:= Result + Year;
//sinon si on formate pour enregistrement dans le .xml
//et que la chaine ne contient que des chiffres ou /
end else if aIso and ( TRegEx.IsMatch( FullStr, '^[0-9]' ) ) then begin
//si la chaine fait 4 caractères de long
if ( Length( FullStr) = 4 ) then
Result:= FullStr + Cst_DateLongFill + Cst_DateSuffix;
//si la chaine fait 7 caractères de long
if ( Length( FullStr) = 7 ) then begin
Month:= Copy( FullStr, 1, 2 );
Year:= Copy( FullStr, 4, 4 );
Result:= Year + Month + Cst_DateShortFill + Cst_DateSuffix;
end;
//si la chaine fait 10 caractères de long
if ( Length( FullStr) = 10 ) then begin
Day:= Copy( FullStr, 1, 2 );
Month:= Copy( FullStr, 4, 2 );
Year:= Copy( FullStr, 7, 4 );
Result:= Year + Month + Day + Cst_DateSuffix;
end;
end;
end;
//Construction d'une messagedlg custom (pour pouvoir traduire les boutons)
function TFrm_Editor.MyMessageDlg(const Msg: string; DlgTypt: TmsgDlgType; button: TMsgDlgButtons;
Caption: array of string; dlgcaption: string ): Integer;
var
aMsgdlg: TForm;
ii: Integer;
Dlgbutton: Tbutton;
Captionindex: Integer;
begin
aMsgdlg := CreateMessageDialog( Msg, DlgTypt, button );
aMsgdlg.Caption := dlgcaption;
aMsgdlg.BiDiMode := bdLeftToRight;
Captionindex := 0;
for ii:= 0 to Pred( aMsgdlg.ComponentCount ) do begin
if (aMsgdlg.components[ii] is Tbutton) then Begin
Dlgbutton:= Tbutton( aMsgdlg.Components[ii] );
if ( Captionindex <= High( Caption ) ) then
Dlgbutton.Caption:= Caption[Captionindex];
Inc( Captionindex );
end;
end;
Result:= aMsgdlg.Showmodal;
end;
//Chargement des paramètres depuis le fichier INI
procedure TFrm_Editor.LoadFromIni;
var
FileIni: TIniFile;
begin
FileIni:= TIniFile.Create( ExtractFilePath( Application.ExeName ) + Cst_IniFilePath );
try
//On tent de lire les fichier ini, si on ne trouve pas on met tout à false par défaut
FGodMode:= FileIni.ReadBool( Cst_IniOptions, Cst_IniGodMode, False );
Mnu_GodMode.Checked:= FGodMode;
Mnu_DeleteWoPrompt.Enabled:= FGodMode;
Btn_Delete.Visible:= FGodMode;
FAutoHash:= FileIni.ReadBool( Cst_IniOptions, Cst_IniAutoHash, False );
Mnu_AutoHash.Checked:= FAutoHash;
FDelWoPrompt:= FileIni.ReadBool( Cst_IniOptions, Cst_IniDelWoPrompt, False );
Mnu_DeleteWoPrompt.Checked:= FDelWoPrompt;
FPiPrompts:= FileIni.ReadBool( Cst_IniOptions, Cst_IniPiPrompts, False );
Mnu_PiPrompts.Checked:= FPiPrompts;
FGenesisLogo:= FileIni.ReadBool( Cst_IniOptions, Cst_IniGenesisLogo, False );
Mnu_Genesis.Checked:= FGenesisLogo;
FShowTips:= FileIni.ReadBool( Cst_IniOptions, Cst_ShowTips, True );
Mnu_ShowTips.Checked:= FShowTips;
FThemeNumber:= FileIni.ReadInteger( Cst_IniOptions, Cst_ThemeNumber, 5 );
FLanguage:= FileIni.ReadInteger( Cst_IniOptions, Cst_IniLanguage, 0 );
FRecalLogin:= FileIni.ReadString( Cst_IniOptions, Cst_IniRecalLogin, Cst_RecalLogin);
FRecalPwd:= FileIni.ReadString( Cst_IniOptions, Cst_IniRecalPwd, Cst_RecalPwd);
FRetroLogin:= FileIni.ReadString( Cst_IniOptions, Cst_IniRetroLogin, Cst_RetroLogin);
FRetroPwd:= FileIni.ReadString( Cst_IniOptions, Cst_IniRetroPwd, Cst_RetroPwd);
FSSLogin:= FileIni.ReadString( Cst_IniOptions, Cst_IniSSUser, '');
FSSPwd:= FileIni.ReadString( Cst_IniOptions, Cst_IniSSPwd, '');
FProxyUser:= FileIni.ReadString( Cst_IniOptions, Cst_IniProxyUser, '');
FProxyPwd:= FileIni.ReadString( Cst_IniOptions, Cst_IniProxyPwd, '');
FProxyServer:= FileIni.ReadString( Cst_IniOptions, Cst_IniProxyServer, '');
FProxyPort:= FileIni.ReadString( Cst_IniOptions, Cst_IniProxyPort, '0');
FProxyUse:= FileIni.ReadBool( Cst_IniOptions, Cst_IniProxyUse, False);
finally
FileIni.Free;
end;
end;
//Enregistrement des paramètres dans le fichier INI
procedure TFrm_Editor.SaveToIni;
var
FileIni: TIniFile;
begin
FileIni:= TIniFile.Create( ExtractFilePath( Application.ExeName ) + Cst_IniFilePath );
try
FileIni.WriteBool( Cst_IniOptions, Cst_IniGodMode, FGodMode );
FileIni.WriteBool( Cst_IniOptions, Cst_IniAutoHash, FAutoHash );
FileIni.WriteBool( Cst_IniOptions, Cst_IniDelWoPrompt, ( FGodMode and FDelWoPrompt ) );
FileIni.WriteBool( Cst_IniOptions, Cst_IniGenesisLogo, FGenesisLogo );
FileIni.WriteBool( Cst_IniOptions, Cst_ShowTips, FShowTips );
FileIni.WriteBool( Cst_IniOptions, Cst_IniPiPrompts, FPiPrompts );
FileIni.WriteInteger( Cst_IniOptions, Cst_ThemeNumber, FThemeNumber );
FileIni.WriteInteger( Cst_IniOptions, Cst_IniLanguage, FLanguage );
FileIni.WriteString( Cst_IniOptions, Cst_IniRecalLogin, FRecalLogin);
FileIni.WriteString( Cst_IniOptions, Cst_IniRecalPwd, FRecalPwd);
FileIni.WriteString( Cst_IniOptions, Cst_IniRetroLogin, FRetroLogin);
FileIni.WriteString( Cst_IniOptions, Cst_IniRetroPwd, FRetroPwd);
FileIni.WriteString( Cst_IniOptions, Cst_IniSSUser, FSSLogin);
FileIni.WriteString( Cst_IniOptions, Cst_IniSSPwd, FSSPwd);
FileIni.WriteString( Cst_IniOptions, Cst_IniProxyUser, FProxyUser);
FileIni.WriteString( Cst_IniOptions, Cst_IniProxyPwd, FProxyPwd);
FileIni.WriteString( Cst_IniOptions, Cst_IniProxyServer, FProxyServer);
if ( FProxyPort.IsEmpty ) then FileIni.WriteString( Cst_IniOptions, Cst_IniProxyPort, '0' )
else FileIni.WriteString( Cst_IniOptions, Cst_IniProxyPort, FProxyPort );
FileIni.WriteBool( Cst_IniOptions, Cst_IniProxyUse, FProxyUse);
finally
FileIni.Free;
end;
end;
//Recup l'enum du theme en fonction de l'entier du fichier ini
function TFrm_Editor.GetThemeEnum( aNumber: Integer ): TThemeName;
var
_ThemeName: TThemeName;
begin
Result:= tnCharcoalDarkSlate;
for _ThemeName:= Low( TThemeName )to High( TThemeName ) do begin
if ( aNumber = Ord( _ThemeName ) ) then begin
Result:= _ThemeName;
Break;
end;
end;
end;
//Recup de l'enum de la langue en fonction de l'entier du fichier ini
function TFrm_Editor.GetLangEnum( aNumber: Integer ): TLangName;
var
_LangName: TLangName;
begin
Result:= lnEnglish;
for _LangName:= Low( TLangName ) to High( TLangName ) do begin
if ( aNumber = Ord( _LangName ) ) then begin
Result:= _LangName;
Break;
end;
end;
end;
//Recup l'énum du pays (région) du jeu scrapé
function TFrm_Editor.GetCountryEnum( const aShortName: string ): TCountryName;
var
_CountryName: TCountryName;
begin
Result:= cnUnd;
for _CountryName:= Low( TCountryName ) to High( TCountryName ) do begin
if ( aShortName = Cst_CountryName[_CountryName] ) then begin
Result:= _CountryName;
Break;
end;
end;
end;
//A l'ouverture du programme
procedure TFrm_Editor.FormCreate(Sender: TObject);
begin
FIsWine := IsRunningUnderWine;
CreateWindowsMediaPlayer;
TranslateComponent( Self );
FImgList:= TObjectList<TImage>.Create;
FInfosList:= TStringList.Create( True );
FPictureLinks:= TObjectList<TMediaInfo>.Create;
Lbl_NbGamesFound.Caption:= '';
GSystemList:= TObjectDictionary<string, TObjectList<TGame>>.Create([doOwnsValues]);
LoadFromIni;
TStyleManager.TrySetStyle( Cst_ThemeNameStr[GetThemeEnum( FThemeNumber )] );
FPiLoadedOnce:= False;
FTempXmlPath:= ExtractFilePath( Application.ExeName ) + Cst_TempXml;
CounterGuard:= TCriticalSection.Create;
end;
procedure TFrm_Editor.CreateWindowsMediaPlayer;
begin
if not FIsWine then
begin
try
Wmp_Video := TWindowsMediaPlayer.Create(Self);
with Wmp_Video do
begin
Top := 0;
Left := 0;
Height := 812;
Width := 612;
TabOrder := 0;
uiMode := 'none';
enableContextMenu := False;
autoSize := False;
stretchToFit := True;
align := alClient;
Visible := false;
Parent := Tbs_Video;
SetBounds(Left, Top, Width, Height);
end;
except
on E: Exception do
ShowMessage('Error creating Windows Media Player: ' + E.Message);
end;
end;
end;
//Met le focus sur le combo system à l'affichage de la fenêtre
procedure TFrm_Editor.FormShow(Sender: TObject);
var
Frm_Help: TFrm_Help;
begin
UseLanguage( Cst_LangNameStr[GetLangEnum( FLanguage )] );
RetranslateComponent( Self );
CheckMenuItem( Succ( FThemeNumber ) );
CheckMenuItem( Succ( FLanguage ), True );
if FShowTips then begin
//Affiche la fenêtre "Help"
Frm_Help:= TFrm_Help.Create(nil);
try
FShowTips:= Frm_Help.Execute( not FShowTips );
finally
Frm_Help.Free;
end;
end;
Tbs_Scrape.TabVisible:= False;
Mnu_ShowTips.Checked:= FShowTips;
Lbx_Games.SetFocus;
end;
//Pour checker le menuitem du numéro de thème ou langue récupéré depuis le fichier ini
procedure TFrm_Editor.CheckMenuItem( aNumber: Integer; aLang: Boolean = False );
var
_MenuItem: TMenuItem;
_CompName: string;
begin
if aLang then _CompName:= Cst_MenuLang + IntToStr( aNumber )
else _CompName:= Cst_MenuTheme + IntToStr( aNumber );
_MenuItem:= ( FindComponent( _CompName ) as TMenuItem ) ;
_MenuItem.Checked:= True;
end;
//Action au click sur le menuitem "choose folder"
procedure TFrm_Editor.Mnu_ChoosefolderClick(Sender: TObject);
begin
Img_BackGround.Visible:= True;
EnableControls( False );
Edt_Search.Enabled:= False;
Lbl_Search.Enabled:= False;
ClearAllFields;
Lbx_Games.Items.Clear;
BuildSystemsList;
Btn_SaveChanges.Enabled:= False;
end;
//Action au click sur menuitem "Reload Systems"
procedure TFrm_Editor.Mnu_ReloadClick(Sender: TObject);
begin
Img_BackGround.Visible:= True;
EnableControls( False );
Edt_Search.Enabled:= False;
Lbl_Search.Enabled:= False;
ClearAllFields;
Lbx_Games.Items.Clear;
BuildSystemsList( True );
Btn_SaveChanges.Enabled:= False;
end;
//permet d'éxecuter la ligne de commande qui stop/start Emulation Station
//utilisé si on accède aux gamelist directement sur le Pi sinon les modifs ne
//sont pas prises en compte. Utilise le petit utilitaire plink.exe
procedure TFrm_Editor.StopOrStartES( aStop, aRecal: Boolean );
var
_PathToPlink: string;
begin
_PathToPlink:= ExtractFilePath( Application.ExeName ) + Cst_ResourcesFolder;
if aStop then begin
if aRecal then
ShellExecute( 0, nil, 'cmd.exe', PChar( Cst_PlinkCommand + FRecalLogin +
Cst_PlinkCommandRecal + FRecalPwd +
Cst_PlinkCommandStop ), PChar( _PathToPlink ), SW_HIDE )
else
ShellExecute( 0, nil, 'cmd.exe', PChar( Cst_PlinkCommand + FRetroLogin +
Cst_PlinkCommandRetro + FRetroPwd +
Cst_PlinkCommandStop ), PChar( _PathToPlink ), SW_HIDE );
end else begin
if aRecal then
ShellExecute( 0, nil, 'cmd.exe', PChar( Cst_PlinkCommand + FRecalLogin +
Cst_PlinkCommandRecal + FRecalPwd +
Cst_PlinkCommandStart ), PChar( _PathToPlink ), SW_HIDE )
else
ShellExecute( 0, nil, 'cmd.exe', PChar( Cst_PlinkCommand + FRetroLogin +
Cst_PlinkCommandRetro + FRetroPwd +
Cst_PlinkCommandStart ), PChar( _PathToPlink ), SW_HIDE )
end;
end;
//Construction de la liste des systèmes trouvés (et des listes de jeux associées)
procedure TFrm_Editor.BuildSystemsList( aReload : Boolean = False );
var
_GameListPath: string;
Info: TSearchRec;
IsFound: Boolean;
ValidFolderCount: Integer;
TmpList: TObjectList<TGame>;
_system: TSystemKindObject;
begin
//on met à vide le chemin de base et le logo systeme
//FRootPath:= '';
Img_System.Picture.Graphic:= nil;
//On vide le combobox des systèmes
//Et on désactive les Controls non nécessaires
Cbx_Systems.Items.Clear;
Cbx_Systems.Enabled:= False;
Cbx_Filter.Enabled:= False;
Lbl_SelectSystem.Enabled:= False;
Lbl_Filter.Enabled:= False;
Lbl_NbGamesFound.Caption:= '';
Btn_ChangeAll.Enabled:= False;
Cbx_KidGame.ItemIndex:= -1;
Cbx_Hidden.ItemIndex:= -1;
Cbx_Favorite.ItemIndex:= -1;
Edt_Search.Text:= '';
//On vide la liste globale des systèmes (cas 2eme ouverture)
GSystemList.Clear;
//On met le compteur de dossiers valides à 0
ValidFolderCount:= 0;
//On sélectionne le dossier parent où se trouvent les dossiers de systèmes
if ( not aReload ) then begin
Mnu_Reload.Enabled:= False;
if ( OpenDialog.Execute ) then
//On récupère le chemin vers le dossier parent
FRootPath:= IncludeTrailingPathDelimiter( OpenDialog.FileName )
else
Exit;
end;
//On check si le dossier n'est pas vide
IsFound:= ( FindFirst( FRootPath + '*.*', faAnyFile, Info) = 0 );
//Si le dossier est vide : message utilisateur
if not IsFound then begin
ShowMessage( Rst_WrongFolder );
Exit;
end;
//On boucle sur les dossiers trouvés pour les lister
while IsFound do begin
//Si le dossier trouvé ne commence pas par un . et qu'il contient
//bien un fichier gamelist.xml alors on crée la liste de jeux
if ( (Info.Attr and faDirectory) <> 0 ) and
( Info.Name[1] <> '.' ) and
( FileExists( FRootPath + IncludeTrailingPathDelimiter( Info.Name ) +
Cst_GameListFileName ) ) then begin
//on chope le nom du dossier en cours pour construire les chemins
FCurrentFolder:= IncludeTrailingPathDelimiter( Info.Name );
//Ici on récupère le chemin vers le fichier gamelist.xml
_GameListPath:= FRootPath + FCurrentFolder + Cst_GameListFileName;
//On tente de construire la liste des jeux depuis le .xml
TmpList:= BuildGamesList( _GameListPath );
//Si la liste n'est pas vide, on traite, sinon on zappe
if Assigned( TmpList ) then begin
//On construit la liste des jeux du système
//et on joute le système à la liste globale de systèmes
GSystemList.Add( Info.Name, TmpList );
//On ajoute ensuite le nom du systeme au combobox des systemes trouvés
_system:= TSystemKindObject.Create( Info.Name );
if ( _system.FSystemKind = skOther ) then
Cbx_Systems.Items.AddObject( Info.Name, _system )
else if ( _system.FSystemKind = skMegaDrive ) and FGenesisLogo then
Cbx_Systems.Items.AddObject( Cst_SystemKindStr[skGenesis], _system )
else
Cbx_Systems.Items.AddObject( Cst_SystemKindStr[_system.FSystemKind], _system );
//On incrémente le compteur de dossier système valides
Inc( ValidFolderCount );
end;
end;
//Enfin, on passe au dossier suivant (s'il y en a un)
IsFound:= ( FindNext(Info) = 0 );
end;
FindClose(Info);
//Si le compteur de dossier valide est à zéro, message utilisateur
if ( ValidFolderCount = 0 ) then begin
ShowMessage( Rst_WrongFolder );
Screen.Cursor:= crDefault;
Exit;
//On active le Combobox des systemes si au moins un systeme a été trouvé
//Idem pour le listbox des jeux du systeme et on charge la liste du premier système
end else begin
//si le dossier sélectionné se trouve sur le Pi,
//on prévient l'utilisateur qu'on va stopper ES
FFolderIsOnPi:= FRootPath.StartsWith( Cst_Recalbox ) or
FRootPath.StartsWith( Cst_Retropie );
if FFolderIsOnPi and not FPiLoadedOnce then begin
FPiLoadedOnce:= True;
if not FPiPrompts then
MyMessageDlg( Rst_StopES, mtInformation, [mbOK], [Rst_Ok], Rst_Info );
if FRootPath.StartsWith( Cst_Recalbox ) then begin
StopOrStartES( True, True );
FSysIsRecal:= True;
end else begin
StopOrStartES( True, False );
FSysIsRecal:= False;
end;
end;
Cbx_Systems.Enabled:= True;
Lbl_SelectSystem.Enabled:= Cbx_Systems.Enabled;
Cbx_Filter.Enabled:= Cbx_Systems.Enabled;
Lbl_Filter.Enabled:= Cbx_Systems.Enabled;
Cbx_Systems.ItemIndex:= 0;
EnableControls( True );
Cbx_Filter.ItemIndex:= 0;
Edt_Search.Enabled:= True;
Lbl_Search.Enabled:= True;
LoadGamesList( getCurrentFolderName );
Mnu_Reload.Enabled:= True;
//On remet le curseur par défaut
Screen.Cursor:= crDefault;
end;
end;
//Construction de la liste des jeux (objets) pour un systeme donné
function TFrm_Editor.BuildGamesList( const aPathToFile: string ): TObjectList<TGame>;
//Permet de s'assurer que le noeud cherché existe, et si ce n'est pas le cas
//renvoie chaine vide, sinon renvoie la valeur texte du noeud
function GetNodeValue( aNode: IXMLNode; const aNodeName: string ): string;
begin
Result:= '';
if Assigned( aNode.ChildNodes.FindNode( aNodeName ) ) then
Result:= aNode.ChildNodes.Nodes[aNodeName].Text;
end;
var
_GameList: TObjectList<TGame>;
_Game: TGame;
_Node: IXmlNode;
begin
//on met le curseur sablier pour montrer que ça bosse.
Screen.Cursor:= crHourGlass;
//Initialisation à nil au cas où liste de jeux vide
Result:= nil;
//On ouvre et active le gamelist.xml pour le parcourir
XMLDoc.FileName:= aPathToFile;
XMLDoc.Active:= True;
//On cherche le premier "jeu"
_Node := XMLDoc.DocumentElement.ChildNodes.FindNode( Cst_Game );
//Si pas de jeu trouvé on sort et on renvoie nil
if not Assigned( _Node ) then Exit;
//On crée la liste d'objets TGame
_GameList:= TObjectList<TGame>.Create( True );
//Ensuite on boucle sur tous les jeux et pour chaque jeu
//on crée un objet TGame qu'on renseigne et ajoute à la _Gamelist
repeat
//On ne crée un "jeu" que si le noeud n'est pas vide.
if _Node.HasChildNodes then begin
//Création de l'objet TGame et passage des infos en argument
_Game:= TGame.Create( GetNodeValue( _Node, Cst_Path ),
GetNodeValue( _Node, Cst_Name ),
GetNodeValue( _Node,Cst_Description ),
GetNodeValue( _Node, Cst_ImageLink ),
GetNodeValue( _Node, Cst_VideoLink ),
GetNodeValue( _Node, Cst_Rating ),
GetNodeValue( _Node, Cst_Developer ),
GetNodeValue( _Node, Cst_Publisher ),
GetNodeValue( _Node, Cst_Genre ),
GetNodeValue( _Node, Cst_Players ),
FormatDateFromString( GetNodeValue( _Node, Cst_ReleaseDate ) ),
GetNodeValue( _Node, Cst_Region ),
GetNodeValue( _Node, Cst_Playcount ),
GetNodeValue( _Node, Cst_LastPlayed ),
GetNodeValue( _Node, Cst_KidGame ),
GetNodeValue( _Node, Cst_Hidden ),
GetNodeValue( _Node, Cst_Favorite ) );
_Game.PhysicalRomPath:= GetPhysicalRomPath( _Game.RomPath );
_Game.PhysicalImagePath:= GetPhysicalMediaPath( _Game.ImagePath );
_Game.PhysicalVideoPath:= GetPhysicalMediaPath( _Game.VideoPath );
_Game.IsOrphan:= not FileExists( _Game.PhysicalRomPath );
//On ajoute à la _Gamelist
_GameList.Add( _Game );
end;
//On passe au jeu suivant
_Node := _Node.NextSibling;
until ( _Node = nil );
XMLDoc.Active:= False;
Result:= _GameList;
end;
//Action à la sélection d'un filtre
procedure TFrm_Editor.Cbx_FilterChange(Sender: TObject);
begin
LoadGamesList( getCurrentFolderName );
end;
//Action à la sélection d'un item du combobox systemes
procedure TFrm_Editor.Cbx_SystemsChange(Sender: TObject);
begin
EmptyScrapeFields;
Edt_Search.Text:= '';
LoadGamesList( getCurrentFolderName );
end;
//quand on tape du texte dans le champ de recherche
procedure TFrm_Editor.Edt_SearchChange(Sender: TObject);
begin
LoadGamesList( getCurrentFolderName );
end;
//Je fais une procédure juste pour activer les controls
//pour pas se les retaper à chaque changement d'état
procedure TFrm_Editor.EnableControls( aValue: Boolean );
begin
Lbl_Name.Enabled:= aValue;
Lbl_Genre.Enabled:= aValue;
Lbl_Rating.Enabled:= aValue;
Lbl_Developer.Enabled:= aValue;
Lbl_Publisher.Enabled:= aValue;
Lbl_Players.Enabled:= aValue;
Lbl_Date.Enabled:= aValue;
Lbl_Description.Enabled:= aValue;
Lbl_Region.Enabled:= aValue;
Lbl_Hidden.Enabled:= aValue;
Lbl_Favorite.Enabled:= aValue;
Lbl_KidGame.Enabled:= aValue;
Btn_ChangeImage.Enabled:= aValue;
Btn_ChangeVideo.Enabled:= aValue;
Btn_Scrape.Enabled:= aValue;
Btn_RemovePicture.Enabled:= aValue;
Btn_RemoveVideo.Enabled:= aValue;
Btn_SetDefaultPicture.Enabled:= aValue;
Btn_MoreInfos.Enabled:= aValue;
Btn_Delete.Enabled:= aValue;
Mnu_System.Enabled:= aValue or not ( GSystemList.Count = 0 );