Program.cs
author StephaneLenclud
Thu, 18 Apr 2013 23:25:10 +0200
branchMiniDisplay
changeset 444 9b09e2ee0968
parent 344 3145aadca3d2
permissions -rw-r--r--
Front View plug-in does not init if no sensor added.
Fixing some format to make strings shorter.
Now trying to start SoundGraphAccess.exe process from same directory.
Packed mode now can display three sensors along with the current time.
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@413
     7
  Copyright (C) 2009-2013 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.Threading;
moel@1
    14
using System.Windows.Forms;
moel@86
    15
using OpenHardwareMonitor.GUI;
moel@1
    16
moel@1
    17
namespace OpenHardwareMonitor {
moel@86
    18
  public static class Program {
moel@86
    19
moel@1
    20
    [STAThread]
moel@86
    21
    public static void Main() {
moel@1
    22
      #if !DEBUG
moel@87
    23
        Application.ThreadException += 
moel@87
    24
          new ThreadExceptionEventHandler(Application_ThreadException);
moel@87
    25
        Application.SetUnhandledExceptionMode(
moel@87
    26
          UnhandledExceptionMode.CatchException);
moel@87
    27
moel@86
    28
        AppDomain.CurrentDomain.UnhandledException += 
moel@86
    29
          new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
moel@1
    30
      #endif
moel@55
    31
moel@106
    32
      if (!AllRequiredFilesAvailable())
moel@106
    33
        Environment.Exit(0);
moel@106
    34
moel@86
    35
      Application.EnableVisualStyles();
moel@86
    36
      Application.SetCompatibleTextRenderingDefault(false);
moel@86
    37
      using (GUI.MainForm form = new GUI.MainForm()) {
moel@86
    38
        form.FormClosed += delegate(Object sender, FormClosedEventArgs e) {
moel@86
    39
          Application.Exit();
moel@86
    40
        };        
moel@86
    41
        Application.Run();
moel@1
    42
      }
moel@1
    43
    }
moel@55
    44
moel@106
    45
    private static bool IsFileAvailable(string fileName) {
moel@106
    46
      string path = Path.GetDirectoryName(Application.ExecutablePath) +
moel@106
    47
        Path.DirectorySeparatorChar;
moel@106
    48
moel@106
    49
      if (!File.Exists(path + fileName)) {
moel@106
    50
        MessageBox.Show("The following file could not be found: " + fileName + 
moel@253
    51
          "\nPlease extract all files from the archive.", "Error",
moel@106
    52
           MessageBoxButtons.OK, MessageBoxIcon.Error);
moel@106
    53
        return false;
moel@106
    54
      }
moel@106
    55
      return true;      
moel@106
    56
    }
moel@106
    57
moel@106
    58
    private static bool AllRequiredFilesAvailable() {
moel@106
    59
      if (!IsFileAvailable("Aga.Controls.dll"))
moel@106
    60
        return false;
moel@253
    61
      if (!IsFileAvailable("OpenHardwareMonitorLib.dll"))
moel@253
    62
        return false;
moel@413
    63
      if (!IsFileAvailable("OxyPlot.dll"))
moel@413
    64
        return false;
moel@413
    65
      if (!IsFileAvailable("OxyPlot.WindowsForms.dll"))
moel@413
    66
        return false;
moel@413
    67
      
moel@106
    68
      return true;
moel@106
    69
    }
moel@106
    70
moel@87
    71
    private static void ReportException(Exception e) {
moel@150
    72
      CrashForm form = new CrashForm();
moel@87
    73
      form.Exception = e;
moel@87
    74
      form.ShowDialog();
moel@87
    75
    }
moel@87
    76
moel@87
    77
    public static void Application_ThreadException(object sender, 
moel@87
    78
      ThreadExceptionEventArgs e) 
moel@87
    79
    {
moel@87
    80
      try {
moel@87
    81
        ReportException(e.Exception);
moel@87
    82
      } catch {
moel@87
    83
      } finally {
moel@87
    84
        Application.Exit();
moel@87
    85
      }
moel@87
    86
    }
moel@87
    87
moel@86
    88
    public static void CurrentDomain_UnhandledException(object sender, 
moel@86
    89
      UnhandledExceptionEventArgs args) 
moel@86
    90
    {
moel@87
    91
      try {
moel@87
    92
        Exception e = args.ExceptionObject as Exception;
moel@87
    93
        if (e != null)
moel@87
    94
          ReportException(e);
moel@98
    95
      } catch {
moel@98
    96
      } finally {
moel@98
    97
        Environment.Exit(0);
moel@98
    98
      }
moel@86
    99
    }   
moel@1
   100
  }
moel@1
   101
}