/// <summary> /// Compresses files into the cabinet file, specifying the names used to store the files in the cabinet. /// </summary> /// <param name="sourceDirectory">This parameter may be null, but if specified it is the root directory /// for any relative paths in <paramref name="sourceFileNames"/>.</param> /// <param name="sourceFileNames">The list of files to be included in the cabinet.</param> /// <param name="fileNames">The names of the files as they are stored in the cabinet. Each name /// includes the internal path of the file, if any. This parameter may be null, in which case the /// files are stored in the cabinet with their source file names and no path information.</param> /// <param name="compLevel">The compression level used when creating the cabinet.</param> /// <param name="callback">Handler for receiving progress information; this may be null if progress is not desired.</param> /// <param name="context">User context object passed to the <paramref name="callback"/>, may be null.</param> /// <remarks> /// Duplicate items in the <paramref name="fileNames"/> array will cause a <see cref="CabinetCreateException"/>. /// </remarks> internal virtual void CompressFiles(string sourceDirectory, string[] sourceFileNames, string[] fileNames, CabinetCompressionLevel compLevel, CabinetStatusCallback callback, object context) { if (sourceFileNames == null) { if (sourceDirectory == null) { throw new ArgumentNullException("sourceDirectory", "Either sourceDirectory or sourceFileNames must be non-null."); } sourceFileNames = System.IO.Directory.GetFiles(sourceDirectory); } if (fileNames == null) { fileNames = new string[sourceFileNames.Length]; for (int i = 0; i < sourceFileNames.Length; i++) { fileNames[i] = Path.GetFileName(sourceFileNames[i]); } } using (Stream stream = this.GetCabinetWriteStream()) { Cabinet.Create(stream, fileNames, compLevel, new CabinetCreateOpenFileHandler(CabinetInfo.CreateOpenFileHandler), new CabinetCreateCloseFileHandler(CabinetInfo.CreateCloseFileHandler), new object[] { sourceDirectory, CreateStringDictionary(fileNames, sourceFileNames) }, callback, context); } }
/// <summary> /// Creates a cabinet and writes it to a stream. /// </summary> /// <param name="stream">The stream for writing the cabinet.</param> /// <param name="files">The names of the files in the cabinet (not external file paths).</param> /// <param name="compLevel">The cabinet compression level.</param> /// <param name="openFileHandler">Callback for opening streams for reading included files.</param> /// <param name="closeFileHandler">Callback for closing included file streams. This may be null, in which /// case the stream's <see cref="Stream.Close"/> method will be called.</param> /// <param name="openFileContext">User context object that will be passed to the /// <paramref name="openFileHandler"/> and <paramref name="closeFileHandler"/>.</param> /// <param name="statusCallback">Callback for reporting creation progress. This may be null /// if status is not desired.</param> /// <param name="statusContext">User context object passed to the <paramref name="statusCallback"/>.</param> /// <exception cref="CabinetCreateException">The cabinet could not be created.</exception> public static void Create(Stream stream, string[] files, CabinetCompressionLevel compLevel, CabinetCreateOpenFileHandler openFileHandler, CabinetCreateCloseFileHandler closeFileHandler, object openFileContext, CabinetStatusCallback statusCallback, object statusContext) #endif // !CABMINIMAL { if (stream == null) { throw new ArgumentNullException("stream"); } Cabinet.Create(null, null, 0, 0, new CabinetOpenCabHandler(Cabinet.DefaultOpenCabHandler), new CabinetCloseCabHandler(Cabinet.DefaultCloseCabHandler), stream, new string[][] { files }, compLevel, openFileHandler, closeFileHandler, openFileContext #if !CABMINIMAL , statusCallback, statusContext #endif // !CABMINIMAL ); }
/// <summary> /// Compresses files into the cabinet file, specifying the names used to store the files in the cabinet. /// </summary> /// <param name="sourceDirectory">This parameter may be null, but if specified it is the root directory /// for any relative paths in <paramref name="filenameMap"/>.</param> /// <param name="filenameMap">A mapping from internal file paths to external file paths.</param> /// <param name="compLevel">The compression level used when creating the cabinet.</param> /// <param name="callback">Handler for receiving progress information; this may be null if progress is not desired.</param> /// <param name="context">User context object passed to the <paramref name="callback"/>, may be null.</param> internal virtual void CompressFileSet(string sourceDirectory, IDictionary filenameMap, CabinetCompressionLevel compLevel, CabinetStatusCallback callback, object context) { if (filenameMap == null) { throw new ArgumentNullException("filenameMap"); } string[] fileNames = new string[filenameMap.Count]; filenameMap.Keys.CopyTo(fileNames, 0); using (Stream stream = this.GetCabinetWriteStream()) { Cabinet.Create(stream, fileNames, compLevel, new CabinetCreateOpenFileHandler(CabinetInfo.CreateOpenFileHandler), new CabinetCreateCloseFileHandler(CabinetInfo.CreateCloseFileHandler), new object[] { sourceDirectory, filenameMap }, callback, context); } }