public static void Export(CResourceManager resman, string filename) { FileStream fs = new FileStream(filename, FileMode.Create); StreamWriter writer = new StreamWriter(fs, Encoding.GetEncoding("SHIFT-JIS")); foreach (KeyValuePair <UInt32, PackageText> kv in resman.dialogue) { if (kv.Value.sourceLen <= 2) { continue; } fs.Write(kv.Value.source, 0, ((int)kv.Value.sourceLen - 1)); fs.Flush(); writer.Write("\r\nE"); writer.Write(kv.Value.translation.Replace("\r\n", "\n").Replace("\n", "\r\nE")); writer.Write("\r\n"); writer.Flush(); fs.Flush(); } fs.Close(); }
public static int Import(CResourceManager resman, string filename, bool appendSoh = false) { FileStream fs = new FileStream(filename, FileMode.Open); StreamReader reader = new StreamReader(fs, Encoding.GetEncoding("SHIFT-JIS")); bool english = false; StringBuilder engText = new StringBuilder(); StringBuilder jpnText = new StringBuilder(); int replaced = 0; while (!reader.EndOfStream) { string line = reader.ReadLine(); if (line.Length > 0 && line[0] == 'E') { if (jpnText.Length == 0) { continue; } english = true; engText.AppendLine(line.Substring(1)); } else { if (english) { jpnText.Replace("\r\n", "\n"); jpnText.Remove(jpnText.Length - 1, 1); jpnText.Append('\x00'); byte[] source = Encoding.GetEncoding("SHIFT-JIS").GetBytes(jpnText.ToString()); try { var value = resman.dialogue.First(k => TxtExport.ByteArrayCompare(source, k.Value.source)); value.Value.translation = engText.ToString(); if (value.Value.translation.Length >= 2) { string text = value.Value.translation.Substring(0, value.Value.translation.Length - 2); if (appendSoh && text.Length > 0 && !text.EndsWith("{dc3}") && !text.EndsWith("{soh}") && !text.EndsWith("{dc3}\r\n") && !text.EndsWith("{soh}\r\n")) { text = text + "{soh}"; } value.Value.translation = text; } replaced++; } catch (InvalidOperationException) { } engText = new StringBuilder(); jpnText = new StringBuilder(); english = false; } jpnText.AppendLine(line); } } fs.Close(); return(replaced); }
private void openClick(object sender, EventArgs e) { DialogResult res = openFileDialog1.ShowDialog(); if (res == DialogResult.OK) { if (isOpened) { selectedDialogue = 0; selectedUi = 0; selectedImage = null; resman.dialogue.Clear(); resman.ui.Clear(); resman.images.Clear(); listView1.Items.Clear(); listView3.Items.Clear(); textBox1.Clear(); textBox2.Clear(); textBox5.Clear(); textBox6.Clear(); textBoxTitle.Clear(); comboBox1.Items.Clear(); textBox1.ReadOnly = true; textBox2.ReadOnly = true; textBox5.ReadOnly = true; textBox6.ReadOnly = true; textBoxTitle.ReadOnly = true; comboBox1.Enabled = false; button1.Enabled = false; button2.Enabled = false; if (pictureBox2.Image != null) { pictureBox2.Image.Dispose(); } if (pictureBox1.Image != null) { pictureBox1.Image.Dispose(); } pictureBox1.Image = null; pictureBox2.Image = null; } statusLabel.Text = "Loading package ..."; resman = new CResourceManager(openFileDialog1.FileName); listView1.BeginUpdate(); listView1.ListViewItemSorter = null; // THIS THING MADE EVERYTHING SO F*****G SLOW foreach (KeyValuePair <UInt32, PackageText> kv in resman.dialogue) { ListViewItem item = new ListViewItem(kv.Key.ToString()); item.SubItems.Add(kv.Value.sourceString); item.SubItems.Add(kv.Value.translation); item.SubItems.Add(kv.Value.translation.Length >= 1 ? "Yes" : "No"); item.Tag = kv.Key; listView1.Items.Add(item); } listView1.EndUpdate(); listView1.ListViewItemSorter = lvwColumnSorter; listView3.BeginUpdate(); listView3.ListViewItemSorter = null; // THIS THING MADE EVERYTHING SO F*****G SLOW foreach (KeyValuePair <UInt32, PackageText> kv in resman.ui) { ListViewItem item = new ListViewItem(kv.Key.ToString()); item.SubItems.Add(kv.Value.sourceString); item.SubItems.Add(kv.Value.translation); item.SubItems.Add(kv.Value.translation.Length >= 1 ? "Yes" : "No"); item.Tag = kv.Key; listView3.Items.Add(item); } listView3.EndUpdate(); listView3.ListViewItemSorter = lvwColumnSorter; comboBox1.BeginUpdate(); foreach (KeyValuePair <string, PackageImage> kv in resman.images) { comboBox1.Items.Add(kv.Value); } comboBox1.EndUpdate(); statusLabel.Text = "Loading done"; isOpened = true; comboBox1.Enabled = true; openedFile = openFileDialog1.FileName; pkgLocation = Path.GetDirectoryName(openedFile); } }