generated from Nexus-Mods/NexusMods.App.Template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from Nexus-Mods/feat/better-fileversioninfo
Update `FileVersionInfo`
- Loading branch information
Showing
2 changed files
with
25 additions
and
7 deletions.
There are no files selected for viewing
17 changes: 11 additions & 6 deletions
17
src/NexusMods.Paths/FileSystemAbstraction/FileVersionInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
using System; | ||
using JetBrains.Annotations; | ||
|
||
namespace NexusMods.Paths; | ||
|
||
/// <summary> | ||
/// Represents version information for a file on disk. | ||
/// </summary> | ||
/// <param name="ProductVersion">Gets the version of the product this file is distributed with.</param> | ||
public record struct FileVersionInfo(Version ProductVersion) | ||
/// <param name="FileVersion">Gets the file version number.</param> | ||
[PublicAPI] | ||
public record struct FileVersionInfo(Version ProductVersion, Version FileVersion) | ||
{ | ||
private static readonly Version Zero = new(0, 0, 0, 0); | ||
|
||
/// <summary> | ||
/// Parses the input as a <see cref="Version"/>. | ||
/// Returns the first non-zero version. | ||
/// </summary> | ||
/// <param name="input"></param> | ||
/// <returns></returns> | ||
public static Version ParseVersionString(string? input) | ||
public Version GetBestVersion() | ||
{ | ||
return input is null ? Version.Parse("1.0.0.0") : Version.Parse(input); | ||
return ProductVersion.Equals(Zero) | ||
? FileVersion | ||
: ProductVersion; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters