コード例 #1
0
        /// <summary>
        /// resolve conflict as an asynchronous operation.
        /// </summary>
        /// <param name="resolve">if set to <c>true</c> [resolve].</param>
        protected virtual async Task ResolveConflictAsync(bool resolve)
        {
            if (ResolvingConflict)
            {
                return;
            }
            ResolvingConflict = true;
            if (ModCompareSelector.VirtualDefinitions?.Count() > 0)
            {
                IHierarchicalDefinitions conflictParent = null;
                int?conflictParentIdx = null;
                int parentIdx         = HierarchalConflicts.ToList().IndexOf(SelectedParentConflict);
                foreach (var item in HierarchalConflicts)
                {
                    if (item.Children.Contains(SelectedConflict))
                    {
                        conflictParent = item;
                        var conflictParentChildren = new List <IHierarchicalDefinitions>(item.Children);
                        conflictParentIdx = conflictParentChildren.IndexOf(SelectedConflict);
                        break;
                    }
                }
                var id = idGenerator.GetNextId();
                await TriggerOverlayAsync(id, true, localizationManager.GetResource(LocalizationResources.Conflict_Solver.OverlayResolve));

                IDefinition patchDefinition = null;
                if (!IsBinaryConflict)
                {
                    patchDefinition = ModCompareSelector.VirtualDefinitions.FirstOrDefault(p => modPatchCollectionService.IsPatchMod(p.ModName));
                }
                else
                {
                    if (resolve)
                    {
                        patchDefinition = takeLeftBinary ? ModCompareSelector.LeftSelectedDefinition : ModCompareSelector.RightSelectedDefinition;
                    }
                    else
                    {
                        patchDefinition = ModCompareSelector.Definitions.FirstOrDefault();
                    }
                }
                if (patchDefinition != null)
                {
                    var generatedFileNames = patchDefinition.GeneratedFileNames;
                    foreach (var fileNames in ModCompareSelector.Definitions.Select(p => p.GeneratedFileNames))
                    {
                        foreach (var item in fileNames)
                        {
                            generatedFileNames.Add(item);
                        }
                    }
                    patchDefinition.GeneratedFileNames = generatedFileNames;
                    SyncCode(patchDefinition);
                    try
                    {
                        if (resolve ?
                            await modPatchCollectionService.ApplyModPatchAsync(Conflicts, patchDefinition, SelectedModCollection.Name) :
                            await modPatchCollectionService.IgnoreModPatchAsync(Conflicts, patchDefinition, SelectedModCollection.Name))
                        {
                            await FilterHierarchalConflictsAsync(Conflicts);

                            IHierarchicalDefinitions selectedConflict = null;
                            if (conflictParentIdx.HasValue && HierarchalConflicts.Any())
                            {
                                foreach (var item in HierarchalConflicts)
                                {
                                    if (item.Name.Equals(conflictParent.Name))
                                    {
                                        if (conflictParentIdx.Value > (item.Children.Count - 1))
                                        {
                                            conflictParentIdx = item.Children.Count - 1;
                                        }
                                        else if (conflictParentIdx.Value < 0)
                                        {
                                            conflictParentIdx = 0;
                                        }
                                        selectedConflict = item.Children.Select(p => p).ToList()[conflictParentIdx.GetValueOrDefault()];
                                        break;
                                    }
                                }
                            }
                            SelectedConflict = selectedConflict;
                            ResetConflicts.Refresh();
                        }
                    }
                    catch (Exception ex)
                    {
                        var title   = localizationManager.GetResource(LocalizationResources.SavingError.Title);
                        var message = localizationManager.GetResource(LocalizationResources.SavingError.Message);
                        logger.Error(ex);
                        notificationAction.ShowNotification(title, message, NotificationType.Error, 30);
                    }
                }
                if (SelectedConflict == null)
                {
                    if (parentIdx > (HierarchalConflicts.Count() - 1))
                    {
                        parentIdx = HierarchalConflicts.Count() - 1;
                    }
                    else if (parentIdx < 0)
                    {
                        parentIdx = 0;
                    }
                    if (HierarchalConflicts.Any())
                    {
                        SelectedParentConflict = HierarchalConflicts.ElementAt(parentIdx);
                    }
                }
                await TriggerOverlayAsync(id, false);
            }
            ResolvingConflict = false;
        }
コード例 #2
0
        /// <summary>
        /// Called when [activated].
        /// </summary>
        /// <param name="disposables">The disposables.</param>
        protected override void OnActivated(CompositeDisposable disposables)
        {
            var resolvingEnabled = this.WhenAnyValue(v => v.ResolvingConflict, v => !v);

            BackCommand = ReactiveCommand.Create(() =>
            {
                Conflicts?.Dispose();
                Conflicts             = null;
                SelectedModsOrder     = null;
                SelectedModCollection = null;
                var args = new NavigationEventArgs()
                {
                    State = NavigationState.Main
                };
                ReactiveUI.MessageBus.Current.SendMessage(args);
            }).DisposeWith(disposables);

            ResolveCommand = ReactiveCommand.Create(() =>
            {
                ResolveConflictAsync(true).ConfigureAwait(true);
            }, resolvingEnabled).DisposeWith(disposables);

            IgnoreCommand = ReactiveCommand.Create(() =>
            {
                ResolveConflictAsync(false).ConfigureAwait(true);
            }, resolvingEnabled).DisposeWith(disposables);

            InvalidOpenDirectoryCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                if (!string.IsNullOrWhiteSpace(InvalidConflictPath))
                {
                    await appAction.OpenAsync(Path.GetDirectoryName(InvalidConflictPath));
                }
            }).DisposeWith(disposables);

            InvalidOpenFileCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                if (!string.IsNullOrWhiteSpace(InvalidConflictPath))
                {
                    await appAction.OpenAsync(InvalidConflictPath);
                }
            }).DisposeWith(disposables);

            this.WhenAnyValue(p => p.Conflicts).Subscribe(s =>
            {
                FilterHierarchalConflictsAsync(s).ConfigureAwait(false);
                IgnoreConflictsRules.CollectionName = SelectedModCollection.Name;
                IgnoreConflictsRules.ConflictResult = s;
                ResetConflicts.SetParameters(s, SelectedModCollection.Name);
                DatabaseSearch.SetParameters(s);
                CustomConflicts.SetParameters(s, SelectedModCollection.Name);
                MergeViewer.InitParameters();
            }).DisposeWith(disposables);

            this.WhenAnyValue(v => v.SelectedParentConflict).Subscribe(s =>
            {
                IsConflictSolverAvailable = !(s?.Key == InvalidKey);
                EvalViewerVisibility();
            }).DisposeWith(disposables);

            this.WhenAnyValue(v => v.SelectedConflict).Subscribe(s =>
            {
                if (Conflicts?.Conflicts != null && !string.IsNullOrWhiteSpace(s?.Key) && IsConflictSolverAvailable)
                {
                    PreviousConflictIndex = SelectedParentConflict.Children.ToList().IndexOf(s);
                    var conflicts         = Conflicts.Conflicts.GetByTypeAndId(s.Key).ToObservableCollection();
                    ModCompareSelector.SelectedModsOrder = SelectedModsOrder;
                    ModCompareSelector.CollectionName    = SelectedModCollection.Name;
                    ModCompareSelector.IsBinaryConflict  = IsBinaryConflict = conflicts?.FirstOrDefault()?.ValueType == ValueType.Binary;
                    ModCompareSelector.Definitions       = conflicts;
                    MergeViewer.SetSidePatchMod(modPatchCollectionService.IsPatchMod(ModCompareSelector.LeftSelectedDefinition?.ModName), modPatchCollectionService.IsPatchMod(ModCompareSelector.RightSelectedDefinition?.ModName));
                    MergeViewer.SetText(string.Empty, string.Empty, true);
                    MergeViewer.ExitEditMode();
                    EvalViewerVisibility();
                    IgnoreEnabled = true;
                }
                else
                {
                    if (HierarchalConflicts == null || !HierarchalConflicts.Any())
                    {
                        ModCompareSelector.Reset();
                        BinaryMergeViewer.Reset();
                        MergeViewer.SetText(string.Empty, string.Empty, true);
                    }
                    PreviousConflictIndex = null;
                    IgnoreEnabled         = false;
                }
            }).DisposeWith(disposables);

            this.WhenAnyValue(v => v.ModCompareSelector.IsActivated).Where(p => p).Subscribe(s =>
            {
                this.WhenAnyValue(v => v.ModCompareSelector.LeftSelectedDefinition).Subscribe(s =>
                {
                    if (s != null && IsConflictSolverAvailable)
                    {
                        MergeViewer.EditingYaml = s.Type.StartsWith(Shared.Constants.LocalizationDirectory);
                        MergeViewer.SetSidePatchMod(modPatchCollectionService.IsPatchMod(ModCompareSelector.LeftSelectedDefinition?.ModName), modPatchCollectionService.IsPatchMod(ModCompareSelector.RightSelectedDefinition?.ModName));
                        MergeViewer.SetText(s.Code, MergeViewer.RightSide);
                        MergeViewer.ExitEditMode();
                        if (!IsBinaryConflict)
                        {
                            BinaryMergeViewer.EnableSelection = ResolveEnabled = ModCompareSelector.LeftSelectedDefinition != null &&
                                                                                 ModCompareSelector.RightSelectedDefinition != null &&
                                                                                 ModCompareSelector.LeftSelectedDefinition != ModCompareSelector.RightSelectedDefinition &&
                                                                                 (modPatchCollectionService.IsPatchMod(ModCompareSelector.LeftSelectedDefinition.ModName) || modPatchCollectionService.IsPatchMod(ModCompareSelector.RightSelectedDefinition.ModName));
                        }
                        else
                        {
                            BinaryMergeViewer.Reset(false);
                            ResolveEnabled = false;
                            BinaryMergeViewer.EnableSelection = ModCompareSelector.LeftSelectedDefinition != null &&
                                                                ModCompareSelector.RightSelectedDefinition != null &&
                                                                ModCompareSelector.LeftSelectedDefinition != ModCompareSelector.RightSelectedDefinition;
                            BinaryMergeViewer.SetLeft(s);
                        }
                    }
                    else
                    {
                        BinaryMergeViewer.Reset();
                        ResolveEnabled = false;
                    }
                }).DisposeWith(disposables);

                this.WhenAnyValue(v => v.ModCompareSelector.RightSelectedDefinition).Subscribe(s =>
                {
                    if (s != null && IsConflictSolverAvailable)
                    {
                        MergeViewer.EditingYaml = s.Type.StartsWith(Shared.Constants.LocalizationDirectory);
                        MergeViewer.SetSidePatchMod(modPatchCollectionService.IsPatchMod(ModCompareSelector.LeftSelectedDefinition?.ModName), modPatchCollectionService.IsPatchMod(ModCompareSelector.RightSelectedDefinition?.ModName));
                        MergeViewer.SetText(MergeViewer.LeftSide, s.Code);
                        MergeViewer.ExitEditMode();
                        if (!IsBinaryConflict)
                        {
                            BinaryMergeViewer.EnableSelection = ResolveEnabled = ModCompareSelector.LeftSelectedDefinition != null &&
                                                                                 ModCompareSelector.RightSelectedDefinition != null &&
                                                                                 ModCompareSelector.LeftSelectedDefinition != ModCompareSelector.RightSelectedDefinition &&
                                                                                 (modPatchCollectionService.IsPatchMod(ModCompareSelector.LeftSelectedDefinition.ModName) || modPatchCollectionService.IsPatchMod(ModCompareSelector.RightSelectedDefinition.ModName));
                        }
                        else
                        {
                            BinaryMergeViewer.Reset(false);
                            ResolveEnabled = false;
                            BinaryMergeViewer.EnableSelection = ModCompareSelector.LeftSelectedDefinition != null &&
                                                                ModCompareSelector.RightSelectedDefinition != null &&
                                                                ModCompareSelector.LeftSelectedDefinition != ModCompareSelector.RightSelectedDefinition;
                            BinaryMergeViewer.SetRight(s);
                        }
                    }
                    else
                    {
                        BinaryMergeViewer.Reset();
                        ResolveEnabled = false;
                    }
                }).DisposeWith(disposables);
            }).DisposeWith(disposables);

            this.WhenAnyValue(v => v.BinaryMergeViewer.IsActivated).Where(p => p).Subscribe(s =>
            {
                Observable.Merge(BinaryMergeViewer.TakeLeftCommand.Select(s => true), BinaryMergeViewer.TakeRightCommand.Select(s => false)).Subscribe(s =>
                {
                    takeLeftBinary = s;
                    ResolveEnabled = true;
                }).DisposeWith(disposables);
            }).DisposeWith(disposables);

            this.WhenAnyValue(p => p.MergeViewer.LeftSide).Where(p => !string.IsNullOrWhiteSpace(p)).Subscribe(s =>
            {
                if (MergeViewer.LeftSidePatchMod)
                {
                    var patchDefinition = ModCompareSelector.VirtualDefinitions.FirstOrDefault(p => modPatchCollectionService.IsPatchMod(p.ModName));
                    SyncCode(patchDefinition);
                }
            }).DisposeWith(disposables);

            this.WhenAnyValue(p => p.MergeViewer.RightSide).Where(p => !string.IsNullOrWhiteSpace(p)).Subscribe(s =>
            {
                if (MergeViewer.RightSidePatchMod)
                {
                    var patchDefinition = ModCompareSelector.VirtualDefinitions.FirstOrDefault(p => modPatchCollectionService.IsPatchMod(p.ModName));
                    SyncCode(patchDefinition);
                }
            }).DisposeWith(disposables);

            this.WhenAnyValue(v => v.IgnoreConflictsRules.IsActivated).Where(p => p).Subscribe(s =>
            {
                Observable.Merge(IgnoreConflictsRules.SaveCommand, IgnoreConflictsRules.CancelCommand).Subscribe(result =>
                {
                    switch (result.State)
                    {
                    case Implementation.CommandState.Success:
                        EditingIgnoreConflictsRules = false;
                        FilterHierarchalConflictsAsync(Conflicts, SelectedConflict).ConfigureAwait(false);
                        break;

                    case Implementation.CommandState.NotExecuted:
                        EditingIgnoreConflictsRules = false;
                        break;

                    default:
                        break;
                    }
                }).DisposeWith(disposables);
            }).DisposeWith(disposables);

            IgnoreRulesCommand = ReactiveCommand.Create(() =>
            {
                EditingIgnoreConflictsRules = true;
            }).DisposeWith(disposables);

            InvalidCustomPatchCommand = ReactiveCommand.Create(() =>
            {
                if (HoveredDefinition.AdditionalData is IDefinition definition)
                {
                    CustomConflicts.SetContent(definition.File, definition.Code);
                }
            }).DisposeWith(disposables);

            this.WhenAnyValue(p => p.ModFilter.IsActivated).Where(p => p).Subscribe(s =>
            {
                ModFilter.SetConflictResult(Conflicts, SelectedModsOrder.ToList(), SelectedModCollection.Name);
                this.WhenAnyValue(p => p.ModFilter.HasSavedState).Where(p => p).Subscribe(s =>
                {
                    FilterHierarchalConflictsAsync(Conflicts, SelectedConflict).ConfigureAwait(false);
                }).DisposeWith(disposables);
            }).DisposeWith(disposables);

            this.WhenAnyValue(p => p.ResetConflicts.IsActivated).Where(p => p).Subscribe(s =>
            {
                ResetConflicts.ResetCommand.Subscribe(s =>
                {
                    if (s.State == Implementation.CommandState.Success)
                    {
                        FilterHierarchalConflictsAsync(Conflicts, SelectedConflict).ConfigureAwait(false);
                    }
                }).DisposeWith(disposables);
            }).DisposeWith(disposables);

            this.WhenAnyValue(p => p.CustomConflicts.Saved).Where(p => p).Subscribe(s =>
            {
                ResetConflicts.Refresh();
            }).DisposeWith(disposables);

            base.OnActivated(disposables);
        }