public void EjectMedia() { if (_selectedMediaWriter == null) { this.Host.ShowMessageBox("请选择光驱", MessageBoxActions.Ok); return; } try { SelectedMediaWriter.EjectMedia(); } catch (COMException e) { this.Host.ShowMessageBox(ImapiReturnValues.GetName(e.ErrorCode), MessageBoxActions.Ok); } }
/// <summary> /// 刻录到光碟上 /// </summary> /// <param name="data">数据</param> private void DoBurn(List <IBurnMediaData> data) { if (data == null || data.Count == 0 || SelectedMediaWriter == null) { return; } MsftDiscFormat2Data discFormat2Data = null; IStream fileSystem = null; try { // // Create and initialize the IDiscFormat2Data // discFormat2Data = new MsftDiscFormat2Data { Recorder = SelectedMediaWriter, ClientName = "ApplicationName", ForceMediaToBeClosed = false }; //if (!discFormat2Data.IsCurrentMediaSupported(SelectedMediaWriter)) //{ // this.Host.ShowMessageBox("没有光碟", MessageBoxActions.Ok); // return; //} // // Set the verification level // var burnVerification = (IBurnVerification)discFormat2Data; burnVerification.BurnVerificationLevel = IMAPI_BURN_VERIFICATION_LEVEL.IMAPI_BURN_VERIFICATION_FULL; // // Check if media is blank, (for RW media) // object[] multisessionInterfaces = null; if (!discFormat2Data.MediaHeuristicallyBlank) { multisessionInterfaces = discFormat2Data.MultisessionInterfaces; } // // Create the file system // if (!CreateMediaFileSystem(SelectedMediaWriter, multisessionInterfaces, data, out fileSystem)) { return; } // // add the Update event handler // discFormat2Data.Update += discFormatData_Update; // // Write the data here // discFormat2Data.Write(fileSystem); // // remove the Update event handler // discFormat2Data.Update -= discFormatData_Update; if (EjectOnCompleted) { SelectedMediaWriter.EjectMedia(); } } catch (COMException e) { this.Host.ShowMessageBox(e.Message, MessageBoxActions.Ok); } finally { if (fileSystem != null) { Marshal.FinalReleaseComObject(fileSystem); } if (discFormat2Data != null) { Marshal.ReleaseComObject(discFormat2Data); } } }
/// <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); } } }