/// <summary> /// Initialize the form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainForm_Load(object sender, EventArgs e) { // // Determine the current recording devices // MsftDiscMaster2 discMaster = new MsftDiscMaster2(); if (!discMaster.IsSupportedEnvironment) { return; } foreach (string uniqueRecorderID in discMaster) { MsftDiscRecorder2 discRecorder2 = new MsftDiscRecorder2(); discRecorder2.InitializeDiscRecorder(uniqueRecorderID); devicesComboBox.Items.Add(discRecorder2); } if (devicesComboBox.Items.Count > 0) { devicesComboBox.SelectedIndex = 0; } // // Create the volume label based on the current date // DateTime now = DateTime.Now; textBoxLabel.Text = now.Year + "_" + now.Month + "_" + now.Day; labelStatusText.Text = string.Empty; labelFormatStatusText.Text = string.Empty; UpdateCapacity(); }
internal DiscRecorder(string uniqueId) { _internalUniqueId = uniqueId; MsftDiscRecorder2 recorder = null; try { List <MediaProfile> profiles; recorder = new MsftDiscRecorder2(); recorder.InitializeDiscRecorder(uniqueId); profiles = new List <MediaProfile>(); foreach (IMAPI_PROFILE_TYPE item in recorder.SupportedProfiles) { profiles.Add((MediaProfile)item); } _profiles = profiles.AsReadOnly(); VolumePath = recorder.VolumePathNames.Length > 0 ? recorder.VolumePathNames.GetValue(0).ToString() : string.Empty; RecorderId = recorder.ProductId; } finally { if (recorder != null) { Marshal.ReleaseComObject(recorder); } } }
/// <summary> /// Initialize the form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainForm_Load(object sender, EventArgs e) { // // Determine the current recording devices // MsftDiscMaster2 discMaster = null; try { discMaster = new MsftDiscMaster2(); if (!discMaster.IsSupportedEnvironment) { return; } foreach (string uniqueRecorderId in discMaster) { var discRecorder2 = new MsftDiscRecorder2(); discRecorder2.InitializeDiscRecorder(uniqueRecorderId); devicesComboBox.Items.Add(discRecorder2); } if (devicesComboBox.Items.Count > 0) { devicesComboBox.SelectedIndex = 0; } } catch (COMException ex) { MessageBox.Show(ex.Message, string.Format("Error:{0} - Please install IMAPI2", ex.ErrorCode), MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } finally { if (discMaster != null) { Marshal.ReleaseComObject(discMaster); } } // // Create the volume label based on the current date // DateTime now = DateTime.Now; textBoxLabel.Text = now.Year + "_" + now.Month + "_" + now.Day; labelStatusText.Text = string.Empty; labelFormatStatusText.Text = string.Empty; // // Select no verification, by default // comboBoxVerification.SelectedIndex = 0; UpdateCapacity(); }
//trial private void button1_Click(object sender, RoutedEventArgs e) { IDiscRecorder2 recorder = new MsftDiscRecorder2(); recorder.InitializeDiscRecorder(selectedDrive); IDiscRecorder2Ex dr2 = recorder as IDiscRecorder2Ex; //recorder.QueryInterface(); byte[] resp = new byte[32]; byte[] recv = new byte[18]; uint sb = 1024; IntPtr respPtr; resp[0] = 0; resp[1] = 0; resp[2] = 0; resp[3] = 0; resp[4] = 0; resp[5] = 0; resp[6] = 0; resp[7] = 0; resp[8] = 0; resp[9] = 0; resp[10] = 0; resp[11] = 0; resp[12] = 0; try { dr2.SendCommandNoData(resp, 6, recv, 60); dr2.GetDiscInformation(out respPtr, ref sb); if (sb > 1024) { sb = 1024; } Marshal.Copy(respPtr, resp, 0, (int)sb); } catch (System.Runtime.InteropServices.COMException) { } }
public List<MsftDiscRecorder2> GetRecordingDevices() { var result = new List<MsftDiscRecorder2>(); MsftDiscMaster2 discMaster = null; try { discMaster = new MsftDiscMaster2(); if (!discMaster.IsSupportedEnvironment) return result; foreach (string uniqueRecorderId in discMaster) { var discRecorder2 = new MsftDiscRecorder2(); discRecorder2.InitializeDiscRecorder(uniqueRecorderId); result.Add(discRecorder2); } } catch (COMException ex) { MessageBox.Show(ex.Message, string.Format("Error: {0} - Please install IMAPI2", ex.ErrorCode), MessageBoxButtons.OK, MessageBoxIcon.Stop); return result; } finally { if (discMaster != null) Marshal.ReleaseComObject(discMaster); } return result; }
internal DiscRecorder(string uniqueId) { _internalUniqueId = uniqueId; MsftDiscRecorder2 recorder = null; try { List <MediaProfile> profiles; recorder = new MsftDiscRecorder2(); recorder.InitializeDiscRecorder(uniqueId); profiles = new List <MediaProfile>(); foreach (IMAPI_PROFILE_TYPE item in recorder.SupportedProfiles) { profiles.Add((MediaProfile)item); } _profiles = profiles.AsReadOnly(); } finally { if (recorder != null) { Marshal.ReleaseComObject(recorder); } } }
/// <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(); }
private void EraseStart_Click(object sender, RoutedEventArgs e) { CancelButton.IsEnabled = false; EraseStartButton.IsEnabled = false; eraseProgress.IsEnabled = true; checkQuickErase.IsEnabled = false; String driveId = (String)Application.Current.Properties["driveId"]; eraseStatusText.Text = Properties.Resources.MediaErase_Erasing; ThreadStart start = delegate() { IDiscRecorder2 recorder = new MsftDiscRecorder2(); recorder.InitializeDiscRecorder(driveId); recorder.AcquireExclusiveAccess(true, "imapi_erase_test"); IDiscFormat2Erase discErase = new MsftDiscFormat2Erase(); discErase.Recorder = recorder; discErase.ClientName = "imapi_erase_test"; try { discErase.FullErase = (bool)checkQuickErase.IsChecked; } catch (System.InvalidOperationException) { discErase.FullErase = false; } DiscFormat2Erase_Events eraseEvent = discErase as DiscFormat2Erase_Events; //DiscFormat2Data_Events burnProgress = dataWriterImage as DiscFormat2Data_Events; if (discErase.FullErase) { eraseEvent.Update += new DiscFormat2Erase_EventsHandler(OnEraseProgress); } try{ discErase.EraseMedia(); } catch { //this.DialogResult = true; } if (discErase.FullErase) { eraseEvent.Update -= new DiscFormat2Erase_EventsHandler(OnEraseProgress); } recorder.ReleaseExclusiveAccess(); Dispatcher.Invoke(new System.EventHandler(OnEraseFinished), this, null); }; Thread thread = new Thread(start); thread.IsBackground = true; thread.Start(); }
private int DoBurn(string activeDiscRecorder) { int result = 0; var discMaster = new MsftDiscMaster2(); var discRecorder2 = new MsftDiscRecorder2(); discRecorder2.InitializeDiscRecorder(activeDiscRecorder); var trackAtOnce = new MsftDiscFormat2TrackAtOnce(); trackAtOnce.ClientName = ""; trackAtOnce.Recorder = discRecorder2; burnData.totalTracks = mediaItems.Count; burnData.currentTrackNumber = 0; // Prepare the wave file streams foreach (MediaFile mediaFile in mediaItems) { if (cancellationToken.IsCancellationRequested) break; // Report back to the UI that we're preparing stream burnData.task = BURN_MEDIA_TASK.BURN_MEDIA_TASK_PREPARING; burnData.filename = mediaFile.ToString(); burnData.currentTrackNumber++; burnProgress.Report(burnData); mediaFile.PrepareStream(); } trackAtOnce.Update += trackAtOnce_Update; trackAtOnce.PrepareMedia(); foreach (MediaFile mediaFile in mediaItems) { if (cancellationToken.IsCancellationRequested) { result = -1; break; } burnData.filename = mediaFile.ToString(); var stream = mediaFile.GetTrackIStream(); trackAtOnce.AddAudioTrack(stream); } trackAtOnce.Update -= trackAtOnce_Update; trackAtOnce.ReleaseMedia(); if (ejectMedia) discRecorder2.EjectMedia(); return result; }
/// <summary> /// Recorder Ctor /// </summary> /// <param name="uniqueId">标识Id</param> public Recorder(string uniqueId) { this.uniqueId = uniqueId; msRecorder = new MsftDiscRecorder2(); msRecorder.InitializeDiscRecorder(uniqueId); InitRecorder(); this.BurnMediaList = new List <BurnMedia>(); this.BurnMediaFileSize = 0; }
/// <summary> /// Worker thread that Formats the Disc /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void backgroundFormatWorker_DoWork(object sender, DoWorkEventArgs e) { // // Create and initialize the IDiscRecorder2 // MsftDiscRecorder2 discRecorder = new MsftDiscRecorder2(); string activeDiscRecorder = (string)e.Argument; discRecorder.InitializeDiscRecorder(activeDiscRecorder); discRecorder.AcquireExclusiveAccess(true, m_clientName); // // Create the IDiscFormat2Erase and set properties // MsftDiscFormat2Erase discFormatErase = new MsftDiscFormat2Erase(); discFormatErase.Recorder = discRecorder; discFormatErase.ClientName = m_clientName; discFormatErase.FullErase = !checkBoxQuickFormat.Checked; // // Setup the Update progress event handler // discFormatErase.Update += new DiscFormat2Erase_EventHandler(discFormatErase_Update); // // Erase the media here // try { discFormatErase.EraseMedia(); e.Result = 0; } catch (COMException ex) { e.Result = ex.ErrorCode; MessageBox.Show(ex.Message, "IDiscFormat2.EraseMedia failed", MessageBoxButtons.OK, MessageBoxIcon.Stop); } // // Remove the Update progress event handler // discFormatErase.Update -= new DiscFormat2Erase_EventHandler(discFormatErase_Update); if (checkBoxEjectFormat.Checked) { discRecorder.EjectMedia(); } discRecorder.ReleaseExclusiveAccess(); }
public void BurnCD() { #region CD WRITING MsftDiscMaster2 discMaster = null; discMaster = new MsftDiscMaster2(); String path = "D://hello2.txt"; Console.WriteLine("Writing to the disc"); if (!discMaster.IsSupportedEnvironment) { return; } foreach (string uniqueRecorderId in discMaster) { var discRecorder2 = new MsftDiscRecorder2(); discRecorder2.InitializeDiscRecorder(uniqueRecorderId); MsftDiscFormat2Data datawriter = new MsftDiscFormat2Data(); datawriter.Recorder = discRecorder2; datawriter.ClientName = "IMAPIv2 TEST"; MsftFileSystemImage FSI = new MsftFileSystemImage(); try { if (!datawriter.MediaHeuristicallyBlank) { FSI.MultisessionInterfaces = datawriter.MultisessionInterfaces; FSI.ImportFileSystem(); } } catch (Exception) { FSI.ChooseImageDefaults(discRecorder2); Console.WriteLine("Multisession is not supported on this disk!"); } try { FSI.Root.AddTree(path, false); IFileSystemImageResult Result = FSI.CreateResultImage(); var stream = Result.ImageStream; Console.WriteLine("\nWriting to disc now!!"); datawriter.Write(stream); Console.WriteLine("\nWrite Process completed!"); } catch (Exception) { Console.WriteLine("Unable to form image from given path!"); Console.WriteLine("\nAborted process!"); } discRecorder2.EjectMedia(); } #endregion OperationContext.Current.GetCallbackChannel <MyCallBackHandler>().CDBurnt(); }
private int DoFormat(string activeDiscRecorder) { MsftDiscRecorder2 discRecorder = null; MsftDiscFormat2Erase discFormatErase = null; int result = 0; try { discRecorder = new MsftDiscRecorder2(); discRecorder.InitializeDiscRecorder(activeDiscRecorder); discFormatErase = new MsftDiscFormat2Erase { Recorder = discRecorder, ClientName = "clientName", FullErase = !quickFormat }; discFormatErase.Update += discFormatErase_Update; try { discFormatErase.EraseMedia(); } catch (COMException ex) { result = ex.ErrorCode; MessageBox.Show(ex.Message, "IDiscFormat2.EraseMedia failed", MessageBoxButton.OK, MessageBoxImage.Stop); } discFormatErase.Update -= discFormatErase_Update; if (ejectDisc) discRecorder.EjectMedia(); } catch (COMException exception) { MessageBox.Show(exception.Message); } finally { if (discRecorder != null) Marshal.ReleaseComObject(discRecorder); if (discFormatErase != null) Marshal.ReleaseComObject(discFormatErase); } return result; }
/// <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++; } } }
public void UpdateDriveList() { IDiscMaster2 discMaster = new MsftDiscMaster2(); // IEnumerator ie = discMaster.GetEnumerator(); int count = discMaster.Count; int cursorPosition = -1; int i; if (driveCount == discMaster.Count) { return; } if (!driveListBox.Items.IsEmpty) { driveListBox.Items.Clear(); } if (discMaster.Count == 0) { selectedSpeed = 0; driveListBox.Items.Add(""); //driveListBox.SelectedIndex = 0; driveListBox.IsEnabled = false; return; } driveId = new String[discMaster.Count]; for (i = 0; i < count; ++i) { IDiscRecorder2 recorder = new MsftDiscRecorder2(); String s = discMaster[i]; if (s == selectedDrive) { cursorPosition = i; } driveId[i] = s; recorder.InitializeDiscRecorder(s); s = recorder.ProductId; this.driveListBox.Items.Add(s); } if (cursorPosition == -1) { selectedSpeed = 0; cursorPosition = 0; } driveListBox.SelectedIndex = cursorPosition; selectedDrive = discMaster[cursorPosition]; driveListBox.IsEnabled = true; }
public IList<MsftDiscRecorder2> GetDiscRecorders() { var result = new List<MsftDiscRecorder2>(); var discMaster = new MsftDiscMaster2(); if (!discMaster.IsSupportedEnvironment) return result; foreach (string uniqueRecorderID in discMaster) { var discRecorder2 = new MsftDiscRecorder2(); discRecorder2.InitializeDiscRecorder(uniqueRecorderID); result.Add(discRecorder2); } return result; }
public bool DetectCDRoms(ref vComboBox lst) { bool flag = false; MsftDiscMaster2 gClass0 = null; try { try { gClass0 = (MsftDiscMaster2)(new GClass0()); if (gClass0.IsSupportedEnvironment) { foreach (string str in gClass0) { MsftDiscRecorder2 msftDiscRecorder2Class = (MsftDiscRecorder2)(new MsftDiscRecorder2Class()); msftDiscRecorder2Class.InitializeDiscRecorder(str); string str1 = msftDiscRecorder2Class.VolumePathNames[0].ToString(); string productId = msftDiscRecorder2Class.ProductId; ListItem listItem = new ListItem() { Text = string.Format("{0} [{1}]", str1, productId), Tag = msftDiscRecorder2Class, ImageIndex = 0 }; lst.Items.Add(listItem); flag = true; } if (lst.Items.Count > 0) { lst.SelectedIndex = 0; } } } catch (COMException cOMException) { throw; } } finally { if (gClass0 != null) { Marshal.ReleaseComObject(gClass0); } } return(flag); }
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); }
static void Main(string[] args) { // Index to recording drive. int index = 2; // Create a DiscMaster2 object to connect to CD/DVD drives. IDiscMaster2 discMaster = new MsftDiscMaster2(); // Initialize the DiscRecorder object for the specified burning device. IDiscRecorder2 recorder = new MsftDiscRecorder2(); recorder.InitializeDiscRecorder(discMaster[index]); IMAPIv2.Samples samples = new IMAPIv2.Samples(); samples.BurnDirectory(recorder, @"D:\Utils"); }
/// <summary> /// Initialize the form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainForm_Load(object sender, EventArgs e) { // // Determine the current recording devices // MsftDiscMaster2 discMaster = null; try { discMaster = new MsftDiscMaster2(); if (!discMaster.IsSupportedEnvironment) { return; } foreach (string uniqueRecorderId in discMaster) { var discRecorder2 = new MsftDiscRecorder2(); discRecorder2.InitializeDiscRecorder(uniqueRecorderId); devicesComboBox.Items.Add(discRecorder2); } if (devicesComboBox.Items.Count > 0) { devicesComboBox.SelectedIndex = 0; } } catch (COMException ex) { MessageBox.Show(ex.Message, string.Format("Error:{0} - Please install IMAPI2", ex.ErrorCode), MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } finally { if (discMaster != null) { Marshal.ReleaseComObject(discMaster); } } labelStatusText.Text = string.Empty; UpdateCapacity(); }
public bool RecorderIsSupported(MsftDiscRecorder2 discRecorder) { IDiscFormat2Data discFormatData = null; bool answer = false; try { discFormatData = new MsftDiscFormat2Data(); answer = discFormatData.IsRecorderSupported(discRecorder); } finally { if (discFormatData != null) { Marshal.ReleaseComObject(discFormatData); } } return(answer); }
public void cekIMAPI() { MsftDiscMaster2 Master = null; try { Master = new MsftDiscMaster2(); if (!Master.IsSupportedEnvironment) { return; } foreach (string uniqueRecorderID in Master) { MsftDiscRecorder2 Recorder = new MsftDiscRecorder2(); Recorder.InitializeDiscRecorder(uniqueRecorderID); comboBoxDrive.Items.Add(Recorder); } if (comboBoxDrive.Items.Count > 0) { comboBoxDrive.SelectedIndex = 0; } } catch { suaraGalat(true); MessageBox.Show(this, "Sepertinya IMAPI2 tidak ditemukan dalam Sistem Operasi ini.", pesan, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); kembaliKeFormUtama(); } finally { if (Master != null) { Marshal.ReleaseComObject(Master); } } }
public List <IDiscRecorder2> findAllDisk() { List <IDiscRecorder2> RecordDisk_List = new List <IDiscRecorder2>(); // // Determine the current recording devices // MsftDiscMaster2 discMaster = null; try { discMaster = new MsftDiscMaster2(); if (!discMaster.IsSupportedEnvironment) { return(null); } foreach (string uniqueRecorderId in discMaster) { var discRecorder2 = new MsftDiscRecorder2(); discRecorder2.InitializeDiscRecorder(uniqueRecorderId); //MessageBox.Show(discRecorder2.ProductId); RecordDisk_List.Add(discRecorder2); //devicesComboBox.Items.Add(); } } catch { MessageBox.Show(string.Format("Error:{0} - Please install IMAPI2")); return(null); } finally { if (discMaster != null) { Marshal.ReleaseComObject(discMaster); } } return(RecordDisk_List); }
/// <summary> /// Initialize the form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainForm_Load(object sender, EventArgs e) { // // Determine the current recording devices // MsftDiscMaster2 discMaster = null; try { discMaster = new MsftDiscMaster2(); if (!discMaster.IsSupportedEnvironment) return; foreach (string uniqueRecorderId in discMaster) { var discRecorder2 = new MsftDiscRecorder2(); discRecorder2.InitializeDiscRecorder(uniqueRecorderId); devicesComboBox.Items.Add(discRecorder2); } if (devicesComboBox.Items.Count > 0) { devicesComboBox.SelectedIndex = 0; } } catch (COMException ex) { MessageBox.Show(ex.Message, string.Format("Error:{0} - Please install IMAPI2", ex.ErrorCode), MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } finally { if (discMaster != null) { Marshal.ReleaseComObject(discMaster); } } labelStatusText.Text = string.Empty; UpdateCapacity(); }
public void FormatMedia(bool quick, bool eject) { if (!_mediaLoaded) { throw new InvalidOperationException("LoadMedia must be called first."); } MsftDiscRecorder2 recorder = null; MsftDiscFormat2Erase discFormatErase = null; try { recorder = new MsftDiscRecorder2(); recorder.InitializeDiscRecorder(_recorders.SelectedItem.InternalUniqueId); discFormatErase = new MsftDiscFormat2Erase { Recorder = recorder, ClientName = ImageMaster.ClientName, FullErase = !quick }; discFormatErase.Update += _discFormatErase_Update; discFormatErase.EraseMedia(); if (eject) { recorder.EjectMedia(); } } finally { if (discFormatErase != null) { Marshal.ReleaseComObject(discFormatErase); } if (recorder != null) { Marshal.ReleaseComObject(recorder); } } }
public BurnerSrvImpl() { try { discMaster = new MsftDiscMaster2(); if (!discMaster.IsSupportedEnvironment) { return; } //Creo la lista con i masterizzatori foreach (string uniqueRecorderId in discMaster) { var discRecorder2 = new MsftDiscRecorder2(); discRecorder2.InitializeDiscRecorder(uniqueRecorderId); System.Diagnostics.Trace.WriteLine("[Volume]: " + discRecorder2.VolumePathNames.GetValue(0)); _listRecorders.Add(discRecorder2); } // Setto alcuni valori di Default ejectMedia = true; closeMedia = false; quickFormat = true; discRecorder = _listRecorders.First(); } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message, string.Format("Error:{0} - Please install IMAPI2", ex.ErrorCode)); return; } finally { if (discMaster != null) { Marshal.ReleaseComObject(discMaster); } } }
public void LoadRecorder() { if (_recorders.SelectedIndex == -1) { throw new InvalidOperationException("No DiscRecorder selected from the DiscRecorders list."); } MsftDiscRecorder2 recorder = null; IDiscFormat2Data discFormatData = null; try { recorder = new MsftDiscRecorder2(); recorder.InitializeDiscRecorder(_recorders.SelectedItem.InternalUniqueId); discFormatData = new MsftDiscFormat2Data(); switch (discFormatData.IsRecorderSupported(recorder)) { case 0x80004003: throw new RecorderNotSupportedException("Pointer is not valid."); case 0xC0AA0202: throw new RecorderNotSupportedException("The selected recorder is not supported on this system."); } _recorderLoaded = true; _mediaLoaded = false; } finally { if (discFormatData != null) { Marshal.ReleaseComObject(discFormatData); } if (recorder != null) { Marshal.ReleaseComObject(recorder); } } }
internal DiscRecorder(string uniqueId) { _internalUniqueId = uniqueId; MsftDiscRecorder2 recorder = null; try { List<MediaProfile> profiles; recorder = new MsftDiscRecorder2(); recorder.InitializeDiscRecorder(uniqueId); profiles = new List<MediaProfile>(); foreach (IMAPI_PROFILE_TYPE item in recorder.SupportedProfiles) { profiles.Add((MediaProfile)item); } _profiles = profiles.AsReadOnly(); } finally { if (recorder != null) Marshal.ReleaseComObject(recorder); } }
private void MainForm_Load(object sender, EventArgs e) { _dictionares = new Dictionares(); MsftDiscMaster2 discMaster = null; try { discMaster = new MsftDiscMaster2(); if (!discMaster.IsSupportedEnvironment) { return; } foreach (string uniqueRecorderId in discMaster) { var tempDiscRecorder = new MsftDiscRecorder2(); tempDiscRecorder.InitializeDiscRecorder(uniqueRecorderId); devicesComboBox.Items.Add(tempDiscRecorder); } if (devicesComboBox.Items.Count > 0) { devicesComboBox.SelectedIndex = 0; } } catch (COMException ex) { MessageBox.Show(ex.Message, string.Format("Error:{0} - Please install IMAPI2", ex.ErrorCode), MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } finally { if (discMaster != null) { Marshal.ReleaseComObject(discMaster); } } InitVolumeLabel(); }
static BurnHelper() { var discMaster = new MsftDiscMaster2(); try { _recorders = new List <IDiscRecorder2>(); for (var i = 0; i < discMaster.Count; ++i) { IDiscFormat2Data mi = new MsftDiscFormat2Data(); try { IDiscRecorder2 rec = new MsftDiscRecorder2(); rec.InitializeDiscRecorder(discMaster[i]); //remove the comment for next 2 lines mi.Recorder = rec; if (mi.IsRecorderSupported(rec)) { _recorders.Add(rec); } } catch (Exception) { //throw; } finally { Marshal.FinalReleaseComObject(mi); } } } finally { Marshal.FinalReleaseComObject(discMaster); } }
/// <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; }
/// <summary> /// Initialize the form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainForm_Load(object sender, EventArgs e) { cls_main main_func = new cls_main(); if (main_func.check_for_components(false)) { if (!File.Exists(appdir + "umk_manager_08.exe")) { pict_mngr.Visible = false; }; if (Directory.Exists(appdir + "system\\service") == false) { chk_service_enabled.Enabled = false; } else { chk_service_enabled.Enabled = true; } main_func.create_registry(); prj_exist = true; umk_folder = main_func.get_value_from_infofile(appdir + "configs\\settings.ini", "umk_folder"); if (umk_folder == "") { MessageBox.Show("УМК не найдены. Запустите УМК Менеджер, чтобы указать правильный путь к директории с УМК.", "УМК не найдены!", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } else { if (Microsoft.VisualBasic.Strings.Right(umk_folder, 1)== "\\") { umk_folder = Microsoft.VisualBasic.Strings.Left(umk_folder, umk_folder.Length-1); }; if (Microsoft.VisualBasic.Strings.Left(umk_folder, 6) == "APPDIR") { umk_folder = main_func.ReplaceAll(umk_folder, "APPDIR\\", appdir); } } clear_form(); show_dg_open(); if (Environment.OSVersion.Version.Major > 5) { MsftDiscMaster2 discMaster = null; try { discMaster = new MsftDiscMaster2(); if (!discMaster.IsSupportedEnvironment) return; foreach (string uniqueRecorderID in discMaster) { MsftDiscRecorder2 discRecorder2 = new MsftDiscRecorder2(); discRecorder2.InitializeDiscRecorder(uniqueRecorderID); devicesComboBox.Items.Add(discRecorder2); } if (devicesComboBox.Items.Count > 0) { devicesComboBox.SelectedIndex = 0; } } catch (COMException ex) { MessageBox.Show(ex.Message, string.Format("Error:{0} - Пожалуйста, установите IMAPI2", ex.ErrorCode), MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } finally { if (discMaster != null) { Marshal.ReleaseComObject(discMaster); } } // // Create the volume label based on the current date // DateTime now = DateTime.Now; textBoxLabel.Text = now.Year + "_" + now.Month + "_" + now.Day; labelStatusText.Text = string.Empty; labelFormatStatusText.Text = string.Empty; // // Select no verification, by default // comboBoxVerification.SelectedIndex = 0; UpdateCapacity(); } else { devicesComboBox.Visible = false; label43.Visible = false; MessageBox.Show("В данной версии ОС некоторые функции программы будут недоступны!", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { Application.Exit(); } }
/// <summary> /// The thread that does the burning of the media /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void backgroundBurnWorker_DoWork(object sender, DoWorkEventArgs e) { MsftDiscRecorder2 discRecorder = null; MsftDiscFormat2Data discFormatData = null; try { // // Create and initialize the IDiscRecorder2 object // discRecorder = new MsftDiscRecorder2(); var burnData = (BurnData)e.Argument; discRecorder.InitializeDiscRecorder(burnData.uniqueRecorderId); // // Create and initialize the IDiscFormat2Data // discFormatData = new MsftDiscFormat2Data { Recorder = discRecorder, ClientName = ClientName }; // // Set the verification level // var burnVerification = (IBurnVerification)discFormatData; burnVerification.BurnVerificationLevel = _verificationLevel; // // Check if media is blank, (for RW media) // object[] multisessionInterfaces = null; if (!discFormatData.MediaHeuristicallyBlank) { multisessionInterfaces = discFormatData.MultisessionInterfaces; } // // Create the file system // IStream fileSystem; if (!CreateMediaFileSystem(discRecorder, multisessionInterfaces, out fileSystem)) { e.Result = -1; return; } // // add the Update event handler // discFormatData.Update += discFormatData_Update; // // Write the data here // try { discFormatData.Write(fileSystem); e.Result = 0; } catch (COMException ex) { e.Result = ex.ErrorCode; MessageBox.Show(ex.Message, "IDiscFormat2Data.Write failed", MessageBoxButtons.OK, MessageBoxIcon.Stop); } finally { if (fileSystem != null) { Marshal.FinalReleaseComObject(fileSystem); } } // // remove the Update event handler // discFormatData.Update -= discFormatData_Update; if (_ejectMedia) { discRecorder.EjectMedia(); } } catch (COMException exception) { // // If anything happens during the format, show the message // MessageBox.Show(exception.Message); e.Result = exception.ErrorCode; } finally { if (discRecorder != null) { Marshal.ReleaseComObject(discRecorder); } if (discFormatData != null) { Marshal.ReleaseComObject(discFormatData); } } }
public void LoadRecorder() { if (_recorders.SelectedIndex == -1) throw new InvalidOperationException("No DiscRecorder selected from the DiscRecorders list."); MsftDiscRecorder2 recorder = null; IDiscFormat2Data discFormatData = null; try { recorder = new MsftDiscRecorder2(); recorder.InitializeDiscRecorder(_recorders.SelectedItem.InternalUniqueId); discFormatData = new MsftDiscFormat2Data(); switch (discFormatData.IsRecorderSupported(recorder)) { case 0x80004003: throw new RecorderNotSupportedException("Pointer is not valid."); case 0xC0AA0202: throw new RecorderNotSupportedException("The selected recorder is not supported on this system."); } _recorderLoaded = true; _mediaLoaded = false; } finally { if (discFormatData != null) Marshal.ReleaseComObject(discFormatData); if (recorder != null) Marshal.ReleaseComObject(recorder); } }
public void WriteImage(BurnVerificationLevel verification, bool finalize, bool eject) { if (!_recorderLoaded) throw new InvalidOperationException("LoadMedia must be called first."); MsftDiscRecorder2 recorder = null; MsftDiscFormat2Data discFormatData = null; try { recorder = new MsftDiscRecorder2(); recorder.InitializeDiscRecorder(_recorders.SelectedItem.InternalUniqueId); discFormatData = new MsftDiscFormat2Data { Recorder = recorder, ClientName = ClientName, ForceMediaToBeClosed = finalize }; // // Set the verification level // var burnVerification = (IBurnVerification)discFormatData; burnVerification.BurnVerificationLevel = IMAPI_BURN_VERIFICATION_LEVEL.IMAPI_BURN_VERIFICATION_NONE; // // Check if media is blank, (for RW media) // object[] multisessionInterfaces = null; if (!discFormatData.MediaHeuristicallyBlank) multisessionInterfaces = discFormatData.MultisessionInterfaces; // // Create the file system // IStream fileSystem; _CreateImage(recorder, multisessionInterfaces, out fileSystem); discFormatData.Update += _discFormatWrite_Update; // // Write the data // try { discFormatData.Write(fileSystem); } finally { if (fileSystem != null) Marshal.FinalReleaseComObject(fileSystem); } discFormatData.Update -= _discFormatWrite_Update; if (eject) recorder.EjectMedia(); } finally { _isWriting = false; if (discFormatData != null) Marshal.ReleaseComObject(discFormatData); if (recorder != null) Marshal.ReleaseComObject(recorder); } }
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); } }
private int DoBurn(string activeDiscRecorder, IMAPI_BURN_VERIFICATION_LEVEL verificationLevel) { MsftDiscRecorder2 discRecorder = null; MsftDiscFormat2Data discFormatData = null; int result = 0; try { discRecorder = new MsftDiscRecorder2(); discRecorder.InitializeDiscRecorder(burnData.uniqueRecorderId); discFormatData = new MsftDiscFormat2Data { Recorder = discRecorder, ClientName = "ClientName", ForceMediaToBeClosed = closeMedia }; var burnVerification = (IBurnVerification)discFormatData; burnVerification.BurnVerificationLevel = verificationLevel; object[] multisessionInterfaces = null; if (!discFormatData.MediaHeuristicallyBlank) multisessionInterfaces = discFormatData.MultisessionInterfaces; IStream fileSystem; if (!CreateMediaFileSystem(discRecorder, multisessionInterfaces, out fileSystem)) return -1; discFormatData.Update += discFormatData_Update; try { discFormatData.Write(fileSystem); result = 0; } catch (COMException ex) { result = ex.ErrorCode; MessageBox.Show(ex.Message, "IDiscFormat2Data.Write failed", MessageBoxButton.OK, MessageBoxImage.Stop); } finally { if (fileSystem != null) Marshal.FinalReleaseComObject(fileSystem); } discFormatData.Update -= discFormatData_Update; if (ejectMedia) discRecorder.EjectMedia(); } catch (COMException exception) { MessageBox.Show(exception.Message); result = exception.ErrorCode; } finally { if (discRecorder != null) Marshal.ReleaseComObject(discRecorder); if (discFormatData != null) Marshal.ReleaseComObject(discFormatData); } return result; }
public void UpdateMediaStatus() { int i; IDiscRecorder2 recorder = new MsftDiscRecorder2(); isSupportedMediaReady = false; isRewritableMedia = false; textSupportedMedia.Text = ""; if (!driveListBox.IsEnabled) { insertedMedia.Text = ""; NextPage.IsEnabled = false; return; } recorder.InitializeDiscRecorder(selectedDrive); IDiscFormat2Data dataWriterImage = new MsftDiscFormat2Data(); try { dataWriterImage.Recorder = recorder; } catch (System.Runtime.InteropServices.COMException e) { if ((uint)e.ErrorCode == 0xC0AA0407) //E_IMAPI_DF2DATA_RECORDER_NOT_SUPPORTED { insertedMedia.Text = ""; NextPage.IsEnabled = false; return; } } int nf, nsec; try{ nf = dataWriterImage.FreeSectorsOnMedia; nsec = dataWriterImage.TotalSectorsOnMedia; } catch (System.Runtime.InteropServices.COMException) { } IDiscRecorder2Ex rc2 = recorder as IDiscRecorder2Ex; byte[] resp = new byte[1024]; uint sb = 1024; IntPtr respPtr; rc2.GetFeaturePage(IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_PROFILE_LIST, true, out respPtr, ref sb); if (sb > 1024) { sb = 1024; } Marshal.Copy(respPtr, resp, 0, (int)sb); for (i = 4; i < (int)sb; i += 4) { if (resp[i + 2] != 0) { textSupportedMedia.Text += "*"; isSupportedMediaReady = true; } switch (resp[i + 1]) { case 9: textSupportedMedia.Text += "CD-R "; break; case 10: textSupportedMedia.Text += "CD-RW "; break; case 17: textSupportedMedia.Text += "DVD-R "; break; case 18: textSupportedMedia.Text += "DVD-RAM "; break; case 19: textSupportedMedia.Text += "DVD-RW "; break; case 21: textSupportedMedia.Text += "DVD-R_DL "; break; case 26: textSupportedMedia.Text += "DVD+RW "; break; case 27: textSupportedMedia.Text += "DVD+R "; break; case 43: textSupportedMedia.Text += "DVD+R_DL "; break; case 65: textSupportedMedia.Text += "BD-R "; break; case 67: textSupportedMedia.Text += "BD-RE "; break; } } IMAPI_MEDIA_PHYSICAL_TYPE n; try { n = dataWriterImage.CurrentPhysicalMediaType; switch (n) { case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDROM: insertedMedia.Text = "CD-ROM or Audio CD"; isCD = true; isBD = false; break; case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDR: insertedMedia.Text = Properties.Resources.MediaType_BlankCDR;//"Blank CD-R"; isSupportedMediaReady = true; isCD = true; isBD = false; break; case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDRW: insertedMedia.Text = "CD-RW"; isSupportedMediaReady = true; isRewritableMedia = true; isCD = true; isBD = false; break; case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHRW: insertedMedia.Text = Properties.Resources.MediaType_DVDRW; isSupportedMediaReady = true; isRewritableMedia = true; isCD = false; isBD = false; break; case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR: insertedMedia.Text = Properties.Resources.MediaType_BlankDVDR;//"Blank DVD-R"; isSupportedMediaReady = true; isCD = false; isBD = false; break; case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDROM: insertedMedia.Text = Properties.Resources.MediaType_DVDROM; isCD = false; isBD = false; break; case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR: insertedMedia.Text = Properties.Resources.MediaType_BlankDVDPlusR;//"Blank DVD+R"; isSupportedMediaReady = true; isCD = false; isBD = false; break; case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSRW: insertedMedia.Text = Properties.Resources.MediaType_DVDPlusRW; isSupportedMediaReady = true; isRewritableMedia = true; isCD = false; isBD = false; break; case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDRAM: //IMAPI_PROFILE_TYPE_DVD_RAM: insertedMedia.Text = Properties.Resources.MediaType_DVDRAM; isSupportedMediaReady = true; isCD = false; isBD = false; isRewritableMedia = true; break; case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDR: insertedMedia.Text = Properties.Resources.MediaType_BlankBDR; isSupportedMediaReady = true; isCD = false; isBD = true; break; case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDRE: insertedMedia.Text = "BD-RE"; isSupportedMediaReady = true; isRewritableMedia = true; isCD = false; isBD = true; break; case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR_DUALLAYER: insertedMedia.Text = Properties.Resources.MediaType_BlankDVDR_DL; isSupportedMediaReady = true; isCD = false; isBD = false; break; case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR_DUALLAYER: insertedMedia.Text = Properties.Resources.MediaType_BlankDVDPlusR_DL; isSupportedMediaReady = true; isCD = false; isBD = false; break; default: insertedMedia.Text = Properties.Resources.MediaType_UnknownMedia; break; } } catch (System.Runtime.InteropServices.COMException e) { if ((uint)e.ErrorCode == 0xC0AA0202) //E_IMAPI_RECORDER_MEDIA_NO_MEDIA { insertedMedia.Text = Properties.Resources.MediaTypeError_NoMediaInserted; //"No media inserted."; } else if ((uint)e.ErrorCode == 0xC0AA02FF) //E_IMAPI_RECORDER_INVALID_RESPONSE_FROM_DEVICE { insertedMedia.Text = Properties.Resources.MediaTypeError_InvalidResponseFromDevice; } else { insertedMedia.Text = "No media detected due to internal error."; } } if (isSupportedMediaReady) { NextPage.IsEnabled = true; } else { NextPage.IsEnabled = false; } if (isBD) { //aaa = dataWriterImage.TotalSectorsOnMedia; //aaa = dataWriterImage.FreeSectorsOnMedia; } }
static void Main(string[] args) { // Index to recording drive. int index = 0; // Create a DiscMaster2 object to connect to CD/DVD drives. IDiscMaster2 discMaster = new MsftDiscMaster2(); // Initialize the DiscRecorder object for the specified burning device. IDiscRecorder2 recorder = new MsftDiscRecorder2(); recorder.InitializeDiscRecorder(discMaster[index]); IMAPIv2.Samples samples = new IMAPIv2.Samples(); samples.BurnDirectory(recorder, @"D:\Utils"); }
public void UpdateWritingSpeedList() { if (selectedSpeed != 0) { return; } if (!writingSpeedListBox.Items.IsEmpty) { this.writingSpeedListBox.Items.Clear(); } if (!isSupportedMediaReady) { writingSpeedListBox.Items.Add(""); writingSpeedListBox.SelectedIndex = 0; writingSpeedListBox.IsEnabled = false; return; } IDiscRecorder2 recorder = new MsftDiscRecorder2(); recorder.InitializeDiscRecorder(selectedDrive); IDiscFormat2Data dataWriterImage = new MsftDiscFormat2Data(); object[] speeds = null; try { dataWriterImage.Recorder = recorder; speeds = dataWriterImage.SupportedWriteSpeeds; } catch (System.Runtime.InteropServices.COMException e) { if ((uint)e.ErrorCode == 0xC0AA0407) //E_IMAPI_DF2DATA_RECORDER_NOT_SUPPORTED { } } if (speeds != null) { writingSpeedListBox.IsEnabled = true; writingSpeed = new int[speeds.Length]; for (int i = 0; i < speeds.Length; ++i) { int n = writingSpeed[i] = (int)speeds[i]; if (isCD) { n = ((n + 1) * 10) / 75; // n = (n * 2) / 150 * 10; // CD 1x: 150 KB per sec // Example GH15L 300(4x) 599(8x) 1199(16x) 1800(24x) 2400(32x) 3000(40x) 3599(48x) 3600(max) // DVR-212L 300(4x) 750(10x) 1200(16x) 1800(24x) 2400(32x) 3000(40x) } else if (isBD) { n = ((n + 1) * 10) / 2195; // n = (n * 2) / 4390 * 10; // BD 1x: 4390 KB per sec // Example BRP-U6X(Optiarc BD-5740L) 4390(2x) 8780(4x) 13170(6x) } else { n = ((n + 1) * 8) / 541; // n = (n * 2) / 1352.5 * 10; } // DVD 1x: 1352.5 KB per sec // Example GH15L 2705(4x) 5410(8x) 10820(16x) // DVR-212L 2705(4x) 4057(6x) 5410(8x) 8115(12x) 10820(16x) if (i == 0 && speeds.Length > 1) { if ((int)speeds[1] + 1 >= (int)speeds[0]) { // avoid duplication and show as "Max" writingSpeedListBox.Items.Add(Properties.Resources.Page2_SpeedMax); continue; } } double f = (double)n / 10.0; writingSpeedListBox.Items.Add(f.ToString("0.#") + Properties.Resources.Page2_SpeedSuffix); } writingSpeedListBox.SelectedIndex = 0; selectedSpeed = (int)speeds[0]; } else { writingSpeedListBox.IsEnabled = false; selectedSpeed = 0; } }
/// <summary> /// Worker thread that Formats the Disc /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void backgroundFormatWorker_DoWork(object sender, DoWorkEventArgs e) { MsftDiscRecorder2 discRecorder = null; MsftDiscFormat2Erase discFormatErase = null; try { // // Create and initialize the IDiscRecorder2 // discRecorder = new MsftDiscRecorder2(); string activeDiscRecorder = (string)e.Argument; discRecorder.InitializeDiscRecorder(activeDiscRecorder); discRecorder.AcquireExclusiveAccess(true, m_clientName); // // Create the IDiscFormat2Erase and set properties // discFormatErase = new MsftDiscFormat2Erase(); discFormatErase.Recorder = discRecorder; discFormatErase.ClientName = m_clientName; discFormatErase.FullErase = !checkBoxQuickFormat.Checked; // // Setup the Update progress event handler // discFormatErase.Update += new DiscFormat2Erase_EventHandler(discFormatErase_Update); // // Erase the media here // try { discFormatErase.EraseMedia(); e.Result = 0; } catch (COMException ex) { e.Result = ex.ErrorCode; MessageBox.Show(ex.Message, "Ошибка при форматировании!", MessageBoxButtons.OK, MessageBoxIcon.Stop); } // // Remove the Update progress event handler // discFormatErase.Update -= new DiscFormat2Erase_EventHandler(discFormatErase_Update); // // Eject the media // if (checkBoxEjectFormat.Checked) { discRecorder.EjectMedia(); } discRecorder.ReleaseExclusiveAccess(); } catch (COMException exception) { // // If anything happens during the format, show the message // // MessageBox.Show(exception.Message); } finally { if (discRecorder != null) { Marshal.ReleaseComObject(discRecorder); } if (discFormatErase != null) { Marshal.ReleaseComObject(discFormatErase); } } }
/// <summary> /// Get the current disc type from drive letter /// </summary> /// <param name="driveLetter"></param> /// <returns></returns> /// <remarks> /// https://stackoverflow.com/questions/11420365/detecting-if-disc-is-in-dvd-drive /// </remarks> public static MediaType?GetDiscType(char?driveLetter) { // Get the DeviceID from the current drive letter string deviceId = null; try { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_CDROMDrive WHERE Id = '" + driveLetter + ":\'"); var collection = searcher.Get(); foreach (ManagementObject queryObj in collection) { deviceId = (string)queryObj["DeviceID"]; } } catch { // We don't care what the error was return(null); } // If we got no valid device, we don't care and just return if (deviceId == null) { return(null); } // Get all relevant disc information try { MsftDiscMaster2 discMaster = new MsftDiscMaster2(); deviceId = deviceId.ToLower().Replace('\\', '#'); string id = null; foreach (var disc in discMaster) { if (disc.ToString().Contains(deviceId)) { id = disc.ToString(); } } // If we couldn't find the drive, we don't care and return if (id == null) { return(null); } // Otherwise, we get the media type, if any MsftDiscRecorder2 recorder = new MsftDiscRecorder2(); recorder.InitializeDiscRecorder(id); MsftDiscFormat2Data dataWriter = new MsftDiscFormat2Data(); dataWriter.Recorder = recorder; var media = dataWriter.CurrentPhysicalMediaType; if (media != IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_UNKNOWN) { return(Converters.ToMediaType(media)); } } catch { // We don't care what the error is } return(null); }
/// <summary> /// The thread that does the burning of the media /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void backgroundBurnWorker_DoWork(object sender, DoWorkEventArgs e) { MsftDiscRecorder2 discRecorder = null; MsftDiscFormat2Data discFormatData = null; try { // // Create and initialize the IDiscRecorder2 object // discRecorder = new MsftDiscRecorder2(); BurnData burnData = (BurnData)e.Argument; discRecorder.InitializeDiscRecorder(burnData.uniqueRecorderId); discRecorder.AcquireExclusiveAccess(true, m_clientName); // // Create and initialize the IDiscFormat2Data // discFormatData = new MsftDiscFormat2Data(); discFormatData.Recorder = discRecorder; discFormatData.ClientName = m_clientName; discFormatData.ForceMediaToBeClosed = checkBoxCloseMedia.Checked; // // Set the verification level // IBurnVerification burnVerification = (IBurnVerification)discFormatData; burnVerification.BurnVerificationLevel = (IMAPI_BURN_VERIFICATION_LEVEL)m_verificationLevel; // // Check if media is blank, (for RW media) // object[] multisessionInterfaces = null; if (!discFormatData.MediaHeuristicallyBlank) { multisessionInterfaces = discFormatData.MultisessionInterfaces; } // // Create the file system // IStream fileSystem = null; if (!CreateMediaFileSystem(discRecorder, multisessionInterfaces, out fileSystem)) { e.Result = -1; return; } // // add the Update event handler // discFormatData.Update += new DiscFormat2Data_EventHandler(discFormatData_Update); // // Write the data here // try { discFormatData.Write(fileSystem); e.Result = 0; } catch (COMException ex) { e.Result = ex.ErrorCode; MessageBox.Show(ex.Message, "Ошибка в процессе записи диска!", MessageBoxButtons.OK, MessageBoxIcon.Stop); } finally { if (fileSystem != null) { Marshal.FinalReleaseComObject(fileSystem); } } // // remove the Update event handler // discFormatData.Update -= new DiscFormat2Data_EventHandler(discFormatData_Update); if (this.checkBoxEject.Checked) { discRecorder.EjectMedia(); } discRecorder.ReleaseExclusiveAccess(); } catch (COMException exception) { // // If anything happens during the format, show the message // //MessageBox.Show(exception.Message); e.Result = exception.ErrorCode; } finally { if (discRecorder != null) { Marshal.ReleaseComObject(discRecorder); } if (discFormatData != null) { Marshal.ReleaseComObject(discFormatData); } } }
private void backgroundBurnWorker2_DoWork(object sender, DoWorkEventArgs e) { MsftDiscRecorder2 discRecorder = null; MsftDiscFormat2Data discFormatData = null; try { // Create and initialize the IDiscRecorder2 object discRecorder = new MsftDiscRecorder2(); var burnData = (BurnData)e.Argument; try { Log.WriteLine("DISK 2 uniqueRecorderId = " + burnData.uniqueRecorderId); discRecorder.InitializeDiscRecorder(burnData.uniqueRecorderId); } catch (Exception ex) { e.Result = -1; Log.WriteLine(ex.ToString()); return; } // Create and initialize the IDiscFormat2Data discFormatData = new MsftDiscFormat2Data { Recorder = discRecorder, ClientName = "VACamera", ForceMediaToBeClosed = _closeMedia }; // Set the verification level var burnVerification = (IBurnVerification)discFormatData; burnVerification.BurnVerificationLevel = _verificationLevel; // Check if media is blank, (for RW media) object[] multisessionInterfaces = null; if (!discFormatData.MediaHeuristicallyBlank) { multisessionInterfaces = discFormatData.MultisessionInterfaces; } // Create the file system IStream fileSystem; if (!createMediaFileSystem(discRecorder, multisessionInterfaces, out fileSystem)) { e.Result = -1; Log.WriteLine("Cannot create filesystem on disk!"); return; } // add the Update event handler discFormatData.Update += discFormatData2_Update; // Write the data here try { discFormatData.Write(fileSystem); e.Result = 0; } catch (Exception ex) { e.Result = -1; Log.WriteLine(ex.ToString()); } finally { if (fileSystem != null) { Marshal.FinalReleaseComObject(fileSystem); } } // remove the Update event handler discFormatData.Update -= discFormatData2_Update; if (_ejectMedia) { discRecorder.EjectMedia(); } } catch (Exception ex) { e.Result = -1; Log.WriteLine(ex.ToString()); } finally { if (discRecorder != null) { Marshal.ReleaseComObject(discRecorder); } if (discFormatData != null) { Marshal.ReleaseComObject(discFormatData); } } }
private void FormDvdWriter_Load(object sender, EventArgs e) { bool isHavingDisk = false; bool isHaveUSB = false; txtFilename.Text = Path.GetFileName(_filePath); long filesize = (new FileInfo(_filePath)).Length; txtFileSize.Text = (filesize < 1000000000 ? string.Format("{0} MB", filesize / 1000000) : string.Format("{0:F2} GB", (float)filesize / 1000000000.0)); // Determine the current recording devices MsftDiscMaster2 discMaster = null; try { discMaster = new MsftDiscMaster2(); if (discMaster.IsSupportedEnvironment) { foreach (string uniqueRecorderId in discMaster) { var discRecorder2 = new MsftDiscRecorder2(); discRecorder2.InitializeDiscRecorder(uniqueRecorderId); listDrive1.Items.Add(discRecorder2); listDrive2.Items.Add(discRecorder2); } if (listDrive1.Items.Count <= 0) { listDrive1.Enabled = false; listDrive1.SelectedIndex = -1; listDrive2.Enabled = false; listDrive2.SelectedIndex = -1; } else if (listDrive1.Items.Count == 1) { listDrive1.SelectedIndex = 0; listDrive2.Enabled = false; listDrive2.SelectedIndex = 0; isHavingDisk = true; } else { listDrive1.SelectedIndex = 0; listDrive2.SelectedIndex = 1; isHavingDisk = true; } } } catch (Exception ex) { MessageBox.Show("Thiết bị không hỗ trợ thư viện IMAPI2"); Log.WriteLine(ex.ToString()); return; } finally { if (discMaster != null) { Marshal.ReleaseComObject(discMaster); } } var driveList = DriveInfo.GetDrives(); foreach (DriveInfo drive in driveList) { if (drive.DriveType == DriveType.Removable) { listDrive3.Items.Add(drive.Name); } if (listDrive3.Items.Count > 0) { listDrive3.SelectedIndex = 0; isHaveUSB = true; btnWrite3.Enabled = true; } else { btnWrite3.Enabled = false; } } if (!(isHaveUSB || isHaveUSB)) { MessageBox.Show("Không tìm thấy ổ đĩa/USB phù hợp"); DialogResult = DialogResult.Cancel; Hide(); Close(); } // Create the volume label based on the current date if needed if (_sessionName.Equals("")) { _sessionName = DateTime.Now.ToString("yyyyMMdd_HHmm"); } }
public void FormatMedia(bool quick, bool eject) { if (!_mediaLoaded) throw new InvalidOperationException("LoadMedia must be called first."); MsftDiscRecorder2 recorder = null; MsftDiscFormat2Erase discFormatErase = null; try { recorder = new MsftDiscRecorder2(); recorder.InitializeDiscRecorder(_recorders.SelectedItem.InternalUniqueId); discFormatErase = new MsftDiscFormat2Erase { Recorder = recorder, ClientName = ImageMaster.ClientName, FullErase = !quick }; discFormatErase.Update += _discFormatErase_Update; discFormatErase.EraseMedia(); if (eject) recorder.EjectMedia(); } finally { if (discFormatErase != null) Marshal.ReleaseComObject(discFormatErase); if (recorder != null) Marshal.ReleaseComObject(recorder); } }
public DevicesManager() { discMaster = new MsftDiscMaster2(); devicesList = new List <MsftDiscRecorder2>(); try { if (!discMaster.IsSupportedEnvironment) { return; } foreach (string uniqueRecorderId in discMaster) { var discRecorder2 = new MsftDiscRecorder2(); discRecorder2.InitializeDiscRecorder(uniqueRecorderId); devicesList.Add(discRecorder2); } } catch (COMException) { return; } finally { if (discMaster != null) { Marshal.ReleaseComObject(discMaster); } } }