示例#1
0
 public async void WatchfulWatcher()
 {
     await Task.Run(() =>
     {
         DataMan.Watcher = new FileSystemWatcher(DownMan.AppData());
         DataMan.Watcher.BeginInit();
         DataMan.Watcher.EnableRaisingEvents = true;
         DataMan.Watcher.NotifyFilter        = NotifyFilters.LastWrite;
         DataMan.Watcher.Filter   = "*.xml";
         DataMan.Watcher.Changed += FileSystemWatcher_Changed;
         DataMan.Watcher.EndInit();
     });
 }
示例#2
0
 private void DeleteButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         var book = (BookModel)DataContext;
         DataMan.DeleteBook(book);
         File.Delete(Path.Combine(DownMan.AppData(), book.DocPath));
         File.Delete(Path.Combine(DownMan.AppData(), book.ImageUrl));
         ((WrapPanel)this.Parent).Children.Remove(this);
     }
     catch (Exception e3)
     {
         MessageBox.Show("Error | " + e3.Message);
     }
 }
示例#3
0
        private void OpenButton_Click(object sender, RoutedEventArgs e)
        {
            if (!File.Exists(Path.Combine(DownMan.AppData(), "sumatra.exe")))
            {
                var zip = Ionic.Zip.ZipFile.Read(Path.Combine(DownMan.AppData(), "sumatra.zip"));
                zip.ExtractAll(DownMan.AppData());
            }

            if (!File.Exists(((BookModel)DataContext).DocPath))
            {
                MessageBox.Show("Error: No File");
                return;
            }

            Process.Start(Path.Combine(DownMan.AppData(), "sumatra.exe"), Path.Combine(DownMan.AppData(), ((BookModel)DataContext).DocPath));
        }
示例#4
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // if app is runnnig but user adds new book


            //var inu = "bluereader://https://bayanbox.ir/download/1304514819017851126/A-Confederate-General-From-Big-Sur-Richard-Brautigan.epub|http://bayanbox.ir/view/7398172316998520139/a-confederate-general-richrad-brautigan.jpg|Richard Brautiagn a condeferate genrakl from big sur";
            if (e.Args.Length > 0)
            //if (true)
            {
                var call = WebUtility.UrlDecode(e.Args[0]);
                //var call = WebUtility.UrlDecode(inu);
                var data = call.ToLower().Replace("bluereader://", "").Split(new[] { '|' });
                if (data.Length < 2 || data[0] == null || data[1] == null || data[2] == null)
                {
                    System.Windows.MessageBox.Show("Error | Link is broken");
                    Current.Shutdown();
                    return;
                }

                if (!IsValidLink(data[0]) || !IsValidLink(data[1]))
                {
                    System.Windows.MessageBox.Show("Error | Link is invalid");
                    Current.Shutdown();
                    return;
                }

                var pg = new ProgressWindow();
                pg.Show();
                Thread th = new Thread(new ThreadStart(() =>
                {
                }));
                th.Start();
                var task = Task.Factory.StartNew(() =>
                {
                    try
                    {
                        var docPath = DownMan.Download(data[0], DownMan.FileType.File);
                        var imgPath = DownMan.Download(data[1], DownMan.FileType.Image);

                        var config = DataMan.GetConfigFile();
                        DataMan.AddNewBook(new BookModel()
                        {
                            Id       = (config.Books?.Count + 1) ?? 0,
                            Title    = data[2],
                            ImageUrl = imgPath,
                            DocPath  = docPath
                        });

                        Dispatcher.Invoke(() =>
                        {
                            Process p = Process.GetCurrentProcess();
                            int c     = Process.GetProcesses().Where(x => x.ProcessName == p.ProcessName).Count();
                            if (c > 1)
                            {
                                Current.Shutdown();
                            }

                            var mw = new MainWindow();
                            pg.Close();
                            mw.ShowDialog();
                        });
                    }
                    catch (Exception ee)
                    {
                        Dispatcher.Invoke(() =>
                        {
                            MessageBox.Show("Error. please try again | " + ee.Message);
                            Current.Shutdown();
                        });
                    }
                });
            }
            else
            {
                Process p = Process.GetCurrentProcess();
                int     c = Process.GetProcesses().Where(x => x.ProcessName == p.ProcessName).Count();
                if (c > 1)
                {
                    MessageBox.Show("an instance is running...");
                    Current.Shutdown();
                }
                var mw = new MainWindow();
                mw.ShowDialog();
            }
        }