private void exporttxtToolStripMenuItem_Click(object sender, EventArgs e) { if (!isOpened) { return; } DialogResult res = saveFileDialog2.ShowDialog(); if (res == DialogResult.OK) { TxtExport.Export(resman, saveFileDialog2.FileName); } }
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 importtxtToolStripMenuItem_Click(object sender, EventArgs e) { if (!isOpened) { return; } DialogResult res = openFileDialog2.ShowDialog(); if (res == DialogResult.OK) { selectedDialogue = 0; selectedUi = 0; listView1.Items.Clear(); listView3.Items.Clear(); textBox1.Clear(); textBox2.Clear(); textBox5.Clear(); textBox6.Clear(); textBox1.ReadOnly = true; textBox2.ReadOnly = true; textBox5.ReadOnly = true; textBox6.ReadOnly = true; int result = TxtExport.Import(resman, openFileDialog2.FileName, addsohAutomaticallyToolStripMenuItem.Checked); 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; MessageBox.Show("Updated " + result + " records"); } }