Ejemplo n.º 1
0
        private void LibInit()
        {
            List <string> folders = new List <string>();
            Dictionary <string, string> fileHashes = new Dictionary <string, string>();
            var progressWindow = new ProgressWindow();

            Task.Factory.StartNew(() =>
            {
                folders = MiddleDude.GetLibFolders();

                if (folders.Count < 1)
                {
                    using (System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog())
                    {
                        dialog.Description = "Select Folder...";
                        if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            string initFolder = dialog.SelectedPath;
                            MiddleDude.AddLibraryFolder(initFolder);
                        }
                    }
                }
            }).ContinueWith(x =>
            {
                progressWindow.StopProgress();
                progressWindow.ChangeText("Locating library contents...");

                string[] allFiles = FileTools.Walker(folders);

                progressWindow.SetProgressBarMax(allFiles.Length);
                progressWindow.StartProgress();
                progressWindow.ChangeText("Processing library files...");

                foreach (string file in allFiles)
                {
                    string ext = Path.GetExtension(file);
                    if (Constants.AllowedExt.Contains(ext.Remove(0, 1)))
                    {
                        string workHash      = WorkIdent.Hash(file);
                        fileHashes[workHash] = file;
                    }
                    progressWindow.UpdateProgressBar();
                }
                progressWindow.StopProgress();
            }).ContinueWith(x =>
            {
                MiddleDude.StoreLibHashes(fileHashes);
            });

            progressWindow.Close();

            Console.WriteLine("LibInit complete!");
            //using (var writer = new FileStream(Constants.LibHashList, FileMode.Create))
            //{
            //    XmlSerializer ser = new XmlSerializer(typeof(SerializableDictionary<string, string>), new XmlRootAttribute("root"));
            //    ser.Serialize(writer, fileHashes);
            //}

            //XmlOperator.Serialize(fileHashes, Constants.LibHashList);
        }
Ejemplo n.º 2
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);
            }
        }