Skip to content

Commit

Permalink
Added: Download, Like, View Count for Downloadable Packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Aug 2, 2022
1 parent 2fd6fa2 commit a9837a7
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> DownloadAsync(string packageFolder, IProgress<double> progress, CancellationToken token = default)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,22 @@ public interface IDownloadablePackage : INotifyPropertyChanged
/// The URL of the web page of the project.
/// </summary>
public Uri? ProjectUri { get; }


/// <summary>
/// Number of likes/upvotes for this package.
/// </summary>
public long? LikeCount { get; }

/// <summary>
/// Number of views for this package.
/// </summary>
public long? ViewCount { get; }

/// <summary>
/// Number of downloads for this package.
/// </summary>
public long? DownloadCount { get; }

/// <summary>
/// Downloads the package in question asynchronously.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, GameBananaManagerIntegration[]>? ManagerIntegrations { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task<ModDependencyResolveResult> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ public class NuGetDownloadablePackage : IDownloadablePackage
public Uri? ProjectUri => _package.ProjectUrl;

/// <inheritdoc />
public Uri? SourceUri => null; // not supported, usually linked by ProjectUri
public long? LikeCount => null;

/// <inheritdoc />
public long? ViewCount => null;

/// <inheritdoc />
public long? DownloadCount { get; private set; }

/// <inheritdoc />
[DoNotNotify]
Expand Down Expand Up @@ -69,13 +75,21 @@ public long FileSize
private Lazy<NuGetUpdateResolver> _resolver;

/// <summary/>
public NuGetDownloadablePackage(IPackageSearchMetadata package, INugetRepository repository)
public NuGetDownloadablePackage(IPackageSearchMetadata package, INugetRepository repository, IEnumerable<VersionInfo>? versions = null)
{
_package = package;
_repository = repository;
_resolver = new Lazy<NuGetUpdateResolver>(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;
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task<List<IDownloadablePackage>> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Reloaded.Mod.Loader.Update.Providers.Update;
public class UpdateDownloadablePackage : IDownloadablePackage
{
/// <summary>
/// The package resovler tied to this package.
/// The package resolver tied to this package.
/// </summary>
public IPackageResolver PackageResolver { get; private set; }

Expand Down Expand Up @@ -56,6 +56,15 @@ public UpdateDownloadablePackage(IPackageResolver packageResolver)
/// <inheritdoc />
public Uri? ProjectUri { get; set; } = null;

/// <inheritdoc />
public long? LikeCount { get; set; } = null;

/// <inheritdoc />
public long? ViewCount { get; set; } = null;

/// <inheritdoc />
public long? DownloadCount { get; set; } = null;

private async Task GetPackageDetailsAsync()
{
var versions = await PackageResolver.GetPackageVersionsAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ public class WebDownloadablePackage : IDownloadablePackage
/// <inheritdoc />
public Uri? ProjectUri { get; set; } = null;

/// <inheritdoc />
public long? LikeCount { get; set; } = null;

/// <inheritdoc />
public long? ViewCount { get; set; } = null;

/// <inheritdoc />
public long? DownloadCount { get; set; } = null;

private Uri _url;

/// <summary>
Expand Down

0 comments on commit a9837a7

Please sign in to comment.