IMAPI:如果图像大小超出可用空间,如何在不引发异常的情况下获取图像大小? [英] IMAPI: How to get image size without throwing exception if image size exceeds free space?

查看:185
本文介绍了IMAPI:如果图像大小超出可用空间,如何在不引发异常的情况下获取图像大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写代码以使用IMAPI(C#.NET)写入媒体(CD/DVD). 写作一切正常. 如果我尝试添加超出媒体可用空间的文件,则会引发异常. 我可以捕捉到异常,但是它没有达到我的目的. 我想添加文件,即使它超出了可用空间. 然后,我想将图像的总大小返回给用户,然后该用户将根据需要执行必要的操作(更新UI,显示消息,在UI上显示图像大小等). 换句话说,即使它超出了可用空间,我也希望获得总图像大小. 我可以看到很多媒体刻录应用程序正在执行此操作.所以这必须是可能的.

I am writing a code to write a media (CD/DVD) using IMAPI (C#.NET). The writing works all fine. In case when I try to add file which exceeds the free space on media, it throws exception. I can catch the exception but it does not serve my purpose. I want to go adding the files even though it exceeds the free space. Then, I want to return total size of image to user who will then do the needful (update UI, show message, show size of image on UI etc.) as per requirements. In other words, I want to get total image size even though it exceeds the free space. I can see lot many media burning applications are doing this; so this must be possible.

下面的代码行引发异常:-

Following line in code throws exception: -

fileSystemImage.Root.AddFile(thisFileItem.DestPath + thisFileItem.DisplayName, stream);

以下是异常详细信息:-

Following are the exception details: -

ComException

ComException

ErrorCode:-1062555360

ErrorCode: -1062555360

消息:添加"myfilename"将导致结果图像的大小大于当前配置的限制.

Message: Adding 'myfilename' would result in a result image having a size larger than the current configured limit.

以下是我的代码:-

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;

推荐答案

不是解决方案,但我得到了帮助.

Not a solution, but i got the hack.

fileSystemImage.FreeMediaBlocks = int.MaxValue;

这将允许创建任何大小的图像(最大整数限制),而与插入的媒体上的空闲块无关.然后,您可以按照自己的方式实施验证.

This will allow to create image of any size (upto integer limit) irrespective of free blocks on media inserted. You can then implement validations in your own way.

这篇关于IMAPI:如果图像大小超出可用空间,如何在不引发异常的情况下获取图像大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆