Skip to content

Commit

Permalink
Changed: Nullability of Items in IDownloadablePackage
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Aug 2, 2022
1 parent f8c439c commit f714c32
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public class DummyDownloadablePackage : IDownloadablePackage
public string Id { get; set; } = "";
public string Name { get; set; } = "";
public string Authors { get; set; } = "";
public Submitter Submitter { get; set; } = new() { UserName = "" };
public Submitter? Submitter { get; set; } = new() { UserName = "" };
public string Description { get; set; } = "";
public string Source { get; set; } = "";
public NuGetVersion Version { get; set; } = new NuGetVersion("1.0.0");
public long FileSize { get; } = 0;
public long? FileSize { get; } = 0;
public string MarkdownReadme { get; } = null;
public DownloadableImage[]? Images { get; set; }
public Uri ProjectUri { get; set; } = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public static ModDependencyResolveResult Combine(IEnumerable<ModDependencyResolv
{
foreach (var found in result.FoundDependencies)
{
if (found.Id == null)
continue;

if (idToNewestVersion.TryGetValue(found.Id, out var existing))
{
if (existing.Version < found.Version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,46 @@ namespace Reloaded.Mod.Loader.Update.Interfaces;
public interface IDownloadablePackage : INotifyPropertyChanged
{
/// <summary>
/// Id of the mod to be downloaded.
/// Name of the mod to be downloaded.
/// </summary>
public string Id { get; }
public string Name { get; }

/// <summary>
/// Name of the mod to be downloaded.
/// Source of the package.
/// Which provider the package comes from.
/// </summary>
public string Name { get; }
public string Source { get; }

/// <summary>
/// Id of the mod to be downloaded.
/// </summary>
public string? Id { get; }

/// <summary>
/// The mod authors. As displayed in launcher.
/// Used for credits.
/// </summary>
public string Authors { get; }
public string? Authors { get; }

/// <summary>
/// Contains information about the person who uploaded this item.
/// </summary>
public Submitter Submitter { get; }
public Submitter? Submitter { get; }

/// <summary>
/// Short description of the mod, as seen in mod config menu.
/// </summary>
public string Description { get; }

/// <summary>
/// Source of the package.
/// Which provider the package comes from.
/// </summary>
public string Source { get; }
public string? Description { get; }

/// <summary>
/// Version of the mod to download.
/// </summary>
public NuGetVersion Version { get; }
public NuGetVersion? Version { get; }

/// <summary>
/// File size in bytes of the item to be downloaded.
/// </summary>
public long FileSize { get; }
public long? FileSize { get; }

/// <summary>
/// Provides a human readable readme file, in markdown format.
Expand All @@ -55,7 +55,7 @@ public interface IDownloadablePackage : INotifyPropertyChanged
/// <summary>
/// Long description of the mod.
/// </summary>
public string LongDescription => MarkdownReadme ?? Description;
public string? LongDescription => MarkdownReadme ?? Description;

/// <summary>
/// Provides a list of images for this package.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public async Task<ModDependencyResolveResult> ResolveAsync(string packageId, Dic
// Merge found dependencies
foreach (var dependency in task.Result.FoundDependencies)
{
if (dependency.Id == null)
continue;

if (!packageToVersionMap.TryGetValue(dependency.Id, out var existing))
{
packageToVersionMap[dependency.Id] = dependency;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ public class NuGetDownloadablePackage : IDownloadablePackage
private static NuGetPackageExtractor _extractor = new();

/// <inheritdoc />
public string Id => _package.Identity.Id;
public string Name => !string.IsNullOrEmpty(_package.Title) ? _package.Title : _package.Identity.Id;

/// <inheritdoc />
public string Name => !string.IsNullOrEmpty(_package.Title) ? _package.Title : _package.Identity.Id;
public string Source => _repository.FriendlyName;

/// <inheritdoc />
public string Authors => _package.Authors;
public string? Id => _package.Identity.Id;

/// <inheritdoc />
public Submitter Submitter => new Submitter() { UserName = _package.Authors };
public string? Authors => _package.Authors;

/// <inheritdoc />
public string Description => _package.Description;
public Submitter? Submitter => new Submitter() { UserName = _package.Authors };

/// <inheritdoc />
public string Source => _repository.FriendlyName;
public string? Description => _package.Description;

/// <inheritdoc />
public NuGetVersion Version => _package.Identity.Version;
public NuGetVersion? Version => _package.Identity.Version;

/// <inheritdoc />
public Uri? ProjectUri => _package.ProjectUrl;
Expand All @@ -45,7 +45,7 @@ public class NuGetDownloadablePackage : IDownloadablePackage

/// <inheritdoc />
[DoNotNotify]
public long FileSize
public long? FileSize
{
get
{
Expand Down Expand Up @@ -84,6 +84,9 @@ public NuGetDownloadablePackage(IPackageSearchMetadata package, INugetRepository
Images = new[] { new DownloadableImage() { Uri = _package.IconUrl } };

// Calculate downloads of package.
if (versions == null)
return;

long downloadCount = 0;
foreach (var version in versions)
downloadCount += version.DownloadCount.GetValueOrDefault(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@ public UpdateDownloadablePackage(IPackageResolver packageResolver)
}

/// <inheritdoc />
public string Id { get; set; } = "";
public string Name { get; set; } = "Unknown Package";

/// <inheritdoc />
public string Name { get; set; } = "Unknown Package";
public string Source { get; internal set; } = null!;

/// <inheritdoc />
public string Authors { get; set; } = "Unknown Author";
public string? Id { get; set; }

/// <inheritdoc />
public Submitter Submitter { get; set; } = new() { UserName = "Unknown Submitter" };
public string? Authors { get; set; }

/// <inheritdoc />
public string Description { get; set; } = "No Description";
public Submitter? Submitter { get; set; }

/// <inheritdoc />
public string Source { get; internal set; } = null!;
public string? Description { get; set; }

/// <inheritdoc />
public NuGetVersion Version { get; internal set; } = null!;
public NuGetVersion? Version { get; internal set; }

/// <inheritdoc />
public long FileSize { get; internal set; }
public long? FileSize { get; internal set; }

/// <inheritdoc />
public string? MarkdownReadme { get; } = null!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@ public class WebDownloadablePackage : IDownloadablePackage
#pragma warning restore CS0067 // Event never used

/// <inheritdoc />
public string Id { get; set; } = "Unknown Package Id";
public string Name { get; set; } = "Unknown Package Name";

/// <inheritdoc />
public string Name { get; set; } = "Unknown Package Name";
public string Source { get; set; } = "Web URL";

/// <inheritdoc />
public string Authors { get; set; } = "Unknown";
public string? Id { get; set; } = null;

/// <inheritdoc />
public Submitter Submitter { get; set; } = new() { UserName = "Unknown" };
public string? Authors { get; set; } = null!;

/// <inheritdoc />
public string Description { get; set; } = "Unknown Package. Comes from the web.";
public Submitter? Submitter { get; set; }

/// <inheritdoc />
public string Source { get; set; } = "Web URL";
public string? Description { get; set; }

/// <inheritdoc />
public NuGetVersion Version { get; set; } = NuGetVersion.Parse("0.0.0");
public NuGetVersion? Version { get; set; }

/// <summary>
/// Size of the file to be downloaded.
/// </summary>
public long FileSize { get; set; }
public long? FileSize { get; set; }

/// <inheritdoc />
public string? MarkdownReadme { get; set; }
Expand Down

0 comments on commit f714c32

Please sign in to comment.