public static void Main(string[] args) { var mode = Mode.Unknown; bool multiExport = true; bool showHelp = false; bool quiet = false; var options = new OptionSet() { { "fcb", "convert XML to FCB", v => mode = v != null ? Mode.ToFCB : mode }, { "xml", "convert FCB to XML", v => mode = v != null ? Mode.ToXML : mode }, { "m|multi-export", "when converting FCB to XML, export to many files when possible", v => multiExport = v != null }, { "q|quiet", "be quiet", v => quiet = v != null }, { "h|help", "show this message and exit", v => showHelp = v != null }, }; List <string> extras; try { extras = options.Parse(args); } catch (OptionException e) { Console.Write("{0}: ", GetExecutableName()); Console.WriteLine(e.Message); Console.WriteLine("Try `{0} --help' for more information.", GetExecutableName()); return; } if (mode == Mode.Unknown && extras.Count >= 1) { var extension = Path.GetExtension(extras[0]); if (extension == ".fcb") { mode = Mode.ToXML; } else if (extension == ".xml") { mode = Mode.ToFCB; } } if (showHelp == true || mode == Mode.Unknown || extras.Count < 1 || extras.Count > 2) { Console.WriteLine("Usage: {0} [OPTIONS]+ input [output]", GetExecutableName()); Console.WriteLine(); Console.WriteLine("Options:"); options.WriteOptionDescriptions(Console.Out); return; } if (quiet == false) { Console.WriteLine("Loading project..."); } var manager = ProjectData.Manager.Load(); IDefinitionProvider defs = null; if (manager.ActiveProject == null) { Console.WriteLine("Warning: no active project loaded."); return; } else { defs = Definitions.Load(Path.Combine(manager.ActiveProject.ListsPath, "binary_classes.xml")); } if (mode == Mode.ToFCB) { string inputPath = extras[0]; string outputPath; string basePath; if (extras.Count > 1) { outputPath = extras[1]; } else { outputPath = Path.ChangeExtension(inputPath, null); outputPath += "_converted.fcb"; } basePath = Path.ChangeExtension(inputPath, null); inputPath = Path.GetFullPath(inputPath); outputPath = Path.GetFullPath(outputPath); basePath = Path.GetFullPath(basePath); var bf = new BinaryResourceFile(); using (var input = File.OpenRead(inputPath)) { if (quiet == false) { Console.WriteLine("Loading XML..."); } var doc = new XPathDocument(input); var nav = doc.CreateNavigator(); var root = nav.SelectSingleNode("/object"); if (root == null) { throw new FormatException(); } if (quiet == false) { Console.WriteLine("Reading XML..."); } bf.Root = ReadNode(basePath, root); } if (quiet == false) { Console.WriteLine("Writing FCB..."); } using (var output = File.Create(outputPath)) { bf.Serialize(output); } } else if (mode == Mode.ToXML) { string inputPath = extras[0]; string outputPath; string basePath; if (extras.Count > 1) { outputPath = extras[1]; basePath = Path.ChangeExtension(outputPath, null); } else { outputPath = Path.ChangeExtension(inputPath, null); outputPath += "_converted"; basePath = outputPath; outputPath += ".xml"; } inputPath = Path.GetFullPath(inputPath); outputPath = Path.GetFullPath(outputPath); basePath = Path.GetFullPath(basePath); if (quiet == false) { Console.WriteLine("Reading binary..."); } var bf = new BinaryResourceFile(); using (var input = File.OpenRead(inputPath)) { bf.Deserialize(input); } var settings = new XmlWriterSettings(); settings.Encoding = Encoding.UTF8; settings.Indent = true; settings.CheckCharacters = false; settings.OmitXmlDeclaration = true; if (quiet == false) { Console.WriteLine("Writing XML..."); } if (multiExport == true && bf.Root.Values.Count == 0 && bf.Root.TypeHash == 0xBCDD10B4 && bf.Root.Children.Where(c => c.TypeHash != 0xE0BDB3DB).Count() == 0) { using (var writer = XmlWriter.Create(outputPath, settings)) { writer.WriteStartDocument(); var root = bf.Root; { writer.WriteStartElement("object"); var def = defs.GetClassDefinition(root.TypeHash); if (def.Name != null) { writer.WriteAttributeString("type", def.Name); } writer.WriteAttributeString("hash", root.TypeHash.ToString("X8")); int counter = 0; int padLength = root.Children.Count.ToString().Length; foreach (var child in root.Children) { counter++; string childName = counter.ToString().PadLeft(padLength, '0'); // name if (child.Values.ContainsKey(0xFE11D138) == true) { var value = child.Values[0xFE11D138]; childName += "_" + Encoding.UTF8.GetString(value, 0, value.Length - 1); } Directory.CreateDirectory(basePath); var childPath = Path.Combine(basePath, childName + ".xml"); using (var childWriter = XmlWriter.Create(childPath, settings)) { childWriter.WriteStartDocument(); WriteNode(childWriter, child, defs); childWriter.WriteEndDocument(); } writer.WriteStartElement("object"); writer.WriteAttributeString("external", Path.GetFileName(childPath)); writer.WriteEndElement(); } writer.WriteEndElement(); } writer.WriteEndDocument(); } } else { using (var writer = XmlWriter.Create(outputPath, settings)) { writer.WriteStartDocument(); WriteNode(writer, bf.Root, defs); writer.WriteEndDocument(); } } } else { throw new InvalidOperationException(); } }
public static void Main(string[] args) { bool showHelp = false; var options = new OptionSet() { { "h|help", "show this message and exit", v => showHelp = v != null }, }; List <string> extras; try { extras = options.Parse(args); } catch (OptionException e) { Console.Write("{0}: ", GetExecutableName()); Console.WriteLine(e.Message); Console.WriteLine("Try `{0} --help' for more information.", GetExecutableName()); return; } if (showHelp == true || extras.Count != 1) { Console.WriteLine("Usage: {0} [OPTIONS]+ input", GetExecutableName()); Console.WriteLine(); Console.WriteLine("Options:"); options.WriteOptionDescriptions(Console.Out); return; } var targetPath = extras[0]; var values = new List <string>(); foreach (var inputPath in Directory.GetFiles(targetPath, "*.fcb", SearchOption.AllDirectories)) { var bf = new BinaryResourceFile(); using (var input = File.OpenRead(inputPath)) { Console.Error.WriteLine("Reading " + inputPath); foreach (var value in BinaryResourceFileDumper.Dump(input)) { if (values.Contains(value) == false) { values.Add(value); } } } } values.Sort(); foreach (var value in values) { Console.WriteLine(value); } }