예제 #1
0
 public NewGroupCreator(
     IProfileGroupsList groupsList,
     Func <GroupVm> groupCreator)
 {
     _groupsList   = groupsList;
     _groupCreator = groupCreator;
 }
 public PatcherInitRenameValidator(
     IProfileGroupsList groupsList,
     IConfirmationPanelControllerVm confirmation)
 {
     _groupsList   = groupsList;
     _confirmation = confirmation;
 }
예제 #3
0
        public PatcherRenameActionVm(
            ILogger logger,
            IPatcherNameVm nameVm,
            IFileSystem fileSystem,
            IPatcherExtraDataPathProvider extraDataPathProvider,
            IProfileGroupsList groupsList)
        {
            _logger                = logger;
            _nameVm                = nameVm;
            _fileSystem            = fileSystem;
            _extraDataPathProvider = extraDataPathProvider;
            Name = nameVm.Name;
            var names = groupsList.Groups.Items
                        .SelectMany(g => g.Patchers.Items)
                        .Select(x => x.NameVm.Name)
                        .ToHashSet(StringComparer.OrdinalIgnoreCase);

            names.Remove(Name);
            ConfirmActionCommand = ReactiveCommand.Create(
                Execute,
                this.WhenAnyValue(x => x.Name).Select(n => !names.Contains(n)));
        }
예제 #4
0
 public SelectedGroupControllerVm(
     IProfileGroupsList groupsList,
     IProfileDisplayControllerVm selected)
 {
     _selectedGroup = Observable.CombineLatest(
         selected.WhenAnyValue(x => x.SelectedObject),
         groupsList.Groups.Connect()
         .ObserveOnGui()
         .QueryWhenChanged(q => q),
         (selected, groups) => selected ?? groups.FirstOrDefault())
                      .Select(x =>
     {
         if (x is GroupVm group)
         {
             return(group);
         }
         if (x is PatcherVm patcher)
         {
             return(patcher.Group);
         }
         return(default(GroupVm?));
     })
                      .ToGuiProperty(this, nameof(SelectedGroup), default(GroupVm?), deferSubscription: true);
 }
예제 #5
0
        public ProfileVm(
            ILifetimeScope scope,
            IPatcherInitializationVm initVm,
            IProfileDataFolderVm dataFolder,
            IProfileIdentifier ident,
            IProfileNameVm nameProvider,
            IProfileLoadOrder loadOrder,
            IProfileDirectories dirs,
            IProfileVersioning versioning,
            IProfileDisplayControllerVm profileDisplay,
            ILockToCurrentVersioning lockSetting,
            ISelectedProfileControllerVm selProfile,
            IProfileExporter exporter,
            IProfileGroupsList groupsList,
            IEnvironmentErrorsVm environmentErrors,
            OverallErrorVm overallErrorVm,
            StartRun startRun,
            ILogger logger)
        {
            Scope              = scope;
            Init               = initVm;
            OverallErrorVm     = overallErrorVm;
            NameVm             = nameProvider;
            Groups             = groupsList.Groups;
            DataFolderOverride = dataFolder;
            Versioning         = versioning;
            LockSetting        = lockSetting;
            Exporter           = exporter;
            DisplayController  = profileDisplay;
            _startRun          = startRun;
            _logger            = logger;
            ID      = ident.ID;
            Release = ident.Release;

            GroupsDisplay = new SourceListUiFunnel <GroupVm>(Groups, this);

            ProfileDirectory = dirs.ProfileDirectory;
            WorkingDirectory = dirs.WorkingDirectory;

            EnvironmentErrors = environmentErrors;

            _dataFolder = dataFolder.WhenAnyValue(x => x.Path)
                          .ToGuiProperty <DirectoryPath>(this, nameof(DataFolder), string.Empty, deferSubscription: true);

            LoadOrder = loadOrder.LoadOrder;

            var enabledGroups = Groups.Connect()
                                .ObserveOnGui()
                                .FilterOnObservable(p => p.WhenAnyValue(x => x.IsOn), scheduler: RxApp.MainThreadScheduler)
                                .RefCount();

            var enabledGroupModKeys = enabledGroups
                                      .Transform(x => x.ModKey)
                                      .QueryWhenChanged(q => q.ToHashSet())
                                      .Replay(1).RefCount();

            _blockingError = Observable.CombineLatest(
                dataFolder.WhenAnyValue(x => x.DataFolderResult),
                loadOrder.WhenAnyValue(x => x.State),
                enabledGroups
                .QueryWhenChanged(q => q)
                .StartWith(Noggog.ListExt.Empty <GroupVm>()),
                enabledGroups
                .FilterOnObservable(g => g.WhenAnyValue(x => x.State).Select(x => x.IsHaltingError))
                .QueryWhenChanged(q => q)
                .StartWith(Noggog.ListExt.Empty <GroupVm>()),
                LoadOrder.Connect()
                .FilterOnObservable(
                    x =>
            {
                return(Observable.CombineLatest(
                           x.WhenAnyValue(y => y.Exists)
                           .DistinctUntilChanged(),
                           enabledGroupModKeys
                           .Select(groupModKeys => groupModKeys.Contains(x.ModKey)),
                           (exists, isEnabledGroupKey) => !exists && !isEnabledGroupKey));
            },
                    scheduler: RxApp.MainThreadScheduler)
                .QueryWhenChanged(q => q)
                .StartWith(Noggog.ListExt.Empty <ReadOnlyModListingVM>())
                .Throttle(TimeSpan.FromMilliseconds(200), RxApp.MainThreadScheduler),
                this.WhenAnyValue(x => x.IgnoreMissingMods),
                (dataFolder, loadOrder, enabledGroups, erroredEnabledGroups, missingMods, ignoreMissingMods) =>
            {
                if (enabledGroups.Count == 0)
                {
                    return(GetResponse <ViewModel> .Fail("There are no enabled groups to run."));
                }
                if (!dataFolder.Succeeded)
                {
                    return(dataFolder.BubbleFailure <ViewModel>());
                }
                if (!loadOrder.Succeeded)
                {
                    return(loadOrder.BubbleFailure <ViewModel>());
                }
                if (!ignoreMissingMods && missingMods.Count > 0)
                {
                    return(GetResponse <ViewModel> .Fail($"Load order had mods that were missing:{Environment.NewLine}{string.Join(Environment.NewLine, missingMods.Select(x => x.ModKey))}"));
                }
                if (erroredEnabledGroups.Count > 0)
                {
                    var errGroup = erroredEnabledGroups.First();
                    return(GetResponse <ViewModel> .Fail(errGroup, $"\"{errGroup.Name}\" has a blocking error: {errGroup.State}"));
                }
                return(GetResponse <ViewModel> .Succeed(null !));
            })
예제 #6
0
        public PatcherInitializationVm(
            ILifetimeScope scope,
            IProfileGroupsList groupsList,
            INewGroupCreator groupCreator,
            ISelectedGroupControllerVm selectedGroupControllerVm,
            IProfileDisplayControllerVm displayControllerVm,
            PatcherInitRenameValidator renamer)
        {
            _scope = scope;
            _selectedGroupControllerVm = selectedGroupControllerVm;
            _displayControllerVm       = displayControllerVm;

            var hasAnyGroups = groupsList.Groups.CountChanged
                               .Select(x => x > 0)
                               .Replay(1)
                               .RefCount();

            AddGitPatcherCommand = ReactiveCommand.Create(
                () => { NewPatcher = Resolve <GitPatcherInitVm, GuiGitPatcherModule, GithubPatcherSettings>(); },
                canExecute: hasAnyGroups);
            AddSolutionPatcherCommand = ReactiveCommand.Create(
                () => { NewPatcher = Resolve <SolutionPatcherInitVm, GuiSolutionPatcherModule, SolutionPatcherSettings>(); },
                hasAnyGroups);
            AddCliPatcherCommand = ReactiveCommand.Create(
                () => { NewPatcher = Resolve <CliPatcherInitVm, GuiCliPatcherModule, CliPatcherSettings>(); },
                hasAnyGroups);
            AddGroupCommand = ReactiveCommand.Create(() =>
            {
                var group = groupCreator.Get();
                groupsList.Groups.Add(group);
                displayControllerVm.SelectedObject = group;
            });
            CompleteConfiguration = ReactiveCommand.CreateFromTask(
                async() =>
            {
                var initializer = this.NewPatcher;
                if (initializer == null)
                {
                    return;
                }
                var list = await initializer.Construct().ToListAsync().ConfigureAwait(false);
                foreach (var item in list)
                {
                    if (!await renamer.ConfirmNameUnique(item))
                    {
                        return;
                    }
                }
                AddNewPatchers(list);
            },
                canExecute: this.WhenAnyValue(x => x.NewPatcher)
                .Select(patcher =>
            {
                if (patcher == null)
                {
                    return(Observable.Return(false));
                }
                return(patcher.WhenAnyValue(x => x.CanCompleteConfiguration)
                       .Select(e => e.Succeeded)
                       .CombineLatest(
                           _selectedGroupControllerVm.WhenAnyValue(x => x.SelectedGroup)
                           .Select(x => x != null),
                           (canComplete, groupExists) => canComplete && groupExists));
            })
                .Switch());

            CancelConfiguration = ReactiveCommand.Create(
                () =>
            {
                NewPatcher?.Cancel();
                NewPatcher = null;
            });

            // Dispose any old patcher initializations
            this.WhenAnyValue(x => x.NewPatcher)
            .DisposePrevious()
            .Subscribe()
            .DisposeWith(this);
        }