Check if files for ways and tags exist upon import.

This commit is contained in:
glax 2023-04-01 15:54:35 +02:00
parent 87e260562f
commit 349ed9da94

View File

@ -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<Region, HashSet<OsmEdge>>(newRegion, ways);