private static bool CheckRestoreRequired(ExternalUpdaterResult launchOption)
        {
            var restore = false;

            if (launchOption == ExternalUpdaterResult.UpdateFailedNoRestore)
            {
                restore = true;
            }
            else if (launchOption == ExternalUpdaterResult.DemandsRestore)
            {
                restore = true;
            }
            else if ((Keyboard.Modifiers & ModifierKeys.Shift) > 0)
            {
                restore = true;
            }
            var successRegistry = LauncherRegistryHelper.GetValue <bool>(LauncherRegistryKeys.ForceRestore, out var forceRestore);

            if (!successRegistry || forceRestore)
            {
                restore = true;
            }
            Logger.Debug($"Check if a full restore is required: {restore}");
            return(restore);
        }
 private static bool ShallUpdate(ExternalUpdaterResult launchOption)
 {
     if ((Keyboard.GetKeyStates(Key.N) & KeyStates.Down) > 0)
     {
         return(false);
     }
     return(launchOption == ExternalUpdaterResult.NoUpdate && FocLauncherInformation.Instance.AutoUpdateEnabled);
 }
        private static void HandleLastUpdateResult(ExternalUpdaterResult launchOption, out bool skipWrite)
        {
            skipWrite = false;
            if (launchOption == ExternalUpdaterResult.UpdateFailedWithRestore)
            {
                new UpdateResultDialog("Update failed",
                                       "The update of the launcher failed but it recovered itself to the last working state.").ShowDialog();
                skipWrite = true;
            }

            if (launchOption == ExternalUpdaterResult.UpdateFailedNoRestore)
            {
                new RestoreDialog(false).ShowDialog();
            }

            if (launchOption == ExternalUpdaterResult.UpdateSuccess)
            {
                new UpdateSuccessDialog().ShowDialog();
                skipWrite = true;
            }
        }
        internal static bool Initialize(ExternalUpdaterResult launchOption)
        {
            if (!Directory.Exists(LauncherConstants.ApplicationBasePath))
            {
                throw new DirectoryNotFoundException($"Required directory '{LauncherConstants.ApplicationBasePath}' not found.");
            }

            SetupRegistry();

            try
            {
                if (CheckRestoreRequired(launchOption))
                {
                    Restore();
                }
                HandleLastUpdateResult(launchOption, out var skipWriteToDisk);
                if (!skipWriteToDisk)
                {
                    AssemblyExtractor.WriteNecessaryAssembliesToDisk(LauncherConstants.ApplicationBasePath, LauncherConstants.ApplicationFileNames);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                if (e is AggregateException aggregate)
                {
                    e = aggregate.GetBaseException();
                }
                LauncherRegistryHelper.WriteValue(LauncherRegistryKeys.ForceRestore, true);
                // TODO: This and the exception dialog should be the same dialog
                new RestartSystemDialog(e.Message).ShowDialog();
                Environment.Exit(0);
            }

            LogInstalledAssemblies();
            SetCurrentUpdateSearchMode();
            return(ShallUpdate(launchOption));
        }