Ejemplo n.º 1
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     if (disposed)
     {
         return;
     }
     GC.SuppressFinalize(this);
     disposed = true;
     AllConflicts?.Dispose();
     Conflicts?.Dispose();
     IgnoredConflicts?.Dispose();
     OrphanConflicts?.Dispose();
     ResolvedConflicts?.Dispose();
     RuleIgnoredConflicts?.Dispose();
     OverwrittenConflicts?.Dispose();
     CustomConflicts?.Dispose();
     AllConflicts         = null;
     Conflicts            = null;
     IgnoredConflicts     = null;
     ResolvedConflicts    = null;
     OrphanConflicts      = null;
     RuleIgnoredConflicts = null;
     OverwrittenConflicts = null;
     CustomConflicts      = null;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     if (disposed)
     {
         return;
     }
     disposed = true;
     AllConflicts?.Dispose();
     Conflicts?.Dispose();
     IgnoredConflicts?.Dispose();
     OrphanConflicts?.Dispose();
     ResolvedConflicts?.Dispose();
     RuleIgnoredConflicts?.Dispose();
     OverwrittenConflicts?.Dispose();
     CustomConflicts?.Dispose();
     AllConflicts         = null;
     Conflicts            = null;
     IgnoredConflicts     = null;
     ResolvedConflicts    = null;
     OrphanConflicts      = null;
     RuleIgnoredConflicts = null;
     OverwrittenConflicts = null;
     CustomConflicts      = null;
 }
Ejemplo n.º 3
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);
        }