예제 #1
0
 public IsoCreator()
 {
     _isDisposed      = false;
     _fileSystemImage = Activator.CreateInstance(IMAPI2FS_MsftFileSystemImage);
     _items           = new SortedDictionary <string, FileSystemInfo>();
     FileSystems      = FsiFileSystems.FsiFileSystemISO9660 | FsiFileSystems.FsiFileSystemJoliet;
     VolumeName       = DateTime.Now.ToString("yyyyMMddHHmmss");
     MediaType        = IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DISK;
 }
예제 #2
0
        private void DetectMedia()
        {
            if (this.cboDevice.SelectedIndex == -1)
            {
                return;
            }
            IDiscRecorder2      tag = (IDiscRecorder2)this.cboDevice.SelectedItem.Tag;
            MsftFileSystemImage msftFileSystemImageClass = null;
            GInterface6         msftDiscFormat2DataClass = null;

            try
            {
                try
                {
                    msftDiscFormat2DataClass = (GInterface6)(new MsftDiscFormat2DataClass());
                    if (msftDiscFormat2DataClass.IsCurrentMediaSupported(tag))
                    {
                        msftDiscFormat2DataClass.Recorder = tag;
                        IMAPI_MEDIA_PHYSICAL_TYPE currentPhysicalMediaType = msftDiscFormat2DataClass.CurrentPhysicalMediaType;
                        this.lblMedia.Text       = this.cdUtil.GetMediaTypeString(currentPhysicalMediaType);
                        msftFileSystemImageClass = (MsftFileSystemImage)(new MsftFileSystemImageClass());
                        msftFileSystemImageClass.ChooseImageDefaultsForMediaType(currentPhysicalMediaType);
                        if (!msftDiscFormat2DataClass.MediaHeuristicallyBlank)
                        {
                            msftFileSystemImageClass.MultisessionInterfaces = msftDiscFormat2DataClass.MultisessionInterfaces;
                            msftFileSystemImageClass.ImportFileSystem();
                        }
                        this._totalDiscSize       = 2048L * (long)msftFileSystemImageClass.FreeMediaBlocks;
                        this.btn_BurnDisc.Enabled = true;
                    }
                    else
                    {
                        this.lblMedia.Text  = LangCtrl.GetString("lblMedia", "NO MEDIA");
                        this._totalDiscSize = 0L;
                        return;
                    }
                }
                catch (COMException cOMException1)
                {
                    COMException cOMException = cOMException1;
                    MessageBox.Show(this, cOMException.Message, "Detect Media Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
            }
            finally
            {
                if (msftDiscFormat2DataClass != null)
                {
                    Marshal.ReleaseComObject(msftDiscFormat2DataClass);
                }
                if (msftFileSystemImageClass != null)
                {
                    Marshal.ReleaseComObject(msftFileSystemImageClass);
                }
            }
            this.UpdateCapacity();
        }
예제 #3
0
        public void IMAPIToMediaTypeTest(IMAPI_MEDIA_PHYSICAL_TYPE imapiType, bool expectNull)
        {
            var actual = imapiType.IMAPIToMediaType();

            if (expectNull)
            {
                Assert.Null(actual);
            }
            else
            {
                Assert.NotNull(actual);
            }
        }
예제 #4
0
        /// <summary>
        /// Displays the string of the specified IMAPI_MEDIA_PHYSICAL_TYPE.
        /// </summary>
        /// <param name="mediaType">The IMAPI_MEDIA_PHYSICAL_TYPE to display.</param>
        /// <returns>The media type text.</returns>
        public string GetMediaType(IMAPI_MEDIA_PHYSICAL_TYPE mediaType)
        {
            switch (mediaType)
            {
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_UNKNOWN:
                return("Empty device or an unknown disc type.");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDROM:
                return("CD-ROM");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDR:
                return("CD-R");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDRW:
                return("CD-RW");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDROM:
                return("Read-only DVD drive and/or disc");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDRAM:
                return("DVD-RAM");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR:
                return("DVD+R");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSRW:
                return("DVD+RW");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR_DUALLAYER:
                return("DVD+R Dual Layer media");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR:
                return("DVD-R");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHRW:
                return("DVD-RW");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR_DUALLAYER:
                return("DVD-R Dual Layer media");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DISK:
                return("Randomly-writable, hardware-defect managed media type that reports the \"Disc\" profile as current.");

            default:
                return("Error!: MediaPhysicalType");
            }
        }
예제 #5
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();
        }
예제 #6
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);
        }
예제 #7
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));
            }
        }
예제 #8
0
        public void scanMedia()
        {
            if (comboBoxDrive.SelectedIndex == -1)
            {
                return;
            }

            IDiscRecorder2       Recorder    = (IDiscRecorder2)comboBoxDrive.Items[comboBoxDrive.SelectedIndex];
            MsftDiscFormat2Erase FormatErase = null;

            try
            {
                FormatErase = new MsftDiscFormat2Erase();
                if (!FormatErase.IsCurrentMediaSupported(Recorder))
                {
                    pictureBoxDisc.Image = BurnFormat.Properties.Resources.CAUTION;
                    suaraGalat(true);
                    buttonFormat.Enabled = false;
                    return;
                }
                else
                {
                    FormatErase.Recorder = Recorder;
                    IMAPI_MEDIA_PHYSICAL_TYPE mediaType = FormatErase.CurrentPhysicalMediaType;
                    pictureBoxDisc.Image = jenisDisc(mediaType);
                    buttonFormat.Enabled = true;
                }
            }

            catch
            {
                suaraGalat(true);
                buttonFormat.Enabled = false;
            }

            finally
            {
                if (FormatErase != null)
                {
                    Marshal.ReleaseComObject(FormatErase);
                    FormatErase = null;
                }
            }
        }
예제 #9
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);
                }
            }
        }
예제 #10
0
        /// <summary>
        /// Convert IMAPI physical media type to a MediaType
        /// </summary>
        /// <param name="type">IMAPI_MEDIA_PHYSICAL_TYPE value to check</param>
        /// <returns>MediaType if possible, null on error</returns>
        public static MediaType?IMAPIToMediaType(this IMAPI_MEDIA_PHYSICAL_TYPE type)
        {
            switch (type)
            {
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_UNKNOWN:
                return(MediaType.NONE);

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDROM:
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDR:
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDRW:
                return(MediaType.CDROM);

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDROM:
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDRAM:
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR:
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSRW:
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR_DUALLAYER:
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR:
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHRW:
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR_DUALLAYER:
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DISK:
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSRW_DUALLAYER:
                return(MediaType.DVD);

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_HDDVDROM:
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_HDDVDR:
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_HDDVDRAM:
                return(MediaType.HDDVD);

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDROM:
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDR:
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDRE:
                return(MediaType.BluRay);

            default:
                return(null);
            }
        }
예제 #11
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();
        }
 public HRESULT ChooseImageDefaultsForMediaType(IMAPI_MEDIA_PHYSICAL_TYPE value)
 {
     return(((delegate * unmanaged <IFileSystemImage2 *, IMAPI_MEDIA_PHYSICAL_TYPE, int>)(lpVtbl[35]))((IFileSystemImage2 *)Unsafe.AsPointer(ref this), value));
 }
예제 #13
0
 /// <summary>
 /// Helper Function: Displays the string of the specified IMAPI_MEDIA_PHYSICAL_TYPE
 /// </summary>
 /// <param name="mediaType">The IMAPI_MEDIA_PHYSICAL_TYPE to display</param>
 private void DisplayMediaType(IMAPI_MEDIA_PHYSICAL_TYPE mediaType)
 {
     switch (mediaType)
     {
         case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_UNKNOWN:
             {
                 Console.WriteLine("\tEmpty device or an unknown disc type.");
             } break;
         case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDROM:
             {
                 Console.WriteLine("\tCD-ROM");
             } break;
         case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDR:
             {
                 Console.WriteLine("\tCD-R");
             } break;
         case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDRW:
             {
                 Console.WriteLine("\tCD-RW");
             } break;
         case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDROM:
             {
                 Console.WriteLine("\tRead-only DVD drive and/or disc");
             } break;
         case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDRAM:
             {
                 Console.WriteLine("\tDVD-RAM");
             } break;
         case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR:
             {
                 Console.WriteLine("\tDVD+R");
             } break;
         case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSRW:
             {
                 Console.WriteLine("\tDVD+RW");
             } break;
         case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR_DUALLAYER:
             {
                 Console.WriteLine("\tDVD+R Dual Layer media");
             } break;
         case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR:
             {
                 Console.WriteLine("\tDVD-R");
             } break;
         case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHRW:
             {
                 Console.WriteLine("\tDVD-RW");
             } break;
         case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR_DUALLAYER:
             {
                 Console.WriteLine("\tDVD-R Dual Layer media");
             } break;
         case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DISK:
             {
                 Console.WriteLine("\tRandomly-writable, hardware-defect managed media type" +
                                   " that reports the \"Disc\" profile as current.");
             } break;
         default:
             {
                 Console.WriteLine("Error!: MediaPhysicalType");
             } break;
     }
 }
예제 #14
0
 void IFileSystemImage.ChooseImageDefaultsForMediaType(IMAPI_MEDIA_PHYSICAL_TYPE value)
 {
     _mediatype = value;
 }
예제 #15
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);
        }
예제 #16
0
        /// <summary>
        /// 获取媒体类型描述
        /// </summary>
        /// <returns></returns>
        public static string GetMediaTypeName(IMAPI_MEDIA_PHYSICAL_TYPE mediaType)
        {
            string mediaTypeName = "";

            switch (mediaType)
            {
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDR:
                break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDRE:
                break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDROM:
                break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDR:
                mediaTypeName = "CD-R";
                break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDROM:
                mediaTypeName = "CD-ROM";
                break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDRW:
                mediaTypeName = "CD-RW";
                break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DISK:
                mediaTypeName = "Randomly-writable, hardware-defect managed media type " +
                                "that reports the \"Disc\" profile as current.";
                break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR:
                mediaTypeName = "DVD-R";
                break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHRW:
                mediaTypeName = "DVD-RW";
                break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR_DUALLAYER:
                mediaTypeName = "DVD-R Dual Layer media";
                break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR:
                mediaTypeName = "DVD+R";
                break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSRW:
                mediaTypeName = "DVD+RW";
                break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSRW_DUALLAYER:
                break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR_DUALLAYER:
                mediaTypeName = "DVD+R Dual Layer media";
                break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDRAM:
                mediaTypeName = "DVD-RAM";
                break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDROM:
                mediaTypeName = "Read-only DVD drive and/or disc";
                break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_HDDVDR:
                break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_HDDVDRAM:
                break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_HDDVDROM:
                break;

            //case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_MAX:
            //  break;
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_UNKNOWN:
                mediaTypeName = "Empty device or an unknown disc type.";
                break;

            default:
                break;
            }
            return(mediaTypeName);
        }
예제 #17
0
        /// <summary>
        /// Helper Function: Displays the string of the specified IMAPI_MEDIA_PHYSICAL_TYPE
        /// </summary>
        /// <param name="mediaType">The IMAPI_MEDIA_PHYSICAL_TYPE to display</param>
        private void DisplayMediaType(IMAPI_MEDIA_PHYSICAL_TYPE mediaType)
        {
            switch (mediaType)
            {
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_UNKNOWN:
            {
                Console.WriteLine("\tEmpty device or an unknown disc type.");
            } break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDROM:
            {
                Console.WriteLine("\tCD-ROM");
            } break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDR:
            {
                Console.WriteLine("\tCD-R");
            } break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDRW:
            {
                Console.WriteLine("\tCD-RW");
            } break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDROM:
            {
                Console.WriteLine("\tRead-only DVD drive and/or disc");
            } break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDRAM:
            {
                Console.WriteLine("\tDVD-RAM");
            } break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR:
            {
                Console.WriteLine("\tDVD+R");
            } break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSRW:
            {
                Console.WriteLine("\tDVD+RW");
            } break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR_DUALLAYER:
            {
                Console.WriteLine("\tDVD+R Dual Layer media");
            } break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR:
            {
                Console.WriteLine("\tDVD-R");
            } break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHRW:
            {
                Console.WriteLine("\tDVD-RW");
            } break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR_DUALLAYER:
            {
                Console.WriteLine("\tDVD-R Dual Layer media");
            } break;

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DISK:
            {
                Console.WriteLine("\tRandomly-writable, hardware-defect managed media type" +
                                  " that reports the \"Disc\" profile as current.");
            } break;

            default:
            {
                Console.WriteLine("Error!: MediaPhysicalType");
            } break;
            }
        }
예제 #18
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 -----");
        }
예제 #19
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);
                }
            }
        }
예제 #20
0
        private static string GetMediaTypeString(IMAPI_MEDIA_PHYSICAL_TYPE mediaType)
        {
            switch (mediaType)
            {
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_UNKNOWN:
            default:
                return("Unknown Media Type");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDROM:
                return("CD-ROM");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDR:
                return("CD-R");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDRW:
                return("CD-RW");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDROM:
                return("DVD ROM");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDRAM:
                return("DVD-RAM");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR:
                return("DVD+R");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSRW:
                return("DVD+RW");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR_DUALLAYER:
                return("DVD+R Dual Layer");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR:
                return("DVD-R");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHRW:
                return("DVD-RW");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR_DUALLAYER:
                return("DVD-R Dual Layer");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DISK:
                return("random-access writes");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSRW_DUALLAYER:
                return("DVD+RW DL");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_HDDVDROM:
                return("HD DVD-ROM");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_HDDVDR:
                return("HD DVD-R");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_HDDVDRAM:
                return("HD DVD-RAM");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDROM:
                return("Blu-ray DVD (BD-ROM)");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDR:
                return("Blu-ray media");

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDRE:
                return("Blu-ray Rewritable media");
            }
        }
예제 #21
0
        /// <summary>
        /// converts an IMAPI_MEDIA_PHYSICAL_TYPE to it's string
        /// </summary>
        /// <param name="mediaType"></param>
        /// <returns></returns>
        public static string GetMediaTypeString(IMAPI_MEDIA_PHYSICAL_TYPE mediaType)
        {
            switch (mediaType)
            {
                //case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_UNKNOWN:
                default:
                    return "Unknown Media Type";

                case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDROM:
                    return "CD-ROM";

                case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDR:
                    return "CD-R";

                case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDRW:
                    return "CD-RW";

                case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDROM:
                    return "DVD ROM";

                case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDRAM:
                    return "DVD-RAM";

                case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR:
                    return "DVD+R";

                case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSRW:
                    return "DVD+RW";

                case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR_DUALLAYER:
                    return "DVD+R Dual Layer";

                case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR:
                    return "DVD-R";

                case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHRW:
                    return "DVD-RW";

                case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR_DUALLAYER:
                    return "DVD-R Dual Layer";

                case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DISK:
                    return "random-access writes";

                case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSRW_DUALLAYER:
                    return "DVD+RW DL";

                case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_HDDVDROM:
                    return "HD DVD-ROM";

                case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_HDDVDR:
                    return "HD DVD-R";

                case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_HDDVDRAM:
                    return "HD DVD-RAM";

                case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDROM:
                    return "Blu-ray DVD (BD-ROM)";

                case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDR:
                    return "Blu-ray media";

                case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDRE:
                    return "Blu-ray Rewritable media";
            }
        }
예제 #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
        Image jenisDisc(IMAPI_MEDIA_PHYSICAL_TYPE disc)
        {
            switch (disc)
            {
            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_UNKNOWN:
            default:
                return(BurnFormat.Properties.Resources.CAUTION);

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDROM:
                return(BurnFormat.Properties.Resources.CDROM);

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDR:
                return(BurnFormat.Properties.Resources.CDminR);

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDRW:
                return(BurnFormat.Properties.Resources.CDminRW);

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDROM:
                return(BurnFormat.Properties.Resources.DVDROM);

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDRAM:
                return(BurnFormat.Properties.Resources.DVDminRAM);

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR:
                return(BurnFormat.Properties.Resources.DVDplusR);

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSRW:
                return(BurnFormat.Properties.Resources.DVDplusRW);

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR_DUALLAYER:
                return(BurnFormat.Properties.Resources.DVDplusRDL);

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR:
                return(BurnFormat.Properties.Resources.DVDminR);

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHRW:
                return(BurnFormat.Properties.Resources.DVDminRW);

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR_DUALLAYER:
                return(BurnFormat.Properties.Resources.DVDminRDL);

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DISK:
                return(BurnFormat.Properties.Resources.RAM);

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSRW_DUALLAYER:
                return(BurnFormat.Properties.Resources.HDDVDDL);

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_HDDVDROM:
                return(BurnFormat.Properties.Resources.HDDVD);

            /*case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_HDDVDR:
             *  return BurnFormat.Properties.Resources.HDDVDminR;*/

            /*case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_HDDVDRAM:
             *  return BurnFormat.Properties.Resources.HDDVDminRAM;*/

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDROM:
                return(BurnFormat.Properties.Resources.BD);

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDR:
                return(BurnFormat.Properties.Resources.BD);

            case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDRE:
                return(BurnFormat.Properties.Resources.BDminRE);
            }
        }
예제 #24
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);
        }
예제 #25
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);
        }