Example #1
0
 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);
 }
Example #2
0
        private void frmConfig_Load(object sender, EventArgs e)
        {
            DB2Config config   = DB2Config.GetInstance();
            CLConfig  clconfig = CLConfig.GetInstance();

            if (string.Equals(config.GetSettingNext("NotShowIco"), "True", StringComparison.OrdinalIgnoreCase))
            {
                checkBoxX1.Checked = true;
            }

            if (string.Equals(config.GetSettingNext("NoVirtualMode"), "True", StringComparison.OrdinalIgnoreCase))
            {
                checkBoxX2.Checked = true;
            }

            if (string.Equals(clconfig.GetSetting("AllowForbiddenCard"), "True", StringComparison.OrdinalIgnoreCase))
            {
                checkBoxX3.Checked = true;
            }

            if (string.Equals(config.GetSettingNext("NoDrag"), "True", StringComparison.OrdinalIgnoreCase))
            {
                checkBoxX4.Checked = true;
            }

            if (!string.Equals(clconfig.GetSettingNext("AllowDIY"), "True", StringComparison.OrdinalIgnoreCase))
            {
                checkBoxX5.Checked = false;
            }

            if (!string.Equals(config.GetSetting("SaveLayout"), "True", StringComparison.OrdinalIgnoreCase))
            {
                checkBoxX6.Checked = false;
            }

            textBox1.Text = config.GetSetting("ImagePath");

            textBox2.Text = config.GetSetting("IcoPath");

            textBox3.Text = config.GetSetting("NBXPath");

            textBox4.Text = config.GetSetting("DeckPath");

            textBox5.Text = config.GetSetting("DIYImagePath");
        }
Example #3
0
        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);
        }