136 lines
4.4 KiB
C#
136 lines
4.4 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Windows.Forms;
|
|
using Xylem.Common.CommonCore.Consts;
|
|
using Xylem.Common.Utils.Logging;
|
|
|
|
namespace Xylem.Common.Ui.MagFluxToolBox
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class FrmMainForm : Form
|
|
{
|
|
private readonly String _configFile =
|
|
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
|
"MagFlux", ProgramConfig.SerialConfigFileName);
|
|
|
|
/// <summary>
|
|
/// Ctor
|
|
/// </summary>
|
|
public FrmMainForm()
|
|
{
|
|
InitializeComponent();
|
|
var logger = NLogHelper.CreateOrGetLogger("MagFluxToolBox");
|
|
var version = Assembly.GetExecutingAssembly().GetName().Version;
|
|
logger.Info($"MagFlux ToolBox Version:{version}");
|
|
lblVersionNumber.Text = $@"ToolBox {version}";
|
|
|
|
try
|
|
{
|
|
var fileVersion = FileVersionInfo.GetVersionInfo("magflux_api.dll");
|
|
logger.Info($"MagFlux API Version:{fileVersion.FileVersion}");
|
|
|
|
fileVersion = FileVersionInfo.GetVersionInfo("shared_code.dll");
|
|
logger.Info($"Shared Code Version:{fileVersion.FileVersion}");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Debug(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void Form_Closed(Object sender, EventArgs e)
|
|
{
|
|
Show();
|
|
}
|
|
|
|
private void FrmMainForm_Load(Object sender, EventArgs e)
|
|
{
|
|
var versionString = "NA";
|
|
Boolean access;
|
|
|
|
try
|
|
{
|
|
var assemblyName = Assembly.GetExecutingAssembly().GetName();
|
|
versionString = $@"Version: {assemblyName.Version.Major}.{assemblyName.Version.Minor}.{assemblyName.Version.Build}";
|
|
access = Logic.SoftwareAccessHelper.Access.HasAccess(assemblyName);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($@"MagFluxToolBox {versionString}" + Environment.NewLine + Environment.NewLine +
|
|
@"Starting in OfflineMode" + Environment.NewLine + Environment.NewLine +
|
|
@"Your version could not be verified!"
|
|
+ Environment.NewLine + ex.Message);
|
|
|
|
Close();
|
|
CheckConfigs();
|
|
foreach (var item in Controls)
|
|
{
|
|
if (item is Button btn)
|
|
{
|
|
btn.Enabled = btn.Name == btnSetup.Name;
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
if (!access)
|
|
{
|
|
MessageBox.Show($@"MagFluxToolBox {versionString}" + Environment.NewLine + Environment.NewLine +
|
|
@"Your version licence is expired!");
|
|
|
|
Close();
|
|
}
|
|
|
|
CheckConfigs();
|
|
}
|
|
|
|
private void CheckConfigs()
|
|
{
|
|
var nLogFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
|
"MagFlux", ProgramConfig.NlogConfig);
|
|
var dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MagFlux");
|
|
|
|
if (!Directory.Exists(dir))
|
|
{
|
|
Directory.CreateDirectory(dir);
|
|
}
|
|
|
|
if (!File.Exists(nLogFile))
|
|
{
|
|
const String fileCop = ProgramConfig.NlogConfig;
|
|
try
|
|
{
|
|
File.Copy(fileCop, nLogFile);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
MessageBox.Show(@"Unable to create log files!");
|
|
}
|
|
}
|
|
|
|
if (!File.Exists(_configFile))
|
|
{
|
|
var text = "Configuration file cannot be found!\nExecute setup.";
|
|
MessageBox.Show(text);
|
|
}
|
|
}
|
|
|
|
private void btnSetup_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmSetup();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void btnTest_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmTest();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
}
|
|
}
|