public static string ConvertToDb(string oneStarDictFilePath)
        {
            var filepath           = oneStarDictFilePath;
            var files              = ParseFiles(filepath);
            List <WordEntry> infos = ParseIfo(files);

            List <IdxEntry>  indexs = ParseIdx(files);
            List <WordEntry> dicts  = 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
            //clear duplicates
            HashSet <string> keys       = new HashSet <string>();
            List <WordEntry> duplicates = new List <WordEntry>();

            foreach (var d in dicts)
            {
                if (!keys.Contains(d.word))
                {
                    keys.Add(d.word);
                }
                else
                {
                    duplicates.Add(d);
                }
            }
            foreach (var d in duplicates)
            {
                dicts.Remove(d);
            }

            converter.InsertDictEntries(dicts);

            return(dbFilePath);
        }
Exemple #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();
        }