summaryrefslogtreecommitdiff
path: root/plugins/MirandaNGHistoryToDB/IMDownloaderComponent/Demo/DownLoaderTestUnit.pas
blob: 2ca42ac174d446a9a6160cba9cac8417ab2b55ae (plain)
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
unit DownLoaderTestUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uIMDownLoader, StdCtrls, ToolWin, ComCtrls, Menus;

type
  TMainForm = class(TForm)
    IMDownloader_Demo: TIMDownloader;
    Edit1: TEdit;
    ToolBar1: TToolBar;
    StatusBar1: TStatusBar;
    RichEdit1: TRichEdit;
    SaveDialog1: TSaveDialog;
    TBDownload: TToolButton;
    TBStopDownload: TToolButton;
    TBView: TToolButton;
    ViewAsTest: TMenuItem;
    SaveToFile: TMenuItem;
    PopupMenu1: TPopupMenu;
    ProgressBar1: TProgressBar;
    procedure FormShow(Sender: TObject);
    procedure IMDownloader_DemoError(Sender: TObject; E: TIMDownLoadError);
    procedure IMDownloader_DemoAccepted(Sender: TObject);
    procedure IMDownloader_DemoStartDownload(Sender: TObject);
    procedure IMDownloader_DemoBreak(Sender: TObject);
    procedure ViewAsTestClick(Sender: TObject);
    procedure SaveToFileClick(Sender: TObject);
    procedure TBDownloadClick(Sender: TObject);
    procedure TBStopDownloadClick(Sender: TObject);
    procedure TBViewClick(Sender: TObject);
    procedure IMDownloader_DemoDownloading(Sender: TObject; AcceptedSize, MaxSize: Cardinal);
    procedure IMDownloader_DemoHeaders(Sender: TObject; Headers: string);
    procedure IMDownloader_DemoMD5Checked(Sender: TObject; MD5Correct,
      SizeCorrect: Boolean; MD5Str: string);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

const
  uURL = 'http://im-history.ru/update/get.php?file=HistoryToDB-Update';

implementation

{$R *.dfm}

procedure TMainForm.FormShow(Sender: TObject);
begin
  Edit1.Text := uURL;
  IMDownloader_Demo.DirPath := ExtractFilePath(Application.ExeName);
end;

procedure TMainForm.IMDownloader_DemoAccepted(Sender: TObject);
begin
  ProgressBar1.Visible := False;
  TBStopDownload.Visible := false;
  TBDownload.Visible := true;
  TBView.Visible := true;
  Edit1.ReadOnly := false;
  StatusBar1.SimpleText :=
    'Ñêà÷èâàíèå óñïåøíî çàâåðøåíî. Âñåãî ïîëó÷åíî äàííûõ â áàéòàõ: ' + IntToStr
    (IMDownloader_Demo.AcceptedSize);
  //RichEdit1.Lines.Append('MD5 ôàéëà â ïàìÿòè: '+MD5DigestToStr(MD5Stream(IMDownloader_Demo.OutStream)));
end;

procedure TMainForm.IMDownloader_DemoBreak(Sender: TObject);
begin
  ProgressBar1.Visible := False;
  TBStopDownload.Visible := false;
  TBStopDownload.Enabled := true;
  TBDownload.Visible := true;
  TBView.Visible := IMDownloader_Demo.AcceptedSize > 0;
  Edit1.ReadOnly := false;
  StatusBar1.SimpleText :=
    'Ñêà÷èâàíèå îñòàíîâëåíî. Âñåãî ïîëó÷åíî äàííûõ â áàéòàõ: ' + IntToStr
    (IMDownloader_Demo.AcceptedSize);
end;

procedure TMainForm.IMDownloader_DemoDownloading(Sender: TObject; AcceptedSize,
  MaxSize: Cardinal);
begin
  StatusBar1.SimpleText := 'Ïîëó÷åíî áàéò: ' + IntToStr(AcceptedSize);
  ProgressBar1.Visible := MaxSize > AcceptedSize;
  ProgressBar1.Max := MaxSize;
  ProgressBar1.Position := AcceptedSize;
end;

procedure TMainForm.IMDownloader_DemoError(Sender: TObject; E: TIMDownLoadError);
var
  s: string;
begin
  ProgressBar1.Visible := False;
  TBStopDownload.Visible := false;
  TBDownload.Visible := true;
  TBView.Visible := IMDownloader_Demo.AcceptedSize > 0;
  Edit1.ReadOnly := false;
  case E of
    deInternetOpen: s := 'Îøèáêà ïðè îòêðûòèè ñåññèè. ';
    deInternetOpenUrl: s := 'Îøèáêà ïðè çàïðàøèâàíèè ôàéëà. ';
    deDownloadingFile: s := 'Îøèáêà ïðè ÷òåíèè ôàéëà. ';
    deRequest: s := 'Îøèáêà ïðè çàïðîñå äàííûõ ÷åðåç ïðîêñè-ñåðâåð. ';
  end;
  StatusBar1.SimpleText :=
    s + 'Âñåãî ïîëó÷åíî äàííûõ â áàéòàõ: ' + IntToStr
    (IMDownloader_Demo.AcceptedSize);
end;

procedure TMainForm.IMDownloader_DemoHeaders(Sender: TObject; Headers: string);
begin
  RichEdit1.Lines.Text := Headers;
end;

procedure TMainForm.IMDownloader_DemoMD5Checked(Sender: TObject; MD5Correct,
  SizeCorrect: Boolean; MD5Str: string);
begin
  if MD5Correct then
    RichEdit1.Lines.Append('Êîíòðîëüíàÿ ñóììà MD5 = '+MD5Str+' - ÂÅÐÍÀ!')
  else
    RichEdit1.Lines.Append('Êîíòðîëüíàÿ ñóììà MD5 = '+MD5Str+' - ÍÅ ÂÅÐÍÀ!');
  if SizeCorrect then
    RichEdit1.Lines.Append('Ðàçìåð ôàéëà = '+IntToStr(IMDownloader_Demo.AcceptedSize)+' - ÂÅÐÍÛÉ!')
  else
    RichEdit1.Lines.Append('Ðàçìåð ôàéëà = '+IntToStr(IMDownloader_Demo.AcceptedSize)+' - ÍÅ ÂÅÐÍÛÉ!');
end;

procedure TMainForm.IMDownloader_DemoStartDownload(Sender: TObject);
begin
  TBDownload.Visible := false;
  TBStopDownload.Visible := true;
  TBView.Visible := false;
  Edit1.ReadOnly := true;
  StatusBar1.SimpleText := 'Èíèöèàëèçàöèÿ ñêà÷èâàíèÿ...';
end;

procedure TMainForm.ViewAsTestClick(Sender: TObject);
begin
  RichEdit1.Lines.LoadFromStream(IMDownloader_Demo.OutStream);
end;

procedure TMainForm.SaveToFileClick(Sender: TObject);
begin
  if Edit1.Text = uURL then
    SaveDialog1.FileName := 'HistoryToDBCreateDB.rar';
  if SaveDialog1.Execute then
    IMDownloader_Demo.OutStream.SaveToFile(SaveDialog1.FileName);
end;

procedure TMainForm.TBDownloadClick(Sender: TObject);
begin
  IMDownloader_Demo.URL := Edit1.Text;
  //IMDownloader_Demo.Proxy := '192.168.42.240:1522';
  IMDownloader_Demo.Proxy := '172.29.72.168:8080';
  IMDownloader_Demo.Download;
end;

procedure TMainForm.TBStopDownloadClick(Sender: TObject);
begin
  StatusBar1.SimpleText := 'Îñòàíàâëèâàåì ñêà÷êó';
  TBStopDownload.Enabled := false;
  IMDownloader_Demo.BreakDownload;
end;

procedure TMainForm.TBViewClick(Sender: TObject);
begin
  TBView.DropdownMenu.Popup(TBView.ClientOrigin.X,
    TBView.ClientOrigin.Y + TBView.Height);
end;

end.