5

C# のファイル フォルダー構造に基づいて.ISO ファイルを作成する最良の方法は何ですか? DiscUtils以外のオープン ソース ライブラリはありますか? DiscUtilsで問題が発生しました。別の方法を試してみたいと思います。私のオプションは何ですか?私はオープンソースを好みますが、解決策に喜んでお金を払うかもしれません.

4

3 に答える 3

5

Windowsには、実際にはISOなどを作成するためのネイティブAPIであるImageMasteringAPIが付属しています。WindowsSDKからIMAPI2Interopアセンブリを取得するか、IMAPI2に関するこのCodeProjectの記事から(おそらく簡単に)取得すると、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にあります。

于 2012-03-26T20:44:10.600 に答える
5

ここにいくつか試してみてください

于 2012-03-13T14:31:49.617 に答える
2

Primo Burner を試すことができます: http://www.primoburner.com/Downloads.aspx

于 2012-03-26T10:24:25.877 に答える