moel@150: /* moel@344: moel@344: This Source Code Form is subject to the terms of the Mozilla Public moel@344: License, v. 2.0. If a copy of the MPL was not distributed with this moel@344: file, You can obtain one at http://mozilla.org/MPL/2.0/. moel@344: moel@344: Copyright (C) 2009-2010 Michael Möller moel@344: moel@344: */ moel@150: moel@150: moel@150: using System; moel@150: using System.IO; moel@150: using System.Net; moel@150: using System.Text; moel@150: using System.Windows.Forms; moel@150: moel@150: namespace OpenHardwareMonitor.GUI { moel@150: public partial class CrashForm : Form { moel@150: moel@150: private Exception exception; moel@150: moel@150: public CrashForm() { moel@150: InitializeComponent(); moel@150: } moel@150: moel@150: public Exception Exception { moel@150: get { return exception; } moel@150: set { moel@150: exception = value; moel@150: StringBuilder s = new StringBuilder(); moel@150: Version version = typeof(CrashForm).Assembly.GetName().Version; moel@150: s.Append("Version: "); s.AppendLine(version.ToString()); moel@150: s.AppendLine(); moel@150: s.AppendLine(exception.ToString()); moel@150: s.AppendLine(); moel@150: if (exception.InnerException != null) { moel@150: s.AppendLine(exception.InnerException.ToString()); moel@150: s.AppendLine(); moel@150: } moel@150: s.Append("Common Language Runtime: "); moel@150: s.AppendLine(Environment.Version.ToString()); moel@150: s.Append("Operating System: "); moel@150: s.AppendLine(Environment.OSVersion.ToString()); moel@150: s.Append("Process Type: "); moel@150: s.AppendLine(IntPtr.Size == 4 ? "32-Bit" : "64-Bit"); moel@150: reportTextBox.Text = s.ToString(); moel@150: } moel@150: } moel@150: moel@150: private void sendButton_Click(object sender, EventArgs e) { moel@150: try { moel@150: Version version = typeof(CrashForm).Assembly.GetName().Version; moel@150: WebRequest request = WebRequest.Create( moel@150: "http://openhardwaremonitor.org/report.php"); moel@150: request.Method = "POST"; moel@150: request.Timeout = 5000; moel@150: request.ContentType = "application/x-www-form-urlencoded"; moel@150: moel@150: string report = moel@206: "type=crash&" + moel@206: "version=" + Uri.EscapeDataString(version.ToString()) + "&" + moel@206: "report=" + Uri.EscapeDataString(reportTextBox.Text) + "&" + moel@206: "comment=" + Uri.EscapeDataString(commentTextBox.Text) + "&" + moel@206: "email=" + Uri.EscapeDataString(emailTextBox.Text); moel@150: byte[] byteArray = Encoding.UTF8.GetBytes(report); moel@150: request.ContentLength = byteArray.Length; moel@150: moel@150: try { moel@150: Stream dataStream = request.GetRequestStream(); moel@150: dataStream.Write(byteArray, 0, byteArray.Length); moel@150: dataStream.Close(); moel@150: moel@150: WebResponse response = request.GetResponse(); moel@150: dataStream = response.GetResponseStream(); moel@150: StreamReader reader = new StreamReader(dataStream); moel@150: string responseFromServer = reader.ReadToEnd(); moel@150: reader.Close(); moel@150: dataStream.Close(); moel@150: response.Close(); moel@150: moel@150: Close(); moel@150: } catch (WebException) { moel@150: MessageBox.Show("Sending the crash report failed.", "Error", moel@150: MessageBoxButtons.OK, MessageBoxIcon.Error); moel@150: } moel@150: } catch { moel@150: } moel@150: } moel@150: } moel@150: }