예제 #1
0
 public static string Name(this DICCommand command)
 {
     return(Converters.DICCommandToString(command));
 }
예제 #2
0
 public static string ShortName(this KnownSystem?system)
 {
     return(Converters.KnownSystemToShortString(system));
 }
예제 #3
0
 public static string ShortName(this MediaType?type)
 {
     return(Converters.MediaTypeToShortString(type));
 }
예제 #4
0
 public static string Extension(this MediaType?type)
 {
     return(Converters.MediaTypeToExtension(type));
 }
예제 #5
0
        /// <summary>
        /// Get the current media type from drive letter
        /// </summary>
        /// <param name="driveLetter"></param>
        /// <returns></returns>
        /// <remarks>
        /// https://stackoverflow.com/questions/11420365/detecting-if-disc-is-in-dvd-drive
        /// </remarks>
        public static MediaType?GetMediaType(char?driveLetter)
        {
            // Get the DeviceID from the current drive letter
            string deviceId = null;

            try
            {
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2",
                                                 "SELECT * FROM Win32_CDROMDrive WHERE Id = '" + driveLetter + ":\'");

                var collection = searcher.Get();
                foreach (ManagementObject queryObj in collection)
                {
                    deviceId = (string)queryObj["DeviceID"];
                }
            }
            catch
            {
                // We don't care what the error was
                return(null);
            }

            // If we got no valid device, we don't care and just return
            if (deviceId == null)
            {
                return(null);
            }

            // Get all relevant disc information
            try
            {
                MsftDiscMaster2 discMaster = new MsftDiscMaster2();
                deviceId = deviceId.ToLower().Replace('\\', '#');
                string id = null;
                foreach (var disc in discMaster)
                {
                    if (disc.ToString().Contains(deviceId))
                    {
                        id = disc.ToString();
                    }
                }

                // If we couldn't find the drive, we don't care and return
                if (id == null)
                {
                    return(null);
                }

                // Otherwise, we get the media type, if any
                MsftDiscRecorder2 recorder = new MsftDiscRecorder2();
                recorder.InitializeDiscRecorder(id);
                MsftDiscFormat2Data dataWriter = new MsftDiscFormat2Data();
                dataWriter.Recorder = recorder;
                var media = dataWriter.CurrentPhysicalMediaType;
                if (media != IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_UNKNOWN)
                {
                    return(Converters.ToMediaType(media));
                }
            }
            catch
            {
                // We don't care what the error is
            }

            return(null);
        }