private void Window_Loaded(object sender, RoutedEventArgs e) { trayIcon = new System.Windows.Forms.NotifyIcon(); trayIcon.Text = App.appName; trayIcon.Icon = Properties.Resources.favicon; trayIcon.BalloonTipClosed += TrayIcon_BalloonTipClosed; trayIcon.BalloonTipClicked += TrayIcon_BalloonTipClicked; timer.Tick += new EventHandler(Timer_Tick); timer.Interval = new TimeSpan(0, 0, 1); //1 sekunda timer.Start(); settings = settings.Load(); settings.Save(); Lang.SetLanguage(settings.Language); LinksStorage links = new LinksStorage(); links = links.Load(); foreach (Link link in links.List) { DownloadClient item = new DownloadClient(link.Url, link.Directory, link.TotalBytes, link.FileName); item.OnDownloadInit += Client_OnDownloadInit; item.OnDownloadCompleted += Client_OnDownloadCompleted; item.OnDownloadError += Client_OnDownloadError; item.OnDownloadStateChanged += Client_OnDownloadStateChanged; item.SpeedLimit = link.SpeedLimit; item.Refresh(); item.LoadIcon(); listView.Items.Add(item); } }
private void Window_Closing(object sender, CancelEventArgs e) { if (DownloadClient.ActiveCount > 0) { if (MessageBox.Show( Lang.Translate("lang_active_download"), Lang.Translate("lang_confirm"), MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) { e.Cancel = true; return; } } LinksStorage links = new LinksStorage(); foreach (DownloadClient item in listView.Items) { Link link = new Link(); link.Directory = item.Directory; link.FileName = item.FileName; link.Url = item.Url; link.TotalBytes = item.TotalBytes; link.SpeedLimit = item.SpeedLimit; links.List.Add(link); } links.Save(); trayIcon.Dispose(); System.Environment.Exit(1); }
/// <summary> /// Načte seznam odkazů /// </summary> /// <returns>Vrátí instanci objektu typu <see cref="LinksStorage"/></returns> public LinksStorage Load() { LinksStorage linksStorage = this; try { using (StreamReader sr = new StreamReader(path)) { XmlSerializer xmls = new XmlSerializer(typeof(LinksStorage)); linksStorage = xmls.Deserialize(sr) as LinksStorage; } } catch (FileNotFoundException ex) { Console.WriteLine(ex.Message); } catch (UnauthorizedAccessException ex) { Console.WriteLine(ex.Message); } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } catch (IOException ex) { Console.WriteLine(ex.Message); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(linksStorage); }