Exemple #1
0
 /// <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
                    );
 }
Exemple #2
0
        public static void Create(CabinetNameHandler nameHandler, object nameContext, long maxCabSize, long maxFolderSize,
                                  CabinetOpenCabHandler openCabHandler, CabinetCloseCabHandler closeCabHandler, object openCabContext,
                                  string[][] foldersAndFiles, CabinetCompressionLevel compLevel, CabinetCreateOpenFileHandler openFileHandler,
                                  CabinetCreateCloseFileHandler closeFileHandler, object openFileContext,
                                  CabinetStatusCallback statusCallback, object statusContext)
        #endif // !CABMINIMAL
        {
            using (CabCreator cabInstance = new CabCreator(maxCabSize, maxFolderSize))
            {
                cabInstance.nameHandler      = nameHandler;
                cabInstance.nameContext      = nameContext;
                cabInstance.openCabHandler   = openCabHandler;
                cabInstance.closeCabHandler  = closeCabHandler;
                cabInstance.openCabContext   = openCabContext;
                cabInstance.openFileHandler  = openFileHandler;
                cabInstance.closeFileHandler = closeFileHandler;
                cabInstance.openFileContext  = openFileContext;

                        #if !CABMINIMAL
                cabInstance.statusCallback = statusCallback;
                cabInstance.statusContext  = statusContext;

                if (cabInstance.statusCallback != null)
                {
                    cabInstance.status.totalFolders = (short)foldersAndFiles.Length;
                    for (int iFolder = 0; iFolder < foldersAndFiles.Length; iFolder++)
                    {
                        string[] files = foldersAndFiles[iFolder];
                        for (int iFile = 0; iFile < files.Length; iFile++)
                        {
                            FileAttributes attributes;
                            DateTime       lastWriteTime;
                            Stream         fileStream = openFileHandler(files[iFile], out attributes, out lastWriteTime, openFileContext);
                            if (fileStream != null)
                            {
                                cabInstance.status.totalFileBytes += fileStream.Length;
                                cabInstance.status.totalFiles++;
                            }
                            closeFileHandler(files[iFile], fileStream, openFileContext);
                        }
                    }
                }
                        #endif // !CABMINIMAL

                for (int iFolder = 0; iFolder < foldersAndFiles.Length; iFolder++)
                {
                    string[] files = foldersAndFiles[iFolder];
                    for (int iFile = 0; iFile < files.Length; iFile++)
                    {
                        FileAttributes attributes;
                        DateTime       lastWriteTime;
                        Stream         fileStream = openFileHandler(files[iFile], out attributes, out lastWriteTime, openFileContext);
                        if (fileStream != null)
                        {
                                                #if !CABMINIMAL
                            if (cabInstance.statusCallback != null)
                            {
                                if (cabInstance.status.currentFolderTotalBytes > 0)
                                {
                                    cabInstance.status.currentFolderBytesProcessed = cabInstance.status.currentFolderTotalBytes;
                                    cabInstance.status.statusType = CabinetStatusType.FinishFolder;
                                    cabInstance.statusCallback(cabInstance.status, cabInstance.statusContext);
                                    cabInstance.status.currentFolderBytesProcessed = cabInstance.status.currentFolderTotalBytes = 0;

                                    if (!(iFolder == 0 && iFile == 0))
                                    {
                                        cabInstance.status.currentFolderNumber++;
                                        if (cabInstance.status.totalFolders <= cabInstance.status.currentFolderNumber)
                                        {
                                            cabInstance.status.totalFolders = (short)(cabInstance.status.currentFolderNumber + 1);
                                        }
                                    }
                                }
                            }
                                                #endif // !CABMINIMAL
                            cabInstance.status.currentFileName = files[iFile];
                            if (!(iFolder == 0 && iFile == 0))
                            {
                                cabInstance.status.currentFileNumber++;
                            }
                                                #if !CABMINIMAL
                            if (cabInstance.statusCallback != null)
                            {
                                cabInstance.status.currentFileTotalBytes     = fileStream.Length;
                                cabInstance.status.currentFileBytesProcessed = 0;
                                cabInstance.status.statusType = CabinetStatusType.StartFile;
                                cabInstance.statusCallback(cabInstance.status, cabInstance.statusContext);
                            }
                                                #endif // !CABMINIMAL

                            cabInstance.AddFile(files[iFile], fileStream, attributes, lastWriteTime, false, compLevel);
                        }
                    }
                    cabInstance.FlushFolder();
                }
                cabInstance.FlushCabinet();
            }
        }
Exemple #3
0
 public static void Create(CabinetNameHandler nameHandler, object nameContext, long maxCabSize, long maxFolderSize,
                           CabinetOpenCabHandler openCabHandler, CabinetCloseCabHandler closeCabHandler, object openCabContext,
                           string[][] foldersAndFiles, CabinetCompressionLevel compLevel, CabinetCreateOpenFileHandler openFileHandler,
                           CabinetCreateCloseFileHandler closeFileHandler, object openFileContext)
Exemple #4
0
 /// <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>
 /// <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)