Example #1
0
        /// <summary>
        /// Extracts the package to the specified <see cref="DirectoryMap"/>
        /// </summary>
        /// <param name="directory"></param>
        /// <param name="args"></param>
        public void ExtractTo(DirectoryMap directory, TurtleExtractArgs args)
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }
            else if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            ExtractFiles(args, delegate(ExtractorEventArgs e)
            {
                PackFile file        = e.PackFile;
                DirectoryMapFile dmf = directory.GetFile(file.RelativePath);

                if ((dmf == null) || !dmf.Unmodified() || !QQnCryptoHelpers.HashComparer.Equals(dmf.FileHash, file.FileHash))
                {
                    using (Stream s = directory.CreateFile(file.RelativePath, file.FileHash, file.FileSize))
                    {
                        QQnPath.CopyStream(e.Stream, s);
                    }
                }
                else
                {
                    directory.UnscheduleDelete(file.RelativePath);                     // Make sure it stays
                }
            });
        }
Example #2
0
        public void TestFileWrite()
        {
            ClearMap();
            using (DirectoryMap dm = DirectoryMap.Get(DirMapPath))
            {
                using (Stream fs = dm.CreateFile("test.txt"))
                {
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        sw.WriteLine("46357865-EFF5-454B-9B8F-845C6C17F9D5");
                    }
                }

                using (Stream fs = dm.CreateFile("sd/test.txt"))
                {
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        sw.WriteLine("46357865-EFF5-454B-9B8F-845C6C17F9D5");
                    }
                }

                using (Stream fs = dm.CreateFile("q/r/s/test.txt"))
                {
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        sw.WriteLine("46357865-EFF5-454B-9B8F-845C6C17F9D5");
                    }
                }

                DirectoryMapFile mf = dm.GetFile("test.txt");

                Assert.That(mf, Is.Not.Null);
            }

            using (DirectoryMap dm = DirectoryMap.Get(DirMapPath))
            {
                Assert.That(dm.GetFile("test.txt"), Is.Not.Null);
                Assert.That(dm.GetFile("-not-existing"), Is.Null);

                Assert.That(dm.GetFile("sD/TeSt.TXT"), Is.Not.Null);

                Assert.That(dm.GetFile("q/r/s/TEST.txt"), Is.Not.Null);
                Assert.That(dm.GetFile("q\\r/s/./test.txt"), Is.Not.Null, "non-normalized file exists");

                Assert.That(dm.GetFile("test.txT").FileSize, Is.EqualTo(38L));
                Assert.That(dm.GetFile("test.txT").FileHash, Is.EqualTo("b2cf3a852a1793273d1029ea777099523da1f734,type=SHA1"));

                DirectoryMapFile dmf = dm.GetFile("test.txt");

                Assert.That(VerifyUtils.VerifyFile(DirMapPath, dmf, VerifyMode.Full), "File is the same in full");

                Assert.That(VerifyUtils.VerifyFile(DirMapPath, dmf, VerifyMode.Time), Is.True, "File is the same in time");
                Assert.That(VerifyUtils.VerifyFile(DirMapPath, dmf, VerifyMode.TimeSize), Is.True, "File is the same in size");
                Assert.That(VerifyUtils.VerifyFile(DirMapPath, dmf, VerifyMode.FileHash), Is.True, "File is the same in filehash");

                File.SetLastWriteTime(dm.GetFile("test.txt").FullName, DateTime.Now);
                Assert.That(VerifyUtils.VerifyFile(DirMapPath, dmf, VerifyMode.Time), Is.False, "File time changed");
                Assert.That(VerifyUtils.VerifyFile(DirMapPath, dmf, VerifyMode.TimeSize), Is.False, "FileTime+Size changed");
                Assert.That(VerifyUtils.VerifyFile(DirMapPath, dmf, VerifyMode.FileHash), Is.True, "File is the same in filehash");
                Assert.That(VerifyUtils.VerifyFile(DirMapPath, dmf, VerifyMode.Full), Is.True, "File has not changed");

                dmf.Update();

                Assert.That(VerifyUtils.VerifyFile(DirMapPath, dmf, VerifyMode.TimeSize), "File is the same in timesize after update");
                Assert.That(VerifyUtils.VerifyFile(DirMapPath, dmf, VerifyMode.Full), "File is the same in full");
            }
        }