예제 #1
0
        private static async Task <List <SvgLayer> > ParseSvgLayers(string filePath)
        {
            if (Path.GetExtension(filePath) == ".zip")
            {
                Console.WriteLine($"Terrain data loading from ZIP");
                var zip    = ZipFile.Open(filePath, ZipArchiveMode.Read);
                var zipRef = new SharedDisposable <ZipArchive>(zip); //This ref will later do the disposing

                List <SvgLayer> ret = new List <SvgLayer>();

                foreach (var zipArchiveEntry in zip.Entries)
                {
                    var layer = new SvgLayer();
                    layer.name    = zipArchiveEntry.FullName;
                    layer.content = new MapLayerDataZipFile(zipArchiveEntry, zipRef.Acquire());
                    layer.width   = (int)zipArchiveEntry.LastWriteTime.Add(zipArchiveEntry.LastWriteTime.Offset).AddYears(-30).ToUnixTimeSeconds();
                    ret.Add(layer);
                }

                return(ret);
            }

            if (Path.GetExtension(filePath) == ".svgz")
            {
                Console.WriteLine($"Terrain data is SVGZ, converting to zip...");
                //process raw first
                await Task.Run(() => ProcessRawSVGZ(filePath));

                filePath = Path.ChangeExtension(filePath, "zip");
                return(await Task.Run(() => ParseSvgLayers(filePath))); //Force seperate thread, as this is slow
            }

            if (Path.GetExtension(filePath) == ".svg")
            {
                Console.WriteLine($"Terrain data is SVG, converting to zip...");
                //process raw first
                await Task.Run(() => ProcessRawSVG(filePath));

                filePath = Path.ChangeExtension(filePath, "zip");
                return(await Task.Run(() => ParseSvgLayers(filePath))); //Force seperate thread, as this is slow
            }

            return(null);
        }
예제 #2
0
 public MapLayerDataZipFile(ZipArchiveEntry zipArchiveEntry, SharedDisposable <ZipArchive> .Reference reference)
 {
     this.zipArchiveEntry = zipArchiveEntry;
     this.reference       = reference;
 }
예제 #3
0
 public Reference(SharedDisposable <T> owner)
 {
     mOwner = owner;
 }