/// <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 static void BurnDirectory(this IDiscRecorder2 recorder, string path, string imageName = "IMAPI Sample") { // Define the new disc format and set the recorder var dataWriterImage = new IDiscFormat2Data { 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 = imageName; // Create an image stream for a specified directory. // Create a new file system image and retrieve the root directory var fsi = new IFileSystemImage { // Set the media size FreeMediaBlocks = dataWriterImage.FreeSectorsOnMedia, // Use legacy ISO 9660 Format FileSystemsToCreate = FsiFileSystems.FsiFileSystemUDF }; // Add the directory to the disc file system IFsiDirectoryItem dir = fsi.Root; Console.WriteLine(); Console.Write("Adding files to image:".PadRight(80)); using (var eventDisp = new ComConnectionPoint(fsi, new DFileSystemImageEventsSink(AddTreeUpdate))) dir.AddTree(path, false); Console.WriteLine(); // Create an image from the file system Console.WriteLine("\nWriting content to disc..."); IFileSystemImageResult result = fsi.CreateResultImage(); // Data stream sent to the burning device IStream stream = result.ImageStream; // Write the image stream to disc using the specified recorder. using (var eventDisp = new ComConnectionPoint(dataWriterImage, new DDiscFormat2DataEventsSink(WriteUpdate))) dataWriterImage.Write(stream); // Burn the stream to disc Console.WriteLine("----- Finished writing content -----");
private IFileSystemImage InitRepository() { Application.DoEvents(); IFileSystemImage ifsi = _repository; var fstype = FsiFileSystems.FsiFileSystemNone; fstype |= FsiFileSystems.FsiFileSystemISO9660; fstype |= FsiFileSystems.FsiFileSystemJoliet; fstype |= FsiFileSystems.FsiFileSystemUDF; ifsi.FileSystemsToCreate = fstype; //_repository.BootableImageFile = _bootableImageFile; ifsi.ChooseImageDefaultsForMediaType(IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DISK); ifsi.VolumeName = _label; //this.Stop += _repository.CancelOp; try { //if (_ckUseUIReport.Checked) //{ //if (_ckWorker.Checked) // _repository.Update += new DiscFormat2Data_EventsHandler(AsyncRepositoryUpdate); //else _repository.Update += RepositoryUpdate; //_lblUpdate.Text = string.Format("Calculating size for {0}...", _lblDest.Text); //Application.DoEvents(); try { //if (_ckWorker.Checked) // _progBar.Style = ProgressBarStyle.Marquee; OnPropertyChanged("50|Calculating size..."); _repository.CalculateSizeBeforeFormatting(); } finally { //if (_ckWorker.Checked) // _progBar.Style = ProgressBarStyle.Continuous; } //} //else //{ // if (_ckWorker.Checked) // _progBar.Style = ProgressBarStyle.Marquee; // _lblUpdate.Text = string.Format("Creating {0}...", _lblDest.Text); //} } finally { } return(ifsi); }
static void AddTreeUpdate(IFileSystemImage @object, string currentFile, long copiedSectors, long totalSectors) { Console.Write(new string('\b', 80)); Console.Write(Path.GetFileName(currentFile).PadRight(80)); }