public static void Pack(this ArchiveInfo o, string sourceDirectory, IList <string> sourceFileNames, IList <string> fileNames, CompressionLevel compLevel, EventHandler <ArchiveProgressEventArgs> progressHandler, IPackStreamContext ipackstreamcontext) { if (sourceFileNames == null) { throw new ArgumentNullException("sourceFileNames"); } checked { if (fileNames == null) { string[] array = new string[sourceFileNames.Count]; for (int i = 0; i < sourceFileNames.Count; i++) { array[i] = Path.GetFileName(sourceFileNames[i]); } fileNames = array; } else if (fileNames.Count != sourceFileNames.Count) { throw new ArgumentOutOfRangeException("fileNames"); } using (CompressionEngine compressionEngine = new CabEngine()) { compressionEngine.Progress += progressHandler; IDictionary <string, string> files = CreateStringDictionary(fileNames, sourceFileNames); ArchiveFileStreamContext archiveFileStreamContext = new ArchiveFileStreamContext(o.FullName, sourceDirectory, files); archiveFileStreamContext.EnableOffsetOpen = true; compressionEngine.CompressionLevel = compLevel; compressionEngine.Pack(archiveFileStreamContext, fileNames); } } }
public void ZipEngineNullParams() { string[] testFiles = new string[] { "test.txt" }; ArchiveFileStreamContext streamContext = new ArchiveFileStreamContext("test.zip", null, null); using (ZipEngine zipEngine = new ZipEngine()) { zipEngine.CompressionLevel = CompressionLevel.None; CompressionTestUtil.TestCompressionEngineNullParams(zipEngine, streamContext, testFiles); } }
public static void TestCompressionEngineNullParams( CompressionEngine engine, ArchiveFileStreamContext streamContext, string[] testFiles) { Exception caughtEx; Console.WriteLine("Testing null streamContext."); caughtEx = null; try { engine.Pack(null, testFiles); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); caughtEx = null; try { engine.Pack(null, testFiles, 0); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); Console.WriteLine("Testing null files."); caughtEx = null; try { engine.Pack(streamContext, null); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); Console.WriteLine("Testing null files."); caughtEx = null; try { engine.Pack(streamContext, null, 0); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); Console.WriteLine("Testing null stream."); caughtEx = null; try { engine.IsArchive(null); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); caughtEx = null; try { engine.FindArchiveOffset(null); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); caughtEx = null; try { engine.GetFiles(null); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); caughtEx = null; try { engine.GetFileInfo(null); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); caughtEx = null; try { engine.Unpack(null, "testUnpack.txt"); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); Console.WriteLine("Testing null streamContext."); caughtEx = null; try { engine.GetFiles(null, null); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); caughtEx = null; try { engine.GetFileInfo(null, null); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); caughtEx = null; try { engine.Unpack((IUnpackStreamContext)null, null); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); }