Пример #1
0
        public void CreateEmptyArchive()
        {
            string tempFile = GetTempFilePath();

            Assert.IsNotNull(tempFile, "No permission to execute this test?");

            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");

                using (IsolatedZipFile f = IsolatedZipFile.Create(tempFile))
                {
                    f.BeginUpdate();
                    f.CommitUpdate();
                    // TODO: Testing is not yet ported - Assert.IsTrue(f.TestArchive(true));
                    f.Close();
                }

                using (IsolatedZipFile f = new IsolatedZipFile(tempFile))
                {
                    Assert.AreEqual(0, f.Count);
                }

                store.DeleteFile(tempFile);
            }
        }
Пример #2
0
        public void Zip64Entries()
        {
            string tempFile = GetTempFilePath();

            Assert.IsNotNull(tempFile, "No permission to execute this test?");

            const int target = 65537;

            using (IsolatedZipFile zipFile = IsolatedZipFile.Create(Path.GetTempFileName()))
            {
                zipFile.BeginUpdate();

                for (int i = 0; i < target; ++i)
                {
                    ZipEntry ze = new ZipEntry(i.ToString());
                    ze.CompressedSize = 0;
                    ze.Size           = 0;
                    zipFile.Add(ze);
                }
                zipFile.CommitUpdate();

                // TODO: Testing is not yet ported - Assert.IsTrue(zipFile.TestArchive(true));
                Assert.AreEqual(target, zipFile.Count, "Incorrect number of entries stored");
            }
        }
Пример #3
0
        /// <summary>
        /// </summary>
        private void ZipFileToISO(object sender, RoutedEventArgs e)
        {
            DeleteSampleText();
            DeleteSampleZip();

            CreateLocalSampleFile(SampleTextFileName);

            /*
             *  Create an archive with ZipFile
             *************************************************************
             */

            IsolatedZipFile zip = IsolatedZipFile.Create(SampleZipFileName);

            zip.BeginUpdate();
            zip.Add(SampleTextFileName);
            zip.CommitUpdate();
            zip.Close();

            /*************************************************************
             *
             */

            DisplayMetrics("CreateIsoZipFile", false);
            DeleteSampleText();
            UnzipFromISOButton.IsEnabled     = true;
            ZipFileFromISOButton.IsEnabled   = true;
            ZipStreamFromISOButton.IsEnabled = false;
        }
Пример #4
0
        public void AddToEmptyArchive()
        {
            string tempFile = GetTempFilePath();

            Assert.IsNotNull(tempFile, "No permission to execute this test?");

            string addFile = Path.Combine(tempFile, "a.dat");

            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                MakeTempFile(addFile, 1);

                try
                {
                    tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");

                    using (IsolatedZipFile f = IsolatedZipFile.Create(tempFile))
                    {
                        f.BeginUpdate();
                        f.Add(addFile);
                        f.CommitUpdate();
                        Assert.AreEqual(1, f.Count);
                        // TODO: Testing is not yet ported - Assert.IsTrue(f.TestArchive(true));
                    }

                    using (IsolatedZipFile f = new IsolatedZipFile(tempFile))
                    {
                        Assert.AreEqual(1, f.Count);
                        f.BeginUpdate();
                        f.Delete(f[0]); // failing here in 4 and 3 - fixed - one-off in zipfile
                        f.CommitUpdate();
                        Assert.AreEqual(0, f.Count);
                        // TODO: Testing is not yet ported - Assert.IsTrue(f.TestArchive(true));
                        f.Close();
                    }

                    store.DeleteFile(tempFile);
                }
                finally
                {
                    store.DeleteFile(addFile);
                }
            }
        }
Пример #5
0
        public void BasicEncryptionToDisk()
        {
            const string TestValue = "0001000";
            string       tempFile  = GetTempFilePath();

            Assert.IsNotNull(tempFile, "No permission to execute this test?");

            tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedZipFile f = IsolatedZipFile.Create(tempFile))
                {
                    f.Password = "******";

                    StringMemoryDataSource m = new StringMemoryDataSource(TestValue);
                    f.BeginUpdate();
                    f.Add(m, "a.dat");
                    f.CommitUpdate();
                }

                using (IsolatedZipFile f = new IsolatedZipFile(tempFile))
                {
                    f.Password = "******";
                    // TODO: Testing is not yet ported - Assert.IsTrue(f.TestArchive(true), "Archive test should pass");
                }

                using (IsolatedZipFile g = new IsolatedZipFile(tempFile))
                {
                    g.Password = "******";
                    ZipEntry ze = g[0];

                    Assert.IsTrue(ze.IsCrypted, "Entry should be encrypted");

                    using (StreamReader r = new StreamReader(g.GetInputStream(0)))
                    {
                        string data = r.ReadToEnd();
                        Assert.AreEqual(TestValue, data);
                    }
                }

                store.DeleteFile(tempFile);
            }
        }
Пример #6
0
        public void AddAndDeleteEntries()
        {
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                string tempFile = GetTempFilePath();
                Assert.IsNotNull(tempFile, "No permission to execute this test?");

                string addFile = Path.Combine(tempFile, "a.dat");
                MakeTempFile(addFile, 1);

                string addFile2 = Path.Combine(tempFile, "b.dat");
                MakeTempFile(addFile2, 259);

                tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");

                using (IsolatedZipFile f = IsolatedZipFile.Create(tempFile))
                {
                    f.BeginUpdate();
                    f.Add(addFile);
                    f.Add(addFile2);
                    f.CommitUpdate();
                    // TODO: Testing is not yet ported - Assert.IsTrue(f.TestArchive(true));
                }

                using (IsolatedZipFile f = new IsolatedZipFile(tempFile))
                {
                    Assert.AreEqual(2, f.Count);
                    // TODO: Testing is not yet ported - Assert.IsTrue(f.TestArchive(true));
                    f.BeginUpdate();
                    f.Delete(f[0]);
                    f.CommitUpdate();
                    Assert.AreEqual(1, f.Count);
                    // TODO: Testing is not yet ported - Assert.IsTrue(f.TestArchive(true));
                }

                store.DeleteFile(addFile);
                store.DeleteFile(addFile2);
                store.DeleteFile(tempFile);
            }
        }
Пример #7
0
        public void UpdateCommentOnlyOnDisk()
        {
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                

                string tempFile = GetTempFilePath();
                Assert.IsNotNull(tempFile, "No permission to execute this test?");

                tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
                if (store.FileExists(tempFile))
                {
                    store.DeleteFile(tempFile);
                }

                using (IsolatedZipFile testFile = IsolatedZipFile.Create(tempFile))
                {
                    testFile.BeginUpdate();
                    testFile.Add(new StringMemoryDataSource("Aha"), "No1", CompressionMethod.Stored);
                    testFile.Add(new StringMemoryDataSource("And so it goes"), "No2", CompressionMethod.Stored);
                    testFile.Add(new StringMemoryDataSource("No3"), "No3", CompressionMethod.Stored);
                    testFile.CommitUpdate();

                    // TODO: Testing is not yet ported -  Assert.IsTrue(testFile.TestArchive(true));
                }

                using (IsolatedZipFile testFile = new IsolatedZipFile(tempFile))
                {
                    // TODO: Testing is not yet ported - Assert.IsTrue(testFile.TestArchive(true));
                    Assert.AreEqual("", testFile.ZipFileComment);

                    testFile.BeginUpdate(new IsolatedDiskArchiveStorage(testFile, FileUpdateMode.Direct));
                    testFile.SetComment("Here is my comment");
                    testFile.CommitUpdate();

                    // TODO: Testing is not yet ported - Assert.IsTrue(testFile.TestArchive(true));
                }

                using (IsolatedZipFile testFile = new IsolatedZipFile(tempFile))
                {
                    // TODO: Testing is not yet ported - Assert.IsTrue(testFile.TestArchive(true));
                    Assert.AreEqual("Here is my comment", testFile.ZipFileComment);
                }
                store.DeleteFile(tempFile);

                // Variant using indirect updating.
                using (IsolatedZipFile testFile = IsolatedZipFile.Create(tempFile))
                {
                    testFile.BeginUpdate();
                    testFile.Add(new StringMemoryDataSource("Aha"), "No1", CompressionMethod.Stored);
                    testFile.Add(new StringMemoryDataSource("And so it goes"), "No2", CompressionMethod.Stored);
                    testFile.Add(new StringMemoryDataSource("No3"), "No3", CompressionMethod.Stored);
                    testFile.CommitUpdate();

                    // TODO: Testing is not yet ported - Assert.IsTrue(testFile.TestArchive(true));
                }

                using (IsolatedZipFile testFile = new IsolatedZipFile(tempFile))
                {
                    // TODO: Testing is not yet ported - Assert.IsTrue(testFile.TestArchive(true));
                    Assert.AreEqual("", testFile.ZipFileComment);

                    testFile.BeginUpdate();
                    testFile.SetComment("Here is my comment");
                    testFile.CommitUpdate();

                    // TODO: Testing is not yet ported - Assert.IsTrue(testFile.TestArchive(true));
                }

                using (IsolatedZipFile testFile = new IsolatedZipFile(tempFile))
                {
                    // TODO: Testing is not yet ported - Assert.IsTrue(testFile.TestArchive(true));
                    Assert.AreEqual("Here is my comment", testFile.ZipFileComment);
                }

                store.DeleteFile(tempFile);
                store.DeleteDirectory(Path.GetDirectoryName(tempFile));

            }
        }
Пример #8
0
        public void AddToEmptyArchive()
        {
            string tempFile = GetTempFilePath();
            Assert.IsNotNull(tempFile, "No permission to execute this test?");

            string addFile = Path.Combine(tempFile, "a.dat");

            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                MakeTempFile(addFile, 1);

                try
                {
                    tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");

                    using (IsolatedZipFile f = IsolatedZipFile.Create(tempFile))
                    {
                        f.BeginUpdate();
                        f.Add(addFile);
                        f.CommitUpdate();
                        Assert.AreEqual(1, f.Count);
                        // TODO: Testing is not yet ported - Assert.IsTrue(f.TestArchive(true));
                    }

                    using (IsolatedZipFile f = new IsolatedZipFile(tempFile))
                    {
                        Assert.AreEqual(1, f.Count);
                        f.BeginUpdate();
                        f.Delete(f[0]); // failing here in 4 and 3 - fixed - one-off in zipfile
                        f.CommitUpdate();
                        Assert.AreEqual(0, f.Count);
                        // TODO: Testing is not yet ported - Assert.IsTrue(f.TestArchive(true));
                        f.Close();
                    }

                    store.DeleteFile(tempFile);
                }
                finally
                {
                    store.DeleteFile(addFile);
                }
            }
        }
Пример #9
0
        public void AddAndDeleteEntries()
        {
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                string tempFile = GetTempFilePath();
                Assert.IsNotNull(tempFile, "No permission to execute this test?");

                string addFile = Path.Combine(tempFile, "a.dat");
                MakeTempFile(addFile, 1);

                string addFile2 = Path.Combine(tempFile, "b.dat");
                MakeTempFile(addFile2, 259);

                tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");

                using (IsolatedZipFile f = IsolatedZipFile.Create(tempFile))
                {
                    f.BeginUpdate();
                    f.Add(addFile);
                    f.Add(addFile2);
                    f.CommitUpdate();
                    // TODO: Testing is not yet ported - Assert.IsTrue(f.TestArchive(true));
                }

                using (IsolatedZipFile f = new IsolatedZipFile(tempFile))
                {
                    Assert.AreEqual(2, f.Count);
                    // TODO: Testing is not yet ported - Assert.IsTrue(f.TestArchive(true));
                    f.BeginUpdate();
                    f.Delete(f[0]);
                    f.CommitUpdate();
                    Assert.AreEqual(1, f.Count);
                    // TODO: Testing is not yet ported - Assert.IsTrue(f.TestArchive(true));
                }

                store.DeleteFile(addFile);
                store.DeleteFile(addFile2);
                store.DeleteFile(tempFile);
            }
        }
Пример #10
0
        public void UpdateCommentOnlyOnDisk()
        {
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                string tempFile = GetTempFilePath();
                Assert.IsNotNull(tempFile, "No permission to execute this test?");

                tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
                if (store.FileExists(tempFile))
                {
                    store.DeleteFile(tempFile);
                }

                using (IsolatedZipFile testFile = IsolatedZipFile.Create(tempFile))
                {
                    testFile.BeginUpdate();
                    testFile.Add(new StringMemoryDataSource("Aha"), "No1", CompressionMethod.Stored);
                    testFile.Add(new StringMemoryDataSource("And so it goes"), "No2", CompressionMethod.Stored);
                    testFile.Add(new StringMemoryDataSource("No3"), "No3", CompressionMethod.Stored);
                    testFile.CommitUpdate();

                    // TODO: Testing is not yet ported -  Assert.IsTrue(testFile.TestArchive(true));
                }

                using (IsolatedZipFile testFile = new IsolatedZipFile(tempFile))
                {
                    // TODO: Testing is not yet ported - Assert.IsTrue(testFile.TestArchive(true));
                    Assert.AreEqual("", testFile.ZipFileComment);

                    testFile.BeginUpdate(new IsolatedDiskArchiveStorage(testFile, FileUpdateMode.Direct));
                    testFile.SetComment("Here is my comment");
                    testFile.CommitUpdate();

                    // TODO: Testing is not yet ported - Assert.IsTrue(testFile.TestArchive(true));
                }

                using (IsolatedZipFile testFile = new IsolatedZipFile(tempFile))
                {
                    // TODO: Testing is not yet ported - Assert.IsTrue(testFile.TestArchive(true));
                    Assert.AreEqual("Here is my comment", testFile.ZipFileComment);
                }
                store.DeleteFile(tempFile);

                // Variant using indirect updating.
                using (IsolatedZipFile testFile = IsolatedZipFile.Create(tempFile))
                {
                    testFile.BeginUpdate();
                    testFile.Add(new StringMemoryDataSource("Aha"), "No1", CompressionMethod.Stored);
                    testFile.Add(new StringMemoryDataSource("And so it goes"), "No2", CompressionMethod.Stored);
                    testFile.Add(new StringMemoryDataSource("No3"), "No3", CompressionMethod.Stored);
                    testFile.CommitUpdate();

                    // TODO: Testing is not yet ported - Assert.IsTrue(testFile.TestArchive(true));
                }

                using (IsolatedZipFile testFile = new IsolatedZipFile(tempFile))
                {
                    // TODO: Testing is not yet ported - Assert.IsTrue(testFile.TestArchive(true));
                    Assert.AreEqual("", testFile.ZipFileComment);

                    testFile.BeginUpdate();
                    testFile.SetComment("Here is my comment");
                    testFile.CommitUpdate();

                    // TODO: Testing is not yet ported - Assert.IsTrue(testFile.TestArchive(true));
                }

                using (IsolatedZipFile testFile = new IsolatedZipFile(tempFile))
                {
                    // TODO: Testing is not yet ported - Assert.IsTrue(testFile.TestArchive(true));
                    Assert.AreEqual("Here is my comment", testFile.ZipFileComment);
                }

                store.DeleteFile(tempFile);
                store.DeleteDirectory(Path.GetDirectoryName(tempFile));
            }
        }