예제 #1
0
        /// <summary>
        /// Generate 1 PlayList file
        /// </summary>
        /// <param name="aPlaylistGenerator">A class that implement the GeneratePlayList method to generate in function of the file format the wanted file</param>
        /// <param name="aDirectory">Directory from where we work</param>
        /// <param name="aMask">for example *.mp3</param>
        /// <param name="aPlayListFilename">name of the playlist file</param>
        /// <param name="aRelativePath">Works with relative or absolute paths</param>
        /// <param name="aRecursive">Include subfolders or not</param>
        private static void Run(GeneratePlaylistBase aPlaylistGenerator, string aDirectory, string aMask, string aPlayListFilename, bool aRelativePath, bool aRecursive, int minimumSong)
        {
            // List the file to include in the playlist
            List <string> files = new List <string>(Directory.EnumerateFiles(aDirectory, aMask, ConvertToSearchOption(aRecursive)));

            //In case of relative paths, retreat the path of each founded filenames
            if (aRelativePath)
            {
                var referencePath = Path.GetFullPath(aDirectory);
                referencePath = referencePath.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar;
                for (int i = 0; i < files.Count; i++)
                {
                    files[i] = PathHelper.MakeRelative(files[i], referencePath);
                }
            }

            // Generate the playlist file
            if (files.Count >= minimumSong)
            {
                aPlaylistGenerator.GeneratePlayList(aPlayListFilename, files);

                // Display a result on the console to inform user
                Console.WriteLine(string.Format("Playlist \"{0}\" generated with \"{1}\" files from directory \"{2}\"", aPlayListFilename, files.Count, aDirectory));
            }
        }
예제 #2
0
        /// <summary>
        /// Generate 1 PlayList file
        /// </summary>
        /// <param name="aPlaylistGenerator">A class that implement the GeneratePlayList method to generate in function of the file format the wanted file</param>
        /// <param name="aDirectory">Directory from where we work</param>
        /// <param name="aMask">for example *.mp3</param>
        /// <param name="aPlayListFilename">name of the playlist file</param>
        /// <param name="aRelativePath">Works with relative or absolute paths</param>
        /// <param name="aRecursive">Include subfolders or not</param>
        /// <param name="minimumSong">Minimum songs to be included in playlist</param>
        /// <param name="aSkipIfFileAlreadyExists">If file already exists, do not overwrite it</param>
        private static void RunGeneratePlayList(GeneratePlaylistBase aPlaylistGenerator, string aDirectory, string aMask, string aPlayListFilename, bool aRelativePath, bool aRecursive, int minimumSong, bool aSkipIfFileAlreadyExists, bool aNumericPrefixSort)
        {
            if (aSkipIfFileAlreadyExists && File.Exists(aPlayListFilename))
            {
                // Display on the console to inform user
                Console.WriteLine($"Skipped : Playlist \"{aPlayListFilename}\" because file already exists");
                return;
            }

            // List the file to include in the playlist
            List <string> files = new List <string>(Directory.EnumerateFiles(aDirectory, aMask, ConvertToSearchOption(aRecursive)));

            //In case of relative paths, retreat the path of each founded filenames
            if (aRelativePath)
            {
                var referencePath = Path.GetFullPath(aDirectory);
                referencePath = referencePath.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar;
                for (int i = 0; i < files.Count; i++)
                {
                    files[i] = PathHelper.PathSlashToBackslash(PathHelper.MakeRelative(files[i], referencePath));
                }
            }

            if (files.Count < minimumSong)
            {
                // Display on the console to inform user
                Console.WriteLine($"Minimun : Playlist \"{aPlayListFilename}\" not generated because threshold not reached");
                return;
            }

            // Sort files
            if (aNumericPrefixSort)
            {
                files.Sort(new NumericPrefixSortComparer());
            }

            // Generate the playlist file
            aPlaylistGenerator.GeneratePlayList(aPlayListFilename, files);

            // Display a result on the console to inform user
            Console.WriteLine($"Generated : Playlist \"{aPlayListFilename}\" with \"{files.Count}\" files from directory \"{aDirectory}\"");
        }