public CnvrsTextSerializable(CnvrsTextFile cnvrsTextFile) { Sheets = cnvrsTextFile.Sheets.Select(x => new Sheet { Name = x.Key, Texts = x.Value.Select(x2 => CreateTextElement(x2.Key, x2.Value)) .ToList(), }).ToList(); Fonts = cnvrsTextFile.Fonts.Select(x => new Font { Name = x.Key, Typeface = x.Value.Typeface, Size = x.Value.Size, LineSpacing = x.Value.LineSpacing, Unknown1 = x.Value.Unknown1, Color = x.Value.Color, Unknown2 = x.Value.Unknown2, Unknown3 = x.Value.Unknown3, Unknown4 = x.Value.Unknown4, }).ToList(); Layouts = cnvrsTextFile.Layouts.Select(x => new Layout { Name = x.Key, TextAlignment = x.Value.TextAlignment, VerticalAlignment = x.Value.VerticalAlignment, WordWrap = x.Value.WordWrap, Fit = x.Value.Fit, }).ToList(); }
static void Convert(RootCommandOptions options) { foreach (var file in options.Files) { var filePath = file.ToString(); // Returns the original path supplied to FileInfo. // Convert from XML if (filePath.EndsWith(".xml", StringComparison.OrdinalIgnoreCase)) { // XML to MTX if (string.Equals(options.Format, "mtx", StringComparison.OrdinalIgnoreCase) || (options.Format is null && filePath.EndsWith(".mtx.xml", StringComparison.OrdinalIgnoreCase))) { var destinationPath = options.Output is not null ? options.Output.FullName : Path.ChangeExtension(filePath, null); // Removes the ".xml" part of the extension. MtxEncoding encoding; if (options.Fpd is not null) { var fpdFile = new FpdFile(options.Fpd.ToString()); encoding = new CharacterMapMtxEncoding(fpdFile.Characters); } else if (options.Fnt is not null) { var fntFile = new FntFile(options.Fnt.ToString()); encoding = new CharacterMapMtxEncoding(fntFile.Characters); } else { encoding = new Utf16MtxEncoding(); } var serializedSource = File.ReadAllText(filePath); var deserializedSource = Utf8XmlSerializer.Deserialize <MtxSerializable>(serializedSource) ?? throw new NullValueException(); var destination = new MtxFile(deserializedSource, encoding); destination.Save(destinationPath); } // XML to CNVRS-TEXT else if (string.Equals(options.Format, "cnvrs-text", StringComparison.OrdinalIgnoreCase) || (options.Format is null && filePath.EndsWith(".cnvrs-text.xml", StringComparison.OrdinalIgnoreCase))) { var destinationPath = options.Output is not null ? options.Output.FullName : Path.ChangeExtension(filePath, null); // Removes the ".xml" part of the extension. var serializedSource = File.ReadAllText(filePath); var deserializedSource = Utf8XmlSerializer.Deserialize <CnvrsTextSerializable>(serializedSource) ?? throw new NullValueException(); var destination = new CnvrsTextFile(deserializedSource); destination.Save(destinationPath); } }