private static void ExtractFile(NameSpaceFile nsf, DirectoryInfo currentOutputDirectory) { var path = Path.Combine(currentOutputDirectory.FullName, nsf.Name); bool useJson = !exportBson; var obj = nsf.Object as WzProperty; if (obj == null) { Console.WriteLine("Unable to export {0}, as its not a WzProperty", nsf.NodePath); return; } byte[] data; using (var exp = new Exporter(exportOptions, obj)) { if (useJson) { data = Encoding.ASCII.GetBytes(exp.ToJson()); } else { data = exp.ToBson(); } if (exportOptions.HasFlag(Options.ExternalImageExport)) { // Generate image path of the first 4 characters of the name (if possible) var imgDir = globalOutputDirectory.CreateSubdirectory("images"); var name = obj.Name.Replace(".img", ""); if (name.Length > 0) { imgDir = imgDir.CreateSubdirectory("" + name[0]); } if (name.Length > 1) { imgDir = imgDir.CreateSubdirectory("" + name[1]); } if (name.Length > 2) { imgDir = imgDir.CreateSubdirectory("" + name[2]); } if (name.Length > 3) { imgDir = imgDir.CreateSubdirectory("" + name[3]); } ExtractImages(exp, imgDir); } } nsf.Checksum = (int)Crc32Algorithm.Compute(data); // This will replace .img with .hash.(json|bson) var outputFile = Path.ChangeExtension(path, $".{nsf.Checksum:X8}." + (useJson ? "json" : "bson")); if (File.Exists(outputFile)) { return; } Console.WriteLine("Writing {0}", outputFile); File.WriteAllBytes( outputFile, data ); }
private void ProcessStringNameSpaceFile(StringDataType type, NameSpaceFile imgFile) { if (!Contains((int)type)) { InsertItem(new GenericKeyedTemplate <StringTemplate>((int)type)); } WzProperty dataBlob = imgFile.Object as WzFileProperty; if (dataBlob.Name.Equals("Eqp.img")) { foreach (var eqpTypeBlob in dataBlob["Eqp"] as WzProperty) { run(eqpTypeBlob.Value as WzProperty); } } else if (dataBlob.Name.Equals("Etc.img")) { run(dataBlob["Etc"] as WzProperty); } else if (dataBlob.Name.Equals("Map.img")) { foreach (var mapBlob in dataBlob) { run(mapBlob.Value as WzProperty); } } else { run(dataBlob); } void run(WzProperty blob) { foreach (var stringBlob in blob) { var templateId = Convert.ToInt32(stringBlob.Key); var prop = stringBlob.Value as WzProperty; if (prop.HasChild("bookName")) { continue; // skill book, we only want skill names } var pEntry = new StringTemplate(templateId); AssignProviderAttributes(pEntry, prop); this[type].Add(pEntry); // BEGIN PROPERTY AUTO POPULATION //foreach (var templateMember in pEntry.GetType().GetMembers()) //{ // var memberData = templateMember.GetCustomAttributes(); // var providerAttribute = memberData // .FirstOrDefault(md => md is ProviderAttributeAttribute); // if (providerAttribute is ProviderAttributeAttribute paa) // { // var pi = pEntry.GetType().GetProperty(templateMember.Name); // // if pi is null: throw -- should not happen // var val = prop.GetImgPropVal(pi.PropertyType, paa.AttributeName); // if (val.IsNullOrDefault() || val is string s && s.Length <= 0) // { // foreach (var attrName in paa.AltAttributeNames) // { // val = prop.GetImgPropVal(pi.PropertyType, attrName); // if (!val.IsNullOrDefault() || val is string ss && ss.Length <= 0) break; // } // } // pi.SetValue(pEntry, prop.GetImgPropVal(pi.PropertyType, paa.AttributeName)); // } //} // END PROPERTY AUTO POPULATION //this[type].Add(new StringTemplate(templateId) //{ // Name = prop.GetString("name"), // StreetName = prop.GetString("streetName"), // Description = prop.GetString("desc") //}); //if (this[type][templateId].Name is null) //{ // this[type][templateId].Name = prop.GetString("mapName"); //} //if (this[type][templateId].Name is null) //{ // throw new NullReferenceException($"Template name is null. ID: {templateId}"); //} } } }