changeset 159:89e2442bbb60

Re #417: Improve install/first use experience * Handle errors in GTK# interface
author IBBoard <dev@ibboard.co.uk>
date Sat, 19 May 2012 20:26:44 +0100
parents 6b4cc1fc3f42
children b926b1b0ed79
files FrmMainWindow.cs
diffstat 1 files changed, 33 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/FrmMainWindow.cs	Sat May 19 14:39:10 2012 +0100
+++ b/FrmMainWindow.cs	Sat May 19 20:26:44 2012 +0100
@@ -1310,13 +1310,45 @@
 
 			if (response == (int)ResponseType.Accept)
 			{
+				List<Exception> exceptions = new List<Exception>();
+
 				foreach (string filePath in filePaths)
 				{
-					WarFoundryLoader.AddNewDataFile(filePath);
+					try
+					{
+						WarFoundryLoader.AddNewDataFile(filePath);
+					}
+					catch (Exception ex)
+					{
+						exceptions.Add(ex);
+					}
 				}
 
 				WarFoundryLoader.GetDefault().LoadFiles();
+
+				if (exceptions.Count > 0)
+				{
+					string errorMsg = MakeAddDataFileFailedMessage(exceptions);
+					MessageDialog dialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, errorMsg);
+					dialog.Run();
+					dialog.Hide();
+					dialog.Dispose();
+				}
 			}
 		}
+
+		private string MakeAddDataFileFailedMessage(List<Exception> exceptions)
+		{
+			StringBuilder sb = new StringBuilder();
+			sb.Append("errors occurred while adding the new data files: ");
+
+			foreach (Exception ex in exceptions)
+			{
+				sb.Append("\n\t• ");
+				sb.Append(ex.Message);
+			}
+
+			return sb.ToString();
+		}
 	}
 }