예제 #1
0
        public static bool CopyToReader(EBookReaderDevices reader, string id)
        {
            Books book = new BookServices().Get(id) as Books;

            if (book != null)
            {
                string filePath = Path.Combine(book.FilePath, book.FileName);
                if (reader != null && string.IsNullOrWhiteSpace(filePath) == false)
                {
                    if (File.Exists(KindleGenApp))
                    {
                        ProcessStartInfo processStartInfo = new ProcessStartInfo();
                        processStartInfo.FileName  = KindleGenApp;
                        processStartInfo.Arguments = string.Format("\"{0}\"", filePath);
                        processStartInfo.RedirectStandardOutput = true;
                        processStartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
                        processStartInfo.CreateNoWindow         = true;
                        processStartInfo.UseShellExecute        = false;
                        Process convertProcess = Process.Start(processStartInfo);
                        convertProcess.WaitForExit(10000);

                        string output = Path.ChangeExtension(filePath, ".mobi");

                        if (File.Exists(output))
                        {
                            FileInfo file = new FileInfo(output);
                            if (Directory.Exists(Path.Combine(reader.LogicalDisk + @"\", KindleFolder)) == false)
                            {
                                Directory.CreateDirectory(Path.Combine(reader.LogicalDisk + @"\", KindleFolder));
                            }

                            File.Copy(output, Path.Combine(reader.LogicalDisk + @"\", KindleFolder, file.Name));

                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
예제 #2
0
        private void mniSendKindle_OnClick(object sender, RoutedEventArgs e)
        {
            Cursor = Cursors.Wait;

            Task.Factory.StartNew(() => Util.NotifyEvent("SendKindle"));

            try
            {
                EBookReaderDevices reader = EBookReaderServices.GetReader();
                if (reader != null)
                {
                    ThumbItem item = MainStack.SelectedItems[0] as ThumbItem;
                    if (item != null)
                    {
                        bool results = EBookReaderServices.CopyToReader(reader, item.Id);
                        if (results == true)
                        {
                            new MessageBoxYesNo(item.Name + " " +
                                                ((App)Application.Current).LoadedLanguageResourceDictionary["CopyKindleOK"], false, false).ShowDialog();
                        }
                        else
                        {
                            new MessageBoxYesNo(((App)Application.Current).LoadedLanguageResourceDictionary["CopyKindleKO"].ToString(), false, false).ShowDialog();
                        }
                    }
                }
                else
                {
                    new MessageBoxYesNo(((App)Application.Current).LoadedLanguageResourceDictionary["NoKindle"].ToString(), false, false).ShowDialog();
                }
            }
            catch (Exception ex)
            {
                CatchException(ex);
            }
            Cursor = null;
        }
예제 #3
0
        private static IList <EBookReaderDevices> GetUsbDevices()
        {
            List <EBookReaderDevices> devices = new List <EBookReaderDevices>();

            ManagementObjectCollection collection;
            SelectQuery selectQuery = new SelectQuery("Win32_DiskDrive");

            using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(selectQuery))
                collection = searcher.Get();

            foreach (ManagementObject device in collection)
            {
                EBookReaderDevices reader = new EBookReaderDevices();
                reader.DeviceID     = device.GetPropertyValue("DeviceID").ToString();
                reader.PNPDeviceID  = device.GetPropertyValue("PNPDeviceID").ToString();
                reader.Description  = device.GetPropertyValue("Description").ToString();
                reader.Manufacturer = device.GetPropertyValue("Manufacturer").ToString();
                reader.Model        = device.GetPropertyValue("Model").ToString();

                foreach (ManagementObject partition in device.GetRelated("Win32_DiskPartition"))
                {
                    reader.Name = partition.GetPropertyValue("Name").ToString();

                    foreach (ManagementObject logical in partition.GetRelated("Win32_LogicalDisk"))
                    {
                        reader.LogicalDisk = logical.GetPropertyValue("Name").ToString();
                    }
                }
                if (reader.Model == Kindle)
                {
                    devices.Add(reader);
                }
            }

            collection.Dispose();
            return(devices);
        }