【发布时间】:2018-05-18 07:07:15
【问题描述】:
首先,对术语进行一些澄清。 finalize,我不是指结束会话;我的意思是,将信息写入 CD 或 DVD 的方式使信息无法再通过通常的方式(Roxio、Nero、Windows Explorer 等)添加到其中。
我已经对此进行了大量研究。有一些像InfraRecorder 这样的开源程序,我们可以从中汲取一些灵感,但它们似乎都涉及到相当复杂的大量使用 IMAPI 的 C++ 代码,这似乎是一种非常低级的处理方式。我们团队中的开发人员都没有 C++ 或 IMAPI 专业知识来支持这样的代码库。
互联网上最有前途的资源似乎是this one,但它似乎不包含finalize 函数。这是“写图像”的代码:
public void WriteImage(BurnVerificationLevel verification, bool finalize, bool eject)
{
if (!_recorderLoaded)
throw new InvalidOperationException("LoadMedia must be called first.");
MsftDiscRecorder2 recorder = null;
MsftDiscFormat2Data discFormatData = null;
try
{
recorder = new MsftDiscRecorder2();
recorder.InitializeDiscRecorder(_recorders.SelectedItem.InternalUniqueId);
discFormatData = new MsftDiscFormat2Data
{
Recorder = recorder,
ClientName = ClientName,
ForceMediaToBeClosed = finalize
};
//
// Set the verification level
//
var burnVerification = (IBurnVerification)discFormatData;
burnVerification.BurnVerificationLevel = IMAPI_BURN_VERIFICATION_LEVEL.IMAPI_BURN_VERIFICATION_NONE;
//
// Check if media is blank, (for RW media)
//
object[] multisessionInterfaces = null;
if (!discFormatData.MediaHeuristicallyBlank)
multisessionInterfaces = discFormatData.MultisessionInterfaces;
//
// Create the file system
//
IStream fileSystem;
_CreateImage(recorder, multisessionInterfaces, out fileSystem);
discFormatData.Update += _discFormatWrite_Update;
//
// Write the data
//
try
{
discFormatData.Write(fileSystem);
}
finally
{
if (fileSystem != null) Marshal.FinalReleaseComObject(fileSystem);
}
discFormatData.Update -= _discFormatWrite_Update;
if (eject) recorder.EjectMedia();
}
finally
{
_isWriting = false;
if (discFormatData != null) Marshal.ReleaseComObject(discFormatData);
if (recorder != null) Marshal.ReleaseComObject(recorder);
}
}
代码的关键部分似乎是这个:
discFormatData = new MsftDiscFormat2Data
{
Recorder = recorder,
ClientName = ClientName,
ForceMediaToBeClosed = finalize // <-- Here
};
但这不是一个终结函数;它是将实际数据刻录到磁盘上的功能。您是否必须实际创建一个新会话才能在现有磁盘上执行终结?
【问题讨论】:
-
前段时间遇到了相反的问题,无法避免敲定。弹射媒体,总是引起引出。 SourceForge 的这个项目帮助了BwgBurn。有一个带有源代码 (c#) 的 zip 文件。希望对您有所帮助。
-
会话关闭称为导出。你想要的是在多会话媒体上写一个“磁盘导出”(或最终会话关闭),对吗?您实际上是否尝试过使用 IMAPI 的 ForceMediaToBeClosed 和 DisableConsumerDvdCompatibility? PS:MM 命令和术语在这里可用:13thmonkey.org/documentation/SCSI/mmc6r02g.pdf
-
@SimonMourier:我不是 IMAPI2 API 方面的专家,而且我尽量不要成为专家。我确实看到需要几个月的工作才能胜任该 API,而我没有几个月的时间来编写单个
FinalizeDisk()函数。您链接的那份工作草稿长达七百多页。 -
但是您是否尝试过使用这两个 IMAPI 属性(又名:您有问题吗?或者?)
-
@SimonMourier:属性不是问题(除了我对它们的无知)。问题是,我有限的知识让我理解它,你不能简单地完成磁盘。 Finalize 不是操作;这是一面旗帜。因此,我认为需要使用此标志集创建一个新会话。但是因为我从来没有真正在代码中这样做过......
标签: c# powershell imapi