forked from NeeeeB/GameList_Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
U_Game.pas
211 lines (191 loc) · 7 KB
/
U_Game.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
unit U_Game;
interface
uses
System.StrUtils, System.Classes, System.SysUtils,
IdHashMessageDigest, IdHashSHA, IdHashCRC,
U_Resources;
type
//Objet stockant uniquement le type système (enum) pour
//combobox systems, permet de retrouver facile l'image et le nom du systeme
TSystemKindObject = class
public
FSystemKind: TSystemKind;
constructor Create( const aName: string );
end;
TGame = class
private
FRomPath: string;
FRomName: string;
FRomNameWoExt: string;
FImagePath: string;
FVideoPath: string;
FName: string;
FDescription: string;
FRating: string;
FReleaseDate: string;
FDeveloper: string;
FPublisher: string;
FGenre: string;
FPlayers: string;
FRegion: string;
FPlaycount: string;
FLastplayed: string;
FCrc32: string;
FMd5: string;
FSha1: string;
FKidGame: Integer;
FHidden: Integer;
FFavorite: Integer;
FIsOrphan: Boolean;
FPhysicalRomPath: string;
FPhysicalImagePath: string;
FPhysicalVideoPath: string;
procedure Load( aPath, aName, aDescription, aImagePath, aVideoPath,
aRating, aDeveloper, aPublisher, aGenre, aPlayers, aDate,
aRegion, aPlaycount, aLastplayed, aKidGame, aHidden, aFavorite: string );
function GetRomName( const aRomPath: string ): string;
public
constructor Create( aPath, aName, aDescription, aImagePath, aVideoPath,
aRating, aDeveloper, aPublisher, aGenre, aPlayers, aDate,
aRegion, aPlaycount, aLastplayed, aKidGame, aHidden, aFavorite: string ); reintroduce;
property RomPath: string read FRomPath write FRomPath;
property RomName: string read FRomName write FRomName;
property RomNameWoExt: string read FRomNameWoExt write FRomNameWoExt;
property ImagePath: string read FImagePath write FImagePath;
property VideoPath: string read FVideoPath write FVideoPath;
property Name: string read FName write FName;
property Description: string read FDescription write FDescription;
property Rating: string read FRating write FRating;
property ReleaseDate: string read FReleaseDate write FReleaseDate;
property Developer: string read FDeveloper write FDeveloper;
property Publisher: string read FPublisher write FPublisher;
property Genre: string read FGenre write FGenre;
property Players: string read FPlayers write FPlayers;
property Region: string read FRegion write FRegion;
property Playcount: string read FPlaycount write FPlaycount;
property Lastplayed: string read FLastplayed write FLastplayed;
property Crc32: string read FCrc32 write FCrc32;
property Md5: string read FMd5 write FMd5;
property Sha1: string read FSha1 write FSha1;
property KidGame: Integer read FKidGame write FKidGame;
property Hidden: Integer read FHidden write FHidden;
property Favorite: Integer read FFavorite write FFavorite;
property IsOrphan: Boolean read FIsOrphan write FIsOrphan;
property PhysicalRomPath: string read FPhysicalRomPath write FPhysicalRomPath;
property PhysicalImagePath: string read FPhysicalImagePath write FPhysicalImagePath;
property PhysicalVideoPath: string read FPhysicalVideoPath write FPhysicalVideoPath;
function CalculateMd5( const aFileName: string ): string;
function CalculateSha1( const aFileName: string ): string;
function CalculateCrc32( const aFileName: string ): string;
end;
implementation
//Constructeur object SystemKindObject
constructor TSystemKindObject.Create( const aName: string );
var
_systemKind: TSystemKind;
begin
FSystemKind:= skOther;
for _systemKind:= Low( TSystemKind )to High( _systemKind ) do begin
if ( Cst_SystemKindFolderNames[_systemKind] = aName ) then begin
FSystemKind:= _systemKind;
Break;
end;
end;
end;
//Constructeur de l'objet TGame
constructor TGame.Create( aPath, aName, aDescription, aImagePath, aVideoPath,
aRating, aDeveloper, aPublisher, aGenre, aPlayers, aDate,
aRegion, aPlaycount, aLastplayed, aKidGame, aHidden, aFavorite: string );
begin
Load( aPath, aName, aDescription, aImagePath, aVideoPath, aRating,
aDeveloper, aPublisher, aGenre, aPlayers, aDate, aRegion, aPlaycount,
aLastplayed, aKidGame, aHidden, aFavorite );
end;
//Chargement des attributs dans l'objet TGame
procedure TGame.Load( aPath, aName, aDescription, aImagePath, aVideoPath, aRating,
aDeveloper, aPublisher, aGenre, aPlayers, aDate,
aRegion, aPlaycount, aLastplayed, aKidGame, aHidden, aFavorite: string );
begin
FRomPath:= aPath;
FRomName:= GetRomName( aPath );
FRomNameWoExt:= ChangeFileExt( FRomName, '' );
FImagePath:= aImagePath;
FVideoPath:= aVideoPath;
FName:= aName;
FDescription:= aDescription;
FRating:= aRating;
FReleaseDate:= aDate;
FDeveloper:= aDeveloper;
FPublisher:= aPublisher;
FGenre:= aGenre;
FPlayers:= aPlayers;
FRegion:= aRegion;
FPlaycount:= aPlaycount;
FLastplayed:= aLastplayed;
if ( aKidGame = Cst_True ) then FKidGame:= 1
else FKidGame:= 0;
if ( aHidden = Cst_True ) then FHidden:= 1
else FHidden:= 0;
if ( aFavorite = Cst_True ) then FFavorite:= 1
else FFavorite:= 0;
end;
//Fonction permettant de récupérer le nom de la rom avec son extension
function TGame.GetRomName( const aRomPath: string ): string;
var
_Pos: Integer;
begin
_Pos:= LastDelimiter( '/', aRomPath );
Result:= Copy( aRomPath, Succ( _Pos ), ( aRomPath.Length - _Pos ) );
end;
//Fonction permettant de récupérer le MD5 des roms
function TGame.CalculateMd5( const aFileName: string ): string;
var
IdMD5: TIdHashMessageDigest5;
FS: TFileStream;
begin
if FileExists( aFileName ) then begin
IdMD5:= TIdHashMessageDigest5.Create;
FS:= TFileStream.Create( aFileName, fmOpenRead or fmShareDenyWrite );
try
Result:= IdMD5.HashStreamAsHex(FS)
finally
FS.Free;
IdMD5.Free;
end;
end;
end;
//fonction permettant de récupérer le SHA1 des roms
function TGame.CalculateSha1( const aFileName: string ): string;
var
IdSHA1: TIdHashSHA1;
FS: TFileStream;
begin
if FileExists( aFileName ) then begin
IdSHA1:= TIdHashSHA1.Create;
FS:= TFileStream.Create( aFileName, fmOpenRead or fmShareDenyWrite );
try
Result:= IdSHA1.HashStreamAsHex(FS)
finally
FS.Free;
IdSHA1.Free;
end;
end;
end;
//fonction permettant de récupérer le SHA1 des roms
function TGame.CalculateCrc32( const aFileName: string ): string;
var
IdCRC32: TIdHashCRC32;
FS: TFileStream;
begin
if FileExists( aFileName ) then begin
IdCRC32:= TIdHashCRC32.Create;
FS:= TFileStream.Create( aFileName, fmOpenRead or fmShareDenyWrite );
try
Result:= IdCRC32.HashStreamAsHex(FS)
finally
FS.Free;
IdCRC32.Free;
end;
end;
end;
end.