private void metroButton3_Click(object sender, EventArgs e) { FileStream fs = new FileStream("mp3.txt", FileMode.Truncate); fs.Close(); fs = new FileStream("mp3.txt", FileMode.Open); BinaryFormatter BF = new BinaryFormatter(); int count = 0; for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++) { for (int j = 0; j < files.Count(); j++) { if (checkedListBox1.CheckedItems[i].ToString() == Path.GetFileName(files[j])) { MP3Reader MR = new MP3Reader(files[j]); MP3Tag_and_nameOf_MP3 Tag = MR.getTag(); BF.Serialize(fs, Tag); count++; break; } } } fs.Close(); MessageBox.Show("You have Added: " + count + " MP3 files successfully"); ArtistComboBox(); TitleComboBox(); GenreComboBox(); AlbumComboBox(); YearComboBox(); }
private void bunifuTileButton11_Click(object sender, EventArgs e) { paths s = new paths(); List <MP3Tag_and_nameOf_MP3> list = new List <MP3Tag_and_nameOf_MP3>(); FileStream fm = new FileStream("mp3.txt", FileMode.Open); BinaryFormatter BF = new BinaryFormatter(); List <MP3Tag_and_nameOf_MP3> lis = new List <MP3Tag_and_nameOf_MP3>(); while (fm.Position != fm.Length) { MP3Tag_and_nameOf_MP3 tag = (MP3Tag_and_nameOf_MP3)BF.Deserialize(fm); lis.Add(tag); } fm.Close(); FileStream fs2 = new FileStream("mp3.txt", FileMode.Truncate); fs2.Close(); int i = 0; for (int m = 0; m < lis.Count; m++) { for (int n = 0; n < s.get_files().Length; n++) { if (lis[m].Mp3_Name == Path.GetFileName(s.get_files()[n])) { MP3Reader MR = new MP3Reader(s.get_files()[n]); MP3Tag_and_nameOf_MP3 tag = MR.getTag(); Mp3FileReader reader = new Mp3FileReader(s.get_files()[n]); TimeSpan duration = reader.TotalTime; list.Add(tag); list[i].Duration = duration; reader.Close(); } } i++; } sort_by_Durat D = new sort_by_Durat(); list.Sort(D); for (int k = 0; k < list.Count; k++) { list[k].Comment = (k + 1) + ""; } for (int m = 0; m < list.Count; m++) { for (int n = m + 1; n < list.Count; n++) { if (list[m].Duration == list[n].Duration) { list[n].Comment = list[m].Comment; } } } int count = 0; int index = 0; for (int a = 0; a < list.Count; a++) { for (int b = 0; b < list.Count; b++) { if (list[b].Comment == a + 1 + "") { count++; index = b; } } if (count != 0) { for (int c = index + 1; c < list.Count; c++) { list[c].Comment = int.Parse(list[c].Comment) - count + 1 + ""; } } count = 0; } FileStream fs3 = new FileStream("mp3.txt", FileMode.Open); BinaryFormatter bf = new BinaryFormatter(); for (int j = 0; j < list.Count; j++) { bf.Serialize(fs3, list[j]); } dataGridView2.DataSource = list; fs3.Close(); //edit comment edit_comment(); }