Пример #1
0
 public PatcherStoreListingVM(GitPatcherInitVM gitInit, PatcherListing listing, RepositoryStoreListingVM repo)
 {
     Repository = repo;
     Raw        = listing;
     try
     {
         Name = Raw.Customization?.Nickname ?? Path.GetFileName(Raw.ProjectPath).TrimEnd(".csproj");
     }
     catch (Exception)
     {
         Name = "Error";
     }
     _IsSelected = gitInit.WhenAnyValue(x => x.SelectedPatcher)
                   .Select(x => x == this)
                   .ToGuiProperty(this, nameof(IsSelected));
     OpenWebsite = ReactiveCommand.Create(() => Utility.NavigateToPath(RepoPath));
     AddCommand  = ReactiveCommand.Create(() =>
     {
         gitInit.AddStorePatcher(this);
     });
 }
Пример #2
0
        public GitPatcherInitVM(ProfileVM profile)
            : base(profile)
        {
            Patcher = new GitPatcherVM(profile);

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

            PatcherRepos = Observable.Return(Unit.Default)
                           .ObserveOn(RxApp.TaskpoolScheduler)
                           .SelectTask(async _ =>
            {
                try
                {
                    var localRepoPath = await GitUtility.CheckOrCloneRepo(
                        GetResponse <string> .Succeed("https://github.com/Mutagen-Modding/Synthesis.Registry"),
                        Paths.RegistryFolder,
                        Log.Logger.Error,
                        CancellationToken.None);
                    if (localRepoPath.Failed)
                    {
                        Error = localRepoPath;
                        return(Observable.Empty <IChangeSet <PatcherStoreListingVM> >());
                    }
                    using var repo = new Repository(localRepoPath.Value.Local);

                    var master = repo.Branches.Where(b => b.IsCurrentRepositoryHead).FirstOrDefault();
                    if (master == null)
                    {
                        Error = ErrorResponse.Fail("Could not find master branch");
                        Log.Logger.Error(Error.Reason);
                        return(Observable.Empty <IChangeSet <PatcherStoreListingVM> >());
                    }
                    repo.Reset(ResetMode.Hard, repo.Branches[$"{master.RemoteName}/{master.FriendlyName}"].Tip);

                    var listingPath = Path.Combine(repo.Info.WorkingDirectory, Constants.AutomaticListingFileName);
                    if (!File.Exists(listingPath))
                    {
                        Error = ErrorResponse.Fail("Could not locate listing file");
                        Log.Logger.Error(Error.Reason);
                        return(Observable.Empty <IChangeSet <PatcherStoreListingVM> >());
                    }
                    var settings = new JsonSerializerOptions();
                    settings.Converters.Add(new JsonStringEnumConverter());
                    var customization = JsonSerializer.Deserialize <MutagenPatchersListing>(File.ReadAllText(listingPath), settings) !;
                    return(customization.Repositories
                           .NotNull()
                           .SelectMany(repo =>
                    {
                        var repoVM = new RepositoryStoreListingVM(repo);
                        return repo.Patchers
                        .Select(p =>
                        {
                            return new PatcherStoreListingVM(this, p, repoVM);
                        });
                    })
                           .AsObservableChangeSet());
                }
                catch (Exception ex)
                {
                    Log.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;
                }));
            }))
                           .ToObservableCollection(this);

            OpenPopulationInfoCommand = ReactiveCommand.Create(() => Utility.NavigateToPath(Constants.ListingRepositoryAddress));
            ClearSearchCommand        = ReactiveCommand.Create(() => Search = string.Empty);
        }
Пример #3
0
        public GitPatcherInitVM(ProfileVM profile)
            : base(profile)
        {
            Patcher = new GitPatcherVM(profile);
            this.CompositeDisposable.Add(Patcher);

            _CanCompleteConfiguration = this.WhenAnyValue(x => x.Patcher.State)
                                        .Select(x => x.RunnableState)
                                        .ToGuiProperty(this, nameof(CanCompleteConfiguration), ErrorResponse.Success);

            PatcherRepos = Observable.Return(Unit.Default)
                           .ObserveOn(RxApp.TaskpoolScheduler)
                           .SelectTask(async _ =>
            {
                try
                {
                    var gitHubClient         = new GitHubClient(new ProductHeaderValue("Synthesis"));
                    gitHubClient.Credentials = new Credentials("9b58542a2ca303d7ced129cc404191f8eea519f7");
                    var content = await gitHubClient.Repository.Content.GetAllContents("Noggog", "Synthesis.Registry", Constants.AutomaticListingFileName);
                    if (content.Count != 1)
                    {
                        return(Observable.Empty <IChangeSet <PatcherStoreListingVM> >());
                    }
                    var customization = JsonSerializer.Deserialize <MutagenPatchersListing>(content[0].Content);
                    return(customization.Repositories
                           .NotNull()
                           .SelectMany(repo =>
                    {
                        var repoVM = new RepositoryStoreListingVM(repo);
                        return repo.Patchers
                        .Select(p =>
                        {
                            return new PatcherStoreListingVM(this, p, repoVM);
                        });
                    })
                           .AsObservableChangeSet());
                }
                catch (Exception ex)
                {
                    Log.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;
                }));
            }))
                           .ToObservableCollection(this);

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