private async void BackupRestore_Click(object sender, RoutedEventArgs e)
        {
            string path       = BackupService.GetGameBackupPath(MERFileSystem.Game, out var isVanilla, false);
            var    gameTarget = Locations.GetTarget(MERFileSystem.Game);

            if (path != null && gameTarget != null)
            {
                if (gameTarget.TextureModded)
                {
                    RestoreController.StartRestore(this, false);
                }
                else
                {
                    MetroDialogSettings settings = new MetroDialogSettings();
                    settings.NegativeButtonText       = "Full";
                    settings.FirstAuxiliaryButtonText = "Cancel";
                    settings.AffirmativeButtonText    = "Quick";
                    settings.DefaultButtonFocus       = MessageDialogResult.Affirmative;
                    var result = await this.ShowMessageAsync("Select restore mode", "Select which restore mode you would like to perform:\n\nQuick: Restores basegame files modifiable by Mass Effect 2 Randomizer, deletes the DLC mod component\n\nFull: Deletes entire game installation and restores the backup in its place. Fully resets the game to the backup state", MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, settings);

                    if (result == MessageDialogResult.FirstAuxiliary)
                    {
                        // Do nothing. User canceled
                    }
                    else
                    {
                        RestoreController.StartRestore(this, result == MessageDialogResult.Affirmative);
                    }
                }
            }
            else if (gameTarget == null)
            {
                await this.ShowMessageAsync($"{MERFileSystem.Game.ToGameName()} not found", $"{MERFileSystem.Game.ToGameName()} was not found, and as such, cannot be restored by {MERFileSystem.Game.ToGameName()} Randomizer. Repair your game using Steam, Origin, or your DVD, or restore your backup using ME3Tweaks Mod Manager.");
            }
        }
        private async void StartRandomization()
        {
            var modPath      = MERFileSystem.GetDLCModPath();
            var backupStatus = BackupService.GetBackupStatus(MERFileSystem.Game);

            if (!backupStatus.BackedUp && !Directory.Exists(modPath))
            {
                var settings = new MetroDialogSettings()
                {
                    AffirmativeButtonText = "Continue anyways",
                    NegativeButtonText    = "Cancel"
                };
                var result = await this.ShowMessageAsync("No ME3Tweaks-based backup availbale", "It is recommended that you create an ME3Tweaks-based backup before randomization, as this allows much faster re-rolls. You can take a backup using the button on the bottom left of the interface.", MessageDialogStyle.AffirmativeAndNegative, settings);

                if (result == MessageDialogResult.Negative)
                {
                    // Do nothing. User canceled
                    return;
                }
            }


            if (Directory.Exists(modPath) && PerformReroll)
            {
                var isControllerInstalled = SFXGame.IsControllerBasedInstall();
                if (!isControllerInstalled)
                {
                    if (backupStatus.BackedUp)
                    {
                        var settings = new MetroDialogSettings()
                        {
                            AffirmativeButtonText    = "Quick restore",
                            NegativeButtonText       = "No restore",
                            FirstAuxiliaryButtonText = "Cancel",
                            DefaultButtonFocus       = MessageDialogResult.Affirmative
                        };
                        var result = await this.ShowMessageAsync("Existing randomization already installed", "An existing randomization is already installed. It is highly recommended that you perform a quick restore before re-rolling so that basegame changes do not stack or are left installed if your new options do not include these changes.\n\nPerform a quick restore before randomization?", MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, settings);

                        if (result == MessageDialogResult.FirstAuxiliary)
                        {
                            // Do nothing. User canceled
                            return;
                        }

                        if (result == MessageDialogResult.Affirmative)
                        {
                            // Perform quick restore first
                            RestoreController.StartRestore(this, true, InternalStartRandomization);
                            return; // Return, we will run randomization after this
                        }

                        // User did not want to restore, just run
                    }
                    else
                    {
                        var settings = new MetroDialogSettings()
                        {
                            AffirmativeButtonText = "Continue anyways",
                            NegativeButtonText    = "Cancel",
                        };
                        var result = await this.ShowMessageAsync("Existing randomization already installed", "An existing randomization is already installed. Some basegame only randomized files may remain after the DLC component is removed, and if options that modify these files are selected, the effects will stack. It is recommended you 'Remove Randomization' in the bottom left window, then repair your game to ensure you have a fresh installation for a re-roll.\n\nAn ME3Tweaks-based backup is recommended to avoid this procedure, which can be created in the bottom left of the application. It enables the quick restore feature, which only takes a few seconds.", MessageDialogStyle.AffirmativeAndNegative, settings);

                        if (result == MessageDialogResult.Negative)
                        {
                            // Do nothing. User canceled
                            return;
                        }
                    }
                }
                else
                {
                    if (backupStatus.BackedUp)
                    {
                        var settings = new MetroDialogSettings()
                        {
                            AffirmativeButtonText     = "Perform quick restore + randomize",
                            NegativeButtonText        = "Perform only quick restore",
                            FirstAuxiliaryButtonText  = "Install anyways",
                            SecondAuxiliaryButtonText = "Cancel",

                            DefaultButtonFocus = MessageDialogResult.Negative
                        };
                        var result = await this.ShowMessageAsync("Controller mod detected", "Performing a quick restore will undo changes made by the ME2Controller mod. After performing a quick restore, but before randomization, you should reinstall ME2Controller.", MessageDialogStyle.AffirmativeAndNegativeAndDoubleAuxiliary, settings);

                        if (result == MessageDialogResult.SecondAuxiliary)
                        {
                            // Do nothing. User canceled
                            return;
                        }

                        if (result == MessageDialogResult.Affirmative)
                        {
                            // Perform quick restore first
                            RestoreController.StartRestore(this, true, InternalStartRandomization);
                            return; // Return, we will run randomization after this
                        }

                        if (result == MessageDialogResult.Negative)
                        {
                            RestoreController.StartRestore(this, true);
                            return; // Return, we will run randomization after this
                        }
                        // User did not want to restore, just run
                    }
                    else
                    {
                        // no backup, can't quick restore
                        var settings = new MetroDialogSettings()
                        {
                            AffirmativeButtonText = "Continue anyways",
                            NegativeButtonText    = "Cancel",
                        };
                        var result = await this.ShowMessageAsync("Existing randomization already installed", "An existing randomization is already installed. Some basegame only randomized files may remain after the DLC component is removed, and if options that modify these files are selected, the effects will stack. It is recommended you 'Remove Randomization' in the bottom left window, then repair your game to ensure you have a fresh installation for a re-roll.\n\nAn ME3Tweaks-based backup is recommended to avoid this procedure, which can be created in the bottom left of the application. It enables the quick restore feature, which only takes a few seconds.", MessageDialogStyle.AffirmativeAndNegative, settings);

                        if (result == MessageDialogResult.Negative)
                        {
                            // Do nothing. User canceled
                            return;
                        }
                    }
                }
            }

            InternalStartRandomization();
        }
Exemple #3
0
        public async Task RestoreAsync(
            RestoreConfiguration configuration,
            DateTime?pointInTime = null)
        {
            var watch = new Stopwatch();

            watch.Start();
            configuration.Validate();

            var     storageFacade = CreateStorageFacade(configuration.StorageAccount);
            ILogger logger        = new StorageFolderLogger(storageFacade.ChangeFolder("logs"));
            var     cosmosFacade  = CreateCosmosFacade(
                configuration.CosmosAccount,
                logger) as ICosmosAccountFacade;
            var sourceCollectionLogger = logger
                                         .AddContext("Db", configuration.SourceCollection.Db)
                                         .AddContext("Collection", configuration.SourceCollection.Collection);
            var indexController = new IndexCollectionController(
                configuration.SourceCollection.Account,
                configuration.SourceCollection.Db,
                configuration.SourceCollection.Collection,
                storageFacade,
                null,
                configuration.Constants.IndexConstants,
                sourceCollectionLogger);

            try
            {
                await indexController.InitializeAsync();

                try
                {
                    if (pointInTime == null)
                    {
                        await indexController.LoadAsync(true);
                    }
                    else
                    {
                        await indexController.LoadUntilAsync(pointInTime);
                    }

                    var collection = await FindOrCreateCollectionAsync(
                        cosmosFacade,
                        configuration.TargetCollection);

                    var targetCollectionLogger = logger
                                                 .AddContext("Db", configuration.TargetCollection.Db)
                                                 .AddContext("Collection", configuration.TargetCollection.Collection);
                    var restoreController = new RestoreController(
                        configuration.SourceCollection.Account,
                        configuration.SourceCollection.Db,
                        configuration.SourceCollection.Collection,
                        storageFacade,
                        collection,
                        targetCollectionLogger);

                    await restoreController.InitializeAsync();

                    try
                    {
                        await restoreController.RestoreAsync(pointInTime);

                        logger.Display($"Elapsed Time:  {watch.Elapsed}");
                        logger.Display("Memory used:  "
                                       + $"{Process.GetCurrentProcess().PrivateMemorySize64 / 1024 / 1024} Mb");
                    }
                    finally
                    {
                        await restoreController.DisposeAsync();
                    }
                }
                finally
                {
                    await Task.WhenAll(indexController.DisposeAsync(), logger.FlushAsync());
                }
            }
            catch (Exception ex)
            {
                logger.DisplayError(ex);
            }
        }