-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathu_report.pas
134 lines (112 loc) · 3.39 KB
/
u_report.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
unit u_report;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, WinInet;
type
Twnd_report = class(TForm)
reports: TMemo;
reportuser: TMemo;
Label43: TLabel;
btn_send: TBitBtn;
Label1: TLabel;
procedure btn_sendClick(Sender: TObject);
procedure reportuserChange(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
wnd_report: Twnd_report;
implementation
uses U_main;
{$R *.dfm}
function GetUrlContent(const Url: string): string;
var
NetHandle: HINTERNET;
UrlHandle: HINTERNET;
Buffer: array[0..1024] of Char;
BytesRead: dWord;
begin
Result := '';
NetHandle := InternetOpen('MapEditor', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if Assigned(NetHandle) then
begin
UrlHandle := InternetOpenUrl(NetHandle, PChar(Url), nil, 0, INTERNET_FLAG_RELOAD, 0);
if Assigned(UrlHandle) then
{ UrlHandle valid? Proceed with download }
begin
FillChar(Buffer, SizeOf(Buffer), 0);
repeat
Result := Result + Buffer;
FillChar(Buffer, SizeOf(Buffer), 0);
InternetReadFile(UrlHandle, @Buffer, SizeOf(Buffer), BytesRead);
until BytesRead = 0;
InternetCloseHandle(UrlHandle);
end
else
{ UrlHandle is not valid. Raise an exception. }
raise Exception.CreateFmt('Cannot open URL %s', [Url]);
InternetCloseHandle(NetHandle);
end
else
{ NetHandle is not valid. Raise an exception }
raise Exception.Create('Unable to initialize Wininet');
end;
function GetComputerNetName: string;
var
buffer: array[0..255] of char;
size: dword;
begin
size := 256;
if GetComputerName(buffer, size) then
Result := buffer
else
Result := ''
end;
Function GetUserFromWindows: string;
Var
UserName : string;
UserNameLen : Dword;
Begin
UserNameLen := 255;
SetLength(userName, UserNameLen) ;
If GetUserName(PChar(UserName), UserNameLen) Then
Result := Copy(UserName,1,UserNameLen - 1)
Else
Result := 'Unknown';
End;
procedure Twnd_report.btn_sendClick(Sender: TObject);
var
send: string;
CanonicalURL: pchar;
CanonicalURL2: pchar;
CanonicalURL3: pchar;
size: integer;
fullurl: string;
begin
send:= reports.lines.GetText;
send:= StringReplace(send, #13, '%0d', [rfReplaceAll, rfIgnoreCase] );
Size := 3 * Length(send);
getmem(CanonicalURL, size);
InternetCanonicalizeUrl(PChar(send), PChar(CanonicalURL), cardinal(Size), 0 );
send:= reportuser.lines.GetText;
send:= StringReplace(send, #13, '%0d', [rfReplaceAll, rfIgnoreCase] );
Size := 3 * Length(send);
getmem(CanonicalURL2, size);
InternetCanonicalizeUrl(PChar(send), PChar(CanonicalURL2), cardinal(Size), 0 );
send:= wnd_about.Label1.caption;
send:= StringReplace(send, #13, '%0d', [rfReplaceAll, rfIgnoreCase] );
Size := 3 * Length(send);
getmem(CanonicalURL3, size);
InternetCanonicalizeUrl(PChar(send), PChar(CanonicalURL3), cardinal(Size), 0 );
fullurl := 'http://mathpudding.com/editor.php?user=' + GetUserFromWindows() + '&pc=' + GetComputerNetName() + '&version=' + CanonicalURL3 + '&info=' + CanonicalURL + '&describe=' + CanonicalURL2;
showmessage(GetUrlContent(fullurl));
hide;
end;
procedure Twnd_report.reportuserChange(Sender: TObject);
begin
btn_send.enabled:= true;
end;
end.