forked from openhardwaremonitor/openhardwaremonitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReportForm.cs
78 lines (65 loc) · 2.45 KB
/
ReportForm.cs
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
/*
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
Copyright (C) 2009-2020 Michael Möller <mmoeller@openhardwaremonitor.org>
*/
using OpenHardwareMonitor.Utilities;
using System;
using System.Drawing;
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;
namespace OpenHardwareMonitor.GUI {
public partial class ReportForm : Form {
private string report;
public ReportForm() {
InitializeComponent();
try {
titleLabel.Font = new Font(SystemFonts.DefaultFont, FontStyle.Bold);
reportTextBox.Font = new Font(FontFamily.GenericMonospace,
SystemFonts.DefaultFont.Size);
} catch { }
}
public string Report {
get { return report; }
set {
report = value;
reportTextBox.Text = report;
}
}
private void sendButton_Click(object sender, EventArgs e) {
Version version = typeof(CrashForm).Assembly.GetName().Version;
WebRequest request = WebRequest.Create(
"http://openhardwaremonitor.org/report.php");
request.Method = "POST";
request.Timeout = 5000;
request.ContentType = "application/x-www-form-urlencoded";
string report =
"type=hardware&" +
"version=" + HttpUtility.UrlEncode(version.ToString()) + "&" +
"report=" + HttpUtility.UrlEncode(reportTextBox.Text) + "&" +
"comment=" + HttpUtility.UrlEncode(commentTextBox.Text) + "&" +
"email=" + HttpUtility.UrlEncode(emailTextBox.Text);
byte[] byteArray = Encoding.UTF8.GetBytes(report);
request.ContentLength = byteArray.Length;
try {
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
reader.Close();
dataStream.Close();
response.Close();
Close();
} catch (WebException) {
MessageBox.Show("Sending the hardware report failed.", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}