1

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

ErrorCode: -1062555360

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

Following is my code: -

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;
Community
  • 1
  • 1
Amit Joshi
  • 15,448
  • 21
  • 77
  • 141
  • That is IMAPI_E_IMAGE_SIZE_LIMIT. It means only one thing, you hit the size limit. How could it possibly not serve a purpose? There is no TryAdd() method, it will have to make do. – Hans Passant May 14 '16 at 11:06
  • @HansPassant: Agreed; but there are many media burning applications those show total image size even if the size exceeds free space. I want to return total image size irrespective of free space available. – Amit Joshi May 14 '16 at 11:55

1 Answers1

2

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.

Amit Joshi
  • 15,448
  • 21
  • 77
  • 141