Esempio n. 1
0
        private void Download_Click(object sender, RoutedEventArgs e)
        {
            if (currentBtn == null)
            {
                return;
            }
            String dir = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "PacChat/Downloads");

            Directory.CreateDirectory(dir);
            String savePath = System.IO.Path.Combine(dir, currentBtn.FileName);

            //if (!MainWindow.Instance.DownloadWindow.Visible)
            //{
            //    MainWindow.Instance.DownloadWindow.ShowPopUp();
            //}
            var downloadWindow = DownloadWindow.Instance;

            if (downloadWindow.IsDownloading(currentBtn.FileID))
            {
                return;
            }

            DownloadProgressNoti noti = new DownloadProgressNoti();

            noti.FileLocation = FileAPI.RepairSavePath(savePath);
            noti.SetFileName(System.IO.Path.GetFileName(noti.FileLocation));
            noti.FileID = currentBtn.FileID;

            downloadWindow.DownloadList.Children.Insert(0, noti);
            MainWindow.chatApplication.model.DownloadProgresses.Add(noti);

            FileAPI.DownloadMedia(currentBtn.StreamURL, savePath,
                                  noti.SetProgress, noti.FinalizeDownload, null);
        }
Esempio n. 2
0
        private void AttachmentLink_Click(object sender, RoutedEventArgs e)
        {
            var            app    = MainWindow.chatApplication;
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.Title            = "Select a place to download";
            dialog.Filter           = "All file types|*.*";
            dialog.FileName         = textBlock.Text;
            dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            if (dialog.ShowDialog() == true)
            {
                //if (!MainWindow.Instance.DownloadWindow.Visible)
                //{
                //    MainWindow.Instance.DownloadWindow.ShowPopUp();
                //}
                String fileID         = AttachmentLink.Tag as String;
                var    downloadWindow = DownloadWindow.Instance;

                if (downloadWindow.IsDownloading(fileID))
                {
                    return;
                }

                DownloadProgressNoti noti = new DownloadProgressNoti();
                noti.SetFileName(System.IO.Path.GetFileName(dialog.FileName));
                noti.FileLocation = dialog.FileName;
                noti.FileID       = fileID;

                downloadWindow.DownloadList.Children.Insert(0, noti);
                MainWindow.chatApplication.model.DownloadProgresses.Add(noti);

                FileAPI.DownloadAttachment(app.model.currentSelectedConversation,
                                           noti.FileID, dialog.FileName,
                                           noti.SetProgress, noti.FinalizeDownload, OnDownloadFileError);
            }
        }