diff --git a/SevenZip/SevenZipCompressor.cs b/SevenZip/SevenZipCompressor.cs index 42c7538..4b13ed0 100644 --- a/SevenZip/SevenZipCompressor.cs +++ b/SevenZip/SevenZipCompressor.cs @@ -1202,6 +1202,8 @@ public void CompressFilesEncrypted(string archiveName, int commonRootLength, str return; } } + + UpdateCompressorPassword(password); if (_volumeSize == 0 || !_compressingFilesOnDisk) { @@ -1499,7 +1501,9 @@ public void CompressStreamDictionary(IDictionary streamDictionar { ValidateStream(archiveStream); } - + + UpdateCompressorPassword(password); + if (streamDictionary.Where( pair => pair.Value != null && (!pair.Value.CanSeek || !pair.Value.CanRead)).Any( pair => !ThrowException(null, @@ -1664,11 +1668,7 @@ public void ModifyArchive(string archiveName, IDictionary newFileNa } } - if (!string.IsNullOrEmpty(password) && string.IsNullOrEmpty(Password)) - { - // When modifying an encrypted archive, Password is not set in the SevenZipCompressor. - Password = password; - } + UpdateCompressorPassword(password); try { @@ -1862,5 +1862,18 @@ private static string[] GetFullFilePaths(IEnumerable fileFullNames) { return fileFullNames.Select(Path.GetFullPath).ToArray(); } + + /// + /// Check and update password in SevenZipCompressor + /// + /// The password to use. + private void UpdateCompressorPassword(string password) + { + if (!string.IsNullOrEmpty(password) && string.IsNullOrEmpty(Password)) + { + // When modifying an encrypted archive, Password is not set in the SevenZipCompressor. + Password = password; + } + } } }