private void ShowContent(string charset) { foreach (ListViewItem item in lstResults.SelectedItems) { string fileName = item.SubItems[ResultsColumnFileName].Text; string directory = item.SubItems[ResultsColumnDirectory].Text; string filePath = Path.Combine(directory, fileName); string content = null; using (StreamReader reader = charset == null ? new StreamReader(filePath, true) : new StreamReader(filePath, Encoding.GetEncoding(charset))) content = reader.ReadToEnd(); string targetCharset = (string)lstConvert.SelectedItem; var f = new PreviewForm(content, charset, targetCharset, GetTranslateOption(), filePath); f.Show(); } }
private void toolStripMenuItemPreview_Click(object sender, EventArgs e) { foreach (ListViewItem item in lstResults.SelectedItems) { string charset = item.SubItems[ResultsColumnCharset].Text; if (charset == "(Unknown)") { charset = null; } if (_encodingNameMap.ContainsKey(charset)) { charset = _encodingNameMap[charset]; } string fileName = item.SubItems[ResultsColumnFileName].Text; string directory = item.SubItems[ResultsColumnDirectory].Text; string filePath = Path.Combine(directory, fileName); FileAttributes attributes = File.GetAttributes(filePath); if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { attributes = attributes ^ FileAttributes.ReadOnly; File.SetAttributes(filePath, attributes); } string content = null; using (StreamReader reader = charset == null ? new StreamReader(filePath, true) : new StreamReader(filePath, Encoding.GetEncoding(charset))) content = reader.ReadToEnd(); string targetCharset = (string)lstConvert.SelectedItem; var f = new PreviewForm(content, charset, targetCharset, GetTranslateOption(), filePath); f.Show(); } }