From f6b78c07ca198f7e5ac6bc4d341f30ebd215a0e6 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 29 Dec 2021 10:00:28 -0800 Subject: [PATCH] Add safety around volume labels --- CHANGELIST.md | 1 + MPF.Core/Data/Drive.cs | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELIST.md b/CHANGELIST.md index d1b2157e..b96e3c99 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -47,6 +47,7 @@ - Validate track count when matching Redump - Allow for better matching of multi track discs - Temporarily disable pulling comments from Redump pages +- Add safety around volume labels ### 2.1 (2021-07-22) - Enum, no more diff --git a/MPF.Core/Data/Drive.cs b/MPF.Core/Data/Drive.cs index 2098249f..4bd420f1 100644 --- a/MPF.Core/Data/Drive.cs +++ b/MPF.Core/Data/Drive.cs @@ -48,7 +48,21 @@ namespace MPF.Core.Data /// /// Media label as read by Windows /// - public string VolumeLabel => driveInfo?.VolumeLabel; + /// The try/catch is needed because Windows will throw an exception if the drive is not marked as active + public string VolumeLabel + { + get + { + try + { + return driveInfo?.VolumeLabel; + } + catch + { + return null; + } + } + } /// /// Media label as read by Windows, formatted to avoid odd outputs