Beispiel #1
0
 private void FileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
 {
     //Thread.Sleep(2000);
     DataMan.GetConfigFile();
     Dispatcher.Invoke(() =>
     {
         UpdateUI();
         Activate();
     });
 }
Beispiel #2
0
        public MainWindow()
        {
            InitializeComponent();

            //Task.Factory.StartNew(() =>
            //{
            //    _ = DataMan.GetConfigFile();
            //    Dispatcher.Invoke(UpdateUI);
            //});
            _ = DataMan.GetConfigFile();
            UpdateUI();
            WatchfulWatcher();
        }
Beispiel #3
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);
     }
 }
Beispiel #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();
            }
        }