diff api/Factories/Xml/WarFoundryXmlFactory.cs @ 312:3854c26073c4

Re #253: Allow multiple data files in a single zip * Rebuild file loading to start to allow multiple files in a native file
author IBBoard <dev@ibboard.co.uk>
date Sat, 26 Feb 2011 20:15:12 +0000
parents b9b8b0e60c31
children
line wrap: on
line diff
--- a/api/Factories/Xml/WarFoundryXmlFactory.cs	Wed Feb 23 20:44:37 2011 +0000
+++ b/api/Factories/Xml/WarFoundryXmlFactory.cs	Sat Feb 26 20:15:12 2011 +0000
@@ -17,6 +17,7 @@
 using IBBoard.WarFoundry.API.Requirements;
 using IBBoard.WarFoundry.API.Objects;
 using ICSharpCode.SharpZipLib.Zip;
+using System.Text.RegularExpressions;
 
 namespace IBBoard.WarFoundry.API.Factories.Xml
 {
@@ -64,22 +65,38 @@
 		
 		protected override bool CheckCanFindArmyFileContent(ZipFile file)
 		{
-			return file.FindEntry("data.armyx", true) > -1;
+			return FindEntries(file, "*.armyx").Count > 0;
 		}
 		
 		protected override bool CheckCanFindSystemFileContent(ZipFile file)
 		{
-			return file.FindEntry("data.systemx", true) > -1;
+			return FindEntries(file, "*.systemx").Count > 0;
 		}
 		
 		protected override bool CheckCanFindRaceFileContent(ZipFile file)
 		{
-			return file.FindEntry("data.racex", true) > -1;
+			return FindEntries(file, "*.racex").Count > 0;
+		}
+		
+		protected override ICollection<ZipEntry> GetArmyZipEntries(ZipFile file)
+		{
+			return FindEntries(file, "*.armyx");
 		}
 		
-		protected override Stream GetArmyDataStream(ZipFile file)
+		private ICollection<ZipEntry> FindEntries(ZipFile file, string wildcardPattern)
 		{
-			return file.GetInputStream(file.FindEntry("data.armyx", true));
+			Regex re = new Regex("^" + Regex.Escape(wildcardPattern).Replace(@"\*", ".*").Replace(@"\?", ".") + "$", RegexOptions.IgnoreCase | RegexOptions.Singleline);
+			ICollection<ZipEntry> entries = new List<ZipEntry>();
+				
+			foreach (ZipEntry entry in file)
+			{
+				if (re.IsMatch(entry.Name))
+				{
+					entries.Add(entry);
+				}
+			}
+			
+			return entries;
 		}
 		
 		protected override Army CreateArmyFromStream (ZipFile file, Stream dataStream)
@@ -102,9 +119,9 @@
 			return elem;
 		}
 
-		protected override Stream GetGameSystemDataStream (ZipFile file)
+		protected override ICollection<ZipEntry> GetGameSystemZipEntries(ZipFile file)
 		{
-			return file.GetInputStream(file.FindEntry("data.systemx", true));
+			return FindEntries(file, "*.systemx");
 		}
 		
 		protected override GameSystem CreateGameSystemFromStream (ZipFile file, Stream dataStream)
@@ -114,9 +131,9 @@
 			return gameSystemFactory.CreateSystemFromElement(file, elem);
 		}
 		
-		protected override Stream GetRaceDataStream (ZipFile file)
+		protected override ICollection<ZipEntry> GetRaceZipEntries(ZipFile file)
 		{
-			return file.GetInputStream(file.FindEntry("data.racex", true));
+			return FindEntries(file, "*.racex");
 		}
 		
 		protected override Race CreateRaceFromStream (ZipFile file, Stream dataStream)