Program.cs 3.21 KB
using Emgu.CV;
using MoyaSignup.Dataclasses;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;

namespace MoyaSignup
{
    static class Program
    {
        public static DebugWriteListener DebugWListener;
        public static Form1 Form1;
        public static LogForm LogFrm;
        public static DateTime HeartBeat = System.DateTime.Now;
        public static string AppDataPath = "";
        public static List<DsDeviceContainer> CaptureDevices;
        public static List<Capture> WebCams;

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (!Debugger.IsAttached)
            {
                if (args.Length == 0 || args[0] != "-noautoupdate")
                {

                    if (AutoUpdateLib.AutoUpdateCore.CheckForUpdates(null))
                        return;     //program is required to close by autoupdate (probably updated)

                }
            }
            System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
            Version appVersion = a.GetName().Version;
            string appVersionString = appVersion.ToString();

            if (Properties.Settings.Default.ApplicationVersion != appVersion.ToString())
            {
                Properties.Settings.Default.Upgrade();
                Properties.Settings.Default.ApplicationVersion = appVersionString;
            }
            
            AppDataPath = Path.Combine(Application.LocalUserAppDataPath, "MoyaSignup");
            if (!Directory.Exists(AppDataPath))
                Directory.CreateDirectory(AppDataPath);

            Directory.SetCurrentDirectory(AppDataPath);

            DebugWListener = new DebugWriteListener("debug.log");
            Debug.Listeners.Add(DebugWListener);
            Debug.WriteLine("[program] Opened debug log");

            Directory.SetCurrentDirectory(Application.StartupPath);

            //HeartBeatMonitor hbmon = new HeartBeatMonitor();
            Form1 = new Form1();

            Form1.KeyUp += Form1_KeyUp;

            Application.Run(Form1);

            Debug.Close();

            //hbmon.Stop();
        }

        private static void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Alt && e.Control && e.KeyCode == Keys.S)
            {
                Debug.WriteLine("[program] Catched key event alt + ctrl + S: Shutting down the program.");
                Form1.AllowShutdown = true;
                //allowShutdown = true;
                Application.Exit();
                return;
            } else if(e.Alt && e.Control && e.KeyCode == Keys.C)
            {
                //WebCamViewForm frm = new WebCamViewForm(webCams);
                //frm.Show();
            }
            else if (e.Alt && e.KeyCode == Keys.F5)
            {
                //userDetailsEditor1.SetPrinter(ThermoPrinterLibrary.ThermoPrinter.Models.IDP3210);
                //MessageBox.Show("Printteri: IDP3210");

            }
        }
    }
}