GUI/CrashForm.cs
author moel.mich
Sun, 23 Sep 2012 18:37:43 +0000
changeset 380 573f1fff48b2
parent 206 1fa8eddc24a7
permissions -rw-r--r--
Fixed Issue 387. The new implementation does not try to start a ring 0 driver that already exists, but could not be opened. It tries to delete the driver and install it new. The driver is now stored temporarily in the application folder. The driver is not correctly removed on system shutdown.
     1 /*
     2  
     3   This Source Code Form is subject to the terms of the Mozilla Public
     4   License, v. 2.0. If a copy of the MPL was not distributed with this
     5   file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6  
     7   Copyright (C) 2009-2010 Michael Möller <mmoeller@openhardwaremonitor.org>
     8 	
     9 */
    10 
    11 
    12 using System;
    13 using System.IO;
    14 using System.Net;
    15 using System.Text;
    16 using System.Windows.Forms;
    17 
    18 namespace OpenHardwareMonitor.GUI {
    19   public partial class CrashForm : Form {
    20 
    21     private Exception exception;
    22 
    23     public CrashForm() {
    24       InitializeComponent();
    25     }
    26 
    27     public Exception Exception {
    28       get { return exception; }
    29       set {
    30         exception = value;
    31         StringBuilder s = new StringBuilder();
    32         Version version = typeof(CrashForm).Assembly.GetName().Version;
    33         s.Append("Version: "); s.AppendLine(version.ToString());        
    34         s.AppendLine();
    35         s.AppendLine(exception.ToString());
    36         s.AppendLine();
    37         if (exception.InnerException != null) {
    38           s.AppendLine(exception.InnerException.ToString());
    39           s.AppendLine();
    40         }
    41         s.Append("Common Language Runtime: "); 
    42         s.AppendLine(Environment.Version.ToString());
    43         s.Append("Operating System: ");
    44         s.AppendLine(Environment.OSVersion.ToString());
    45         s.Append("Process Type: ");
    46         s.AppendLine(IntPtr.Size == 4 ? "32-Bit" : "64-Bit");
    47         reportTextBox.Text = s.ToString();        
    48       }
    49     }
    50 
    51     private void sendButton_Click(object sender, EventArgs e) {
    52       try {
    53         Version version = typeof(CrashForm).Assembly.GetName().Version;
    54         WebRequest request = WebRequest.Create(
    55           "http://openhardwaremonitor.org/report.php");
    56         request.Method = "POST";
    57         request.Timeout = 5000;
    58         request.ContentType = "application/x-www-form-urlencoded";
    59 
    60         string report =
    61           "type=crash&" +
    62           "version=" + Uri.EscapeDataString(version.ToString()) + "&" +
    63           "report=" + Uri.EscapeDataString(reportTextBox.Text) + "&" +
    64           "comment=" + Uri.EscapeDataString(commentTextBox.Text) + "&" +
    65           "email=" + Uri.EscapeDataString(emailTextBox.Text);
    66         byte[] byteArray = Encoding.UTF8.GetBytes(report);
    67         request.ContentLength = byteArray.Length;
    68 
    69         try {
    70           Stream dataStream = request.GetRequestStream();
    71           dataStream.Write(byteArray, 0, byteArray.Length);
    72           dataStream.Close();
    73 
    74           WebResponse response = request.GetResponse();
    75           dataStream = response.GetResponseStream();
    76           StreamReader reader = new StreamReader(dataStream);
    77           string responseFromServer = reader.ReadToEnd();
    78           reader.Close();
    79           dataStream.Close();
    80           response.Close();
    81 
    82           Close();
    83         } catch (WebException) {
    84           MessageBox.Show("Sending the crash report failed.", "Error", 
    85             MessageBoxButtons.OK, MessageBoxIcon.Error);
    86         }
    87       } catch {
    88       }
    89     }
    90   }  
    91 }