Skip to content

Commit

Permalink
chore: clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
nopdan committed Jan 26, 2024
1 parent 0dbe53e commit 9d56350
Show file tree
Hide file tree
Showing 148 changed files with 792 additions and 975 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# 深蓝词库转换

[![Stars](https://img.shields.io/github/stars/studyzy/imewlconverter)](https://github.com/studyzy/imewlconverter/stargazers)
![Actions Check](https://badgen.net/github/checks/studyzy/imewlconverter)
![License](https://badgen.net/github/license/studyzy/imewlconverter)
![GitHub repo size](https://img.shields.io/github/repo-size/studyzy/imewlconverter)
![Actions Check](https://github.com/studyzy/imewlconverter/actions/workflows/winform.yml/badge.svg)
![License](https://img.shields.io/github/license/studyzy/imewlconverter)
![Repo size](https://img.shields.io/github/repo-size/studyzy/imewlconverter)
[![Code Count](https://tokei.rs/b1/github/studyzy/imewlconverter)](https://github.com/studyzy/imewlconverter)

[![Join the chat](https://badges.gitter.im/studyzy/imewlconverter.svg)](https://gitter.im/studyzy/imewlconverter?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Expand Down
14 changes: 7 additions & 7 deletions src/IME WL Converter Win/CoreWinFormMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

using Studyzy.IMEWLConverter.IME;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Windows.Forms;
using Studyzy.IMEWLConverter.IME;

namespace Studyzy.IMEWLConverter
{
Expand All @@ -32,12 +32,12 @@ internal class CoreWinFormMapping
private void InitImportFormMapping()
{
imeFormMapping = new Dictionary<Type, Form>();
imeFormMapping.Add(typeof (Rime), new RimeConfigForm());
imeFormMapping.Add(typeof (LingoesLd2), new Ld2EncodingConfigForm());
imeFormMapping.Add(typeof (Xiaoxiao), new XiaoxiaoConfigForm());
imeFormMapping.Add(typeof (SelfDefining), new SelfDefiningConfigForm());
imeFormMapping.Add(typeof (UserDefinePhrase), new PhraseFormatConfigForm());
imeFormMapping.Add(typeof (XiaoxiaoErbi), new ErbiTypeForm());
imeFormMapping.Add(typeof(Rime), new RimeConfigForm());
imeFormMapping.Add(typeof(LingoesLd2), new Ld2EncodingConfigForm());
imeFormMapping.Add(typeof(Xiaoxiao), new XiaoxiaoConfigForm());
imeFormMapping.Add(typeof(SelfDefining), new SelfDefiningConfigForm());
imeFormMapping.Add(typeof(UserDefinePhrase), new PhraseFormatConfigForm());
imeFormMapping.Add(typeof(XiaoxiaoErbi), new ErbiTypeForm());
imeFormMapping.Add(typeof(Win10MsPinyin), new PinyinConfigForm());
imeFormMapping.Add(typeof(Gboard), new PinyinConfigForm());
}
Expand Down
4 changes: 2 additions & 2 deletions src/IME WL Converter Win/EncodingComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

Expand Down Expand Up @@ -60,7 +59,8 @@ public Encoding SelectedEncoding
{
return Encoding.GetEncoding(Text);
}
catch (Exception ex) {
catch (Exception ex)
{
MessageBox.Show(ex.Message, "出错", MessageBoxButtons.OK, MessageBoxIcon.Error);

Check warning on line 64 in src/IME WL Converter Win/EncodingComboBox.cs

View workflow job for this annotation

GitHub Actions / build

This call site is reachable on all platforms. 'MessageBoxButtons.OK' is only supported on: 'windows' 6.1 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
return Encoding.Default;
}
Expand Down
20 changes: 10 additions & 10 deletions src/IME WL Converter Win/Forms/AboutBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public string AssemblyTitle
get
{
object[] attributes =
Assembly.GetExecutingAssembly().GetCustomAttributes(typeof (AssemblyTitleAttribute), false);
Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
if (attributes.Length > 0)
{
var titleAttribute = (AssemblyTitleAttribute) attributes[0];
var titleAttribute = (AssemblyTitleAttribute)attributes[0];
if (titleAttribute.Title != "")
{
return titleAttribute.Title;
Expand All @@ -65,12 +65,12 @@ public string AssemblyDescription
get
{
object[] attributes =
Assembly.GetExecutingAssembly().GetCustomAttributes(typeof (AssemblyDescriptionAttribute), false);
Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyDescriptionAttribute) attributes[0]).Description;
return ((AssemblyDescriptionAttribute)attributes[0]).Description;
}
}

Expand All @@ -79,12 +79,12 @@ public string AssemblyProduct
get
{
object[] attributes =
Assembly.GetExecutingAssembly().GetCustomAttributes(typeof (AssemblyProductAttribute), false);
Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyProductAttribute) attributes[0]).Product;
return ((AssemblyProductAttribute)attributes[0]).Product;
}
}

Expand All @@ -93,12 +93,12 @@ public string AssemblyCopyright
get
{
object[] attributes =
Assembly.GetExecutingAssembly().GetCustomAttributes(typeof (AssemblyCopyrightAttribute), false);
Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCopyrightAttribute) attributes[0]).Copyright;
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
}
}

Expand All @@ -107,12 +107,12 @@ public string AssemblyCompany
get
{
object[] attributes =
Assembly.GetExecutingAssembly().GetCustomAttributes(typeof (AssemblyCompanyAttribute), false);
Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCompanyAttribute) attributes[0]).Company;
return ((AssemblyCompanyAttribute)attributes[0]).Company;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/IME WL Converter Win/Forms/ChineseConverterSelectForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

using System;
using System.Windows.Forms;
using Studyzy.IMEWLConverter.Entities;
using Studyzy.IMEWLConverter.Language;
using System;
using System.Windows.Forms;

namespace Studyzy.IMEWLConverter
{
Expand Down
6 changes: 0 additions & 6 deletions src/IME WL Converter Win/Forms/DonateForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
*/

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;

namespace Studyzy.IMEWLConverter
Expand Down
2 changes: 1 addition & 1 deletion src/IME WL Converter Win/Forms/ErbiTypeForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

using Studyzy.IMEWLConverter.Entities;
using System;
using System.Windows.Forms;
using Studyzy.IMEWLConverter.Entities;

namespace Studyzy.IMEWLConverter
{
Expand Down
8 changes: 0 additions & 8 deletions src/IME WL Converter Win/Forms/ErrorLogForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Studyzy.IMEWLConverter
Expand Down
9 changes: 5 additions & 4 deletions src/IME WL Converter Win/Forms/FilterConfigForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

using Studyzy.IMEWLConverter.Entities;
using System;
using System.Windows.Forms;
using Studyzy.IMEWLConverter.Entities;

namespace Studyzy.IMEWLConverter
{
Expand Down Expand Up @@ -123,8 +123,8 @@ private void cbxKeepNumber__CheckedChanged(object sender, EventArgs e)
{
if (cbxKeepNumber_.Checked)
{
cbxKeepNumber.Checked = false;
cbxChsNumber.Checked = false;
cbxKeepNumber.Checked = false;
cbxChsNumber.Checked = false;
}

}
Expand All @@ -140,7 +140,8 @@ private void cbxKeepEnglish_CheckedChanged(object sender, EventArgs e)

private void cbxKeepEnglish__CheckedChanged(object sender, EventArgs e)
{
if (cbxKeepEnglish_.Checked) {
if (cbxKeepEnglish_.Checked)
{
cbxKeepEnglish.Checked = false;
cbxPrefixEnglish.Checked = false;
}
Expand Down
25 changes: 12 additions & 13 deletions src/IME WL Converter Win/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,18 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;
using Studyzy.IMEWLConverter.Entities;
using Studyzy.IMEWLConverter.Filters;
using Studyzy.IMEWLConverter.Generaters;
using Studyzy.IMEWLConverter.Helpers;
using Studyzy.IMEWLConverter.IME;
using Studyzy.IMEWLConverter.Language;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
using System.Windows.Forms;

namespace Studyzy.IMEWLConverter
{
Expand Down Expand Up @@ -168,7 +165,7 @@ private IWordLibraryImport GetImportInterface(string str)
//private bool isFolderBatchConvert = false;
private FilterConfig filterConfig = new FilterConfig();
//private ParsePattern fromUserSetPattern;
private SortType sortType=SortType.Default;
private SortType sortType = SortType.Default;
private bool sortDesc = false;

private IWordLibraryImport import;
Expand Down Expand Up @@ -603,13 +600,14 @@ private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerComple
}
else if (mergeTo1File)
{
var dataText=string.Join("\r\n", mainBody.ExportContents);
var dataText = string.Join("\r\n", mainBody.ExportContents);
if (toolStripMenuItemShowLess.Checked && (dataText.Length > 200000))
{
richTextBox1.Text = "为避免输出时卡死,“高级设置”中选中了“结果只显示首、末10万字”,本文本框中不显示转换后的全部结果,若要查看转换后的结果再确定是否保存请取消该设置。\n\n"
+ dataText.Substring(0, 100000) + "\n\n\n...\n\n\n" + dataText.Substring(dataText.Length - 100000);
}
else if (dataText.Length > 0) {
else if (dataText.Length > 0)
{
richTextBox1.Text = dataText;
//btnExport.Enabled = true;
}
Expand Down Expand Up @@ -646,7 +644,8 @@ private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerComple

}
}
else {
else
{
MessageBox.Show("转换失败,没有找到词条", "深蓝词库转换", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/IME WL Converter Win/Forms/MergeWLForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

using Studyzy.IMEWLConverter.Helpers;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Studyzy.IMEWLConverter.Helpers;

namespace Studyzy.IMEWLConverter
{
Expand Down Expand Up @@ -85,7 +85,7 @@ private void btnMergeWL_Click(object sender, EventArgs e)

private Dictionary<string, List<string>> ConvertTxt2Dictionary(string txt)
{
string[] lines = txt.Split(new[] {'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries);
string[] lines = txt.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
var mainDict = new Dictionary<string, List<string>>();
foreach (string line in lines)
{
Expand Down
36 changes: 18 additions & 18 deletions src/IME WL Converter Win/Forms/PhraseFormatConfigForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,19 @@ private void btnOK_Click(object sender, EventArgs e)
switch (cbxCodeType.Text)
{
case "用户自定义短语":
selectCodeType = CodeType.UserDefinePhrase;break;
selectCodeType = CodeType.UserDefinePhrase; break;
case "拼音":
selectCodeType = CodeType.Pinyin;break;
selectCodeType = CodeType.Pinyin; break;
case "拼音首字母":
selectCodeType = CodeType.Pinyin;
isShortCode = true;
break;
case "五笔":
selectCodeType = CodeType.Wubi98;break;
selectCodeType = CodeType.Wubi98; break;
default:
selectCodeType = CodeType.UserDefinePhrase; break;
}

userFormat = txbUserFormat.Text;
DialogResult = DialogResult.OK;
}
Expand All @@ -95,38 +95,38 @@ private void PhraseFormatConfigForm_Load(object sender, EventArgs e)
switch (selectIndex)
{
case 0:
{
rbtnSougouFormat.Checked = true;
}
{
rbtnSougouFormat.Checked = true;
}
break;
case 1:
{
rbtnQQFormat.Checked = true;
}
{
rbtnQQFormat.Checked = true;
}
break;
case 2:
{
rbtnBaiduFormat.Checked = true;
}
{
rbtnBaiduFormat.Checked = true;
}
break;
default:
{
rbtnUserFormat.Checked = true;
}
{
rbtnUserFormat.Checked = true;
}
break;
}
txbUserFormat.Text = userFormat;
switch (selectCodeType)
{
case CodeType.UserDefinePhrase:cbxCodeType.Text = "用户自定义短语";break;
case CodeType.UserDefinePhrase: cbxCodeType.Text = "用户自定义短语"; break;
case CodeType.Pinyin:
cbxCodeType.Text = "拼音";
if (isShortCode)
{
cbxCodeType.Text = "拼音首字母";
}
break;
case CodeType.Wubi98:cbxCodeType.Text = "五笔";break;
case CodeType.Wubi98: cbxCodeType.Text = "五笔"; break;
default: cbxCodeType.Text = "用户自定义短语"; break;
}
}
Expand Down
Loading

0 comments on commit 9d56350

Please sign in to comment.