-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuChecksumsForm.pas
151 lines (125 loc) · 4.32 KB
/
uChecksumsForm.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
{
Copyright (c) 2019,2021 Daniel T. Borelli <[email protected]>
This file is part of ArchIsoMyDrive.
ArchIsoMyDrive is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ArchIsoMyDrive is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ArchIsoMyDrive. If not, see <http://www.gnu.org/licenses/>.
}
unit uChecksumsForm;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
Buttons, ExtCtrls, uResources, uRHash, CTypes;
type
{ TChecksumsForm }
TChecksumsForm = class(TForm)
btnClose: TBitBtn;
btnCalculate: TButton;
cbxChecksums: TComboBox;
edtCompare: TEdit;
edtHash: TEdit;
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
lblMatches: TLabel;
lblIsoName: TLabel;
procedure btnCalculateClick(Sender: TObject);
procedure edtCompareChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
fileName : string;
procedure SetFileName(const aFileName : string);
public
property ISOFileName : string write SetFileName;
end;
var
ChecksumsForm: TChecksumsForm;
implementation
{$R *.lfm}
{ TChecksumsForm }
procedure TChecksumsForm.SetFileName(const aFileName : string);
begin
fileName := aFileName;
lblIsoName.Caption := 'ISO :' + ExtractFileName(aFileName);
end;
procedure TChecksumsForm.btnCalculateClick(Sender: TObject);
const
MD5 = 0;
SHA1 = 1;
SHA256 = 2;
SHA384 = 3;
SHA512 = 4;
var
id : cuint;
hex : string;
i : integer;
digest : array[0..127] of cuchar;
ndigest : integer;
ret : cint;
begin
Enabled := False;
Application.ProcessMessages();
case cbxChecksums.ItemIndex of
MD5 : begin
id := RHASH_MD5;
ndigest := 16; // 128 bits
end;
SHA1 : begin
id := RHASH_SHA1;
ndigest := 20; // 160 bits
end;
SHA256 : begin
id := RHASH_SHA256;
ndigest := 32; // 256 bits
end;
SHA384 : begin
id := RHASH_SHA384;
ndigest := 48; // 384 bits
end;
SHA512 : begin
id := RHASH_SHA512;
ndigest := 64; // 512 bits
end;
end;
ret := rhash_file(id, PChar(fileName), @digest);
assert(ret = 0);
hex := '';
for i:= 0 to ndigest - 1 do
hex := hex + LowerCase(IntToHex(digest[i], 2));
edtHash.Text := hex.Substring(0, ndigest * 2);
Enabled := True;
edtCompareChange(nil);
end;
procedure TChecksumsForm.edtCompareChange(Sender: TObject);
begin
if (edtCompare.Text <> '') and (edtHash.Text <> '') then
begin
edtHash.Text := Trim(edtHash.Text);
if edtCompare.Text = edtHash.Text then
begin
lblMatches.Caption := rsChecksumMatch;
lblMatches.Font.Color := clGreen;
end
else
begin
lblMatches.Caption := rsChecksumNotMatch;
lblMatches.Font.Color := clRed;
end;
end
end;
procedure TChecksumsForm.FormCreate(Sender: TObject);
begin
cbxChecksums.ItemIndex := 2;
end;
end.