Rev 2 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 6 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | unit MD5; |
1 | unit MD5; |
2 | 2 | ||
3 | interface |
3 | interface |
4 | 4 | ||
5 | uses |
5 | uses |
6 | Classes; |
6 | Classes, Common; |
- | 7 | ||
- | 8 | type |
|
- | 9 | TCheckSumFileMD5 = class(TCheckSumFile) |
|
- | 10 | protected |
|
- | 11 | Fmd5File: string; |
|
- | 12 | public |
|
- | 13 | constructor Create(AFileName: string); override; |
|
- | 14 | procedure ToStringList(slOut: TStringList); override; |
|
- | 15 | function SingleFileChecksum(AFileName: string): string; override; |
|
- | 16 | function MergeLine(AFileName, ACheckSum: string): string; override; |
|
- | 17 | end; |
|
7 | 18 | ||
8 | function md5file(const filename: string): string; |
19 | function md5file(const filename: string): string; |
9 | procedure MD5FileToStringList(amd5file: string; slOut: TStringList); |
20 | procedure MD5FileToStringList(amd5file: string; slOut: TStringList); |
10 | 21 | ||
11 | implementation |
22 | implementation |
12 | 23 | ||
13 | uses |
24 | uses |
14 | SysUtils, IdHashMessageDigest, idHash, Common, LongFilenameOperations; |
25 | SysUtils, IdHashMessageDigest, idHash, LongFilenameOperations; |
15 | 26 | ||
16 | function md5file(const filename: string): string; |
27 | function md5file(const filename: string): string; |
17 | var |
28 | var |
18 | IdMD5: TIdHashMessageDigest5; |
29 | IdMD5: TIdHashMessageDigest5; |
19 | FS: TFileStream; |
30 | FS: TFileStream; |
Line 88... | Line 99... | ||
88 | finally |
99 | finally |
89 | MyCloseFile(fil); |
100 | MyCloseFile(fil); |
90 | end; |
101 | end; |
91 | end; |
102 | end; |
92 | 103 | ||
- | 104 | { TCheckSumFileMD5 } |
|
- | 105 | ||
- | 106 | constructor TCheckSumFileMD5.Create(AFileName: string); |
|
- | 107 | begin |
|
- | 108 | inherited; |
|
- | 109 | fmd5File := AFileName; |
|
- | 110 | if not SameText(ExtractFileExt(AFileName),'.sfv') then |
|
- | 111 | raise Exception.Create('Invalid checksum file extension.'); |
|
- | 112 | end; |
|
- | 113 | ||
- | 114 | function TCheckSumFileMD5.MergeLine(AFileName, ACheckSum: string): string; |
|
- | 115 | begin |
|
- | 116 | result := ACheckSum + ' *' + AFileName; |
|
- | 117 | end; |
|
- | 118 | ||
- | 119 | function TCheckSumFileMD5.SingleFileChecksum(AFileName: string): string; |
|
- | 120 | begin |
|
- | 121 | result := md5file(AFileName); |
|
- | 122 | end; |
|
- | 123 | ||
- | 124 | procedure TCheckSumFileMD5.ToStringList(slOut: TStringList); |
|
- | 125 | begin |
|
- | 126 | inherited; |
|
- | 127 | MD5FileToStringList(fmd5File, slOut); |
|
- | 128 | end; |
|
- | 129 | ||
93 | end. |
130 | end. |