Exemplo n.º 1
0
		private static void CheckZipFile(Stream stream, string[] filestocheckexist, bool filenameonly, string password, bool aes128)
		{
			List<string> zipFiles = new List<string>();
			using (Chilkat.Zip zip = new Chilkat.Zip())
			{
				zip.UnlockComponent("WRKSHRZIP_YrPEVwzmlDsV");
				zip.SetPassword(password);

				byte[] zipData = StreamUtils.SafeButUnpleasantReadAllStreamIntoByteArray(stream);

				if (!string.IsNullOrEmpty(password) && !aes128)
				{
					string sTempFile = Path.GetTempFileName();
					System.IO.File.WriteAllBytes(sTempFile, zipData);

					bool bPwdProtected = zip.IsPasswordProtected(sTempFile);

					System.IO.File.Delete(sTempFile);

					Assert.IsTrue(bPwdProtected);
				}

				if (!zip.OpenFromMemory(zipData))
					throw new System.Exception(zip.LastErrorText);

				Assert.AreEqual(zip.Encryption, aes128 ? 4 : 0);
				Assert.AreEqual(zip.EncryptKeyLength, aes128 ? 128 : 0);

				for (int index = 0; index < zip.NumEntries; ++index)
				{
					using (Chilkat.ZipEntry zipEntry = zip.GetEntryByIndex(index))
					{
						if (null == zipEntry)
							break;



						zipFiles.Add(filenameonly ? Path.GetFileName(zipEntry.FileName) : zipEntry.FileName);
					}
				}
			}

			foreach (string file in filestocheckexist)
			{
				Assert.IsTrue(zipFiles.Contains(file), "Did not find expected file inside zip : " + file);
			}

			stream.Close();
		}