public static CardLibrary GetInstance() { if (instance == null) { CLConfig config = CLConfig.GetInstance(); Path = System.AppDomain.CurrentDomain.BaseDirectory; KeepInMemory = string.Equals(config.GetSetting("KeepInMemory"), "true", StringComparison.OrdinalIgnoreCase); if (KeepInMemory) { ramdir = new Lucene.Net.Store.RAMDirectory(Path + "CardIndex"); CardsReader Reader = new LuceneReader(); instance = new CardLibrary(Reader.Read(ramdir)); if (Directory.Exists(Path + "DIYCardIndex")) { ramdiydir = new Lucene.Net.Store.RAMDirectory(Path + "DIYCardIndex"); instance.AddDIYCards(Reader.Read(ramdiydir)); } } else { CardsReader Reader = new LuceneReader(); instance = new CardLibrary(Reader.Read(Path + "CardIndex")); if (Directory.Exists(Path + "DIYCardIndex")) { instance.AddDIYCards(Reader.Read(Path + "DIYCardIndex")); } } } return(instance); }
private void button6_Click(object sender, EventArgs e) { this.Text = "测试中,请稍候"; CardsReader mReader = new LuceneReader(); CardLibrary cardLibrary = new CardLibrary(mReader.Read("CardIndex")); OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "中中版查卡器数据文件 (ocg.yxwp)|ocg.yxwp|All files (*.*)|*.*"; openFileDialog1.FilterIndex = 0; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { File.WriteAllText("test.txt", "", Encoding.GetEncoding("GB2312")); int i = 0; StreamReader sr = new StreamReader(openFileDialog1.FileName, Encoding.GetEncoding("GB2312")); while (!sr.EndOfStream) { string s = sr.ReadLine(); string[] ss = s.Split('^'); string n = ss[1]; i++; if (cardLibrary.GetCardByName(n) == null && cardLibrary.GetCardByOldName(n) == null) { File.AppendAllText("test.txt", string.Format("{0} {1}\r\n", i, n), Encoding.GetEncoding("GB2312")); } } sr.Close(); } this.Text = "辅助转换工具"; MessageBox.Show("测试完成!"); }
private void button5_Click(object sender, EventArgs e) { this.Text = "转换中,请稍候"; CardsReader mReader = new LuceneReader(); CardLibrary cardLibrary = new CardLibrary(mReader.Read("CardIndex")); CardsSaver aSaver = new AllCardsSaver(); aSaver.Save("allcards.dll", cardLibrary.GetCards()); this.Text = "辅助转换工具"; MessageBox.Show("导出完成!"); }
public static CardLibrary GetInstance() { //单实例 if (instance == null) { //读取配置 CLConfig config = CLConfig.GetInstance(); //获取路径 path = Global.GetPath(); //清除多余索引文件 if (File.Exists(path + "CardIndex\\list.txt")) { string[] files = File.ReadAllLines(path + "CardIndex\\list.txt", Encoding.UTF8); foreach (string s in Directory.GetFiles(path + "CardIndex")) { string ss = s.Substring(s.LastIndexOf('\\') + 1); bool inlist = false; foreach (string s2 in files) { if (string.Equals(ss, s2, StringComparison.OrdinalIgnoreCase)) { inlist = true; break; } } if (!(inlist || string.Equals(ss, "list.txt", StringComparison.OrdinalIgnoreCase))) { File.Delete(s); } } } //读取主索引 indexdir = new Lucene.Net.Store.SimpleFSDirectory(new DirectoryInfo(path + "CardIndex"), new Lucene.Net.Store.SimpleFSLockFactory()); //读取DIY索引 if (Directory.Exists(path + "DIYCardIndex")) { diydir = new Lucene.Net.Store.SimpleFSDirectory(new DirectoryInfo(path + "DIYCardIndex"), new Lucene.Net.Store.SimpleFSLockFactory()); } //是否使用内存索引 KeepInMemory = string.Equals(config.GetSetting("KeepInMemory"), "true", StringComparison.OrdinalIgnoreCase); if (KeepInMemory) { indexdir = new Lucene.Net.Store.RAMDirectory(indexdir); if (diydir != null) { diydir = new Lucene.Net.Store.RAMDirectory(diydir); } } //读取所有卡片信息,建立卡片数据库实例 LuceneReader Reader = new LuceneReader(); instance = new CardLibrary(Reader.Read(indexdir)); if (diydir != null) { instance.AddDIYCards(Reader.Read(diydir)); } //建立搜索器实例 instance.BuildSearcher(); } return(instance); }