Esempio n. 1
0
 public CliPatcherInitVm(
     IPatcherNameVm nameVm,
     IPatcherInitializationVm init,
     IShowHelpSetting showHelpSetting,
     IPathToExecutableInputVm executableInputVm,
     IPatcherFactory factory)
 {
     _init                     = init;
     Factory                   = factory;
     NameVm                    = nameVm;
     ShowHelpSetting           = showHelpSetting;
     ExecutableInput           = executableInputVm;
     _canCompleteConfiguration = executableInputVm.WhenAnyValue(x => x.Picker.ErrorState)
                                 .Cast <ErrorResponse, ErrorResponse>()
                                 .ToGuiProperty(this, nameof(CanCompleteConfiguration), ErrorResponse.Success);
 }
Esempio n. 2
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 !));
            })
Esempio n. 3
0
        public GitPatcherInitVm(
            IPatcherInitializationVm init,
            ILogger logger,
            IPatcherFactory patcherFactory,
            INavigateTo navigateTo,
            IPathSanitation pathSanitation,
            PatcherStoreListingVm.Factory listingVmFactory,
            IRegistryListingsProvider listingsProvider,
            PatcherInitRenameValidator renamer)
        {
            _init           = init;
            _patcherFactory = patcherFactory;
            _renamer        = renamer;
            _pathSanitation = pathSanitation;
            Patcher         = patcherFactory.GetGitPatcher();

            _canCompleteConfiguration = this.WhenAnyValue(x => x.Patcher.RepoClonesValid.Valid)
                                        .Select(x => ErrorResponse.Create(x))
                                        .ToGuiProperty(this, nameof(CanCompleteConfiguration), ErrorResponse.Success);

            PatcherRepos = Observable.Return(Unit.Default)
                           .ObserveOn(RxApp.TaskpoolScheduler)
                           .SelectTask(async _ =>
            {
                try
                {
                    var customization = listingsProvider.Get(CancellationToken.None);

                    if (customization.Failed)
                    {
                        return(Observable.Empty <IChangeSet <PatcherStoreListingVm> >());
                    }

                    return(customization.Value
                           .SelectMany(repo =>
                    {
                        return repo.Patchers
                        .Select(p =>
                        {
                            return listingVmFactory(this, p, repo);
                        });
                    })
                           .AsObservableChangeSet());
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Error downloading patcher listing");
                    Error = ErrorResponse.Fail(ex);
                }
                return(Observable.Empty <IChangeSet <PatcherStoreListingVm> >());
            })
                           .Switch()
                           .Sort(Comparer <PatcherStoreListingVm> .Create((x, y) => x.Name.CompareTo(y.Name)))
                           .Filter(this.WhenAnyValue(x => x.ShowAll)
                                   .DistinctUntilChanged()
                                   .Select(show => new Func <PatcherStoreListingVm, bool>(
                                               (p) =>
            {
                if (p.Raw.Customization?.Visibility is VisibilityOptions.Visible)
                {
                    return(true);
                }
                else if (p.Raw.Customization?.Visibility is VisibilityOptions.IncludeButHide)
                {
                    return(show);
                }
                else if (p.Raw.Customization?.Visibility is VisibilityOptions.Exclude)
                {
                    return(false);                                                                               // just in case.
                }
                else
                {
                    return(true);
                }
            })))
                           .Filter(this.WhenAnyValue(x => x.Search)
                                   .Debounce(TimeSpan.FromMilliseconds(350), RxApp.MainThreadScheduler)
                                   .Select(x => x.Trim())
                                   .DistinctUntilChanged()
                                   .Select(search =>
            {
                if (string.IsNullOrWhiteSpace(search))
                {
                    return(new Func <PatcherStoreListingVm, bool>(_ => true));
                }
                return(new Func <PatcherStoreListingVm, bool>(
                           (p) =>
                {
                    if (p.Name.Contains(search, StringComparison.OrdinalIgnoreCase))
                    {
                        return true;
                    }
                    if (p.Raw.Customization?.OneLineDescription?.Contains(search, StringComparison.OrdinalIgnoreCase) ?? false)
                    {
                        return true;
                    }
                    return false;
                }));
            }))
                           .ObserveOn(RxApp.MainThreadScheduler)
                           .ToObservableCollection(this);

            OpenPopulationInfoCommand = ReactiveCommand.Create(() => navigateTo.Navigate(Constants.ListingRepositoryAddress));
            ClearSearchCommand        = ReactiveCommand.Create(() => Search = string.Empty);
        }