예제 #1
0
        /// <summary>
        /// Backup processing method.  Called from the worker thread.
        /// </summary>
        protected override void Backup()
        {
            if (String.IsNullOrEmpty(this.activeDriveId))
            {
                throw new InvalidOperationException("Drive not initialized.");
            }

            // Reset the time remaining from previous burns.
            this.StatusUpdateArgs.TimeRemaining = TimeSpan.Zero;
            this.UpdateStatus(DriveStatus.Burning);

            MsftDiscRecorder2 discRecorder2 = new MsftDiscRecorder2();

            discRecorder2.InitializeDiscRecorder(this.activeDriveId);
            discRecorder2.AcquireExclusiveAccess(true, ClientName);

            MsftDiscFormat2Data discFormatData = new MsftDiscFormat2Data();

            if (!discFormatData.IsCurrentMediaSupported(discRecorder2))
            {
                throw new IOException("Invalid media.");
            }

            discFormatData.Recorder             = discRecorder2;
            discFormatData.ClientName           = ClientName;
            discFormatData.ForceMediaToBeClosed = true;
            using (var stream = this.ImageReader.ImageFile.OpenRead())
            {
                discFormatData.Update += this.DiscFormatData_Update;

                try
                {
                    discFormatData.Write(ComStream.ToIStream(stream));
                }
                catch (COMException ex)
                {
                    // Ignore canceled hresult.  Other errors should be reported to the UI thread.
                    if (ex.ErrorCode != -1062600702)
                    {
                        throw;
                    }
                }
                finally
                {
                    discFormatData.Update -= this.DiscFormatData_Update;
                    discRecorder2.EjectMedia();
                }

                // Double check that the burn was completed.  Some cases with XP and 2003 do not
                // return an error, but the burn is not successful.  Using progress < 99 since
                // the last update isn't always returned.
                if (!this.WorkerThread.CancellationPending && this.progress < 99)
                {
                    throw new IOException("Burn not completed.");
                }
            }

            discRecorder2.ReleaseExclusiveAccess();
        }
예제 #2
0
        private void ButtonDetectMedia_Click(object sender, EventArgs e)
        {
            if (devicesComboBox.SelectedIndex == -1)
            {
                return;
            }

            var discRecorder =
                (IDiscRecorder2)devicesComboBox.Items[devicesComboBox.SelectedIndex];

            MsftFileSystemImage fileSystemImage = null;
            MsftDiscFormat2Data discFormatData  = null;

            try
            {
                // Create and initialize the IDiscFormat2Data
                discFormatData = new MsftDiscFormat2Data();
                if (!discFormatData.IsCurrentMediaSupported(discRecorder))
                {
                    labelMediaType.Text = "Media not supported!";
                    return;
                }
                else
                {
                    // Get the media type in the recorder
                    discFormatData.Recorder = discRecorder;
                    var mediaType = discFormatData.CurrentPhysicalMediaType;
                    labelMediaType.Text = GetMediaTypeString(mediaType);

                    // Create a file system and select the media type
                    fileSystemImage = new MsftFileSystemImage();
                    fileSystemImage.ChooseImageDefaultsForMediaType(mediaType);

                    // See if there are other recorded sessions on the disc
                    if (!discFormatData.MediaHeuristicallyBlank)
                    {
                        fileSystemImage.MultisessionInterfaces = discFormatData.MultisessionInterfaces;
                        fileSystemImage.ImportFileSystem();
                    }
                }
            }
            catch (COMException exception)
            {
                MessageBox.Show(this, exception.Message, "Detect Media Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (discFormatData != null)
                {
                    Marshal.ReleaseComObject(discFormatData);
                }

                if (fileSystemImage != null)
                {
                    Marshal.ReleaseComObject(fileSystemImage);
                }
            }
        }
예제 #3
0
        private void ButtonDetectMedia_Click(object sender, EventArgs e)
        {
            if (devicesComboBox.SelectedIndex == -1)
            {
                return;
            }
            var discRecorder = (IDiscRecorder2)devicesComboBox.Items[devicesComboBox.SelectedIndex];
            MsftFileSystemImage fileSystemImage = null;
            MsftDiscFormat2Data discFormatData  = null;

            try
            {
                discFormatData = new MsftDiscFormat2Data();
                if (!discFormatData.IsCurrentMediaSupported(discRecorder))
                {
                    labelMediaType.Text = "Media not supported!";
                    return;
                }
                else
                {
                    discFormatData.Recorder = discRecorder;
                    var mediaType = discFormatData.CurrentPhysicalMediaType;

                    freeSpaceOnDisk = (2048 * discFormatData.FreeSectorsOnMedia) / 1048576;
                    FreeSpace.Text  = "Free Space: " + Convert.ToInt32(freeSpaceOnDisk).ToString() + " MB";
                    TotalSpace.Text = "Total Space: " + Convert.ToInt32((2048 * discFormatData.TotalSectorsOnMedia) / 1048576).ToString() + " MB";

                    labelMediaType.Text = _dictionares.TypeDictionary[mediaType];
                    fileSystemImage     = new MsftFileSystemImage();
                    fileSystemImage.ChooseImageDefaultsForMediaType(mediaType);
                    if (!discFormatData.MediaHeuristicallyBlank)
                    {
                        fileSystemImage.MultisessionInterfaces = discFormatData.MultisessionInterfaces;
                        fileSystemImage.ImportFileSystem();
                    }
                }
            }
            catch (COMException exception)
            {
                MessageBox.Show(this, exception.Message, "Detect Media Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (discFormatData != null)
                {
                    Marshal.ReleaseComObject(discFormatData);
                }

                if (fileSystemImage != null)
                {
                    Marshal.ReleaseComObject(fileSystemImage);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Burns data files to disc in a single session using files from a
        /// single directory tree.
        /// </summary>
        /// <param name="recorder">Burning Device. Must be initialized.</param>
        /// <param name="path">Directory of files to burn.</param>
        public void BurnDirectory(IDiscRecorder2 recorder, String path)
        {
            // Define the new disc format and set the recorder
            IDiscFormat2Data dataWriterImage = new MsftDiscFormat2Data();

            dataWriterImage.Recorder = recorder;

            if (!dataWriterImage.IsRecorderSupported(recorder))
            {
                Console.WriteLine("The recorder is not supported");
                return;
            }

            if (!dataWriterImage.IsCurrentMediaSupported(recorder))
            {
                Console.WriteLine("The current media is not supported");
                return;
            }

            dataWriterImage.ClientName = "IMAPI Sample";

            // Create an image stream for a specified directory.

            // Create a new file system image and retrieve the root directory
            IFileSystemImage fsi = new MsftFileSystemImage();

            // Set the media size
            fsi.FreeMediaBlocks = dataWriterImage.FreeSectorsOnMedia;

            // Use legacy ISO 9660 Format
            fsi.FileSystemsToCreate = FsiFileSystems.FsiFileSystemISO9660;

            // Add the directory to the disc file system
            IFsiDirectoryItem dir = fsi.Root;

            dir.AddTree(path, false);

            // Create an image from the file system
            Console.WriteLine("Writing content to disc...");
            IFileSystemImageResult result = fsi.CreateResultImage();

            // Data stream sent to the burning device
            IStream stream = result.ImageStream;

            DiscFormat2Data_Events progress = dataWriterImage as DiscFormat2Data_Events;

            progress.Update += new DiscFormat2Data_EventsHandler(DiscFormat2Data_ProgressUpdate);

            // Write the image stream to disc using the specified recorder.
            dataWriterImage.Write(stream);   // Burn the stream to disc

            progress.Update -= new DiscFormat2Data_EventsHandler(DiscFormat2Data_ProgressUpdate);

            Console.WriteLine("----- Finished writing content -----");
        }
예제 #5
0
        /// <summary>
        /// Burns data files to disc in a single session using files from a 
        /// single directory tree.
        /// </summary>
        /// <param name="recorder">Burning Device. Must be initialized.</param>
        /// <param name="path">Directory of files to burn.</param>
        public void BurnDirectory(IDiscRecorder2 recorder, String path)
        {
            // Define the new disc format and set the recorder
            IDiscFormat2Data dataWriterImage = new MsftDiscFormat2Data();
            dataWriterImage.Recorder = recorder;

            if(!dataWriterImage.IsRecorderSupported(recorder))
            {
                Console.WriteLine("The recorder is not supported");
                return;
            }

            if (!dataWriterImage.IsCurrentMediaSupported(recorder))
            {
                Console.WriteLine("The current media is not supported");
                return;
            }

            dataWriterImage.ClientName = "IMAPI Sample";

            // Create an image stream for a specified directory.

            // Create a new file system image and retrieve the root directory
            IFileSystemImage fsi = new MsftFileSystemImage();

            // Set the media size
            fsi.FreeMediaBlocks = dataWriterImage.FreeSectorsOnMedia;

            // Use legacy ISO 9660 Format
            fsi.FileSystemsToCreate = FsiFileSystems.FsiFileSystemISO9660;

            // Add the directory to the disc file system
            IFsiDirectoryItem dir = fsi.Root;
            dir.AddTree(path, false);

            // Create an image from the file system
            Console.WriteLine("Writing content to disc...");
            IFileSystemImageResult result = fsi.CreateResultImage();

            // Data stream sent to the burning device
            IStream stream = result.ImageStream;

            DiscFormat2Data_Events progress = dataWriterImage as DiscFormat2Data_Events;
            progress.Update += new DiscFormat2Data_EventsHandler(DiscFormat2Data_ProgressUpdate);

            // Write the image stream to disc using the specified recorder.
            dataWriterImage.Write(stream);   // Burn the stream to disc

            progress.Update -= new DiscFormat2Data_EventsHandler(DiscFormat2Data_ProgressUpdate);

            Console.WriteLine("----- Finished writing content -----");
        }
예제 #6
0
        /// <summary>
        /// 初始化Recorder
        /// 更新Recorder信息,更新光盘后可重试.
        /// </summary>
        public void InitRecorder()
        {
            try
            {
                if (msRecorder.VolumePathNames != null && msRecorder.VolumePathNames.Length > 0)
                {
                    foreach (object mountPoint in msRecorder.VolumePathNames)
                    {   //挂载点 取其中一个
                        RecorderName = mountPoint.ToString();
                        break;
                    }
                }
                // Define the new disc format and set the recorder
                MsftDiscFormat2Data dataWriter = new MsftDiscFormat2Data();
                dataWriter.Recorder = msRecorder;

                if (!dataWriter.IsRecorderSupported(msRecorder))
                {
                    return;
                }
                if (!dataWriter.IsCurrentMediaSupported(msRecorder))
                {
                    return;
                }
                if (dataWriter.FreeSectorsOnMedia >= 0)
                {   //可用大小
                    FreeDiskSize = dataWriter.FreeSectorsOnMedia * 2048L;
                }

                if (dataWriter.TotalSectorsOnMedia >= 0)
                {   //总大小
                    TotalDiskSize = dataWriter.TotalSectorsOnMedia * 2048L;
                }
                CurMediaState     = dataWriter.CurrentMediaStatus;                  //媒体状态
                CurMediaStateName = RecorderHelper.GetMediaStateName(CurMediaState);
                CurMediaType      = dataWriter.CurrentPhysicalMediaType;            //媒介类型
                CurMediaTypeName  = RecorderHelper.GetMediaTypeName(CurMediaType);
                CanBurn           = RecorderHelper.GetMediaBurnAble(CurMediaState); //判断是否可刻录
            }
            catch (COMException ex)
            {
                string errMsg = ex.Message.Replace("\r\n", ""); //去掉异常信息里的\r\n
                this.CurMediaStateName = $"COM Exception:{errMsg}";
            }
            catch (Exception ex)
            {
                this.CurMediaStateName = $"{ex.Message}";
            }
        }
예제 #7
0
파일: Disc.cs 프로젝트: waffle-iron/nequeo
        /// <summary>
        /// Set the recorder list.
        /// </summary>
        private void SetRecoderList()
        {
            // If recorders exist.
            if (_discMaster.Count > 0)
            {
                int count = 0;

                // Create the list of recorders.
                _discRecoders = new List <DiscRecorder>();

                // For each recirder found.
                foreach (string device in _discMaster)
                {
                    // Initialize the DiscRecorder object for the specified burning device.
                    IDiscRecorder2 recorder = new MsftDiscRecorder2();
                    recorder.InitializeDiscRecorder(_discMaster[count]);

                    // Get the media image.
                    IDiscFormat2Data mediaImage = new MsftDiscFormat2Data();
                    mediaImage.Recorder = recorder;

                    // Create a new recorder.
                    DiscRecorder rec = new DiscRecorder()
                    {
                        Index                   = count,
                        Name                    = device,
                        Recorder                = recorder,
                        MediaImage              = mediaImage,
                        VolumeName              = recorder.VolumeName,
                        ProductId               = recorder.ProductId,
                        VendorId                = recorder.VendorId,
                        ActiveDiscRecorder      = recorder.ActiveDiscRecorder,
                        VolumePathNames         = recorder.VolumePathNames,
                        CurrentFeaturePages     = recorder.CurrentFeaturePages,
                        CurrentProfiles         = recorder.CurrentProfiles,
                        SupportedFeaturePages   = recorder.SupportedFeaturePages,
                        SupportedProfiles       = recorder.SupportedProfiles,
                        SupportedModePages      = recorder.SupportedModePages,
                        IsRecorderSupported     = mediaImage.IsRecorderSupported(recorder),
                        IsCurrentMediaSupported = mediaImage.IsCurrentMediaSupported(recorder),
                        SupportedMediaTypes     = mediaImage.SupportedMediaTypes
                    };

                    // Add the recorder to the list.
                    _discRecoders.Add(rec);
                    count++;
                }
            }
        }
예제 #8
0
        private void buttonDetectMedia_Click(object sender, EventArgs e)
        {
            IDiscRecorder2 discRecorder =
                (IDiscRecorder2)devicesComboBox.Items[devicesComboBox.SelectedIndex];

            //
            // Create and initialize the IDiscFormat2Data
            //
            MsftDiscFormat2Data discFormatData = new MsftDiscFormat2Data();

            if (!discFormatData.IsCurrentMediaSupported(discRecorder))
            {
                labelMediaType.Text = "Media not supported!";
                totalDiscSize       = 0;
                return;
            }
            else
            {
                //
                // Get the media type in the recorder
                //
                discFormatData.Recorder = discRecorder;
                IMAPI_MEDIA_PHYSICAL_TYPE mediaType = discFormatData.CurrentPhysicalMediaType;
                labelMediaType.Text = GetMediaTypeString(mediaType);

                //
                // Create a file system and select the media type
                //
                MsftFileSystemImage fileSystemImage = new MsftFileSystemImage();
                fileSystemImage.ChooseImageDefaultsForMediaType(mediaType);

                //
                // See if there are other recorded sessions on the disc
                //
                if (!discFormatData.MediaHeuristicallyBlank)
                {
                    fileSystemImage.MultisessionInterfaces = discFormatData.MultisessionInterfaces;
                    fileSystemImage.ImportFileSystem();
                }

                Int64 freeMediaBlocks = fileSystemImage.FreeMediaBlocks;
                totalDiscSize = 2048 * freeMediaBlocks;
            }


            UpdateCapacity();
        }
예제 #9
0
        private bool IsMediaWritable(MsftDiscRecorder2 discRecorder)
        {
            MsftFileSystemImage fileSystemImage = null;
            MsftDiscFormat2Data discFormatData  = null;

            try
            {
                // Create and initialize the IDiscFormat2Data
                discFormatData = new MsftDiscFormat2Data();
                if (!discFormatData.IsCurrentMediaSupported(discRecorder))
                {
                    return(false);
                }
                else
                {
                    // Get the media type in the recorder
                    discFormatData.Recorder = discRecorder;
                    IMAPI_MEDIA_PHYSICAL_TYPE mediaType = discFormatData.CurrentPhysicalMediaType;

                    // Create a file system and select the media type
                    fileSystemImage = new MsftFileSystemImage();
                    fileSystemImage.ChooseImageDefaultsForMediaType(mediaType);

                    // See if there are other recorded sessions on the disc
                    if (!discFormatData.MediaHeuristicallyBlank)
                    {
                        try
                        {
                            fileSystemImage.MultisessionInterfaces = discFormatData.MultisessionInterfaces;
                        }
                        catch (Exception ex)
                        {
                            Log.WriteLine(ex.ToString());
                            return(false);
                        }
                        fileSystemImage.ImportFileSystem();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine(ex.ToString());
                return(false);
            }
            return(true);
        }
예제 #10
0
        public static bool CanWriteMedia(IDiscRecorder2 rec)
        {
            var mi = new MsftDiscFormat2Data();

            try
            {
                mi.Recorder = rec;
                return(mi.IsRecorderSupported(rec) && mi.IsCurrentMediaSupported(rec));
            }
            catch
            {
                return(false);
            }
            finally
            {
                Marshal.FinalReleaseComObject(mi);
            }
        }
예제 #11
0
        public string GetNameOfCurrentMedia(int index)
        {
            var discRecorder = devicesList[index];

            MsftDiscFormat2Data discFormatData = null;

            discFormatData = new MsftDiscFormat2Data();
            if (!discFormatData.IsCurrentMediaSupported(discRecorder))
            {
                return("Media not supported!");
            }
            else
            {
                discFormatData.Recorder = discRecorder;
                IMAPI_MEDIA_PHYSICAL_TYPE mediaType = discFormatData.CurrentPhysicalMediaType;
                return(DevicesManager.GetMediaTypeString(mediaType));
            }
        }
예제 #12
0
        /// <summary>
        /// 获得光碟容量
        /// </summary>
        private void GetDiskSize()
        {
            IDiscFormat2Data format2Data = null;

            try
            {
                format2Data = new MsftDiscFormat2Data();

                if (format2Data.IsRecorderSupported(SelectedMediaWriter) == false)
                {
                    this.Host.ShowMessageBox("没有光碟", MessageBoxActions.Ok);
                    return;
                }

                if (!format2Data.IsCurrentMediaSupported(SelectedMediaWriter))
                {
                    this.Host.ShowMessageBox("没有光碟", MessageBoxActions.Ok);
                    _diskSize        = -1;
                    _diskUseAbleSize = -1;
                    return;
                }
                format2Data.Recorder = SelectedMediaWriter;
                IMAPI_MEDIA_PHYSICAL_TYPE mediaType = format2Data.CurrentPhysicalMediaType;
                CurrentMediaDescription = EnumeratorMediaPhysicalLType.GetMediaTypeString(mediaType);
                Int64 totalSectors = format2Data.TotalSectorsOnMedia;
                Int64 freeSectors  = format2Data.FreeSectorsOnMedia;
                _diskSize        = totalSectors * 2048;
                _diskUseAbleSize = freeSectors * 2048;
            }
            catch (COMException e)
            {
                this.Host.ShowMessageBox(ImapiReturnValues.GetName(e.ErrorCode), MessageBoxActions.Ok);
                _diskSize        = 0;
                _diskUseAbleSize = 0;
            }
            finally
            {
                if (format2Data != null)
                {
                    Marshal.ReleaseComObject(format2Data);
                }
            }
        }
예제 #13
0
        /// <summary>
        /// Initializes the drive.  Detects available DVD drives and the media inserted in each drive.
        /// </summary>
        /// <returns>The result of the detection.</returns>
        public override DriveStatus Initialize()
        {
            DriveStatus result = DriveStatus.NoDrive;

            try
            {
                MsftDiscMaster2 discMaster = new MsftDiscMaster2();
                if (!discMaster.IsSupportedEnvironment || discMaster.Count <= 0)
                {
                    result = DriveStatus.NoDrive;
                }
                else
                {
                    bool possibleDriveFound = false;
                    foreach (string recorderID in discMaster)
                    {
                        try
                        {
                            MsftDiscRecorder2 discRecorder2 = new MsftDiscRecorder2();
                            discRecorder2.InitializeDiscRecorder(recorderID);

                            // Check that the drive is supported
                            bool supportsBurn = false;
                            foreach (IMAPI_FEATURE_PAGE_TYPE type in discRecorder2.SupportedFeaturePages)
                            {
                                switch (type)
                                {
                                case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_RANDOMLY_WRITABLE:
                                case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_INCREMENTAL_STREAMING_WRITABLE:
                                case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_WRITE_ONCE:
                                case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_DVD_DASH_WRITE:
                                case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_LAYER_JUMP_RECORDING:
                                case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_BD_WRITE:
                                case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_HD_DVD_WRITE:
                                    supportsBurn = true;
                                    break;
                                }

                                if (supportsBurn)
                                {
                                    break;
                                }
                            }

                            // This device does not support buring, skip it.
                            if (!supportsBurn)
                            {
                                continue;
                            }

                            MsftDiscFormat2Data discFormatData = new MsftDiscFormat2Data();
                            if (!String.IsNullOrEmpty(discRecorder2.ExclusiveAccessOwner))
                            {
                                result = DriveStatus.DriveNotReady;
                            }
                            else if (discFormatData.IsCurrentMediaSupported(discRecorder2))
                            {
                                discFormatData.Recorder = discRecorder2;

                                // Detect the media
                                if (!discFormatData.MediaHeuristicallyBlank)
                                {
                                    result = DriveStatus.MediaNotBlank;
                                }
                                else if (2048L * discFormatData.TotalSectorsOnMedia < this.ImageReader.ImageFile.Length)
                                {
                                    if (!possibleDriveFound)
                                    {
                                        result = DriveStatus.MediaTooSmall;
                                    }
                                }
                                else
                                {
                                    // Valid media found, use this drive.
                                    result = this.SetActiveDrive(recorderID);

                                    // Set the write speed
                                    SetWriteSpeed(discFormatData);

                                    break;
                                }
                            }
                            else if (!possibleDriveFound)
                            {
                                // Check if the media has files on it since IsCurrentMediaSupported returns false when the media is not recordable.
                                DriveInfo info = new DriveInfo((string)discRecorder2.VolumePathNames[0]);
                                if (!info.IsReady)
                                {
                                    result = DriveStatus.NoMedia;
                                }
                                else if (info.RootDirectory.GetFiles().Length > 0 ||
                                         info.RootDirectory.GetDirectories().Length > 0)
                                {
                                    result = DriveStatus.MediaNotBlank;
                                }
                            }

                            // If we found a drive with media, save that as a possible drive, but keep
                            // looking in case there is a drive with valid media.
                            possibleDriveFound = result != DriveStatus.NoDrive && result != DriveStatus.NoMedia;
                        }
                        catch (COMException ex)
                        {
                            switch ((uint)ex.ErrorCode)
                            {
                            case 0xC0AA0205:     // E_IMAPI_RECORDER_MEDIA_BECOMING_READY
                            case 0xC0AA0206:     // E_IMAPI_RECORDER_MEDIA_FORMAT_IN_PROGRESS
                            case 0xC0AA0207:     // E_IMAPI_RECORDER_MEDIA_BUSY
                            case 0xC0AA020D:     // E_IMAPI_RECORDER_COMMAND_TIMEOUT
                            case 0xC0AA0210:     // E_IMAPI_RECORDER_LOCKED
                                result = DriveStatus.DriveNotReady;
                                break;

                            default:
                                result = DriveStatus.InvalidMedia;
                                this.Logging.WriteException("Error trying to read media.", ex);
                                break;
                            }
                        }
                    }
                }
            }
            catch (COMException ex)
            {
                result = DriveStatus.NoDrive;
                this.Logging.WriteException("Error trying to read drives.", ex);
            }

            return(result);
        }
예제 #14
0
파일: MainForm.cs 프로젝트: developer88/umk
        bool if_thereIS_Disk()
        {
            if (devicesComboBox.SelectedIndex == -1)
            {
                return false;
            }
            IDiscRecorder2 discRecorder =
              (IDiscRecorder2)devicesComboBox.Items[devicesComboBox.SelectedIndex];

            MsftDiscFormat2Data discFormatData = null;

            try
            {
                //
                // Create and initialize the IDiscFormat2Data
                //
                discFormatData = new MsftDiscFormat2Data();
                if (!discFormatData.IsCurrentMediaSupported(discRecorder))
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            catch { return false; }
        }
예제 #15
0
        /// <summary>
        /// Examines and reports the media characteristics.
        /// </summary>
        /// <param name="recorder">Burning Device. Must be initialized.</param>
        public void DisplayMediaCharacteristics(IDiscRecorder2 recorder)
        {
            // Define the new disc format and set the recorder
            IDiscFormat2Data mediaImage = new MsftDiscFormat2Data();
            mediaImage.Recorder = recorder;

            // *** Validation methods inherited from IMAPI2.MsftDiscFormat2
            bool boolResult = mediaImage.IsRecorderSupported(recorder);
            if (boolResult)
            {
                Console.WriteLine("--- Current recorder IS supported. ---");
            }
            else
            {
                Console.WriteLine("--- Current recorder IS NOT supported. ---");
            }

            boolResult = mediaImage.IsCurrentMediaSupported(recorder);
            if (boolResult)
            {
                Console.WriteLine("--- Current media IS supported. ---");
            }
            else
            {
                Console.WriteLine("--- Current media IS NOT supported. ---");
            }

            Console.WriteLine("ClientName = {0}", mediaImage.ClientName);

            // Check a few CurrentMediaStatus possibilities. Each status is associated
            // with a bit and some combinations are legal.
            uint curMediaStatus = (uint)mediaImage.CurrentMediaStatus;
            Console.WriteLine("Checking Current Media Status");

            if (curMediaStatus == (uint)IMAPI_FORMAT2_DATA_MEDIA_STATE.IMAPI_FORMAT2_DATA_MEDIA_STATE_UNKNOWN)
            {
                Console.WriteLine("\tMedia state is unknown.");
            }
            else
            {
                if ((curMediaStatus & (uint)IMAPI_FORMAT2_DATA_MEDIA_STATE.IMAPI_FORMAT2_DATA_MEDIA_STATE_OVERWRITE_ONLY) != 0)
                {
                    Console.WriteLine("\tCurrently, only overwriting is supported.");
                }
                if ((curMediaStatus & (uint)IMAPI_FORMAT2_DATA_MEDIA_STATE.IMAPI_FORMAT2_DATA_MEDIA_STATE_RANDOMLY_WRITABLE) != 0)
                {
                    Console.WriteLine("\tCurrently, media supports random writing.");
                }
                if ((curMediaStatus & (uint)IMAPI_FORMAT2_DATA_MEDIA_STATE.IMAPI_FORMAT2_DATA_MEDIA_STATE_APPENDABLE) != 0)
                {
                    Console.WriteLine("\tMedia is currently appendable.");
                }
                if ((curMediaStatus & (uint)IMAPI_FORMAT2_DATA_MEDIA_STATE.IMAPI_FORMAT2_DATA_MEDIA_STATE_FINAL_SESSION) != 0)
                {
                    Console.WriteLine("\tMedia is in final writing session.");
                }
                if ((curMediaStatus & (uint)IMAPI_FORMAT2_DATA_MEDIA_STATE.IMAPI_FORMAT2_DATA_MEDIA_STATE_DAMAGED) != 0)
                {
                    Console.WriteLine("\tMedia is damaged.");
                }
            }

            IMAPI_MEDIA_PHYSICAL_TYPE mediaType = mediaImage.CurrentPhysicalMediaType;
            Console.Write("Current Media Type");
            DisplayMediaType(mediaType);

            Console.WriteLine("SupportedMediaTypes in the device: ");
            foreach (IMAPI_MEDIA_PHYSICAL_TYPE supportedMediaType in mediaImage.SupportedMediaTypes)
            {
                DisplayMediaType(supportedMediaType);
            }

            Console.Write("\n----- Finished -----");
        }
예제 #16
0
        /// <summary>
        /// Backup processing method.  Called from the worker thread.
        /// </summary>
        protected override void Backup()
        {
            if (String.IsNullOrEmpty(this.activeDriveId))
            {
                throw new InvalidOperationException("Drive not initialized.");
            }

            // Reset the time remaining from previous burns.
            this.StatusUpdateArgs.TimeRemaining = TimeSpan.Zero;
            this.UpdateStatus(DriveStatus.Burning);

            MsftDiscRecorder2 discRecorder2 = new MsftDiscRecorder2();
            discRecorder2.InitializeDiscRecorder(this.activeDriveId);
            discRecorder2.AcquireExclusiveAccess(true, ClientName);

            MsftDiscFormat2Data discFormatData = new MsftDiscFormat2Data();
            if (!discFormatData.IsCurrentMediaSupported(discRecorder2))
            {
                throw new IOException("Invalid media.");
            }

            discFormatData.Recorder = discRecorder2;
            discFormatData.ClientName = ClientName;
            discFormatData.ForceMediaToBeClosed = true;
            using (var stream = this.ImageReader.ImageFile.OpenRead())
            {
                discFormatData.Update += this.DiscFormatData_Update;

                try
                {
                    discFormatData.Write(ComStream.ToIStream(stream));
                }
                catch (COMException ex)
                {
                    // Ignore canceled hresult.  Other errors should be reported to the UI thread.
                    if (ex.ErrorCode != -1062600702)
                    {
                        throw;
                    }
                }
                finally
                {
                    discFormatData.Update -= this.DiscFormatData_Update;
                    discRecorder2.EjectMedia();
                }

                // Double check that the burn was completed.  Some cases with XP and 2003 do not
                // return an error, but the burn is not successful.  Using progress < 99 since
                // the last update isn't always returned.
                if (!this.WorkerThread.CancellationPending && this.progress < 99)
                {
                    throw new IOException("Burn not completed.");
                }
            }

            discRecorder2.ReleaseExclusiveAccess();
        }
예제 #17
0
파일: DVD.cs 프로젝트: Zenkinet/valycam
        public Int64 detectDisk(IDiscRecorder2 disk)
        {
            int error_code   = 0;
            var discRecorder = disk;

            MsftFileSystemImage fileSystemImage = null;
            MsftDiscFormat2Data discFormatData  = null;

            try
            {
                //
                // Create and initialize the IDiscFormat2Data
                //
                discFormatData = new MsftDiscFormat2Data();
                if (!discFormatData.IsCurrentMediaSupported(discRecorder))
                {
                    //labelMediaType.Text = "Media not supported!";
                    MessageBox.Show("Media not supported!");
                    _totalDiscSize = 0;
                    error_code     = ERROR_MEDIA_NOT_SUPPORT;
                }
                else
                {
                    //
                    // Get the media type in the recorder
                    //
                    discFormatData.Recorder = discRecorder;
                    IMAPI_MEDIA_PHYSICAL_TYPE mediaType = discFormatData.CurrentPhysicalMediaType;
                    //labelMediaType.Text = GetMediaTypeString(mediaType);

                    //
                    // Create a file system and select the media type
                    //
                    fileSystemImage = new MsftFileSystemImage();
                    fileSystemImage.ChooseImageDefaultsForMediaType(mediaType);

                    //
                    // See if there are other recorded sessions on the disc
                    //
                    if (!discFormatData.MediaHeuristicallyBlank)
                    {
                        fileSystemImage.MultisessionInterfaces =
                            discFormatData.MultisessionInterfaces;
                        fileSystemImage.ImportFileSystem();
                    }

                    Int64 freeMediaBlocks = fileSystemImage.FreeMediaBlocks;
                    _totalDiscSize = 2048 * freeMediaBlocks;
                    MessageBox.Show("Disk size: " + _totalDiscSize.ToString());
                }
            }
            catch (COMException exception)
            {
                MessageBox.Show(exception.Message, "Detect Media Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                error_code = ERROR_DETECT_MEDIA;
            }
            finally
            {
                if (discFormatData != null)
                {
                    Marshal.ReleaseComObject(discFormatData);
                }

                if (fileSystemImage != null)
                {
                    Marshal.ReleaseComObject(fileSystemImage);
                }
            }

            if (error_code != 0)
            {
                return(error_code);
            }

            return(_totalDiscSize);
        }
예제 #18
0
        private void buttonDetectMedia_Click(object sender, EventArgs e)
        {
            if (devicesComboBox.SelectedIndex == -1)
            {
                return;
            }

            var discRecorder =
                (IDiscRecorder2)devicesComboBox.Items[devicesComboBox.SelectedIndex];

            MsftFileSystemImage fileSystemImage = null;
            MsftDiscFormat2Data discFormatData = null;

            try
            {
                //
                // Create and initialize the IDiscFormat2Data
                //
                discFormatData = new MsftDiscFormat2Data();
                if (!discFormatData.IsCurrentMediaSupported(discRecorder))
                {
                    labelMediaType.Text = "Media not supported!";
                    _totalDiscSize = 0;
                    return;
                }
                else
                {
                    //
                    // Get the media type in the recorder
                    //
                    discFormatData.Recorder = discRecorder;
                    IMAPI_MEDIA_PHYSICAL_TYPE mediaType = discFormatData.CurrentPhysicalMediaType;
                    labelMediaType.Text = GetMediaTypeString(mediaType);

                    //
                    // Create a file system and select the media type
                    //
                    fileSystemImage = new MsftFileSystemImage();
                    fileSystemImage.ChooseImageDefaultsForMediaType(mediaType);

                    //
                    // See if there are other recorded sessions on the disc
                    //
                    if (!discFormatData.MediaHeuristicallyBlank)
                    {
                        fileSystemImage.MultisessionInterfaces = discFormatData.MultisessionInterfaces;
                        fileSystemImage.ImportFileSystem();
                    }

                    Int64 freeMediaBlocks = fileSystemImage.FreeMediaBlocks;
                    _totalDiscSize = 2048 * freeMediaBlocks;
                }
            }
            catch (COMException exception)
            {
                MessageBox.Show(this, exception.Message, "Detect Media Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (discFormatData != null)
                {
                    Marshal.ReleaseComObject(discFormatData);
                }

                if (fileSystemImage != null)
                {
                    Marshal.ReleaseComObject(fileSystemImage);
                }
            }


            UpdateCapacity();
        }
예제 #19
0
        /// <summary>
        /// Initializes the drive.  Detects available DVD drives and the media inserted in each drive.
        /// </summary>
        /// <returns>The result of the detection.</returns>
        public override DriveStatus Initialize()
        {
            DriveStatus result = DriveStatus.NoDrive;

            try
            {
                MsftDiscMaster2 discMaster = new MsftDiscMaster2();
                if (!discMaster.IsSupportedEnvironment || discMaster.Count <= 0)
                {
                    result = DriveStatus.NoDrive;
                }
                else
                {
                    bool possibleDriveFound = false;
                    foreach (string recorderID in discMaster)
                    {
                        try
                        {
                            MsftDiscRecorder2 discRecorder2 = new MsftDiscRecorder2();
                            discRecorder2.InitializeDiscRecorder(recorderID);

                            // Check that the drive is supported
                            bool supportsBurn = false;
                            foreach (IMAPI_FEATURE_PAGE_TYPE type in discRecorder2.SupportedFeaturePages)
                            {
                                switch (type)
                                {
                                    case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_RANDOMLY_WRITABLE:
                                    case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_INCREMENTAL_STREAMING_WRITABLE:
                                    case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_WRITE_ONCE:
                                    case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_DVD_DASH_WRITE:
                                    case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_LAYER_JUMP_RECORDING:
                                    case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_BD_WRITE:
                                    case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_HD_DVD_WRITE:
                                        supportsBurn = true;
                                        break;
                                }

                                if (supportsBurn)
                                {
                                    break;
                                }
                            }

                            // This device does not support buring, skip it.
                            if (!supportsBurn)
                            {
                                continue;
                            }

                            MsftDiscFormat2Data discFormatData = new MsftDiscFormat2Data();
                            if (!String.IsNullOrEmpty(discRecorder2.ExclusiveAccessOwner))
                            {
                                result = DriveStatus.DriveNotReady;
                            }
                            else if (discFormatData.IsCurrentMediaSupported(discRecorder2))
                            {
                                discFormatData.Recorder = discRecorder2;

                                // Detect the media
                                if (!discFormatData.MediaHeuristicallyBlank)
                                {
                                    result = DriveStatus.MediaNotBlank;
                                }
                                else if (2048L * discFormatData.TotalSectorsOnMedia < this.ImageReader.ImageFile.Length)
                                {
                                    if (!possibleDriveFound)
                                    {
                                        result = DriveStatus.MediaTooSmall;
                                    }
                                }
                                else
                                {
                                    // Valid media found, use this drive.
                                    result = this.SetActiveDrive(recorderID);

                                    // Set the write speed
                                    SetWriteSpeed(discFormatData);

                                    break;
                                }
                            }
                            else if (!possibleDriveFound)
                            {
                                // Check if the media has files on it since IsCurrentMediaSupported returns false when the media is not recordable.
                                DriveInfo info = new DriveInfo((string)discRecorder2.VolumePathNames[0]);
                                if (!info.IsReady)
                                {
                                    result = DriveStatus.NoMedia;
                                }
                                else if (info.RootDirectory.GetFiles().Length > 0
                                     || info.RootDirectory.GetDirectories().Length > 0)
                                {
                                    result = DriveStatus.MediaNotBlank;
                                }
                            }

                            // If we found a drive with media, save that as a possible drive, but keep
                            // looking in case there is a drive with valid media.
                            possibleDriveFound = result != DriveStatus.NoDrive && result != DriveStatus.NoMedia;
                        }
                        catch (COMException ex)
                        {
                            switch ((uint)ex.ErrorCode)
                            {
                                case 0xC0AA0205: // E_IMAPI_RECORDER_MEDIA_BECOMING_READY
                                case 0xC0AA0206: // E_IMAPI_RECORDER_MEDIA_FORMAT_IN_PROGRESS
                                case 0xC0AA0207: // E_IMAPI_RECORDER_MEDIA_BUSY
                                case 0xC0AA020D: // E_IMAPI_RECORDER_COMMAND_TIMEOUT
                                case 0xC0AA0210: // E_IMAPI_RECORDER_LOCKED
                                    result = DriveStatus.DriveNotReady;
                                    break;
                                default:
                                    result = DriveStatus.InvalidMedia;
                                    this.Logging.WriteException("Error trying to read media.", ex);
                                    break;
                            }
                        }
                    }
                }
            }
            catch (COMException ex)
            {
                result = DriveStatus.NoDrive;
                this.Logging.WriteException("Error trying to read drives.", ex);
            }

            return result;
        }
예제 #20
0
        private void DetectMedia()
        {
            MsftFileSystemImage fileSystemImage = null;
            MsftDiscFormat2Data discFormatData = null;

            try
            {
                discFormatData = new MsftDiscFormat2Data();
                if (!discFormatData.IsCurrentMediaSupported(discRecorder))
                {
                    MediaTypeText = "Media not supported!";
                    totalDiscSize = 0;
                    return;
                }
                else
                {
                    // Get the media type in the recorder
                    discFormatData.Recorder = discRecorder;
                    IMAPI_MEDIA_PHYSICAL_TYPE mediaType = discFormatData.CurrentPhysicalMediaType;
                    MediaTypeText = StringProvider.GetMediaTypeString(mediaType);

                    fileSystemImage = new MsftFileSystemImage();
                    fileSystemImage.ChooseImageDefaultsForMediaType(mediaType);

                    // See if there are other recorded sessions on the disc
                    if (!discFormatData.MediaHeuristicallyBlank)
                    {
                        fileSystemImage.MultisessionInterfaces = discFormatData.MultisessionInterfaces;
                        fileSystemImage.ImportFileSystem();
                    }

                    Int64 freeMediaBlocks = fileSystemImage.FreeMediaBlocks;
                    totalDiscSize = 2048 * freeMediaBlocks;
                }
            }
            catch (COMException exception)
            {
                MessageBox.Show(exception.Message, "Detect Media Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (discFormatData != null)
                    Marshal.ReleaseComObject(discFormatData);

                if (fileSystemImage != null)
                    Marshal.ReleaseComObject(fileSystemImage);
            }

            UpdateCapacity();
        }
예제 #21
0
        /// <summary>
        /// Verifico se il supporto può essere utilizzato per masterizzare
        /// </summary>
        public bool testMedia()
        {
            MsftFileSystemImage fileSystemImage = null;
            MsftDiscFormat2Data discFormatData  = null;

            try
            {
                //
                // Create and initialize the IDiscFormat2Data
                //
                discFormatData = new MsftDiscFormat2Data();
                if (!discFormatData.IsCurrentMediaSupported(discRecorder))
                {
                    System.Diagnostics.Trace.WriteLine("Media not supported!");
                    _totalDiscSize = 0;
                    BurnerMsg errorMediaMsg = new BurnerMsg(this);
                    errorMediaMsg.fase          = Fase.ErrorMedia;
                    errorMediaMsg.statusMessage = "Media not supported!";
                    OnInviaStatoMasterizzazione(errorMediaMsg);
                    return(false);
                }
                else
                {
                    //
                    // Get the media type in the recorder
                    //
                    discFormatData.Recorder = this.discRecorder;
                    IMAPI_MEDIA_PHYSICAL_TYPE mediaType = discFormatData.CurrentPhysicalMediaType;
                    System.Diagnostics.Trace.WriteLine("Etichetta Media: " + GetMediaTypeString(mediaType));

                    //
                    // Create a file system and select the media type
                    //
                    fileSystemImage = new MsftFileSystemImage();
                    fileSystemImage.ChooseImageDefaultsForMediaType(mediaType);

                    //
                    // See if there are other recorded sessions on the disc
                    //
                    if (!discFormatData.MediaHeuristicallyBlank)
                    {
                        fileSystemImage.MultisessionInterfaces = discFormatData.MultisessionInterfaces;
                        fileSystemImage.ImportFileSystem();
                    }

                    Int64 freeMediaBlocks = fileSystemImage.FreeMediaBlocks;
                    _totalDiscSize = 2048 * freeMediaBlocks;
                }
            }
            catch (COMException exception)
            {
                System.Diagnostics.Trace.WriteLine("Detect Media Error " + exception.Message);
                BurnerMsg errorMediaMsg = new BurnerMsg(this);
                errorMediaMsg.fase          = Fase.ErrorMedia;
                errorMediaMsg.statusMessage = "Detect Media Error " + exception.Message;
                OnInviaStatoMasterizzazione(errorMediaMsg);
                return(false);
            }
            finally
            {
                if (discFormatData != null)
                {
                    Marshal.ReleaseComObject(discFormatData);
                }

                if (fileSystemImage != null)
                {
                    Marshal.ReleaseComObject(fileSystemImage);
                }
            }
            UpdateCapacity();
            return(true);
        }
예제 #22
0
        public void scanMedia()
        {
            if (comboBoxDrive.SelectedIndex == -1)
            {
                return;
            }

            IDiscRecorder2      Recorder    = (IDiscRecorder2)comboBoxDrive.Items[comboBoxDrive.SelectedIndex];
            MsftFileSystemImage SystemImage = null;
            MsftDiscFormat2Data FormatData  = null;

            try
            {
                FormatData = new MsftDiscFormat2Data();
                if (!FormatData.IsCurrentMediaSupported(Recorder))
                {
                    ukuranDiscTotal      = 0;
                    pictureBoxDisc.Image = BurnFormat.Properties.Resources.CAUTION;
                    suaraGalat(true);
                    return;
                }
                else
                {
                    FormatData.Recorder = Recorder;
                    IMAPI_MEDIA_PHYSICAL_TYPE mediaType = FormatData.CurrentPhysicalMediaType;
                    pictureBoxDisc.Image = jenisDisc(mediaType);

                    SystemImage = new MsftFileSystemImage();
                    SystemImage.ChooseImageDefaultsForMediaType(mediaType);

                    if (!FormatData.MediaHeuristicallyBlank)
                    {
                        SystemImage.MultisessionInterfaces = FormatData.MultisessionInterfaces;
                        SystemImage.ImportFileSystem();
                    }

                    Int64 spaceBebas = SystemImage.FreeMediaBlocks;
                    ukuranDiscTotal = 2048 * spaceBebas;

                    buttonBurn.Enabled = true;
                }
            }

            catch (COMException exception)
            {
                suaraGalat(true);
                pictureBoxDisc.Image = BurnFormat.Properties.Resources.CAUTION;

                MessageBox.Show(this, exception.Message, pesan,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            finally
            {
                if (FormatData != null)
                {
                    Marshal.ReleaseComObject(FormatData);
                    FormatData = null;
                }

                if (SystemImage != null)
                {
                    Marshal.ReleaseComObject(SystemImage);
                    SystemImage = null;
                }
            }
            kapasitasData();
        }
예제 #23
0
        public long GetTotalDiscSizeOFCurrentMedia(int index)
        {
            var discRecorder = devicesList[index];

            MsftFileSystemImage fileSystemImage = null;
            MsftDiscFormat2Data discFormatData  = null;

            try
            {
                //
                // Create and initialize the IDiscFormat2Data
                //
                discFormatData = new MsftDiscFormat2Data();
                if (!discFormatData.IsCurrentMediaSupported(discRecorder))
                {
                    return(0);
                }
                else
                {
                    //
                    // Get the media type in the recorder
                    //
                    discFormatData.Recorder = discRecorder;
                    IMAPI_MEDIA_PHYSICAL_TYPE mediaType = discFormatData.CurrentPhysicalMediaType;

                    //
                    // Create a file system and select the media type
                    //
                    fileSystemImage = new MsftFileSystemImage();
                    fileSystemImage.ChooseImageDefaultsForMediaType(mediaType);

                    //
                    // See if there are other recorded sessions on the disc
                    //
                    if (!discFormatData.MediaHeuristicallyBlank)
                    {
                        fileSystemImage.MultisessionInterfaces = discFormatData.MultisessionInterfaces;
                        fileSystemImage.ImportFileSystem();
                    }

                    long freeMediaBlocks = fileSystemImage.FreeMediaBlocks;
                    return(2048 * freeMediaBlocks);
                }
            }
            catch (COMException)
            {
                return(0);
            }
            finally
            {
                if (discFormatData != null)
                {
                    Marshal.ReleaseComObject(discFormatData);
                }

                if (fileSystemImage != null)
                {
                    Marshal.ReleaseComObject(fileSystemImage);
                }
            }
        }
예제 #24
0
        public void LoadMedia()
        {
            long mediaStateFlags;
            var  mediaStates = new List <MediaState>();

            if (!_recorderLoaded)
            {
                throw new InvalidOperationException("LoadRecorder must be called first.");
            }
            if (_recorders.SelectedIndex == -1)
            {
                throw new InvalidOperationException("No DiscRecorder selected on the DiscRecorders list.");
            }

            MsftDiscRecorder2   recorder = null;
            MsftFileSystemImage image    = null;
            MsftDiscFormat2Data format   = null;

            try
            {
                recorder = new MsftDiscRecorder2();
                recorder.InitializeDiscRecorder(_recorders.SelectedItem.InternalUniqueId);
                format = new MsftDiscFormat2Data();
                if (!format.IsCurrentMediaSupported(recorder))
                {
                    throw new MediaNotSupportedException("There is no media in the device.");
                }

                //
                // Get the media type in the recorder
                //
                format.Recorder = recorder;
                _media          = (PhysicalMedia)format.CurrentPhysicalMediaType;

                mediaStateFlags = (long)format.CurrentMediaStatus;
                foreach (MediaState state in Enum.GetValues(typeof(MediaState)))
                {
                    if (((long)mediaStateFlags & (long)state) > 0)
                    {
                        mediaStates.Add(state);
                    }
                }
                if (mediaStates.Count == 0)
                {
                    mediaStates.Add(MediaState.Unknown);
                }
                _mediaStates = new ReadOnlyCollection <MediaState>(mediaStates);

                if ((mediaStateFlags & (long)IMAPI_FORMAT2_DATA_MEDIA_STATE.IMAPI_FORMAT2_DATA_MEDIA_STATE_WRITE_PROTECTED) > 0)
                {
                    throw new MediaNotSupportedException("The media in the device is write protected.");
                }
                //
                // Create a file system and select the media type
                //
                image = new MsftFileSystemImage();
                image.ChooseImageDefaultsForMediaType((IMAPI_MEDIA_PHYSICAL_TYPE)_media);

                //
                // See if there are other recorded sessions on the disc
                //
                if (!format.MediaHeuristicallyBlank)
                {
                    image.MultisessionInterfaces = format.MultisessionInterfaces;
                    image.ImportFileSystem();
                }
                _mediaCapacity = 2048 * (long)image.FreeMediaBlocks;
                _mediaLoaded   = true;
            }
            finally
            {
                if (image != null)
                {
                    Marshal.ReleaseComObject(image);
                }
                if (format != null)
                {
                    Marshal.ReleaseComObject(format);
                }
                if (recorder != null)
                {
                    Marshal.ReleaseComObject(recorder);
                }
            }
        }
예제 #25
0
        /// <summary>
        /// Examines and reports the media characteristics.
        /// </summary>
        /// <param name="recorder">Burning Device. Must be initialized.</param>
        public void DisplayMediaCharacteristics(IDiscRecorder2 recorder)
        {
            // Define the new disc format and set the recorder
            IDiscFormat2Data mediaImage = new MsftDiscFormat2Data();

            mediaImage.Recorder = recorder;

            // *** Validation methods inherited from IMAPI2.MsftDiscFormat2
            bool boolResult = mediaImage.IsRecorderSupported(recorder);

            if (boolResult)
            {
                Console.WriteLine("--- Current recorder IS supported. ---");
            }
            else
            {
                Console.WriteLine("--- Current recorder IS NOT supported. ---");
            }

            boolResult = mediaImage.IsCurrentMediaSupported(recorder);
            if (boolResult)
            {
                Console.WriteLine("--- Current media IS supported. ---");
            }
            else
            {
                Console.WriteLine("--- Current media IS NOT supported. ---");
            }

            Console.WriteLine("ClientName = {0}", mediaImage.ClientName);

            // Check a few CurrentMediaStatus possibilities. Each status is associated
            // with a bit and some combinations are legal.
            uint curMediaStatus = (uint)mediaImage.CurrentMediaStatus;

            Console.WriteLine("Checking Current Media Status");

            if (curMediaStatus == (uint)IMAPI_FORMAT2_DATA_MEDIA_STATE.IMAPI_FORMAT2_DATA_MEDIA_STATE_UNKNOWN)
            {
                Console.WriteLine("\tMedia state is unknown.");
            }
            else
            {
                if ((curMediaStatus & (uint)IMAPI_FORMAT2_DATA_MEDIA_STATE.IMAPI_FORMAT2_DATA_MEDIA_STATE_OVERWRITE_ONLY) != 0)
                {
                    Console.WriteLine("\tCurrently, only overwriting is supported.");
                }
                if ((curMediaStatus & (uint)IMAPI_FORMAT2_DATA_MEDIA_STATE.IMAPI_FORMAT2_DATA_MEDIA_STATE_RANDOMLY_WRITABLE) != 0)
                {
                    Console.WriteLine("\tCurrently, media supports random writing.");
                }
                if ((curMediaStatus & (uint)IMAPI_FORMAT2_DATA_MEDIA_STATE.IMAPI_FORMAT2_DATA_MEDIA_STATE_APPENDABLE) != 0)
                {
                    Console.WriteLine("\tMedia is currently appendable.");
                }
                if ((curMediaStatus & (uint)IMAPI_FORMAT2_DATA_MEDIA_STATE.IMAPI_FORMAT2_DATA_MEDIA_STATE_FINAL_SESSION) != 0)
                {
                    Console.WriteLine("\tMedia is in final writing session.");
                }
                if ((curMediaStatus & (uint)IMAPI_FORMAT2_DATA_MEDIA_STATE.IMAPI_FORMAT2_DATA_MEDIA_STATE_DAMAGED) != 0)
                {
                    Console.WriteLine("\tMedia is damaged.");
                }
            }

            IMAPI_MEDIA_PHYSICAL_TYPE mediaType = mediaImage.CurrentPhysicalMediaType;

            Console.Write("Current Media Type");
            DisplayMediaType(mediaType);

            Console.WriteLine("SupportedMediaTypes in the device: ");
            foreach (IMAPI_MEDIA_PHYSICAL_TYPE supportedMediaType in mediaImage.SupportedMediaTypes)
            {
                DisplayMediaType(supportedMediaType);
            }

            Console.Write("\n----- Finished -----");
        }
예제 #26
0
        private bool detectMedia2()
        {
            if (listDrive2.SelectedIndex == -1)
            {
                txtStatus2.Text = "Không có ổ đĩa";
                return(false);
            }

            var discRecorder = (IDiscRecorder2)listDrive2.Items[listDrive2.SelectedIndex];

            MsftFileSystemImage fileSystemImage = null;
            MsftDiscFormat2Data discFormatData  = null;

            try
            {
                // Create and initialize the IDiscFormat2Data
                discFormatData = new MsftDiscFormat2Data();
                if (!discFormatData.IsCurrentMediaSupported(discRecorder))
                {
                    txtStatus2.Text = "Ổ đĩa không có chức năng ghi";
                    return(false);
                }
                else
                {
                    // Get the media type in the recorder
                    discFormatData.Recorder = discRecorder;
                    IMAPI_MEDIA_PHYSICAL_TYPE mediaType = discFormatData.CurrentPhysicalMediaType;
                    txtStatus2.Text = GetMediaTypeString(mediaType);

                    // Create a file system and select the media type
                    fileSystemImage = new MsftFileSystemImage();
                    fileSystemImage.ChooseImageDefaultsForMediaType(mediaType);

                    // See if there are other recorded sessions on the disc
                    if (!discFormatData.MediaHeuristicallyBlank)
                    {
                        try
                        {
                            fileSystemImage.MultisessionInterfaces = discFormatData.MultisessionInterfaces;
                            fileSystemImage.ImportFileSystem();
                        }
                        catch (Exception ex)
                        {
                            txtStatus2.Text = GetMediaTypeString(mediaType) + " - " + "Đĩa đã bị khóa chức năng ghi.";
                            Log.WriteLine(ex.ToString());
                            return(false);
                        }
                    }

                    Int64 freeMediaBlocks = fileSystemImage.FreeMediaBlocks;
                    long  _totalDiscSize  = 2048 * freeMediaBlocks;

                    txtStatus2.Text = GetMediaTypeString(mediaType) + " - " + "Dung lượng trống: " + (_totalDiscSize < 1000000000 ?
                                                                                                      string.Format("{0}MB", _totalDiscSize / 1000000) :
                                                                                                      string.Format("{0:F2}GB", (float)_totalDiscSize / 1000000000.0));
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine(ex.ToString());
                return(false);
            }

            return(true);
        }
예제 #27
0
        public void LoadMedia()
        {
            long mediaStateFlags;
            var mediaStates = new List<MediaState>();

            if (!_recorderLoaded)
                throw new InvalidOperationException("LoadRecorder must be called first.");
            if (_recorders.SelectedIndex == -1)
                throw new InvalidOperationException("No DiscRecorder selected on the DiscRecorders list.");

            MsftDiscRecorder2 recorder = null;
            MsftFileSystemImage image = null;
            MsftDiscFormat2Data format = null;

            try
            {
                recorder = new MsftDiscRecorder2();
                recorder.InitializeDiscRecorder(_recorders.SelectedItem.InternalUniqueId);
                format = new MsftDiscFormat2Data();
                if (!format.IsCurrentMediaSupported(recorder))
                    throw new MediaNotSupportedException("There is no media in the device.");

                //
                // Get the media type in the recorder
                //
                format.Recorder = recorder;
                _media = (PhysicalMedia)format.CurrentPhysicalMediaType;

                mediaStateFlags = (long)format.CurrentMediaStatus;
                foreach (MediaState state in Enum.GetValues(typeof(MediaState)))
                {
                    if (((long)mediaStateFlags & (long)state) > 0)
                        mediaStates.Add(state);
                }
                if (mediaStates.Count == 0) mediaStates.Add(MediaState.Unknown);
                _mediaStates = new ReadOnlyCollection<MediaState>(mediaStates);

                if ((mediaStateFlags & (long)IMAPI_FORMAT2_DATA_MEDIA_STATE.IMAPI_FORMAT2_DATA_MEDIA_STATE_WRITE_PROTECTED) > 0)
                    throw new MediaNotSupportedException("The media in the device is write protected.");
                //
                // Create a file system and select the media type
                //
                image = new MsftFileSystemImage();
                image.ChooseImageDefaultsForMediaType((IMAPI_MEDIA_PHYSICAL_TYPE)_media);

                //
                // See if there are other recorded sessions on the disc
                //
                if (!format.MediaHeuristicallyBlank)
                {
                    image.MultisessionInterfaces = format.MultisessionInterfaces;
                    image.ImportFileSystem();
                }

                _mediaCapacity = 2048 * image.FreeMediaBlocks;
                _mediaLoaded = true;
            }
            finally
            {
                if (image != null) Marshal.ReleaseComObject(image);
                if (format != null) Marshal.ReleaseComObject(format);
                if (recorder != null) Marshal.ReleaseComObject(recorder);
            }
        }