コード例 #1
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();
                }
            }
        }
コード例 #2
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);
        }
コード例 #3
0
        /// <summary>
        ///     If the user has made a back up file then they can restore it from here.
        /// </summary>
        public static void RestoreGenreDefaultListFromBackup()
        {
            try
            {
                MyMessages.NameOfMethod = MethodBase.GetCurrentMethod().Name;

                var validate = false;

                GenreDefaultListCollection.ClearCollection();

                using (var ofd = new OpenFileDialog())
                {
                    ofd.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
                    ofd.FilterIndex      = 2;
                    ofd.RestoreDirectory = true;
                    ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

                    if (ofd.ShowDialog() == DialogResult.OK)
                    {
                        using (var sr = new StreamReader(ofd.FileName))
                        {
                            string genreName;
                            while ((genreName = sr.ReadLine()) != null)
                            {
                                if (!validate)
                                {
                                    validate = CheckForValidGenreName(genreName);
                                }
                                else
                                {
                                    if (!string.IsNullOrEmpty(genreName))
                                    {
                                        GenreDefaultListCollection.AddItem(genreName);
                                    }
                                }
                            }
                        }
                    }
                }

                if (GenreDefaultListCollection.ItemCount() <= 0)
                {
                    return;
                }

                MyMessages.QuestionMessage = "This will overwrite your current genre default list."
                                             + " Do you wish to continue.";
                var result = MyMessages.ShowQuestionMessage(MyMessages.QuestionMessage, MyMessages.NameOfClass);
                if (result == DialogResult.Yes)
                {
                    GenreFileReadWrite.WriteGenreTemplateList();
                }
            }
            catch (FileNotFoundException ex)
            {
                MyMessages.ErrorMessage = "Not a valid path. Exiting operation.";
                MyMessages.BuildErrorString(
                    MyMessages.NameOfClass, MyMessages.NameOfMethod, MyMessages.ErrorMessage, ex.Message);
            }
            catch (ArgumentNullException ex)
            {
                MyMessages.ErrorMessage = "Not a valid path. Exiting operation.";
                MyMessages.BuildErrorString(
                    MyMessages.NameOfClass, MyMessages.NameOfMethod, MyMessages.ErrorMessage, ex.Message);
            }
        }