changeset 443:86725e88052e

Re #380: WarFoundry chokes on zips written by Mac OS X * Add "is dot-file" check to behave like Linux and Mac and ignore files with name ".something" Also: * Fix load failure message argument order * Save some regex checks by making sure zip entry is a file first
author IBBoard <dev@ibboard.co.uk>
date Sun, 04 Dec 2011 20:40:31 +0000
parents 5ac76de8ce62
children 206a45fdfa9e
files API/AbstractWarFoundryLoader.cs API/Factories/AbstractNativeWarFoundryFactory.cs API/Factories/Xml/WarFoundryXmlFactory.cs
diffstat 3 files changed, 35 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/API/AbstractWarFoundryLoader.cs	Sat Dec 03 20:10:13 2011 +0000
+++ b/API/AbstractWarFoundryLoader.cs	Sun Dec 04 20:40:31 2011 +0000
@@ -298,7 +298,7 @@
 	
 					if (!loaded)
 					{
-						failure = new FileLoadFailure(file, "FileLoadFailed", "Failed to load {0} as GameSystem using {1}");
+						failure = new FileLoadFailure(file, "Failed to load \"{0}\" as GameSystem using {1}", "FileLoadFailed");
 					}
 				}
 				catch (Exception ex)
@@ -330,7 +330,7 @@
 	
 					if (!loaded)
 					{
-						failure = new FileLoadFailure(file, "FileLoadFailed", "Failed to load {0} as Race using {1}");
+						failure = new FileLoadFailure(file, "Failed to load {0} as Race using {1}", "FileLoadFailed");
 					}
 				}
 				catch (Exception ex)
--- a/API/Factories/AbstractNativeWarFoundryFactory.cs	Sat Dec 03 20:10:13 2011 +0000
+++ b/API/Factories/AbstractNativeWarFoundryFactory.cs	Sun Dec 04 20:40:31 2011 +0000
@@ -29,22 +29,22 @@
 			//Do nothing - just make the constructor non-public
 		}
 				
-		protected override ZipFile GetFileAsSupportedType (FileInfo file)
+		protected override ZipFile GetFileAsSupportedType(FileInfo file)
 		{
 			ZipFile zip = null;
 			string ext = file.Extension.ToLower();
 
-			if (ext == ".race" || ext == ".army" || ext == ".system")
+			if (ext == ".race" || ext == ".army" || ext == ".system")
 			{
-				try
+				try
 				{
 					zip = new ZipFile(file.FullName);
-				}
-				catch (ZipException)
+				}
+				catch (ZipException)
 				{
 					//Silently dispose as per spec for the method
-				}
-				catch (IOException)
+				}
+				catch (IOException)
 				{
 					//Silently dispose as per spec for the method
 				}
@@ -147,14 +147,26 @@
 
 			foreach (ZipEntry entry in dataStreams)
 			{
+				if (IsDotFile(entry))
+				{
+					continue;
+				}
+
 				using (Stream dataStream = file.GetInputStream(entry))
 				{
-				armies.Add(CreateArmyFromStream(file, dataStream));
+					armies.Add(CreateArmyFromStream(file, dataStream));
 				}
 			}
 			
 			return armies;
 		}
+
+		private bool IsDotFile(ZipEntry entry)
+		{
+			string name = entry.Name;
+			int slashIdx = name.LastIndexOf('/');
+			return (slashIdx != -1 && slashIdx == name.LastIndexOf("/.")) || (name.Length > 0 && name[0] == '.');
+		}
 		
 		protected abstract ICollection<ZipEntry> GetArmyZipEntries(ZipFile file);
 		protected abstract Army CreateArmyFromStream(ZipFile file, Stream dataStream);
@@ -165,7 +177,12 @@
 			ICollection<Race> races = new List<Race>();
 
 			foreach (ZipEntry entry in dataStreams)
-			{					
+			{
+				if (IsDotFile(entry))
+				{
+					continue;
+				}
+
 				using (Stream dataStream = file.GetInputStream(entry))
 				{
 					races.Add(CreateRaceFromStream(file, dataStream));
@@ -185,6 +202,11 @@
 
 			foreach (ZipEntry entry in dataStreams)
 			{
+				if (IsDotFile(entry))
+				{
+					continue;
+				}
+
 				using (Stream dataStream = file.GetInputStream(entry))
 				{
 					systems.Add(CreateGameSystemFromStream(file, dataStream));
--- a/API/Factories/Xml/WarFoundryXmlFactory.cs	Sat Dec 03 20:10:13 2011 +0000
+++ b/API/Factories/Xml/WarFoundryXmlFactory.cs	Sun Dec 04 20:40:31 2011 +0000
@@ -40,7 +40,7 @@
 			return factory;
 		}
 		
-		private WarFoundryXmlFactory() : base()
+		protected WarFoundryXmlFactory() : base()
 		{
 			gameSystemFactory = new WarFoundryXmlGameSystemFactory(this);
 			raceFactory = new WarFoundryXmlRaceFactory(this);
@@ -89,7 +89,7 @@
 				
 			foreach (ZipEntry entry in file)
 			{
-				if (re.IsMatch(entry.Name))
+				if (entry.IsFile && re.IsMatch(entry.Name))
 				{
 					entries.Add(entry);
 				}