From 0360df0604f91069bc97c21f4abd5392d65a6a16 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 2 Nov 2021 10:54:08 -0700 Subject: [PATCH] Wrap directory checks in case of corruption --- MPF.Core/Data/Drive.cs | 48 +++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/MPF.Core/Data/Drive.cs b/MPF.Core/Data/Drive.cs index 28689973..5b23dd39 100644 --- a/MPF.Core/Data/Drive.cs +++ b/MPF.Core/Data/Drive.cs @@ -256,28 +256,42 @@ namespace MPF.Core.Data } // DVD-Audio - if (Directory.Exists(Path.Combine(drivePath, "AUDIO_TS")) - && Directory.EnumerateFiles(Path.Combine(drivePath, "AUDIO_TS")).Count() > 0) + try { - return RedumpSystem.DVDAudio; + if (Directory.Exists(Path.Combine(drivePath, "AUDIO_TS")) + && Directory.EnumerateFiles(Path.Combine(drivePath, "AUDIO_TS")).Any()) + { + return RedumpSystem.DVDAudio; + } } + catch { } // DVD-Video and Xbox - if (Directory.Exists(Path.Combine(drivePath, "VIDEO_TS")) - && Directory.EnumerateFiles(Path.Combine(drivePath, "VIDEO_TS")).Count() > 0) + try { - // TODO: Maybe add video track hashes to compare for Xbox and X360? - if (this.VolumeLabel.StartsWith("SEP13011042", StringComparison.OrdinalIgnoreCase)) - return RedumpSystem.MicrosoftXbox; + if (Directory.Exists(Path.Combine(drivePath, "VIDEO_TS")) + && Directory.EnumerateFiles(Path.Combine(drivePath, "VIDEO_TS")).Any()) + { + // TODO: Maybe add video track hashes to compare for Xbox and X360? + if (this.VolumeLabel.StartsWith("SEP13011042", StringComparison.OrdinalIgnoreCase)) + return RedumpSystem.MicrosoftXbox; - return RedumpSystem.DVDVideo; + return RedumpSystem.DVDVideo; + } } + catch { } // HD-DVD-Video - if (Directory.Exists(Path.Combine(drivePath, "HVDVD_TS")) - && Directory.EnumerateFiles(Path.Combine(drivePath, "HVDVD_TS")).Count() > 0) + try + { + if (Directory.Exists(Path.Combine(drivePath, "HVDVD_TS")) + && Directory.EnumerateFiles(Path.Combine(drivePath, "HVDVD_TS")).Any()) + { + return RedumpSystem.HDDVDVideo; + } + } + catch { - return RedumpSystem.HDDVDVideo; } // Sega Dreamcast @@ -349,11 +363,15 @@ namespace MPF.Core.Data } // VCD - if (Directory.Exists(Path.Combine(drivePath, "VCD")) - && Directory.EnumerateFiles(Path.Combine(drivePath, "VCD")).Count() > 0) + try { - return RedumpSystem.VideoCD; + if (Directory.Exists(Path.Combine(drivePath, "VCD")) + && Directory.EnumerateFiles(Path.Combine(drivePath, "VCD")).Any()) + { + return RedumpSystem.VideoCD; + } } + catch { } // Default return return defaultValue;