/// <summary> /// Analyzes the mods asynchronous. /// </summary> /// <param name="mode">The mode.</param> /// <returns>Task.</returns> protected virtual async Task AnalyzeModsAsync(PatchStateMode mode) { SubscribeToProgressReport(Disposables); var overlayProgress = Smart.Format(localizationManager.GetResource(LocalizationResources.Mod_Actions.Overlay_Conflict_Solver_Progress), new { PercentDone = 0, Count = 1, TotalCount = 3 }); var message = localizationManager.GetResource(LocalizationResources.Mod_Actions.Overlay_Conflict_Solver_Loading_Definitions); await TriggerOverlayAsync(true, message, overlayProgress); modPatchCollectionService.InvalidatePatchModState(CollectionMods.SelectedModCollection.Name); modPatchCollectionService.ResetPatchStateCache(); var definitions = await Task.Run(() => { return(modPatchCollectionService.GetModObjects(gameService.GetSelected(), CollectionMods.SelectedMods)); }).ConfigureAwait(false); var conflicts = await Task.Run(() => { if (definitions != null) { return(modPatchCollectionService.FindConflicts(definitions, CollectionMods.SelectedModCollection.Mods.ToList(), mode)); } return(null); }).ConfigureAwait(false); var syncedConflicts = await Task.Run(async() => { return(await modPatchCollectionService.SyncPatchStateAsync(conflicts, CollectionMods.SelectedModCollection.Name).ConfigureAwait(false)); }).ConfigureAwait(false); if (syncedConflicts != null) { conflicts = syncedConflicts; } var args = new NavigationEventArgs() { SelectedCollection = CollectionMods.SelectedModCollection, Results = conflicts, State = NavigationState.ConflictSolver, SelectedMods = CollectionMods.SelectedMods.Select(p => p.Name).ToList() }; ReactiveUI.MessageBus.Current.SendMessage(args); await TriggerOverlayAsync(false); definitionAnalyzeLoadHandler?.Dispose(); definitionLoadHandler?.Dispose(); definitionSyncHandler?.Dispose(); }
/// <summary> /// Called when [activated]. /// </summary> /// <param name="disposables">The disposables.</param> protected override void OnActivated(CompositeDisposable disposables) { ShowAdvancedFeatures = (gameService.GetSelected()?.AdvancedFeaturesSupported).GetValueOrDefault(); var allowModSelectionEnabled = this.WhenAnyValue(v => v.AllowModSelection); RenameCommand = ReactiveCommand.Create(() => { return(new CommandResult <ModifyAction>(ModifyAction.Rename, CommandState.Success)); }, allowModSelectionEnabled).DisposeWith(disposables); DuplicateCommand = ReactiveCommand.CreateFromTask(async() => { if (ActiveCollection != null) { var copy = CopyCollection(ActiveCollection.Name); if (modCollectionService.Save(copy)) { await TriggerOverlayAsync(true, localizationManager.GetResource(LocalizationResources.Collection_Mods.Overlay_Rename_Message)); await modPatchCollectionService.CopyPatchCollectionAsync(ActiveCollection.Name, copy.Name); await TriggerOverlayAsync(false); return(new CommandResult <ModifyAction>(ModifyAction.Duplicate, CommandState.Success)); } else { return(new CommandResult <ModifyAction>(ModifyAction.Duplicate, CommandState.Failed)); } } return(new CommandResult <ModifyAction>(ModifyAction.Duplicate, CommandState.NotExecuted)); }, allowModSelectionEnabled).DisposeWith(disposables); MergeOpenCommand = ReactiveCommand.Create(() => { IsMergeOpen = true; }, allowModSelectionEnabled).DisposeWith(disposables); MergeCloseCommand = ReactiveCommand.Create(() => { IsMergeOpen = false; }).DisposeWith(disposables); MergeAdvancedCommand = ReactiveCommand.CreateFromTask(async() => { if (ActiveCollection != null) { var copy = await GetMergedCollectionAsync(); await TriggerOverlayAsync(true, localizationManager.GetResource(LocalizationResources.App.WaitBackgroundOperationMessage)); await shutDownState.WaitUntilFreeAsync(); var savedCollection = modCollectionService.GetAll().FirstOrDefault(p => p.IsSelected); while (savedCollection == null) { await Task.Delay(25); savedCollection = modCollectionService.GetAll().FirstOrDefault(p => p.IsSelected); } SubscribeToProgressReports(disposables, true); var mode = await modPatchCollectionService.GetPatchStateModeAsync(ActiveCollection.Name); if (mode == PatchStateMode.None) { // fallback to default mod if no patch collection specified mode = PatchStateMode.Default; } var overlayProgress = Smart.Format(localizationManager.GetResource(LocalizationResources.Collection_Mods.MergeCollection.Overlay_Progress), new { PercentDone = 0, Count = 1, TotalCount = 3 }); var message = localizationManager.GetResource(LocalizationResources.Collection_Mods.MergeCollection.Advanced.Overlay_Loading_Definitions); await TriggerOverlayAsync(true, message, overlayProgress); modPatchCollectionService.ResetPatchStateCache(); var definitions = await Task.Run(() => { return(modPatchCollectionService.GetModObjects(gameService.GetSelected(), SelectedMods)); }).ConfigureAwait(false); var conflicts = await Task.Run(() => { if (definitions != null) { return(modPatchCollectionService.FindConflicts(definitions, ActiveCollection.Mods.ToList(), mode)); } return(null); }).ConfigureAwait(false); var mergeMod = await Task.Run(async() => { return(await modMergeService.MergeCollectionByDefinitionsAsync(conflicts, SelectedMods.Select(p => p.Name).ToList(), copy.Name).ConfigureAwait(false)); }).ConfigureAwait(false); copy.Mods = new List <string>() { mergeMod.DescriptorFile }; await TriggerOverlayAsync(false); definitionAnalyzeLoadHandler?.Dispose(); definitionLoadHandler?.Dispose(); definitionMergeProgressHandler?.Dispose(); modCollectionService.Delete(copy.Name); modPatchCollectionService.InvalidatePatchModState(copy.Name); if (modCollectionService.Save(copy)) { return(new CommandResult <ModifyAction>(ModifyAction.Merge, CommandState.Success)); } else { return(new CommandResult <ModifyAction>(ModifyAction.Merge, CommandState.Failed)); } } return(new CommandResult <ModifyAction>(ModifyAction.Merge, CommandState.NotExecuted)); }, allowModSelectionEnabled).DisposeWith(disposables); MergeBasicCommand = ReactiveCommand.CreateFromTask(async() => { if (ActiveCollection != null) { var copy = await GetMergedCollectionAsync(); await TriggerOverlayAsync(true, localizationManager.GetResource(LocalizationResources.App.WaitBackgroundOperationMessage)); await shutDownState.WaitUntilFreeAsync(); var savedCollection = modCollectionService.GetAll().FirstOrDefault(p => p.IsSelected); while (savedCollection == null) { await Task.Delay(25); savedCollection = modCollectionService.GetAll().FirstOrDefault(p => p.IsSelected); } SubscribeToProgressReports(disposables, false); var overlayProgress = Smart.Format(localizationManager.GetResource(LocalizationResources.Collection_Mods.MergeCollection.Overlay_Progress), new { PercentDone = 0, Count = 1, TotalCount = 2 }); var message = localizationManager.GetResource(LocalizationResources.Collection_Mods.MergeCollection.Basic.Overlay_Gathering_Mod_Info); await TriggerOverlayAsync(true, message, overlayProgress); var mergeMod = await Task.Run(async() => { return(await modMergeService.MergeCollectionByFilesAsync(copy.Name)); }).ConfigureAwait(false); copy.Mods = new List <string>() { mergeMod.DescriptorFile }; await TriggerOverlayAsync(false); fileMergeProgressHandler?.Dispose(); modCollectionService.Delete(copy.Name); modPatchCollectionService.InvalidatePatchModState(copy.Name); if (modCollectionService.Save(copy)) { return(new CommandResult <ModifyAction>(ModifyAction.Merge, CommandState.Success)); } else { return(new CommandResult <ModifyAction>(ModifyAction.Merge, CommandState.Failed)); } } return(new CommandResult <ModifyAction>(ModifyAction.Merge, CommandState.NotExecuted)); }, allowModSelectionEnabled).DisposeWith(disposables); base.OnActivated(disposables); }