예제 #1
0
        public static Dictionary <string, string> GetKindleList()
        {
            /* If Kindle is not connected, it will use the list of IDs stored from the last time it was.
             * Returns a dictionary in the format:
             *      Dictionary
             *      {
             *          MD5 hash: Filepath
             *      }
             */
            Dictionary <string, string> fileHashes = new Dictionary <string, string>();
            var progressWindow = new ProgressWindow();

            progressWindow.Show();
            progressWindow.StopProgress();

            Task.Factory.StartNew(() =>
            {
                foreach (DriveInfo drive in DriveInfo.GetDrives())
                {
                    string driveName = drive.IsReady ? drive.VolumeLabel : null; // Makes sure we only try to query mounted drives
                    if (driveName != null && driveName.Contains("Kindle"))       // TODO more robust Kindle detection
                    {
                        // Kindle is connected, get current library


                        progressWindow.ChangeText("Locating Kindle contents...");


                        string[] kindleFiles = FileTools.Walker(new List <string> {
                            drive.Name
                        });
                        progressWindow.SetProgressBarMax(kindleFiles.Length);
                        progressWindow.StartProgress();
                        progressWindow.ChangeText("Processing Kindle files...");

                        foreach (string file in kindleFiles)
                        {
                            string ext = Path.GetExtension(file);
                            if (ext.StartsWith("."))
                            {
                                ext = ext.Substring(1);
                            }
                            if (Constants.AllowedExt.Contains(ext))
                            {
                                string workHash      = WorkIdent.Hash(file);
                                fileHashes[workHash] = file;
                            }

                            progressWindow.UpdateProgressBar();
                        }

                        MiddleDude.StoreKindle(fileHashes);
                    }
                }
            });


            progressWindow.Close();
            Console.WriteLine("Kindle fetch complete!");
            try
            {
                fileHashes = MiddleDude.LoadKindle();
                return(fileHashes);
            }
            catch (InvalidOperationException)
            {
                return(fileHashes);
            }
        }