Exemplo n.º 1
0
        private void ToolBar_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

                var      content  = files[0];
                FileInfo fileInfo = new FileInfo(content);
                if (fileInfo != null)
                {
                    string extension = System.IO.Path.GetExtension(content);
                    switch (extension)
                    {
                    case ".db":
                    {        // If is db file
                        this.viewModel.DbPath = content;
                    }
                    break;

                    case ".idx":
                    {
                        var dbPath = content.Substring(0, content.Length - 4) + ".db";
                        if (!File.Exists(dbPath))
                        {
                            dbPath = StarDictParser.ConvertToDb(content);
                        }

                        //recheck
                        if (!File.Exists(dbPath))
                        {
                            MessageBox.Show($"Please check if db file exists : {System.IO.Path.GetFileName(dbPath)} \r\nor\r\nTry to repair the dict file name.", "Error");
                        }

                        this.viewModel.DbPath = dbPath;
                    }
                    break;
                    }
                }
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Please supply a StarDict idx file path!");
                return;
            }

            foreach (var arg in args)
            {
                Console.WriteLine(arg);
            }

            var filepath           = args[0];
            var files              = StarDictParser.ParseFiles(filepath);
            List <WordEntry> infos = StarDictParser.ParseIfo(files);

            List <IdxEntry>  indexs = StarDictParser.ParseIdx(files);
            List <WordEntry> dicts  = StarDictParser.ParseDict(files, indexs);

            var dbFilePath = SQLiteDBHelper.ParseDbFilePath(files.idx);

            using (SQLiteDBHelper converter = new SQLiteDBHelper())
            {
                converter.InitDb(dbFilePath);

                //transfer entries to db
                // 1. ifo
                infos.ForEach(info => converter.InsertIfoEntry(info.word, info.content));

                // 2. dict
                converter.InsertDictEntries(dicts);
            }

            Console.WriteLine("Done!");

            Console.Write("Press any key to continue ...");
            Console.ReadKey();
        }