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; } } }
/// <summary> /// 擦除光碟中数据 /// </summary> private void DoEreaseDisc() { if (SelectedMediaWriter == null) { return; } MsftDiscFormat2Erase discFormatErase = null; try { // // Create the IDiscFormat2Erase and set properties // discFormatErase = new MsftDiscFormat2Erase { Recorder = SelectedMediaWriter, ClientName = "ApplicationName", FullErase = true }; if (discFormatErase.IsCurrentMediaSupported(SelectedMediaWriter)) { this.Host.ShowMessageBox("没有光碟", MessageBoxActions.Ok); return; } // // Setup the Update progress event handler // discFormatErase.Update += discFormatErase_Update; // // Erase the media here // discFormatErase.EraseMedia(); // // Remove the Update progress event handler // discFormatErase.Update -= discFormatErase_Update; // // Eject the media // if (EjectOnCompleted) { SelectedMediaWriter.EjectMedia(); } } catch (COMException exception) { // // If anything happens during the format, show the message // this.Host.ShowMessageBox(ImapiReturnValues.GetName(exception.ErrorCode), MessageBoxActions.Ok); } finally { if (discFormatErase != null) { Marshal.ReleaseComObject(discFormatErase); } } }