Пример #1
0
        /// <summary>
        /// Gets a list of songs in a folder, non-recursive
        /// </summary>
        public IReadOnlyList <PublicModels.Song> GetSongsInFolder(string folderPath)
        {
            ThrowIfNotReady();

            SHA1 sha1 = SHA1.Create();

            string firstPathPart = MediaUtils.GetFirstPathElement(folderPath);
            string realPath      = MediaUtils.ReplaceFirstPathElement(folderPath, MediaFolderUniquePaths[firstPathPart]);

            var files = Directory.EnumerateFiles(realPath);

            List <PublicModels.Song> songs = new List <PublicModels.Song>();

            foreach (var file in files)
            {
                var    hashBytes = sha1.ComputeHash(File.ReadAllBytes(file));
                string hash      = HashUtils.BytesToHexString(hashBytes);

                var rawSong = DBContext.Song.Find(hash);
                if (rawSong != null)
                {
                    var song = PublicModels.Song.FromDBObject(rawSong, DBContext);
                    songs.Add(song);
                }
            }

            return(songs);
        }
Пример #2
0
        /// <summary>
        /// Gets a list of subfolders within a media folder
        /// </summary>
        public IReadOnlyList <string> GetFoldersInFolder(string folderPath)
        {
            ThrowIfNotReady();

            string firstPathPart = MediaUtils.GetFirstPathElement(folderPath);
            string realPath      = MediaUtils.ReplaceFirstPathElement(folderPath, MediaFolderUniquePaths[firstPathPart]);

            return(Directory.EnumerateDirectories(realPath).Select(d => new DirectoryInfo(d).Name).ToImmutableArray());
        }
Пример #3
0
        /// <summary>
        /// Gets if a media folder exists and is valid
        /// </summary>
        public bool GetFolderExists(string folderPath)
        {
            ThrowIfNotReady();

            //so the idea is:
            //check if the first segment matches one of our root paths. Fail if it doesn't. Replace with real path if it does
            string firstPathPart = MediaUtils.GetFirstPathElement(folderPath);

            if (!MediaFolderUniquePaths.ContainsKey(firstPathPart))
            {
                return(false);
            }
            //check if the real path exists on disk. Success if it does
            string realPath = MediaUtils.ReplaceFirstPathElement(folderPath, MediaFolderUniquePaths[firstPathPart]);

            if (Directory.Exists(realPath))
            {
                return(true);
            }

            return(false);
        }