DVD ISO from C# - .NET DiscUtils alternatives

女生的网名这么多〃 提交于 2019-12-01 03:13:46

问题


What is the best way to make .ISO files based on a file folder structure from C#? Is there an open source library other than DiscUtils? Running into issues with DiscUtils and I'd like try another path. What are my options? I'd prefer open source but might also be willing to pay for a solution.


回答1:


Windows actually comes with a native API for creating ISOs and much more: the 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.

Unfortunately, you also need a few paragraphs to properly clean up the COM nonsense involved, but the end result is still pretty manageable:

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. IStream and STATSTG are in System.Runtime.InteropServices.ComTypes..




回答2:


Here are some more to try

  • C# [ISO] image creator (no support for audio CDs)
  • IsoCreator



回答3:


You could try Primo Burner: http://www.primoburner.com/Downloads.aspx



来源:https://stackoverflow.com/questions/9685894/dvd-iso-from-c-sharp-net-discutils-alternatives

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!