Improved error handling
This commit is contained in:
3
MusicOrganizer/MainForm.Designer.cs
generated
3
MusicOrganizer/MainForm.Designer.cs
generated
@@ -59,6 +59,7 @@
|
|||||||
this.button2.TabIndex = 1;
|
this.button2.TabIndex = 1;
|
||||||
this.button2.Text = "Create BPM folder structure";
|
this.button2.Text = "Create BPM folder structure";
|
||||||
this.button2.UseVisualStyleBackColor = true;
|
this.button2.UseVisualStyleBackColor = true;
|
||||||
|
this.button2.Click += new System.EventHandler(this.button2_Click);
|
||||||
//
|
//
|
||||||
// button1
|
// button1
|
||||||
//
|
//
|
||||||
@@ -91,7 +92,7 @@
|
|||||||
//
|
//
|
||||||
// columnFilename
|
// columnFilename
|
||||||
//
|
//
|
||||||
this.columnFilename.AspectName = "filename";
|
this.columnFilename.AspectName = "relativeFilename";
|
||||||
this.columnFilename.Text = "Filename";
|
this.columnFilename.Text = "Filename";
|
||||||
//
|
//
|
||||||
// columnArtist
|
// columnArtist
|
||||||
|
@@ -7,16 +7,26 @@ namespace MusicOrganizer
|
|||||||
{
|
{
|
||||||
public partial class MainForm : Form
|
public partial class MainForm : Form
|
||||||
{
|
{
|
||||||
|
struct Item
|
||||||
|
{
|
||||||
|
public string filename;
|
||||||
|
public string relativeFilename;
|
||||||
|
public string artist;
|
||||||
|
public string title;
|
||||||
|
public string bpm;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Item> items;
|
||||||
|
|
||||||
public MainForm()
|
public MainForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
objectListView1.AlwaysGroupByColumn = columnBpm;
|
objectListView1.AlwaysGroupByColumn = columnBpm;
|
||||||
|
items = new List<Item>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void button1_Click(object sender, EventArgs e)
|
private void button1_Click(object sender, EventArgs e)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
string musicFolder;
|
string musicFolder;
|
||||||
|
|
||||||
@@ -36,13 +46,48 @@ namespace MusicOrganizer
|
|||||||
if (!musicFolder.EndsWith("\\") && !musicFolder.EndsWith("/"))
|
if (!musicFolder.EndsWith("\\") && !musicFolder.EndsWith("/"))
|
||||||
musicFolder += Path.DirectorySeparatorChar;
|
musicFolder += Path.DirectorySeparatorChar;
|
||||||
|
|
||||||
var paths = Directory.GetFileSystemEntries(musicFolder, "*.mp3", SearchOption.AllDirectories);
|
string[] paths;
|
||||||
|
|
||||||
var objects = new List<object>();
|
again1:
|
||||||
|
try
|
||||||
|
{
|
||||||
|
paths = Directory.GetFileSystemEntries(musicFolder, "*.mp3", SearchOption.AllDirectories);
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
var result = MessageBox.Show(string.Format("Error occured when collecting files\n\n{0}", ex.Message), "Error occured", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
|
||||||
|
|
||||||
|
switch(result)
|
||||||
|
{
|
||||||
|
case DialogResult.Retry: goto again1;
|
||||||
|
case DialogResult.Cancel: return;
|
||||||
|
default: throw new Exception("Unknown option clicked.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var newItems = new List<Item>();
|
||||||
|
|
||||||
foreach (var path in paths)
|
foreach (var path in paths)
|
||||||
{
|
{
|
||||||
var file = TagLib.File.Create(path);
|
TagLib.File file;
|
||||||
|
|
||||||
|
again2:
|
||||||
|
try
|
||||||
|
{
|
||||||
|
file = TagLib.File.Create(path);
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
var result = MessageBox.Show(string.Format("Error occured when processing file\n\n{0}\n\n{1}", path, ex.Message), "Error occured", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
|
||||||
|
|
||||||
|
switch(result)
|
||||||
|
{
|
||||||
|
case DialogResult.Abort: return;
|
||||||
|
case DialogResult.Retry: goto again2;
|
||||||
|
case DialogResult.Ignore: continue;
|
||||||
|
default: throw new Exception("Unknown option clicked.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
string relativePath;
|
string relativePath;
|
||||||
if (path.StartsWith(musicFolder))
|
if (path.StartsWith(musicFolder))
|
||||||
@@ -50,23 +95,26 @@ namespace MusicOrganizer
|
|||||||
else
|
else
|
||||||
relativePath = path;
|
relativePath = path;
|
||||||
|
|
||||||
objects.Add(new {
|
newItems.Add(new Item
|
||||||
filename = relativePath,
|
{
|
||||||
|
filename = path,
|
||||||
|
relativeFilename = relativePath,
|
||||||
artist = file.Tag.FirstPerformer,
|
artist = file.Tag.FirstPerformer,
|
||||||
title = file.Tag.Title,
|
title = file.Tag.Title,
|
||||||
bpm = string.Format("{0}BPM", file.Tag.BeatsPerMinute)
|
bpm = string.Format("{0}BPM", file.Tag.BeatsPerMinute)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
objectListView1.SetObjects(objects);
|
items = newItems;
|
||||||
|
objectListView1.SetObjects(items);
|
||||||
objectListView1.AutoResizeColumns();
|
objectListView1.AutoResizeColumns();
|
||||||
|
|
||||||
button2.Enabled = true;
|
button2.Enabled = items.Count > 0;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
|
private void button2_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user