示例#1
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);
        }
示例#2
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);
            }
        }
示例#3
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);
            }
        }
示例#4
0
        /// <summary>
        ///     Creates the new genre user list. If there is not GenreUserList. Then
        ///     create one.
        /// </summary>
        private static void CreateNewGenreUserList()
        {
            var directoryName = GenreFileItems.GetGenreUserTemplateListDirectory();
            var userListName  = GenreFileItems.GetFileNameOfGenreUserList();

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

            genreDirPath = Path.Combine(genreDirPath, directoryName);

            var dirCreate = new DirectoryFileCopyMoveDelete();

            if (!Directory.Exists(genreDirPath))
            {
                DirectoryFileCopyMoveDelete.CreateNewDirectory(genreDirPath);
            }

            var genreFilePath = Path.Combine(genreDirPath, userListName);

            if (!File.Exists(genreFilePath))
            {
                DirectoryFileCopyMoveDelete.CreateNewFile(genreDirPath);
            }
        }