public PreviewControl() { InitializeComponent(); rom = null; currentMessage = null; System.Drawing.Text.InstalledFontCollection fontCollection = new System.Drawing.Text.InstalledFontCollection(); FontFamily jpnFontFamily = fontCollection.Families.FirstOrDefault(x => x.Name == "Meiryo"); if (jpnFontFamily != null) { txtMessage.Font = new Font(jpnFontFamily, 9.0f); } pbPreview.Paint += ((s, ev) => { if (currentMessage != null) { ev.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; ev.Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; using (Bitmap img = rom.GetMessageImage(currentMessage, vsbPages.Value)) { ev.Graphics.DrawImage(img, new Rectangle(0, 0, img.Width * 2, img.Height * 2)); } } }); vsbPages.ValueChanged += ((s, ev) => { pbPreview.Refresh(); }); }
public static void DumpComparison(string filename, RomHandler romPrimary, RomHandler romSecondary) { TextWriter writer = File.CreateText(filename); using (HtmlTextWriter html = new HtmlTextWriter(writer)) { html.WriteLine("<!DOCTYPE html>"); html.RenderBeginTag(HtmlTextWriterTag.Html); { WriteHeader(html, string.Format("{0} Message Comparison", System.Windows.Forms.Application.ProductName)); html.RenderBeginTag(HtmlTextWriterTag.Body); { html.RenderBeginTag(HtmlTextWriterTag.H2); { if (romSecondary != null) { html.WriteEncodedText(string.Format("Comparison between {0} ({1}) and {2} ({3})", Path.GetFileName(romPrimary.FileName), romPrimary.Language, Path.GetFileName(romSecondary.FileName), romSecondary.Language)); } else { html.WriteEncodedText(string.Format("Dump of {0} ({1})", Path.GetFileName(romPrimary.FileName), romPrimary.Language)); } } html.RenderEndTag(); html.RenderBeginTag(HtmlTextWriterTag.H4); { Version ver = new Version(System.Windows.Forms.Application.ProductVersion); html.WriteEncodedText(string.Format("{0} v{1}.{2}", System.Windows.Forms.Application.ProductName, ver.Major, ver.Minor)); html.WriteEncodedText(" - "); html.WriteEncodedText(string.Format("{0}", (Assembly.GetExecutingAssembly().GetCustomAttribute(typeof(AssemblyCopyrightAttribute)) as AssemblyCopyrightAttribute).Copyright)); } html.RenderEndTag(); int numBanks = 0; if (romSecondary != null) { numBanks = (romPrimary.MessageBanks.Length == romSecondary.MessageBanks.Length ? romPrimary.MessageBanks.Length : Math.Max(romPrimary.MessageBanks.Length, romSecondary.MessageBanks.Length)); } else { numBanks = romPrimary.MessageBanks.Length; } for (int i = 0; i < numBanks; i++) { MessageBank[] langBanks = new MessageBank[] { (romPrimary != null && i < romPrimary.MessageBanks.Length ? romPrimary.MessageBanks[i] : null), (romSecondary != null && i < romSecondary.MessageBanks.Length ? romSecondary.MessageBanks[i] : null) }; string bankId = string.Format("bank-{0:D4}", i); html.AddAttribute(HtmlTextWriterAttribute.Class, "header"); html.RenderBeginTag(HtmlTextWriterTag.Div); { html.AddAttribute(HtmlTextWriterAttribute.Class, "header-text"); html.RenderBeginTag(HtmlTextWriterTag.Span); { if (romPrimary.MessageBanks[i].Number == -1) { html.Write("General"); } else { html.Write("Bank {0}", romPrimary.MessageBanks[i].Number); } } html.RenderEndTag(); html.AddAttribute(HtmlTextWriterAttribute.Class, "header-toggle"); html.RenderBeginTag(HtmlTextWriterTag.Span); { html.AddAttribute(HtmlTextWriterAttribute.Href, string.Format("javascript:toggle('{0}');", bankId), false); html.RenderBeginTag(HtmlTextWriterTag.A); { html.Write("+/-"); } html.RenderEndTag(); } html.RenderEndTag(); } html.RenderEndTag(); html.AddAttribute(HtmlTextWriterAttribute.Id, bankId); html.AddStyleAttribute(HtmlTextWriterStyle.Display, "table"); html.RenderBeginTag(HtmlTextWriterTag.Table); { html.RenderBeginTag(HtmlTextWriterTag.Tr); { html.AddAttribute(HtmlTextWriterAttribute.Class, "header-id"); html.RenderBeginTag(HtmlTextWriterTag.Th); { html.Write("ID"); } html.RenderEndTag(); html.AddAttribute(HtmlTextWriterAttribute.Class, "header-desc-text"); html.RenderBeginTag(HtmlTextWriterTag.Th); { html.Write("Primary ({0})", romPrimary.Language); } html.RenderEndTag(); if (romSecondary != null) { html.AddAttribute(HtmlTextWriterAttribute.Class, "header-desc-text"); html.RenderBeginTag(HtmlTextWriterTag.Th); { html.Write("Secondary ({0})", romSecondary.Language); } html.RenderEndTag(); } html.AddAttribute(HtmlTextWriterAttribute.Class, "header-desc-sim"); html.RenderBeginTag(HtmlTextWriterTag.Th); { html.Write("Primary ({0}; Sim)", romPrimary.Language); } html.RenderEndTag(); if (romSecondary != null) { html.AddAttribute(HtmlTextWriterAttribute.Class, "header-desc-sim"); html.RenderBeginTag(HtmlTextWriterTag.Th); { html.Write("Secondary ({0}; Sim)", romSecondary.Language); } html.RenderEndTag(); } } html.RenderEndTag(); int numMessages = 0; if (langBanks[1] != null) { numMessages = (langBanks[0].Messages.Count == langBanks[1].Messages.Count ? langBanks[0].Messages.Count : Math.Max(langBanks[0].Messages.Count, langBanks[1].Messages.Count)); } else { numMessages = langBanks[0].Messages.Count; } for (int j = 0; j < numMessages; j++) { html.RenderBeginTag(HtmlTextWriterTag.Tr); { html.AddAttribute(HtmlTextWriterAttribute.Class, "message-id"); html.RenderBeginTag(HtmlTextWriterTag.Th); { html.Write("#{0}", j + 1); } html.RenderEndTag(); string jpnMessage = (j < langBanks[0].Messages.Count ? langBanks[0].Messages[j].Text : string.Empty); for (int k = 0; k < langBanks.Length; k++) { if (langBanks[k] == null) { continue; } string message = (j < langBanks[k].Messages.Count ? langBanks[k].Messages[j].Text : string.Empty); if (k != 0 && jpnMessage.Equals(message) || message.StartsWith("エラー" + Environment.NewLine)) { html.AddAttribute(HtmlTextWriterAttribute.Class, "message-desc-suspicious"); } else { html.AddAttribute(HtmlTextWriterAttribute.Class, "message-desc-text"); } html.RenderBeginTag(HtmlTextWriterTag.Td); { message = message.Replace(" ", " "); message = message.Replace("<", "<"); message = message.Replace(">", ">"); message = message.Replace(Environment.NewLine, "<br />"); message = message.Replace("[Highlight:On]", "<span style=\"color:#ff0000;\">"); message = message.Replace("[Highlight:Off]", "</span>"); int numSpanStart = CountSubstrings(message, "<span "); int numSpanEnd = CountSubstrings(message, "</span>"); if (numSpanStart > numSpanEnd) { message += "</span>"; } else if (numSpanEnd > numSpanStart) { message = "<span>" + message; } html.Write(message); } html.RenderEndTag(); } for (int k = 0; k < langBanks.Length; k++) { if (langBanks[k] == null) { continue; } Message message = langBanks[k].Messages[j]; html.AddAttribute(HtmlTextWriterAttribute.Class, "message-desc-sim"); html.RenderBeginTag(HtmlTextWriterTag.Td); { string imgFile = string.Format("img\\{0}-{1}-{2}.png", i, j, k); string imgPath = Path.Combine(Path.GetDirectoryName(filename), imgFile); if (!Directory.Exists(Path.GetDirectoryName(imgPath))) { Directory.CreateDirectory(Path.GetDirectoryName(imgPath)); } Bitmap image = (k == 0 ? romPrimary.GetMessageImage(message) : romSecondary.GetMessageImage(message)); if (image == null) { continue; } image.Save(imgPath); html.AddAttribute(HtmlTextWriterAttribute.Src, imgFile.Replace('\\', '/')); html.AddAttribute(HtmlTextWriterAttribute.Alt, Path.GetFileNameWithoutExtension(imgFile)); html.RenderBeginTag(HtmlTextWriterTag.Img); html.RenderEndTag(); html.WriteBreak(); } html.RenderEndTag(); } } html.RenderEndTag(); } } html.RenderEndTag(); html.WriteBreak(); } } html.RenderEndTag(); } html.RenderEndTag(); } writer.Close(); }
public void Initialize(RomHandler rom) { this.rom = rom; }
private void openROMsToolStripMenuItem_Click(object sender, EventArgs e) { if (Properties.Settings.Default.File1 != string.Empty) { ofdRomFirst.InitialDirectory = Path.GetDirectoryName(Properties.Settings.Default.File1); ofdRomFirst.FileName = Path.GetFileName(Properties.Settings.Default.File1); } if (Properties.Settings.Default.File2 != string.Empty) { ofdRomSecond.InitialDirectory = Path.GetDirectoryName(Properties.Settings.Default.File2); ofdRomSecond.FileName = Path.GetFileName(Properties.Settings.Default.File2); } int romsLoaded = 0; if (ofdRomFirst.ShowDialog() == DialogResult.OK) { RomHandler loadedRom = new RomHandler(ofdRomFirst.FileName); Properties.Settings.Default.File1 = ofdRomFirst.FileName; if (loadedRom.Language == GameLanguage.Japanese) { primaryRom = loadedRom; } else if (loadedRom.Language == GameLanguage.English) { secondaryRom = loadedRom; } romsLoaded++; } if (ofdRomSecond.ShowDialog() == DialogResult.OK) { RomHandler loadedRom = new RomHandler(ofdRomSecond.FileName); Properties.Settings.Default.File2 = ofdRomSecond.FileName; if (primaryRom == null) { primaryRom = loadedRom; } else if (secondaryRom == null) { secondaryRom = loadedRom; } romsLoaded++; } if (romsLoaded == 0) { Text = Application.ProductName; } else if (romsLoaded == 1) { Text = string.Format("{0} - [{1}]", Application.ProductName, Path.GetFileName(ofdRomFirst.FileName)); } else if (romsLoaded == 2) { Text = string.Format("{0} - [{1}, {2}]", Application.ProductName, Path.GetFileName(ofdRomFirst.FileName), Path.GetFileName(ofdRomSecond.FileName)); } else { throw new Exception("The f**k did you do!?!"); } previewControlPrimary.Enabled = (primaryRom != null); previewControlSecondary.Enabled = (secondaryRom != null); createComparisonToolStripMenuItem.Enabled = true; InitializeViewer(); }