changeset 243:425912324be5

Re #417: Improve install/first use experience * Handle file copy errors in WinForms and tell user
author IBBoard <dev@ibboard.co.uk>
date Sat, 19 May 2012 20:16:21 +0100
parents 2bde6d18d3bd
children c50dc3c4136e
files FrmMain.cs
diffstat 1 files changed, 31 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/FrmMain.cs	Sat May 19 16:46:19 2012 +0100
+++ b/FrmMain.cs	Sat May 19 20:16:21 2012 +0100
@@ -3,6 +3,7 @@
 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
 
 using System;
+using System.Text;
 using System.Collections.Generic;
 using System.Drawing;
 using System.Drawing.Drawing2D;
@@ -1507,15 +1508,44 @@
 
 			if (dr == DialogResult.OK)
 			{
+				List<Exception> exceptions = new List<Exception>();
+
 				foreach (string filePath in addDataFileDialog.FileNames)
 				{
-					WarFoundryLoader.AddNewDataFile(filePath);
+					try
+					{
+						WarFoundryLoader.AddNewDataFile(filePath);
+					}
+					catch (Exception ex)
+					{
+						exceptions.Add(ex);
+					}
 				}
 
 				WarFoundryLoader.GetDefault().LoadFiles();
+
+				if (exceptions.Count > 0)
+				{
+					string errorMsg = MakeAddDataFileFailedMessage(exceptions);
+					MessageBox.Show(this, errorMsg, "errors adding new data files", MessageBoxButtons.OK, MessageBoxIcon.Error);
+				}
 			}
 
 			addDataFileDialog.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();
+		}
 	}
 }