X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;ds=sidebyside;f=ShardProcessor%2FProgram.cs;h=0d2f1e1b85fa1bfd29e742a93b8095e1daeadc12;hb=ec3438c8c02c57ac0241b388851e659b1cc0fc65;hp=e9e5b6c44e2bf610b1a4b906f58b5d9767304d82;hpb=989738939a2e623b8bf6db337968e3114a9a99ee;p=automap%2Fautomap.git diff --git a/ShardProcessor/Program.cs b/ShardProcessor/Program.cs index e9e5b6c..0d2f1e1 100644 --- a/ShardProcessor/Program.cs +++ b/ShardProcessor/Program.cs @@ -1,19 +1,101 @@ using System; +using System.IO; +using System.Text.RegularExpressions; + +using Automap; + +using Hjg.Pngcs; +using Hjg.Pngcs.Chunks; + +using ProtoBuf; namespace ShardProcessor -{ +{ class MainClass { - /* + //private ILogger Logger { get; set; } + const string chunkFile_filter = @"*_*.png"; + static Regex chunkShardRegex = new Regex(@"(?[\d]+)_(?[\d]+)\.png", RegexOptions.Singleline); + static string mapPath; + internal const string _chunkPath = @"Chunks"; + + /* TODO: -Process existing PNGs: Report/Dump contents of Chunk Metadata, as per current version + -Grayscale Heightmap extraction from P.Buf heightmap from shards -Extract contents of game's SQLLite map DB, INTO Automap type shards... -Other stuff? chunk fixing / validation? */ public static void Main(string[ ] args) { Console.WriteLine("AUTOMAP Offline Shard processor v0.1"); + //Called once - thus it can only be in a static constructor. + PngChunk.FactoryRegister(PngMetadataChunk.ID, typeof(PngMetadataChunk)); + ArgsDecoder(args); } + + private static void ArgsDecoder(string[ ] args) + { + //#1 Path to maps '~/ApplicationData/vintagestory/Map/World_1234567890 + mapPath = args[1]; + + //#0 Command: Heightmaps (Generation from existing shard data) + string command = args[0]; + + if (command == "--heightmap") { + Process_ShardData( ); + } + + } + + private static void Process_ShardData( ) + { + var shardsDir = new DirectoryInfo( Path.Combine(mapPath , _chunkPath)); + + var shardFiles = shardsDir.GetFiles(chunkFile_filter); + + if (shardFiles.Length > 0) { + #if DEBUG + //Logger.VerboseDebug("Metadata reloading from {0} shards", shardFiles.Length); + #endif + + foreach (var shardFile in shardFiles) { + + if (shardFile.Length < 1024) continue; + var result = chunkShardRegex.Match(shardFile.Name); + if (!result.Success) continue; + + int X_chunk_pos = int.Parse(result.Groups["X"].Value); + int Z_chunk_pos = int.Parse(result.Groups["Z"].Value); + + try { + using (var fileStream = shardFile.OpenRead( )) { + + PngReader pngRead = new PngReader(fileStream); + pngRead.ReadSkippingAllRows( ); + pngRead.End( ); + //Parse PNG chunks for METADATA in shard + PngMetadataChunk metadataFromPng = pngRead.GetChunksList( ).GetById1(PngMetadataChunk.ID) as PngMetadataChunk; + ColumnMeta columnData = metadataFromPng.ChunkMetadata; + //columnData.HeightMap //Should be sane Heightmap... + + + + } + + } catch (PngjException someEx) { + //Logger.Error("PNG Corruption file '{0}' - Reason: {1}", shardFile.Name, someEx); + continue; + } catch (ProtoException protoEx) { + //Logger.Error("ProtoBuf invalid! file:'{0}' - Reason: {1}", shardFile.Name, protoEx); + continue; + } + } + } + + + } + } }