예제 #1
0
        /// <summary>
        ///     Writes the genre template list.
        /// </summary>
        /// <returns>
        ///     <c>true</c>, if genre template list was write, <c>false</c> otherwise.
        /// </returns>
        public static bool WriteGenreTemplateList()
        {
            try
            {
                MyMessages.NameOfMethod = MethodBase.GetCurrentMethod().Name;

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

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

                var count = GenreDefaultListCollection.ItemCount();

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

                return(true);
            }
            catch (FileNotFoundException ex)
            {
                MyMessages.ErrorMessage = "Unable to find file.";
                MyMessages.BuildErrorString(
                    MyMessages.NameOfClass, MyMessages.NameOfMethod, MyMessages.ErrorMessage, ex.Message);
                return(false);
            }
            catch (IOException ex)
            {
                MyMessages.ErrorMessage = "Encountered error while writing to file. Operation canceled.";
                MyMessages.BuildErrorString(
                    MyMessages.NameOfClass, MyMessages.NameOfMethod, MyMessages.ErrorMessage, ex.Message);
                return(false);
            }
        }
예제 #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);
            }
        }