diff --git a/src/NexusMods.Paths/FileSystemAbstraction/FileVersionInfo.cs b/src/NexusMods.Paths/FileSystemAbstraction/FileVersionInfo.cs
index 69faa30..d982d62 100644
--- a/src/NexusMods.Paths/FileSystemAbstraction/FileVersionInfo.cs
+++ b/src/NexusMods.Paths/FileSystemAbstraction/FileVersionInfo.cs
@@ -1,4 +1,5 @@
using System;
+using JetBrains.Annotations;
namespace NexusMods.Paths;
@@ -6,15 +7,19 @@ namespace NexusMods.Paths;
/// Represents version information for a file on disk.
///
/// Gets the version of the product this file is distributed with.
-public record struct FileVersionInfo(Version ProductVersion)
+/// Gets the file version number.
+[PublicAPI]
+public record struct FileVersionInfo(Version ProductVersion, Version FileVersion)
{
+ private static readonly Version Zero = new(0, 0, 0, 0);
+
///
- /// Parses the input as a .
+ /// Returns the first non-zero version.
///
- ///
- ///
- 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;
}
}
diff --git a/src/NexusMods.Paths/FileSystemAbstraction/RealFileSystem/FileEntry.cs b/src/NexusMods.Paths/FileSystemAbstraction/RealFileSystem/FileEntry.cs
index e012249..0712a83 100644
--- a/src/NexusMods.Paths/FileSystemAbstraction/RealFileSystem/FileEntry.cs
+++ b/src/NexusMods.Paths/FileSystemAbstraction/RealFileSystem/FileEntry.cs
@@ -52,7 +52,20 @@ public FileEntry(IFileSystem fileSystem, AbsolutePath path)
public FileVersionInfo GetFileVersionInfo()
{
var fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(_path.GetFullPath());
- return new FileVersionInfo(FileVersionInfo.ParseVersionString(fvi.ProductVersion));
+
+ var sProductVersion = fvi.ProductVersion;
+ if (!Version.TryParse(sProductVersion, out var productVersion))
+ {
+ productVersion = new Version(fvi.ProductMajorPart, fvi.ProductMinorPart, fvi.ProductBuildPart, fvi.ProductPrivatePart);
+ }
+
+ var sFileVersion = fvi.FileVersion;
+ if (!Version.TryParse(sFileVersion, out var fileVersion))
+ {
+ fileVersion = new Version(fvi.FileMajorPart, fvi.FileMinorPart, fvi.FileBuildPart, fvi.FilePrivatePart);
+ }
+
+ return new FileVersionInfo(productVersion, fileVersion);
}
}
}