# HG changeset patch # User IBBoard # Date 1323031231 0 # Node ID 86725e88052e137ca3d583836ddc35d7cb764240 # Parent 5ac76de8ce628c8152c6df678b4c9996f30b6a48 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 diff -r 5ac76de8ce62 -r 86725e88052e API/AbstractWarFoundryLoader.cs --- 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) diff -r 5ac76de8ce62 -r 86725e88052e API/Factories/AbstractNativeWarFoundryFactory.cs --- 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 GetArmyZipEntries(ZipFile file); protected abstract Army CreateArmyFromStream(ZipFile file, Stream dataStream); @@ -165,7 +177,12 @@ ICollection races = new List(); 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)); diff -r 5ac76de8ce62 -r 86725e88052e API/Factories/Xml/WarFoundryXmlFactory.cs --- 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); }