public IsoImageBuilder(FileSystemType fileSystemType) { _fsi.ChooseImageDefaultsForMediaType(IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DISK); switch (fileSystemType) { case FileSystemType.Iso9660: _fsi.FileSystemsToCreate = FsiFileSystems.FsiFileSystemISO9660; _fsi.ISO9660InterchangeLevel = 2; break; case FileSystemType.Joliet: _fsi.FileSystemsToCreate = FsiFileSystems.FsiFileSystemJoliet | FsiFileSystems.FsiFileSystemISO9660; _fsi.ISO9660InterchangeLevel = 2; break; case FileSystemType.Udf: _fsi.FileSystemsToCreate = FsiFileSystems.FsiFileSystemUDF; break; default: throw new ArgumentOutOfRangeException(nameof(fileSystemType), fileSystemType, null); } }
public IsoImage(string VolumeName) { ISO = new MsftFileSystemImage(); ISO.ChooseImageDefaultsForMediaType(IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DISK); ISO.FileSystemsToCreate = FsiFileSystems.FsiFileSystemISO9660 | FsiFileSystems.FsiFileSystemJoliet; ISO.VolumeName = VolumeName; }
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); } } }
private void materialFlatButton3_Click(object sender, EventArgs e) { bool correctdump = false; if (Directory.Exists(input.Text + "\\MSXC")) { if (Directory.Exists(input.Text + "\\Licenses")) { correctdump = true; } } if (correctdump) { IFileSystemImage ifsi = new MsftFileSystemImage(); ifsi.ChooseImageDefaultsForMediaType(IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DISK); ifsi.FileSystemsToCreate = FsiFileSystems.FsiFileSystemUDF; ifsi.VolumeName = "DVD_ROM"; ifsi.Root.AddTree(input.Text, true); //use a valid folder //this will implement the Write method for the formatter IStream imagestream = ifsi.CreateResultImage().ImageStream; if (imagestream != null) { System.Runtime.InteropServices.ComTypes.STATSTG stat; imagestream.Stat(out stat, 0x01); IStream newStream; if (0 == SHCreateStreamOnFile (output.Text, 0x00001001, out newStream) && newStream != null) { IntPtr inBytes = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(long))); IntPtr outBytes = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(long))); try { imagestream.CopyTo(newStream, stat.cbSize, inBytes, outBytes); Marshal.ReleaseComObject(imagestream); imagestream = null; newStream.Commit(0); } finally { Marshal.ReleaseComObject(newStream); Marshal.FreeHGlobal(inBytes); Marshal.FreeHGlobal(outBytes); if (imagestream != null) { Marshal.ReleaseComObject(imagestream); } } } } Marshal.ReleaseComObject(ifsi); MessageBox.Show("Dump converted to iso"); } else { MessageBox.Show("The path given: \n" + input.Text + "\n" + "appears to be an incorrect dump, check this path and try again" + "\n" + "if you still get this error you should try redumping the title" + "\n" + "in the case that all of the suggestions have failed you should" + "\n" + "ask for help on the Xbox One homebrew discord"); } }
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); } } }
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); }
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); } } }
IFileSystemImageResult IFileSystemImage.CreateResultImage() { if (_sysImage == null) { _cancel = false; } #if DEBUG var tm = new Stopwatch(); tm.Start(); #endif try { FileSysImage = new MsftFileSystemImage(); _sysImage.ChooseImageDefaultsForMediaType(_mediatype); if (BootableImageFile != null) { CreateBootDisc(BootableImageFile); } var root = _sysImage.Root; _sysImage.FileSystemsToCreate = _fsifs; _sysImage.VolumeName = _volumeName; ActualSize = 0; var bUpdateUI = Update != null && Update.GetInvocationList().Length > 0; _items.ForEach(delegate(FileSystemInfo item) { if (!_cancel) { if ((item.Attributes & FileAttributes.Directory) == 0) { CreateFSIFile(item as FileInfo, root); } else { var dirinf = item as DirectoryInfo; if (dirinf.Parent != null) { if (bUpdateUI) { CreateFSIFolder(item as DirectoryInfo, root); } else { root.AddTree(item.FullName, false); } } else { foreach (var fsi in dirinf.GetFileSystemInfos()) { if (_cancel) { break; } if ((fsi.Attributes & FileAttributes.Directory) == 0) { CreateFSIFile(fsi as FileInfo, root); } else { if (bUpdateUI) { CreateFSIFolder(fsi as DirectoryInfo, root); } else { root.AddTree(fsi.FullName, true); } } } } } } }); return(_cancel ? null : _sysImage.CreateResultImage()); } catch (ApplicationException) { FileSysImage = null; throw; } catch (COMException ex) { FileSysImage = null; throw new ApplicationException("multiple folder occurence in source folders: " + ex.Message, ex); } catch { Cancel = true; throw; } finally { if (_cancel) { FileSysImage = null; } #if DEBUG tm.Stop(); Debug.WriteLine(string.Format("Preparing the image lasted {0} ms", tm.Elapsed.TotalMilliseconds.ToString("#,#"))); #endif } }
// note, these won't be read by PS2? //Created by Joshua Bylotas //http://www.ivorymatter.com public static void CreateISOImage(string Name, string dir, string ISOPath) { //Create File System Object to write to and set properties IFileSystemImage ifsi = new MsftFileSystemImage(); ifsi.ChooseImageDefaultsForMediaType(IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR_DUALLAYER); ifsi.FileSystemsToCreate = FsiFileSystems.FsiFileSystemISO9660 | FsiFileSystems.FsiFileSystemUDF; // ifsi.ISO9660InterchangeLevel = 1; // ifsi.UDFRevision = 0x0102; ifsi.VolumeName = Name; //string[] folders = System.IO.Directory.GetDirectories(dir); //string[] files = System.IO.Directory.GetFiles(dir); //for (int i = 0; i < folders.Count; i++) //{ // ifsi.Root.Addd //} ifsi.Root.AddTree(dir, false); //this will implement the Write method for the formatter IStream imagestream = ifsi.CreateResultImage().ImageStream; if (imagestream != null) { System.Runtime.InteropServices.ComTypes.STATSTG stat; imagestream.Stat(out stat, 0x01); IStream newStream; SHCreateStreamOnFile(ISOPath, 0x00001001, out newStream); if (newStream != null) { IntPtr inBytes = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(long))); IntPtr outBytes = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(long))); try { imagestream.CopyTo(newStream, stat.cbSize, inBytes, outBytes); Marshal.ReleaseComObject(imagestream); imagestream = null; newStream.Commit(0); } finally { Marshal.ReleaseComObject(newStream); Marshal.FreeHGlobal(inBytes); Marshal.FreeHGlobal(outBytes); if (imagestream != null) { Marshal.ReleaseComObject(imagestream); } } } } Marshal.ReleaseComObject(ifsi); }
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(); }
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); } } }
/// <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); }
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(); }
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); }
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 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); } }