public void WriteToFile(string FileName, bool Overwrite = true) { IFileSystemImageResult Res = ISO.CreateResultImage(); IStream ImgStream = (IStream)Res.ImageStream; if (ImgStream != null) { STATSTG Stat; ImgStream.Stat(out Stat, 0x1); if (File.Exists(FileName)) { if (Overwrite) { File.Delete(FileName); } else { throw new Exception("File already exists: " + FileName); } } IStream OutStream; SHCreateStreamOnFile(FileName, 0x1001, out OutStream); ImgStream.CopyTo(OutStream, Stat.cbSize, IntPtr.Zero, IntPtr.Zero); OutStream.Commit(0); } }
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 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); }
public Stream Build() { var result = _fsi.CreateResultImage(); // Data stream sent to the burning device var stream = result.ImageStream; return(new ImageStream(stream)); }
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"); } }
/// <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.</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."); } }
/// <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(); }
/// <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); } } }
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> /// 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); }
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; }
// 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 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); }
/// <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 -----"); }
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 } }
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 = _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 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); } }