private static OS.Schema Schema() { if (os != null) { return(os); } var osl = new ObjectSchemaLoader(); foreach (var ObjectSchemaPath in c.SchemaPaths) { if (Directory.Exists(ObjectSchemaPath)) { foreach (var f in Directory.GetFiles(ObjectSchemaPath, "*.tree", SearchOption.AllDirectories).OrderBy(s => s, StringComparer.OrdinalIgnoreCase)) { osl.LoadType(f); } } else { osl.LoadType(ObjectSchemaPath); } } var oslr = osl.GetResult(); os = oslr.Schema; return(os); }
public static void GenerateTypeCompatibilityTreeFile(List <KeyValuePair <String, String> > ListOfObjectSchemaDirOrCookedObjectSchemaFileAndVersion, String CompatibilityObjectSchemaFile, bool CommunicationOnly = false) { var HeadObjectSchema = GetObjectSchema(); var HeadSchema = HeadObjectSchema.GetSubSchema(HeadObjectSchema.Types.Where(t => (!CommunicationOnly || (t.OnPrimitive || t.OnClientCommand || t.OnServerCommand)) && (t.Version() == "")), new TypeSpec[] { }); var Versions = ListOfObjectSchemaDirOrCookedObjectSchemaFileAndVersion.Select(p => { var vosl = new ObjectSchemaLoader(); if (File.Exists(p.Key)) { vosl.LoadSchema(p.Key); } else if (Directory.Exists(p.Key)) { foreach (var f in Directory.GetFiles(p.Key, "*.tree", SearchOption.AllDirectories).OrderBy(s => s, StringComparer.OrdinalIgnoreCase)) { vosl.LoadType(f); } } else { throw new InvalidOperationException("InvalidPath: " + p.Key); } var Schema = vosl.GetResult().Schema; return(new KeyValuePair <String, Schema>(p.Value, Schema.GetSubSchema(Schema.Types.Where(t => (!CommunicationOnly || (t.OnPrimitive || t.OnClientCommand || t.OnServerCommand)) && (t.Version() == "")), new TypeSpec[] { }))); }).ToList(); var Comment = "" + @"==========================================================================" + "\r\n" + @"" + "\r\n" + @" Notice: This file is automatically generated." + "\r\n" + @" Please don't modify this file." + "\r\n" + @"" + "\r\n" + @" SchemaHash: Head 0x" + HeadSchema.GetNonattributed().Hash().ToString("X16") + "\r\n" + String.Join("", Versions.AsEnumerable().Reverse().Select(v => @" " + v.Key + " 0x" + v.Value.GetNonattributed().Hash().ToString("X16") + "\r\n")) + @"" + "\r\n" + @"==========================================================================" + "\r\n" ; var DiffGenerator = new ObjectSchemaDiffGenerator(); var Result = DiffGenerator.GetCompatibleTypes(Versions.Concat(new List <KeyValuePair <String, Schema> > { new KeyValuePair <String, Schema>("", HeadSchema) }).ToList()); var osw = new ObjectSchemaWriter(); var Compiled = osw.Write(Result, Comment); if (File.Exists(CompatibilityObjectSchemaFile)) { var Original = Txt.ReadFile(CompatibilityObjectSchemaFile); if (String.Equals(Compiled, Original, StringComparison.Ordinal)) { return; } } var Dir = FileNameHandling.GetFileDirectory(CompatibilityObjectSchemaFile); if (Dir != "" && !Directory.Exists(Dir)) { Directory.CreateDirectory(Dir); } Txt.WriteFile(CompatibilityObjectSchemaFile, TextEncoding.UTF8, Compiled); }