From 349ed9da94113b690e5ef6d0f2a5166f9ec1aa6b Mon Sep 17 00:00:00 2001 From: glax Date: Sat, 1 Apr 2023 15:54:35 +0200 Subject: [PATCH] Check if files for ways and tags exist upon import. --- Server/RegionConverter.cs | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/Server/RegionConverter.cs b/Server/RegionConverter.cs index bd61438..b7c31d9 100644 --- a/Server/RegionConverter.cs +++ b/Server/RegionConverter.cs @@ -251,14 +251,16 @@ public class RegionConverter throw new FileNotFoundException("Region does not exist"); #pragma warning disable SYSLIB0011 - using (FileStream wayFileStream = new FileStream(Path.Join(folderPath, regionHash.ToString(), RegionConverter.WaysFileName), FileMode.Open)) - { - while (wayFileStream.Position < wayFileStream.Length) + string waysPath = Path.Join(folderPath, regionHash.ToString(), RegionConverter.WaysFileName); + if(File.Exists(waysPath)) + using (FileStream wayFileStream = new FileStream(waysPath, FileMode.Open)) { - OsmEdge deserializedEdge = (OsmEdge)bFormatter.Deserialize(wayFileStream); - ways.Add(deserializedEdge); + while (wayFileStream.Position < wayFileStream.Length) + { + OsmEdge deserializedEdge = (OsmEdge)bFormatter.Deserialize(wayFileStream); + ways.Add(deserializedEdge); + } } - } using (FileStream nodeFileStream = new FileStream(Path.Join(folderPath, regionHash.ToString(), RegionConverter.NodesFileName), FileMode.Open)) { @@ -268,17 +270,19 @@ public class RegionConverter newRegion.nodes.Add(deserializedNode); } } - - using (FileStream tagsFileStream = new FileStream(Path.Join(folderPath, regionHash.ToString(), RegionConverter.TagsFileName), FileMode.Open)) - { - while (tagsFileStream.Position < tagsFileStream.Length) + + string tagsPath = Path.Join(folderPath, regionHash.ToString(), RegionConverter.TagsFileName); + if(File.Exists(tagsPath)) + using (FileStream tagsFileStream = new FileStream(tagsPath, FileMode.Open)) { - TagManager tm = (TagManager)bFormatter.Deserialize(tagsFileStream); - ulong id = (ulong)tm.wayTagSets.First()!.Value.First(tag => tag.key == Tag.TagType.id)!.value; - foreach(Tag tag in tm.wayTagSets.First()!.Value) - newRegion.tagManager.AddTag(id, tag); + while (tagsFileStream.Position < tagsFileStream.Length) + { + TagManager tm = (TagManager)bFormatter.Deserialize(tagsFileStream); + ulong id = (ulong)tm.wayTagSets.First()!.Value.First(tag => tag.key == Tag.TagType.id)!.value; + foreach(Tag tag in tm.wayTagSets.First()!.Value) + newRegion.tagManager.AddTag(id, tag); + } } - } #pragma warning restore SYSLIB0011 return new ValueTuple>(newRegion, ways);