source: trunk/ULogExceptions.pas

Last change on this file was 1, checked in by george, 15 years ago
  • Přidáno: Verze 1.0
  • Přidáno: Pomocné komponenty a ikony.
  • Přidáno: Skript pro sestavení instalačního programu a instalační programy jednotlivých verzí.
File size: 6.1 KB
Line 
1// You have to turn on generating of detailed map file!
2// Release date 24.2.2006
3
4unit ULogExceptions;
5
6interface
7
8uses
9 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
10 Dialogs, StdCtrls, Sockets, ExtCtrls, Registry, cTCPClient, UMapFile, WinSock;
11
12const
13 ErrorLogHost = 'www.zdechov.net';
14 ErrorLogScript = 'jirihajda/error.php';
15 NazevSouboru = 'Error.txt';
16
17type
18 TStoreError = class(TThread)
19 Bezi: Boolean;
20 procedure Execute; override;
21 end;
22
23 TRadekInfoVyjimky = record
24 Popis: string;
25 Text: string;
26 end;
27
28 TLogExceptions = class(TForm)
29 Label1: TLabel;
30 Button1: TButton;
31 Edit1: TEdit;
32 Label2: TLabel;
33 Button2: TButton;
34 Memo1: TMemo;
35 Image1: TImage;
36 CheckBox1: TCheckBox;
37 TcpClient1: TTcpClient;
38 procedure Button2Click(Sender: TObject);
39 procedure FormShow(Sender: TObject);
40 procedure Button1Click(Sender: TObject);
41 procedure FormCreate(Sender: TObject);
42 procedure FormClose(Sender: TObject; var Action: TCloseAction);
43 procedure FormDestroy(Sender: TObject);
44 private
45 FMapFile: TMapFile;
46// Report: string;
47 StoreError: TStoreError;
48 Data: array of TRadekInfoVyjimky;
49 Vyska: Integer;
50 procedure Send;
51 public
52 Stav: string; // Obsah lokálních promìnných
53 NazevAplikace: string; // Název aplikace
54 AppReleaseDate: string;
55 AppVersion: string;
56 procedure Obsluha(Sender : TObject; E : Exception );
57 procedure Pridat(NovyPopis, NovyText: string);
58 end;
59
60var
61 LogExceptions: TLogExceptions;
62
63implementation
64
65{$R *.dfm}
66
67{ TOsetreniVyjimek }
68
69function ReturnAddr(Index: Integer): Pointer;
70asm
71 MOV EAX,[EBP+Index*4]
72end;
73
74procedure TLogExceptions.Obsluha(Sender: TObject; E: Exception);
75var
76// ExtRec: PExceptionRecord;
77// Log: string;
78 Soubor: TextFile;
79 I: Integer;
80begin
81 FMapFile.LoadExceptionData;
82// ShowMessage();
83 Pridat('Èas', DateTimeToStr(Now));
84 Pridat('Aplikace', NazevAplikace);
85 Pridat('Verze', AppVersion);
86 Pridat('Datum vydání', AppReleaseDate);
87 Pridat('Text chyby', E.Message);
88 Pridat('Tøída vyjímky', E.ClassName);
89 Pridat('Adresa', Format('%p',[ReturnAddr(6)]));
90 Pridat('Jednotka', FMapFile.ExceptUnitName);
91 Pridat('Metoda', FMapFile.ExceptMethodName);
92 Pridat('Øádek', IntToStr(FMapFile.ExceptLineNumber));
93 Pridat('Stavové informace', Stav);
94
95 ShowModal; // Ukaž dialog
96
97 if Edit1.Text <> '' then Pridat('Komentáø uživatele', Edit1.Text);
98
99 // Uložit chybu do souboru
100 AssignFile(Soubor,NazevSouboru);
101 try
102 if FileExists(NazevSouboru) then Append(Soubor) else Rewrite(Soubor);
103 WriteLn(Soubor);
104 for I := 0 to High(Data) do WriteLn(Soubor,Data[I].Popis+': '+Data[I].Text);
105 finally
106 CloseFile(Soubor);
107 end;
108 StoreError.Execute;
109end;
110
111procedure TLogExceptions.Pridat(NovyPopis, NovyText: string);
112begin
113 SetLength(Data,Length(Data)+1);
114 with Data[High(Data)] do begin
115 Popis := NovyPopis;
116 Text := NovyText;
117 end;
118end;
119
120procedure TLogExceptions.Send;
121var
122 I: Integer;
123 //II: Integer;
124 Hlaseni: string;
125 //Buf: array[0..10000] of Char;
126 //Pocet: Integer;
127// Radek: string;
128 UseProxy: Boolean;
129 ProxyServer: string;
130 ProxyPort: string;
131 HostHTTP: string;
132begin
133 // Check if proxy server enabled
134 with TRegistry.Create do try
135 RootKey := HKEY_CURRENT_USER;
136 OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings', False);
137 UseProxy := ReadBool('ProxyEnable');
138 ProxyServer := ReadString('ProxyServer');
139 finally
140 Free;
141 end;
142
143 // Generate report
144 Hlaseni := '';
145 for I := 0 to High(Data) do with Data[I] do
146 Hlaseni := Hlaseni + '&' + Popis + '=' + Text;
147 Delete(Hlaseni, 1, 1);
148
149 // Replace blank spaces by special char %20
150 while Pos(' ', Hlaseni) > 0 do
151 Hlaseni := Copy(Hlaseni, 1, Pos(' ', Hlaseni)-1) + '%20' + Copy(Hlaseni, Pos(' ', Hlaseni) + 1, Length(Hlaseni));
152
153 if UseProxy then begin
154 ProxyPort := Copy(ProxyServer,Pos(':',ProxyServer)+1,255);
155 Delete(ProxyServer,Pos(':',ProxyServer),255);
156 TcpClient1.RemoteHost := ProxyServer;
157 TcpClient1.RemotePort := ProxyPort;
158 end else begin
159 TcpClient1.RemoteHost := ErrorLogHost;
160 TcpClient1.RemotePort := '80';
161 end;
162
163 HostHTTP := 'http://' + ErrorLogHost + '/' + ErrorLogScript;
164 with TcpClient1 do begin
165 Connect;
166 if Connected then begin
167 SendLn('GET ' + HostHTTP + '?' + Hlaseni + ' HTTP/1.0');
168 SendLn('Accept: text/html');
169 SendLn('Content-Type: text/plain; charset="iso-8859-2"');
170 Hlaseni := '';
171 SendLn('Content-length: '+IntToStr(Length(Hlaseni)));
172 if UseProxy then SendLn('Host: ' + ErrorLogHost);
173 SendLn('');
174 SendLn(Hlaseni);
175// Memo1.Lines.Add(Hlaseni);
176
177 //for I := 0 to 100 do
178 // Memo1.Lines.Add(Receiveln);
179 Close;
180 end; // else ShowMessage('Nepodaøilo se pøipojit k serveru');
181 end;
182 SetLength(Data,0);
183end;
184
185procedure TLogExceptions.Button2Click(Sender: TObject);
186begin
187 if Height = Vyska then Height := Vyska + Memo1.Height + 8 else Height := Vyska;
188end;
189
190procedure TLogExceptions.FormShow(Sender: TObject);
191var
192 I: Integer;
193begin
194 Vyska := Height;
195 Memo1.Clear;
196 for I := 0 to High(Data) do with Data[I] do Memo1.Lines.Add(Popis+': '+Text);
197 Edit1.Text := '';
198 //Send;
199end;
200
201procedure TLogExceptions.Button1Click(Sender: TObject);
202begin
203 if CheckBox1.Checked then Application.Terminate;
204 Close;
205end;
206
207{ TOdeslani }
208
209procedure TStoreError.Execute;
210begin
211 Bezi := True;
212 LogExceptions.Send;
213 Bezi := False;
214end;
215
216procedure TLogExceptions.FormCreate(Sender: TObject);
217begin
218 StoreError := TStoreError.Create(True);
219 NazevAplikace := Application.Title;
220 Application.OnException := Obsluha;
221 FMapFile := TMapFile.Create;
222 FMapFile.MapFileName := ChangeFileExt(Application.ExeName, '.map');
223end;
224
225procedure TLogExceptions.FormClose(Sender: TObject;
226 var Action: TCloseAction);
227begin
228 Height := Vyska;
229end;
230
231procedure TLogExceptions.FormDestroy(Sender: TObject);
232begin
233 FreeAndNil(FMapFile);
234end;
235
236end.
Note: See TracBrowser for help on using the repository browser.