tbf/DeviceTest/Program.cs

87 lines
2.9 KiB
C#
Raw Normal View History

2016-10-11 14:18:54 +00:00
using System;
using System.Collections.Generic;
using System.IO;
2016-10-11 14:18:54 +00:00
using System.Linq;
using System.Windows.Forms;
namespace DeviceTest
{
static class Program
{
/// Program information
public static string Version; /// version string
public static DateTime BuildDateTime; /// date and time of program build
/// Local settings
public static readonly string LocAppDataDir;
public static readonly string LocalSettingsFileName;
public static readonly string LocalSettingsBackupName;
public static LocalSettings LocalSettings;
static Program()
{
/// Program version string
System.Reflection.Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly();
Version ver = thisAssembly.GetName().Version;
Version = string.Format("{0}.{1}.{2}", ver.Major, ver.Minor, ver.Build);
BuildDateTime = new System.IO.FileInfo(thisAssembly.Location).LastWriteTime;
/// Local program configuration directory including the trailing backslash
LocAppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) +
Path.DirectorySeparatorChar + "TestBenchFramework" + Path.DirectorySeparatorChar;
LocalSettingsFileName = LocAppDataDir + "DeviceTest.xml";
LocalSettingsBackupName = LocAppDataDir + "DeviceTest.backup.xml";
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
///
/// Load the local settings
///
Program.LocalSettings = LocalSettings.Load(Program.LocalSettingsFileName);
if (Program.LocalSettings == null)
{
/// Loading local seetings from regular config file failed. Use the backup
Program.LocalSettings = LocalSettings.Load(Program.LocalSettingsBackupName);
if (Program.LocalSettings == null)
{
MessageBox.Show("Na tomto počítači nebol tento program ani raz spustený.\r\nPoužijú sa základné nastavenia.", "Upozornenie", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
Program.LocalSettings = new LocalSettings();
Directory.CreateDirectory(LocAppDataDir);
Program.LocalSettings.Save();
}
else
{
LocalSettings.Save(); /// Save the settings to overwrite the wrong file
}
}
else
{
/// Loading local seetings from the regular config file was successful. Update the backup
File.Copy(Program.LocalSettingsFileName, Program.LocalSettingsBackupName, true);
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
try
{
DeviceTestDlg dlg = new DeviceTestDlg();
Application.Run(dlg);
}
catch (Exception exc)
{
MessageBox.Show("Program havaroval:" +
Environment.NewLine + Environment.NewLine + exc.Message +
((exc.InnerException == null) ? string.Empty : (Environment.NewLine + exc.InnerException.Message)) +
Environment.NewLine + exc.StackTrace,
"Pozor!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
2016-10-11 14:18:54 +00:00
}