diff --git a/BurnOutSharp/ProtectionType/ProtectDisc.cs b/BurnOutSharp/ProtectionType/ProtectDisc.cs index 907a6726..c96d186a 100644 --- a/BurnOutSharp/ProtectionType/ProtectDisc.cs +++ b/BurnOutSharp/ProtectionType/ProtectDisc.cs @@ -232,8 +232,8 @@ namespace BurnOutSharp.ProtectionType { if (files.Length > 0) { - FileVersionInfo fvinfo = FileVersionInfo.GetVersionInfo(files[0]); - if (fvinfo.FileVersion != "") + var fvinfo = Utilities.GetFileVersionInfo(files[0]); + if (!string.IsNullOrWhiteSpace(fvinfo?.FileVersion)) { version = fvinfo.FileVersion.Replace(" ", "").Replace(",", "."); //ProtectDisc 9 uses a ProtectDisc-Core dll version 8.0.x @@ -249,8 +249,8 @@ namespace BurnOutSharp.ProtectionType files = Directory.GetFiles(Path.GetTempPath(), "a*.tmp"); if (files.Length > 0) { - FileVersionInfo fvinfo = FileVersionInfo.GetVersionInfo(files[0]); - if (fvinfo.FileVersion != "") + var fvinfo = Utilities.GetFileVersionInfo(files[0]); + if (!string.IsNullOrWhiteSpace(fvinfo?.FileVersion)) { version = fvinfo.FileVersion.Replace(" ", "").Replace(",", "."); fvinfo = null; diff --git a/BurnOutSharp/ProtectionType/SolidShield.cs b/BurnOutSharp/ProtectionType/SolidShield.cs index 530faf45..1efa0640 100644 --- a/BurnOutSharp/ProtectionType/SolidShield.cs +++ b/BurnOutSharp/ProtectionType/SolidShield.cs @@ -123,11 +123,8 @@ namespace BurnOutSharp.ProtectionType public static string GetFileVersion(string file, byte[] fileContent, List positions) { - string companyName = string.Empty; - if (file != null) - companyName = FileVersionInfo.GetVersionInfo(file).CompanyName.ToLower(); - - if (companyName.Contains("solidshield") || companyName.Contains("tages")) + string companyName = Utilities.GetFileVersionInfo(file)?.CompanyName.ToLowerInvariant(); + if (!string.IsNullOrWhiteSpace(companyName) && (companyName.Contains("solidshield") || companyName.Contains("tages"))) return Utilities.GetFileVersion(file); return null; diff --git a/BurnOutSharp/ProtectionType/VOBProtectCDDVD.cs b/BurnOutSharp/ProtectionType/VOBProtectCDDVD.cs index b1a863bd..b2199bd1 100644 --- a/BurnOutSharp/ProtectionType/VOBProtectCDDVD.cs +++ b/BurnOutSharp/ProtectionType/VOBProtectCDDVD.cs @@ -156,8 +156,8 @@ namespace BurnOutSharp.ProtectionType { if (files.Length > 0) { - FileVersionInfo fvinfo = FileVersionInfo.GetVersionInfo(files[0]); - if (fvinfo.FileVersion != "") + var fvinfo = Utilities.GetFileVersionInfo(files[0]); + if (!string.IsNullOrWhiteSpace(fvinfo?.FileVersion)) { version = fvinfo.FileVersion.Replace(" ", "").Replace(",", "."); //ProtectDisc 9 uses a ProtectDisc-Core dll version 8.0.x @@ -173,8 +173,8 @@ namespace BurnOutSharp.ProtectionType files = Directory.GetFiles(Path.GetTempPath(), "a*.tmp"); if (files.Length > 0) { - FileVersionInfo fvinfo = FileVersionInfo.GetVersionInfo(files[0]); - if (fvinfo.FileVersion != "") + var fvinfo = Utilities.GetFileVersionInfo(files[0]); + if (!string.IsNullOrWhiteSpace(fvinfo?.FileVersion)) { version = fvinfo.FileVersion.Replace(" ", "").Replace(",", "."); fvinfo = null; diff --git a/BurnOutSharp/Utilities.cs b/BurnOutSharp/Utilities.cs index 2bb57cfb..1b20b086 100644 --- a/BurnOutSharp/Utilities.cs +++ b/BurnOutSharp/Utilities.cs @@ -243,6 +243,26 @@ namespace BurnOutSharp #region Protection + /// + /// Get the file version info object related to a path, if possible + /// + /// File to get information for + /// FileVersionInfo object on success, null on error + public static FileVersionInfo GetFileVersionInfo(string file) + { + if (file == null || !File.Exists(file)) + return null; + + try + { + return FileVersionInfo.GetVersionInfo(file); + } + catch + { + return null; + } + } + /// /// Get the file version as reported by the filesystem /// @@ -250,12 +270,9 @@ namespace BurnOutSharp /// Version string, null on error public static string GetFileVersion(string file) { - if (file == null || !File.Exists(file)) + var fvinfo = GetFileVersionInfo (file); + if (fvinfo?.FileVersion == null) return string.Empty; - - FileVersionInfo fvinfo = FileVersionInfo.GetVersionInfo(file); - if (fvinfo.FileVersion == null) - return ""; if (fvinfo.FileVersion != "") return fvinfo.FileVersion.Replace(", ", "."); else