来自C#的DVD ISO – .NET DiscUtils替代品

基于C#的文件夹结构制作.ISO文件的最佳方法是什么? 是否有DiscUtils以外的开源库? 遇到DiscUtils的问题,我想尝试另一条路径。 我有什么选择? 我更喜欢开源但可能也愿意为解决方案买单。

Windows实际上带有用于创建ISO的本机API以及更多: Image Mastering API 。 一旦从Windows SDK中获取IMAPI2 Interop程序集,或者(可能更容易)从此CodeProject文章中获取有关IMAPI2的文章 ,创建ISO只需几行代码。

不幸的是,你还需要一些段落来正确清理所涉及的COM废话,但最终的结果仍然是可管理的:

MsftFileSystemImage iso = new MsftFileSystemImage(); iso.ChooseImageDefaultsForMediaType(IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DISK); iso.FileSystemsToCreate = FsiFileSystems.FsiFileSystemISO9660 | FsiFileSystems.FsiFileSystemJoliet; iso.Root.AddTree(@"c:\path\goes\here\", false); dynamic resultImage = iso.CreateResultImage(); dynamic imageStream = resultImage.ImageStream; IStream newStream = null; if (imageStream != null) { STATSTG stat = null; imageStream.Stat(stat, 0x1); int res = SHCreateStreamOnFile(@"c:\path\to\your.iso", 0x1001, newStream); if (res == 0 && 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); } finally { Marshal.FinalReleaseComObject(imageStream); newStream.Commit(0); Marshal.FinalReleaseComObject(newStream); Marshal.FreeHGlobal(inBytes); Marshal.FreeHGlobal(outBytes); Marshal.FinalReleaseComObject(resultImage); Marshal.FinalReleaseComObject(iso); } } else { Marshal.FinalReleaseComObject(imageStream); Marshal.FinalReleaseComObject(resultImage); Marshal.FinalReleaseComObject(iso); //TODO: Throw exception or do whatever to signal failure here } } else { Marshal.FinalReleaseComObject(resultImage); Marshal.FinalReleaseComObject(iso); //TODO: Throw exception or do whatever to signal failure here } 

有关Win32 / COM API胶水的详细信息,请访问pinvoke.net:SHCreateStreamOnFile。 IStream和STATSTG位于System.Runtime.InteropServices.ComTypes中。 。

以下是一些尝试

  • C#[ISO]图像创建者 ( 不支持音频CD
  • IsoCreator

您可以尝试Primo Burner: http : //www.primoburner.com/Downloads.aspx