Beispiel #1
0
 private void RenameSong(object sender, EventArgs e)
 {
     if (this.listViewSongs.SelectedItems.Count > 0)
     {
         if (this.listViewSongs.SelectedItems[0].Group != this.listViewSongs.Groups["customMusic"])
         {
             using (RenameMessageBox messageBox = new RenameMessageBox(Path.GetFileNameWithoutExtension(this.listViewSongs.SelectedItems[0].SubItems[1].Text))) {
                 if (messageBox.ShowDialog(this) == DialogResult.OK)
                 {
                     string newName = Path.GetFileNameWithoutExtension(messageBox.NewName) + ".wav";
                     if (File.Exists(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Custom Music", newName)))
                     {
                         ErrorMessageBox.Show(this, "A song already exists with that name.", "");
                     }
                     else
                     {
                         File.Move(
                             Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Custom Music", this.listViewSongs.SelectedItems[0].SubItems[1].Text),
                             Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Custom Music", newName)
                             );
                         if (File.Exists(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Custom Music", "Modified", this.listViewSongs.SelectedItems[0].SubItems[1].Text)))
                         {
                             File.Move(
                                 Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Custom Music", "Modified", this.listViewSongs.SelectedItems[0].SubItems[1].Text),
                                 Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Custom Music", "Modified", newName)
                                 );
                         }
                         this.listViewSongs.SelectedItems[0].SubItems[1].Text = newName;
                         if (this.listViewSongs.SelectedItems[0].ImageIndex == 1)
                         {
                             this.listViewSongs.SelectedItems[0].ImageIndex = 0;
                             this.currentSong.Stop();
                             this.playing         = false;
                             this.playingCustom   = false;
                             this.buttonPlay.Text = "Play";
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
 public static DialogResult Show(Form parent, string text1, string text2)
 {
     using (var form = new ErrorMessageBox(text1, text2)) {
         return(form.ShowDialog(parent));
     }
 }
Beispiel #3
0
        private void SongDragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                bool     invalid       = false;
                bool     invalidType   = false;
                bool     alreadyExists = false;
                bool     error         = false;
                string[] fileDrops     = (string[])(e.Data.GetData(DataFormats.FileDrop));
                for (int i = 0; i < fileDrops.Length; i++)
                {
                    try {
                        string file = fileDrops[i];
                        if (File.Exists(file))
                        {
                            if (Path.GetExtension(file).ToLower() == ".wav")
                            {
                                using (WaveFileReader reader = new WaveFileReader(file)) {
                                    if (reader.WaveFormat.SampleRate == 22050 && reader.WaveFormat.Encoding == WaveFormatEncoding.Pcm && reader.WaveFormat.Channels == 2)
                                    {
                                        if (!File.Exists(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Custom Music", Path.GetFileName(file))))
                                        {
                                            SoundPlayer song = new SoundPlayer(file);
                                            song.Dispose();

                                            File.Copy(
                                                file,
                                                Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Custom Music", Path.GetFileName(file))
                                                , false);

                                            ListViewItem item = new ListViewItem(this.listViewSongs.Groups["musicList"]);
                                            item.SubItems.Add(new ListViewItem.ListViewSubItem(item, Path.GetFileName(file)));

                                            using (WaveFileReader reader2 = new WaveFileReader(file)) {
                                                item.SubItems.Add(new ListViewItem.ListViewSubItem(item, reader2.TotalTime.ToString((reader2.TotalTime.TotalHours >= 1) ? @"hh\:mm\:ss" : @"mm\:ss")));
                                            }

                                            item.SubItems.Add(new ListViewItem.ListViewSubItem(item, ""));

                                            this.listViewSongs.Items.Add(item);
                                        }
                                        else
                                        {
                                            alreadyExists = true;
                                        }
                                    }
                                    else
                                    {
                                        invalidType = true;
                                    }
                                }
                            }
                            else
                            {
                                invalidType = true;
                            }
                            if (invalidType)
                            {
                                try {
                                    string newfile = Path.GetFileNameWithoutExtension(file) + ".wav";
                                    this.ConvertMusicFile(file, Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Custom Music", Path.GetFileName(newfile)));

                                    ListViewItem item = new ListViewItem(this.listViewSongs.Groups["musicList"]);
                                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, Path.GetFileName(newfile)));

                                    using (WaveFileReader reader = new WaveFileReader(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Custom Music", Path.GetFileName(newfile)))) {
                                        item.SubItems.Add(new ListViewItem.ListViewSubItem(item, reader.TotalTime.ToString((reader.TotalTime.TotalHours >= 1) ? @"hh\:mm\:ss" : @"mm\:ss")));
                                    }

                                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, ""));

                                    this.listViewSongs.Items.Add(item);
                                }
                                catch (Exception) {
                                    error = true;
                                }
                            }
                        }
                        else
                        {
                            invalid = true;
                        }
                    }
                    catch (Exception) {
                        invalid = true;
                    }
                }
                if (error)
                {
                    ErrorMessageBox.Show(this, "There was an error converting some", "songs and they were not added.");
                }
                else if (invalidType)
                {
                    ErrorMessageBox.Show(this, "Some songs were not the proper", "format and were converted.");
                }
                if (alreadyExists)
                {
                    ErrorMessageBox.Show(this, "Some songs already existed with", "their name and were not added.");
                }
                if (invalid)
                {
                    ErrorMessageBox.Show(this, "Some songs were invalid or missing", "and were not added.");
                }
            }
        }