author | moel.mich |
Sun, 23 Sep 2012 18:37:43 +0000 | |
changeset 380 | 573f1fff48b2 |
parent 291 | 61c3d984fb2d |
child 413 | 362c5e77197d |
permissions | -rw-r--r-- |
moel@1 | 1 |
/* |
moel@1 | 2 |
|
moel@344 | 3 |
This Source Code Form is subject to the terms of the Mozilla Public |
moel@344 | 4 |
License, v. 2.0. If a copy of the MPL was not distributed with this |
moel@344 | 5 |
file, You can obtain one at http://mozilla.org/MPL/2.0/. |
moel@1 | 6 |
|
moel@344 | 7 |
Copyright (C) 2009-2010 Michael Möller <mmoeller@openhardwaremonitor.org> |
moel@344 | 8 |
|
moel@1 | 9 |
*/ |
moel@1 | 10 |
|
moel@1 | 11 |
using System; |
moel@86 | 12 |
using System.IO; |
moel@86 | 13 |
using System.Text; |
moel@86 | 14 |
using System.Threading; |
moel@1 | 15 |
using System.Windows.Forms; |
moel@86 | 16 |
using OpenHardwareMonitor.GUI; |
moel@1 | 17 |
|
moel@1 | 18 |
namespace OpenHardwareMonitor { |
moel@86 | 19 |
public static class Program { |
moel@86 | 20 |
|
moel@1 | 21 |
[STAThread] |
moel@86 | 22 |
public static void Main() { |
moel@1 | 23 |
#if !DEBUG |
moel@87 | 24 |
Application.ThreadException += |
moel@87 | 25 |
new ThreadExceptionEventHandler(Application_ThreadException); |
moel@87 | 26 |
Application.SetUnhandledExceptionMode( |
moel@87 | 27 |
UnhandledExceptionMode.CatchException); |
moel@87 | 28 |
|
moel@86 | 29 |
AppDomain.CurrentDomain.UnhandledException += |
moel@86 | 30 |
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); |
moel@1 | 31 |
#endif |
moel@55 | 32 |
|
moel@106 | 33 |
if (!AllRequiredFilesAvailable()) |
moel@106 | 34 |
Environment.Exit(0); |
moel@106 | 35 |
|
moel@86 | 36 |
Application.EnableVisualStyles(); |
moel@86 | 37 |
Application.SetCompatibleTextRenderingDefault(false); |
moel@86 | 38 |
using (GUI.MainForm form = new GUI.MainForm()) { |
moel@86 | 39 |
form.FormClosed += delegate(Object sender, FormClosedEventArgs e) { |
moel@86 | 40 |
Application.Exit(); |
moel@86 | 41 |
}; |
moel@86 | 42 |
Application.Run(); |
moel@1 | 43 |
} |
moel@1 | 44 |
} |
moel@55 | 45 |
|
moel@106 | 46 |
private static bool IsFileAvailable(string fileName) { |
moel@106 | 47 |
string path = Path.GetDirectoryName(Application.ExecutablePath) + |
moel@106 | 48 |
Path.DirectorySeparatorChar; |
moel@106 | 49 |
|
moel@106 | 50 |
if (!File.Exists(path + fileName)) { |
moel@106 | 51 |
MessageBox.Show("The following file could not be found: " + fileName + |
moel@253 | 52 |
"\nPlease extract all files from the archive.", "Error", |
moel@106 | 53 |
MessageBoxButtons.OK, MessageBoxIcon.Error); |
moel@106 | 54 |
return false; |
moel@106 | 55 |
} |
moel@106 | 56 |
return true; |
moel@106 | 57 |
} |
moel@106 | 58 |
|
moel@106 | 59 |
private static bool AllRequiredFilesAvailable() { |
moel@106 | 60 |
if (!IsFileAvailable("Aga.Controls.dll")) |
moel@106 | 61 |
return false; |
moel@253 | 62 |
if (!IsFileAvailable("OpenHardwareMonitorLib.dll")) |
moel@253 | 63 |
return false; |
moel@286 | 64 |
|
moel@106 | 65 |
return true; |
moel@106 | 66 |
} |
moel@106 | 67 |
|
moel@87 | 68 |
private static void ReportException(Exception e) { |
moel@150 | 69 |
CrashForm form = new CrashForm(); |
moel@87 | 70 |
form.Exception = e; |
moel@87 | 71 |
form.ShowDialog(); |
moel@87 | 72 |
} |
moel@87 | 73 |
|
moel@87 | 74 |
public static void Application_ThreadException(object sender, |
moel@87 | 75 |
ThreadExceptionEventArgs e) |
moel@87 | 76 |
{ |
moel@87 | 77 |
try { |
moel@87 | 78 |
ReportException(e.Exception); |
moel@87 | 79 |
} catch { |
moel@87 | 80 |
} finally { |
moel@87 | 81 |
Application.Exit(); |
moel@87 | 82 |
} |
moel@87 | 83 |
} |
moel@87 | 84 |
|
moel@86 | 85 |
public static void CurrentDomain_UnhandledException(object sender, |
moel@86 | 86 |
UnhandledExceptionEventArgs args) |
moel@86 | 87 |
{ |
moel@87 | 88 |
try { |
moel@87 | 89 |
Exception e = args.ExceptionObject as Exception; |
moel@87 | 90 |
if (e != null) |
moel@87 | 91 |
ReportException(e); |
moel@98 | 92 |
} catch { |
moel@98 | 93 |
} finally { |
moel@98 | 94 |
Environment.Exit(0); |
moel@98 | 95 |
} |
moel@86 | 96 |
} |
moel@1 | 97 |
} |
moel@1 | 98 |
} |