Beispiel #1
0
        public void TestAllFilesAndFolders()
        {
            int    files = 0, folders = 0, total = 0;
            string dir = TestFolder;

            FindFile.AllFilesIn(dir, e => { Assert.IsTrue(File.Exists(e.FullPath)); files++; });
            FindFile.AllFoldersIn(dir, e => { Assert.IsTrue(Directory.Exists(e.FullPath)); folders++; });
            FindFile.AllFilesAndFoldersIn(dir, e => { Assert.IsTrue(File.Exists(e.FullPath) || Directory.Exists(e.FullPath)); total++; });
            Assert.AreEqual(6, files);
            Assert.AreEqual(2, folders);
            Assert.AreEqual(8, total);
        }
        public void TestCancel()
        {
            int total = 0;

            FindFile.AllFilesAndFoldersIn(TestFolder,
                                          e =>
            {
                Assert.IsTrue(File.Exists(e.FullPath));
                total++;
                e.CancelEnumeration = true;
            });
            Assert.AreEqual(1, total);
        }
 public static bool TryMakeSubDirTipPath(ref string path)
 {
     if (!string.IsNullOrEmpty(path))
     {
         bool flag;
         if (path.StartsWith("::"))
         {
             using (IDLWrapper wrapper = new IDLWrapper(path)) {
                 return(wrapper.IsFolder);
             }
         }
         if (path.StartsWith(@"a:\", StringComparison.OrdinalIgnoreCase) || path.StartsWith(@"b:\", StringComparison.OrdinalIgnoreCase))
         {
             return(false);
         }
         if (!Directory.Exists(path))
         {
             if (!File.Exists(path) || !Path.GetExtension(path).PathEquals(".lnk"))
             {
                 return(false);
             }
             path = GetLinkTargetPath(path);
             if (!Directory.Exists(path))
             {
                 return(false);
             }
         }
         FileSystemInfo targetIfFolderLink = GetTargetIfFolderLink(new DirectoryInfo(path), out flag);
         if (flag)
         {
             bool fSearchHidden;
             bool fSearchSystem;
             QTUtility.GetHiddenFileSettings(out fSearchHidden, out fSearchSystem);
             bool flag4 = Config.Tips.SubDirTipsFiles;
             path = targetIfFolderLink.FullName;
             using (FindFile file = new FindFile(path, fSearchHidden, fSearchSystem)) {
                 return(file.SubDirectoryExists() || (flag4 && file.SubFileExists()));
             }
         }
     }
     return(false);
 }
        public void TestFindFileProperties()
        {
            FindFile ff = new FindFile();

            Assert.AreEqual("", ff.BaseDirectory);
            Assert.AreEqual("*", ff.FilePattern);
            Assert.AreEqual(true, ff.Recursive);
            Assert.AreEqual(true, ff.IncludeFiles);
            Assert.AreEqual(true, ff.IncludeFolders);
            Assert.AreEqual(false, ff.RaiseOnAccessDenied);
            Assert.AreEqual(4096, ff.MaxPath);

            Assert.AreEqual(TestFolder, ff.BaseDirectory = TestFolder);
            Assert.AreEqual("a.*", ff.FilePattern        = "a.*");
            Assert.AreEqual(false, ff.Recursive          = false);
            Assert.AreEqual(false, ff.IncludeFiles       = false);
            Assert.AreEqual(false, ff.IncludeFolders     = false);
            Assert.AreEqual(true, ff.RaiseOnAccessDenied = true);
            Assert.AreEqual(1024, ff.MaxPath             = 1024);

            ff.FileFound += (o, e) => Assert.Fail("Should not find anything.");
            ff.Find();
        }
        public void TestAccessDenied()
        {
            string child2 = Path.Combine(TestFolder, @"child1\child2");

            DirectorySecurity acl = Directory.GetAccessControl(child2);

            byte[] original = acl.GetSecurityDescriptorBinaryForm();
            acl.AddAccessRule(
                new FileSystemAccessRule(
                    new SecurityIdentifier(WellKnownSidType.WorldSid, null),
                    FileSystemRights.ListDirectory,
                    AccessControlType.Deny)
                );
            Directory.SetAccessControl(child2, acl);
            try
            {
                //By default it ignores AccessDenied
                FindFile ff = new FindFile(child2, "*", false, false);
                ff.FileFound += (o, e) => Assert.Fail("Should not find a file");
                ff.Find();

                //Now raise the AccessDenied
                ff.RaiseOnAccessDenied = true;
                try
                {
                    ff.Find();
                    Assert.Fail("Should throw Access Denied.");
                }
                catch (System.ComponentModel.Win32Exception we)
                { Assert.AreEqual(5, we.NativeErrorCode); }
            }
            finally
            {
                acl.SetSecurityDescriptorBinaryForm(original, AccessControlSections.All);
                Directory.SetAccessControl(child2, acl);
            }
        }
 public static bool TryMakeSubDirTipPath(ref string path) {
     if(!string.IsNullOrEmpty(path)) {
         bool flag;
         if(path.StartsWith("::")) {
             using(IDLWrapper wrapper = new IDLWrapper(path)) {
                 return wrapper.IsFolder;
             }
         }
         if(path.StartsWith(@"a:\", StringComparison.OrdinalIgnoreCase) || path.StartsWith(@"b:\", StringComparison.OrdinalIgnoreCase)) {
             return false;
         }
         if(!Directory.Exists(path)) {
             if(!File.Exists(path) || !Path.GetExtension(path).PathEquals(".lnk")) {
                 return false;
             }
             path = GetLinkTargetPath(path);
             if(!Directory.Exists(path)) {
                 return false;
             }
         }
         FileSystemInfo targetIfFolderLink = GetTargetIfFolderLink(new DirectoryInfo(path), out flag);
         if(flag) {
             bool fSearchHidden = QTUtility.CheckConfig(Settings.SubDirTipsHidden);
             bool fSearchSystem = QTUtility.CheckConfig(Settings.SubDirTipsSystem);
             bool flag4 = QTUtility.CheckConfig(Settings.SubDirTipsFiles);
             path = targetIfFolderLink.FullName;
             using(FindFile file = new FindFile(path, fSearchHidden, fSearchSystem)) {
                 return (file.SubDirectoryExists() || (flag4 && file.SubFileExists()));
             }
         }
     }
     return false;
 }
            public IEnumerable <IDirectoryCacheProviderFileInfo> GetFilesInFolder(string folder)
            {
                FindFile findFile = new FindFile();  // <- interop workaround for slow DirectoryInfo.GetFiles(), we can replace this with DirectoryInfo in .NET 4

                return(findFile.GetFiles(folder).Select(fi => (IDirectoryCacheProviderFileInfo)(new DefaultDirectoryCacheProviderFileInfo(fi))));
            }
Beispiel #8
0
 public void SetFindFile(FindFile findFile)
 {
     this.findFile = findFile;
 }