-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileChecker.pas
More file actions
58 lines (48 loc) · 1.16 KB
/
FileChecker.pas
File metadata and controls
58 lines (48 loc) · 1.16 KB
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
unit FileChecker;
interface
implementation
uses
Classes, SysUtils;
const
TAG_VERSION_2_3 = 3;
ID3V2_FRAME_COUNT = 7;
type
TagInfo = record
ID: array [1..3] of AnsiChar;
Version: Byte;
Revision: Byte;
Flags: Byte;
Size: array [1..4] of Byte;
FileSize: Integer;
Frame: array [1..ID3V2_FRAME_COUNT] of string;
end;
TFileChecker = class(TObject)
function IsCorrectFile(const FileName: string): Boolean;
end;
var
HeaderInf: TFileChecker;
function TFileChecker.IsCorrectFile(const FileName: string): Boolean;
var
SourceFile: file;
Transferred: Integer;
Tag: TagInfo;
begin
try
Result := true;
{ Set read-access and open file }
AssignFile(SourceFile, FileName);
FileMode := 0;
Reset(SourceFile, 1);
{ Read header and get file size }
BlockRead(SourceFile, Tag, 10, Transferred);
Tag.FileSize := FileSize(SourceFile);
CloseFile(SourceFile);
{ if transfer is not complete }
if Transferred < 10 then Result := false;
if Tag.ID <> 'ID3' then Result := false;
except
{ Error }
Result := false;
end;
end;
end.