summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/Utilities/DriveUtilities.cs
blob: d07056ef898cf1f71ad77f4b9db8e3ade18a170f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="DriveUtilities.cs" company="HandBrake Project (http://handbrake.fr)">
//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
// </copyright>
// <summary>
//   The drive utilities.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace HandBrakeWPF.Utilities
{
    using System.Collections.Generic;
    using System.IO;

    using HandBrakeWPF.Model;

    /// <summary>
    /// The drive utilities.
    /// </summary>
    public class DriveUtilities
    {
        /// <summary>
        /// Get a list of available DVD drives which are ready and contain DVD content.
        /// </summary>
        /// <returns>A List of Drives with their details</returns>
        public static List<DriveInformation> GetDrives()
        {
            var drives = new List<DriveInformation>();
            DriveInfo[] theCollectionOfDrives = DriveInfo.GetDrives();
            int id = 0;
            foreach (DriveInfo curDrive in theCollectionOfDrives)
            {
                if (curDrive.DriveType == DriveType.CDRom && curDrive.IsReady)
                {
                    if (Directory.Exists(curDrive.RootDirectory + "VIDEO_TS") ||
                        Directory.Exists(curDrive.RootDirectory + "BDMV"))
                    {
                        drives.Add(
                            new DriveInformation
                            {
                                Id = id, 
                                VolumeLabel = curDrive.VolumeLabel, 
                                RootDirectory = curDrive.RootDirectory.ToString()
                            });
                        id++;
                    }
                }
            }

            return drives;
        }
    }
}