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 diff
     1.1 --- a/FrmMain.cs	Sat May 19 16:46:19 2012 +0100
     1.2 +++ b/FrmMain.cs	Sat May 19 20:16:21 2012 +0100
     1.3 @@ -3,6 +3,7 @@
     1.4  // 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.
     1.5  
     1.6  using System;
     1.7 +using System.Text;
     1.8  using System.Collections.Generic;
     1.9  using System.Drawing;
    1.10  using System.Drawing.Drawing2D;
    1.11 @@ -1507,15 +1508,44 @@
    1.12  
    1.13  			if (dr == DialogResult.OK)
    1.14  			{
    1.15 +				List<Exception> exceptions = new List<Exception>();
    1.16 +
    1.17  				foreach (string filePath in addDataFileDialog.FileNames)
    1.18  				{
    1.19 -					WarFoundryLoader.AddNewDataFile(filePath);
    1.20 +					try
    1.21 +					{
    1.22 +						WarFoundryLoader.AddNewDataFile(filePath);
    1.23 +					}
    1.24 +					catch (Exception ex)
    1.25 +					{
    1.26 +						exceptions.Add(ex);
    1.27 +					}
    1.28  				}
    1.29  
    1.30  				WarFoundryLoader.GetDefault().LoadFiles();
    1.31 +
    1.32 +				if (exceptions.Count > 0)
    1.33 +				{
    1.34 +					string errorMsg = MakeAddDataFileFailedMessage(exceptions);
    1.35 +					MessageBox.Show(this, errorMsg, "errors adding new data files", MessageBoxButtons.OK, MessageBoxIcon.Error);
    1.36 +				}
    1.37  			}
    1.38  
    1.39  			addDataFileDialog.Dispose();
    1.40  		}
    1.41 +
    1.42 +		private string MakeAddDataFileFailedMessage(List<Exception> exceptions)
    1.43 +		{
    1.44 +			StringBuilder sb = new StringBuilder();
    1.45 +			sb.Append("errors occurred while adding the new data files: ");
    1.46 +
    1.47 +			foreach (Exception ex in exceptions)
    1.48 +			{
    1.49 +				sb.Append("\n\t");
    1.50 +				sb.Append(ex.Message);
    1.51 +			}
    1.52 +
    1.53 +			return sb.ToString();
    1.54 +		}
    1.55  	}
    1.56  }