|
1 | | -using ICSharpCode.SharpZipLib.Core; |
2 | | -using ICSharpCode.SharpZipLib.Zip; |
| 1 | +using ICSharpCode.SharpZipLib.Zip; |
3 | 2 | using NUnit.Framework; |
4 | 3 | using System; |
5 | | -using System.Diagnostics; |
6 | 4 | using System.IO; |
7 | 5 | using System.Text; |
8 | 6 | using ICSharpCode.SharpZipLib.Tests.TestSupport; |
@@ -74,7 +72,7 @@ public void ZipOutputStreamEncryptEmptyEntries( |
74 | 72 | zipOutputStream.CloseEntry(); |
75 | 73 | } |
76 | 74 |
|
77 | | - VerifyZipWith7Zip(ms, "password"); |
| 75 | + SevenZipHelper.VerifyZipWith7Zip(ms, "password"); |
78 | 76 | } |
79 | 77 | } |
80 | 78 |
|
@@ -315,7 +313,7 @@ public void ZipFileAesAdd() |
315 | 313 | } |
316 | 314 |
|
317 | 315 | // As an extra test, verify the file with 7-zip |
318 | | - VerifyZipWith7Zip(memoryStream, password); |
| 316 | + SevenZipHelper.VerifyZipWith7Zip(memoryStream, password); |
319 | 317 | } |
320 | 318 | } |
321 | 319 |
|
@@ -399,7 +397,7 @@ public void ZipFileAesDelete() |
399 | 397 | } |
400 | 398 |
|
401 | 399 | // As an extra test, verify the file with 7-zip |
402 | | - VerifyZipWith7Zip(memoryStream, password); |
| 400 | + SevenZipHelper.VerifyZipWith7Zip(memoryStream, password); |
403 | 401 | } |
404 | 402 | } |
405 | 403 |
|
@@ -471,54 +469,6 @@ public void ZipinputStreamShouldGracefullyFailWithAESStreams() |
471 | 469 | } |
472 | 470 | } |
473 | 471 |
|
474 | | - private static readonly string[] possible7zPaths = new[] { |
475 | | - // Check in PATH |
476 | | - "7z", "7za", |
477 | | - |
478 | | - // Check in default install location |
479 | | - Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "7-Zip", "7z.exe"), |
480 | | - Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "7-Zip", "7z.exe"), |
481 | | - }; |
482 | | - |
483 | | - public static bool TryGet7zBinPath(out string path7z) |
484 | | - { |
485 | | - var runTimeLimit = TimeSpan.FromSeconds(3); |
486 | | - |
487 | | - foreach (var testPath in possible7zPaths) |
488 | | - { |
489 | | - try |
490 | | - { |
491 | | - var p = Process.Start(new ProcessStartInfo(testPath, "i") |
492 | | - { |
493 | | - RedirectStandardOutput = true, |
494 | | - UseShellExecute = false |
495 | | - }); |
496 | | - while (!p.StandardOutput.EndOfStream && (DateTime.Now - p.StartTime) < runTimeLimit) |
497 | | - { |
498 | | - p.StandardOutput.DiscardBufferedData(); |
499 | | - } |
500 | | - if (!p.HasExited) |
501 | | - { |
502 | | - p.Close(); |
503 | | - Assert.Warn($"Timed out checking for 7z binary in \"{testPath}\"!"); |
504 | | - continue; |
505 | | - } |
506 | | - |
507 | | - if (p.ExitCode == 0) |
508 | | - { |
509 | | - path7z = testPath; |
510 | | - return true; |
511 | | - } |
512 | | - } |
513 | | - catch (Exception) |
514 | | - { |
515 | | - continue; |
516 | | - } |
517 | | - } |
518 | | - path7z = null; |
519 | | - return false; |
520 | | - } |
521 | | - |
522 | 472 | public void WriteEncryptedZipToStream(Stream stream, string password, int keySize, CompressionMethod compressionMethod = CompressionMethod.Deflated) |
523 | 473 | { |
524 | 474 | using (var zs = new ZipOutputStream(stream)) |
@@ -572,51 +522,10 @@ public void CreateZipWithEncryptedEntries(string password, int keySize, Compress |
572 | 522 | using (var ms = new MemoryStream()) |
573 | 523 | { |
574 | 524 | WriteEncryptedZipToStream(ms, password, keySize, compressionMethod); |
575 | | - VerifyZipWith7Zip(ms, password); |
576 | | - } |
577 | | - } |
578 | | - |
579 | | - /// <summary> |
580 | | - /// Helper function to verify the provided zip stream with 7Zip. |
581 | | - /// </summary> |
582 | | - /// <param name="zipStream">A stream containing the zip archive to test.</param> |
583 | | - /// <param name="password">The password for the archive.</param> |
584 | | - private void VerifyZipWith7Zip(Stream zipStream, string password) |
585 | | - { |
586 | | - if (TryGet7zBinPath(out string path7z)) |
587 | | - { |
588 | | - Console.WriteLine($"Using 7z path: \"{path7z}\""); |
589 | | - |
590 | | - var fileName = Path.GetTempFileName(); |
591 | | - |
592 | | - try |
593 | | - { |
594 | | - using (var fs = File.OpenWrite(fileName)) |
595 | | - { |
596 | | - zipStream.Seek(0, SeekOrigin.Begin); |
597 | | - zipStream.CopyTo(fs); |
598 | | - } |
599 | | - |
600 | | - var p = Process.Start(path7z, $"t -p{password} \"{fileName}\""); |
601 | | - if (!p.WaitForExit(2000)) |
602 | | - { |
603 | | - Assert.Warn("Timed out verifying zip file!"); |
604 | | - } |
605 | | - |
606 | | - Assert.AreEqual(0, p.ExitCode, "Archive verification failed"); |
607 | | - } |
608 | | - finally |
609 | | - { |
610 | | - File.Delete(fileName); |
611 | | - } |
612 | | - } |
613 | | - else |
614 | | - { |
615 | | - Assert.Warn("Skipping file verification since 7za is not in path"); |
| 525 | + SevenZipHelper.VerifyZipWith7Zip(ms, password); |
616 | 526 | } |
617 | 527 | } |
618 | 528 |
|
619 | | - |
620 | 529 | private const string DummyDataString = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. |
621 | 530 | Fusce bibendum diam ac nunc rutrum ornare. Maecenas blandit elit ligula, eget suscipit lectus rutrum eu. |
622 | 531 | Maecenas aliquam, purus mattis pulvinar pharetra, nunc orci maximus justo, sed facilisis massa dui sed lorem. |
|
0 commit comments