コード例 #1
0
ファイル: Class1.cs プロジェクト: systembugtj/bookasa
        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);
                }
            }
        }
コード例 #2
0
ファイル: Class1.cs プロジェクト: systembugtj/bookasa
        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);
                }
            }
        }
コード例 #3
0
ファイル: MainPage.xaml.cs プロジェクト: systembugtj/bookasa
        /// <summary>
        /// </summary>
        private void ZipFileFromISO(object sender, RoutedEventArgs e)
        {
            DeleteSampleText();

            /*
             *  Extract an archive using IsolatedZipFile
             *************************************************************
             */

            using (var zip = new IsolatedZipFile(SampleZipFileName))
            {
                var entry = zip.GetEntry(SampleTextFileName);
                using (var streamIn = zip.GetInputStream(entry))
                {
                    using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        using (var streamOut = store.OpenFile(SampleTextFileName, FileMode.Create))
                        {
                            streamIn.CopyTo(streamOut);
                        }
                    }
                }
            }

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

            DisplayMetrics("ZipFileFromISO", false);
        }
        public void Noid()
        {
            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream fs = store.CreateFile("foo.txt"))
                {
                    using (var writer = new StreamWriter(fs))
                    {
                        writer.Write("Foo Bar FU!");
                    }
                }

                store.CreateDirectory("foobarfu");
                string fooText = Guid.NewGuid().ToString();
                using (var createdFile = store.CreateFile("foo.txt"))
                {
                    using (var writer = new StreamWriter(createdFile))
                    {

                        writer.Write(fooText);
                    }
                }

                using (var createdFile = store.CreateFile("foobarfu\\foo.txt"))
                {
                    using (var writer = new StreamWriter(createdFile))
                    {

                        writer.Write(fooText);
                    }
                }


                var factory = new IsolatedZipEntryFactory();

                ZipEntry fentry = factory.MakeFileEntry("foo.txt");

                ZipEntry dentry = factory.MakeDirectoryEntry("foobarfu");


                using (var f = IsolatedZipFile.Create("foo.zip"))
                {
                    f.BeginUpdate();
                    f.Add("foo.txt");
                    f.CommitUpdate();
                }

                using (var f = new IsolatedZipFile("foo.zip"))
                {
                    var entry = f.GetEntry("foo.txt");
                    string content = new StreamReader(f.GetInputStream(entry)).ReadToEnd();
                    Assert.AreEqual(fooText, content);
                }

                var fz = new IsolatedFastZip();
                fz.CreateZip("fz.zip", "foobarfu", true, "");
            }
        }
コード例 #5
0
        public void Noid()
        {
            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream fs = store.CreateFile("foo.txt"))
                {
                    using (var writer = new StreamWriter(fs))
                    {
                        writer.Write("Foo Bar FU!");
                    }
                }

                store.CreateDirectory("foobarfu");
                string fooText = Guid.NewGuid().ToString();
                using (var createdFile = store.CreateFile("foo.txt"))
                {
                    using (var writer = new StreamWriter(createdFile))
                    {
                        writer.Write(fooText);
                    }
                }

                using (var createdFile = store.CreateFile("foobarfu\\foo.txt"))
                {
                    using (var writer = new StreamWriter(createdFile))
                    {
                        writer.Write(fooText);
                    }
                }


                var factory = new IsolatedZipEntryFactory();

                ZipEntry fentry = factory.MakeFileEntry("foo.txt");

                ZipEntry dentry = factory.MakeDirectoryEntry("foobarfu");


                using (var f = IsolatedZipFile.Create("foo.zip"))
                {
                    f.BeginUpdate();
                    f.Add("foo.txt");
                    f.CommitUpdate();
                }

                using (var f = new IsolatedZipFile("foo.zip"))
                {
                    var    entry   = f.GetEntry("foo.txt");
                    string content = new StreamReader(f.GetInputStream(entry)).ReadToEnd();
                    Assert.AreEqual(fooText, content);
                }

                var fz = new IsolatedFastZip();
                fz.CreateZip("fz.zip", "foobarfu", true, "");
            }
        }
コード例 #6
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);
                }
            }
        }
コード例 #7
0
ファイル: Class1.cs プロジェクト: systembugtj/bookasa
        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);
                }
            }
        }
コード例 #8
0
ファイル: Class1.cs プロジェクト: systembugtj/bookasa
        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);
            }
        }
コード例 #9
0
ファイル: Class1.cs プロジェクト: systembugtj/bookasa
        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");
        }
コード例 #10
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");
        }
コード例 #11
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);
                }
            }
        }
コード例 #12
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);
                }
            }
        }
コード例 #13
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);
            }
        }
コード例 #14
0
        /// <summary>
        /// </summary>
        private void ZipFileFromISO(object sender, RoutedEventArgs e)
        {
            DeleteSampleText();

            /*
             *  Extract an archive using IsolatedZipFile
             *************************************************************
             */

            using (var zip = new IsolatedZipFile(SampleZipFileName))
            {
                var entry = zip.GetEntry(SampleTextFileName);
                using (var streamIn = zip.GetInputStream(entry))
                {
                    using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        using (var streamOut = store.OpenFile(SampleTextFileName, FileMode.Create))
                        {
                            streamIn.CopyTo(streamOut);
                        }
                    }
                }
            }

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

            DisplayMetrics("ZipFileFromISO", false);
        }