changeset 481:81f32062c9fa

Re #419: Remove assumptions of a file-based install * Convert schemas to resources and load them from there * Remove use of "data" folder relative to exe location from default "Hacks" (GTK/WinForms GUIs can re-add it locally)
author IBBoard <dev@ibboard.co.uk>
date Mon, 25 Jun 2012 21:04:02 +0100
parents e0641e0eb86c
children 1ed2f3ab5e35
files API/Exporters/WarFoundryHtmlExporter.cs API/Factories/Xml/WarFoundryXmlFactoryUtils.cs API/WarFoundryHacks.cs IBBoard.WarFoundry.API.csproj
diffstat 4 files changed, 502 insertions(+), 526 deletions(-) [+]
line diff
     1.1 --- a/API/Exporters/WarFoundryHtmlExporter.cs	Wed May 23 21:00:33 2012 +0100
     1.2 +++ b/API/Exporters/WarFoundryHtmlExporter.cs	Mon Jun 25 21:04:02 2012 +0100
     1.3 @@ -12,378 +12,380 @@
     1.4  using IBBoard.Xml;
     1.5  using IBBoard.WarFoundry.API.Objects;
     1.6  using IBBoard.WarFoundry.API.Util;
     1.7 +using System.Reflection;
     1.8  
     1.9  namespace IBBoard.WarFoundry.API.Exporters
    1.10  {
    1.11 -	/// <summary>
    1.12 -	/// Custom exporter that exports an army as a basic HTML file
    1.13 -	/// </summary>
    1.14 -	public class WarFoundryHtmlExporter : IWarFoundryExporter
    1.15 -	{
    1.16 -		private static WarFoundryHtmlExporter exporter;
    1.17 -		private delegate string GetStatCellTextDelegate(Stat stat);
    1.18 +		/// <summary>
    1.19 +		/// Custom exporter that exports an army as a basic HTML file
    1.20 +		/// </summary>
    1.21 +		public class WarFoundryHtmlExporter : IWarFoundryExporter
    1.22 +		{
    1.23 +				private static WarFoundryHtmlExporter exporter;
    1.24 +				private delegate string GetStatCellTextDelegate(Stat stat);
    1.25  		
    1.26 -		public static WarFoundryHtmlExporter GetDefault()
    1.27 -		{
    1.28 -			if (exporter == null)
    1.29 -			{
    1.30 -				exporter = new WarFoundryHtmlExporter();
    1.31 -			}
    1.32 +				public static WarFoundryHtmlExporter GetDefault()
    1.33 +				{
    1.34 +						if (exporter == null)
    1.35 +						{
    1.36 +								exporter = new WarFoundryHtmlExporter();
    1.37 +						}
    1.38  			
    1.39 -			return exporter;
    1.40 +						return exporter;
    1.41 +				}
    1.42 +		
    1.43 +				private WarFoundryHtmlExporter()
    1.44 +				{
    1.45 +						//Hide constructor
    1.46 +				}
    1.47 +		
    1.48 +				public void ExportArmy(Army army, string path)
    1.49 +				{
    1.50 +						XmlDocument doc = new XmlDocument();
    1.51 +						XmlResourceResolver resolver = new XmlResourceResolver(Assembly.GetExecutingAssembly());
    1.52 +						resolver.AddMapping("-//W3C//ENTITIES Latin 1 for XHTML//EN", "IBBoard.API.schemas.xhtml1-lat1.ent");
    1.53 +						resolver.AddMapping("http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent", "IBBoard.API.schemas.xhtml1-lat1.ent");
    1.54 +						resolver.AddMapping("-//W3C//ENTITIES Symbols for XHTML//EN", "IBBoard.API.schemas.xhtml1-symbol.ent");
    1.55 +						resolver.AddMapping("http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent", "IBBoard.API.schemas.xhtml1-symbol.ent");
    1.56 +						resolver.AddMapping("-//W3C//ENTITIES Special for XHTML//EN", "IBBoard.API.schemas.xhtml1-special.ent");
    1.57 +						resolver.AddMapping("http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent", "IBBoard.API.schemas.xhtml1-special.ent");
    1.58 +						resolver.AddMapping("-//W3C//DTD XHTML 1.0 Strict//EN", "IBBoard.WarFoundry.schemas.xhtml1-strict.dtd");
    1.59 +						resolver.AddMapping("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", "IBBoard.WarFoundry.schemas.xhtml1-strict.dtd");
    1.60 +						doc.XmlResolver = resolver;
    1.61 +						doc.AppendChild(doc.CreateDocumentType("html", "-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", null));
    1.62 +						XmlElement html = doc.CreateElement("html");
    1.63 +						doc.AppendChild(html);
    1.64 +						XmlElement head = doc.CreateElement("head");
    1.65 +						html.AppendChild(head);
    1.66 +						XmlElement title = doc.CreateElement("title");
    1.67 +						title.InnerXml = army.Name;
    1.68 +						head.AppendChild(title);
    1.69 +						XmlElement metaCharset = doc.CreateElement("meta");
    1.70 +						metaCharset.SetAttribute("http-equiv", "Content-Type");
    1.71 +						metaCharset.SetAttribute("content", "text/html;charset=UTF-8");
    1.72 +						head.AppendChild(metaCharset);
    1.73 +						XmlElement style = doc.CreateElement("style");
    1.74 +						style.InnerText = "table, th, td { border: 1px solid #000; border-spacing: 0; border-collapse: collapse; margin: 0 }\n"
    1.75 +								+ "table table { width: 100%; border-width: 0; margin: -2px }\n"
    1.76 +								+ "table table td { border-width:0 1px }";
    1.77 +						head.AppendChild(style);
    1.78 +						XmlElement body = doc.CreateElement("body");
    1.79 +						html.AppendChild(body);
    1.80 +						XmlElement header = doc.CreateElement("h1");
    1.81 +						header.InnerText = Translation.GetTranslation("armyHtmlOutputBodyHeader", "{0} - {1}pts", army.Name, army.Points);
    1.82 +						body.AppendChild(header);
    1.83 +			
    1.84 +						foreach (XmlElement table in CreateTables(army, doc))
    1.85 +						{
    1.86 +								if (!IsTableOnlyHeader(table))
    1.87 +								{
    1.88 +										body.AppendChild(table);
    1.89 +								}
    1.90 +						}
    1.91 +
    1.92 +						File.WriteAllText(path, doc.OuterXml);
    1.93 +				}
    1.94 +
    1.95 +				private bool IsTableOnlyHeader(XmlElement table)
    1.96 +				{
    1.97 +						return table.ChildNodes.Count == 1;
    1.98 +				}
    1.99 +		
   1.100 +				private XmlElement[] CreateTables(Army army, XmlDocument doc)
   1.101 +				{
   1.102 +						Dictionary<string, XmlElement> tables = new Dictionary<string, XmlElement>();
   1.103 +			
   1.104 +						foreach (SystemStats statSets in army.GameSystem.SystemStats)
   1.105 +						{
   1.106 +								tables[statSets.ID] = CreateTable(statSets, doc);
   1.107 +						}
   1.108 +			
   1.109 +						foreach (Unit unit in army.GetUnits())
   1.110 +						{
   1.111 +								CreateUnitRow(unit, tables[GetFirstStatType(unit)]);
   1.112 +						}
   1.113 +			
   1.114 +						return DictionaryUtils.ToArray(tables);
   1.115 +				}
   1.116 +
   1.117 +				private static string GetFirstStatType(Unit unit)
   1.118 +				{
   1.119 +						string[] unitStatIDs = unit.UnitStatsArrayIDs;
   1.120 +						return GetFirstStatType(unitStatIDs);
   1.121 +				}
   1.122 +		
   1.123 +				public static string GetFirstStatType(string[] unitStatIDs)
   1.124 +				{
   1.125 +						return unitStatIDs[0];
   1.126 +				}
   1.127 +		
   1.128 +				private XmlElement CreateTable(SystemStats stats, XmlDocument doc)
   1.129 +				{
   1.130 +						XmlElement table = doc.CreateElement("table");
   1.131 +						XmlElement headerRow = doc.CreateElement("tr");
   1.132 +						table.AppendChild(headerRow);
   1.133 +						XmlElement name = doc.CreateElement("th");
   1.134 +						name.InnerText = Translation.GetTranslation("armyHtmlOutputTableHeaderUnitName", "name");
   1.135 +						headerRow.AppendChild(name);
   1.136 +			
   1.137 +						XmlElement unitTypeName = doc.CreateElement("th");
   1.138 +						unitTypeName.InnerText = Translation.GetTranslation("armyHtmlOutputTableHeaderUnitTypeName", "type name");
   1.139 +						headerRow.AppendChild(unitTypeName);
   1.140 +			
   1.141 +						foreach (StatSlot stat in stats.StatSlots)
   1.142 +						{
   1.143 +								XmlElement statHeader = doc.CreateElement("th");
   1.144 +								statHeader.InnerText = stat.Name;
   1.145 +								headerRow.AppendChild(statHeader);
   1.146 +						}
   1.147 +			
   1.148 +						XmlElement notes = doc.CreateElement("th");
   1.149 +						notes.InnerText = Translation.GetTranslation("armyHtmlOutputTableHeaderUnitNotes", "name");
   1.150 +						;
   1.151 +						headerRow.AppendChild(notes);
   1.152 +			
   1.153 +						XmlElement points = doc.CreateElement("th");
   1.154 +						points.InnerText = Translation.GetTranslation("armyHtmlOutputTableHeaderUnitPoints", "name");
   1.155 +						;
   1.156 +						headerRow.AppendChild(points);
   1.157 +			
   1.158 +						return table;
   1.159 +				}
   1.160 +		
   1.161 +				private XmlElement CreateUnitRow(Unit unit, XmlElement tableElem)
   1.162 +				{
   1.163 +						XmlDocument doc = tableElem.OwnerDocument;
   1.164 +						XmlElement row = doc.CreateElement("tr");
   1.165 +						tableElem.AppendChild(row);
   1.166 +						Stat[][] memberStats = unit.UnitStatsArraysWithName;
   1.167 +						string[] statTypeIDs = unit.UnitStatsArrayIDs;
   1.168 +						string defaultStatType = GetFirstStatType(statTypeIDs);
   1.169 +						int statRowCount = 0;
   1.170 +						bool hasOther = false;
   1.171 +			
   1.172 +						foreach (string statTypeID in statTypeIDs)
   1.173 +						{
   1.174 +								if (statTypeID.Equals(defaultStatType))
   1.175 +								{
   1.176 +										statRowCount++;
   1.177 +								} else if (!hasOther)
   1.178 +								{
   1.179 +										statRowCount++;
   1.180 +										hasOther = true;
   1.181 +								}
   1.182 +						}
   1.183 +			
   1.184 +						XmlElement name = doc.CreateElement("td");
   1.185 +						name.InnerText = unit.Name;
   1.186 +						SetRowSpan(name, statRowCount);
   1.187 +						row.AppendChild(name);
   1.188 +						CreateStatsBlock(row, memberStats, statTypeIDs);
   1.189 +
   1.190 +						StringBuilder sb = new StringBuilder();
   1.191 +						UnitEquipmentItem[] unitEquipment = unit.GetEquipment();
   1.192 +			
   1.193 +						if (unitEquipment.Length > 0)
   1.194 +						{
   1.195 +								bool addSeparator = false;
   1.196 +				
   1.197 +								foreach (UnitEquipmentItem equip in unitEquipment)
   1.198 +								{
   1.199 +										if (!addSeparator)
   1.200 +										{
   1.201 +												addSeparator = true;
   1.202 +										} else
   1.203 +										{
   1.204 +												sb.Append(", ");
   1.205 +										}
   1.206 +
   1.207 +										string amountString;
   1.208 +										double amount = UnitEquipmentUtil.GetEquipmentAmount(unit, equip);
   1.209 +
   1.210 +										if (UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip))
   1.211 +										{
   1.212 +
   1.213 +												if (amount == 100)
   1.214 +												{
   1.215 +														amountString = GetEquipmentAmountAllTranslation(unit);
   1.216 +												} else
   1.217 +												{
   1.218 +														int number = UnitEquipmentUtil.GetEquipmentAmountTaken(unit, equip);
   1.219 +														amountString = GetEquipmentAmountRatioTranslation(amount, number);
   1.220 +												}
   1.221 +										} else
   1.222 +										{
   1.223 +												if (amount == -1)
   1.224 +												{
   1.225 +														amountString = GetEquipmentAmountAllTranslation(unit);
   1.226 +												} else
   1.227 +												{
   1.228 +														amountString = GetEquipmentAmountNumberTranslation((int)amount);
   1.229 +												}
   1.230 +										}
   1.231 +
   1.232 +										sb.Append(Translation.GetTranslation("armyHtmlExportEquipAmountRatio", "{0} for {1}", equip.Name, amountString));
   1.233 +								}
   1.234 +				
   1.235 +								sb.Append(". ");
   1.236 +						}
   1.237 +			
   1.238 +						ICollection<Ability> abilities = unit.Abilities;
   1.239 +			
   1.240 +						if (abilities.Count > 0)
   1.241 +						{
   1.242 +								bool addSeparator = false;
   1.243 +				
   1.244 +								foreach (Ability ability in abilities)
   1.245 +								{
   1.246 +										if (!addSeparator)
   1.247 +										{
   1.248 +												addSeparator = true;
   1.249 +										} else
   1.250 +										{
   1.251 +												sb.Append(", ");
   1.252 +										}
   1.253 +					
   1.254 +										sb.Append(ability.Name);
   1.255 +								}
   1.256 +				
   1.257 +								sb.Append(". ");
   1.258 +						}
   1.259 +			
   1.260 +						XmlElement notes = doc.CreateElement("td");
   1.261 +						notes.InnerText = sb.ToString();
   1.262 +						SetRowSpan(notes, statRowCount);
   1.263 +						row.AppendChild(notes);
   1.264 +			
   1.265 +						XmlElement points = doc.CreateElement("td");
   1.266 +						points.InnerText = unit.Points.ToString();
   1.267 +						SetRowSpan(points, statRowCount);
   1.268 +						row.AppendChild(points);
   1.269 +			
   1.270 +						return row;
   1.271 +				}
   1.272 +		
   1.273 +				private static void SetRowSpan(XmlElement xmlElement, int statRowCount)
   1.274 +				{
   1.275 +						if (statRowCount > 1)
   1.276 +						{
   1.277 +								xmlElement.SetAttribute("rowspan", statRowCount.ToString());
   1.278 +						}
   1.279 +				}
   1.280 +		
   1.281 +				private void CreateStatsBlock(XmlElement unitRow, Stat[][] memberStats, string[] statTypeIDs)
   1.282 +				{
   1.283 +						XmlDocument doc = unitRow.OwnerDocument;
   1.284 +						string defaultStatType = GetFirstStatType(statTypeIDs);
   1.285 +			
   1.286 +						Stat[] defaultStatLine = memberStats[0];
   1.287 +						int defaultStatLineCount = defaultStatLine.Length;
   1.288 +						AddStatCell(defaultStatLine[0].SlotValueString, unitRow);
   1.289 +			
   1.290 +						for (int i = 1; i < defaultStatLineCount; i++)
   1.291 +						{
   1.292 +								string statText = GetDefaultStatCellText(defaultStatLine[i]);
   1.293 +								AddStatCell(statText, unitRow);
   1.294 +						}
   1.295 +			
   1.296 +						int statCount = statTypeIDs.Length;
   1.297 +			
   1.298 +						if (statCount > 1)
   1.299 +						{
   1.300 +								XmlElement unitTable = (XmlElement)unitRow.ParentNode;
   1.301 +								Dictionary<string, XmlElement> statParents = CreateStatsParentElements(statTypeIDs, unitTable);
   1.302 +				
   1.303 +								for (int i = 1; i < statCount; i++)
   1.304 +								{
   1.305 +										Stat[] statLine = memberStats[i];
   1.306 +										string statTypeID = statTypeIDs[i];
   1.307 +										XmlElement tableElement = DictionaryUtils.GetValue(statParents, statTypeID);
   1.308 +										int statLineCount = statLine.Length;
   1.309 +										XmlElement statRow = doc.CreateElement("tr");
   1.310 +										tableElement.AppendChild(statRow);
   1.311 +										GetStatCellTextDelegate statCellTextDelegate = (statTypeID.Equals(defaultStatType) ? new GetStatCellTextDelegate(GetDefaultStatCellText) : new GetStatCellTextDelegate(GetOtherStatCellText));
   1.312 +										AddStatCell(statLine[0].SlotValueString, statRow);
   1.313 +				
   1.314 +										for (int j = 1; j < statLineCount; j++)
   1.315 +										{
   1.316 +												string statText = statCellTextDelegate(statLine[j]);
   1.317 +												AddStatCell(statText, statRow);
   1.318 +										}
   1.319 +								}
   1.320 +				
   1.321 +								if (statParents.Count > 1)
   1.322 +								{
   1.323 +										AddOtherUnitStatTables(statParents, unitTable, defaultStatLineCount);
   1.324 +								}
   1.325 +						}
   1.326 +				}
   1.327 +		
   1.328 +				private static void AddOtherUnitStatTables(Dictionary<string, XmlElement> statParents, XmlElement unitTable, int defaultStatLineCount)
   1.329 +				{
   1.330 +						XmlDocument doc = unitTable.OwnerDocument;
   1.331 +						XmlElement otherStatsRow = doc.CreateElement("tr");
   1.332 +						unitTable.AppendChild(otherStatsRow);
   1.333 +						XmlElement otherStatsCell = doc.CreateElement("td");
   1.334 +						otherStatsCell.SetAttribute("colspan", defaultStatLineCount.ToString());
   1.335 +						otherStatsRow.AppendChild(otherStatsCell);
   1.336 +			
   1.337 +						foreach (XmlElement tableElem in statParents.Values)
   1.338 +						{
   1.339 +								if (tableElem != unitTable)
   1.340 +								{
   1.341 +										otherStatsCell.AppendChild(tableElem);
   1.342 +								}
   1.343 +						}
   1.344 +				}
   1.345 +
   1.346 +				private Dictionary<string, XmlElement> CreateStatsParentElements(string[] statTypeIDs, XmlElement parentTable)
   1.347 +				{
   1.348 +						Dictionary<string, XmlElement> statParents = new Dictionary<string, XmlElement>();
   1.349 +						XmlDocument doc = parentTable.OwnerDocument;
   1.350 +						string defaultStatTypeID = GetFirstStatType(statTypeIDs);
   1.351 +						statParents[defaultStatTypeID] = parentTable;
   1.352 +			
   1.353 +						foreach (string statTypeID in statTypeIDs)
   1.354 +						{
   1.355 +								if (!statParents.ContainsKey(statTypeID))
   1.356 +								{
   1.357 +										XmlElement tableElement = doc.CreateElement("table");
   1.358 +										statParents[statTypeID] = tableElement;
   1.359 +								}
   1.360 +						}
   1.361 +			
   1.362 +						return statParents;
   1.363 +				}
   1.364 +
   1.365 +				private string GetDefaultStatCellText(Stat stat)
   1.366 +				{
   1.367 +						return Translation.GetTranslation("armyHtmlExportDefaultStatCellText", "{0}", stat.SlotValueString, stat.ParentSlotName);
   1.368 +				}
   1.369 +
   1.370 +				private string GetOtherStatCellText(Stat stat)
   1.371 +				{
   1.372 +						return Translation.GetTranslation("armyHtmlExportOtherStatCellText", "{1}: {0}", stat.SlotValueString, stat.ParentSlotName);
   1.373 +				}
   1.374 +		
   1.375 +				private static void AddStatCell(string statValue, XmlElement row)
   1.376 +				{
   1.377 +						XmlElement statCell = row.OwnerDocument.CreateElement("td");
   1.378 +						statCell.InnerText = statValue;
   1.379 +						row.AppendChild(statCell);
   1.380 +				}
   1.381 +		
   1.382 +				private string GetEquipmentAmountRatioTranslation(double amount, int number)
   1.383 +				{
   1.384 +						return Translation.GetTranslation("armyHtmlExportEquipAmountPercentage", "{0}% ({1})", amount, number);
   1.385 +				}
   1.386 +		
   1.387 +				private string GetEquipmentAmountNumberTranslation(int amount)
   1.388 +				{
   1.389 +						return Translation.GetTranslation("armyHtmlExportEquipAmountNumber", "{0}", amount);
   1.390 +				}
   1.391 +		
   1.392 +				private string GetEquipmentAmountAllTranslation(Unit unit)
   1.393 +				{
   1.394 +						return Translation.GetTranslation("armyHtmlExportEquipAmountAll", "all ({1})", 100, unit.Size);
   1.395 +				}
   1.396  		}
   1.397 -		
   1.398 -		private WarFoundryHtmlExporter()
   1.399 -		{
   1.400 -			//Hide constructor
   1.401 -		}
   1.402 -		
   1.403 -		public void ExportArmy(Army army, string path)
   1.404 -		{
   1.405 -			XmlDocument doc = new XmlDocument();
   1.406 -			CustomXmlResolver resolver = new CustomXmlResolver();
   1.407 -			Uri localUri = new Uri("file://" + IBBoard.Constants.ExecutablePath + "/schemas/xhtml1-strict.dtd");
   1.408 -			resolver.AddMapping("-//W3C//DTD XHTML 1.0 Strict//EN", localUri);
   1.409 -			resolver.AddMapping("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", localUri);
   1.410 -			doc.XmlResolver = resolver;
   1.411 -			doc.AppendChild(doc.CreateDocumentType("html", "-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", null));
   1.412 -			XmlElement html = doc.CreateElement("html");
   1.413 -			doc.AppendChild(html);
   1.414 -			XmlElement head = doc.CreateElement("head");
   1.415 -			html.AppendChild(head);
   1.416 -			XmlElement title = doc.CreateElement("title");
   1.417 -			title.InnerXml = army.Name;
   1.418 -			head.AppendChild(title);
   1.419 -			XmlElement metaCharset = doc.CreateElement("meta");
   1.420 -			metaCharset.SetAttribute("http-equiv", "Content-Type");
   1.421 -			metaCharset.SetAttribute("content", "text/html;charset=UTF-8");
   1.422 -			head.AppendChild(metaCharset);
   1.423 -			XmlElement style = doc.CreateElement("style");
   1.424 -			style.InnerText = "table, th, td { border: 1px solid #000; border-spacing: 0; border-collapse: collapse; margin: 0 }\n"
   1.425 -				+"table table { width: 100%; border-width: 0; margin: -2px }\n"
   1.426 -				+"table table td { border-width:0 1px }";
   1.427 -			head.AppendChild(style);
   1.428 -			XmlElement body = doc.CreateElement("body");
   1.429 -			html.AppendChild(body);
   1.430 -			XmlElement header = doc.CreateElement("h1");
   1.431 -			header.InnerText = Translation.GetTranslation("armyHtmlOutputBodyHeader", "{0} - {1}pts", army.Name, army.Points);
   1.432 -			body.AppendChild(header);
   1.433 -			
   1.434 -			foreach (XmlElement table in CreateTables(army, doc))
   1.435 -			{
   1.436 -				if (!IsTableOnlyHeader(table))
   1.437 -				{
   1.438 -					body.AppendChild(table);
   1.439 -				}
   1.440 -			}
   1.441 -
   1.442 -			File.WriteAllText(path, doc.OuterXml);
   1.443 -		}
   1.444 -
   1.445 -		private bool IsTableOnlyHeader(XmlElement table)
   1.446 -		{
   1.447 -			return table.ChildNodes.Count == 1;
   1.448 -		}
   1.449 -		
   1.450 -		private XmlElement[] CreateTables(Army army, XmlDocument doc)
   1.451 -		{
   1.452 -			Dictionary<string, XmlElement> tables = new Dictionary<string, XmlElement>();
   1.453 -			
   1.454 -			foreach (SystemStats statSets in army.GameSystem.SystemStats)
   1.455 -			{
   1.456 -				tables[statSets.ID] = CreateTable(statSets, doc);
   1.457 -			}
   1.458 -			
   1.459 -			foreach (Unit unit in army.GetUnits())
   1.460 -			{
   1.461 -				CreateUnitRow(unit, tables[GetFirstStatType(unit)]);
   1.462 -			}
   1.463 -			
   1.464 -			return DictionaryUtils.ToArray(tables);
   1.465 -		}
   1.466 -
   1.467 -		private static string GetFirstStatType(Unit unit)
   1.468 -		{
   1.469 -			string[] unitStatIDs = unit.UnitStatsArrayIDs;
   1.470 -			return GetFirstStatType(unitStatIDs);
   1.471 -		}
   1.472 -		
   1.473 -		public static string GetFirstStatType(string[] unitStatIDs)
   1.474 -		{
   1.475 -			return unitStatIDs[0];
   1.476 -		}
   1.477 -		
   1.478 -		private XmlElement CreateTable(SystemStats stats, XmlDocument doc)
   1.479 -		{
   1.480 -			XmlElement table = doc.CreateElement("table");
   1.481 -			XmlElement headerRow = doc.CreateElement("tr");
   1.482 -			table.AppendChild(headerRow);
   1.483 -			XmlElement name = doc.CreateElement("th");
   1.484 -			name.InnerText = Translation.GetTranslation("armyHtmlOutputTableHeaderUnitName", "name");
   1.485 -			headerRow.AppendChild(name);
   1.486 -			
   1.487 -			XmlElement unitTypeName = doc.CreateElement("th");
   1.488 -			unitTypeName.InnerText = Translation.GetTranslation("armyHtmlOutputTableHeaderUnitTypeName", "type name");
   1.489 -			headerRow.AppendChild(unitTypeName);
   1.490 -			
   1.491 -			foreach (StatSlot stat in stats.StatSlots)
   1.492 -			{
   1.493 -				XmlElement statHeader = doc.CreateElement("th");
   1.494 -				statHeader.InnerText = stat.Name;
   1.495 -				headerRow.AppendChild(statHeader);
   1.496 -			}
   1.497 -			
   1.498 -			XmlElement notes = doc.CreateElement("th");
   1.499 -			notes.InnerText = Translation.GetTranslation("armyHtmlOutputTableHeaderUnitNotes", "name");;
   1.500 -			headerRow.AppendChild(notes);
   1.501 -			
   1.502 -			XmlElement points = doc.CreateElement("th");
   1.503 -			points.InnerText = Translation.GetTranslation("armyHtmlOutputTableHeaderUnitPoints", "name");;
   1.504 -			headerRow.AppendChild(points);
   1.505 -			
   1.506 -			return table;
   1.507 -		}
   1.508 -		
   1.509 -		private XmlElement CreateUnitRow(Unit unit, XmlElement tableElem)
   1.510 -		{
   1.511 -			XmlDocument doc = tableElem.OwnerDocument;
   1.512 -			XmlElement row = doc.CreateElement("tr");
   1.513 -			tableElem.AppendChild(row);
   1.514 -			Stat[][] memberStats = unit.UnitStatsArraysWithName;
   1.515 -			string[] statTypeIDs = unit.UnitStatsArrayIDs;
   1.516 -			string defaultStatType = GetFirstStatType(statTypeIDs);
   1.517 -			int statRowCount = 0;
   1.518 -			bool hasOther = false;
   1.519 -			
   1.520 -			foreach (string statTypeID in statTypeIDs)
   1.521 -			{
   1.522 -				if (statTypeID.Equals(defaultStatType))
   1.523 -				{
   1.524 -					statRowCount++;
   1.525 -				}
   1.526 -				else if (!hasOther)
   1.527 -				{
   1.528 -					statRowCount++;
   1.529 -					hasOther = true;
   1.530 -				}
   1.531 -			}
   1.532 -			
   1.533 -			XmlElement name = doc.CreateElement("td");
   1.534 -			name.InnerText = unit.Name;
   1.535 -			SetRowSpan(name, statRowCount);
   1.536 -			row.AppendChild(name);
   1.537 -			CreateStatsBlock(row, memberStats, statTypeIDs);
   1.538 -
   1.539 -			StringBuilder sb = new StringBuilder();
   1.540 -			UnitEquipmentItem[] unitEquipment = unit.GetEquipment();
   1.541 -			
   1.542 -			if (unitEquipment.Length > 0)
   1.543 -			{
   1.544 -				bool addSeparator = false;
   1.545 -				
   1.546 -				foreach (UnitEquipmentItem equip in unitEquipment)
   1.547 -				{
   1.548 -					if (!addSeparator)
   1.549 -					{
   1.550 -						addSeparator = true;
   1.551 -					}
   1.552 -					else
   1.553 -					{
   1.554 -						sb.Append(", ");
   1.555 -					}
   1.556 -
   1.557 -					string amountString;
   1.558 -					double amount = UnitEquipmentUtil.GetEquipmentAmount(unit, equip);
   1.559 -
   1.560 -					if (UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip))
   1.561 -					{
   1.562 -
   1.563 -						if (amount == 100)
   1.564 -						{
   1.565 -							amountString = GetEquipmentAmountAllTranslation(unit);
   1.566 -						}
   1.567 -						else
   1.568 -						{
   1.569 -							int number = UnitEquipmentUtil.GetEquipmentAmountTaken(unit, equip);
   1.570 -							amountString = GetEquipmentAmountRatioTranslation(amount, number);
   1.571 -						}
   1.572 -					}
   1.573 -					else
   1.574 -					{
   1.575 -						if (amount == -1)
   1.576 -						{
   1.577 -							amountString = GetEquipmentAmountAllTranslation(unit);
   1.578 -						}
   1.579 -						else
   1.580 -						{
   1.581 -							amountString = GetEquipmentAmountNumberTranslation((int)amount);
   1.582 -						}
   1.583 -					}
   1.584 -
   1.585 -					sb.Append(Translation.GetTranslation("armyHtmlExportEquipAmountRatio", "{0} for {1}", equip.Name, amountString));
   1.586 -				}
   1.587 -				
   1.588 -				sb.Append(". ");
   1.589 -			}
   1.590 -			
   1.591 -			ICollection<Ability> abilities = unit.Abilities;
   1.592 -			
   1.593 -			if (abilities.Count > 0)
   1.594 -			{
   1.595 -				bool addSeparator = false;
   1.596 -				
   1.597 -				foreach (Ability ability in abilities)
   1.598 -				{
   1.599 -					if (!addSeparator)
   1.600 -					{
   1.601 -						addSeparator = true;
   1.602 -					}
   1.603 -					else
   1.604 -					{
   1.605 -						sb.Append(", ");
   1.606 -					}
   1.607 -					
   1.608 -					sb.Append(ability.Name);
   1.609 -				}
   1.610 -				
   1.611 -				sb.Append(". ");
   1.612 -			}
   1.613 -			
   1.614 -			XmlElement notes = doc.CreateElement("td");
   1.615 -			notes.InnerText = sb.ToString();
   1.616 -			SetRowSpan(notes, statRowCount);
   1.617 -			row.AppendChild(notes);
   1.618 -			
   1.619 -			XmlElement points = doc.CreateElement("td");
   1.620 -			points.InnerText = unit.Points.ToString();
   1.621 -			SetRowSpan(points, statRowCount);
   1.622 -			row.AppendChild(points);
   1.623 -			
   1.624 -			return row;
   1.625 -		}
   1.626 -		
   1.627 -		private static void SetRowSpan(XmlElement xmlElement, int statRowCount)
   1.628 -		{
   1.629 -			if (statRowCount > 1)
   1.630 -			{
   1.631 -				xmlElement.SetAttribute("rowspan", statRowCount.ToString());
   1.632 -			}
   1.633 -		}
   1.634 -		
   1.635 -		private void CreateStatsBlock(XmlElement unitRow, Stat[][] memberStats, string[] statTypeIDs)
   1.636 -		{
   1.637 -			XmlDocument doc = unitRow.OwnerDocument;
   1.638 -			string defaultStatType = GetFirstStatType(statTypeIDs);
   1.639 -			
   1.640 -			Stat[] defaultStatLine = memberStats[0];
   1.641 -			int defaultStatLineCount = defaultStatLine.Length;
   1.642 -			AddStatCell(defaultStatLine[0].SlotValueString, unitRow);
   1.643 -			
   1.644 -			for (int i = 1; i < defaultStatLineCount; i++)
   1.645 -			{
   1.646 -				string statText = GetDefaultStatCellText(defaultStatLine[i]);
   1.647 -				AddStatCell(statText, unitRow);
   1.648 -			}
   1.649 -			
   1.650 -			int statCount = statTypeIDs.Length;
   1.651 -			
   1.652 -			if (statCount > 1)
   1.653 -			{
   1.654 -				XmlElement unitTable = (XmlElement)unitRow.ParentNode;
   1.655 -				Dictionary<string, XmlElement> statParents = CreateStatsParentElements(statTypeIDs, unitTable);
   1.656 -				
   1.657 -				for (int i = 1; i < statCount; i++)
   1.658 -				{
   1.659 -					Stat[] statLine = memberStats[i];
   1.660 -					string statTypeID = statTypeIDs[i];
   1.661 -					XmlElement tableElement = DictionaryUtils.GetValue(statParents, statTypeID);
   1.662 -					int statLineCount = statLine.Length;
   1.663 -					XmlElement statRow = doc.CreateElement("tr");
   1.664 -					tableElement.AppendChild(statRow);
   1.665 -					GetStatCellTextDelegate statCellTextDelegate = (statTypeID.Equals(defaultStatType) ? new GetStatCellTextDelegate(GetDefaultStatCellText) : new GetStatCellTextDelegate(GetOtherStatCellText));
   1.666 -					AddStatCell(statLine[0].SlotValueString, statRow);
   1.667 -				
   1.668 -					for (int j = 1; j < statLineCount; j++)
   1.669 -					{
   1.670 -						string statText = statCellTextDelegate(statLine[j]);
   1.671 -						AddStatCell(statText, statRow);
   1.672 -					}
   1.673 -				}
   1.674 -				
   1.675 -				if (statParents.Count > 1)
   1.676 -				{
   1.677 -					AddOtherUnitStatTables(statParents, unitTable, defaultStatLineCount);
   1.678 -				}
   1.679 -			}
   1.680 -		}
   1.681 -		
   1.682 -		private static void AddOtherUnitStatTables(Dictionary<string, XmlElement> statParents, XmlElement unitTable, int defaultStatLineCount)
   1.683 -		{
   1.684 -			XmlDocument doc = unitTable.OwnerDocument;
   1.685 -			XmlElement otherStatsRow = doc.CreateElement("tr");
   1.686 -			unitTable.AppendChild(otherStatsRow);
   1.687 -			XmlElement otherStatsCell = doc.CreateElement("td");
   1.688 -			otherStatsCell.SetAttribute("colspan", defaultStatLineCount.ToString());
   1.689 -			otherStatsRow.AppendChild(otherStatsCell);
   1.690 -			
   1.691 -			foreach (XmlElement tableElem in statParents.Values)
   1.692 -			{
   1.693 -				if (tableElem != unitTable)
   1.694 -				{
   1.695 -					otherStatsCell.AppendChild(tableElem);
   1.696 -				}
   1.697 -			}
   1.698 -		}
   1.699 -
   1.700 -		private Dictionary<string, XmlElement> CreateStatsParentElements(string[] statTypeIDs, XmlElement parentTable)
   1.701 -		{
   1.702 -			Dictionary<string, XmlElement> statParents = new Dictionary<string, XmlElement>();
   1.703 -			XmlDocument doc = parentTable.OwnerDocument;
   1.704 -			string defaultStatTypeID = GetFirstStatType(statTypeIDs);
   1.705 -			statParents[defaultStatTypeID] = parentTable;
   1.706 -			
   1.707 -			foreach (string statTypeID in statTypeIDs)
   1.708 -			{
   1.709 -				if (!statParents.ContainsKey(statTypeID))
   1.710 -				{
   1.711 -					XmlElement tableElement = doc.CreateElement("table");
   1.712 -					statParents[statTypeID] = tableElement;
   1.713 -				}
   1.714 -			}
   1.715 -			
   1.716 -			return statParents;
   1.717 -		}
   1.718 -
   1.719 -		private string GetDefaultStatCellText(Stat stat)
   1.720 -		{
   1.721 -			return Translation.GetTranslation("armyHtmlExportDefaultStatCellText", "{0}", stat.SlotValueString, stat.ParentSlotName);
   1.722 -		}
   1.723 -
   1.724 -		private string GetOtherStatCellText(Stat stat)
   1.725 -		{
   1.726 -			return Translation.GetTranslation("armyHtmlExportOtherStatCellText", "{1}: {0}", stat.SlotValueString, stat.ParentSlotName);
   1.727 -		}
   1.728 -		
   1.729 -		private static void AddStatCell(string statValue, XmlElement row)
   1.730 -		{
   1.731 -			XmlElement statCell = row.OwnerDocument.CreateElement("td");
   1.732 -			statCell.InnerText = statValue;
   1.733 -			row.AppendChild(statCell);
   1.734 -		}
   1.735 -		
   1.736 -		private string GetEquipmentAmountRatioTranslation (double amount, int number)
   1.737 -		{
   1.738 -			return Translation.GetTranslation ("armyHtmlExportEquipAmountPercentage", "{0}% ({1})", amount, number);
   1.739 -		}
   1.740 -		
   1.741 -		private string GetEquipmentAmountNumberTranslation(int amount)
   1.742 -		{
   1.743 -			return Translation.GetTranslation("armyHtmlExportEquipAmountNumber", "{0}", amount);
   1.744 -		}
   1.745 -		
   1.746 -		private string GetEquipmentAmountAllTranslation(Unit unit)
   1.747 -		{
   1.748 -			return Translation.GetTranslation("armyHtmlExportEquipAmountAll", "all ({1})", 100, unit.Size);
   1.749 -		}
   1.750 -	}
   1.751  }
     2.1 --- a/API/Factories/Xml/WarFoundryXmlFactoryUtils.cs	Wed May 23 21:00:33 2012 +0100
     2.2 +++ b/API/Factories/Xml/WarFoundryXmlFactoryUtils.cs	Mon Jun 25 21:04:02 2012 +0100
     2.3 @@ -8,142 +8,123 @@
     2.4  using System.Xml.Schema;
     2.5  using IBBoard.WarFoundry.API.Objects;
     2.6  using IBBoard.IO;
     2.7 +using IBBoard.Xml;
     2.8 +using System.Reflection;
     2.9  
    2.10  namespace IBBoard.WarFoundry.API.Factories.Xml
    2.11  {
    2.12 -	/// <summary>
    2.13 -	/// A collection of useful utility methods for loading WarFoundry data from XML files
    2.14 -	/// </summary>
    2.15 -	public class WarFoundryXmlFactoryUtils
    2.16 -	{
    2.17 -		public static readonly string NS_BASE = "http://ibboard.co.uk/warfoundry/";
    2.18 -		private static XmlReaderSettings settings;
    2.19 -		private static XmlNamespaceManager nsManager;
    2.20 +		/// <summary>
    2.21 +		/// A collection of useful utility methods for loading WarFoundry data from XML files
    2.22 +		/// </summary>
    2.23 +		public class WarFoundryXmlFactoryUtils
    2.24 +		{
    2.25 +				public static readonly string NS_BASE = "http://ibboard.co.uk/warfoundry/";
    2.26 +				private static XmlReaderSettings settings;
    2.27 +				private static XmlNamespaceManager nsManager;
    2.28  		
    2.29 -		public static XmlNodeList SelectNodes(XmlNode element, string xpathQuery)
    2.30 -		{
    2.31 -			return element.SelectNodes(xpathQuery, GetNamespaceManager());
    2.32 -		}
    2.33 +				public static XmlNodeList SelectNodes(XmlNode element, string xpathQuery)
    2.34 +				{
    2.35 +						return element.SelectNodes(xpathQuery, GetNamespaceManager());
    2.36 +				}
    2.37  		
    2.38 -		public static XmlNode SelectSingleNode(XmlNode element, string xpathQuery)
    2.39 -		{
    2.40 -			return element.SelectSingleNode(xpathQuery, GetNamespaceManager());
    2.41 -		}
    2.42 +				public static XmlNode SelectSingleNode(XmlNode element, string xpathQuery)
    2.43 +				{
    2.44 +						return element.SelectSingleNode(xpathQuery, GetNamespaceManager());
    2.45 +				}
    2.46  		
    2.47 -		public static XmlElement SelectSingleElement(XmlNode element, string xpathQuery)
    2.48 -		{
    2.49 -			XmlNode node = SelectSingleNode(element, xpathQuery);
    2.50 -			return (node is XmlElement) ? (XmlElement) node : null;
    2.51 -		}
    2.52 +				public static XmlElement SelectSingleElement(XmlNode element, string xpathQuery)
    2.53 +				{
    2.54 +						XmlNode node = SelectSingleNode(element, xpathQuery);
    2.55 +						return (node is XmlElement) ? (XmlElement)node : null;
    2.56 +				}
    2.57  				
    2.58 -		public static XmlNamespaceManager GetNamespaceManager()
    2.59 -		{
    2.60 -			if (nsManager == null)
    2.61 -			{
    2.62 -				nsManager = new XmlNamespaceManager(new NameTable());
    2.63 -				nsManager.AddNamespace("core", NS_BASE + "core");
    2.64 -				nsManager.AddNamespace("cat", NS_BASE + "cats");
    2.65 -				nsManager.AddNamespace("race", NS_BASE + "race");
    2.66 -				nsManager.AddNamespace("system", NS_BASE + "system");
    2.67 -				nsManager.AddNamespace("army", NS_BASE + "army");
    2.68 -			}
    2.69 +				public static XmlNamespaceManager GetNamespaceManager()
    2.70 +				{
    2.71 +						if (nsManager == null)
    2.72 +						{
    2.73 +								nsManager = new XmlNamespaceManager(new NameTable());
    2.74 +								nsManager.AddNamespace("core", NS_BASE + "core");
    2.75 +								nsManager.AddNamespace("cat", NS_BASE + "cats");
    2.76 +								nsManager.AddNamespace("race", NS_BASE + "race");
    2.77 +								nsManager.AddNamespace("system", NS_BASE + "system");
    2.78 +								nsManager.AddNamespace("army", NS_BASE + "army");
    2.79 +						}
    2.80  			
    2.81 -			return nsManager;
    2.82 -		}
    2.83 +						return nsManager;
    2.84 +				}
    2.85  		
    2.86 -		/// <summary>
    2.87 -		/// Lazy-getter for XML reader settings. May throw a <see cref="InvalidDataException"/> if there is a problem with the translation schema.
    2.88 -		/// </summary>
    2.89 -		/// <returns>
    2.90 -		/// A <see cref="XmlReaderSettings"/> with the default values for validating the translation document against the translation schema
    2.91 -		/// </returns>
    2.92 -		public static XmlReaderSettings GetReaderSettings()
    2.93 -		{
    2.94 -			if (settings == null)
    2.95 -			{
    2.96 -				settings = new XmlReaderSettings();
    2.97 -				settings.ValidationType = ValidationType.Schema;
    2.98 -				//settings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings;
    2.99 -				settings.ProhibitDtd = true;
   2.100 -				settings.ValidationEventHandler+= new ValidationEventHandler(ValidationEventMethod);
   2.101 -				XmlSchemaSet cache = new XmlSchemaSet();
   2.102 -				string path =  Path.Combine(IBBoard.Constants.ExecutablePath, "schemas");
   2.103 -				AddSchemaToCache(cache, NS_BASE + "core", Path.Combine(path, "warfoundry-core.xsd"));
   2.104 -				AddSchemaToCache(cache, NS_BASE + "cats", Path.Combine(path, "warfoundry-cats.xsd"));
   2.105 -				AddSchemaToCache(cache, NS_BASE + "race", Path.Combine(path, "race.xsd"));
   2.106 -				AddSchemaToCache(cache, NS_BASE + "system", Path.Combine(path, "system.xsd"));
   2.107 -				AddSchemaToCache(cache, NS_BASE + "army", Path.Combine(path, "army.xsd"));
   2.108 -				settings.Schemas.Add(cache);
   2.109 -				settings.Schemas.CompilationSettings.EnableUpaCheck = false;
   2.110 -			}
   2.111 +				/// <summary>
   2.112 +				/// Lazy-getter for XML reader settings. May throw a <see cref="InvalidDataException"/> if there is a problem with the translation schema.
   2.113 +				/// </summary>
   2.114 +				/// <returns>
   2.115 +				/// A <see cref="XmlReaderSettings"/> with the default values for validating the translation document against the translation schema
   2.116 +				/// </returns>
   2.117 +				public static XmlReaderSettings GetReaderSettings()
   2.118 +				{
   2.119 +						if (settings == null)
   2.120 +						{
   2.121 +								settings = new XmlReaderSettings();
   2.122 +								settings.ValidationType = ValidationType.Schema;
   2.123 +								//settings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings;
   2.124 +								settings.ProhibitDtd = true;
   2.125 +								settings.ValidationEventHandler += new ValidationEventHandler(ValidationEventMethod);
   2.126 +								XmlSchemaSet cache = new XmlSchemaSet();
   2.127 +								string path = "IBBoard.WarFoundry.schemas.";
   2.128 +								Assembly assm = Assembly.GetExecutingAssembly();
   2.129 +								XmlTools.AddSchemaToSetFromResource(cache, NS_BASE + "core", assm, path + "warfoundry-core.xsd");
   2.130 +								XmlTools.AddSchemaToSetFromResource(cache, NS_BASE + "cats", assm, path + "warfoundry-cats.xsd");
   2.131 +								XmlTools.AddSchemaToSetFromResource(cache, NS_BASE + "race", assm, path + "race.xsd");
   2.132 +								XmlTools.AddSchemaToSetFromResource(cache, NS_BASE + "system", assm, path + "system.xsd");
   2.133 +								XmlTools.AddSchemaToSetFromResource(cache, NS_BASE + "army", assm, path + "army.xsd");
   2.134 +								settings.Schemas.Add(cache);
   2.135 +								settings.Schemas.CompilationSettings.EnableUpaCheck = false;
   2.136 +						}
   2.137  			
   2.138 -			return settings;
   2.139 -		}
   2.140 +						return settings;
   2.141 +				}
   2.142  		
   2.143 -		private static void ValidationEventMethod(object sender, ValidationEventArgs e)
   2.144 -		{
   2.145 -			if (e.Severity == XmlSeverityType.Error)
   2.146 -			{
   2.147 -				throw new InvalidFileException("Problem validating against schema for WarFoundry data: " + e.Message, e.Exception);
   2.148 -			}
   2.149 -			else
   2.150 -			{
   2.151 -				//TODO: Fire some kind of warning event
   2.152 -			}
   2.153 -		}
   2.154 +				private static void ValidationEventMethod(object sender, ValidationEventArgs e)
   2.155 +				{
   2.156 +						if (e.Severity == XmlSeverityType.Error)
   2.157 +						{
   2.158 +								throw new InvalidFileException("Problem validating against schema for WarFoundry data: " + e.Message, e.Exception);
   2.159 +						} else
   2.160 +						{
   2.161 +								//TODO: Fire some kind of warning event
   2.162 +						}
   2.163 +				}
   2.164  		
   2.165 -		private static void AddSchemaToCache(XmlSchemaSet cache, string xmlNamespace, string schemaLocation)
   2.166 -		{
   2.167 -			try
   2.168 -			{
   2.169 -				cache.Add(xmlNamespace, schemaLocation);
   2.170 -			}
   2.171 -			catch (IOException)
   2.172 -			{
   2.173 -				//TODO: Warn on schema failure
   2.174 -			}
   2.175 -			catch (XmlSchemaException)
   2.176 -			{
   2.177 -				//TODO: Warn on schema failure
   2.178 -			}
   2.179 -			catch (XmlException)
   2.180 -			{
   2.181 -				//TODO: Warn on schema failure
   2.182 -			}
   2.183 -		}
   2.184 -		
   2.185 -		public static XmlDocument CreateXmlDocumentFromStream(Stream stream)
   2.186 -		{
   2.187 -			XmlDocument doc = new XmlDocument();
   2.188 -			XmlReader reader = XmlReader.Create(stream, GetReaderSettings());
   2.189 +				public static XmlDocument CreateXmlDocumentFromStream(Stream stream)
   2.190 +				{
   2.191 +						XmlDocument doc = new XmlDocument();
   2.192 +						XmlReader reader = XmlReader.Create(stream, GetReaderSettings());
   2.193  			
   2.194 -			try
   2.195 -			{
   2.196 -				doc.Load(reader);
   2.197 -			}
   2.198 +						try
   2.199 +						{
   2.200 +								doc.Load(reader);
   2.201 +						}
   2.202  			//Don't catch XMLSchemaExceptions - let them get thrown out
   2.203  			finally
   2.204 -			{
   2.205 -				reader.Close();
   2.206 -			}
   2.207 +						{
   2.208 +								reader.Close();
   2.209 +						}
   2.210  
   2.211 -			return doc;
   2.212 +						return doc;
   2.213 +				}
   2.214 +		
   2.215 +				public static bool CanCompleteLoading(IWarFoundryStagedLoadObject obj)
   2.216 +				{
   2.217 +						bool canLoad = true;			
   2.218 +			
   2.219 +						if (obj.IsFullyLoaded)
   2.220 +						{
   2.221 +								canLoad = false;
   2.222 +						} else if (obj.IsLoading)
   2.223 +						{
   2.224 +								canLoad = false;
   2.225 +						}
   2.226 +			
   2.227 +						return canLoad;
   2.228 +				}
   2.229  		}
   2.230 -		
   2.231 -		public static bool CanCompleteLoading(IWarFoundryStagedLoadObject obj)
   2.232 -		{
   2.233 -			bool canLoad = true;			
   2.234 -			
   2.235 -			if (obj.IsFullyLoaded)
   2.236 -			{
   2.237 -				canLoad = false;
   2.238 -			}
   2.239 -			else if (obj.IsLoading)
   2.240 -			{
   2.241 -				canLoad = false;
   2.242 -			}
   2.243 -			
   2.244 -			return canLoad;
   2.245 -		}
   2.246 -	}
   2.247  }
     3.1 --- a/API/WarFoundryHacks.cs	Wed May 23 21:00:33 2012 +0100
     3.2 +++ b/API/WarFoundryHacks.cs	Mon Jun 25 21:04:02 2012 +0100
     3.3 @@ -19,7 +19,7 @@
     3.4  		public static void Initialise()
     3.5  		{
     3.6  			//Set default data path - should be a preference
     3.7 -			WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Path.Combine(Constants.ExecutablePath, "data")));
     3.8 +			//WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Path.Combine(Constants.ExecutablePath, "data")));
     3.9  			//Make sure we have at least one loader - should be controlled by plugins
    3.10  			WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory());
    3.11  			//Make sure we have a way to save files - should be controlled by plugins
     4.1 --- a/IBBoard.WarFoundry.API.csproj	Wed May 23 21:00:33 2012 +0100
     4.2 +++ b/IBBoard.WarFoundry.API.csproj	Mon Jun 25 21:04:02 2012 +0100
     4.3 @@ -62,42 +62,6 @@
     4.4      <None Include="COPYING" />
     4.5      <Compile Include="API\Exporters\WarFoundryXMLWithXSLExporter.cs" />
     4.6      <Compile Include="AssemblyInfo.cs" />
     4.7 -    <None Include="schemas\army.xsd">
     4.8 -      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
     4.9 -      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    4.10 -    </None>
    4.11 -    <None Include="schemas\race.xsd">
    4.12 -      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
    4.13 -      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    4.14 -    </None>
    4.15 -    <None Include="schemas\system.xsd">
    4.16 -      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
    4.17 -      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    4.18 -    </None>
    4.19 -    <None Include="schemas\warfoundry-cats.xsd">
    4.20 -      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
    4.21 -      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    4.22 -    </None>
    4.23 -    <None Include="schemas\warfoundry-core.xsd">
    4.24 -      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
    4.25 -      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    4.26 -    </None>
    4.27 -    <None Include="schemas\xhtml1-strict.dtd">
    4.28 -      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
    4.29 -      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    4.30 -    </None>
    4.31 -    <None Include="schemas\xhtml-lat1.ent">
    4.32 -      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
    4.33 -      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    4.34 -    </None>
    4.35 -    <None Include="schemas\xhtml-special.ent">
    4.36 -      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
    4.37 -      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    4.38 -    </None>
    4.39 -    <None Include="schemas\xhtml-symbol.ent">
    4.40 -      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
    4.41 -      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    4.42 -    </None>
    4.43      <Compile Include="API\Objects\ICostedWarFoundryObject.cs" />
    4.44      <Compile Include="API\Commands\CreateAndAddUnitCommand.cs" />
    4.45      <Compile Include="API\Commands\RemoveUnitCommand.cs" />
    4.46 @@ -234,4 +198,33 @@
    4.47    <ItemGroup>
    4.48      <Folder Include="API\Objects\Requirement\Context\" />
    4.49    </ItemGroup>
    4.50 +  <ItemGroup>
    4.51 +    <EmbeddedResource Include="schemas\army.xsd">
    4.52 +      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
    4.53 +    </EmbeddedResource>
    4.54 +    <EmbeddedResource Include="schemas\race.xsd">
    4.55 +      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
    4.56 +    </EmbeddedResource>
    4.57 +    <EmbeddedResource Include="schemas\system.xsd">
    4.58 +      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
    4.59 +    </EmbeddedResource>
    4.60 +    <EmbeddedResource Include="schemas\warfoundry-cats.xsd">
    4.61 +      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
    4.62 +    </EmbeddedResource>
    4.63 +    <EmbeddedResource Include="schemas\warfoundry-core.xsd">
    4.64 +      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
    4.65 +    </EmbeddedResource>
    4.66 +    <EmbeddedResource Include="schemas\xhtml1-strict.dtd">
    4.67 +      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
    4.68 +    </EmbeddedResource>
    4.69 +    <EmbeddedResource Include="schemas\xhtml-lat1.ent">
    4.70 +      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
    4.71 +    </EmbeddedResource>
    4.72 +    <EmbeddedResource Include="schemas\xhtml-special.ent">
    4.73 +      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
    4.74 +    </EmbeddedResource>
    4.75 +    <EmbeddedResource Include="schemas\xhtml-symbol.ent">
    4.76 +      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
    4.77 +    </EmbeddedResource>
    4.78 +  </ItemGroup>
    4.79  </Project>
    4.80 \ No newline at end of file