?? formmain.cs
字號:
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new FormMain());
}
string Gb2312_To_UniCode(string strGb2312)
{
System.Text.Encoding E_Gb2312 = System.Text.Encoding.GetEncoding("gb2312");
System.Text.Encoding E_Utf8 = System.Text.Encoding.UTF8;
return E_Utf8.GetString(System.Text.Encoding.Convert(E_Gb2312,E_Utf8,E_Gb2312.GetBytes(strGb2312)));
}
string UniCode_To_Gb2312(string strUnicode)
{
System.Text.Encoding E_Gb2312 = System.Text.Encoding.GetEncoding("gb2312");
System.Text.Encoding E_Utf8 = System.Text.Encoding.UTF8;
return E_Gb2312.GetString(System.Text.Encoding.Convert(E_Utf8,E_Gb2312,E_Utf8.GetBytes(strUnicode)));
}
string Gb2312_To_Big5(string strGb2312)
{
System.Text.Encoding E_Gb2312 = System.Text.Encoding.GetEncoding("gb2312");
System.Text.Encoding E_Big5 = System.Text.Encoding.GetEncoding("big5");
return E_Big5.GetString(System.Text.Encoding.Convert(E_Gb2312,E_Big5,E_Gb2312.GetBytes(strGb2312)));
}
string Big5_To_Gb2312(string strUnicode)
{
System.Text.Encoding E_Gb2312 = System.Text.Encoding.GetEncoding("gb2312");
System.Text.Encoding E_Big5 = System.Text.Encoding.GetEncoding("big5");
return E_Gb2312.GetString(System.Text.Encoding.Convert(E_Big5,E_Gb2312,E_Big5.GetBytes(strUnicode)));
}
private void Re_Insert_To_Item()
{
try
{
string[] files = System.IO.Directory.GetFiles(this.tBFilePath.Text);
if(this.cLB_FilesList.Items.Count > 0)
{
this.cLB_FilesList.Items.Clear();
}
foreach (string file in files)
{
this.cLB_FilesList.Items.Add(System.IO.Path.GetFileName(file));
}
}
catch(Exception e)
{
}
/*
for(int int1 = 0; int1 < files.Length; int1 ++)
{
this.cLB_FilesList.Items.Add(files[int1]);
}
*/
}
private void button1_Click(object sender, System.EventArgs e)
{
if(pathBrowser.ShowDialog() == DialogResult.OK)
{
this.tBFilePath.Text = pathBrowser.SelectedPath;
Re_Insert_To_Item();
}
}
private void tBFilePath_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
switch(e.KeyValue)
{
case 13:
Re_Insert_To_Item();
break;
deafult:
break;
}
}
private void cbSelectAll_CheckedChanged(object sender, System.EventArgs e)
{
for(int int1 = 0; int1 < this.cLB_FilesList.Items.Count; int1++)
{
this.cLB_FilesList.SetItemChecked(int1, this.cbSelectAll.Checked);
}
}
private void btGBtoUTF8_Click(object sender, System.EventArgs e)
{
this.pBTranStatus.Maximum = this.cLB_FilesList.CheckedItems.Count;
this.pBTranStatus.Step = 1;
string lineRead, lineWrite, sFN_Target;
foreach (string file in this.cLB_FilesList.CheckedItems)
{
this.lbCurFile.Text = file;
if(System.IO.Directory.Exists(this.tbTargetPath.Text) && (this.tbTargetPath.Text != this.tBFilePath.Text ))
{
sFN_Target = this.tbTargetPath.Text + "\\" + file;
}
else
{
sFN_Target = this.tBFilePath.Text + "\\" + file + ".UTF8";
}
System.IO.StreamReader trSource = new System.IO.StreamReader(this.tBFilePath.Text + "\\" + file, System.Text.Encoding.GetEncoding("gb2312"));
System.IO.StreamWriter trTarget = new System.IO.StreamWriter(sFN_Target, false, System.Text.Encoding.UTF8);
/*
char[] buffer = new char[512];
int len;
while(trSource.Peek() >=0)
{
len = trSource.Read(buffer,0,512);
trTarget.Write(buffer,0,len);
}
*/
while((lineRead = trSource.ReadLine()) != null)
{
lineWrite = this.Gb2312_To_UniCode(lineRead);
if(this.cbReplaceCodePage.Checked)
{
if(lineWrite.IndexOf("charset=gb2312") > 0) lineWrite = (lineWrite.ToLower()).Replace("charset=gb2312", "charset=utf-8");
lineWrite = (lineWrite.ToLower()).Replace("CodePage=936", "codepage=65001");
lineWrite = (lineWrite.ToLower()).Replace("CODEPAGE=\"936\"", "codepage=\"65001\"");
}
trTarget.WriteLine(lineWrite);
}
trTarget.Close();
trSource.Close();
this.pBTranStatus.PerformStep();
}
}
private void btUTF8toGB_Click(object sender, System.EventArgs e)
{
this.pBTranStatus.Maximum = this.cLB_FilesList.CheckedItems.Count;
this.pBTranStatus.Step = 1;
string lineRead, lineWrite, sFN_Target;
foreach (string file in this.cLB_FilesList.CheckedItems)
{
this.lbCurFile.Text = file;
if(System.IO.Directory.Exists(this.tbTargetPath.Text) && (this.tbTargetPath.Text != this.tBFilePath.Text ))
{
sFN_Target = this.tbTargetPath.Text + "\\" + file;
}
else
{
sFN_Target = this.tBFilePath.Text + "\\" + file + ".gb";
}
System.IO.StreamReader trSource = new System.IO.StreamReader(this.tBFilePath.Text + "\\" + file, System.Text.Encoding.UTF8);
System.IO.StreamWriter trTarget = new System.IO.StreamWriter(sFN_Target, false, System.Text.Encoding.GetEncoding("gb2312"));
/*
char[] buffer = new char[512];
int len;
while(trSource.Peek() >=0)
{
len = trSource.Read(buffer,0,512);
trTarget.Write(buffer,0,len);
}
*/
while((lineRead = trSource.ReadLine()) != null)
{
lineWrite = this.UniCode_To_Gb2312(lineRead);
if(this.cbReplaceCodePage.Checked)
{
if(lineWrite.ToLower().IndexOf("charset=utf-8") > 0) lineWrite = (lineWrite.ToLower()).Replace("charset=utf-8","charset=gb2312");
if(lineWrite.ToLower().IndexOf("codepage=65001") > 0) lineWrite = (lineWrite.ToLower()).Replace("codepage=65001","CodePage=936");
if(lineWrite.ToLower().IndexOf("codepage=\"65001\"") > 0) lineWrite = (lineWrite.ToLower()).Replace("codepage=\"65001\"","CODEPAGE=\"936\"");
}
trTarget.WriteLine(lineWrite);
}
trTarget.Close();
trSource.Close();
this.pBTranStatus.PerformStep();
}
}
private void btTargetPate_Click(object sender, System.EventArgs e)
{
if(fbdTargetPath.ShowDialog() == DialogResult.OK)
{
this.tbTargetPath.Text = fbdTargetPath.SelectedPath;
}
}
private void btBig5ToGb2312_Click(object sender, System.EventArgs e)
{
this.pBTranStatus.Maximum = this.cLB_FilesList.CheckedItems.Count;
this.pBTranStatus.Step = 1;
string lineRead, lineWrite, sFN_Target;
foreach (string file in this.cLB_FilesList.CheckedItems)
{
this.lbCurFile.Text = file;
if(System.IO.Directory.Exists(this.tbTargetPath.Text) && (this.tbTargetPath.Text != this.tBFilePath.Text ))
{
sFN_Target = this.tbTargetPath.Text + "\\" + file;
}
else
{
sFN_Target = this.tBFilePath.Text + "\\" + file + ".gb";
}
System.IO.StreamReader trSource = new System.IO.StreamReader(this.tBFilePath.Text + "\\" + file, System.Text.Encoding.GetEncoding("big5"));
System.IO.StreamWriter trTarget = new System.IO.StreamWriter(sFN_Target, false, System.Text.Encoding.GetEncoding("gb2312"));
while((lineRead = trSource.ReadLine()) != null)
{
lineWrite = this.Big5_To_Gb2312(lineRead);
if(this.cbReplaceCodePage.Checked)
{
if(lineWrite.ToLower().IndexOf("charset=big5") > 0) lineWrite = (lineWrite.ToLower()).Replace("charset=big5","charset=gb2312");
// if(lineWrite.ToLower().IndexOf("codepage=65001") > 0) lineWrite = (lineWrite.ToLower()).Replace("codepage=65001","CodePage=936");
// if(lineWrite.ToLower().IndexOf("codepage=\"65001\"") > 0) lineWrite = (lineWrite.ToLower()).Replace("codepage=\"65001\"","CODEPAGE=\"936\"");
}
trTarget.WriteLine(lineWrite);
}
trTarget.Close();
trSource.Close();
this.pBTranStatus.PerformStep();
}
}
private void btGb2312ToBig5_Click(object sender, System.EventArgs e)
{
this.pBTranStatus.Maximum = this.cLB_FilesList.CheckedItems.Count;
this.pBTranStatus.Step = 1;
string lineRead, lineWrite, sFN_Target;
foreach (string file in this.cLB_FilesList.CheckedItems)
{
this.lbCurFile.Text = file;
if(System.IO.Directory.Exists(this.tbTargetPath.Text) && (this.tbTargetPath.Text != this.tBFilePath.Text ))
{
sFN_Target = this.tbTargetPath.Text + "\\" + file;
}
else
{
sFN_Target = this.tBFilePath.Text + "\\" + file + ".big5";
}
System.IO.StreamReader trSource = new System.IO.StreamReader(this.tBFilePath.Text + "\\" + file, System.Text.Encoding.GetEncoding("gb2312"));
System.IO.StreamWriter trTarget = new System.IO.StreamWriter(sFN_Target, false, System.Text.Encoding.GetEncoding("big5"));
while((lineRead = trSource.ReadLine()) != null)
{
lineWrite = this.Gb2312_To_Big5(lineRead);
if(this.cbReplaceCodePage.Checked)
{
if(lineWrite.ToLower().IndexOf("charset=gb2312") > 0) lineWrite = (lineWrite.ToLower()).Replace("charset=gb2312","charset=big5");
}
trTarget.WriteLine(lineWrite);
}
trTarget.Close();
trSource.Close();
this.pBTranStatus.PerformStep();
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -