예제 #1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            AppDomain.CurrentDomain.UnhandledException += App.CurrentDomain_UnhandledException;
            try
            {
                NativeMethods.SetCurrentProcessExplicitAppUserModelID("com.squirrel.XIVHunt.XIV-Hunt");
            }
            catch
            {
            }
            if (ApplicationRunningHelper.AlreadyRunning())
            {
                Thread.Sleep(2000);
                if (ApplicationRunningHelper.AlreadyRunning())
                {
                    return;
                }
            }
            bool isFirstInstall = App.RestoreSettings();

            if (isFirstInstall && App.IsSquirrelInstall())
            {
                try
                {
                    Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
                    new LanguageSelector().ShowDialog();
                }
                catch (Exception)
                {
                }
            }
            if (App.IsSquirrelInstall())
            {
                SquirrelAwareApp.HandleEvents(null, delegate(Version v)
                {
                    Updater.OnAppUpdate();
                }, null, null, new Action(Updater.OnFirstRun), null);
                using (CancellationTokenSource cts = new CancellationTokenSource())
                {
                    Task task = Updater.Create(cts.Token);
                    task.Start();
                    task.Wait();
                }
            }
            base.MainWindow = new Window1();
            Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
            base.MainWindow.Show();
            base.OnStartup(e);
            if (isFirstInstall && App.IsSquirrelInstall())
            {
                Task.Run(async delegate()
                {
                    await Task.Delay(1000).ConfigureAwait(false);
                    App.TryShowInstalledShortcutInfoToast();
                });
            }
        }
예제 #2
0
        protected override void OnStartup(StartupEventArgs e)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            try { NativeMethods.SetCurrentProcessExplicitAppUserModelID(AppID); } catch { }
            if (ApplicationRunningHelper.AlreadyRunning())
            {
                Thread.Sleep(2000);
                if (ApplicationRunningHelper.AlreadyRunning())
                {
                    return;
                }
            }

            bool isFirstInstall = RestoreSettings();

            if (isFirstInstall && IsSquirrelInstall())
            {
                try
                {
                    Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
                    new UI.LanguageSelector().ShowDialog();
                }
                catch (Exception) { }
            }
            if (IsSquirrelInstall())
            {
                SquirrelAwareApp.HandleEvents(onAppUpdate: v => Updater.OnAppUpdate(), onFirstRun: Updater.OnFirstRun);
                using (CancellationTokenSource cts = new CancellationTokenSource())
                {
                    var updateTask = Updater.Create(cts.Token);
                    updateTask.Start();
                    updateTask.Wait();
                }
            }

            MainWindow           = new Window1();
            Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
            MainWindow.Show();

            base.OnStartup(e);
            if (isFirstInstall)
            {
                Task.Factory.StartNew(async() =>
                {
                    await Task.Delay(1000);
                    TryShowInstalledShortcutInfoToast();
                });
            }
        }
예제 #3
0
        public static void Main(string[] args)
        {
#if !DEBUG
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
#endif
            if (ApplicationRunningHelper.AlreadyRunning())
            {
                Thread.Sleep(2000);
                if (ApplicationRunningHelper.AlreadyRunning())
                {
                    return;
                }
            }
            try
            {
                if (Settings.Default.CallUpgrade)
                {
                    Updater.RestoreSettings();
                    Settings.Default.Reload();
                }
            }catch (Exception e)
            {
                WriteExceptionToErrorFile(new Exception("Failed to restore previous settings.", e));
            }
#if !DEBUG
            SquirrelAwareApp.HandleEvents(onAppUpdate: v => Updater.OnAppUpdate(), onFirstRun: () => Updater.OnFirstRun());
            try { NativeMethods.SetCurrentProcessExplicitAppUserModelID("com.squirrel.XIVHunt.XIV-Hunt"); } catch { }
            using (var cts = new CancellationTokenSource())
            {
                var updateTask = Updater.Create(cts.Token);
                updateTask.Start();
                updateTask.Wait();
            }
#endif

            Application app = new Application {
                MainWindow = new Window1()
            };
            Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
            app.Run(app.MainWindow);
        }