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

Bud*_*Joe 5 .net c# dvd iso9660

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

Mic*_*out 5

这里还有更多尝试


mdb*_*mdb 5

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
}
Run Code Online (Sandbox Code Playgroud)

可以在pinvoke.net上找到有关Win32/COM API粘合剂的详细信息:SHCreateStreamOnFile.IStream和STATSTG位于System.Runtime.InteropServices.ComTypes中..