using Serilog;
using System;
using System.IO;
using System.Windows.Forms;

namespace BulkPrinting
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Globals.MaxDBPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Configuration.MaxDataPathName);
            Globals.MaxDBFilePath = Path.Combine(Globals.MaxDBPath, Configuration.MaxDBFileName);
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .WriteTo.Debug()
                .WriteTo.File(
                    Path.Combine(Globals.MaxDBPath, "application.log"),
                    rollOnFileSizeLimit: true,
                    fileSizeLimitBytes: 1024 * 1024,
                    retainedFileCountLimit: 10,
                    restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information)
                .CreateLogger();

            Log.Information("Version {0} starting", Application.ProductVersion);

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

#if SIMULATE_HDD_SERIAL
            //Globals.HDDSerialNumber = "9VMTDFGX";
            Globals.HDDSerialNumber = "2ZRA6NXL";
#else
            Globals.HDDSerialNumber = Utility.GetHDDSerial();
#endif

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new UserLoginForm());

            Log.Information("Version {0} exiting", Application.ProductVersion);
        }

        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Log.Fatal((Exception)e.ExceptionObject, "Unhandled exception");
        }
    }
}
