static FactorySetting() { using (Stream stream = Application.GetResourceStream(new Uri(@"Assets\FactorySetting-1.40.X9A", UriKind.Relative)).Stream) Instance = X9aFile.Parse(stream); InitSound = Instance.Voices.Last(); }
private void LoadFile(string path) { try { x9aFile = ParseX9A(path); } catch (Exception ex) { TaskDialog taskDialog = new TaskDialog(); taskDialog.MainIcon = TaskDialogIcon.Error; taskDialog.Content = "X9A Editor cannot read this file, most likely because it was created using an unsupported CP88/CP73 firmware version.\r\n\r\nPlease report this issue on <a href=\"https://github.com/chausner/X9AEditor\">GitHub</a>."; taskDialog.ExpandedInformation = ex.ToString(); taskDialog.EnableHyperlinks = true; taskDialog.AllowDialogCancellation = true; taskDialog.WindowTitle = "Error opening file"; taskDialog.Buttons.Add(new TaskDialogButton(ButtonType.Ok)); taskDialog.HyperlinkClicked += (sender, e) => Process.Start(e.Href); taskDialog.ShowDialog(); return; } LoadedFilePath = path; Voices.Clear(); for (int i = 0; i < x9aFile.Voices.Length; i++) { Voices.Add(new VoiceViewModel((X9aFile.Voice)x9aFile.Voices[i].Clone(), (i / 8) + 1, (i % 8) + 1, this)); } }
private X9aFile ParseX9A(string path) { X9aFile x9aFile; byte[] data = File.ReadAllBytes(path); using (MemoryStream memoryStream = new MemoryStream(data, false)) x9aFile = X9aFile.Parse(path); // as a sanity check, we re-encode the parsed file and check that we end up with exactly the same bytes // this should give us confidence that the file is in a supported format byte[] data2; using (MemoryStream memoryStream = new MemoryStream(data.Length)) { x9aFile.Save(memoryStream); data2 = memoryStream.ToArray(); } if (!data2.SequenceEqual(data)) { throw new InvalidDataException("Re-encoded X9A is different from input"); } return(x9aFile); }