-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuMD5Check.pas
170 lines (147 loc) · 3.46 KB
/
uMD5Check.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
unit uMD5Check;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
edtFile: TEdit;
btnFile: TButton;
mmoResult: TMemo;
OpenDlg: TOpenDialog;
btnCalc: TButton;
rdoText: TRadioButton;
rdoFile: TRadioButton;
mmoText: TMemo;
GroupBox1: TGroupBox;
rdoUtf8: TRadioButton;
rdoUnicode: TRadioButton;
rdoAnsi: TRadioButton;
lblLink: TLabel;
procedure btnFileClick(Sender: TObject);
procedure btnCalcClick(Sender: TObject);
procedure rdoFileClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure lblLinkClick(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
uses
uMD5, HTTPApp, ShellAPI;
{$R *.dfm}
procedure TForm1.btnFileClick(Sender: TObject);
begin
if OpenDlg.Execute then
begin
edtFile.Text := OpenDlg.FileName;
end;
end;
procedure TForm1.btnCalcClick(Sender: TObject);
procedure CalcFile;
var
objFileStream: TFileStream;
begin
if FileExists(edtFile.Text) then
begin
objFileStream := TFileStream.Create(edtFile.Text, fmOpenRead);
try
mmoResult.Lines.Add(MD5Stream(objFileStream));
finally
FreeAndNil(objFileStream);
end;
end;
end;
procedure CalcText;
var
objStrStream: TStringStream;
begin
objStrStream := TStringStream.Create(mmoText.Text);
try
mmoResult.Lines.Add(MD5Stream(objStrStream));
finally
FreeAndNil(objStrStream);
end;
end;
procedure CalcTextUtf8;
var
objStrStream: TStringStream;
begin
objStrStream := TStringStream.Create(AnsiToUtf8(mmoText.Text));
try
mmoResult.Lines.Add(MD5Stream(objStrStream));
finally
FreeAndNil(objStrStream);
end;
end;
//ת»»
function Str_Gb2UniCode(text: string): String;
var
i,len: Integer;
cur: Integer;
t: String;
ws: WideString;
begin
Result := '';
ws := text;
len := Length(ws);
i := 1;
while i <= len do
begin
cur := Ord(ws[i]);
FmtStr(t,'%4.4X',[cur]);
Result := Result + t;
Inc(i);
end;
end;
//ת»»ÎªUnicode
function AnsiToUnicode(s:string):WideString;
var
lpWideChar:PWideChar;
len:Integer;
begin
len := ( Length(s) + 1 ) * 2;
GetMem(lpWideChar, len);
ZeroMemory(lpWideChar, len);
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,
PChar(s), Length(s),lpWideChar, Len);
Result := lpWideChar;
FreeMem(lpWideChar);
end;
procedure CalcTextUnicode;
var
objStrStream: TStringStream;
begin
mmoResult.Lines.Add(MD5String(Str_Gb2UniCode(mmoText.Text)));
end;
begin
if rdoFile.Checked then
CalcFile
else if rdoText.Checked then
begin
if rdoUtf8.Checked then
CalcTextUtf8
else if rdoUnicode.Checked then
CalcTextUnicode
else
CalcText;
end
end;
procedure TForm1.rdoFileClick(Sender: TObject);
begin
edtFile.Enabled := (Sender = rdoFile);
btnFile.Enabled := (Sender = rdoFile);
mmoText.Enabled := Sender = rdoText;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
rdoFile.Checked := True;
end;
procedure TForm1.lblLinkClick(Sender: TObject);
begin
ShellExecute(Handle, nil, 'http://www.mini188.com', nil, nil, SW_NORMAL);
end;
end.