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>
        ///     Writes the genre directories contained in the users music directory
        ///     tree to File. These are the genre directories the user actually has.
        /// </summary>
        /// <returns>
        ///     <c>true</c>, if genre users list was written, <c>false</c> otherwise.
        /// </returns>
        public static bool WriteGenreUsersList()
        {
            MyMessages.NameOfMethod = MethodBase.GetCurrentMethod().Name;

            var directoryName = GenreFileItems.GetApplicationDirectory();
            var userListName  = GenreFileItems.GetFileNameOfGenreUserList();

            var genreFilePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

            genreFilePath = Path.Combine(genreFilePath, directoryName);
            genreFilePath = Path.Combine(genreFilePath, userListName);

            var count = GenreDirectoryNamesUsersCollection.ItemCount();

            if (File.Exists(genreFilePath))
            {
                if (count < 1)
                {
                    MyMessages.InformationMessage = "There are no genre directories to save to file."
                                                    + Environment.NewLine + "Exiting operation.";
                    MyMessages.ShowInformationMessageBox();
                    return(false);
                }
            }

            using (var genreStreamWriter = new StreamWriter(genreFilePath))
            {
                for (var i = 0; i < count; i++)
                {
                    var genreName = GenreDirectoryNamesUsersCollection.GetItemAt(i);
                    genreStreamWriter.WriteLine(genreName);
                }

                if (!File.Exists(genreFilePath) ||
                    new FileInfo(genreFilePath).Length == 0)
                {
                    return(true);
                }
                MyMessages.InformationMessage = "users genre list has been created and saved.";
                MyMessages.ShowInformationMessage(MyMessages.InformationMessage, MyMessages.NameOfMethod);
            }

            return(true);
        }
Ejemplo n.º 3
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();
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Check if genre name is contained in the genre template
        /// </summary>
        /// <param name="genreType"></param>
        /// <returns></returns>
        public static bool CheckGenreContainedInGenreTemplate(string genreType)
        {
            var declaringType = MethodBase.GetCurrentMethod().DeclaringType;

            if (declaringType != null)
            {
                MyMessages.NameOfClass = declaringType.Name;
            }

            MyMessages.NameOfMethod = MethodBase.GetCurrentMethod().Name;

            if (!GenreFileReadWrite.ReadGenreTemplateList())
            {
                const string msg = "Encountered error while reading genre template list. Operation canceled.";
                MyMessages.ShowErrorMessageBox(msg, MyMessages.NameOfClass, MyMessages.NameOfMethod);
                return(false);
            }

            var count = GenreDirectoryNamesUsersCollection.ItemCount();

            for (var i = 0; i < count; i++)
            {
                var item      = GenreDirectoryNamesUsersCollection.GetItemAt(i);
                var substring = genreType;

                var index = item.IndexOf(substring, StringComparison.CurrentCultureIgnoreCase);

                if (index <= -1)
                {
                    continue;
                }

                break;
            }

            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Compares the name of the genre name to current directory. Check to
        ///     see if the current directory matches the genre directory name. Some
        ///     multiple artist Cd's do not have artist directory. Compare to keep
        ///     from using genre name as artist name.
        /// </summary>
        /// <returns>True if valid artist directory name else false.</returns>
        /// <param name="directoryName">Directory name.</param>
        private bool CompareGenreNameToCurrentDirectoryName(string directoryName)
        {
            if (string.IsNullOrEmpty(directoryName))
            {
                MyMessages.ErrorMessage = "The directory name is null, or empty";
                MyMessages.ShowErrorMessage(MyMessages.ErrorMessage, MyMessages.NameOfMethod);
            }

            var cnt = GenreDirectoryNamesUsersCollection.ItemCount();

            for (var i = 0; i < cnt; i++)
            {
                var comp = string.Compare(
                    GenreDirectoryNamesUsersCollection.GetItemAt(i), directoryName,
                    StringComparison.CurrentCultureIgnoreCase);

                if (comp == 0)
                {
                    return(true);
                }
            }

            return(false);
        }