123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466 |
- namespace SevenZip
- {
- using System.Collections.Generic;
- using System.IO;
- using System.Threading.Tasks;
- partial class SevenZipCompressor
- {
- #region Delegates
- private delegate void CompressFiles1Delegate(string archiveName, string[] fileFullNames);
- private delegate void CompressFiles2Delegate(Stream archiveStream, string[] fileFullNames);
- private delegate void CompressFiles3Delegate(string archiveName, int commonRootLength, string[] fileFullNames);
- private delegate void CompressFiles4Delegate(Stream archiveStream, int commonRootLength, string[] fileFullNames);
- private delegate void CompressFilesEncrypted1Delegate(string archiveName, string password, string[] fileFullNames);
- private delegate void CompressFilesEncrypted2Delegate(Stream archiveStream, string password, string[] fileFullNames);
- private delegate void CompressFilesEncrypted3Delegate(string archiveName, int commonRootLength, string password, string[] fileFullNames);
- private delegate void CompressFilesEncrypted4Delegate(Stream archiveStream, int commonRootLength, string password, string[] fileFullNames);
- private delegate void CompressDirectoryDelegate(string directory, string archiveName, string password, string searchPattern, bool recursion);
- private delegate void CompressDirectory2Delegate(string directory, Stream archiveStream, string password, string searchPattern, bool recursion);
- private delegate void CompressStreamDelegate(Stream inStream, Stream outStream, string password);
- private delegate void ModifyArchiveDelegate(string archiveName, IDictionary<int, string> newFileNames, string password);
- #endregion
- #region BeginCompressFiles overloads
-
- /// <summary>
- /// Packs files into the archive asynchronously.
- /// </summary>
- /// <param name="fileFullNames">Array of file names to pack.</param>
- /// <param name="archiveName">The archive file name.</param>
- public void BeginCompressFiles(string archiveName, params string[] fileFullNames)
- {
- SaveContext();
- Task.Run(() => new CompressFiles1Delegate(CompressFiles).Invoke(archiveName, fileFullNames))
- .ContinueWith(_ => ReleaseContext());
- }
- /// <summary>
- /// Packs files into the archive asynchronously.
- /// </summary>
- /// <param name="fileFullNames">Array of file names to pack.</param>
- /// <param name="archiveStream">The archive output stream.
- /// Use CompressFiles(string archiveName ... ) overloads for archiving to disk.</param>
- public void BeginCompressFiles(Stream archiveStream, params string[] fileFullNames)
- {
- SaveContext();
- Task.Run(() => new CompressFiles2Delegate(CompressFiles).Invoke(archiveStream, fileFullNames))
- .ContinueWith(_ => ReleaseContext());
- }
- /// <summary>
- /// Packs files into the archive asynchronously.
- /// </summary>
- /// <param name="fileFullNames">Array of file names to pack.</param>
- /// <param name="commonRootLength">The length of the common root of the file names.</param>
- /// <param name="archiveName">The archive file name.</param>
- public void BeginCompressFiles(string archiveName, int commonRootLength, params string[] fileFullNames)
- {
- SaveContext();
- Task.Run(() => new CompressFiles3Delegate(CompressFiles).Invoke(archiveName, commonRootLength, fileFullNames))
- .ContinueWith(_ => ReleaseContext());
- }
- /// <summary>
- /// Packs files into the archive asynchronously.
- /// </summary>
- /// <param name="fileFullNames">Array of file names to pack.</param>
- /// <param name="commonRootLength">The length of the common root of the file names.</param>
- /// <param name="archiveStream">The archive output stream.
- /// Use CompressFiles(string archiveName, ... ) overloads for archiving to disk.</param>
- public void BeginCompressFiles(Stream archiveStream, int commonRootLength, params string[] fileFullNames)
- {
- SaveContext();
- Task.Run(() => new CompressFiles4Delegate(CompressFiles).Invoke(archiveStream, commonRootLength, fileFullNames))
- .ContinueWith(_ => ReleaseContext());
- }
- /// <summary>
- /// Packs files into the archive asynchronously.
- /// </summary>
- /// <param name="fileFullNames">Array of file names to pack.</param>
- /// <param name="archiveName">The archive file name</param>
- /// <param name="password">The archive password.</param>
- public void BeginCompressFilesEncrypted(string archiveName, string password, params string[] fileFullNames )
- {
- SaveContext();
- Task.Run(() => new CompressFilesEncrypted1Delegate(CompressFilesEncrypted).Invoke(archiveName, password, fileFullNames))
- .ContinueWith(_ => ReleaseContext());
- }
- /// <summary>
- /// Packs files into the archive asynchronously.
- /// </summary>
- /// <param name="fileFullNames">Array of file names to pack.</param>
- /// <param name="archiveStream">The archive output stream.
- /// Use CompressFiles( ... string archiveName ... ) overloads for archiving to disk.</param>
- /// <param name="password">The archive password.</param>
- public void BeginCompressFilesEncrypted(Stream archiveStream, string password, params string[] fileFullNames)
- {
- SaveContext();
- Task.Run(() => new CompressFilesEncrypted2Delegate(CompressFilesEncrypted).Invoke(archiveStream, password, fileFullNames))
- .ContinueWith(_ => ReleaseContext());
- }
- /// <summary>
- /// Packs files into the archive asynchronously.
- /// </summary>
- /// <param name="fileFullNames">Array of file names to pack.</param>
- /// <param name="archiveName">The archive file name</param>
- /// <param name="password">The archive password.</param>
- /// <param name="commonRootLength">The length of the common root of the file names.</param>
- public void BeginCompressFilesEncrypted(string archiveName, int commonRootLength, string password, params string[] fileFullNames)
- {
- SaveContext();
- Task.Run(() => new CompressFilesEncrypted3Delegate(CompressFilesEncrypted).Invoke(archiveName, commonRootLength, password, fileFullNames))
- .ContinueWith(_ => ReleaseContext());
- }
- /// <summary>
- /// Packs files into the archive asynchronously.
- /// </summary>
- /// <param name="fileFullNames">Array of file names to pack.</param>
- /// <param name="archiveStream">The archive output stream.
- /// Use CompressFiles( ... string archiveName ... ) overloads for archiving to disk.</param>
- /// <param name="password">The archive password.</param>
- /// <param name="commonRootLength">The length of the common root of the file names.</param>
- public void BeginCompressFilesEncrypted(Stream archiveStream, int commonRootLength, string password, params string[] fileFullNames)
- {
- SaveContext();
- Task.Run(() => new CompressFilesEncrypted4Delegate(CompressFilesEncrypted).Invoke(archiveStream, commonRootLength, password, fileFullNames))
- .ContinueWith(_ => ReleaseContext());
- }
- #endregion
- #region CompressFilesAsync overloads
- /// <summary>
- /// Packs files into the archive asynchronously.
- /// </summary>
- /// <param name="fileFullNames">Array of file names to pack.</param>
- /// <param name="archiveName">The archive file name.</param>
- public async Task CompressFilesAsync(string archiveName, params string[] fileFullNames)
- {
- try
- {
- SaveContext();
- await Task.Run(() => new CompressFiles1Delegate(CompressFiles).Invoke(archiveName, fileFullNames));
- }
- finally
- {
- ReleaseContext();
- }
- }
- /// <summary>
- /// Packs files into the archive asynchronously.
- /// </summary>
- /// <param name="fileFullNames">Array of file names to pack.</param>
- /// <param name="archiveStream">The archive output stream.
- /// Use CompressFiles(string archiveName ... ) overloads for archiving to disk.</param>
- public async Task CompressFilesAsync(Stream archiveStream, params string[] fileFullNames)
- {
- try
- {
- SaveContext();
- await Task.Run(() => new CompressFiles2Delegate(CompressFiles).Invoke(archiveStream, fileFullNames));
- }
- finally
- {
- ReleaseContext();
- }
- }
- /// <summary>
- /// Packs files into the archive asynchronously.
- /// </summary>
- /// <param name="fileFullNames">Array of file names to pack.</param>
- /// <param name="commonRootLength">The length of the common root of the file names.</param>
- /// <param name="archiveName">The archive file name.</param>
- public async Task CompressFilesAsync(string archiveName, int commonRootLength, params string[] fileFullNames)
- {
- try
- {
- SaveContext();
- await Task.Run(() => new CompressFiles3Delegate(CompressFiles).Invoke(archiveName, commonRootLength, fileFullNames));
- }
- finally
- {
- ReleaseContext();
- }
- }
- /// <summary>
- /// Packs files into the archive asynchronously.
- /// </summary>
- /// <param name="fileFullNames">Array of file names to pack.</param>
- /// <param name="commonRootLength">The length of the common root of the file names.</param>
- /// <param name="archiveStream">The archive output stream.
- /// Use CompressFiles(string archiveName, ... ) overloads for archiving to disk.</param>
- public async Task CompressFilesAsync(Stream archiveStream, int commonRootLength, params string[] fileFullNames)
- {
- try
- {
- SaveContext();
- await Task.Run(() => new CompressFiles4Delegate(CompressFiles).Invoke(archiveStream, commonRootLength, fileFullNames));
- }
- finally
- {
- ReleaseContext();
- }
- }
- /// <summary>
- /// Packs files into the archive asynchronously.
- /// </summary>
- /// <param name="fileFullNames">Array of file names to pack.</param>
- /// <param name="archiveName">The archive file name</param>
- /// <param name="password">The archive password.</param>
- public async Task CompressFilesEncryptedAsync(string archiveName, string password, params string[] fileFullNames)
- {
- try
- {
- SaveContext();
- await Task.Run(() => new CompressFilesEncrypted1Delegate(CompressFilesEncrypted).Invoke(archiveName, password, fileFullNames));
- }
- finally
- {
- ReleaseContext();
- }
- }
- /// <summary>
- /// Packs files into the archive asynchronously.
- /// </summary>
- /// <param name="fileFullNames">Array of file names to pack.</param>
- /// <param name="archiveStream">The archive output stream.
- /// Use CompressFiles( ... string archiveName ... ) overloads for archiving to disk.</param>
- /// <param name="password">The archive password.</param>
- public async Task CompressFilesEncryptedAsync(Stream archiveStream, string password, params string[] fileFullNames)
- {
- try
- {
- SaveContext();
- await Task.Run(() => new CompressFilesEncrypted2Delegate(CompressFilesEncrypted).Invoke(archiveStream, password, fileFullNames));
- }
- finally
- {
- ReleaseContext();
- }
- }
- /// <summary>
- /// Packs files into the archive asynchronously.
- /// </summary>
- /// <param name="fileFullNames">Array of file names to pack.</param>
- /// <param name="archiveName">The archive file name</param>
- /// <param name="password">The archive password.</param>
- /// <param name="commonRootLength">The length of the common root of the file names.</param>
- public async Task CompressFilesEncryptedAsync(string archiveName, int commonRootLength, string password, params string[] fileFullNames)
- {
- try
- {
- SaveContext();
- await Task.Run(() => new CompressFilesEncrypted3Delegate(CompressFilesEncrypted).Invoke(archiveName, commonRootLength, password, fileFullNames));
- }
- finally
- {
- ReleaseContext();
- }
- }
- /// <summary>
- /// Packs files into the archive asynchronously.
- /// </summary>
- /// <param name="fileFullNames">Array of file names to pack.</param>
- /// <param name="archiveStream">The archive output stream.
- /// Use CompressFiles( ... string archiveName ... ) overloads for archiving to disk.</param>
- /// <param name="password">The archive password.</param>
- /// <param name="commonRootLength">The length of the common root of the file names.</param>
- public async Task CompressFilesEncryptedAsync(Stream archiveStream, int commonRootLength, string password, params string[] fileFullNames)
- {
- try
- {
- SaveContext();
- await Task.Run(() => new CompressFilesEncrypted4Delegate(CompressFilesEncrypted).Invoke(archiveStream, commonRootLength, password, fileFullNames));
- }
- finally
- {
- ReleaseContext();
- }
- }
- #endregion
- #region BeginCompressDirectory overloads
- /// <summary>
- /// Packs all files in the specified directory asynchronously.
- /// </summary>
- /// <param name="directory">The directory to compress.</param>
- /// <param name="archiveName">The archive file name.</param>
- /// <param name="password">The archive password.</param>
- /// <param name="searchPattern">Search string, such as "*.txt".</param>
- /// <param name="recursion">If true, files will be searched for recursively; otherwise, not.</param>
- public void BeginCompressDirectory(string directory, string archiveName, string password = "", string searchPattern = "*", bool recursion = true)
- {
- SaveContext();
- Task.Run(() => new CompressDirectoryDelegate(CompressDirectory).Invoke(directory, archiveName, password, searchPattern, recursion))
- .ContinueWith(_ => ReleaseContext());
- }
- /// <summary>
- /// Packs all files in the specified directory asynchronously.
- /// </summary>
- /// <param name="directory">The directory to compress.</param>
- /// <param name="archiveStream">The archive output stream.
- /// Use CompressDirectory( ... string archiveName ... ) overloads for archiving to disk.</param>
- /// <param name="password">The archive password.</param>
- /// <param name="searchPattern">Search string, such as "*.txt".</param>
- /// <param name="recursion">If true, files will be searched for recursively; otherwise, not.</param>
- public void BeginCompressDirectory(string directory, Stream archiveStream, string password , string searchPattern = "*", bool recursion = true)
- {
- SaveContext();
- Task.Run(() => new CompressDirectory2Delegate(CompressDirectory).Invoke(directory, archiveStream, password, searchPattern, recursion))
- .ContinueWith(_ => ReleaseContext());
- }
- #endregion
- #region CompressDirectoryAsync overloads
- /// <summary>
- /// Packs all files in the specified directory asynchronously.
- /// </summary>
- /// <param name="directory">The directory to compress.</param>
- /// <param name="archiveName">The archive file name.</param>
- /// <param name="password">The archive password.</param>
- /// <param name="searchPattern">Search string, such as "*.txt".</param>
- /// <param name="recursion">If true, files will be searched for recursively; otherwise, not.</param>
- public async Task CompressDirectoryAsync(string directory, string archiveName, string password = "", string searchPattern = "*", bool recursion = true)
- {
- try
- {
- SaveContext();
- await Task.Run(() => new CompressDirectoryDelegate(CompressDirectory).Invoke(directory, archiveName, password, searchPattern, recursion));
- }
- finally
- {
- ReleaseContext();
- }
- }
- /// <summary>
- /// Packs all files in the specified directory asynchronously.
- /// </summary>
- /// <param name="directory">The directory to compress.</param>
- /// <param name="archiveStream">The archive output stream.
- /// Use CompressDirectory( ... string archiveName ... ) overloads for archiving to disk.</param>
- /// <param name="password">The archive password.</param>
- /// <param name="searchPattern">Search string, such as "*.txt".</param>
- /// <param name="recursion">If true, files will be searched for recursively; otherwise, not.</param>
- public async Task CompressDirectoryAsync(string directory, Stream archiveStream, string password, string searchPattern = "*", bool recursion = true)
- {
- try
- {
- SaveContext();
- await Task.Run(() => new CompressDirectory2Delegate(CompressDirectory).Invoke(directory, archiveStream, password, searchPattern, recursion));
- }
- finally
- {
- ReleaseContext();
- }
- }
- #endregion
- #region BeginCompressStream overloads
- /// <summary>
- /// Compresses the specified stream.
- /// </summary>
- /// <param name="inStream">The source uncompressed stream.</param>
- /// <param name="outStream">The destination compressed stream.</param>
- /// <param name="password">The archive password.</param>
- /// <exception cref="System.ArgumentException">ArgumentException: at least one of the specified streams is invalid.</exception>
- public void BeginCompressStream(Stream inStream, Stream outStream, string password = "")
- {
- SaveContext();
- Task.Run(() => new CompressStreamDelegate(CompressStream).Invoke(inStream, outStream, password))
- .ContinueWith(_ => ReleaseContext());
- }
- #endregion
- #region CompressStreamAsync overloads
- /// <summary>
- /// Compresses the specified stream.
- /// </summary>
- /// <param name="inStream">The source uncompressed stream.</param>
- /// <param name="outStream">The destination compressed stream.</param>
- /// <param name="password">The archive password.</param>
- /// <exception cref="System.ArgumentException">ArgumentException: at least one of the specified streams is invalid.</exception>
- public async Task CompressStreamAsync(Stream inStream, Stream outStream, string password = "")
- {
- try
- {
- SaveContext();
- await Task.Run(() => new CompressStreamDelegate(CompressStream).Invoke(inStream, outStream, password));
- }
- finally
- {
- ReleaseContext();
- }
- }
- #endregion
- #region BeginModifyArchive overloads
- /// <summary>
- /// Modifies the existing archive asynchronously (renames files or deletes them).
- /// </summary>
- /// <param name="archiveName">The archive file name.</param>
- /// <param name="newFileNames">New file names. Null value to delete the corresponding index.</param>
- /// <param name="password">The archive password.</param>
- public void BeginModifyArchive(string archiveName, IDictionary<int, string> newFileNames, string password = "")
- {
- SaveContext();
- Task.Run(() => new ModifyArchiveDelegate(ModifyArchive).Invoke(archiveName, newFileNames, password))
- .ContinueWith(_ => ReleaseContext());
- }
- #endregion
- #region ModifyArchiveAsync overloads
- /// <summary>
- /// Modifies the existing archive asynchronously (renames files or deletes them).
- /// </summary>
- /// <param name="archiveName">The archive file name.</param>
- /// <param name="newFileNames">New file names. Null value to delete the corresponding index.</param>
- /// <param name="password">The archive password.</param>
- public async Task ModifyArchiveAsync(string archiveName, IDictionary<int, string> newFileNames, string password = "")
- {
- try
- {
- SaveContext();
- await Task.Run(() => new ModifyArchiveDelegate(ModifyArchive).Invoke(archiveName, newFileNames, password));
- }
- finally
- {
- ReleaseContext();
- }
- }
- #endregion
- }
- }
|