diff --git a/source/Reloaded.Mod.Loader.Tests/Update/Mocks/DummyDownloadablePackage.cs b/source/Reloaded.Mod.Loader.Tests/Update/Mocks/DummyDownloadablePackage.cs index 38a9f0cd..b9831c8b 100644 --- a/source/Reloaded.Mod.Loader.Tests/Update/Mocks/DummyDownloadablePackage.cs +++ b/source/Reloaded.Mod.Loader.Tests/Update/Mocks/DummyDownloadablePackage.cs @@ -23,6 +23,9 @@ public class DummyDownloadablePackage : IDownloadablePackage public string MarkdownReadme { get; } = null; public DownloadableImage[]? Images { get; set; } public Uri ProjectUri { get; set; } = null; + public long? LikeCount { get; } = null; + public long? ViewCount { get; } = null; + public long? DownloadCount { get; } = null; public Task DownloadAsync(string packageFolder, IProgress progress, CancellationToken token = default) { diff --git a/source/Reloaded.Mod.Loader.Update/Interfaces/IDownloadablePackage.cs b/source/Reloaded.Mod.Loader.Update/Interfaces/IDownloadablePackage.cs index 8aabc692..5ea8749e 100644 --- a/source/Reloaded.Mod.Loader.Update/Interfaces/IDownloadablePackage.cs +++ b/source/Reloaded.Mod.Loader.Update/Interfaces/IDownloadablePackage.cs @@ -66,7 +66,22 @@ public interface IDownloadablePackage : INotifyPropertyChanged /// The URL of the web page of the project. /// public Uri? ProjectUri { get; } - + + /// + /// Number of likes/upvotes for this package. + /// + public long? LikeCount { get; } + + /// + /// Number of views for this package. + /// + public long? ViewCount { get; } + + /// + /// Number of downloads for this package. + /// + public long? DownloadCount { get; } + /// /// Downloads the package in question asynchronously. /// diff --git a/source/Reloaded.Mod.Loader.Update/Providers/GameBanana/GameBananaPackageProvider.cs b/source/Reloaded.Mod.Loader.Update/Providers/GameBanana/GameBananaPackageProvider.cs index 7002257a..4624e7a9 100644 --- a/source/Reloaded.Mod.Loader.Update/Providers/GameBanana/GameBananaPackageProvider.cs +++ b/source/Reloaded.Mod.Loader.Update/Providers/GameBanana/GameBananaPackageProvider.cs @@ -190,6 +190,9 @@ private static void GameBananaAddCommon(GameBananaMod modItem, GameBananaModFile package.Source = SourceName; package.FileSize = file.FileSize.GetValueOrDefault(); package.ProjectUri = new Uri(modItem.LinkToModPage); + package.LikeCount = modItem.LikeCount; + package.ViewCount = modItem.ViewCount; + package.DownloadCount = modItem.DownloadCount; GameBananaAddAuthors(modItem, package); GameBananaAddSubmitter(modItem, package); GameBananaAddImages(modItem, package); diff --git a/source/Reloaded.Mod.Loader.Update/Providers/GameBanana/Structures/GameBananaMod.cs b/source/Reloaded.Mod.Loader.Update/Providers/GameBanana/Structures/GameBananaMod.cs index 02d860c3..78a3c7ea 100644 --- a/source/Reloaded.Mod.Loader.Update/Providers/GameBanana/Structures/GameBananaMod.cs +++ b/source/Reloaded.Mod.Loader.Update/Providers/GameBanana/Structures/GameBananaMod.cs @@ -32,6 +32,15 @@ public class GameBananaMod [JsonPropertyName("_aSubmitter")] public GameBananaSubmitter Submitter { get; set; } = new GameBananaSubmitter(); + [JsonPropertyName("_nDownloadCount")] + public long DownloadCount { get; set; } + + [JsonPropertyName("_nViewCount")] + public long ViewCount { get; set; } + + [JsonPropertyName("_nLikeCount")] + public long LikeCount { get; set; } + [JsonConverter(typeof(GameBananaManagerIntegrationConverter))] [JsonPropertyName("_aModManagerIntegrations")] public Dictionary? ManagerIntegrations { get; set; } diff --git a/source/Reloaded.Mod.Loader.Update/Providers/NuGet/NuGetDependencyResolver.cs b/source/Reloaded.Mod.Loader.Update/Providers/NuGet/NuGetDependencyResolver.cs index c8bbbc09..c0576a89 100644 --- a/source/Reloaded.Mod.Loader.Update/Providers/NuGet/NuGetDependencyResolver.cs +++ b/source/Reloaded.Mod.Loader.Update/Providers/NuGet/NuGetDependencyResolver.cs @@ -23,7 +23,7 @@ public async Task ResolveAsync(string packageId, Dic { var package = dependency.Generic; var repository = dependency.Repository; - result.FoundDependencies.Add(new NuGetDownloadablePackage(package, repository)); + result.FoundDependencies.Add(new NuGetDownloadablePackage(package, repository, await package.GetVersionsAsync())); } foreach (var notFound in searchResult.PackagesNotFound) diff --git a/source/Reloaded.Mod.Loader.Update/Providers/NuGet/NuGetDownloadablePackage.cs b/source/Reloaded.Mod.Loader.Update/Providers/NuGet/NuGetDownloadablePackage.cs index 707a6709..d5bfe90e 100644 --- a/source/Reloaded.Mod.Loader.Update/Providers/NuGet/NuGetDownloadablePackage.cs +++ b/source/Reloaded.Mod.Loader.Update/Providers/NuGet/NuGetDownloadablePackage.cs @@ -35,7 +35,13 @@ public class NuGetDownloadablePackage : IDownloadablePackage public Uri? ProjectUri => _package.ProjectUrl; /// - public Uri? SourceUri => null; // not supported, usually linked by ProjectUri + public long? LikeCount => null; + + /// + public long? ViewCount => null; + + /// + public long? DownloadCount { get; private set; } /// [DoNotNotify] @@ -69,13 +75,21 @@ public long FileSize private Lazy _resolver; /// - public NuGetDownloadablePackage(IPackageSearchMetadata package, INugetRepository repository) + public NuGetDownloadablePackage(IPackageSearchMetadata package, INugetRepository repository, IEnumerable? versions = null) { _package = package; _repository = repository; _resolver = new Lazy(GetResolver, true); if (_package.IconUrl != null) Images = new[] { new DownloadableImage() { Uri = _package.IconUrl } }; + + // Calculate downloads of package. + long downloadCount = 0; + foreach (var version in versions) + downloadCount += version.DownloadCount.GetValueOrDefault(0); + + if (downloadCount > 0) + DownloadCount = downloadCount; } /// diff --git a/source/Reloaded.Mod.Loader.Update/Providers/NuGet/NuGetPackageProvider.cs b/source/Reloaded.Mod.Loader.Update/Providers/NuGet/NuGetPackageProvider.cs index f928cfd5..f9d7fc80 100644 --- a/source/Reloaded.Mod.Loader.Update/Providers/NuGet/NuGetPackageProvider.cs +++ b/source/Reloaded.Mod.Loader.Update/Providers/NuGet/NuGetPackageProvider.cs @@ -24,7 +24,7 @@ public async Task> SearchAsync(string text, int skip var packages = tuple.Generic; var repository = tuple.Repository; foreach (var package in packages) - result.Add(new NuGetDownloadablePackage(package, repository)); + result.Add(new NuGetDownloadablePackage(package, repository, await package.GetVersionsAsync())); } return result; diff --git a/source/Reloaded.Mod.Loader.Update/Providers/Update/UpdateDownloadablePackage.cs b/source/Reloaded.Mod.Loader.Update/Providers/Update/UpdateDownloadablePackage.cs index e0e1e752..a3d78f6f 100644 --- a/source/Reloaded.Mod.Loader.Update/Providers/Update/UpdateDownloadablePackage.cs +++ b/source/Reloaded.Mod.Loader.Update/Providers/Update/UpdateDownloadablePackage.cs @@ -8,7 +8,7 @@ namespace Reloaded.Mod.Loader.Update.Providers.Update; public class UpdateDownloadablePackage : IDownloadablePackage { /// - /// The package resovler tied to this package. + /// The package resolver tied to this package. /// public IPackageResolver PackageResolver { get; private set; } @@ -56,6 +56,15 @@ public UpdateDownloadablePackage(IPackageResolver packageResolver) /// public Uri? ProjectUri { get; set; } = null; + /// + public long? LikeCount { get; set; } = null; + + /// + public long? ViewCount { get; set; } = null; + + /// + public long? DownloadCount { get; set; } = null; + private async Task GetPackageDetailsAsync() { var versions = await PackageResolver.GetPackageVersionsAsync(); diff --git a/source/Reloaded.Mod.Loader.Update/Providers/Web/WebDownloadablePackage.cs b/source/Reloaded.Mod.Loader.Update/Providers/Web/WebDownloadablePackage.cs index 3630227c..59f42481 100644 --- a/source/Reloaded.Mod.Loader.Update/Providers/Web/WebDownloadablePackage.cs +++ b/source/Reloaded.Mod.Loader.Update/Providers/Web/WebDownloadablePackage.cs @@ -49,6 +49,15 @@ public class WebDownloadablePackage : IDownloadablePackage /// public Uri? ProjectUri { get; set; } = null; + /// + public long? LikeCount { get; set; } = null; + + /// + public long? ViewCount { get; set; } = null; + + /// + public long? DownloadCount { get; set; } = null; + private Uri _url; ///