/// <summary> /// 加文件,完全看不懂啊 /// </summary> /// <param name="root"></param> /// <returns></returns> private bool AddFile(ref IFsiDirectoryItem root) { System.Runtime.InteropServices.ComTypes.IStream stream = null; try { Win32.SHCreateStreamOnFile(m_strThisPath, Win32.STGM_READ | Win32.STGM_SHARE_DENY_WRITE, ref stream); if (stream != null) { root.AddFile(m_strDisplayName, stream); return(true); } return(true); } catch (System.Exception ex) { return(false); } finally { if (stream != null) { Marshal.FinalReleaseComObject(stream); } } }
public bool AddToFileSystem(IFsiDirectoryItem rootItem, CancellationToken cancellationToken, string basePath = "") { if (cancellationToken.IsCancellationRequested) { return(false); } try { // Add each file individually instead of using rootItem.AddTree so that all the streams are ManagedIStream var relativePath = System.IO.Path.Combine(basePath, DisplayName); rootItem.AddDirectory(relativePath); foreach (var item in mediaItems) { item.AddToFileSystem(rootItem, cancellationToken, relativePath); cancellationToken.ThrowIfCancellationRequested(); } return(true); } catch (Exception) { return(false); } }
public bool AddToFileSystem(IFsiDirectoryItem rootItem) { IStream stream = null; try { Win32.SHCreateStreamOnFile(filePath, Win32.STGM_READ | Win32.STGM_SHARE_DENY_WRITE, ref stream); if (stream != null) { rootItem.AddFile(displayName, stream); return(true); } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message, "Error adding file"); } finally { if (stream != null) { Marshal.FinalReleaseComObject(stream); } } return(false); }
public bool AddToFileSystem(IFsiDirectoryItem rootItem) { bool flag; IStream stream = null; try { try { Win32.SHCreateStreamOnFileW(this.filePath, 32, ref stream); if (stream != null) { rootItem.AddFile(this.displayName, stream); flag = true; return(flag); } } catch (Exception exception1) { Exception exception = exception1; MessageBox.Show(exception.Message, "Error adding file", MessageBoxButtons.OK, MessageBoxIcon.Hand); } return(false); } finally { if (stream != null) { Marshal.FinalReleaseComObject(stream); } } return(flag); }
private void _AddNode(IFsiDirectoryItem root, IMediaNode node) { IStream stream = null; try { if (node is DirectoryNode) { root.AddTree(node.Path, true); } else { Shell.SHCreateStreamOnFile(node.Path, Shell.STGM_READ | Shell.STGM_SHARE_DENY_WRITE, ref stream); if (stream != null) { root.AddFile(node.Name, stream); } } } finally { if (stream != null) { Marshal.FinalReleaseComObject(stream); } } }
public bool AddToFileSystem(IFsiDirectoryItem rootItem) { IStream stream = null; try { Win32.SHCreateStreamOnFile(filePath, Win32.STGM_READ | Win32.STGM_SHARE_DENY_WRITE, ref stream); if (stream != null) { rootItem.AddFile(displayName, stream); return(true); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error adding file", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (stream != null) { Marshal.FinalReleaseComObject(stream); } } return(false); }
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 = 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 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); }
/// <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 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 -----");
/// <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> /// /// </summary> /// <param name="rootItem"></param> /// <returns></returns> private bool AddDir(ref IFsiDirectoryItem rootItem) { try { rootItem.AddTree(m_strThisPath, true); return(true); } catch (Exception ex) { return(false); } }
/// <summary> /// 增加到文件系统中 /// </summary> /// <returns></returns> public bool AddToFileSystem(IFsiDirectoryItem root) { //根据类型不同,有不同的加法 if (m_mediaType == MediaType.Dir) { return(AddDir(ref root)); } else { return(AddFile(ref root)); } return(false); }
/// <summary> /// /// </summary> /// <param name="rootItem"></param> /// <returns></returns> public bool AddToFileSystem(IFsiDirectoryItem rootItem) { try { rootItem.AddTree(m_directoryPath, true); return(true); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message, "Error adding folder"); return(false); } }
/// <summary> /// /// </summary> /// <param name="rootItem"></param> /// <returns></returns> public bool AddToFileSystem(IFsiDirectoryItem rootItem) { try { rootItem.AddTree(m_directoryPath, true); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error adding folder", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } }
public bool tambahkanKeFileSystem(IFsiDirectoryItem rootItem) { try { rootItem.AddTree(pathDirektori, true); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message, "Kesalahan menambahkan folder...", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } }
public bool AddToFileSystem(IFsiDirectoryItem rootItem) { bool flag; try { rootItem.AddTree(this.m_directoryPath, true); flag = true; } catch (Exception exception1) { Exception exception = exception1; MessageBox.Show(exception.Message, "Error adding folder", MessageBoxButtons.OK, MessageBoxIcon.Hand); flag = false; } return(flag); }
public bool AddToFileSystem(IFsiDirectoryItem rootItem, CancellationToken cancellationToken, string basePath = "") { if (cancellationToken.IsCancellationRequested) { return(false); } try { var stream = new ManagedIStream(File.Open(Path, FileMode.Open, FileAccess.Read, FileShare.Read)); rootItem.AddFile(System.IO.Path.Combine(basePath, DisplayName), stream); return(true); } catch (Exception) { return(false); } }
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 AddToFileSystem(IFsiDirectoryItem rootItem) { try { IStream stream = null; SHCreateStreamOnFile(filePath, STGM_READ | STGM_SHARE_DENY_WRITE, ref stream); if (stream != null) { rootItem.AddFile(displayName, stream); return(true); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error adding file", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(false); }
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 CreateFSIFolder(DirectoryInfo fsobject, IFsiDirectoryItem diritem) { if (fsobject == null || diritem == null || _cancel) { return; } DirectoryInfo pysicalFolder = null; pysicalFolder = new DirectoryInfo(UniqueListFileSystemInfo.GetPhysicalPath(fsobject.FullName.TrimEnd('\\'))); IFsiDirectoryItem crtdiritem = null; if (diritem.FullPath.Length == 0) { try { var newpath = string.Format("{0}\\{1}", diritem.FullPath, pysicalFolder.Name); if (_sysImage.Exists(newpath) != FsiItemType.FsiItemDirectory) { diritem.AddDirectory(pysicalFolder.Name); } } catch { } crtdiritem = diritem[pysicalFolder.Name] as IFsiDirectoryItem; } else { crtdiritem = diritem; } var files = pysicalFolder.GetFiles("*"); //all files foreach (var file in files) { if (_cancel) { return; } CreateFSIFile(file, crtdiritem); } DirectoryInfo[] folders = null; folders = pysicalFolder.GetDirectories("*"); if (folders != null && folders.Length > 0) { foreach (var folder in folders) { if (_cancel) { return; } try { var newpath = string.Format("{0}\\{1}", crtdiritem.FullPath, folder.Name); if (_sysImage.Exists(newpath) != FsiItemType.FsiItemDirectory) { crtdiritem.AddDirectory(folder.Name); } } catch { Cancel = true; throw; } var subdir = crtdiritem[folder.Name] as IFsiDirectoryItem; CreateFSIFolder(folder, subdir); } } }
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 CreateFSIFile(FileInfo file, IFsiDirectoryItem diritem) { var realpath = UniqueListFileSystemInfo.GetPhysicalPath(file.FullName); var index = realpath.IndexOf(":\\") + 1; if (_sysImage.Exists(realpath.Substring(index)) == FsiItemType.FsiItemNotFound) { var crtdiritem = diritem; var name = Path.GetFileName(realpath); if (string.Compare(diritem.FullPath, Path.GetDirectoryName(realpath).Substring(index), true) != 0) { var fsipath = Path.GetDirectoryName(realpath).Substring(index + 1 + diritem.FullPath.Length); var dirs = fsipath.Split('\\'); var dInfo = new DirectoryInfo(CaptureDirectory); var subdirs = dInfo.FullName.Split('\\'); //MessageBox.Show(subdirs.Length.ToString()); //create the subdirs one by one foreach (var dir in dirs.Skip(subdirs.Length - 1)) { if (dir.Length == 0) { continue; //in the root like C:\ } try { var newpath = string.Format("{0}\\{1}", crtdiritem.FullPath, dir); if (_sysImage.Exists(newpath) != FsiItemType.FsiItemDirectory) { crtdiritem.AddDirectory(dir); } } catch { Cancel = true; throw; } crtdiritem = crtdiritem[dir] as IFsiDirectoryItem; } } COMTypes.IStream newStream = null; try { newStream = LoadCOMStream(realpath); crtdiritem.AddFile(name, newStream); } finally { Marshal.FinalReleaseComObject(newStream); } ActualSize += file.Length; if (Update != null && Update.GetInvocationList().Length > 0) { Update(file.FullName, file.Length); } } else { throw new ApplicationException(realpath.Substring(index) + " occurs in multiple source folders with the same name."); } }
public bool AddToFileSystem(IFsiDirectoryItem rootItem) { IStream stream = null; try { Win32.SHCreateStreamOnFile(filePath, Win32.STGM_READ | Win32.STGM_SHARE_DENY_WRITE, ref stream); if (stream != null) { rootItem.AddFile(displayName, stream); return true; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error adding file", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (stream != null) { Marshal.FinalReleaseComObject(stream); } } return false; }
/// <summary> /// add item to burn data tree /// </summary> /// <param name="rootItem"></param> /// <returns></returns> public bool AddToFileSystem(IFsiDirectoryItem rootItem) { IStream stream = null; try { Win32.SHCreateStreamOnFile(filePath, Win32.STGM_READ | Win32.STGM_SHARE_DENY_WRITE, ref stream); if (stream != null) { rootItem.AddFile(_displayName, stream); return true; } } catch (Exception ex) { throw new global::System.InvalidOperationException("Error adding to FileSystem" + ex.Message); } finally { if (stream != null) { Marshal.FinalReleaseComObject(stream); } } return false; }
/// <summary> /// add item to burn data tree /// </summary> /// <param name="rootItem"></param> /// <param name="isBurnDirectoryExist"></param> /// <returns></returns> public bool AddToFileSystem(IFsiDirectoryItem rootItem) { try { var filename = System.IO.Path.GetFileName(_mDirectoryPath); IFsiItem item; try { item = (IFsiItem)rootItem["\\" + filename]; } catch (Exception) { item = null; } if (item != null) { IFsiDirectoryItem dirItem = item as IFsiDirectoryItem; foreach (var mediaItem in _mediaItems) { mediaItem.AddToFileSystem(dirItem); } } else { rootItem.AddTree(_mDirectoryPath, true); } return true; } catch (Exception ex) { throw new global::System.InvalidOperationException("Error adding to FileSystem" + ex.Message); } }
private void _AddNode(IFsiDirectoryItem root, IMediaNode node) { IStream stream = null; try { if (node is DirectoryNode) { root.AddTree(node.Path, true); } else { Shell.SHCreateStreamOnFile(node.Path, Shell.STGM_READ | Shell.STGM_SHARE_DENY_WRITE, ref stream); if (stream != null) root.AddFile(node.Name, stream); } } finally { if (stream != null) { Marshal.FinalReleaseComObject(stream); } } }
public bool AddToFileSystem(IFsiDirectoryItem rootItem) { try { rootItem.AddTree(m_directoryPath, true); return true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error adding folder", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } }
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); }