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 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); } } }
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 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(); }
/// <summary> /// Burns data files to disc in a single session using files from a /// single directory tree. /// </summary> /// <param name="recorder">Burning device.</param> /// <param name="path">Directory of files to burn.</param> /// <param name="clientName">The friendly name of the client (used to determine recorder reservation conflicts).</param> public void BurnDirectory(DiscRecorder recorder, string path, string clientName = "IMAPI Client Record Name") { if (!recorder.MediaImage.IsRecorderSupported(recorder.Recorder)) { throw new Exception("The recorder is not supported"); } if (!recorder.MediaImage.IsCurrentMediaSupported(recorder.Recorder)) { throw new Exception("The current media is not supported"); } // Set the client name. recorder.MediaImage.ClientName = clientName; // Create an image stream for a specified directory. // Create a new file system image and retrieve the root directory IFileSystemImage fsi = new MsftFileSystemImage(); // Set the media size fsi.FreeMediaBlocks = recorder.MediaImage.FreeSectorsOnMedia; // Use legacy ISO 9660 Format fsi.FileSystemsToCreate = FsiFileSystems.FsiFileSystemISO9660; // Add the directory to the disc file system IFsiDirectoryItem dir = fsi.Root; dir.AddTree(path, false); // Write the progress. if (recorder.ProgressAction != null) { recorder.ProgressAction("Writing content to disc."); } // Create an image from the file system. // Data stream sent to the burning device IFileSystemImageResult result = fsi.CreateResultImage(); IStream stream = result.ImageStream; DiscFormat2Data_Events progress = recorder.MediaImage as DiscFormat2Data_Events; progress.Update += new DiscFormat2Data_EventsHandler(recorder.DiscFormat2Data_ProgressUpdate); // Write the image stream to disc using the specified recorder. recorder.MediaImage.Write(stream); // Burn the stream to disc progress.Update -= new DiscFormat2Data_EventsHandler(recorder.DiscFormat2Data_ProgressUpdate); // Write the progress. if (recorder.ProgressAction != null) { recorder.ProgressAction("Finished writing content."); } }
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); } } }
/// <summary> /// Burns data files to disc in a single session using files from a /// single directory tree. /// </summary> /// <param name="recorder">Burning Device. Must be initialized.</param> /// <param name="path">Directory of files to burn.</param> public void BurnDirectory(IDiscRecorder2 recorder, String path) { // Define the new disc format and set the recorder IDiscFormat2Data dataWriterImage = new MsftDiscFormat2Data(); dataWriterImage.Recorder = recorder; if (!dataWriterImage.IsRecorderSupported(recorder)) { Console.WriteLine("The recorder is not supported"); return; } if (!dataWriterImage.IsCurrentMediaSupported(recorder)) { Console.WriteLine("The current media is not supported"); return; } dataWriterImage.ClientName = "IMAPI Sample"; // Create an image stream for a specified directory. // Create a new file system image and retrieve the root directory IFileSystemImage fsi = new MsftFileSystemImage(); // Set the media size fsi.FreeMediaBlocks = dataWriterImage.FreeSectorsOnMedia; // Use legacy ISO 9660 Format fsi.FileSystemsToCreate = FsiFileSystems.FsiFileSystemISO9660; // Add the directory to the disc file system IFsiDirectoryItem dir = fsi.Root; dir.AddTree(path, false); // Create an image from the file system Console.WriteLine("Writing content to disc..."); IFileSystemImageResult result = fsi.CreateResultImage(); // Data stream sent to the burning device IStream stream = result.ImageStream; DiscFormat2Data_Events progress = dataWriterImage as DiscFormat2Data_Events; progress.Update += new DiscFormat2Data_EventsHandler(DiscFormat2Data_ProgressUpdate); // Write the image stream to disc using the specified recorder. dataWriterImage.Write(stream); // Burn the stream to disc progress.Update -= new DiscFormat2Data_EventsHandler(DiscFormat2Data_ProgressUpdate); Console.WriteLine("----- Finished writing content -----"); }
/// <summary> /// Burns data files to disc in a single session using files from a /// single directory tree. /// </summary> /// <param name="recorder">Burning Device. Must be initialized.</param> /// <param name="path">Directory of files to burn.</param> public void BurnDirectory(IDiscRecorder2 recorder, String path) { // Define the new disc format and set the recorder IDiscFormat2Data dataWriterImage = new MsftDiscFormat2Data(); dataWriterImage.Recorder = recorder; if(!dataWriterImage.IsRecorderSupported(recorder)) { Console.WriteLine("The recorder is not supported"); return; } if (!dataWriterImage.IsCurrentMediaSupported(recorder)) { Console.WriteLine("The current media is not supported"); return; } dataWriterImage.ClientName = "IMAPI Sample"; // Create an image stream for a specified directory. // Create a new file system image and retrieve the root directory IFileSystemImage fsi = new MsftFileSystemImage(); // Set the media size fsi.FreeMediaBlocks = dataWriterImage.FreeSectorsOnMedia; // Use legacy ISO 9660 Format fsi.FileSystemsToCreate = FsiFileSystems.FsiFileSystemISO9660; // Add the directory to the disc file system IFsiDirectoryItem dir = fsi.Root; dir.AddTree(path, false); // Create an image from the file system Console.WriteLine("Writing content to disc..."); IFileSystemImageResult result = fsi.CreateResultImage(); // Data stream sent to the burning device IStream stream = result.ImageStream; DiscFormat2Data_Events progress = dataWriterImage as DiscFormat2Data_Events; progress.Update += new DiscFormat2Data_EventsHandler(DiscFormat2Data_ProgressUpdate); // Write the image stream to disc using the specified recorder. dataWriterImage.Write(stream); // Burn the stream to disc progress.Update -= new DiscFormat2Data_EventsHandler(DiscFormat2Data_ProgressUpdate); Console.WriteLine("----- Finished writing content -----"); }
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(); }
public void Reset() { lock (this) { _cancel = false; if (_sysImage != null) { //CleanUp(_sysImage.Root); Marshal.FinalReleaseComObject(_sysImage); _sysImage = null; } } }
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); }
/// <summary> /// Burns a boot image and data files to disc in a single session /// using files from a single directory tree. /// </summary> /// <param name="recorder">Burning Device. Must be initialized.</param> /// <param name="path">Directory of files to burn. /// \\winbuilds\release\winmain\latest.tst\amd64fre\en-us\skus.cmi\staged\windows /// </param> /// <param name="bootFile">Path and filename of boot image. /// \\winbuilds\release\winmain\latest.tst\x86fre\bin\etfsboot.com /// </param> public void CreateBootDisc(IDiscRecorder2 recorder, String path, String bootFile) { // -------- Adding Boot Image Code ----- Console.WriteLine("Creating BootOptions"); IBootOptions bootOptions = new MsftBootOptions(); bootOptions.Manufacturer = "Microsoft"; bootOptions.PlatformId = PlatformId.PlatformX86; bootOptions.Emulation = EmulationType.EmulationNone; // Need stream for boot image file Console.WriteLine("Creating IStream for file {0}", bootFile); IStream iStream = new AStream( new FileStream(bootFile, FileMode.Open, FileAccess.Read, FileShare.Read)); bootOptions.AssignBootImage(iStream); // Create disc file system image (ISO9660 in this example) IFileSystemImage fsi = new MsftFileSystemImage(); fsi.FreeMediaBlocks = -1; // Enables larger-than-CD image fsi.FileSystemsToCreate = FsiFileSystems.FsiFileSystemISO9660 | FsiFileSystems.FsiFileSystemJoliet | FsiFileSystems.FsiFileSystemUDF; // Hooking bootStream to FileSystemObject fsi.BootImageOptions = bootOptions; // Hooking content files FileSystemObject fsi.Root.AddTree(path, false); IFileSystemImageResult result = fsi.CreateResultImage(); IStream stream = result.ImageStream; // Create and write stream to disc using the specified recorder. IDiscFormat2Data dataWriterBurn = new MsftDiscFormat2Data(); dataWriterBurn.Recorder = recorder; dataWriterBurn.ClientName = "IMAPI Sample"; dataWriterBurn.Write(stream); Console.WriteLine("----- Finished writing content -----"); }
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 bool DetectMedia(ListItem li, ref Label lbl) { bool flag = false; lbl.Text = string.Empty; MsftFileSystemImage msftFileSystemImage = null; GInterface6 msftDiscFormat2DataClass = null; IDiscRecorder2 tag = (IDiscRecorder2)li.Tag; try { try { msftDiscFormat2DataClass = (GInterface6)(new MsftDiscFormat2DataClass()); if (msftDiscFormat2DataClass.IsCurrentMediaSupported(tag)) { msftDiscFormat2DataClass.Recorder = tag; lbl.Text = this.GetMediaTypeString(msftDiscFormat2DataClass.CurrentPhysicalMediaType); flag = true; } else { lbl.Text = "No Media"; } } catch (COMException cOMException) { } } finally { if (msftDiscFormat2DataClass != null) { Marshal.ReleaseComObject(msftDiscFormat2DataClass); } if (msftFileSystemImage != null) { Marshal.ReleaseComObject(msftFileSystemImage); } } return(flag); }
//private bool CleanUp( IFsiDirectoryItem fsidir) //{ // if (fsidir == null) // return false; // IEnumerator enm = fsidir.GetEnumerator(); // while (enm.MoveNext()) // { // IFsiItem it = enm.Current as IFsiItem; // IFsiFileItem fit = it as IFsiFileItem; // if (fit != null) // { // COMTypes.IStream str = fit.Data; // IntPtr pointer = Marshal.GetIUnknownForObject(str); // int i = Marshal.Release(pointer); // i = Marshal.Release(pointer); // } // else // return CleanUp(it as IFsiDirectoryItem); // } // return true; //} void IDisposable.Dispose() { Monitor.Enter(this); try { BootableImageFile = null; if (_sysImage != null) { //CleanUp(_sysImage.Root); Marshal.FinalReleaseComObject(_sysImage); _sysImage = null; } } catch (SynchronizationLockException) { } finally { Monitor.Exit(this); GC.SuppressFinalize(this); } }
/// <summary> /// executes the task. /// </summary> /// <returns>true if the task successfully executed; otherwise, false.</returns> public override bool Execute() { Log.LogMessage(MessageImportance.Normal, $"CreateDiscImage: [{this.OutputFilePath}]"); try { if (File.Exists(this.OutputFilePath)) { File.Delete(this.OutputFilePath); } } catch (IOException e) { Log.LogErrorFromException(e, showStackTrace: false); return(false); } var fileSystemImage = default(MsftFileSystemImage); var discRoot = default(IFsiDirectoryItem); var resultImage = default(IFileSystemImageResult); var imageStream = default(FsiStream); var fileItemStreams = new List <FsiStream>(); try { fileSystemImage = new MsftFileSystemImage(); fileSystemImage.FileSystemsToCreate = this.FileSystemType == "ISO9660" ? FsiFileSystems.FsiFileSystemISO9660 : this.FileSystemType == "UDF" ? FsiFileSystems.FsiFileSystemUDF : FsiFileSystems.FsiFileSystemUnknown; if (this.UseJoliet && this.FileSystemType == "ISO9660") { fileSystemImage.FileSystemsToCreate |= FsiFileSystems.FsiFileSystemJoliet; } fileSystemImage.FreeMediaBlocks = 0; fileSystemImage.VolumeName = this.VolumeLabel; var removeRootsFullPath = this.RemoveRoots .Select(item => item.GetMetadata("FullPath")) .Select(path => path.EndsWith("\\") ? path : path + "\\") .Select(path => path.ToLower()) .ToArray(); discRoot = fileSystemImage.Root; var registerdSubDirs = new HashSet <string>(); foreach (var sourceFile in this.SourceFiles) { var srcFullPath = sourceFile.GetMetadata("FullPath"); var srcFullPathToLower = srcFullPath.ToLower(); var srcPath = string.Join("", new[] { "Directory", "FileName", "Extension" }.Select(name => sourceFile.GetMetadata(name))); var fullPathToRemoveRoot = removeRootsFullPath.FirstOrDefault(path => srcFullPathToLower.StartsWith(path)); srcPath = removeRootsFullPath == null ? srcPath : srcFullPath.Substring(fullPathToRemoveRoot.Length); Log.LogMessage(MessageImportance.Low, $"CreateDiscImage: srcFullPath is [{srcFullPath}]"); Log.LogMessage(MessageImportance.Low, $"CreateDiscImage: srcPath is [{srcPath}]"); var subDir = Path.GetDirectoryName(srcPath); if (subDir != "" && !registerdSubDirs.Contains(subDir)) { var dirs = subDir.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries); dirs.Aggregate("", (prev, current) => { var dir = Path.Combine(prev, current); if (!registerdSubDirs.Contains(dir)) { Log.LogMessage(MessageImportance.Low, $"CreateDiscImage: AddDirectory [{dir}]"); discRoot.AddDirectory(dir); registerdSubDirs.Add(dir); } return(dir); }); } Log.LogMessage(MessageImportance.Low, $"CreateDiscImage: AddFile [{srcPath}]"); var fileItemStream = default(FsiStream); SHCreateStreamOnFile(srcFullPath, STGM.READ, out fileItemStream); discRoot.AddFile(srcPath, fileItemStream); fileItemStreams.Add(fileItemStream); } resultImage = fileSystemImage.CreateResultImage(); imageStream = resultImage.ImageStream; WriteIStreamToFile(imageStream, this.OutputFilePath); } finally { try { if (imageStream != null) { Marshal.ReleaseComObject(imageStream); } if (resultImage != null) { Marshal.ReleaseComObject(resultImage); } if (discRoot != null) { Marshal.ReleaseComObject(discRoot); } if (fileSystemImage != null) { Marshal.ReleaseComObject(fileSystemImage); } imageStream = null; resultImage = null; discRoot = null; fileSystemImage = null; fileItemStreams.ForEach(stream => Marshal.ReleaseComObject(stream)); fileItemStreams.Clear(); } catch (Exception e) { Log.LogWarningFromException(e, showStackTrace: true); } } Log.LogMessage(MessageImportance.Normal, $"CreateDiscImage: Complete."); return(!Log.HasLoggedErrors); }
// 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(); }
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 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; 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 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 void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { MsftDiscRecorder2 Recorder = null; MsftDiscFormat2Erase Format = null; MsftFileSystemImage fileSystem = null; try { Recorder = new MsftDiscRecorder2(); string activeDiscRecorder = (string)e.Argument; Recorder.InitializeDiscRecorder(activeDiscRecorder); Recorder.AcquireExclusiveAccess(true, namaProgram); fileSystem = new MsftFileSystemImage(); fileSystem.VolumeName = ""; Format = new MsftDiscFormat2Erase(); Format.Recorder = Recorder; Format.ClientName = namaProgram; Format.FullErase = checkBoxFormatCepat.Checked; Format.Update += new DiscFormat2Erase_EventHandler(eraseUpdate); try { Format.EraseMedia(); e.Result = 0; } catch (COMException ex) { e.Result = ex.ErrorCode; MessageBox.Show("Sepertinya media ini tidak bisa dihapus...\nKemungkinan media terkunci, diproteksi atau sudah rusak.", pesan, MessageBoxButtons.OK, MessageBoxIcon.Stop); } Format.Update -= new DiscFormat2Erase_EventHandler(eraseUpdate); if (checkBoxKeluarkanTray.Checked) { Recorder.EjectMedia(); } } catch (COMException exception) { MessageBox.Show(exception.Message, pesan); if (checkBoxKeluarkanTray.Checked) { Recorder.EjectMedia(); } } finally { if (Recorder != null) { Recorder.ReleaseExclusiveAccess(); Marshal.ReleaseComObject(Recorder); } if (Format != null) { Marshal.ReleaseComObject(Format); } } }
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); }
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); }
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); } } }
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); } } }
/// <summary> /// Burns a boot image and data files to disc in a single session /// using files from a single directory tree. /// </summary> /// <param name="recorder">Burning Device. Must be initialized.</param> /// <param name="path">Directory of files to burn. /// \\winbuilds\release\winmain\latest.tst\amd64fre\en-us\skus.cmi\staged\windows /// </param> /// <param name="bootFile">Path and filename of boot image. /// \\winbuilds\release\winmain\latest.tst\x86fre\bin\etfsboot.com /// </param> public void CreateBootDisc(IDiscRecorder2 recorder, String path, String bootFile) { // -------- Adding Boot Image Code ----- Console.WriteLine("Creating BootOptions"); IBootOptions bootOptions = new MsftBootOptions(); bootOptions.Manufacturer = "Microsoft"; bootOptions.PlatformId = PlatformId.PlatformX86; bootOptions.Emulation = EmulationType.EmulationNone; // Need stream for boot image file Console.WriteLine("Creating IStream for file {0}", bootFile); IStream iStream = new AStream( new FileStream(bootFile, FileMode.Open, FileAccess.Read, FileShare.Read)); bootOptions.AssignBootImage(iStream); // Create disc file system image (ISO9660 in this example) IFileSystemImage fsi = new MsftFileSystemImage(); fsi.FreeMediaBlocks = -1; // Enables larger-than-CD image fsi.FileSystemsToCreate = FsiFileSystems.FsiFileSystemISO9660 | FsiFileSystems.FsiFileSystemJoliet | FsiFileSystems.FsiFileSystemUDF; // Hooking bootStream to FileSystemObject fsi.BootImageOptions = bootOptions; // Hooking content files FileSystemObject fsi.Root.AddTree(path, false); IFileSystemImageResult result = fsi.CreateResultImage(); IStream stream= result.ImageStream; // Create and write stream to disc using the specified recorder. IDiscFormat2Data dataWriterBurn = new MsftDiscFormat2Data(); dataWriterBurn.Recorder = recorder; dataWriterBurn.ClientName = "IMAPI Sample"; dataWriterBurn.Write(stream); Console.WriteLine("----- Finished writing content -----"); }
/// <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(); }
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); } }