Ejemplo n.º 1
0
        public void ExtractEmptyDirectories()
        {
            string tempFilePath = GetTempFilePath();

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

            string name = Path.Combine(tempFilePath, "x.zip");

            EnsureTestDirectoryIsEmpty(tempFilePath);

            string targetDir = Path.Combine(tempFilePath, ZipTempDir + @"\floyd");

            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (var fs = store.CreateFile(name))
                {
                    using (ZipOutputStream zOut = new ZipOutputStream(fs))
                    {
                        zOut.PutNextEntry(new ZipEntry("floyd/"));
                    }
                }

                IsolatedFastZip fastZip = new IsolatedFastZip();
                fastZip.CreateEmptyDirectories = true;
                fastZip.ExtractZip(name, targetDir, "zz");

                store.DeleteFile(name);
                Assert.IsTrue(Directory.Exists(targetDir), "Empty directory should be created");
            }
        }
Ejemplo n.º 2
0
        public void UnicodeText()
        {
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                IsolatedFastZip zippy   = new IsolatedFastZip();
                ZipEntryFactory factory = new ZipEntryFactory();
                factory.IsUnicodeText = true;
                zippy.EntryFactory    = factory;

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

                const string tempName1 = "a.dat";
                string       addFile   = Path.Combine(tempFilePath, tempName1);
                MakeTempFile(addFile, 1);

                try
                {
                    MemoryStream target = new MemoryStream();
                    zippy.CreateZip(target, tempFilePath, false, tempName1, null); // failing here in 4

                    MemoryStream archive = new MemoryStream(target.ToArray());

                    using (IsolatedZipFile z = new IsolatedZipFile(archive))
                    {
                        Assert.AreEqual(1, z.Count);
                        Assert.IsTrue(z[0].IsUnicodeText);
                    }
                }
                finally
                {
                    store.DeleteFile(addFile);
                }
            }
        }
Ejemplo n.º 3
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, "");
            }
        }
Ejemplo n.º 4
0
        public void ExtractExceptions()
        {
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                IsolatedFastZip fastZip      = new IsolatedFastZip();
                string          tempFilePath = GetTempFilePath();
                Assert.IsNotNull(tempFilePath, "No permission to execute this test?");

                string addFile = Path.Combine(tempFilePath, "test.zip");
                try
                {
                    fastZip.ExtractZip(addFile, @"z:\doesnt exist", null);
                }
                finally
                {
                    store.DeleteFile(addFile);
                }
            }
        }
Ejemplo n.º 5
0
        public void NonAsciiPasswords()
        {
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                const string tempName1 = "a.dat";

                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);

                string password = "******";
                try
                {
                    IsolatedFastZip fastZip = new IsolatedFastZip();
                    fastZip.Password = password;

                    fastZip.CreateZip(target, tempFilePath, false, @"a\.dat", null); // failing here in 4

                    MemoryStream archive = new MemoryStream(target.ToArray());
                    using (IsolatedZipFile zf = new IsolatedZipFile(archive))
                    {
                        zf.Password = password;
                        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));
                        Assert.IsTrue(entry.IsCrypted);
                    }
                }
                finally
                {
                    store.DeleteFile(tempName1);
                }
            }
        }