Example #1
0
 public IList<string> FindFiles(ISearchQuery searchQuery, FileTypes fileType, FileListSort fileListSort)
 {
     return FindFiles(searchQuery, new List<FileTypes>(new FileTypes[] { fileType }), fileListSort);
 }
Example #2
0
        public IList<string> FindFiles(ISearchQuery searchQuery, IList<FileTypes> fileTypes, FileListSort fileListSort)
        {
            List<string> result = new List<string>();

            if (configSettings.MusicDirectories.Count == 0)
                return result;
            StringBuilder search = new StringBuilder();

            foreach (string wa in searchQuery.WantedAtoms) {
                search.Append("*");
                search.Append(wa);
            }
            search.Append("*.");

            foreach (FileTypes fileTypeEnum in fileTypes) {
                string fileType;
                if (FileTypes.ALL == fileTypeEnum)
                    fileType = "*";
                else
                    fileType = fileTypeEnum.ToString();

                fileType = fileType.ToLower();

                foreach (string musicDir in configSettings.MusicDirectories) {
                    string[] found;
                    try {
                        //PROBLEM! http://www.mono-project.com/IOMap also man mono
                        found = fileSystem.GetFiles(musicDir, search + fileType, SearchOption.AllDirectories);
                    }
                    catch {
                        found = new string[0];
                    }
                    foreach (string hit in found) {
                        //don't add it twice, and discard any extension-greater-than-three-characters microsoft retardedness:
                        //http://msdn2.microsoft.com/en-us/library/ms143316(VS.80).aspx
                        if ((result.Contains(hit)) ||
                            ((Path.GetExtension(hit).ToLower() != ("." + fileType).ToLower()) && (FileTypes.ALL != fileTypeEnum)))
                        continue;

                        //also don't add it if it contains unwanted atoms
                        bool add = true;
                        foreach (string uwa in searchQuery.UnwantedAtoms)
                            if (Regex.IsMatch(Path.GetFileNameWithoutExtension(hit), Regex.Escape(uwa), RegexOptions.IgnoreCase)) {
                                add = false;
                                break;
                            }
                        if (add)
                            result.Add(hit);
                    }
                }
            }
            switch (fileListSort) {
                case FileListSort.SmallestFirst:
                    result.Sort(new FilenameComparer(true));
                    break;
                case FileListSort.LargestFirst:
                    result.Sort(new FilenameComparer(false));
                    break;
                case FileListSort.Random:
                    Randomise(result);
                    break;
            }

            return result;
        }
Example #3
0
        public void VariousResultSorts(FileListSort fileListSort, string first, string second, string third)
        {
            string[] foundFiles = new string[] { "a dog track.mp3",
                "a dog and fish track.mp3",
                "a dog and cat track.mp3"
            };

            SetupResult.For(_searchQuery.WantedAtoms).Return(new List<string>(new string[] { }));
            SetupResult.For(_configSettings.MusicDirectories).Return(new List<string>(new string[] { "somePath" }));
            SetupResult.For(_searchQuery.UnwantedAtoms).Return(new List<string>(new string[] { }));
            Expect.Call(_fileSystem.GetFiles(null, null, SearchOption.AllDirectories)).IgnoreArguments().Return(foundFiles);
            ReplayAll();

            IList<string> result = _fileFinder.FindFiles(_searchQuery, FileTypes.MP3, fileListSort);
            Assert.AreEqual(3, result.Count);
            Assert.AreEqual(first, result[0]);
            Assert.AreEqual(second, result[1]);
            Assert.AreEqual(third, result[2]);

            VerifyAll();
        }