This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Controller.cs
228 lines (197 loc) · 7.19 KB
/
Controller.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using ANDREICSLIB;
using ANDREICSLIB.ClassExtras;
using ANDREICSLIB.NewControls;
using Mp3Lib;
namespace Music_File_Info_Editor
{
public class Controller
{
public static void Initcols(List<string> cols)
{
cols.Add("Order");
cols.Add("Album");
cols.Add("Artist");
cols.Add("Comment");
cols.Add("Composer");
cols.Add("Disc");
cols.Add("Genre");
cols.Add("Lyrics");
cols.Add("Song");
cols.Add("Title");
cols.Add("Track");
cols.Add("Year");
cols.Add("Path");
}
public static ListViewItem initLVI(ListView fileList)
{
var LVI = new ListViewItem();
//ignore first column
for (var a = 1; a < fileList.Columns.Count; a++)
{
LVI.SubItems.Add("");
}
return LVI;
}
public static void setLVI(ListViewItem IN, String columnName, String text, ListView fileList)
{
var col = ListViewExtras.GetColumnNumber(fileList, columnName);
IN.SubItems[col].Text = text;
}
public static void DropInFiles(string[] files, ListView fileList)
{
var acceptall = false;
var nochanges = false;
const string YTA = "Yes To All";
const string nostr = "No";
const string noallstr = "No To All";
const string yesstr = "Yes";
const string cancelstr = "Cancel";
var l = new List<string>();
l.Add(YTA);
l.Add(yesstr);
l.Add(nostr);
l.Add(noallstr);
l.Add(cancelstr);
foreach (var s in files)
{
var LVI = initLVI(fileList);
LVI.Text = fileList.Items.Count.ToString();
LVI.Name = LVI.Text;
LVI.SubItems.Add(s);
Mp3File mf = null;
var retrycount = 0;
var retrymax = 10;
retry:
try
{
mf = new Mp3File(s);
}
catch (Exception exp)
{
retrycount++;
if (retrycount >= retrymax)
{
MessageBox.Show("Error opening file:" + exp.ToString());
var DR = MessageBox.Show("Do you want to continue?", "option", MessageBoxButtons.YesNo);
if (DR == DialogResult.No)
return;
continue;
}
//for a certain period, retry
Thread.Sleep(100);
goto retry;
}
LVI.Tag = mf;
var sas = mf.Audio;
sas.ScanWholeFile();
//clean files on entry
var newData = new changes.TagHandlerUpdate(mf);
if (nochanges == false)
{
Music_File_Info_Editor.changes.cleanMP3(newData);
var changes = Music_File_Info_Editor.changes.areThereDifferences(mf, newData);
var makechanges = true;
if (changes && acceptall == false)
{
var tt = "The file:" + mf.FileName +
" has a title/album/artist with blank characters at the start or end, or has multiple white space. Do you wish to fix these?";
var MMB = new MultipleMessageBox("option", tt, l);
MMB.ShowDialog();
if (MMB.IsSet == false)
return;
switch (MMB.Result)
{
case cancelstr:
return;
case nostr:
makechanges = false;
break;
case YTA:
acceptall = true;
break;
case noallstr:
makechanges = false;
nochanges = true;
break;
}
}
if (makechanges)
{
if (Music_File_Info_Editor.changes.makeChangesAndContinue(newData, mf) == false)
return;
}
}
//only add if the name isnt there already
var add = true;
foreach (ListViewItem tt in fileList.Items)
{
var s1 = tt.SubItems[ListViewExtras.GetColumnNumber(fileList, "Path")].Text;
if (s1.Equals(mf.FileName))
{
add = false;
break;
}
}
if (add)
fileList.Items.Add(LVI);
}
RefreshInfo(fileList);
ListViewExtras.AutoResize(fileList);
}
public static void RefreshInfo(ListView fileList)
{
foreach (ListViewItem LVI in fileList.Items)
{
var mm = ((Mp3File)LVI.Tag);
var TH = ((Mp3File)LVI.Tag).TagHandler;
setLVI(LVI, "Album", TH.Album, fileList);
setLVI(LVI, "Artist", TH.Artist, fileList);
setLVI(LVI, "Comment", TH.Comment, fileList);
setLVI(LVI, "Composer", TH.Composer, fileList);
setLVI(LVI, "Disc", TH.Disc, fileList);
setLVI(LVI, "Genre", TH.Genre, fileList);
setLVI(LVI, "Lyrics", TH.Lyrics, fileList);
setLVI(LVI, "Song", TH.Song, fileList);
setLVI(LVI, "Title", TH.Title, fileList);
setLVI(LVI, "Track", TH.Track, fileList);
setLVI(LVI, "Year", TH.Year, fileList);
setLVI(LVI, "Path", mm.FileName, fileList);
}
}
public static IEnumerable<Mp3File> getMP3Tags(List<ListViewItem> selectedItems)
{
foreach (var l in selectedItems)
{
yield return ((Mp3File)l.Tag);
}
/*
var count = 0;
var max = selectedItems.Count;
while (count < max)
{
ListViewItem save = null;
foreach (var LVI in selectedItems)
{
if (Int32.Parse(LVI.Name).Equals(count))
{
save = LVI;
break;
}
}
if (save != null)
{
yield return ((Mp3File)save.Tag);
selectedItems.Remove(save);
}
count++;
}
* */
}
}
}