Exemplo n.º 1
0
        // TODO: Add notable clips
        public Task Populate(string filePath)
        {
            var ver = XRayUtil.CheckXRayVersion(filePath);

            if (ver == XRayUtil.XRayVersion.Invalid)
            {
                Logger.Log("Invalid X-Ray file.");
                return(Task.Delay(1));
            }
            var terms = ver == XRayUtil.XRayVersion.New
                ? XRayUtil.ExtractTermsNew(new SQLiteConnection($"Data Source={filePath}; Version=3;"), true)
                : XRayUtil.ExtractTermsOld(filePath);

            flpPeople.Controls.Clear();
            flpTerms.Controls.Clear();

            foreach (XRay.Term t in terms)
            {
                XRayPanel p = new XRayPanel(t.Type, t.TermName, Math.Max(t.Occurrences.Count, t.Locs.Count).ToString(), t.Desc);
                if (t.Type == "character")
                {
                    flpPeople.Controls.Add(p);
                }
                if (t.Type == "topic")
                {
                    flpTerms.Controls.Add(p);
                }
            }
            tcXray.SelectedIndex = 0;
            return(Task.Delay(1));
        }
Exemplo n.º 2
0
        private void btnExtractTerms_Click(object sender, EventArgs e)
        {
            string selPath = UIFunctions.GetFile("Open a Kindle X-Ray file...", "", "ASC files|*.asc", _settings.outDir);

            if (selPath == "" || !selPath.Contains("XRAY.entities"))
            {
                Logger.Log("Invalid or no file selected.");
                return;
            }
            var newVer = XRayUtil.CheckXRayVersion(selPath);

            if (newVer == XRayUtil.XRayVersion.Invalid)
            {
                Logger.Log("Invalid X-Ray file.");
                return;
            }
            try
            {
                var terms = newVer == XRayUtil.XRayVersion.New
                    ? XRayUtil.ExtractTermsNew(new SQLiteConnection($"Data Source={selPath}; Version=3;"), true)
                    : XRayUtil.ExtractTermsOld(selPath);
                if (!Directory.Exists(Environment.CurrentDirectory + @"\xml\"))
                {
                    Directory.CreateDirectory(Environment.CurrentDirectory + @"\xml\");
                }
                string outfile = Environment.CurrentDirectory + @"\xml\" + Path.GetFileNameWithoutExtension(selPath) + ".xml";
                Functions.Save(terms.ToList(), outfile);
                Logger.Log("Character data has been successfully extracted and saved to: " + outfile);
            }
            catch (Exception ex)
            {
                Logger.Log("Error:\r\n" + ex.Message + "\r\n" + ex.StackTrace);
            }
        }