private static void Restore()
 {
     Logger.Debug("Performing full restore by deleting the application's base directory.");
     Directory.Delete(LauncherConstants.ApplicationBasePath, true);
     Directory.CreateDirectory(LauncherConstants.ApplicationBasePath);
     LauncherRegistryHelper.DeleteValue(LauncherRegistryKeys.ForceRestore);
 }
        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);
        }
Ejemplo n.º 3
0
 protected override void OnRestoreFailed(Exception ex, UpdateInformation updateInformation)
 {
     base.OnRestoreFailed(ex, updateInformation);
     Clean().Wait();
     if (LauncherRestartManager.ShowRestoreDialog(true))
     {
         var options = CreateRestoreRestartOptions();
         if (options is null)
         {
             throw ex;
         }
         ApplicationRestartManager.RestartApplication(options);
     }
     else
     {
         LauncherRegistryHelper.WriteValue(LauncherRegistryKeys.ForceRestore, true);
         Environment.Exit(-1);
     }
 }
        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));
        }
 private static void SetupRegistry()
 {
     LauncherRegistryHelper.Initialize();
 }