GUI/CrashForm.cs
author moel.mich
Mon, 01 Nov 2010 20:44:21 +0000
changeset 237 9bf70d316cea
parent 150 522da3b8cb1a
child 344 3145aadca3d2
permissions -rw-r--r--
Restricted the access to the kernel driver to system and built-in administrators.
     1 /*
     2   
     3   Version: MPL 1.1/GPL 2.0/LGPL 2.1
     4 
     5   The contents of this file are subject to the Mozilla Public License Version
     6   1.1 (the "License"); you may not use this file except in compliance with
     7   the License. You may obtain a copy of the License at
     8  
     9   http://www.mozilla.org/MPL/
    10 
    11   Software distributed under the License is distributed on an "AS IS" basis,
    12   WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
    13   for the specific language governing rights and limitations under the License.
    14 
    15   The Original Code is the Open Hardware Monitor code.
    16 
    17   The Initial Developer of the Original Code is 
    18   Michael Möller <m.moeller@gmx.ch>.
    19   Portions created by the Initial Developer are Copyright (C) 2009-2010
    20   the Initial Developer. All Rights Reserved.
    21 
    22   Contributor(s):
    23 
    24   Alternatively, the contents of this file may be used under the terms of
    25   either the GNU General Public License Version 2 or later (the "GPL"), or
    26   the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    27   in which case the provisions of the GPL or the LGPL are applicable instead
    28   of those above. If you wish to allow use of your version of this file only
    29   under the terms of either the GPL or the LGPL, and not to allow others to
    30   use your version of this file under the terms of the MPL, indicate your
    31   decision by deleting the provisions above and replace them with the notice
    32   and other provisions required by the GPL or the LGPL. If you do not delete
    33   the provisions above, a recipient may use your version of this file under
    34   the terms of any one of the MPL, the GPL or the LGPL.
    35  
    36 */
    37 
    38 using System;
    39 using System.IO;
    40 using System.Net;
    41 using System.Text;
    42 using System.Windows.Forms;
    43 
    44 namespace OpenHardwareMonitor.GUI {
    45   public partial class CrashForm : Form {
    46 
    47     private Exception exception;
    48 
    49     public CrashForm() {
    50       InitializeComponent();
    51     }
    52 
    53     public Exception Exception {
    54       get { return exception; }
    55       set {
    56         exception = value;
    57         StringBuilder s = new StringBuilder();
    58         Version version = typeof(CrashForm).Assembly.GetName().Version;
    59         s.Append("Version: "); s.AppendLine(version.ToString());        
    60         s.AppendLine();
    61         s.AppendLine(exception.ToString());
    62         s.AppendLine();
    63         if (exception.InnerException != null) {
    64           s.AppendLine(exception.InnerException.ToString());
    65           s.AppendLine();
    66         }
    67         s.Append("Common Language Runtime: "); 
    68         s.AppendLine(Environment.Version.ToString());
    69         s.Append("Operating System: ");
    70         s.AppendLine(Environment.OSVersion.ToString());
    71         s.Append("Process Type: ");
    72         s.AppendLine(IntPtr.Size == 4 ? "32-Bit" : "64-Bit");
    73         reportTextBox.Text = s.ToString();        
    74       }
    75     }
    76 
    77     private void sendButton_Click(object sender, EventArgs e) {
    78       try {
    79         Version version = typeof(CrashForm).Assembly.GetName().Version;
    80         WebRequest request = WebRequest.Create(
    81           "http://openhardwaremonitor.org/report.php");
    82         request.Method = "POST";
    83         request.Timeout = 5000;
    84         request.ContentType = "application/x-www-form-urlencoded";
    85 
    86         string report =
    87           "type=crash&" +
    88           "version=" + Uri.EscapeDataString(version.ToString()) + "&" +
    89           "report=" + Uri.EscapeDataString(reportTextBox.Text) + "&" +
    90           "comment=" + Uri.EscapeDataString(commentTextBox.Text) + "&" +
    91           "email=" + Uri.EscapeDataString(emailTextBox.Text);
    92         byte[] byteArray = Encoding.UTF8.GetBytes(report);
    93         request.ContentLength = byteArray.Length;
    94 
    95         try {
    96           Stream dataStream = request.GetRequestStream();
    97           dataStream.Write(byteArray, 0, byteArray.Length);
    98           dataStream.Close();
    99 
   100           WebResponse response = request.GetResponse();
   101           dataStream = response.GetResponseStream();
   102           StreamReader reader = new StreamReader(dataStream);
   103           string responseFromServer = reader.ReadToEnd();
   104           reader.Close();
   105           dataStream.Close();
   106           response.Close();
   107 
   108           Close();
   109         } catch (WebException) {
   110           MessageBox.Show("Sending the crash report failed.", "Error", 
   111             MessageBoxButtons.OK, MessageBoxIcon.Error);
   112         }
   113       } catch {
   114       }
   115     }
   116   }  
   117 }