Пример #1
0
        public ProfileDisplayVM(ProfilesDisplayVM parent, ProfileVM?profile = null)
        {
            Parent  = parent;
            Profile = profile;

            _IsDisplaying = parent.WhenAnyValue(x => x.DisplayedProfile)
                            .Select(x => x == this)
                            .ToGuiProperty(this, nameof(IsDisplaying));

            _IsActive = this.WhenAnyFallback(x => x.Profile !.IsActive, fallback: false)
                        .ToGuiProperty(this, nameof(IsActive));

            DeleteCommand = ReactiveCommand.Create(
                canExecute: this.WhenAnyFallback(x => x.Profile !.IsActive, fallback: true)
                .Select(active => !active),
                execute: () =>
            {
                var profile = this.Profile;
                if (profile == null || profile.IsActive)
                {
                    return;
                }
                Parent.Config.MainVM.TargetConfirmation = new ConfirmationActionVM(
                    "Confirm",
                    $"Are you sure you want to delete {profile.Nickname}?",
                    () =>
                {
                    parent.Config.Profiles.Remove(profile);
                    Parent.SwitchToActive();
                });
            });
            SwitchToCommand = ReactiveCommand.Create(
                execute: () =>
            {
                var profile = this.Profile;
                if (profile == null || profile.IsActive)
                {
                    return;
                }
                Parent.Config.SelectedProfile = profile;
            });
            OpenInternalProfileFolderCommand = ReactiveCommand.Create(
                execute: () =>
            {
                Utility.NavigateToPath(Profile !.ProfileDirectory);
            },
                canExecute: this.WhenAnyValue(x => x.Profile)
                .Select(x => x != null));
        }
Пример #2
0
        public MainVM(Window window)
        {
            _window = window;
            var dotNet = Observable.Interval(TimeSpan.FromSeconds(10), RxApp.TaskpoolScheduler)
                         .StartWith(0)
                         .SelectTask(async i =>
            {
                try
                {
                    var ret = await DotNetCommands.DotNetSdkVersion(CancellationToken.None);
                    Log.Logger.Information($"dotnet SDK: {ret}");
                    return(ret);
                }
                catch (Exception ex)
                {
                    Log.Logger.Error(ex, $"Error retrieving dotnet SDK version");
                    return(default(Version?));
                }
            });

            DotNetSdkInstalled = dotNet
                                 .Take(1)
                                 .Merge(dotNet
                                        .FirstAsync(v => v != null))
                                 .DistinctUntilChanged()
                                 .Replay(1)
                                 .RefCount();

            Configuration        = new ConfigurationVM(this);
            ActivePanel          = Configuration;
            DiscardActionCommand = NoggogCommand.CreateFromObject(
                objectSource: this.WhenAnyValue(x => x.TargetConfirmation),
                canExecute: target => target != null,
                execute: (_) =>
            {
                TargetConfirmation = null;
            },
                disposable: this.CompositeDisposable);
            ConfirmActionCommand = NoggogCommand.CreateFromObject(
                objectSource: this.WhenAnyFallback(x => x.TargetConfirmation !.ToDo),
                canExecute: toDo => toDo != null,
                execute: toDo =>
            {
                toDo?.Invoke();
                TargetConfirmation = null;
            },
                disposable: this.CompositeDisposable);

            _Hot = this.WhenAnyValue(x => x.ActivePanel)
                   .Select(x =>
            {
                switch (x)
                {
                case ConfigurationVM config:
                    return(config.WhenAnyFallback(x => x.CurrentRun !.Running, fallback: false));

                case PatchersRunVM running:
                    return(running.WhenAnyValue(x => x.Running));

                default:
                    break;
                }
                return(Observable.Return(false));
            })
                   .Switch()
                   .DistinctUntilChanged()
                   .ToGuiProperty(this, nameof(Hot));

            OpenProfilesPageCommand = ReactiveCommand.Create(() =>
            {
                ActivePanel = new ProfilesDisplayVM(Configuration, ActivePanel);
            },
                                                             canExecute: Observable.CombineLatest(
                                                                 this.WhenAnyFallback(x => x.Configuration.CurrentRun !.Running, fallback: false),
                                                                 this.WhenAnyValue(x => x.ActivePanel)
                                                                 .Select(x => x is ProfilesDisplayVM),
                                                                 (running, isProfile) => !running && !isProfile));

            IdeOptions.AddRange(EnumExt.GetValues <IDE>());

            Task.Run(() => Mutagen.Bethesda.WarmupAll.Init()).FireAndForget();

            SynthesisVersion = Mutagen.Bethesda.Synthesis.Versions.SynthesisVersion;
            MutagenVersion   = Mutagen.Bethesda.Synthesis.Versions.MutagenVersion;

            var latestVersions = Observable.Return(Unit.Default)
                                 .ObserveOn(RxApp.TaskpoolScheduler)
                                 .CombineLatest(
                DotNetSdkInstalled,
                (_, v) => v)
                                 .SelectTask(async v =>
            {
                var normalUpdateTask     = GetLatestVersions(v, includePrerelease: false);
                var prereleaseUpdateTask = GetLatestVersions(v, includePrerelease: true);
                await Task.WhenAll(normalUpdateTask, prereleaseUpdateTask);
                return(Normal: await normalUpdateTask, Prerelease: await prereleaseUpdateTask);
            })
                                 .Replay(1)
                                 .RefCount();

            NewestMutagenVersion = Observable.CombineLatest(
                latestVersions,
                this.WhenAnyFallback(x => x.Configuration.SelectedProfile !.ConsiderPrereleaseNugets),
                (vers, prereleases) => prereleases ? vers.Prerelease.MutagenVersion : vers.Normal.MutagenVersion)
                                   .Replay(1)
                                   .RefCount();
            NewestSynthesisVersion = Observable.CombineLatest(
                latestVersions,
                this.WhenAnyFallback(x => x.Configuration.SelectedProfile !.ConsiderPrereleaseNugets),
                (vers, prereleases) => prereleases ? vers.Prerelease.SynthesisVersion : vers.Normal.SynthesisVersion)
                                     .Replay(1)
                                     .RefCount();

            // Switch to DotNet screen if missing
            DotNetSdkInstalled
            .Subscribe(v =>
            {
                if (v == null)
                {
                    ActivePanel = new DotNetNotInstalledVM(this, this.ActivePanel, DotNetSdkInstalled);
                }
            });

            _ActiveConfirmation = Observable.CombineLatest(
                this.WhenAnyFallback(x => x.Configuration.SelectedProfile !.SelectedPatcher)
                .Select(x =>
            {
                if (x is not GitPatcherVM gitPatcher)
                {
                    return(Observable.Return(default(GitPatcherVM?)));
                }
                return(gitPatcher.WhenAnyValue(x => x.PatcherSettings.SettingsOpen)
                       .Select(open => open ? (GitPatcherVM?)gitPatcher : null));
            })
                .Switch(),
                this.WhenAnyValue(x => x.TargetConfirmation),
                (openPatcher, target) =>
            {
                if (target != null)
                {
                    return(target);
                }
                if (openPatcher == null)
                {
                    return(default(ConfirmationActionVM?));
                }
                return(new ConfirmationActionVM(
                           "External Patcher Settings Open",
                           $"{openPatcher.Nickname} is open for settings manipulation.",
                           toDo: null));
            })
                                  .ToGuiProperty(this, nameof(ActiveConfirmation), default(ConfirmationActionVM?));

            _InModal = this.WhenAnyValue(x => x.ActiveConfirmation)
                       .Select(x => x != null)
                       .ToGuiProperty(this, nameof(InModal));
        }
Пример #3
0
        public MainVM()
        {
            var dotNet = Observable.Interval(TimeSpan.FromSeconds(10), RxApp.TaskpoolScheduler)
                         .StartWith(0)
                         .SelectTask(async i =>
            {
                try
                {
                    var ret = await DotNetQueries.DotNetSdkVersion();
                    Log.Logger.Information($"dotnet SDK: {ret}");
                    return(ret);
                }
                catch (Exception ex)
                {
                    Log.Logger.Error(ex, $"Error retrieving dotnet SDK version");
                    return(default(Version?));
                }
            });

            DotNetSdkInstalled = dotNet
                                 .Take(1)
                                 .Merge(dotNet
                                        .FirstAsync(v => v != null))
                                 .DistinctUntilChanged()
                                 .Replay(1)
                                 .RefCount();

            Configuration        = new ConfigurationVM(this);
            ActivePanel          = Configuration;
            DiscardActionCommand = ReactiveCommand.Create(() => ActiveConfirmation = null);
            ConfirmActionCommand = ReactiveCommand.Create(
                () =>
            {
                if (ActiveConfirmation == null)
                {
                    return;
                }
                ActiveConfirmation.ToDo();
                ActiveConfirmation = null;
            });

            _Hot = this.WhenAnyValue(x => x.ActivePanel)
                   .Select(x =>
            {
                switch (x)
                {
                case ConfigurationVM config:
                    return(config.WhenAnyFallback(x => x.CurrentRun !.Running, fallback: false));

                case PatchersRunVM running:
                    return(running.WhenAnyValue(x => x.Running));

                default:
                    break;
                }
                return(Observable.Return(false));
            })
                   .Switch()
                   .DistinctUntilChanged()
                   .ToGuiProperty(this, nameof(Hot));

            OpenProfilesPageCommand = ReactiveCommand.Create(() =>
            {
                ActivePanel = new ProfilesDisplayVM(Configuration, ActivePanel);
            },
                                                             canExecute: Observable.CombineLatest(
                                                                 this.WhenAnyFallback(x => x.Configuration.CurrentRun !.Running, fallback: false),
                                                                 this.WhenAnyValue(x => x.ActivePanel)
                                                                 .Select(x => x is ProfilesDisplayVM),
                                                                 (running, isProfile) => !running && !isProfile));

            IdeOptions.AddRange(EnumExt.GetValues <IDE>());

            Task.Run(() => Mutagen.Bethesda.WarmupAll.Init()).FireAndForget();

            SynthesisVersion = Mutagen.Bethesda.Synthesis.Versions.SynthesisVersion;
            MutagenVersion   = Mutagen.Bethesda.Synthesis.Versions.MutagenVersion;

            var latestVersions = Observable.Return(Unit.Default)
                                 .ObserveOn(RxApp.TaskpoolScheduler)
                                 .CombineLatest(
                DotNetSdkInstalled,
                (_, v) => v)
                                 .SelectTask(GetLatestVersions)
                                 .Replay(1)
                                 .RefCount();

            NewestMutagenVersion = latestVersions
                                   .Select(x => x.MutagenVersion);
            NewestSynthesisVersion = latestVersions
                                     .Select(x => x.SynthesisVersion);

            // Switch to DotNet screen if missing
            DotNetSdkInstalled
            .Subscribe(v =>
            {
                if (v == null)
                {
                    ActivePanel = new DotNetNotInstalledVM(this, this.ActivePanel, DotNetSdkInstalled);
                }
            });
        }