C# IMAPI:如果图像大小超过可用空间,如何获得图像大小而不引发异常?
我正在编写一个代码,用IMAPI(C#NET)编写媒体(CD/DVD)。 这篇文章写得很好。 如果我试图添加的文件超过了媒体上的可用空间,它会抛出异常。 我能抓住这个例外,但它不符合我的目的。 我想添加文件,即使它超出了可用空间。 然后,我想将图像的总大小返回给用户,用户将根据需要执行所需操作(更新UI、显示消息、在UI上显示图像大小等)。 换句话说,我想得到总的图像大小,即使它超过了可用空间。 我可以看到很多媒体刻录应用程序都在这样做;所以这一定是可能的 代码中的以下行引发异常:-C# IMAPI:如果图像大小超过可用空间,如何获得图像大小而不引发异常?,c#,imapi,C#,Imapi,我正在编写一个代码,用IMAPI(C#NET)编写媒体(CD/DVD)。 这篇文章写得很好。 如果我试图添加的文件超过了媒体上的可用空间,它会抛出异常。 我能抓住这个例外,但它不符合我的目的。 我想添加文件,即使它超出了可用空间。 然后,我想将图像的总大小返回给用户,用户将根据需要执行所需操作(更新UI、显示消息、在UI上显示图像大小等)。 换句话说,我想得到总的图像大小,即使它超过了可用空间。 我可以看到很多媒体刻录应用程序都在这样做;所以这一定是可能的 代码中的以下行引发异常:- fileS
fileSystemImage.Root.AddFile(thisFileItem.DestPath + thisFileItem.DisplayName, stream);
以下是例外情况的详细信息:-
例外情况
错误代码:-1062555360
消息:添加“myfilename”将导致结果图像的大小大于当前配置的限制
以下是我的代码:-
MsftDiscFormat2Data discFormatData = null;
MsftDiscRecorder2 discRecorder = null;
MsftFileSystemImage fileSystemImage = null;
discRecorder = new MsftDiscRecorder2();
discRecorder.InitializeDiscRecorder(UniqueRecorderId);
discFormatData = new MsftDiscFormat2Data
{
Recorder = discRecorder,
ClientName = CLIENT_NAME,
ForceMediaToBeClosed = _closeSession
};
fileSystemImage = new MsftFileSystemImage();
fileSystemImage.VolumeName = _volumeID;
fileSystemImage.Update += fileSystemImage_Update;
fileSystemImage.ChooseImageDefaults(discRecorder);
fileSystemImage.FileSystemsToCreate = FsiFileSystems.FsiFileSystemJoliet | FsiFileSystems.FsiFileSystemISO9660 | FsiFileSystems.FsiFileSystemUDF;
if(!discFormatData.MediaHeuristicallyBlank)
{
fileSystemImage.MultisessionInterfaces = discFormatData.MultisessionInterfaces;
fileSystemImage.ImportFileSystem();
}
foreach(FileItem thisFileItem in listFileItem)
{
IStream stream = null;
if(thisFileItem.SourcePath != null)
Win32.SHCreateStreamOnFile(thisFileItem.SourcePath, Win32.STGM_READ | Win32.STGM_SHARE_DENY_WRITE, ref stream);
fileSystemImage.Root.AddFile(thisFileItem.DestPath + thisFileItem.DisplayName, stream);
}
IFileSystemImageResult objIFileSystemImageResult;
objIFileSystemImageResult = fileSystemImage.CreateResultImage();
_imageSize = (objIFileSystemImageResult.TotalBlocks * objIFileSystemImageResult.BlockSize);
IStream imageStream = objIFileSystemImageResult.ImageStream;
fileSystemImage.Update -= fileSystemImage_Update;
这不是一个解决办法,但我被黑了
fileSystemImage.FreeMediaBlocks = int.MaxValue;
这将允许创建任意大小(不超过整数限制)的图像,而不考虑插入的介质上的空闲块。然后,您可以用自己的方式实现验证。这就是IMAPI\u E\u IMAGE\u SIZE\u LIMIT。这只意味着一件事,你达到了尺寸限制。它怎么可能不起作用呢?没有TryAdd()方法,它只能勉强应付。@HansPassant:同意;但有许多媒体刻录应用程序显示总图像大小,即使大小超过可用空间。我想返回总图像大小,而不考虑可用空间。