private bool CreateMediaFileSystem(IDiscRecorder2 discRecorder, object[] multisessionInterfaces, out IStream dataStream) { MsftFileSystemImage fileSystemImage = new MsftFileSystemImage(); fileSystemImage.ChooseImageDefaults(discRecorder); fileSystemImage.FileSystemsToCreate = FsiFileSystems.FsiFileSystemJoliet | FsiFileSystems.FsiFileSystemISO9660; fileSystemImage.VolumeName = textBoxLabel.Text; fileSystemImage.Update += new DFileSystemImage_EventHandler(fileSystemImage_Update); // // If multisessions, then import previous sessions // if (multisessionInterfaces != null) { fileSystemImage.MultisessionInterfaces = multisessionInterfaces; fileSystemImage.ImportFileSystem(); } // // Get the image root // IFsiDirectoryItem rootItem = fileSystemImage.Root; // // Add Files and Directories to File System Image // foreach (IMediaItem mediaItem in listBoxFiles.Items) { // // Check if we've cancelled // if (backgroundBurnWorker.CancellationPending) { break; } // // Add to File System // mediaItem.AddToFileSystem(rootItem); } fileSystemImage.Update -= new DFileSystemImage_EventHandler(fileSystemImage_Update); // // did we cancel? // if (backgroundBurnWorker.CancellationPending) { dataStream = null; return(false); } dataStream = fileSystemImage.CreateResultImage().ImageStream; return(true); }
private bool CreateMediaFileSystem(IDiscRecorder2 discRecorder, object[] multisessionInterfaces, out IStream dataStream) { bool flag; MsftFileSystemImage msftFileSystemImageClass = null; try { try { msftFileSystemImageClass = (MsftFileSystemImage)(new MsftFileSystemImageClass()); msftFileSystemImageClass.ChooseImageDefaults(discRecorder); msftFileSystemImageClass.FileSystemsToCreate = FsiFileSystems.FsiFileSystemISO9660 | FsiFileSystems.FsiFileSystemJoliet; msftFileSystemImageClass.VolumeName = this.txtVolumeLabel.Text; msftFileSystemImageClass.Update += new DFileSystemImage_EventHandler(this.fileSystemImage_Update); if (multisessionInterfaces != null) { msftFileSystemImageClass.MultisessionInterfaces = multisessionInterfaces; msftFileSystemImageClass.ImportFileSystem(); } IFsiDirectoryItem root = msftFileSystemImageClass.Root; foreach (IMediaItem dirItem in this.DirItems) { if (this.backgroundWorker.CancellationPending) { break; } dirItem.AddToFileSystem(root); } msftFileSystemImageClass.Update -= new DFileSystemImage_EventHandler(this.fileSystemImage_Update); if (!this.backgroundWorker.CancellationPending) { dataStream = msftFileSystemImageClass.CreateResultImage().ImageStream; } else { dataStream = null; flag = false; return(flag); } } catch (COMException cOMException1) { COMException cOMException = cOMException1; MessageBox.Show(this, cOMException.Message, "Create File System Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); dataStream = null; flag = false; return(flag); } return(true); } finally { if (msftFileSystemImageClass != null) { Marshal.ReleaseComObject(msftFileSystemImageClass); } } return(flag); }
private void ButtonDetectMedia_Click(object sender, EventArgs e) { if (devicesComboBox.SelectedIndex == -1) { return; } var discRecorder = (IDiscRecorder2)devicesComboBox.Items[devicesComboBox.SelectedIndex]; MsftFileSystemImage fileSystemImage = null; MsftDiscFormat2Data discFormatData = null; try { // Create and initialize the IDiscFormat2Data discFormatData = new MsftDiscFormat2Data(); if (!discFormatData.IsCurrentMediaSupported(discRecorder)) { labelMediaType.Text = "Media not supported!"; return; } else { // Get the media type in the recorder discFormatData.Recorder = discRecorder; var mediaType = discFormatData.CurrentPhysicalMediaType; labelMediaType.Text = GetMediaTypeString(mediaType); // Create a file system and select the media type fileSystemImage = new MsftFileSystemImage(); fileSystemImage.ChooseImageDefaultsForMediaType(mediaType); // See if there are other recorded sessions on the disc if (!discFormatData.MediaHeuristicallyBlank) { fileSystemImage.MultisessionInterfaces = discFormatData.MultisessionInterfaces; fileSystemImage.ImportFileSystem(); } } } catch (COMException exception) { MessageBox.Show(this, exception.Message, "Detect Media Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (discFormatData != null) { Marshal.ReleaseComObject(discFormatData); } if (fileSystemImage != null) { Marshal.ReleaseComObject(fileSystemImage); } } }
FsiFileSystems IFileSystemImage.ImportFileSystem() { if (_sysImage == null) { throw new NullReferenceException("_sysImage is not valid"); } return(_sysImage.ImportFileSystem()); }
private bool CreateMediaFileSystem(IDiscRecorder2 discRecorder, object[] multisessionInterfaces, out IStream dataStream) { MsftFileSystemImage fileSystemImage = null; try { fileSystemImage = new MsftFileSystemImage(); fileSystemImage.ChooseImageDefaults(discRecorder); fileSystemImage.FileSystemsToCreate = FsiFileSystems.FsiFileSystemJoliet | FsiFileSystems.FsiFileSystemISO9660; fileSystemImage.VolumeName = textBoxLabel.Text; fileSystemImage.Update += FileSystemImage_Update; if (multisessionInterfaces != null) { fileSystemImage.MultisessionInterfaces = multisessionInterfaces; fileSystemImage.ImportFileSystem(); } var rootItem = fileSystemImage.Root; foreach (IMediaItem mediaItem in listBoxFiles.Items) { if (backgroundBurnWorker.CancellationPending) { break; } mediaItem.AddToFileSystem(rootItem); } fileSystemImage.Update -= FileSystemImage_Update; if (backgroundBurnWorker.CancellationPending) { dataStream = null; return(false); } dataStream = fileSystemImage.CreateResultImage().ImageStream; } catch (COMException exception) { MessageBox.Show(this, exception.Message, "Create File System Error", MessageBoxButtons.OK, MessageBoxIcon.Error); dataStream = null; return(false); } finally { if (fileSystemImage != null) { Marshal.ReleaseComObject(fileSystemImage); } } return(true); }
private bool membuatFileSystem(IDiscRecorder2 Recorder, object[] multiSesi, out IStream streamData) { MsftFileSystemImage fileSystem = null; try { fileSystem = new MsftFileSystemImage(); fileSystem.ChooseImageDefaults(Recorder); fileSystem.FileSystemsToCreate = FsiFileSystems.FsiFileSystemJoliet | FsiFileSystems.FsiFileSystemISO9660; fileSystem.VolumeName = textBoxNamaDisc.Text; fileSystem.Update += new DFileSystemImage_EventHandler(fileSystemHandler); if (multiSesi != null) { fileSystem.MultisessionInterfaces = multiSesi; fileSystem.ImportFileSystem(); } IFsiDirectoryItem rootItem = fileSystem.Root; foreach (IMediaItem mediaItem in listBox.Items) { if (backgroundWorker.CancellationPending) { break; } mediaItem.tambahkanKeFileSystem(rootItem); } fileSystem.Update -= new DFileSystemImage_EventHandler(fileSystemHandler); if (backgroundWorker.CancellationPending) { streamData = null; return(false); } streamData = fileSystem.CreateResultImage().ImageStream; } catch (COMException exception) { MessageBox.Show(this, exception.Message, "Kesalahan File System dengan kode :", MessageBoxButtons.OK, MessageBoxIcon.Error); streamData = null; return(false); } finally { if (fileSystem != null) { Marshal.ReleaseComObject(fileSystem); } } return(true); }
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(); }
private void ButtonDetectMedia_Click(object sender, EventArgs e) { if (devicesComboBox.SelectedIndex == -1) { return; } var discRecorder = (IDiscRecorder2)devicesComboBox.Items[devicesComboBox.SelectedIndex]; MsftFileSystemImage fileSystemImage = null; MsftDiscFormat2Data discFormatData = null; try { discFormatData = new MsftDiscFormat2Data(); if (!discFormatData.IsCurrentMediaSupported(discRecorder)) { labelMediaType.Text = "Media not supported!"; return; } else { discFormatData.Recorder = discRecorder; var mediaType = discFormatData.CurrentPhysicalMediaType; freeSpaceOnDisk = (2048 * discFormatData.FreeSectorsOnMedia) / 1048576; FreeSpace.Text = "Free Space: " + Convert.ToInt32(freeSpaceOnDisk).ToString() + " MB"; TotalSpace.Text = "Total Space: " + Convert.ToInt32((2048 * discFormatData.TotalSectorsOnMedia) / 1048576).ToString() + " MB"; labelMediaType.Text = _dictionares.TypeDictionary[mediaType]; fileSystemImage = new MsftFileSystemImage(); fileSystemImage.ChooseImageDefaultsForMediaType(mediaType); if (!discFormatData.MediaHeuristicallyBlank) { fileSystemImage.MultisessionInterfaces = discFormatData.MultisessionInterfaces; fileSystemImage.ImportFileSystem(); } } } catch (COMException exception) { MessageBox.Show(this, exception.Message, "Detect Media Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (discFormatData != null) { Marshal.ReleaseComObject(discFormatData); } if (fileSystemImage != null) { Marshal.ReleaseComObject(fileSystemImage); } } }
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 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(); }
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); }
private void _CreateImage(IDiscRecorder2 discRecorder, object[] multisessionInterfaces, out IStream dataStream) { MsftFileSystemImage image = null; string volumeLabel = this.VolumeLabel; try { if (String.IsNullOrEmpty(volumeLabel)) { volumeLabel = DateTime.Now.ToShortDateString(); } image = new MsftFileSystemImage(); image.ChooseImageDefaults(discRecorder); image.FileSystemsToCreate = FsiFileSystems.FsiFileSystemJoliet | FsiFileSystems.FsiFileSystemISO9660; image.VolumeName = volumeLabel; image.Update += _fileSystemImage_Update; // If multisessions, then import previous sessions if (multisessionInterfaces != null) { image.MultisessionInterfaces = multisessionInterfaces; image.ImportFileSystem(); } IFsiDirectoryItem rootNode = image.Root; foreach (IMediaNode node in this.Nodes) { _AddNode(rootNode, node); } image.Update -= _fileSystemImage_Update; dataStream = image.CreateResultImage().ImageStream; } finally { if (image != null) { Marshal.ReleaseComObject(image); } } }
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(); }
private bool CreateMediaFileSystem(IDiscRecorder2 discRecorder, object[] multisessionInterfaces, out IStream dataStream) { MsftFileSystemImage fileSystemImage = null; try { fileSystemImage = new MsftFileSystemImage(); fileSystemImage.ChooseImageDefaults(discRecorder); fileSystemImage.FileSystemsToCreate = FsiFileSystems.FsiFileSystemJoliet | FsiFileSystems.FsiFileSystemISO9660; fileSystemImage.VolumeName = volume_label.Text; fileSystemImage.Update += fileSystemImage_Update; // // If multisessions, then import previous sessions // if (multisessionInterfaces != null) { fileSystemImage.MultisessionInterfaces = multisessionInterfaces; fileSystemImage.ImportFileSystem(); } // // Get the image root // IFsiDirectoryItem rootItem = fileSystemImage.Root; // // Add Files and Directories to File System Image // foreach (IMediaItem mediaItem in lb.Items) { // // Check if we've cancelled // if (backgroundBurnWorker.CancellationPending) { break; } // // Add to File System // mediaItem.AddToFileSystem(rootItem); } fileSystemImage.Update -= fileSystemImage_Update; // // did we cancel? // if (backgroundBurnWorker.CancellationPending) { dataStream = null; return(false); } dataStream = fileSystemImage.CreateResultImage().ImageStream; } catch (COMException exception) { MessageBox.Show(this, exception.Message, "Create File System Error", MessageBoxButtons.OK, MessageBoxIcon.Error); dataStream = null; return(false); } finally { if (fileSystemImage != null) { Marshal.ReleaseComObject(fileSystemImage); } } return(true); }
public void LoadMedia() { long mediaStateFlags; var mediaStates = new List <MediaState>(); if (!_recorderLoaded) { throw new InvalidOperationException("LoadRecorder must be called first."); } if (_recorders.SelectedIndex == -1) { throw new InvalidOperationException("No DiscRecorder selected on the DiscRecorders list."); } MsftDiscRecorder2 recorder = null; MsftFileSystemImage image = null; MsftDiscFormat2Data format = null; try { recorder = new MsftDiscRecorder2(); recorder.InitializeDiscRecorder(_recorders.SelectedItem.InternalUniqueId); format = new MsftDiscFormat2Data(); if (!format.IsCurrentMediaSupported(recorder)) { throw new MediaNotSupportedException("There is no media in the device."); } // // Get the media type in the recorder // format.Recorder = recorder; _media = (PhysicalMedia)format.CurrentPhysicalMediaType; mediaStateFlags = (long)format.CurrentMediaStatus; foreach (MediaState state in Enum.GetValues(typeof(MediaState))) { if (((long)mediaStateFlags & (long)state) > 0) { mediaStates.Add(state); } } if (mediaStates.Count == 0) { mediaStates.Add(MediaState.Unknown); } _mediaStates = new ReadOnlyCollection <MediaState>(mediaStates); if ((mediaStateFlags & (long)IMAPI_FORMAT2_DATA_MEDIA_STATE.IMAPI_FORMAT2_DATA_MEDIA_STATE_WRITE_PROTECTED) > 0) { throw new MediaNotSupportedException("The media in the device is write protected."); } // // Create a file system and select the media type // image = new MsftFileSystemImage(); image.ChooseImageDefaultsForMediaType((IMAPI_MEDIA_PHYSICAL_TYPE)_media); // // See if there are other recorded sessions on the disc // if (!format.MediaHeuristicallyBlank) { image.MultisessionInterfaces = format.MultisessionInterfaces; image.ImportFileSystem(); } _mediaCapacity = 2048 * (long)image.FreeMediaBlocks; _mediaLoaded = true; } finally { if (image != null) { Marshal.ReleaseComObject(image); } if (format != null) { Marshal.ReleaseComObject(format); } if (recorder != null) { Marshal.ReleaseComObject(recorder); } } }
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); }
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); } } }
private void DetectMedia() { MsftFileSystemImage fileSystemImage = null; MsftDiscFormat2Data discFormatData = null; try { discFormatData = new MsftDiscFormat2Data(); if (!discFormatData.IsCurrentMediaSupported(discRecorder)) { MediaTypeText = "Media not supported!"; totalDiscSize = 0; return; } else { // Get the media type in the recorder discFormatData.Recorder = discRecorder; IMAPI_MEDIA_PHYSICAL_TYPE mediaType = discFormatData.CurrentPhysicalMediaType; MediaTypeText = StringProvider.GetMediaTypeString(mediaType); fileSystemImage = new MsftFileSystemImage(); fileSystemImage.ChooseImageDefaultsForMediaType(mediaType); // See if there are other recorded sessions on the disc if (!discFormatData.MediaHeuristicallyBlank) { fileSystemImage.MultisessionInterfaces = discFormatData.MultisessionInterfaces; fileSystemImage.ImportFileSystem(); } Int64 freeMediaBlocks = fileSystemImage.FreeMediaBlocks; totalDiscSize = 2048 * freeMediaBlocks; } } catch (COMException exception) { MessageBox.Show(exception.Message, "Detect Media Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (discFormatData != null) Marshal.ReleaseComObject(discFormatData); if (fileSystemImage != null) Marshal.ReleaseComObject(fileSystemImage); } UpdateCapacity(); }
private bool CreateMediaFileSystem(IDiscRecorder2 discRecorder, object[] multisessionInterfaces, out IStream dataStream) { MsftFileSystemImage fileSystemImage = null; try { fileSystemImage = new MsftFileSystemImage(); fileSystemImage.ChooseImageDefaults(discRecorder); fileSystemImage.FileSystemsToCreate = FsiFileSystems.FsiFileSystemJoliet | FsiFileSystems.FsiFileSystemISO9660; fileSystemImage.VolumeName = ""; fileSystemImage.Update += fileSystemImage_Update; if (multisessionInterfaces != null) { fileSystemImage.MultisessionInterfaces = multisessionInterfaces; fileSystemImage.ImportFileSystem(); } var rootItem = fileSystemImage.Root; foreach (var mediaItem in mediaItems) { if (cancellationToken.IsCancellationRequested) break; mediaItem.AddToFileSystem(rootItem); } fileSystemImage.Update -= fileSystemImage_Update; if (cancellationToken.IsCancellationRequested) { dataStream = null; return false; } dataStream = fileSystemImage.CreateResultImage().ImageStream; } catch (COMException exception) { MessageBox.Show(exception.Message, "Create File System Error", MessageBoxButton.OK, MessageBoxImage.Error); dataStream = null; return false; } finally { if (fileSystemImage != null) Marshal.ReleaseComObject(fileSystemImage); } return true; }
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(); }
private bool CreateMediaFileSystem(IDiscRecorder2 discRecorder, object[] multisessionInterfaces, out IStream dataStream) { MsftFileSystemImage fileSystemImage = null; try { fileSystemImage = new MsftFileSystemImage(); fileSystemImage.ChooseImageDefaults(discRecorder); fileSystemImage.FileSystemsToCreate = FsiFileSystems.FsiFileSystemJoliet | FsiFileSystems.FsiFileSystemISO9660; System.Diagnostics.Trace.WriteLine("Etichetta: " + this.etichetta); fileSystemImage.VolumeName = this.etichetta; //fileSystemImage.Update += fileSystemImage_Update; fileSystemImage.Update += new DFileSystemImage_EventHandler(fileSystemImage_Update); // // If multisessions, then import previous sessions // if (multisessionInterfaces != null) { fileSystemImage.MultisessionInterfaces = multisessionInterfaces; fileSystemImage.ImportFileSystem(); } // // Get the image root // IFsiDirectoryItem rootItem = fileSystemImage.Root; // // Add Files and Directories to File System Image // foreach (IMediaItem mediaItem in listaFileDaMasterizzare) { // // Check if we've cancelled // if (backgroundBurnWorker.CancellationPending) { break; } // // Add to File System // mediaItem.AddToFileSystem(rootItem); } //fileSystemImage.Update -= fileSystemImage_Update; fileSystemImage.Update -= new DFileSystemImage_EventHandler(fileSystemImage_Update); // // did we cancel? // if (backgroundBurnWorker.CancellationPending) { dataStream = null; return(false); } dataStream = fileSystemImage.CreateResultImage().ImageStream; } catch (COMException exception) { System.Diagnostics.Trace.WriteLine("FileSystem" + exception.Message); BurnerMsg burnerMsg = new BurnerMsg(this); burnerMsg.fase = Fase.MasterizzazioneFallita; OnInviaStatoMasterizzazione(burnerMsg); //MessageBox.Show(this, exception.Message, "Create File System Error", // MessageBoxButtons.OK, MessageBoxIcon.Error); dataStream = null; return(false); } finally { if (fileSystemImage != null) { Marshal.ReleaseComObject(fileSystemImage); } } return(true); }
/// <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); }
private void _CreateImage(IDiscRecorder2 discRecorder, object[] multisessionInterfaces, out IStream dataStream) { MsftFileSystemImage image = null; string volumeLabel = this.VolumeLabel; try { if (String.IsNullOrEmpty(volumeLabel)) volumeLabel = DateTime.Now.ToShortDateString(); image = new MsftFileSystemImage(); image.ChooseImageDefaults(discRecorder); image.FileSystemsToCreate = FsiFileSystems.FsiFileSystemJoliet | FsiFileSystems.FsiFileSystemISO9660; image.VolumeName = volumeLabel; image.Update += _fileSystemImage_Update; // If multisessions, then import previous sessions if (multisessionInterfaces != null) { image.MultisessionInterfaces = multisessionInterfaces; image.ImportFileSystem(); } IFsiDirectoryItem rootNode = image.Root; foreach (IMediaNode node in this.Nodes) { _AddNode(rootNode, node); } image.Update -= _fileSystemImage_Update; dataStream = image.CreateResultImage().ImageStream; } finally { if (image != null) Marshal.ReleaseComObject(image); } }
private bool createMediaFileSystem(IDiscRecorder2 discRecorder, object[] multisessionInterfaces, out IStream dataStream) { MsftFileSystemImage fileSystemImage = null; try { fileSystemImage = new MsftFileSystemImage(); fileSystemImage.ChooseImageDefaults(discRecorder); fileSystemImage.FileSystemsToCreate = FsiFileSystems.FsiFileSystemJoliet | FsiFileSystems.FsiFileSystemISO9660; fileSystemImage.VolumeName = _sessionName; // If multisessions, then import previous sessions if (multisessionInterfaces != null) { try { fileSystemImage.MultisessionInterfaces = multisessionInterfaces; fileSystemImage.ImportFileSystem(); } catch (Exception ex) { // ignore multisession Log.WriteLine(ex.ToString()); } } // Get the image root IFsiDirectoryItem rootItem = fileSystemImage.Root; // Burn disks in parallel could make the file in burning is lock lock (syncData) { // Add Files and Directories to File System Image var fileItem = new FileItem(_filePath); IMediaItem mediaItem = fileItem; mediaItem.AddToFileSystem(rootItem); // Make data stream try { dataStream = fileSystemImage.CreateResultImage().ImageStream; } catch (Exception ex) { dataStream = null; MessageBox.Show("Ổ đĩa bị khóa hoặc có lỗi trong quá trình định dạng đĩa"); Log.WriteLine(ex.ToString()); return(false); } } } catch (Exception ex) { dataStream = null; MessageBox.Show("Ổ đĩa bị khóa hoặc có lỗi trong quá trình định dạng đĩa"); Log.WriteLine(ex.ToString()); return(false); } finally { if (fileSystemImage != null) { Marshal.ReleaseComObject(fileSystemImage); } } return(true); }
private bool CreateMediaFileSystem(IDiscRecorder2 discRecorder, object[] multisessionInterfaces, out IStream dataStream) { MsftFileSystemImage fileSystemImage = null; try { fileSystemImage = new MsftFileSystemImage(); fileSystemImage.ChooseImageDefaults(discRecorder); fileSystemImage.FileSystemsToCreate = FsiFileSystems.FsiFileSystemJoliet | FsiFileSystems.FsiFileSystemISO9660; fileSystemImage.VolumeName = volume_label.Text; fileSystemImage.Update += fileSystemImage_Update; // // If multisessions, then import previous sessions // if (multisessionInterfaces != null) { fileSystemImage.MultisessionInterfaces = multisessionInterfaces; fileSystemImage.ImportFileSystem(); } // // Get the image root // IFsiDirectoryItem rootItem = fileSystemImage.Root; // // Add Files and Directories to File System Image // foreach (IMediaItem mediaItem in lb.Items) { // // Check if we've cancelled // if (backgroundBurnWorker.CancellationPending) { break; } // // Add to File System // mediaItem.AddToFileSystem(rootItem); } fileSystemImage.Update -= fileSystemImage_Update; // // did we cancel? // if (backgroundBurnWorker.CancellationPending) { dataStream = null; return false; } dataStream = fileSystemImage.CreateResultImage().ImageStream; } catch (COMException exception) { MessageBox.Show(this, exception.Message, "Create File System Error", MessageBoxButtons.OK, MessageBoxIcon.Error); dataStream = null; return false; } finally { if (fileSystemImage != null) { Marshal.ReleaseComObject(fileSystemImage); } } return true; }
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); }
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); } }