private BrowseMusicResponse BrowseMusic()
        {
            BrowseMusicResponse resp = new BrowseMusicResponse();

            Microsoft.Win32.OpenFileDialog openDialog = new Microsoft.Win32.OpenFileDialog()
            {
                DefaultExt  = ".mp3",
                Filter      = "MP3 File (*.mp3)|*.mp3|WAV File (*.wav)|*.wav|All files (*.*)|*.*",
                Multiselect = true
            };

            bool?openResult = openDialog.ShowDialog();

            if (openResult == true)
            {
                for (int i = 0; i < openDialog.FileNames.Length; i++)
                {
                    if (string.IsNullOrWhiteSpace(openDialog.FileNames[i]))
                    {
                        continue;
                    }
                    Match soundPathMatch = Regex.Match(openDialog.FileNames[i] + ":", @"\\sound\\(.*?):", RegexOptions.IgnoreCase);
                    if (soundPathMatch.Success)
                    {
                        int musicDuration = 0;
                        if (openDialog.FileNames[i].EndsWith(".wav"))
                        {
                            musicDuration = GetWavFileDuration(openDialog.FileNames[i]);
                        }
                        else if (openDialog.FileNames[i].EndsWith(".mp3"))
                        {
                            musicDuration = GetMp3FileDuration(openDialog.FileNames[i]);
                        }

                        resp.MusicList.Add(new Core.Classes.SoundPkg.MusicSound()
                        {
                            Path   = string.Format("sound\\{0}", soundPathMatch.Groups[1].Value),
                            Length = musicDuration
                        });
                        resp.Result = BrowseResult.Found;
                    }
                }
            }
            else
            {
                resp.Result = BrowseResult.Canceled;
            }
            return(resp);
        }
 private void AddBtn_Click(object sender, RoutedEventArgs e)
 {
     if (sender == null)
     {
         return;
     }
     if (sender is Button senderBtn)
     {
         if (senderBtn.Tag.ToString() == "music")
         {
             BrowseMusicResponse browseResp = BrowseMusic();
             if (browseResp.Result == BrowseResult.Found)
             {
                 foreach (Core.Classes.SoundPkg.MusicSound music in browseResp.MusicList)
                 {
                     ActualBoss.Sounds.Music.Add(music);
                 }
             }
             else if (browseResp.Result == BrowseResult.NotFound)
             {
                 MessageBox.Show("The music must be located in a folder called sound (without 's').", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
             }
         }
         else if (senderBtn.Tag.ToString() == "ability")
         {
             BrowseSoundResponse browseResp = BrowseSounds();
             if (browseResp.Result == BrowseResult.Found)
             {
                 foreach (string path in browseResp.PathList)
                 {
                     ActualBoss.Sounds.Ability.Add(new Core.Classes.SoundPkg.AbilitySound()
                     {
                         Path = path
                     });
                 }
             }
             else if (browseResp.Result == BrowseResult.NotFound)
             {
                 MessageBox.Show("The sounds must be located in a folder called sound (without 's').", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
             }
         }
         else
         {
             ObservableCollection <Core.Classes.SoundPkg.Sound> pkg = GetCollectionByTag(senderBtn.Tag.ToString());
             if (pkg != null)
             {
                 BrowseSoundResponse browseResp = BrowseSounds();
                 if (browseResp.Result == BrowseResult.Found)
                 {
                     foreach (string path in browseResp.PathList)
                     {
                         pkg.Add(new Core.Classes.SoundPkg.Sound()
                         {
                             Path = path
                         });
                     }
                 }
                 else if (browseResp.Result == BrowseResult.NotFound)
                 {
                     MessageBox.Show("The sounds must be located in a folder called sound (without 's').", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                 }
             }
         }
     }
 }