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 diff
     1.1 --- a/FrmMainWindow.cs	Sat May 19 14:39:10 2012 +0100
     1.2 +++ b/FrmMainWindow.cs	Sat May 19 20:26:44 2012 +0100
     1.3 @@ -1310,13 +1310,45 @@
     1.4  
     1.5  			if (response == (int)ResponseType.Accept)
     1.6  			{
     1.7 +				List<Exception> exceptions = new List<Exception>();
     1.8 +
     1.9  				foreach (string filePath in filePaths)
    1.10  				{
    1.11 -					WarFoundryLoader.AddNewDataFile(filePath);
    1.12 +					try
    1.13 +					{
    1.14 +						WarFoundryLoader.AddNewDataFile(filePath);
    1.15 +					}
    1.16 +					catch (Exception ex)
    1.17 +					{
    1.18 +						exceptions.Add(ex);
    1.19 +					}
    1.20  				}
    1.21  
    1.22  				WarFoundryLoader.GetDefault().LoadFiles();
    1.23 +
    1.24 +				if (exceptions.Count > 0)
    1.25 +				{
    1.26 +					string errorMsg = MakeAddDataFileFailedMessage(exceptions);
    1.27 +					MessageDialog dialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, errorMsg);
    1.28 +					dialog.Run();
    1.29 +					dialog.Hide();
    1.30 +					dialog.Dispose();
    1.31 +				}
    1.32  			}
    1.33  		}
    1.34 +
    1.35 +		private string MakeAddDataFileFailedMessage(List<Exception> exceptions)
    1.36 +		{
    1.37 +			StringBuilder sb = new StringBuilder();
    1.38 +			sb.Append("errors occurred while adding the new data files: ");
    1.39 +
    1.40 +			foreach (Exception ex in exceptions)
    1.41 +			{
    1.42 +				sb.Append("\n\t• ");
    1.43 +				sb.Append(ex.Message);
    1.44 +			}
    1.45 +
    1.46 +			return sb.ToString();
    1.47 +		}
    1.48  	}
    1.49  }