public WordLibraryList Import(string str) { GlobalCache.CharList.Clear(); GlobalCache.Stackes.Clear(); GlobalCache.WordList.Clear(); var fs = new FileStream(str, FileMode.Open, FileAccess.Read); ParseHeader(fs); TouchPalChar rootChar = TouchPalChar.Load(fs); //载入第一个字 LoadTree(fs, rootChar); fs.Close(); var wwl = new WordLibraryList(); foreach (int i in GlobalCache.WordList.Keys) { TouchPalWord w = GlobalCache.WordList[i]; var wl = new WordLibrary(); wl.Count = w.Count; wl.PinYin = w.PinYin.ToArray(); wl.Word = w.ChineseWord; //sb.AppendLine(py + "\t" + GlobalCache.WordList[i].ChineseWord + "\t" + GlobalCache.WordList[i].Count); wwl.Add(wl); } return(wwl); }
private void LoadTree(FileStream fs, TouchPalChar root) { if (root.CountPosition > 0) { GlobalCache.Stackes.Push(root); int wordLength = GlobalCache.Stackes.Count; root.Word = TouchPalWord.LoadCountAndWord(wordLength, fs, root.CountPosition); root.Word.Chars = GlobalCache.Stackes.ToArray(); GlobalCache.Stackes.Pop(); } #if DEBUG DebugPrintData(root); #endif if (root.NextCharPosition > 0) { GlobalCache.Stackes.Push(root); root.NextChar = TouchPalChar.Load(fs, root.NextCharPosition); LoadTree(fs, root.NextChar); } if (root.NextCharPosition > 0 && root.JumpToPosition > 0) { GlobalCache.Stackes.Pop(); } if (root.JumpToPosition > 0) { root.JumpToChar = TouchPalChar.Load(fs, root.JumpToPosition); LoadTree(fs, root.JumpToChar); } if (root.NextCharPosition > 0 && root.JumpToPosition == 0) { GlobalCache.Stackes.Pop(); } //if (root.PrevCharPosition > 0) //{ // root.PrevChar = TouchPalChar.Load(fs, root.PrevCharPosition); //} //if (root.PrevValidCharPosition > 0) //{ // root.PrevValidChar = TouchPalChar.Load(fs, root.PrevValidCharPosition); //} }