Ejemplo n.º 1
0
        private void btnUpdateSelected_Click(object sender, RoutedEventArgs e)
        {
            if (updateGrid.SelectedItems.Count > 0)
            {
                var selectedUpdate = updateGrid.SelectedItems.Cast <ProgVersion>();
                foreach (ProgVersion updatable in selectedUpdate)
                {
                    if (IsUrlValid(updatable.Url.Trim()))
                    {
                        try
                        {
                            WebDownloadClient download       = new WebDownloadClient(updatable.Url);
                            string            updateablefile = updatable.Name;
                            updateablefile    = updateablefile + ".exe";
                            download.FileName = updateablefile;
                            download.DownloadProgressChanged += download.DownloadProgressChangedHandler;
                            download.DownloadCompleted       += download.DownloadCompletedHandler;
                            download.PropertyChanged         += this.mainWindow.PropertyChangedHandler;
                            download.StatusChanged           += this.mainWindow.StatusChangedHandler;
                            download.DownloadCompleted       += this.mainWindow.DownloadCompletedHandler;

                            if (!Directory.Exists(Settings.Default.DownloadLocation))
                            {
                                Directory.CreateDirectory(Settings.Default.DownloadLocation);
                            }
                            string filePath = Settings.Default.DownloadLocation + download.FileName;
                            string tempPath = filePath + ".tmp";

                            if (File.Exists(tempPath))
                            {
                                string message = "Уже выполняется загрузка по указнному пути.";
                                Xceed.Wpf.Toolkit.MessageBox.Show(message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                                return;
                            }
                            if (File.Exists(filePath))
                            {
                                File.Delete(filePath);
                            }

                            download.CheckUrl();
                            if (download.HasError)
                            {
                                return;
                            }

                            download.TempDownloadPath = tempPath;

                            download.AddedOn              = DateTime.UtcNow;
                            download.CompletedOn          = DateTime.MinValue;
                            download.OpenFileOnCompletion = true;
                            DownloadManager.Instance.DownloadsList.Add(download);

                            download.Start();
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            Xceed.Wpf.Toolkit.MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    else
                    {
                        Xceed.Wpf.Toolkit.MessageBox.Show("Указанный в файле путь загрузки файла обновления недействителен", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void btnDownload_Click(object sender, RoutedEventArgs e)
        {
            if (urlValid)
            {
                if (tbSaveAs.Text.Length < 3 || !tbSaveAs.Text.Contains("."))
                {
                    Xceed.Wpf.Toolkit.MessageBox.Show("The local file name is not valid.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                try
                {
                    WebDownloadClient download = new WebDownloadClient(tbURL.Text.Trim());

                    download.FileName = tbSaveAs.Text.Trim();

                    // Register WebDownloadClient events
                    download.DownloadProgressChanged += download.DownloadProgressChangedHandler;
                    download.DownloadCompleted       += download.DownloadCompletedHandler;
                    download.PropertyChanged         += this.mainWindow.PropertyChangedHandler;
                    download.StatusChanged           += this.mainWindow.StatusChangedHandler;
                    download.DownloadCompleted       += this.mainWindow.DownloadCompletedHandler;

                    // Create path to temporary file
                    if (!Directory.Exists(tbDownloadFolder.Text))
                    {
                        Directory.CreateDirectory(tbDownloadFolder.Text);
                    }
                    string filePath = tbDownloadFolder.Text + download.FileName;
                    string tempPath = filePath + ".tmp";

                    // Check if there is already an ongoing download on that path
                    if (File.Exists(tempPath))
                    {
                        string message = "There is already a download in progress at the specified path.";
                        Xceed.Wpf.Toolkit.MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    // Check if the file already exists
                    if (File.Exists(filePath))
                    {
                        string message = "There is already a file with the same name, do you want to overwrite it? "
                                         + "If not, please change the file name or download folder.";
                        MessageBoxResult result = Xceed.Wpf.Toolkit.MessageBox.Show(message, "File Name Conflict: " + filePath, MessageBoxButton.YesNo, MessageBoxImage.Warning);

                        if (result == MessageBoxResult.Yes)
                        {
                            File.Delete(filePath);
                        }
                        else
                        {
                            return;
                        }
                    }

                    // Set username and password if HTTP authentication is required
                    if (cbLoginToServer.IsChecked.Value && (tbUsername.Text.Trim().Length > 0) && (tbPassword.Password.Trim().Length > 0))
                    {
                        download.ServerLogin = new NetworkCredential(tbUsername.Text.Trim(), tbPassword.Password.Trim());
                    }

                    // Check the URL
                    download.CheckUrl();
                    if (download.HasError)
                    {
                        return;
                    }

                    download.TempDownloadPath = tempPath;

                    download.AddedOn              = DateTime.UtcNow;
                    download.CompletedOn          = DateTime.MinValue;
                    download.OpenFileOnCompletion = this.cbOpenFileOnCompletion.IsChecked.Value;

                    // Add the download to the downloads list
                    DownloadManager.Instance.DownloadsList.Add(download);

                    // Start downloading the file
                    if (startImmediately)
                    {
                        download.Start();
                    }
                    else
                    {
                        download.Status = DownloadStatus.Paused;
                    }

                    // Close the Add New Download window
                    this.Close();
                }
                catch (Exception ex)
                {
                    Xceed.Wpf.Toolkit.MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("The URL is not a valid download link.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 3
0
        private void btnDownload_Click(object sender, RoutedEventArgs e)
        {
            if (urlValid)
            {
                if (tbSaveAs.Text.Length < 3 || !tbSaveAs.Text.Contains("."))
                {
                    Xceed.Wpf.Toolkit.MessageBox.Show("The local file name is not valid.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                try
                {
                    WebDownloadClient download = new WebDownloadClient(tbURL.Text.Trim());

                    download.FileName = tbSaveAs.Text.Trim();

                    // Register WebDownloadClient events
                    download.DownloadProgressChanged += download.DownloadProgressChangedHandler;
                    download.DownloadCompleted += download.DownloadCompletedHandler;
                    download.PropertyChanged += this.mainWindow.PropertyChangedHandler;
                    download.StatusChanged += this.mainWindow.StatusChangedHandler;
                    download.DownloadCompleted += this.mainWindow.DownloadCompletedHandler;

                    // Create path to temporary file
                    if (!Directory.Exists(tbDownloadFolder.Text))
                    {
                        Directory.CreateDirectory(tbDownloadFolder.Text);
                    }
                    string filePath = tbDownloadFolder.Text + download.FileName;
                    string tempPath = filePath + ".tmp";

                    // Check if there is already an ongoing download on that path
                    if (File.Exists(tempPath))
                    {
                        string message = "There is already a download in progress at the specified path.";
                        Xceed.Wpf.Toolkit.MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    // Check if the file already exists
                    if (File.Exists(filePath))
                    {
                        string message = "There is already a file with the same name, do you want to overwrite it? "
                                       + "If not, please change the file name or download folder.";
                        MessageBoxResult result = Xceed.Wpf.Toolkit.MessageBox.Show(message, "File Name Conflict: " + filePath, MessageBoxButton.YesNo, MessageBoxImage.Warning);

                        if (result == MessageBoxResult.Yes)
                        {
                            File.Delete(filePath);
                        }
                        else
                            return;
                    }

                    // Set username and password if HTTP authentication is required
                    if (cbLoginToServer.IsChecked.Value && (tbUsername.Text.Trim().Length > 0) && (tbPassword.Password.Trim().Length > 0))
                    {
                        download.ServerLogin = new NetworkCredential(tbUsername.Text.Trim(), tbPassword.Password.Trim());
                    }

                    // Check the URL
                    download.CheckUrl();
                    if (download.HasError)
                        return;

                    download.TempDownloadPath = tempPath;

                    download.AddedOn = DateTime.UtcNow;
                    download.CompletedOn = DateTime.MinValue;
                    download.OpenFileOnCompletion = this.cbOpenFileOnCompletion.IsChecked.Value;

                    // Add the download to the downloads list
                    DownloadManager.Instance.DownloadsList.Add(download);

                    // Start downloading the file
                    if (startImmediately)
                        download.Start();
                    else
                        download.Status = DownloadStatus.Paused;

                    // Close the Add New Download window
                    this.Close();
                }
                catch (Exception ex)
                {
                    Xceed.Wpf.Toolkit.MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("The URL is not a valid download link.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 4
0
        private void btnDownload_Click(object sender, RoutedEventArgs e)
        {
            if (downloadUrls.Count > 0)
            {
                try
                {
                    foreach (string url in downloadUrls)
                    {
                        WebDownloadClient download = new WebDownloadClient(url);
                        download.IsBatch         = true;
                        download.BatchUrlChecked = false;

                        download.FileName = url.Substring(url.LastIndexOf('/') + 1);

                        // Register WebDownloadClient events
                        download.DownloadProgressChanged += download.DownloadProgressChangedHandler;
                        download.DownloadCompleted       += download.DownloadCompletedHandler;
                        download.PropertyChanged         += this.mainWindow.PropertyChangedHandler;
                        download.StatusChanged           += this.mainWindow.StatusChangedHandler;
                        download.DownloadCompleted       += this.mainWindow.DownloadCompletedHandler;

                        // Create path to temporary file
                        if (!Directory.Exists(tbDownloadFolder.Text))
                        {
                            Directory.CreateDirectory(tbDownloadFolder.Text);
                        }
                        string filePath = tbDownloadFolder.Text + download.FileName;
                        string tempPath = filePath + ".tmp";

                        // Check if there is already an ongoing download on that path
                        if (File.Exists(tempPath))
                        {
                            // If there is, skip adding this download
                            continue;
                        }

                        // Check if the file already exists
                        if (File.Exists(filePath))
                        {
                            string           message = "Такой файл уже существует. Перезаписать?";
                            MessageBoxResult result  = Xceed.Wpf.Toolkit.MessageBox.Show(message, "Конфликт имен файлов: " + filePath, MessageBoxButton.YesNo, MessageBoxImage.Warning);

                            if (result == MessageBoxResult.Yes)
                            {
                                File.Delete(filePath);
                            }
                            else
                            {
                                // Skip adding this download
                                continue;
                            }
                        }

                        // Set username and password if HTTP authentication is required
                        if (cbLoginToServer.IsChecked.Value && (tbUsername.Text.Trim().Length > 0) && (tbPassword.Password.Trim().Length > 0))
                        {
                            download.ServerLogin = new NetworkCredential(tbUsername.Text.Trim(), tbPassword.Password.Trim());
                        }

                        download.TempDownloadPath = tempPath;

                        download.AddedOn     = DateTime.UtcNow;
                        download.CompletedOn = DateTime.MinValue;

                        // Add the download to the downloads list
                        DownloadManager.Instance.DownloadsList.Add(download);

                        // Start downloading the file
                        if (startImmediately)
                        {
                            download.Start();
                        }
                        else
                        {
                            download.Status = DownloadStatus.Paused;
                        }
                    }

                    // Close the Create Batch Download window
                    this.Close();
                }
                catch (Exception ex)
                {
                    Xceed.Wpf.Toolkit.MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("Нет файлов для загрузки!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 5
0
        private void LoadDownloadsFromXml()
        {
            try
            {
                if (File.Exists("Downloads.xml"))
                {
                    // Load downloads from XML file
                    XElement downloads = XElement.Load("Downloads.xml");
                    if (downloads.HasElements)
                    {
                        IEnumerable <XElement> downloadsList =
                            from el in downloads.Elements()
                            select el;
                        foreach (XElement download in downloadsList)
                        {
                            // Create WebDownloadClient object based on XML data
                            WebDownloadClient downloadClient = new WebDownloadClient(download.Element("url").Value);

                            downloadClient.FileName = download.Element("file_name").Value;

                            downloadClient.DownloadProgressChanged += downloadClient.DownloadProgressChangedHandler;
                            downloadClient.DownloadCompleted       += downloadClient.DownloadCompletedHandler;
                            downloadClient.PropertyChanged         += this.PropertyChangedHandler;
                            downloadClient.StatusChanged           += this.StatusChangedHandler;
                            downloadClient.DownloadCompleted       += this.DownloadCompletedHandler;

                            string username = download.Element("username").Value;
                            string password = download.Element("password").Value;
                            if (username != String.Empty && password != String.Empty)
                            {
                                downloadClient.ServerLogin = new NetworkCredential(username, password);
                            }

                            downloadClient.TempDownloadPath = download.Element("temp_path").Value;
                            downloadClient.FileSize         = Convert.ToInt64(download.Element("file_size").Value);
                            downloadClient.DownloadedSize   = Convert.ToInt64(download.Element("downloaded_size").Value);

                            DownloadManager.Instance.DownloadsList.Add(downloadClient);

                            if (download.Element("status").Value == "Completed")
                            {
                                downloadClient.Status = DownloadStatus.Completed;
                            }
                            else
                            {
                                downloadClient.Status = DownloadStatus.Paused;
                            }

                            downloadClient.StatusText = download.Element("status_text").Value;

                            downloadClient.ElapsedTime = TimeSpan.Parse(download.Element("total_time").Value);
                            downloadClient.AddedOn     = DateTime.Parse(download.Element("added_on").Value);
                            downloadClient.CompletedOn = DateTime.Parse(download.Element("completed_on").Value);

                            downloadClient.SupportsRange        = Boolean.Parse(download.Element("supports_resume").Value);
                            downloadClient.HasError             = Boolean.Parse(download.Element("has_error").Value);
                            downloadClient.OpenFileOnCompletion = Boolean.Parse(download.Element("open_file").Value);
                            downloadClient.TempFileCreated      = Boolean.Parse(download.Element("temp_created").Value);
                            downloadClient.IsBatch         = Boolean.Parse(download.Element("is_batch").Value);
                            downloadClient.BatchUrlChecked = Boolean.Parse(download.Element("url_checked").Value);

                            if (downloadClient.Status == DownloadStatus.Paused && !downloadClient.HasError && Settings.Default.StartDownloadsOnStartup)
                            {
                                downloadClient.Start();
                            }
                        }

                        // Create empty XML file
                        XElement  root = new XElement("downloads");
                        XDocument xd   = new XDocument();
                        xd.Add(root);
                        xd.Save("Downloads.xml");
                    }
                }
            }
            catch (Exception)
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("Ошибка при загрузке листа загрузок", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 6
0
        private void btnDownload_Click(object sender, RoutedEventArgs e)
        {
            if (downloadUrls.Count > 0)
            {
                try
                {
                    foreach (string url in downloadUrls)
                    {
                        WebDownloadClient download = new WebDownloadClient(url);
                        download.IsBatch = true;
                        download.BatchUrlChecked = false;

                        download.FileName = url.Substring(url.LastIndexOf('/') + 1);

                        // Register WebDownloadClient events
                        download.DownloadProgressChanged += download.DownloadProgressChangedHandler;
                        download.DownloadCompleted += download.DownloadCompletedHandler;
                        download.PropertyChanged += this.mainWindow.PropertyChangedHandler;
                        download.StatusChanged += this.mainWindow.StatusChangedHandler;
                        download.DownloadCompleted += this.mainWindow.DownloadCompletedHandler;

                        // Create path to temporary file
                        if (!Directory.Exists(tbDownloadFolder.Text))
                        {
                            Directory.CreateDirectory(tbDownloadFolder.Text);
                        }
                        string filePath = tbDownloadFolder.Text + download.FileName;
                        string tempPath = filePath + ".tmp";

                        // Check if there is already an ongoing download on that path
                        if (File.Exists(tempPath))
                        {
                            // If there is, skip adding this download
                            continue;
                        }

                        // Check if the file already exists
                        if (File.Exists(filePath))
                        {
                            string message = "There is already a file with the same name, do you want to overwrite it?";
                            MessageBoxResult result = Xceed.Wpf.Toolkit.MessageBox.Show(message, "File Name Conflict: " + filePath, MessageBoxButton.YesNo, MessageBoxImage.Warning);

                            if (result == MessageBoxResult.Yes)
                            {
                                File.Delete(filePath);
                            }
                            else
                            {
                                // Skip adding this download
                                continue;
                            }
                        }

                        // Set username and password if HTTP authentication is required
                        if (cbLoginToServer.IsChecked.Value && (tbUsername.Text.Trim().Length > 0) && (tbPassword.Password.Trim().Length > 0))
                        {
                            download.ServerLogin = new NetworkCredential(tbUsername.Text.Trim(), tbPassword.Password.Trim());
                        }

                        download.TempDownloadPath = tempPath;

                        download.AddedOn = DateTime.UtcNow;
                        download.CompletedOn = DateTime.MinValue;

                        // Add the download to the downloads list
                        DownloadManager.Instance.DownloadsList.Add(download);

                        // Start downloading the file
                        if (startImmediately)
                            download.Start();
                        else
                            download.Status = DownloadStatus.Paused;
                    }

                    // Close the Create Batch Download window
                    this.Close();
                }
                catch (Exception ex)
                {
                    Xceed.Wpf.Toolkit.MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
                Xceed.Wpf.Toolkit.MessageBox.Show("There are no files to download!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
        }
Ejemplo n.º 7
0
        private void LoadDownloadsFromXml()
        {
            try
            {
                if (File.Exists("Downloads.xml"))
                {
                    // Load downloads from XML file
                    XElement downloads = XElement.Load("Downloads.xml");
                    if (downloads.HasElements)
                    {
                        IEnumerable<XElement> downloadsList =
                            from el in downloads.Elements()
                            select el;
                        foreach (XElement download in downloadsList)
                        {
                            // Create WebDownloadClient object based on XML data
                            WebDownloadClient downloadClient = new WebDownloadClient(download.Element("url").Value);

                            downloadClient.FileName = download.Element("file_name").Value;

                            downloadClient.DownloadProgressChanged += downloadClient.DownloadProgressChangedHandler;
                            downloadClient.DownloadCompleted += downloadClient.DownloadCompletedHandler;
                            downloadClient.PropertyChanged += this.PropertyChangedHandler;
                            downloadClient.StatusChanged += this.StatusChangedHandler;
                            downloadClient.DownloadCompleted += this.DownloadCompletedHandler;

                            string username = download.Element("username").Value;
                            string password = download.Element("password").Value;
                            if (username != String.Empty && password != String.Empty)
                            {
                                downloadClient.ServerLogin = new NetworkCredential(username, password);
                            }

                            downloadClient.TempDownloadPath = download.Element("temp_path").Value;
                            downloadClient.FileSize = Convert.ToInt64(download.Element("file_size").Value);
                            downloadClient.DownloadedSize = Convert.ToInt64(download.Element("downloaded_size").Value);

                            DownloadManager.Instance.DownloadsList.Add(downloadClient);

                            if (download.Element("status").Value == "Completed")
                            {
                                downloadClient.Status = DownloadStatus.Completed;
                            }
                            else
                            {
                                downloadClient.Status = DownloadStatus.Paused;
                            }

                            downloadClient.StatusText = download.Element("status_text").Value;

                            downloadClient.ElapsedTime = TimeSpan.Parse(download.Element("total_time").Value);
                            downloadClient.AddedOn = DateTime.Parse(download.Element("added_on").Value);
                            downloadClient.CompletedOn = DateTime.Parse(download.Element("completed_on").Value);

                            downloadClient.SupportsRange = Boolean.Parse(download.Element("supports_resume").Value);
                            downloadClient.HasError = Boolean.Parse(download.Element("has_error").Value);
                            downloadClient.OpenFileOnCompletion = Boolean.Parse(download.Element("open_file").Value);
                            downloadClient.TempFileCreated = Boolean.Parse(download.Element("temp_created").Value);
                            downloadClient.IsBatch = Boolean.Parse(download.Element("is_batch").Value);
                            downloadClient.BatchUrlChecked = Boolean.Parse(download.Element("url_checked").Value);

                            if (downloadClient.Status == DownloadStatus.Paused && !downloadClient.HasError && Settings.Default.StartDownloadsOnStartup)
                            {
                                downloadClient.Start();
                            }
                        }

                        // Create empty XML file
                        XElement root = new XElement("downloads");
                        XDocument xd = new XDocument();
                        xd.Add(root);
                        xd.Save("Downloads.xml");
                    }
                }
            }
            catch (Exception)
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("There was an error while loading the download list.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 8
0
        private void btnDownload_Click(object sender, RoutedEventArgs e)
        {
            if (urlValid)
            {
                if (tbSaveAs.Text.Length < 3 || !tbSaveAs.Text.Contains("."))
                {
                    Xceed.Wpf.Toolkit.MessageBox.Show("Имя файла неверно.", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                try
                {
                    WebDownloadClient download = new WebDownloadClient(tbURL.Text.Trim());

                    download.FileName = tbSaveAs.Text.Trim();

                    // Register WebDownloadClient events
                    download.DownloadProgressChanged += download.DownloadProgressChangedHandler;
                    download.DownloadCompleted       += download.DownloadCompletedHandler;
                    download.PropertyChanged         += this.mainWindow.PropertyChangedHandler;
                    download.StatusChanged           += this.mainWindow.StatusChangedHandler;
                    download.DownloadCompleted       += this.mainWindow.DownloadCompletedHandler;

                    // Create path to temporary file
                    if (!Directory.Exists(tbDownloadFolder.Text))
                    {
                        Directory.CreateDirectory(tbDownloadFolder.Text);
                    }
                    string filePath = tbDownloadFolder.Text + download.FileName;
                    string tempPath = filePath + ".tmp";

                    // Check if there is already an ongoing download on that path
                    if (File.Exists(tempPath))
                    {
                        string message = "Уже выполняется загрузка по указнному пути.";
                        Xceed.Wpf.Toolkit.MessageBox.Show(message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    // Check if the file already exists
                    if (File.Exists(filePath))
                    {
                        string message = "Файл с таким именем уже сущестует. Перезаписать? "
                                         + "Если нет, пожалуйста измените название файла или путь загрузки.";
                        MessageBoxResult result = Xceed.Wpf.Toolkit.MessageBox.Show(message, "Конфликт имен файлов: " + filePath, MessageBoxButton.YesNo, MessageBoxImage.Warning);

                        if (result == MessageBoxResult.Yes)
                        {
                            File.Delete(filePath);
                        }
                        else
                        {
                            return;
                        }
                    }

                    // Set username and password if HTTP authentication is required
                    if (cbLoginToServer.IsChecked.Value && (tbUsername.Text.Trim().Length > 0) && (tbPassword.Password.Trim().Length > 0))
                    {
                        download.ServerLogin = new NetworkCredential(tbUsername.Text.Trim(), tbPassword.Password.Trim());
                    }

                    // Check the URL
                    download.CheckUrl();
                    if (download.HasError)
                    {
                        return;
                    }

                    download.TempDownloadPath = tempPath;

                    download.AddedOn              = DateTime.UtcNow;
                    download.CompletedOn          = DateTime.MinValue;
                    download.OpenFileOnCompletion = this.cbOpenFileOnCompletion.IsChecked.Value;

                    // Add the download to the downloads list
                    DownloadManager.Instance.DownloadsList.Add(download);

                    // Start downloading the file
                    if (startImmediately)
                    {
                        download.Start();
                    }
                    else
                    {
                        download.Status = DownloadStatus.Paused;
                    }

                    // Close the Add New Download window
                    this.Close();
                }
                catch (Exception ex)
                {
                    Xceed.Wpf.Toolkit.MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("Указанный URL недействителен.", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 9
0
        public void Donwload_and_install(string url, string path)
        {
            if (IsUrlValid(url))
            {
                try
                {
                    WebDownloadClient download       = new WebDownloadClient(url);
                    string            updateablefile = url.Substring(url.LastIndexOf("/") + 1);
                    if (path != null)
                    {
                        download.execpath = @path;
                    }
                    download.FileName = updateablefile;
                    download.DownloadProgressChanged += download.DownloadProgressChangedHandler;
                    download.DownloadCompleted       += download.DownloadCompletedHandler;
                    download.PropertyChanged         += this.mainWindow.PropertyChangedHandler;
                    download.StatusChanged           += this.mainWindow.StatusChangedHandler;
                    download.DownloadCompleted       += this.mainWindow.DownloadCompletedHandler;

                    if (!Directory.Exists(Settings.Default.DownloadLocation))
                    {
                        Directory.CreateDirectory(Settings.Default.DownloadLocation);
                    }
                    string filePath = Settings.Default.DownloadLocation + download.FileName;
                    string tempPath = filePath + ".tmp";

                    if (File.Exists(tempPath))
                    {
                        string message = "Уже выполняется загрузка по указнному пути.";
                        Xceed.Wpf.Toolkit.MessageBox.Show(message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }

                    download.CheckUrl();
                    if (download.HasError)
                    {
                        return;
                    }

                    download.TempDownloadPath = tempPath;

                    download.AddedOn              = DateTime.UtcNow;
                    download.CompletedOn          = DateTime.MinValue;
                    download.OpenFileOnCompletion = true;
                    DownloadManager.Instance.DownloadsList.Add(download);

                    download.Start();
                }
                catch (Exception ex)
                {
                    Xceed.Wpf.Toolkit.MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("Указанный в файле путь загрузки файла обновления недействителен", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 10
0
        void btnDownload_Click(object sender, RoutedEventArgs e)
        {
            if (downloadUrls.Count > 0)
            {
                try
                {
                    foreach (string url in downloadUrls)
                    {
                        var download = new WebDownloadClient(url)
                        {
                            IsBatch         = true,
                            BatchUrlChecked = false,
                            FileName        = url.Substring(url.LastIndexOf('/') + 1)
                        };

                        // Register WebDownloadClient events
                        download.DownloadProgressChanged += download.DownloadProgressChangedHandler;
                        download.DownloadCompleted       += download.DownloadCompletedHandler;
                        download.PropertyChanged         += mainWindow.PropertyChangedHandler;
                        download.StatusChanged           += mainWindow.StatusChangedHandler;
                        download.DownloadCompleted       += mainWindow.DownloadCompletedHandler;

                        // Create path to temporary file
                        if (!Directory.Exists(tbDownloadFolder.Text))
                        {
                            Directory.CreateDirectory(tbDownloadFolder.Text);
                        }
                        string filePath = Path.Combine(tbDownloadFolder.Text, download.FileName);
                        string tempPath = filePath + ".tmp";

                        // Check if there is already an ongoing download on that path
                        if (File.Exists(tempPath))
                        {
                            // If there is, skip adding this download
                            continue;
                        }

                        // Check if the file already exists
                        if (File.Exists(filePath))
                        {
                            string           message = "There is already a file with the same name, do you want to overwrite it?";
                            MessageBoxResult result  = Xceed.Wpf.Toolkit.MessageBox.Show(message, "File Name Conflict: " + filePath, MessageBoxButton.YesNo, MessageBoxImage.Warning);

                            if (result == MessageBoxResult.Yes)
                            {
                                File.Delete(filePath);
                            }
                            else
                            {
                                // Skip adding this download
                                continue;
                            }
                        }

                        // Set username and password if HTTP authentication is required
                        if (cbLoginToServer.IsChecked.Value && (tbUsername.Text.Trim().Length > 0) && (tbPassword.Password.Trim().Length > 0))
                        {
                            download.ServerLogin = new NetworkCredential(tbUsername.Text.Trim(), tbPassword.Password.Trim());
                        }

                        download.TempDownloadPath = tempPath;

                        download.AddedOn     = DateTime.UtcNow;
                        download.CompletedOn = DateTime.MinValue;

                        // Add the download to the downloads list
                        DownloadManager.Instance.DownloadsList.Add(download);

                        // Start downloading the file
                        if (startImmediately)
                        {
                            download.Start();
                        }
                        else
                        {
                            download.Status = DownloadStatus.Paused;
                        }
                    }

                    // Close the Create Batch Download window
                    Close();
                }
                catch (Exception ex)
                {
                    Xceed.Wpf.Toolkit.MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("There are no files to download!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }