public void Create(string filename) //ToDo(DZ): Is this enough implementation for the memory-only version? { erf = new Cabinet.ERF(); ccab = Cabinet.CCAB.Create(); ccab.cb = int.MaxValue; ccab.cbFolderThresh = int.MaxValue; ccab.setID = ++seq; Array.Copy("".ToCharArray(), ccab.szCabPath, "".Length); Array.Copy(filename.ToCharArray(), ccab.szCab, filename.Length); handle = Cabinet.FCICreate( ref erf, FciFilePlacedDelegate, FciAllocDelegate, FciFreeDelegate, FciOpenDelegate, FciReadDelegate, FciWriteDelegate, FciCloseDelegate, FciSeekDelegate, FciDeleteDelegate, FciGetTempFileDelegate, ref ccab, IntPtr.Zero); if (handle == -1) { throw new Exception("Failed to create cabinet: " + filename); } }
/// <summary> /// Creates and initializes the CAB file compressor. /// </summary> /// <param name="folder">Where to place the created CAB file. If null, current working directory is used.</param> /// <param name="filename">The name of the CAB file including extension, but without path information.</param> public void Create(string folder, string filename) { erf = new Cabinet.ERF(); ccab = Cabinet.CCAB.Create(); ccab.cb = int.MaxValue; ccab.cbFolderThresh = int.MaxValue; ccab.setID = ++seq; // If folder is null, use the current working folder. if (folder == null) { folder = Directory.GetCurrentDirectory(); } folder = Path.GetFullPath(folder); // Ensure the folder path ends with a backslash if (!folder.EndsWith("" + Cabinet.DirectorySeparatorChar)) { folder += Cabinet.DirectorySeparatorChar; } Array.Copy(folder.ToCharArray(), ccab.szCabPath, folder.Length); Array.Copy(filename.ToCharArray(), ccab.szCab, filename.Length); handle = Cabinet.FCICreate( ref erf, FciFilePlacedDelegate, FciAllocDelegate, FciFreeDelegate, FciOpenDelegate, FciReadDelegate, FciWriteDelegate, FciCloseDelegate, FciSeekDelegate, FciDeleteDelegate, FciGetTempFileDelegate, ref ccab, IntPtr.Zero); if (handle == -1) { throw new Exception("Failed to create cabinet: " + filename); } }