예제 #1
0
        public void RoundTrip()
        {
            string tempFile = GetTempFilePath();

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

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

                    using (IsolatedZipFile zipFile = new IsolatedZipFile(tempFile))
                    {
                        foreach (ZipEntry e in zipFile)
                        {
                            Stream instream = zipFile.GetInputStream(e);
                            CheckKnownEntry(instream, 1024);
                        }
                        zipFile.Close();
                    }
                }
                finally
                {
                    store.DeleteFile(tempFile);
                }
            }
        }
예제 #2
0
        public void FindEntriesInArchiveWithLongComment()
        {
            string tempFile = GetTempFilePath();

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

            tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
            string longComment = new String('A', 65535);

            MakeZipFile(tempFile, "", 1, 1, longComment);
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                try
                {
                    using (IsolatedZipFile zipFile = new IsolatedZipFile(tempFile))
                    {
                        foreach (ZipEntry e in zipFile)
                        {
                            Stream instream = zipFile.GetInputStream(e);
                            CheckKnownEntry(instream, 1);
                        }
                        zipFile.Close();
                    }
                }
                finally
                {
                    store.DeleteFile(tempFile);
                }
            }
        }
예제 #3
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);
            }
        }
예제 #4
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;
        }
예제 #5
0
        public void FindEntry()
        {
            string tempFile = GetTempFilePath();

            Assert.IsNotNull(tempFile, "No permission to execute this test?");
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
                MakeZipFile(tempFile, new string[] { "Farriera", "Champagne", "Urban myth" }, 10, "Aha");

                using (IsolatedZipFile zipFile = new IsolatedZipFile(tempFile))
                {
                    Assert.AreEqual(3, zipFile.Count, "Expected 1 entry");

                    int testIndex = zipFile.FindEntry("Farriera", false);
                    Assert.AreEqual(0, testIndex, "Case sensitive find failure");
                    Assert.IsTrue(string.Compare(zipFile[testIndex].Name, "Farriera", StringComparison.InvariantCulture) == 0);


                    testIndex = zipFile.FindEntry("farriera", false);
                    Assert.AreEqual(-1, testIndex, "Case sensitive find failure");


                    testIndex = zipFile.FindEntry("farriera", true);
                    Assert.AreEqual(0, testIndex, "Case insensitive find failure");
                    Assert.IsTrue(string.Compare(zipFile[testIndex].Name, "Farriera", StringComparison.InvariantCultureIgnoreCase) == 0);

                    testIndex = zipFile.FindEntry("urban mYTH", false);
                    Assert.AreEqual(-1, testIndex, "Case sensitive find failure");

                    testIndex = zipFile.FindEntry("urban mYTH", true);
                    Assert.AreEqual(2, testIndex, "Case insensitive find failure");
                    Assert.IsTrue(string.Compare(zipFile[testIndex].Name, "urban mYTH", StringComparison.InvariantCultureIgnoreCase) == 0);

                    testIndex = zipFile.FindEntry("Champane.", false);
                    Assert.AreEqual(-1, testIndex, "Case sensitive find failure");

                    testIndex = zipFile.FindEntry("Champane.", true);
                    Assert.AreEqual(-1, testIndex, "Case insensitive find failure");

                    zipFile.Close();
                }
                store.DeleteFile(tempFile);
            }
        }
예제 #6
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);
                }
            }
        }
예제 #7
0
        public void HandlesNoEntries()
        {
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                string tempFile = GetTempFilePath();
                Assert.IsNotNull(tempFile, "No permission to execute this test?");

                tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
                MakeZipFile(tempFile, "", 0, 1, "Aha");

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

                store.DeleteFile(tempFile);
            }
        }
예제 #8
0
        public void FindEntriesInArchiveExtraData()
        {
            string tempFile = GetTempFilePath();

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

            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
                string longComment = new String('A', 65535);

                FileStream tempStream = store.CreateFile(tempFile);
                MakeZipFile(tempStream, false, "", 1, 1, longComment);

                tempStream.WriteByte(85);
                tempStream.Close();

                fails = false;
                try
                {
                    using (IsolatedZipFile zipFile = new IsolatedZipFile(tempFile))
                    {
                        foreach (ZipEntry e in zipFile)
                        {
                            Stream instream = zipFile.GetInputStream(e);
                            CheckKnownEntry(instream, 1);
                        }
                        zipFile.Close();
                    }
                }
                catch
                {
                    fails = true;
                }

                store.DeleteFile(tempFile);
            }
            Assert.IsTrue(fails, "Currently zip file wont be found");
        }
예제 #9
0
        public void PartialStreamClosing()
        {
            string tempFile = GetTempFilePath();

            if (tempFile != null)
            {
                tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
                MakeZipFile(tempFile, new String[] { "Farriera", "Champagne", "Urban myth" }, 10, "Aha");

                using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (IsolatedZipFile zipFile = new IsolatedZipFile(tempFile))
                    {
                        Stream stream = zipFile.GetInputStream(0);
                        stream.Close();

                        stream = zipFile.GetInputStream(1);
                        zipFile.Close();
                    }
                    store.DeleteFile(tempFile);
                }
            }
        }
예제 #10
0
        public void PartialStreamClosing()
        {
            string tempFile = GetTempFilePath();

            if (tempFile != null)
            {
                tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
                MakeZipFile(tempFile, new String[] { "Farriera", "Champagne", "Urban myth" }, 10, "Aha");

                using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (IsolatedZipFile zipFile = new IsolatedZipFile(tempFile))
                    {
                        Stream stream = zipFile.GetInputStream(0);
                        stream.Close();

                        stream = zipFile.GetInputStream(1);
                        zipFile.Close();
                    }
                    store.DeleteFile(tempFile);
                }
            }
        }
예제 #11
0
        public void Basics()
        {
            const string tempName1 = "a(1).dat";

            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                MemoryStream target = new MemoryStream();

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

                string addFile = Path.Combine(tempFilePath, tempName1);
                MakeTempFile(addFile, 1);

                try
                {
                    IsolatedFastZip fastZip = new IsolatedFastZip();
                    fastZip.CreateZip(target, tempFilePath, false, @"a\(1\)\.dat", null); // failing here in 4

                    MemoryStream archive = new MemoryStream(target.ToArray());
                    using (IsolatedZipFile zf = new IsolatedZipFile(archive))
                    {
                        Assert.AreEqual(1, zf.Count);
                        ZipEntry entry = zf[0];
                        Assert.AreEqual(tempName1, entry.Name);
                        Assert.AreEqual(1, entry.Size);
                        // TODO: Testing is not yet ported - Assert.IsTrue(zf.TestArchive(true));

                        zf.Close();
                    }
                }
                finally
                {
                    store.DeleteFile(tempName1);
                }
            }
        }
예제 #12
0
        public void HandlesNoEntries()
        {
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                string tempFile = GetTempFilePath();
                Assert.IsNotNull(tempFile, "No permission to execute this test?");

                tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
                MakeZipFile(tempFile, "", 0, 1, "Aha");

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

                store.DeleteFile(tempFile);
            }
        }
예제 #13
0
        public void Basics()
        {
            const string tempName1 = "a(1).dat";
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                MemoryStream target = new MemoryStream();

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

                string addFile = Path.Combine(tempFilePath, tempName1);
                MakeTempFile(addFile, 1);

                try
                {
                    IsolatedFastZip fastZip = new IsolatedFastZip();
                    fastZip.CreateZip(target, tempFilePath, false, @"a\(1\)\.dat", null); // failing here in 4

                    MemoryStream archive = new MemoryStream(target.ToArray());
                    using (IsolatedZipFile zf = new IsolatedZipFile(archive))
                    {
                        Assert.AreEqual(1, zf.Count);
                        ZipEntry entry = zf[0];
                        Assert.AreEqual(tempName1, entry.Name);
                        Assert.AreEqual(1, entry.Size);
                        // TODO: Testing is not yet ported - Assert.IsTrue(zf.TestArchive(true));

                        zf.Close();
                    }
                }
                finally
                {
                    store.DeleteFile(tempName1);
                }
            }
        }
예제 #14
0
        public void FindEntry()
        {
            string tempFile = GetTempFilePath();
            Assert.IsNotNull(tempFile, "No permission to execute this test?");
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
                MakeZipFile(tempFile, new string[] { "Farriera", "Champagne", "Urban myth" }, 10, "Aha");

                using (IsolatedZipFile zipFile = new IsolatedZipFile(tempFile))
                {
                    Assert.AreEqual(3, zipFile.Count, "Expected 1 entry");

                    int testIndex = zipFile.FindEntry("Farriera", false);
                    Assert.AreEqual(0, testIndex, "Case sensitive find failure");
                    Assert.IsTrue(string.Compare(zipFile[testIndex].Name, "Farriera", StringComparison.InvariantCulture) == 0);


                    testIndex = zipFile.FindEntry("farriera", false);
                    Assert.AreEqual(-1, testIndex, "Case sensitive find failure");


                    testIndex = zipFile.FindEntry("farriera", true);
                    Assert.AreEqual(0, testIndex, "Case insensitive find failure");
                    Assert.IsTrue(string.Compare(zipFile[testIndex].Name, "Farriera", StringComparison.InvariantCultureIgnoreCase) == 0);

                    testIndex = zipFile.FindEntry("urban mYTH", false);
                    Assert.AreEqual(-1, testIndex, "Case sensitive find failure");

                    testIndex = zipFile.FindEntry("urban mYTH", true);
                    Assert.AreEqual(2, testIndex, "Case insensitive find failure");
                    Assert.IsTrue(string.Compare(zipFile[testIndex].Name, "urban mYTH", StringComparison.InvariantCultureIgnoreCase) == 0);

                    testIndex = zipFile.FindEntry("Champane.", false);
                    Assert.AreEqual(-1, testIndex, "Case sensitive find failure");

                    testIndex = zipFile.FindEntry("Champane.", true);
                    Assert.AreEqual(-1, testIndex, "Case insensitive find failure");

                    zipFile.Close();
                }
                store.DeleteFile(tempFile);
            }
        }
예제 #15
0
        public void FindEntriesInArchiveExtraData()
        {
            string tempFile = GetTempFilePath();
            Assert.IsNotNull(tempFile, "No permission to execute this test?");
            bool fails;
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
                string longComment = new String('A', 65535);

                FileStream tempStream = store.CreateFile(tempFile);
                MakeZipFile(tempStream, false, "", 1, 1, longComment);

                tempStream.WriteByte(85);
                tempStream.Close();

                fails = false;
                try
                {
                    using (IsolatedZipFile zipFile = new IsolatedZipFile(tempFile))
                    {
                        foreach (ZipEntry e in zipFile)
                        {
                            Stream instream = zipFile.GetInputStream(e);
                            CheckKnownEntry(instream, 1);
                        }
                        zipFile.Close();
                    }
                }
                catch
                {
                    fails = true;
                }

                store.DeleteFile(tempFile);
            }
            Assert.IsTrue(fails, "Currently zip file wont be found");
        }
예제 #16
0
        public void FindEntriesInArchiveWithLongComment()
        {
            string tempFile = GetTempFilePath();
            Assert.IsNotNull(tempFile, "No permission to execute this test?");

            tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
            string longComment = new String('A', 65535);
            MakeZipFile(tempFile, "", 1, 1, longComment);
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                try
                {
                    using (IsolatedZipFile zipFile = new IsolatedZipFile(tempFile))
                    {
                        foreach (ZipEntry e in zipFile)
                        {
                            Stream instream = zipFile.GetInputStream(e);
                            CheckKnownEntry(instream, 1);
                        }
                        zipFile.Close();
                    }
                }
                finally
                {
                    store.DeleteFile(tempFile);
                }
            }
        }
예제 #17
0
        public void RoundTrip()
        {
            string tempFile = GetTempFilePath();
            Assert.IsNotNull(tempFile, "No permission to execute this test?");

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

                    using (IsolatedZipFile zipFile = new IsolatedZipFile(tempFile))
                    {
                        foreach (ZipEntry e in zipFile)
                        {
                            Stream instream = zipFile.GetInputStream(e);
                            CheckKnownEntry(instream, 1024);
                        }
                        zipFile.Close();
                    }
                }
                finally
                {
                    store.DeleteFile(tempFile);
                }
            }
        }
예제 #18
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);
                }
            }
        }