I have copied a program that writes an ISO file using the IMAPI. It seems to truncate directory names. For example, if I call this function:
image.Root.AddTree("C:\\DIR\\SUBDIR", true);
What I get in the ISO is:
SUBDIR\file 1
SUBDIR\file 2
...
The "DIR" part is dropped.
What I want is:
DIR\SUBDIR\file 1
DIR\SUBDIR\file 2
...
I have seen Create a folder in disk and Burn Into it using IMAPI 2, one of the replies suggests using
rootItem.AddDirectory(directoryName);
rootItem.get_Item(directoryName, newDirItem);
but get_Item
causes a compilation error "cannot explicitly call operator or accessor"
Any suggestions on how to explicitly create directories (and write to them) in the ISO file?
Here is the code. Add IMAPI2 and IMAPI2FS to the References.
using System;
using System.IO;
using System.Runtime.InteropServices;
using IMAPI2FS; // COM reference: Microsoft IMAPI2 File System Image Creator
using IStream = System.Runtime.InteropServices.ComTypes.IStream;
using STATSTG = System.Runtime.InteropServices.ComTypes.STATSTG;
namespace CreateISO
{
class IsoImage
{
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode, PreserveSig = true)]
static extern void SHCreateStreamOnFile(string pszFile, uint grfMode, out IStream ppstm);
public void CreateISO(string path)
{
var image = (IFileSystemImage)new MsftFileSystemImage(); // same as Activator.CreateInstance(Type.GetTypeFromProgID("IMAPI2FS.MsftFileSystemImage"))
image.ChooseImageDefaultsForMediaType(IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DISK);
image.FileSystemsToCreate = FsiFileSystems.FsiFileSystemJoliet | FsiFileSystems.FsiFileSystemISO9660;
image.VolumeName = Path.GetDirectoryName(path);
image.Root.AddTree(path, true);
var inStream = (IStream)image.CreateResultImage().ImageStream;
STATSTG stat;
inStream.Stat(out stat, 0x01);
IStream outStream;
SHCreateStreamOnFile("C:\\temp\\demo.iso", 0x00001001, out outStream);
unsafe
{
long inBytes;
long outBytes;
long* pin = &inBytes;
long* pout = &outBytes;
inStream.CopyTo(outStream, stat.cbSize, (IntPtr)pin, (IntPtr)pout);
outStream.Commit(0);
}
}
}
}