2010-01-26 22:37:48 +00:00
|
|
|
|
/*
|
|
|
|
|
|
2012-05-27 14:23:31 +00:00
|
|
|
|
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/.
|
2010-01-26 22:37:48 +00:00
|
|
|
|
|
2013-07-21 14:17:11 +00:00
|
|
|
|
Copyright (C) 2009-2013 Michael Möller <mmoeller@openhardwaremonitor.org>
|
2012-05-27 14:23:31 +00:00
|
|
|
|
|
2010-01-26 22:37:48 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
2010-04-02 16:05:07 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
2010-01-26 22:37:48 +00:00
|
|
|
|
using System.Windows.Forms;
|
2010-04-02 16:05:07 +00:00
|
|
|
|
using OpenHardwareMonitor.GUI;
|
2010-01-26 22:37:48 +00:00
|
|
|
|
|
|
|
|
|
namespace OpenHardwareMonitor {
|
2010-04-02 16:05:07 +00:00
|
|
|
|
public static class Program {
|
|
|
|
|
|
2010-01-26 22:37:48 +00:00
|
|
|
|
[STAThread]
|
2010-04-02 16:05:07 +00:00
|
|
|
|
public static void Main() {
|
2010-01-26 22:37:48 +00:00
|
|
|
|
#if !DEBUG
|
2010-04-05 15:31:19 +00:00
|
|
|
|
Application.ThreadException +=
|
|
|
|
|
new ThreadExceptionEventHandler(Application_ThreadException);
|
|
|
|
|
Application.SetUnhandledExceptionMode(
|
|
|
|
|
UnhandledExceptionMode.CatchException);
|
|
|
|
|
|
2010-04-02 16:05:07 +00:00
|
|
|
|
AppDomain.CurrentDomain.UnhandledException +=
|
|
|
|
|
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
|
2010-01-26 22:37:48 +00:00
|
|
|
|
#endif
|
2010-02-19 19:50:07 +00:00
|
|
|
|
|
2010-05-01 12:12:37 +00:00
|
|
|
|
if (!AllRequiredFilesAvailable())
|
|
|
|
|
Environment.Exit(0);
|
|
|
|
|
|
2010-04-02 16:05:07 +00:00
|
|
|
|
Application.EnableVisualStyles();
|
|
|
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
|
|
|
|
using (GUI.MainForm form = new GUI.MainForm()) {
|
|
|
|
|
form.FormClosed += delegate(Object sender, FormClosedEventArgs e) {
|
|
|
|
|
Application.Exit();
|
|
|
|
|
};
|
|
|
|
|
Application.Run();
|
2010-01-26 22:37:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-02-19 19:50:07 +00:00
|
|
|
|
|
2010-05-01 12:12:37 +00:00
|
|
|
|
private static bool IsFileAvailable(string fileName) {
|
|
|
|
|
string path = Path.GetDirectoryName(Application.ExecutablePath) +
|
|
|
|
|
Path.DirectorySeparatorChar;
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(path + fileName)) {
|
|
|
|
|
MessageBox.Show("The following file could not be found: " + fileName +
|
2011-02-07 22:06:58 +00:00
|
|
|
|
"\nPlease extract all files from the archive.", "Error",
|
2010-05-01 12:12:37 +00:00
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool AllRequiredFilesAvailable() {
|
|
|
|
|
if (!IsFileAvailable("Aga.Controls.dll"))
|
|
|
|
|
return false;
|
2011-02-07 22:06:58 +00:00
|
|
|
|
if (!IsFileAvailable("OpenHardwareMonitorLib.dll"))
|
|
|
|
|
return false;
|
2013-07-21 14:17:11 +00:00
|
|
|
|
if (!IsFileAvailable("OxyPlot.dll"))
|
|
|
|
|
return false;
|
|
|
|
|
if (!IsFileAvailable("OxyPlot.WindowsForms.dll"))
|
|
|
|
|
return false;
|
|
|
|
|
|
2010-05-01 12:12:37 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-05 15:31:19 +00:00
|
|
|
|
private static void ReportException(Exception e) {
|
2010-07-04 12:12:37 +00:00
|
|
|
|
CrashForm form = new CrashForm();
|
2010-04-05 15:31:19 +00:00
|
|
|
|
form.Exception = e;
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Application_ThreadException(object sender,
|
|
|
|
|
ThreadExceptionEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
ReportException(e.Exception);
|
|
|
|
|
} catch {
|
|
|
|
|
} finally {
|
|
|
|
|
Application.Exit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-02 16:05:07 +00:00
|
|
|
|
public static void CurrentDomain_UnhandledException(object sender,
|
|
|
|
|
UnhandledExceptionEventArgs args)
|
|
|
|
|
{
|
2010-04-05 15:31:19 +00:00
|
|
|
|
try {
|
|
|
|
|
Exception e = args.ExceptionObject as Exception;
|
|
|
|
|
if (e != null)
|
|
|
|
|
ReportException(e);
|
2010-04-25 19:05:15 +00:00
|
|
|
|
} catch {
|
|
|
|
|
} finally {
|
|
|
|
|
Environment.Exit(0);
|
|
|
|
|
}
|
2010-04-02 16:05:07 +00:00
|
|
|
|
}
|
2010-01-26 22:37:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|