private void TextBox_TextChanged(object sender, TextChangedEventArgs e) { System.Windows.Controls.TextBox tbox = (System.Windows.Controls.TextBox)sender; ContentPresenter cp = (ContentPresenter)tbox.TemplatedParent; LNGRow lrow = (LNGRow)cp.Content; lrow.TransText = tbox.Text; }
private void CopyContextButtonClick(object sender, RoutedEventArgs e) { LNGRow lrow = (LNGRow)stringsView.SelectedItem; if (lrow == null) { return; } System.Windows.Clipboard.SetText(lrow.OrigText); }
private void TranslateContextButtonClick2(object sender, RoutedEventArgs e) { LNGRow lrow = (LNGRow)stringsView.SelectedItem; if (lrow == null) { return; } byte[] trans = Encoding.UTF8.GetBytes(this.GoogleTranslate2(lrow.OrigText)); lrow.TransText = Encoding.GetEncoding(this.curEnc).GetString(Encoding.Convert(Encoding.UTF8, Encoding.GetEncoding(this.curEnc), trans)); stringsView.Items.Refresh(); AutoSizeColumns(stringsView.View as GridView); }
private void ReadFile() { MainWindowElement.Title = this.windowTitle + " - " + this.FileName; MainWindowElement.Title += " [" + Encoding.GetEncoding(this.curEnc).WebName + "]"; byte[] knownSignature = new byte[] { 0xA5, 0x5A, 0x5A, 0xA5, 0x01, 0x00, 0x00, 0x01 }; this.addrLength = 4; using (FileStream fs = new FileStream(this.FileName, FileMode.Open, FileAccess.Read)) { byte[] signature = new byte[8]; fs.Read(signature, 0, signature.Length); if (!signature.SequenceEqual(knownSignature)) { System.Windows.MessageBox.Show("Unknown signature!"); return; } int bytesPerSymbol = Encoding.GetEncoding(this.curEnc).GetByteCount(new char[] { 'A' }); byte[] lastStringOffset = new byte[4]; fs.Position = 0x20; fs.Read(lastStringOffset, 0, lastStringOffset.Length); fs.Position = 0x40; byte[] addr = new byte[4] { 0xff, 0xff, 0x00, 0x00 }; byte[] endaddr = new byte[4] { 0x00, 0x00, 0x00, 0x00 }; byte[] bChar = new byte[bytesPerSymbol]; byte[] bEndChar = new byte[bytesPerSymbol]; List <byte> bText = new List <byte>(); lngRows.Clear(); int addr_id = 1; fs.Read(addr, 0, this.addrLength); // may be 4 bytes offset if (addr[2] != 0 || addr[3] != 0) { this.addrLength = 2; addr[2] = 0; addr[3] = 0; fs.Position -= 2; } while (!addr.SequenceEqual(endaddr)) { bText.Clear(); long nextAddr = fs.Position; fs.Position = 0x40 + BitConverter.ToUInt32(addr, 0) * 2; if (BitConverter.GetBytes(fs.Position).SequenceEqual(lastStringOffset)) { break; } fs.Read(bChar, 0, bChar.Length); while (fs.Position < fs.Length - 1) { if (bChar.SequenceEqual(bEndChar)) { break; } foreach (byte mchar in bChar) { bText.Add(mchar); } fs.Read(bChar, 0, bChar.Length); } LNGRow lrow = new LNGRow( addr_id, addr, Encoding.GetEncoding(this.curEnc).GetString(bText.ToArray()), this.curEnc); lngRows.Add(lrow); addr_id++; fs.Position = nextAddr; fs.Read(addr, 0, this.addrLength); if (fs.Position >= fs.Length - 1) { addr = endaddr; } } ((GridView)stringsView.View).Columns[1].Header = "Original: (found " + lngRows.Count + " strings)"; stringsView.ItemsSource = lngRows.Where(row => row.OrigText != ""); stringsView.Items.Refresh(); AutoSizeColumns(stringsView.View as GridView); } }