/// <summary> /// Adds a file to the CAB. /// </summary> /// <param name="storedPath">The relative path where the file will be extracted by the decompressor. /// If null, this path is derived from the path information in the next parameter.</param> /// <param name="fullPathAndFilename">The full path to the file being added.</param> /// <param name="compress">Whether or not to compress the file data.</param> public void AddFile(string storedPath, string fullPathAndFilename, string filenameOverride, bool compress) { fullPathAndFilename = Path.GetFullPath(fullPathAndFilename); // If stored path is null, generate it from the file being added. if (storedPath == null) { storedPath = Path.GetDirectoryName(fullPathAndFilename); string drive = Path.GetPathRoot(storedPath); if (storedPath.StartsWith(drive)) { storedPath = storedPath.Substring(drive.Length); } } // Make sure it ends with a backslash if (!storedPath.EndsWith("" + Cabinet.DirectorySeparatorChar)) { storedPath = storedPath + Cabinet.DirectorySeparatorChar; } // Make sure it doesn't start with a backslash if (storedPath.StartsWith("" + Cabinet.DirectorySeparatorChar)) { storedPath = storedPath.Substring(1); } // Build the stored filename with path. string filenameInCab; if (filenameOverride == null) { filenameInCab = storedPath + Path.GetFileName(fullPathAndFilename); } else { filenameInCab = storedPath + Path.GetFileName(filenameOverride); } ushort compressionType = compress ? (ushort)Cabinet.tcompTYPE_MSZIP : (ushort)Cabinet.tcompTYPE_NONE; bool result = Cabinet.FCIAddFile( handle, fullPathAndFilename, filenameInCab, 0, FciGetNextCabinetDelegate, FciStatusDelegate, FciGetOpenInfoDelegate, compressionType); if (!result) { throw new Exception("Failed to add file to cabinet: " + fullPathAndFilename); } }
public void AddFile(string storedPath, string filename, bool compress) //ToDo(DZ): Is this enough implementation for the memory-only version? { ushort compressionType = compress ? (ushort)Cabinet.tcompTYPE_MSZIP : (ushort)Cabinet.tcompTYPE_NONE; bool result = Cabinet.FCIAddFile( handle, filename, storedPath, 0, FciGetNextCabinetDelegate, FciStatusDelegate, FciGetOpenInfoDelegate, compressionType); if (!result) { throw new Exception("Failed to add file to cabinet: " + filename); } }