示例#1
0
        public void Test_COMPRESS_SPACE()
        {
            String FILENAME = "MultipleStorage3.cfs"; // 22Kb

            FileInfo srcFile = new FileInfo(FILENAME);

            File.Copy(FILENAME, "MultipleStorage_Deleted_Compress.cfs", true);

            CompoundFile cf = new CompoundFile("MultipleStorage_Deleted_Compress.cfs", CFSUpdateMode.Update, CFSConfiguration.SectorRecycle | CFSConfiguration.EraseFreeSectors);

            CFStorage st = cf.RootStorage.GetStorage("MyStorage");

            st = st.GetStorage("AnotherStorage");

            Assert.IsNotNull(st);
            st.Delete("Another2Stream");
            cf.Commit();
            cf.Close();

            CompoundFile.ShrinkCompoundFile("MultipleStorage_Deleted_Compress.cfs"); // -> 7Kb

            FileInfo dstFile = new FileInfo("MultipleStorage_Deleted_Compress.cfs");

            Assert.IsTrue(srcFile.Length > dstFile.Length);
        }
示例#2
0
        private void HandleFile(FileStream fs, string fileName)
        {
            var type = GetApplicationName(fileName);

            using (var cf = new CompoundFile(fs, CFSUpdateMode.Update, CFSConfiguration.SectorRecycle | CFSConfiguration.NoValidationException | CFSConfiguration.EraseFreeSectors)) {
                CFStorage storage = cf.RootStorage;

                int             numDeleted = 0;
                Action <CFItem> va         = delegate(CFItem target) {
                    bool doFilter  = ContainsPattern(storage, target.Name);
                    bool canFilter = !"DestList".Equals(target.Name);

                    if (doFilter)
                    {
                        if (canFilter)
                        {
                            Logger.Debug($"Deleting {target.Name} from {fileName} {type}");
                            storage.Delete(target.Name);
                            numDeleted++;
                        }
                        else
                        {
                            Logger.Debug($"Found but skipping {target.Name} from {fileName}");
                        }
                    }
                };
                storage.VisitEntries(va, false);

                if (numDeleted > 0)
                {
                    cf.Commit();
                    Logger.Debug($"Modifying {fileName}, deleted {numDeleted} entries");
                }
            }
        }
示例#3
0
 static void DeleteStorageChildren(CFStorage target)
 {
     target.VisitEntries(i => {
         if (i.IsStorage)
         {
             DeleteStorageChildren((CFStorage)i);
         }
         target.Delete(i.Name);
     }, false);
 }
示例#4
0
        public void Test_DELETE_STREAM_1()
        {
            String filename = "MultipleStorage.cfs";

            CompoundFile cf  = new CompoundFile(filename);
            CFStorage    cfs = cf.RootStorage.GetStorage("MyStorage");

            cfs.Delete("MySecondStream");

            cf.Save(TestContext.CurrentContext.WorkDirectory + "MultipleStorage_REMOVED_STREAM_1.cfs");
            cf.Close();
        }
示例#5
0
        public void Test_DELETE_STREAM_2()
        {
            String filename = "MultipleStorage.cfs";

            CompoundFile cf  = new CompoundFile(filename);
            CFStorage    cfs = cf.RootStorage.GetStorage("MyStorage").GetStorage("AnotherStorage");

            cfs.Delete("AnotherStream");

            cf.Save(TestContext + "MultipleStorage_REMOVED_STREAM_2.cfs");

            cf.Close();
        }
示例#6
0
        public void Test_DELETE_DIRECTORY()
        {
            String       FILENAME = "MultipleStorage2.cfs";
            CompoundFile cf       = new CompoundFile(FILENAME, CFSUpdateMode.ReadOnly, CFSConfiguration.Default);

            CFStorage st = cf.RootStorage.GetStorage("MyStorage");

            Assert.IsNotNull(st);

            st.Delete("AnotherStorage");

            cf.Save("MultipleStorage_Delete.cfs");

            cf.Close();
        }
示例#7
0
        public void Test_DELETE_MINISTREAM_STREAM()
        {
            String       FILENAME = "MultipleStorage2.cfs";
            CompoundFile cf       = new CompoundFile(FILENAME);

            CFStorage       found  = null;
            Action <CFItem> action = delegate(CFItem item) { if (item.Name == "AnotherStorage")
                                                             {
                                                                 found = item as CFStorage;
                                                             }
            };

            cf.RootStorage.VisitEntries(action, true);

            Assert.IsNotNull(found);

            found.Delete("AnotherStream");

            cf.Save("MultipleDeleteMiniStream");
            cf.Close();
        }
示例#8
0
        public void Test_DELETE_WITHOUT_COMPRESSION()
        {
            String FILENAME = "MultipleStorage3.cfs";

            FileInfo srcFile = new FileInfo(FILENAME);

            CompoundFile cf = new CompoundFile(FILENAME);

            CFStorage st = cf.RootStorage.GetStorage("MyStorage");

            st = st.GetStorage("AnotherStorage");

            Assert.IsNotNull(st);

            st.Delete("Another2Stream"); //17Kb

            //cf.CompressFreeSpace();
            cf.Save("MultipleStorage_Deleted_Compress.cfs");

            cf.Close();
            FileInfo dstFile = new FileInfo("MultipleStorage_Deleted_Compress.cfs");

            Assert.IsFalse(srcFile.Length > dstFile.Length);
        }