public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); comboBoxInput.IntegralHeight = false; comboBoxInput.MaxDropDownItems = 10; using (var sr = new StreamReader(OptionManager.Instance().StylePath)) { m_css = sr.ReadToEnd(); } m_posSaver = new WindowPositionSaver(this, "CsDict", "main"); }
void PlayVoice() { string word = m_dict.GetWordByIndex(m_position); // 遇到词组 取第一个单词 int pos = word.IndexOf(' '); if (pos > 0) { word = word.Substring(0, word.IndexOf(' ')); } string path = OptionManager.Instance().VoicePath + word[0] + "\\" + word + ".wav"; m_sp.Stop(); try { m_sp.SoundLocation = path; m_sp.Play(); } catch (FileNotFoundException) { // do nothing } }
public static void CreateIndex(BackgroundWorker worker) { string fileName = OptionManager.Instance().DictPath; string idxFileName = OptionManager.Instance().IdxPath; var arrayRecord = new ArrayList(); int offset = 0; int lastPos = offset; int tmpByte; var tmpStream = new MemoryStream(); const float totalCount = 50439; // 怎样程序获得呢? int lastPercent = 0; int percent = 0; // try { var f = new FileStream(fileName, FileMode.Open); tmpByte = f.ReadByte(); while (tmpByte > 0) { if (tmpByte == '\t') { var rec = new Record(); rec.nOffset = lastPos; rec.strWord = System.Text.Encoding.UTF8.GetString(tmpStream.ToArray()); rec.strMetaphone = GetMetaphone(rec.strWord); arrayRecord.Add(rec); //Debug.WriteLine(rec.strWord + ";" + rec.strMetaphone); percent = (int)((float)arrayRecord.Count / totalCount * 90.0f); if (percent != lastPercent) { lastPercent = percent; worker.ReportProgress(percent, "已处理: " + arrayRecord.Count + " " + rec.strWord + "-->" + rec.strMetaphone); } } else if (tmpByte == '\n') { lastPos = offset + 1; tmpStream.SetLength(0); } else { tmpStream.WriteByte((byte)tmpByte); } offset++; tmpByte = f.ReadByte(); } f.Close(); // } // catch ( Exception e ) { // MessageBox.Show(e.StackTrace); // worker.ReportProgress(50, "错误: " + e.Message); // } worker.ReportProgress(90, "排序..."); arrayRecord.Sort(new CompareWord()); worker.ReportProgress(92, "排序完成"); worker.ReportProgress(94, "写入索引文件..."); WriteIdxFile(arrayRecord, idxFileName); worker.ReportProgress(96, "写入完成"); worker.ReportProgress(98, "排序相似性..."); arrayRecord.Sort(new CompareMetaphone()); worker.ReportProgress(100, "写入相似性文件..."); WriteIdxFile(arrayRecord, OptionManager.Instance().MetaphoneIdxPath); }
public IndexedDict() { m_dictFile = new FileStream(OptionManager.Instance().DictPath, FileMode.Open, FileAccess.Read); m_idxFile = new FileStream(OptionManager.Instance().IdxPath, FileMode.Open, FileAccess.Read); m_metaphoneFile = new FileStream(OptionManager.Instance().MetaphoneIdxPath, FileMode.Open, FileAccess.Read); }