简体   繁体   English

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

[英]DVD ISO from C# - .NET DiscUtils alternatives

What is the best way to make .ISO files based on a file folder structure from C#?根据 C# 的文件夹结构制作.ISO 文件的最佳方法是什么? Is there an open source library other than DiscUtils ?除了DiscUtils之外,还有其他开源库吗? Running into issues with DiscUtils and I'd like try another path.遇到 DiscUtils的问题,我想尝试另一条路径。 What are my options?我有哪些选择? I'd prefer open source but might also be willing to pay for a solution.我更喜欢开源,但也可能愿意为解决方案付费。

Here are some more to try这里还有一些可以尝试

Windows actually comes with a native API for creating ISOs and much more: the Image Mastering API . Windows 实际上带有用于创建 ISO 的原生 API 等等: Image Mastering API Once you grab the IMAPI2 Interop assembly from the Windows SDK or (probably easier) from this CodeProject article about IMAPI2 , creating an ISO is only a few lines of code.一旦您从 Windows SDK 或(可能更容易)从有关 IMAPI2 的 CodeProject 文章中获取 IMAPI2 互操作程序集,创建 ISO 只需几行代码。

Unfortunately, you also need a few paragraphs to properly clean up the COM nonsense involved, but the end result is still pretty manageable:不幸的是,您还需要一些段落来正确清理所涉及的 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
}

Details for the only bit of Win32/COM API glue used can be found on pinvoke.net: SHCreateStreamOnFile .可以在 pinvoke.net 上找到唯一使用的 Win32/COM API 粘合的详细信息: SHCreateStreamOnFile IStream and STATSTG are in System.Runtime.InteropServices.ComTypes. IStream 和 STATSTG 在System.Runtime.InteropServices.ComTypes 中。 . .

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM