Ejemplo n.º 1
0
        /// <summary>
        ///     Reads the genre users list. Fill the
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static bool ReadGenreUsersList(string filePath)
        {
            try
            {
                MyMessages.NameOfMethod = MethodBase.GetCurrentMethod().Name;

                if (!File.Exists(filePath))
                {
                    CreateNewGenreUserList();
                    return(false);
                }

                // Read the file and display it line by line.
                using (var sr = new StreamReader(filePath))
                {
                    string genreName;
                    while ((genreName = sr.ReadLine()) != null)
                    {
                        GenreDirectoryNamesUsersCollection.AddItem(genreName);
                        GenreDirectoryNamesUsersCollection.SortCollection();
                    }
                }

                // All OK
                return(true);
            }
            catch (FileNotFoundException ex)
            {
                MyMessages.ErrorMessage = "Unable to locate this file. Possibly it has not been created yet.";
                MyMessages.BuildErrorString(
                    MyMessages.NameOfClass, MyMessages.NameOfMethod, MyMessages.ErrorMessage, ex.Message);
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Get all Genre directories from music directory.
        ///     Add all Genre directories found to genreDirectoriesCollection.
        /// </summary>
        public void GetAllGenreDirectories(string musicDirPath)
        {
            MyMessages.NameOfMethod = MethodBase.GetCurrentMethod().Name;

            if (string.IsNullOrEmpty(musicDirPath))
            {
                MyMessages.ErrorMessage = "Not a valid path to music directory.";
                MyMessages.ShowErrorMessage(MyMessages.ErrorMessage, MyMessages.NameOfMethod);
            }

            Debug.Assert(musicDirPath != null, "musicDirPath != null");
            var geneDirectories = new List <string>(
                Directory.EnumerateDirectories(musicDirPath, "*", SearchOption.TopDirectoryOnly));

            GenreDirectoryNamesUsersCollection.ClearCollection();

            if (geneDirectories.Count <= 0)
            {
                return;
            }
            foreach (var genrePath in geneDirectories)
            {
                GenreDirectoriesCollection.AddItem(genrePath);

                var itemPath = PathOperations.ReverseString(genrePath);

                var genreName = PathOperations.GetNameBeforeFirstSeparator(itemPath);

                genreName = PathOperations.ReverseString(genreName);

                // check and make sure this is a valid genre directory name. There could be other directory
                // types.
                if (ValidateOperations.ValidateFormatGenreDirectoryName(genreName))
                {
                    GenreDirectoryNamesUsersCollection.AddItem(genreName);
                    GenreFileReadWrite.WriteGenreUsersList();
                }
            }
        }