using System;
using System.Windows;

namespace ShaferExample
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            AppCode = AppUtils.DefAppSettings("appCode", "demo");
            AppName = AppUtils.DefAppSettings("appName", string.Empty);
            AppDesc = AppUtils.DefAppSettings("appDesc", string.Empty);

            AppDomain currentDomain = AppDomain.CurrentDomain;
            currentDomain.UnhandledException += new UnhandledExceptionEventHandler(AppUtils.ErrorHandler);
            Licensing = new LicensingLogic();
            SetStartupUri();
        }

        protected override void OnExit(ExitEventArgs e)
        {
            base.OnExit(e);
            WinSparkle.CleanUp();
            Licensing.Dispose();
        }

        private void SetStartupUri()
        {
            if (Licensing.LicenseAcquired)
            {
                StartupUri = new Uri("/ShaferExample;component/AppWindow.xaml", uriKind: UriKind.Relative);
            }
            else
            {
                StartupUri = new Uri("/ShaferExample;component/RegistrationWindow.xaml", uriKind: UriKind.Relative);
            }
        }

        public static string AppCode { get; set; }
        public static string AppDesc { get; set; }
        public static string AppName { get; set; } 
        public static LicensingLogic Licensing { get; set; }

    }
}
