/// <summary>
 /// Сменить вкладку
 /// </summary>
 private void TabControlLists_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     _curTabType = TabControlLists.SelectedIndex == 0 ? BlockTabType.Artists : BlockTabType.Songs;
     SetTitle();
 }
 /// <summary>
 /// Вручную обновить лист блокировки.
 /// </summary>
 private void RefreshList(BlockTabType tabType)
 {
     if (tabType == BlockTabType.Artists)
         DataGridArtists.Items.Refresh();
     else
         DataGridSongs.Items.Refresh();
 }
        /// <summary>
        /// Открыть диалог открытия файлов.
        /// </summary>
        /// <param name="multiselect">Можно ли выбрать много файлов</param>
        /// <param name="tabType">Тип блокировки</param>
        /// <param name="headers">Использовать файлы песен или листов</param>
        /// <returns></returns>
        private string[] ShowOpenFileDialog(bool multiselect, BlockTabType tabType, bool headers = false)
        {
            var loadDialog = new OpenFileDialog();
            loadDialog.Multiselect = multiselect;
            var txtFilter = "|Text files (*.txt)|*.txt";
            var allFilter = "|All files (*.*)|*.*";
            var avkFilter = "Artists files (*.avk)|*.avk" + txtFilter + allFilter;
            var svkFilter = "Songs files (*.svk)|*.svk" + txtFilter + allFilter;

            var musicFilter = "Audio|*.mp3;*.wma;*.flac;*.m4a;*.aac;*.wav";

            if (headers != true)
                loadDialog.Filter = _curTabType == BlockTabType.Artists ? avkFilter : svkFilter;
            else
            {
                loadDialog.Filter = (musicFilter + allFilter);
            }
            if (loadDialog.ShowDialog() != true) return null;
            return loadDialog.FileNames;
        }
        /// <summary>
        /// Добавить в список блокировки коллекции.
        /// </summary>
        /// <param name="fileNames">Коллекция</param>
        private void ParseFiles(string[] fileNames, BlockTabType tabType)
        {
            var wrongsFiles = "";
            foreach (var fileName in fileNames)
            {

            #if !DEBUG
                try
                {
            #endif
                _mainWindow.BlockCollection(fileName, tabType);
            #if !DEBUG
                }
                catch (Exception file)
                {
                    wrongsFiles += "\n" + file.Message;
                }
            #endif
            }
            if (wrongsFiles != "")
            {
                MessageBox.Show("Next files can't open:" + wrongsFiles);
            }
        }
 /// <summary>
 /// Добавить в список блокировки названия песен.
 /// </summary>
 /// <param name="fileHeaders"></param>
 /// <param name="tabType"></param>
 private void ParsreFilesHeaders(string[] fileHeaders, BlockTabType tabType)
 {
     var wrongsFiles = "";
     foreach (var fileHeader in fileHeaders)
     {
     #if !DEBUG
         try
         {
     #endif
             _mainWindow.BlockHeader(fileHeader, tabType);
     #if !DEBUG
         }
         catch (Exception file)
         {
             wrongsFiles += "\n" + file.Message;
         }
     #endif
     }
     if (wrongsFiles != "")
     {
         MessageBox.Show("Next files headers can't parse:" + wrongsFiles);
     }
 }
 /// <summary>
 /// Замещение текущего листа.
 /// </summary>
 private void OpenFile(string fileName, BlockTabType tabType)
 {
     try
     {
         ClearCurList();
         _mainWindow.BlockCollection(fileName, tabType);
         if (tabType == BlockTabType.Artists)
             Settings.PathCurUsedArtists = fileName;
         else
             Settings.PathCurUsedSongs = fileName;
         SetTitle();
     }
     catch (Exception fileException)
     {
         MessageBox.Show("Can't open file: " + fileException);
         throw;
     }
 }
 /// <summary>
 /// Новый файл списка блокировки.
 /// </summary>
 /// <param name="tabType"></param>
 private void NewFile(BlockTabType tabType)
 {
     ClearCurList();
     if (tabType == BlockTabType.Artists)
     {
         Settings.PathCurUsedArtists = "New";
     }
     else
     {
         Settings.PathCurUsedSongs = "New";
     }
     SetTitle();
 }
 /// <summary>
 /// Запись списка блокировки в файл
 /// </summary>
 /// <param name="fileFullName">Полный путь к файлу</param>
 /// <param name="tabType">Тип нужного листа</param>
 public void WriteFile(string fileFullName, BlockTabType tabType)
 {
     using (StreamWriter fileWriter = new StreamWriter(fileFullName))
     {
         if (tabType == BlockTabType.Artists)
         {
             foreach (var artist in BlockedArtistList)
             {
                 fileWriter.WriteLine(artist.Artist);
             }
         }
         else
         {
             foreach (var artist in BlockedSongList)
             {
                 fileWriter.WriteLine(artist.Artist + " - " + artist.Title);
             }
         }
     }
 }
 /// <summary>
 /// Добавить в список блокировки по названию файла
 /// </summary>
 /// <param name="filePath">Путь до файла</param>
 /// <param name="tabType">Тип блокировки</param>
 public void BlockHeader(string filePath, BlockTabType tabType)
 {
     #if !DEBUG
     try
     {
     #endif
         var fileName = Path.GetFileNameWithoutExtension(filePath);
         var indexOfSep = fileName.IndexOf(" - ");
         if (indexOfSep == -1)
             throw new Exception();
         var artist = fileName.Substring(0, indexOfSep);
         if (tabType == BlockTabType.Artists)
         {
             BlockedArtistList.Add(new ArtistToBind(artist));
         }
         else
         {
             var title = fileName.Substring(indexOfSep + 3);
             BlockedSongList.Add(new ArtistTitleToBind(artist, title));
         }
     #if !DEBUG
     }
     catch (Exception)
     {
         throw new Exception("fileName");
     }
     #endif
 }
 /// <summary>
 /// Добавить элементы из коллекции в лист блокировки.
 /// </summary>
 /// <param name="fileName">Путь</param>
 /// <param name="tabType">Тип листа</param>
 public void BlockCollection(string fileName, BlockTabType tabType)
 {
     #if !DEBUG
     try
     {
     #endif
         using (var fileReader = new StreamReader(fileName))
         {
             string line;
             while ((line = fileReader.ReadLine()) != null)
             {
                 if (tabType == BlockTabType.Artists)
                 {
                     BlockedArtistList.Add(new ArtistToBind(line));
                 }
                 else
                 {
                     var indexOfSep = line.IndexOf(" - ");
                     if (indexOfSep == -1)
                         throw new Exception();
                     var artist = line.Substring(0, indexOfSep);
                     var title = line.Substring(indexOfSep + 3);
                     BlockedSongList.Add(new ArtistTitleToBind(artist, title));
                 }
             }
         }
     #if !DEBUG
     }
     catch (Exception)
     {
         throw new Exception("fileName");
     }
     #endif
 }