예제 #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);
                    }
                }
            }
        }
예제 #2
0
        public void Checker()
        {
            if (IsUrlValid(tbServerAddr.Text.Trim()))
            {
                string            version    = null;
                string            url        = null;
                VersionChecker    verChecker = new VersionChecker();
                WebDownloadClient download   = new WebDownloadClient(tbServerAddr.Text.Trim());
                download.CheckUrl();
                if (download.HasError)
                {
                    return;
                }
                try
                {
                    HttpWebRequest  rq       = (HttpWebRequest)WebRequest.Create(tbServerAddr.Text.Trim());
                    HttpWebResponse response = (HttpWebResponse)rq.GetResponse();
                    string          addr     = tbServerAddr.Text.Trim();
                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    {
                        addr = reader.ReadToEnd();
                    }
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(addr);
                    XmlElement xdoc = doc.DocumentElement;
                    foreach (XmlNode node in xdoc)
                    {
                        string name = node.Attributes[0].Value;

                        foreach (XmlNode childnode in node.ChildNodes)
                        {
                            if (childnode.Name == "Version")
                            {
                                version = childnode.InnerText;
                            }
                            if (childnode.Name == "Url")
                            {
                                url = childnode.InnerText;
                            }
                        }
                        upd.Add(new ProgName(name, version, url));
                    }
                }
                catch (Exception ss)
                {
                    string           message = ss.ToString();
                    MessageBoxResult result  = Xceed.Wpf.Toolkit.MessageBox.Show(message, "SecretService");
                }

                string sb1 = null;
                string sb2 = null;

                RegistryKey key;
                key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
                foreach (String keyName in key.GetSubKeyNames())
                {
                    try
                    {
                        sb1 = null;
                        sb2 = null;
                        RegistryKey subkey = key.OpenSubKey(keyName);
                        sb1 = subkey.GetValue("DisplayName") as string;
                        sb2 = subkey.GetValue("DisplayVersion") as string;
                        var outcomeupd = upd.FindIndex(x => string.Equals(x.Name, sb1, StringComparison.CurrentCultureIgnoreCase));
                        if (outcomeupd != -1)
                        {
                            string vers    = upd[outcomeupd].Version;
                            string realurl = upd[outcomeupd].Url;
                            if (verChecker.NewVersionExists(sb2, vers))
                            {
                                if (upd.Exists(x => x.Name == sb1))
                                {
                                    outcome.Add(new ProgVersion(sb1, sb2, vers, realurl));
                                }
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                    catch (Exception ss)
                    {
                        string           message = ss.ToString();
                        MessageBoxResult result  = Xceed.Wpf.Toolkit.MessageBox.Show(message, "SecretService");
                    }
                }

                key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
                foreach (String keyName in key.GetSubKeyNames())
                {
                    try
                    {
                        sb1 = null;
                        sb2 = null;
                        RegistryKey subkey = key.OpenSubKey(keyName);
                        sb1 = subkey.GetValue("DisplayName") as string;
                        sb2 = subkey.GetValue("DisplayVersion") as string;
                        var outcomeupd = upd.FindIndex(x => string.Equals(x.Name, sb1, StringComparison.CurrentCultureIgnoreCase));
                        if (outcomeupd != -1)
                        {
                            string vers    = upd[outcomeupd].Version;
                            string realurl = upd[outcomeupd].Url;
                            if (verChecker.NewVersionExists(sb2, vers))
                            {
                                if (upd.Exists(x => x.Name == sb1))
                                {
                                    outcome.Add(new ProgVersion(sb1, sb2, vers, realurl));
                                }
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                    catch (Exception ss)
                    {
                        string           message = ss.ToString();
                        MessageBoxResult result  = Xceed.Wpf.Toolkit.MessageBox.Show(message, "SecretService");
                    }
                }
            }
            else
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("Указанный URL недействителен.", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #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);
            }
        }
예제 #4
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);
            }
        }
예제 #5
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);
            }
        }
예제 #6
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);
            }
        }