Exemplo n.º 1
0
        /// <summary>
        /// check for updates as an asynchronous operation.
        /// </summary>
        /// <param name="autoUpdateCheck">if set to <c>true</c> [automatic update check].</param>
        protected virtual async Task CheckForUpdatesAsync(bool autoUpdateCheck = false)
        {
            CheckingForUpdates = true;
            UpdateInfoVisible  = false;
            var updatesAvailable = await updater.CheckForUpdatesAsync();

            if (updatesAvailable)
            {
                Changelog         = updater.GetChangeLog();
                VersionContent    = updater.GetVersion();
                UpdateInfoVisible = true;
                var openState = IsOpen;
                IsOpen = false;
                IsOpen = openState;
                if (autoUpdateCheck)
                {
                    var title   = localizationManager.GetResource(LocalizationResources.Options.Updates.UpdateNotification.Title);
                    var message = localizationManager.GetResource(LocalizationResources.Options.Updates.UpdateNotification.Message);
                    notificationAction.ShowNotification(title, message, NotificationType.Info, 30, onClick: () => { IsOpen = true; });
                }
            }
            else
            {
                if (!autoUpdateCheck)
                {
                    var title   = localizationManager.GetResource(LocalizationResources.Notifications.NoUpdatesAvailable.Title);
                    var message = localizationManager.GetResource(LocalizationResources.Notifications.NoUpdatesAvailable.Message);
                    notificationAction.ShowNotification(title, message, NotificationType.Info);
                }
            }
            CheckingForUpdates = false;
        }
        /// <summary>
        /// check new mods as an asynchronous operation.
        /// </summary>
        protected virtual async Task CheckNewModsAsync()
        {
            await TriggerOverlayAsync(true, message : localizationManager.GetResource(LocalizationResources.Installed_Mods.RefreshingModList));

            await modService.InstallModsAsync();

            RefreshMods();
            var title   = localizationManager.GetResource(LocalizationResources.Notifications.NewDescriptorsChecked.Title);
            var message = localizationManager.GetResource(LocalizationResources.Notifications.NewDescriptorsChecked.Message);

            notificationAction.ShowNotification(title, message, NotificationType.Info);
            await TriggerOverlayAsync(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// check new mods as an asynchronous operation.
        /// </summary>
        protected virtual async Task CheckNewModsAsync()
        {
            var id = idGenerator.GetNextId();

            await TriggerOverlayAsync(id, true, message : localizationManager.GetResource(LocalizationResources.Installed_Mods.RefreshingModList));

            var result = await modService.InstallModsAsync(Mods);

            if (result != null && result.Any(p => p.Invalid))
            {
                await ShowInvalidModsNotificationAsync(result.Where(p => p.Invalid).ToList());
            }
            RefreshMods();
            var title   = localizationManager.GetResource(LocalizationResources.Notifications.NewDescriptorsChecked.Title);
            var message = localizationManager.GetResource(LocalizationResources.Notifications.NewDescriptorsChecked.Message);

            notificationAction.ShowNotification(title, message, NotificationType.Info);
            await TriggerOverlayAsync(id, false);
        }
        /// <summary>
        /// apply collection as an asynchronous operation.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <param name="showOverlay">if set to <c>true</c> [show overlay].</param>
        protected virtual async Task ApplyCollectionAsync(long id, bool showOverlay = true)
        {
            if (ApplyingCollection)
            {
                return;
            }
            ApplyingCollection = true;
            if (CollectionMods.SelectedModCollection != null)
            {
                if (showOverlay)
                {
                    await TriggerOverlayAsync(id, true, localizationManager.GetResource(LocalizationResources.Mod_Actions.Overlay_Apply_Message));
                }
                var notificationType = NotificationType.Success;
                try
                {
                    var result = await modService.ExportModsAsync(CollectionMods.SelectedMods.ToList(), InstalledMods.AllMods.ToList(), CollectionMods.SelectedModCollection.Name);

                    string title;
                    string message;
                    if (result)
                    {
                        title   = localizationManager.GetResource(LocalizationResources.Notifications.CollectionApplied.Title);
                        message = Smart.Format(localizationManager.GetResource(LocalizationResources.Notifications.CollectionApplied.Message), new { CollectionName = CollectionMods.SelectedModCollection.Name });
                    }
                    else
                    {
                        title            = localizationManager.GetResource(LocalizationResources.Notifications.CollectionNotApplied.Title);
                        message          = Smart.Format(localizationManager.GetResource(LocalizationResources.Notifications.CollectionNotApplied.Message), new { CollectionName = CollectionMods.SelectedModCollection.Name });
                        notificationType = NotificationType.Error;
                    }
                    notificationAction.ShowNotification(title, message, notificationType, 5);
                }
                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 (showOverlay)
                {
                    await TriggerOverlayAsync(id, false);
                }
            }
            ApplyingCollection = false;
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Called when [activated].
        /// </summary>
        /// <param name="disposables">The disposables.</param>
        protected override void OnActivated(CompositeDisposable disposables)
        {
            var saveEnabled = this.WhenAnyValue(v => v.AllowSave, v => v == true);
            var loadEnabled = this.WhenAnyValue(v => v.AllowLoad, v => v == true);

            this.WhenAnyValue(v => v.Path).Subscribe(s =>
            {
                EvalConditions();
            }).DisposeWith(disposables);

            this.WhenAnyValue(v => v.CurrentEditText).Subscribe(s =>
            {
                EvalConditions();
            }).DisposeWith(disposables);

            CloseCommand = ReactiveCommand.Create(() =>
            {
                ForceClosePopup();
            }).DisposeWith(disposables);

            CustomPatchCommand = ReactiveCommand.Create(() =>
            {
                Document = new TextDocument(CurrentEditText ?? string.Empty);
                IsOpen   = true;
            }).DisposeWith(disposables);

            SaveCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                var definition = InitDefinition();
                if (ConflictResult.CustomConflicts.GetByFile(Path.StandardizeDirectorySeparator()).Any())
                {
                    await modPatchCollectionService.ResetCustomConflictAsync(ConflictResult, definition.TypeAndId, CollectionName);
                }
                if (await modPatchCollectionService.AddCustomModPatchAsync(ConflictResult, definition, CollectionName))
                {
                    if (!promptShown && ConflictResult.AllConflicts.GetByFile(definition.FileCI).Any())
                    {
                        promptShown = true;
                        var title   = localizationManager.GetResource(LocalizationResources.Notifications.CustomPatchRerunConflictSolver.Title);
                        var message = localizationManager.GetResource(LocalizationResources.Notifications.CustomPatchRerunConflictSolver.Message);
                        notificationAction.ShowNotification(title, message, NotificationType.Warning, 10);
                    }
                    Saved           = true;
                    Saved           = false;
                    Path            = string.Empty;
                    CurrentEditText = string.Empty;
                    Document        = new TextDocument(CurrentEditText);
                }
            }, saveEnabled).DisposeWith(disposables);

            LoadCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                var definition = ConflictResult.CustomConflicts.GetByFile(Path.StandardizeDirectorySeparator()).FirstOrDefault();
                if (definition != null)
                {
                    var code        = await modPatchCollectionService.LoadDefinitionContentsAsync(definition, CollectionName);
                    CurrentEditText = code;
                    Document        = new TextDocument(CurrentEditText ?? string.Empty);
                }
            }, loadEnabled).DisposeWith(disposables);

            base.OnActivated(disposables);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Called when [activated].
        /// </summary>
        /// <param name="disposables">The disposables.</param>
        protected override void OnActivated(CompositeDisposable disposables)
        {
            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))
                    {
                        var id = idGenerator.GetNextId();
                        await TriggerOverlayAsync(id, true, localizationManager.GetResource(LocalizationResources.Collection_Mods.Overlay_Duplicate_Message));
                        await Task.Run(async() =>
                        {
                            await modPatchCollectionService.CopyPatchCollectionAsync(ActiveCollection.Name, copy.Name).ConfigureAwait(false);
                        }).ConfigureAwait(false);
                        await TriggerOverlayAsync(id, 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);

            MergeBasicCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                if (ActiveCollection != null && ActiveCollection.Mods?.Count() > 0)
                {
                    var copy = await GetMergedCollectionAsync();
                    var id   = idGenerator.GetNextId();

                    await TriggerOverlayAsync(id, 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(id, disposables, MergeType.Basic);

                    var overlayProgress = Smart.Format(localizationManager.GetResource(LocalizationResources.Collection_Mods.MergeCollection.Overlay_Progress), new
                    {
                        PercentDone = 0.ToLocalizedPercentage(),
                        Count       = 1,
                        TotalCount  = 3
                    });
                    var message = localizationManager.GetResource(LocalizationResources.Collection_Mods.MergeCollection.DiskInfoOverlay);
                    await TriggerOverlayAsync(id, true, message, overlayProgress);

                    var result = await Task.Run(async() => await modMergeService.HasEnoughFreeSpaceAsync(copy.Name));
                    if (!result)
                    {
                        var notiTitle   = localizationManager.GetResource(LocalizationResources.Notifications.CollectionMergeNotEnoughSpace.Title);
                        var notiMessage = localizationManager.GetResource(LocalizationResources.Notifications.CollectionMergeNotEnoughSpace.Message);
                        await TriggerOverlayAsync(id, false);
                        freeSpaceCheckHandler?.Dispose();
                        fileMergeProgressHandler?.Dispose();
                        notificationAction.ShowNotification(notiTitle, notiMessage, NotificationType.Error, 10);
                        return(new CommandResult <ModifyAction>(ModifyAction.Merge, CommandState.Failed));
                    }

                    await modPatchCollectionService.CleanPatchCollectionAsync(copy.Name);

                    var mergeMod = await Task.Run(async() =>
                    {
                        return(await modMergeService.MergeCollectionByFilesAsync(copy.Name));
                    }).ConfigureAwait(false);
                    copy.Mods = new List <string>()
                    {
                        mergeMod.DescriptorFile
                    };

                    await TriggerOverlayAsync(id, false);
                    freeSpaceCheckHandler?.Dispose();
                    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);

            MergeCompressCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                if (ActiveCollection != null && ActiveCollection.Mods?.Count() > 0)
                {
                    var copy = await GetMergedCollectionAsync();
                    var id   = idGenerator.GetNextId();

                    await TriggerOverlayAsync(id, 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(id, disposables, MergeType.Compress);

                    var overlayProgress = Smart.Format(localizationManager.GetResource(LocalizationResources.Collection_Mods.MergeCollection.Overlay_Progress), new
                    {
                        PercentDone = 0.ToLocalizedPercentage(),
                        Count       = 1,
                        TotalCount  = 3
                    });
                    var message = localizationManager.GetResource(LocalizationResources.Collection_Mods.MergeCollection.DiskInfoOverlay);
                    await TriggerOverlayAsync(id, true, message, overlayProgress);

                    var result = await Task.Run(async() => await modMergeService.HasEnoughFreeSpaceAsync(copy.Name));
                    if (!result)
                    {
                        var notiTitle   = localizationManager.GetResource(LocalizationResources.Notifications.CollectionMergeNotEnoughSpace.Title);
                        var notiMessage = localizationManager.GetResource(LocalizationResources.Notifications.CollectionMergeNotEnoughSpace.Message);
                        await TriggerOverlayAsync(id, false);
                        freeSpaceCheckHandler?.Dispose();
                        fileMergeProgressHandler?.Dispose();
                        notificationAction.ShowNotification(notiTitle, notiMessage, NotificationType.Error, 10);
                        return(new CommandResult <ModifyAction>(ModifyAction.Merge, CommandState.Failed));
                    }

                    await modPatchCollectionService.CleanPatchCollectionAsync(copy.Name);

                    var mergeMods = await Task.Run(async() =>
                    {
                        return(await modMergeService.MergeCompressCollectionAsync(copy.Name, Smart.Format(localizationManager.GetResource(LocalizationResources.Collection_Mods.MergeCollection.MergeCompressModPrefix), new
                        {
                            Name = copy.Name.Replace($"{localizationManager.GetResource(LocalizationResources.Collection_Mods.MergeCollection.MergedCollectionPrefix)} ", string.Empty)
                        })));
                    }).ConfigureAwait(false);
                    copy.Mods = mergeMods.Select(p => p.DescriptorFile).ToList();

                    await TriggerOverlayAsync(id, false);
                    freeSpaceCheckHandler?.Dispose();
                    fileMergeProgressHandler?.Dispose();

                    modCollectionService.Delete(copy.Name);
                    modPatchCollectionService.InvalidatePatchModState(copy.Name);
                    await modService.InstallModsAsync(null);
                    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);
        }