12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- using System.Diagnostics;
- namespace FileCharsetConvert;
- public partial class MainForm : Form
- {
- public MainForm()
- {
- InitializeComponent();
- cmbInEnc.DataSource = Encoding.GetEncodings();
- cmbOutEnc.DataSource = Encoding.GetEncodings();
- }
- private void btnSelectFolder_Click(object sender, EventArgs e)
- {
- if (dlgFolder.ShowDialog() == DialogResult.OK)
- txtFolder.Text = dlgFolder.SelectedPath;
- }
- private void btnScan_Click(object sender, EventArgs e)
- {
- List<string> ScanResult = new List<string>();
- foreach (var item in txtFlt.Text.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
- {
- ScanResult.AddRange(Directory.GetFiles(txtFolder.Text, item,
- chkSubDir.Checked ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly));
- }
- var FileList = ScanResult.Distinct().ToList();
- lvMain.Items.Clear();
- foreach (var item in FileList)
- {
- var lvi = new ListViewItem();
- lvi.Text = item;
- lvi.SubItems.Add("未转换");
- lvMain.Items.Add(lvi);
- }
- }
- private void btnApplySelection_Click(object sender, EventArgs e)
- {
- foreach (ListViewItem item in lvMain.SelectedItems)
- {
- File.WriteAllText(item.Text,
- File.ReadAllText(item.Text, ((EncodingInfo)cmbInEnc.SelectedItem).GetEncoding()),
- ((EncodingInfo)cmbOutEnc.SelectedItem).GetEncoding());
- item.SubItems[1].Text = "已转换";
- }
- }
- private void lvMain_MouseDoubleClick(object sender, MouseEventArgs e)
- {
- if (lvMain.SelectedItems.Count != 0)
- {
- string filename = Path.GetTempFileName() + "-" + Path.GetFileName(lvMain.SelectedItems[0].Text) + ".txt";
- File.WriteAllText(filename,
- File.ReadAllText(lvMain.SelectedItems[0].Text, ((EncodingInfo)cmbInEnc.SelectedItem).GetEncoding()),
- ((EncodingInfo)cmbOutEnc.SelectedItem).GetEncoding());
- Process.Start(new ProcessStartInfo() { FileName = filename, UseShellExecute = true });
- }
- }
- }
|