From a3bdbdc175c0e431cc6aee45779d74ba63159b8b Mon Sep 17 00:00:00 2001 From: fireattack Date: Tue, 12 Jul 2016 22:54:07 -0500 Subject: [PATCH] Fix #1 and others --- FixCue/FixCue.csproj | 4 + FixCue/Form1.cs | 306 ++++++++++++++++++++++--------------------- FixCue/app.manifest | 76 +++++++++++ 3 files changed, 238 insertions(+), 148 deletions(-) create mode 100644 FixCue/app.manifest diff --git a/FixCue/FixCue.csproj b/FixCue/FixCue.csproj index 7494598..fda2ef3 100644 --- a/FixCue/FixCue.csproj +++ b/FixCue/FixCue.csproj @@ -60,6 +60,9 @@ AllRules.ruleset + + app.manifest + @@ -93,6 +96,7 @@ True + diff --git a/FixCue/Form1.cs b/FixCue/Form1.cs index eda7fa7..39d96af 100644 --- a/FixCue/Form1.cs +++ b/FixCue/Form1.cs @@ -1,4 +1,4 @@ -using System; +锘縰sing System; using System.Drawing; using System.IO; using System.Runtime.InteropServices; @@ -18,18 +18,19 @@ public partial class Form1 : Form { Regex re = new Regex(@"(.+)\\(?.+)\.(.+)"); - Regex fileline = new Regex(@"FILE ""(.+)\.([^.]+?)""", RegexOptions.IgnoreCase); - string original_path = ""; //原始文件名 - string readText = ""; //内容 - // int code = 0; //编码 - string FileInFileLine; + Regex fileLine = new Regex(@"FILE ""(.+)\.([^.]+?)""", RegexOptions.IgnoreCase); + string originalPath = ""; //鍘熷鏂囦欢鍚 + + string readText = ""; //鍐呭 + // int code = 0; //缂栫爜 + string fileInFileLine; INIClass config = new INIClass(Application.StartupPath+@"\config.ini"); List musicfiles = new List(); char[] JISMapBuffer = File.ReadAllText(Application.StartupPath + @"\maps\jis.map", Encoding.Unicode).ToCharArray(); char[] GBMapBuffer = File.ReadAllText(Application.StartupPath + @"\maps\gb.map", Encoding.Unicode).ToCharArray(); char[] Big5MapBuffer = File.ReadAllText(Application.StartupPath + @"\maps\big5.map", Encoding.Unicode).ToCharArray(); bool loaded = false; - bool forcecode = false; + bool forceCode = false; //bool started = false; public Form1() @@ -39,16 +40,16 @@ public Form1() private string OpenFile(string original_path) { - if (forcecode) + if (forceCode) { if (comboBox1.Text == "950") ReadBIG5(); else readText = File.ReadAllText(original_path, Encoding.GetEncoding(int.Parse(comboBox1.Text))); - forcecode = false; + forceCode = false; } else { - switch (getcodetype(original_path)) + switch (getCodeType(original_path)) { case "CODETYPE_UTF8NOBOM": { @@ -84,7 +85,7 @@ private string OpenFile(string original_path) } } } - string FileInFileLine = fileline.Match(readText).Groups[1].Value.ToLower(); + string FileInFileLine = fileLine.Match(readText).Groups[1].Value.ToLower(); return FileInFileLine; } @@ -93,16 +94,16 @@ private void ReadBIG5() readText = ""; // readText = File.ReadAllText(original_path, Encoding.GetEncoding(950)); //char[] Big5MapBuffer = File.ReadAllText(Application.StartupPath + @"\maps\big5.map", Encoding.Unicode).ToCharArray(); - Byte[] MyByte = File.ReadAllBytes(original_path); + Byte[] MyByte = File.ReadAllBytes(originalPath); int high, low, chr, i; // var OutPutByte = new List(); for (i = 0; i < MyByte.Length; ) { - high = MyByte[i]; //读取第一个byte + high = MyByte[i]; //璇诲彇绗竴涓猙yte i++; - if (high > 0x7F) //第一个byte是高位 + if (high > 0x7F) //绗竴涓猙yte鏄珮浣 { - low = MyByte[i]; //读取低位 + low = MyByte[i]; //璇诲彇浣庝綅 i++; } else @@ -111,7 +112,7 @@ private void ReadBIG5() high = 0; } chr = low + high * 256; - if (chr < 0x80) // ASCII码 + if (chr < 0x80) // ASCII鐮 { var encoding = new UnicodeEncoding(); readText += encoding.GetString(new byte[] { (byte)chr, 0 }); @@ -126,7 +127,7 @@ private void ReadBIG5() private void ChangeOutputFilePath() { - FilePathTextBox.Text = re.Replace(original_path, @"$1\" + RenameTextBox.Text.Replace(@"%filename%", @"${filename}") + @".$2"); + FilePathTextBox.Text = re.Replace(originalPath, @"$1\" + RenameTextBox.Text.Replace(@"%filename%", @"${filename}") + @".$2"); } private bool IsUserAdministrator() @@ -149,7 +150,7 @@ private bool IsUserAdministrator() return isAdmin; } - private void main_func() // 主要转码部分 + private void main_func() // 涓昏杞爜閮ㄥ垎 { loaded = true; if (!AutoOutputCheckBox.Checked) @@ -158,15 +159,15 @@ private bool IsUserAdministrator() if (!CoverOldFileCheckBox.Checked) ChangeOutputFilePath(); else - FilePathTextBox.Text = original_path; + FilePathTextBox.Text = originalPath; - FileInFileLine = OpenFile(original_path); + fileInFileLine = OpenFile(originalPath); string[] exts = { "ape", "tta", "flac", "tak", "wav", "m4a","wv" }; musicfiles.Clear(); - if (Path.GetExtension(original_path).ToLower() == ".cue") + if (Path.GetExtension(originalPath).ToLower() == ".cue") { - // 自动修正「The True Audio」→「WAVE」以便于fb2k识别 + // 鑷姩淇銆孴he True Audio銆嶁啋銆學AVE銆嶄互渚夸簬fb2k璇嗗埆 if (ttafixCheckBox.Checked) { readText = Regex.Replace(readText, "the true audio", "WAVE", RegexOptions.IgnoreCase); @@ -174,22 +175,22 @@ private bool IsUserAdministrator() foreach (string ext in exts) { - musicfiles.AddRange(Directory.GetFiles(Path.GetDirectoryName(original_path), "*." + ext)); + musicfiles.AddRange(Directory.GetFiles(Path.GetDirectoryName(originalPath), "*." + ext)); } bool MultiMusicFileType = false; - // 自动替换FILE字段文件名 + // 鑷姩鏇挎崲FILE瀛楁鏂囦欢鍚 if (fileLineCheckBox.Checked) { - if (musicfiles.Count == 0) //如果没有搜到音乐类型文件,不作任何事情 + if (musicfiles.Count == 0) //濡傛灉娌℃湁鎼滃埌闊充箰绫诲瀷鏂囦欢锛屼笉浣滀换浣曚簨鎯 { } - else if (musicfiles.Count == 1) //如果只搜到一个,那么将FILE行的被引用文件替换 + else if (musicfiles.Count == 1) //濡傛灉鍙悳鍒颁竴涓紝閭d箞灏咶ILE琛岀殑琚紩鐢ㄦ枃浠舵浛鎹 { string MyFile = Path.GetFileName(musicfiles[0]); - readText = fileline.Replace(readText, @"FILE """ + MyFile + @""""); + readText = fileLine.Replace(readText, @"FILE """ + MyFile + @""""); } - else //如果搜到多个,那逐个尝试是否与FileInFileLine匹配 + else //濡傛灉鎼滃埌澶氫釜锛岄偅閫愪釜灏濊瘯鏄惁涓嶧ileInFileLine鍖归厤 { string MyExt = Path.GetExtension(musicfiles[0]); for (int i = 1; i < musicfiles.Count; i++) @@ -202,56 +203,56 @@ private bool IsUserAdministrator() } foreach (string MyFilePath in musicfiles) { - if (FileInFileLine == Path.GetFileNameWithoutExtension(MyFilePath).ToLower()) + if (fileInFileLine == Path.GetFileNameWithoutExtension(MyFilePath).ToLower()) { string MyFile = Path.GetFileName(MyFilePath); - readText = fileline.Replace(readText, @"FILE """ + MyFile + @""""); + readText = fileLine.Replace(readText, @"FILE """ + MyFile + @""""); break; } - if (Path.GetFileNameWithoutExtension(original_path).ToLower() == Path.GetFileNameWithoutExtension(MyFilePath).ToLower()) + if (Path.GetFileNameWithoutExtension(originalPath).ToLower() == Path.GetFileNameWithoutExtension(MyFilePath).ToLower()) { string MyFile = Path.GetFileName(MyFilePath); - readText = fileline.Replace(readText, @"FILE """ + MyFile + @""""); + readText = fileLine.Replace(readText, @"FILE """ + MyFile + @""""); break; } } - if (!MultiMusicFileType) //如果都没有匹配的但是却有只有一种音乐类型,那么好歹替换了罢(咦? - readText = fileline.Replace(readText, @"FILE ""$1" + MyExt + @""""); + if (!MultiMusicFileType) //濡傛灉閮芥病鏈夊尮閰嶇殑浣嗘槸鍗存湁鍙湁涓绉嶉煶涔愮被鍨嬶紝閭d箞濂芥鏇挎崲浜嗙舰锛堝挦锛 + readText = fileLine.Replace(readText, @"FILE ""$1" + MyExt + @""""); } } } FileContentTextBox.Text = readText; - // 自动模式 + // 鑷姩妯″紡 if (AutoOutputCheckBox.Checked) output(); } - private string getcodetype(string path) + private string getCodeType(string path) { string strCodeType = "CODETYPE_UTF8NOBOM"; - Byte[] MyByte = File.ReadAllBytes(path); + Byte[] myByte = File.ReadAllBytes(path); int high, low, chr, i; int JP1 = 0, JP2 = 0; - bool FakeJP = false; + bool fakeJP = false; i = 0; bool isUTF8 = true; - while (i < MyByte.Length) + while (i < myByte.Length) { - if ((0x80 & MyByte[i]) == 0) // ASCII + if ((0x80 & myByte[i]) == 0) // ASCII { i++; continue; } - else if ((0xE0 & MyByte[i]) == 0xC0) // 110xxxxx + else if ((0xE0 & myByte[i]) == 0xC0) // 110xxxxx { - if (i + 1 > MyByte.Length) + if (i + 1 > myByte.Length) { isUTF8 = false; break; } - if ((0xC0 & MyByte[i + 1]) == 0x80) // 10xxxxxx + if ((0xC0 & myByte[i + 1]) == 0x80) // 10xxxxxx { i += 2; continue; @@ -262,19 +263,19 @@ private string getcodetype(string path) break; } } - else if ((0xF0 & MyByte[i]) == 0xE0) // 1110xxxx + else if ((0xF0 & myByte[i]) == 0xE0) // 1110xxxx { - if (i + 1 > MyByte.Length) + if (i + 1 > myByte.Length) { isUTF8 = false; break; } - if (i + 2 > MyByte.Length) + if (i + 2 > myByte.Length) { isUTF8 = false; break; } - if (((0xC0 & MyByte[i + 1]) == 0x80) && ((0xC0 & MyByte[i + 2]) == 0x80)) // 10xxxxxx 10xxxxxx + if (((0xC0 & myByte[i + 1]) == 0x80) && ((0xC0 & myByte[i + 2]) == 0x80)) // 10xxxxxx 10xxxxxx { i += 3; continue; @@ -285,7 +286,7 @@ private string getcodetype(string path) break; } } - else // 不是UTF-8字符串 + else //涓嶆槸UTF-8瀛楃涓 { isUTF8 = false; break; @@ -297,24 +298,24 @@ private string getcodetype(string path) if (strCodeType == "CODETYPE_SHIFTJIS") { - for (i = 0; i < MyByte.Length; ) + for (i = 0; i < myByte.Length; ) { - high = MyByte[i]; //读取第一个byte + high = myByte[i]; //璇诲彇绗竴涓猙yte i++; - if (high <= 0x7F) //ASCII码区 + if (high <= 0x7F) //ASCII鐮佸尯 { low = high; high = 0; } - else if ((high >= 0xA1) && (high <= 0xDF)) //半角片假名区 + else if ((high >= 0xA1) && (high <= 0xDF)) //鍗婅鐗囧亣鍚嶅尯 { low = high; high = 0; JP1++; } - else //双字节区 + else //鍙屽瓧鑺傚尯 { - low = MyByte[i]; //读取低位 + low = myByte[i]; //璇诲彇浣庝綅 i++; JP2++; } @@ -322,16 +323,16 @@ private string getcodetype(string path) if (chr < 0x80) // ASCII { } - else if (chr < 0xA1) // 0x80 - 0xA0 未定义空间 + else if (chr < 0xA1) // 0x80 - 0xA0 鏈畾涔夌┖闂 { - strCodeType = "CODETYPE_DEFAULT"; // 未知编码 + strCodeType = "CODETYPE_DEFAULT"; // 鏈煡缂栫爜 break; } - else if (chr < (0xA1 + 63)) // 0xA1 - 0xDF 半角假名区 + else if (chr < (0xA1 + 63)) // 0xA1 - 0xDF 鍗婅鍋囧悕鍖 { } - else if (chr < 0x8140) // 0xE0 - 0x813F 未定义空间 + else if (chr < 0x8140) // 0xE0 - 0x813F 鏈畾涔夌┖闂 { - strCodeType = "CODETYPE_DEFAULT"; // 未知编码 + strCodeType = "CODETYPE_DEFAULT"; // 鏈煡缂栫爜 break; } else // 0x8140 - 0xFFFF @@ -349,19 +350,19 @@ private string getcodetype(string path) if ((strCodeType == "CODETYPE_SHIFTJIS")&&((float)JP1/JP2 >= 1.8)) { - FakeJP = true; + fakeJP = true; strCodeType = "CODETYPE_GBK"; } if (strCodeType == "CODETYPE_GBK") { - for (i = 0; i < MyByte.Length; ) + for (i = 0; i < myByte.Length; ) { - high = MyByte[i]; //读取第一个byte + high = myByte[i]; //璇诲彇绗竴涓猙yte i++; - if (high > 0x7F) //第一个byte是高位 + if (high > 0x7F) //绗竴涓猙yte鏄珮浣 { - low = MyByte[i]; //读取低位 + low = myByte[i]; //璇诲彇浣庝綅 i++; } else @@ -371,11 +372,11 @@ private string getcodetype(string path) } chr = low + high * 256; - if (chr < 0x80) // ASCII码 + if (chr < 0x80) // ASCII鐮 { } - else if (chr < 0x8140) // 0x80 - 0x813F 未定义空间 + else if (chr < 0x8140) // 0x80 - 0x813F 鏈畾涔夌┖闂 { - strCodeType = "CODETYPE_DEFAULT"; // 未知编码 + strCodeType = "CODETYPE_DEFAULT"; // 鏈煡缂栫爜 break; } else @@ -392,13 +393,13 @@ private string getcodetype(string path) if (strCodeType == "CODETYPE_BIG5") { - for (i = 0; i < MyByte.Length; ) + for (i = 0; i < myByte.Length; ) { - high = MyByte[i]; //读取第一个byte + high = myByte[i]; //璇诲彇绗竴涓猙yte i++; - if (high > 0x7F) //第一个byte是高位 + if (high > 0x7F) //绗竴涓猙yte鏄珮浣 { - low = MyByte[i]; //读取低位 + low = myByte[i]; //璇诲彇浣庝綅 i++; } else @@ -407,11 +408,11 @@ private string getcodetype(string path) high = 0; } chr = low + high * 256; - if (chr < 0x80) // ASCII码 + if (chr < 0x80) // ASCII鐮 { } - else if (chr < 0x8140) // 0x80 - 0x813F 未定义空间 + else if (chr < 0x8140) // 0x80 - 0x813F 鏈畾涔夌┖闂 { - strCodeType = "CODETYPE_DEFAULT"; // 未知编码 + strCodeType = "CODETYPE_DEFAULT"; // 鏈煡缂栫爜 break; } else @@ -425,7 +426,7 @@ private string getcodetype(string path) } } } - if ((strCodeType == "CODETYPE_DEFAULT") && FakeJP) + if ((strCodeType == "CODETYPE_DEFAULT") && fakeJP) strCodeType = "CODETYPE_SHIFTJIS"; return strCodeType; @@ -437,25 +438,25 @@ private void output() sw.Write(FileContentTextBox.Text); sw.Close(); - if (Path.GetExtension(original_path).ToLower() == ".cue") + if (Path.GetExtension(originalPath).ToLower() == ".cue") { - // 是否自动发送到播放器 + // 鏄惁鑷姩鍙戦佸埌鎾斁鍣 if (AutoSend2PlayerCheckBox.Checked) { System.Diagnostics.Process.Start(PlayerPathTextBox.Text, paremeterTextBox.Text.Replace("%1", FilePathTextBox.Text)); } - //是否自动处理其他Cue文件 + //鏄惁鑷姩澶勭悊鍏朵粬Cue鏂囦欢 if (AutoDealOtherCueCheckBox.Checked) { - if (musicfiles.Count == 0) //如果没有搜到音乐类型文件,不作任何事情 + if (musicfiles.Count == 0) //濡傛灉娌℃湁鎼滃埌闊充箰绫诲瀷鏂囦欢锛屼笉浣滀换浣曚簨鎯 { } - else if (musicfiles.Count == 1) //如果只搜到一个,那么无脑隐藏其他cue + else if (musicfiles.Count == 1) //濡傛灉鍙悳鍒颁竴涓紝閭d箞鏃犺剳闅愯棌鍏朵粬cue { DealOtherCue(false); } else { - DealOtherCue(true); //如果有多个音乐类型文件,那么仅隐藏与该cue引用了同一个音乐文件的cue + DealOtherCue(true); //濡傛灉鏈夊涓煶涔愮被鍨嬫枃浠讹紝閭d箞浠呴殣钘忎笌璇ue寮曠敤浜嗗悓涓涓煶涔愭枃浠剁殑cue } } @@ -467,7 +468,7 @@ private void output() OutputButton.Enabled = false; loaded = false; - // 是否自动退出 + // 鏄惁鑷姩閫鍑 if ((AutoExitCheckBox.Checked) && (AutoExitCheckBox.Enabled)) { Application.Exit(); @@ -477,7 +478,7 @@ private void output() private void DealOtherCue(bool MultiMusicFile) { List CueFile = new List(); - CueFile.AddRange(Directory.GetFiles(Path.GetDirectoryName(original_path), "*.cue")); + CueFile.AddRange(Directory.GetFiles(Path.GetDirectoryName(originalPath), "*.cue")); for (int i = 0; i < CueFile.Count; i++) { if (CueFile[i] != FilePathTextBox.Text) @@ -488,7 +489,7 @@ private void DealOtherCue(bool MultiMusicFile) } else { - if (FileInFileLine == OpenFile(CueFile[i])) + if (fileInFileLine == OpenFile(CueFile[i])) { DealOtherCueChild(CueFile[i]); } @@ -510,30 +511,30 @@ private void DealOtherCueChild(string path) } else if (radioButton3.Checked) { - Directory.CreateDirectory(Path.GetDirectoryName(original_path) + @"\" + SubDirTextBox.Text + @"\"); - File.Move(path, Path.GetDirectoryName(original_path) + @"\" + SubDirTextBox.Text + @"\" + Path.GetFileName(path)); + Directory.CreateDirectory(Path.GetDirectoryName(originalPath) + @"\" + SubDirTextBox.Text + @"\"); + File.Move(path, Path.GetDirectoryName(originalPath) + @"\" + SubDirTextBox.Text + @"\" + Path.GetFileName(path)); } } - private void button1_Click(object sender, EventArgs e) //通过“打开”对话框打开文件 + private void button1_Click(object sender, EventArgs e) //閫氳繃鈥滄墦寮鈥濆璇濇鎵撳紑鏂囦欢 { if (OpenFileDialog.ShowDialog() == DialogResult.OK) { - original_path = OpenFileDialog.FileName; + originalPath = OpenFileDialog.FileName; main_func(); } } - private void Form1_DragDrop(object sender, DragEventArgs e) //通过拖拽打开文件 + private void Form1_DragDrop(object sender, DragEventArgs e) //閫氳繃鎷栨嫿鎵撳紑鏂囦欢 { - original_path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); + originalPath = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); main_func(); } - private void Form1_DragEnter_1(object sender, DragEventArgs e) //通过拖拽打开文件必须 + private void Form1_DragEnter_1(object sender, DragEventArgs e) //閫氳繃鎷栨嫿鎵撳紑鏂囦欢蹇呴』 { if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Link; @@ -567,7 +568,7 @@ private void DealOtherCueChild(string path) // } //} - private void Form1_Load(object sender, EventArgs e) //读取配置,初始化 + private void Form1_Load(object sender, EventArgs e) //璇诲彇閰嶇疆锛屽垵濮嬪寲 { string[] com = Environment.GetCommandLineArgs(); comboBox1.Text = "932"; @@ -610,12 +611,12 @@ private void DealOtherCueChild(string path) } if (com.Length != 1) { - original_path = com[1]; + originalPath = com[1]; main_func(); } } - private void Form1_FormClosed(object sender, FormClosedEventArgs e) //保存配置 + private void Form1_FormClosed(object sender, FormClosedEventArgs e) //淇濆瓨閰嶇疆 { config.IniWriteValue("Location", "x", this.Location.X.ToString()); config.IniWriteValue("Location", "y", this.Location.Y.ToString()); @@ -641,18 +642,18 @@ private void DealOtherCueChild(string path) } } - private void button2_Click(object sender, EventArgs e) // 手动输出 + private void button2_Click(object sender, EventArgs e) //鎵嬪姩杈撳嚭 { output(); } - private void checkBox1_CheckedChanged(object sender, EventArgs e) // 是否替换源文件 + private void checkBox1_CheckedChanged(object sender, EventArgs e) //鏄惁鏇挎崲婧愭枃浠 { if (CoverOldFileCheckBox.Checked) { RenameTextBox.Enabled = false; - FilePathTextBox.Text = original_path; + FilePathTextBox.Text = originalPath; // RenameTextBox.Text = "%filename%"; } else @@ -663,7 +664,7 @@ private void DealOtherCueChild(string path) } } - private void checkBox2_CheckedChanged(object sender, EventArgs e) //自动模式时禁用「输出」按钮 + private void checkBox2_CheckedChanged(object sender, EventArgs e) //鑷姩妯″紡鏃剁鐢ㄣ岃緭鍑恒嶆寜閽 { if (AutoOutputCheckBox.Checked) { @@ -726,17 +727,17 @@ private void button3_Click(object sender, EventArgs e) } } - private void button4_Click(object sender, EventArgs e) // 添加到注册表 + private void button4_Click(object sender, EventArgs e) // 娣诲姞鍒版敞鍐岃〃 { if (IsUserAdministrator()) { - RegistryKey Root = Registry.ClassesRoot; + RegistryKey root = Registry.ClassesRoot; RegistryKey software = null; - RegistryKey CurrentUser = Registry.CurrentUser; + RegistryKey currentUser = Registry.CurrentUser; if ((System.Environment.OSVersion.Version.Major == 5) || ((System.Environment.OSVersion.Version.Major == 6) && (System.Environment.OSVersion.Version.Minor == 0))) { - software = CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cue\OpenWithProgids"); + software = currentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cue\OpenWithProgids"); if (software != null) { foreach (string b in software.GetValueNames()) @@ -745,9 +746,11 @@ private void button3_Click(object sender, EventArgs e) } } string a = ""; - software = Root.OpenSubKey(".cue"); + software = root.OpenSubKey(".cue"); if (software != null) - a = software.GetValue("").ToString(); + { + a = software.GetValue("", "").ToString(); + } if (a != "") AddToReg(a); else @@ -759,11 +762,10 @@ private void button3_Click(object sender, EventArgs e) if ((System.Environment.OSVersion.Version.Major == 6) && (System.Environment.OSVersion.Version.Minor >= 1)) { string a = ""; - software = CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cue\UserChoice"); + software = currentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cue\UserChoice"); if (software != null) { - if (software.GetValue("Progid") != null) - a = software.GetValue("Progid").ToString(); + a = software.GetValue("Progid", "").ToString(); } if (a != "") { @@ -771,51 +773,56 @@ private void button3_Click(object sender, EventArgs e) } else { - software = Root.OpenSubKey(".cue"); + software = root.OpenSubKey(".cue"); if (software != null) - a = software.GetValue("").ToString(); + { + a = software.GetValue("", "").ToString(); + } if (a != "") + { AddToReg(a); + } else { AddToReg(".cue"); } + } } - MessageBox.Show("已成功注册到右键菜单!"); + MessageBox.Show("宸叉垚鍔熸敞鍐屽埌鍙抽敭鑿滃崟!"); } else { - MessageBox.Show("请重启程序用管理员身份运行!"); + MessageBox.Show("璇烽噸鍚▼搴忕敤绠$悊鍛樿韩浠借繍琛!"); } } void AddToReg(string a) { - RegistryKey Root = Registry.ClassesRoot; - RegistryKey cue = Root.CreateSubKey(a); + RegistryKey root = Registry.ClassesRoot; + RegistryKey cue = root.CreateSubKey(a); RegistryKey shell = cue.CreateSubKey("shell"); - if (shell.OpenSubKey("用 FixCue 修复") != null) - shell.DeleteSubKeyTree("用 FixCue 修复"); + if (shell.OpenSubKey("鐢 FixCue 淇") != null) //鑰佺増鏈仐鐣 + shell.DeleteSubKeyTree("鐢 FixCue 淇"); if (shell.OpenSubKey("Fix") != null) shell.DeleteSubKeyTree("Fix"); - RegistryKey mystring = shell.CreateSubKey("Fix"); - mystring.SetValue("", "用 FixCue 修复"); - RegistryKey command = mystring.CreateSubKey("command"); + RegistryKey fix = shell.CreateSubKey("Fix"); + fix.SetValue("", "鐢 FixCue 淇"); + RegistryKey command = fix.CreateSubKey("command"); command.SetValue("", @"""" + Application.ExecutablePath + @""" ""%1"""); } - private void button5_Click(object sender, EventArgs e) //从注册表移除 + private void button5_Click(object sender, EventArgs e) //浠庢敞鍐岃〃绉婚櫎 { if (IsUserAdministrator()) { - RegistryKey CurrentUser = Registry.CurrentUser; - RegistryKey Root = Registry.ClassesRoot; + RegistryKey currentUser = Registry.CurrentUser; + RegistryKey root = Registry.ClassesRoot; RegistryKey software = null; if ((System.Environment.OSVersion.Version.Major == 5) || ((System.Environment.OSVersion.Version.Major == 6) && (System.Environment.OSVersion.Version.Minor == 0))) { - software = CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cue\OpenWithProgids"); + software = currentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cue\OpenWithProgids"); if (software != null) { foreach (string b in software.GetValueNames()) @@ -824,11 +831,15 @@ void AddToReg(string a) } } string a = ""; - software = Root.OpenSubKey(".cue"); + software = root.OpenSubKey(".cue"); if (software != null) - a = software.GetValue("").ToString(); + { + a = software.GetValue("", "").ToString(); + } if (a != "") + { RemoveFromReg(a); + } else { RemoveFromReg(".cue"); @@ -839,11 +850,10 @@ void AddToReg(string a) { string a = ""; - software = CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cue\UserChoice"); + software = currentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cue\UserChoice"); if (software != null) { - if (software.GetValue("Progid") != null) - a = software.GetValue("Progid").ToString(); + a = software.GetValue("Progid","").ToString(); } if (a != "") { @@ -851,9 +861,9 @@ void AddToReg(string a) } else { - software = Root.OpenSubKey(".cue"); + software = root.OpenSubKey(".cue"); if (software != null) - a = software.GetValue("").ToString(); + a = software.GetValue("","").ToString(); if (a != "") RemoveFromReg(a); else @@ -862,28 +872,28 @@ void AddToReg(string a) } } } - MessageBox.Show("已成功从右键菜单卸载!"); + MessageBox.Show("宸叉垚鍔熶粠鍙抽敭鑿滃崟鍗歌浇!"); } else { - MessageBox.Show("请重启程序用管理员身份运行!"); + MessageBox.Show("璇烽噸鍚▼搴忕敤绠$悊鍛樿韩浠借繍琛!"); } } void RemoveFromReg(string a) { - RegistryKey Root = Registry.ClassesRoot; - RegistryKey cue_shell = Root.OpenSubKey(a + @"\shell", true); + RegistryKey root = Registry.ClassesRoot; + RegistryKey cue_shell = root.OpenSubKey(a + @"\shell", true); if (cue_shell != null) { - if (cue_shell.OpenSubKey("用 FixCue 修复") != null) - cue_shell.DeleteSubKeyTree("用 FixCue 修复"); + if (cue_shell.OpenSubKey("鐢 FixCue 淇") != null) //鑰佺増鏈仐鐣 + cue_shell.DeleteSubKeyTree("鐢 FixCue 淇"); if (cue_shell.OpenSubKey("Fix") != null) cue_shell.DeleteSubKeyTree("Fix"); } } - private void Form1_SizeChanged(object sender, EventArgs e) + private void Form1_SizeChanged(object sender, EventArgs e) //??? { if (this.Width >= 817) { pictureBox1.Left = this.Width - 56; } @@ -895,7 +905,7 @@ private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (loaded) { - forcecode = true; + forceCode = true; main_func(); } } @@ -909,28 +919,28 @@ public class INIClass [DllImport("kernel32")] private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath); /// - /// 构造方法 + /// 鏋勯犳柟娉 /// - /// 文件路径 + /// 鏂囦欢璺緞 public INIClass(string INIPath) { inipath = INIPath; } /// - /// 写入INI文件 + /// 鍐欏叆INI鏂囦欢 /// - /// 项目名称(如 [TypeName] ) - /// 键 - /// 值 + /// 椤圭洰鍚嶇О(濡 [TypeName] ) + /// 閿 + /// 鍊 public void IniWriteValue(string Section, string Key, string Value) { WritePrivateProfileString(Section, Key, Value, this.inipath); } /// - /// 读出INI文件 + /// 璇诲嚭INI鏂囦欢 /// - /// 项目名称(如 [TypeName] ) - /// 键 + /// 椤圭洰鍚嶇О(濡 [TypeName] ) + /// 閿 public string IniReadValue(string Section, string Key) { StringBuilder temp = new StringBuilder(500); @@ -938,9 +948,9 @@ public string IniReadValue(string Section, string Key) return temp.ToString(); } /// - /// 验证文件是否存在 + /// 楠岃瘉鏂囦欢鏄惁瀛樺湪 /// - /// 布尔值 + /// 甯冨皵鍊 public bool ExistINIFile() { return System.IO.File.Exists(inipath); diff --git a/FixCue/app.manifest b/FixCue/app.manifest new file mode 100644 index 0000000..4670159 --- /dev/null +++ b/FixCue/app.manifest @@ -0,0 +1,76 @@ +锘 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +