/// <summary>
        ///     Fills the genre template list collection with default genre directories.
        /// </summary>
        public static void FillGenreTemplateListCollection()
        {
            MyMessages.NameOfMethod = MethodBase.GetCurrentMethod().Name;

            GenreDefaultListCollection.ClearCollection();
            GenreDefaultListCollection.AddItem("#");
            GenreDefaultListCollection.AddItem(Bigbands);
            GenreDefaultListCollection.AddItem(Bluegrass);
            GenreDefaultListCollection.AddItem(Blues);
            GenreDefaultListCollection.AddItem(Cajun);
            GenreDefaultListCollection.AddItem(Calypso);
            GenreDefaultListCollection.AddItem(Caribbean);
            GenreDefaultListCollection.AddItem(Celtic);
            GenreDefaultListCollection.AddItem(Children);
            GenreDefaultListCollection.AddItem(Classical);
            GenreDefaultListCollection.AddItem(Country);
            GenreDefaultListCollection.AddItem(Dance);
            GenreDefaultListCollection.AddItem(EasyListening);
            GenreDefaultListCollection.AddItem(Finnish);
            GenreDefaultListCollection.AddItem(HipHop);
            GenreDefaultListCollection.AddItem(Holiday);
            GenreDefaultListCollection.AddItem(Insperational);
            GenreDefaultListCollection.AddItem(Instrumental);
            GenreDefaultListCollection.AddItem(Irish);
            GenreDefaultListCollection.AddItem(Japan);
            GenreDefaultListCollection.AddItem(Jazz);
            GenreDefaultListCollection.AddItem(Latin);
            GenreDefaultListCollection.AddItem(NewAge);
            GenreDefaultListCollection.AddItem(Opera);
            GenreDefaultListCollection.AddItem(Polka);
            GenreDefaultListCollection.AddItem(Pop);
            GenreDefaultListCollection.AddItem(Rap);
            GenreDefaultListCollection.AddItem(RB);
            GenreDefaultListCollection.AddItem(Reggae);
            GenreDefaultListCollection.AddItem(Rock);
            GenreDefaultListCollection.AddItem(Soul);
            GenreDefaultListCollection.AddItem(SoundTrack);
            GenreDefaultListCollection.AddItem(SouthAmerica);
            GenreDefaultListCollection.AddItem(Vocals);
            GenreDefaultListCollection.AddItem(WorkOut);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Reads the genre template list. Used to read in the list of genre
        ///     directories the user has and to create, change and add to the genre
        ///     directories list. The list is found at: /home/user-name/.local/share/MusicManager/Genre-Template-List
        /// </summary>
        /// <returns>
        ///     <c>true</c>, if genre template list was read, <c>false</c> otherwise.
        /// </returns>
        public static bool ReadGenreTemplateList()
        {
            try
            {
                MyMessages.NameOfMethod = MethodBase.GetCurrentMethod().Name;

                var directoryName    = GenreFileItems.GetGenreUserTemplateListDirectory();
                var templateListName = GenreFileItems.GetFileNameOfGenreTemplateList();

                var genreFilePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                genreFilePath = Path.Combine(genreFilePath, directoryName);
                genreFilePath = Path.Combine(genreFilePath, templateListName);

                // Read the file and display it line by line.
                using (var genreSr = new StreamReader(genreFilePath))
                {
                    string genreName;
                    while ((genreName = genreSr.ReadLine()) != null)
                    {
                        if (!string.IsNullOrEmpty(genreName))
                        {
                            GenreDefaultListCollection.AddItem(genreName);
                        }
                    }

                    GenreDefaultListCollection.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.º 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);
            }
        }