Exemple #1
0
        public static void DownloadFileAsync(string fileLocation,
                                             DownloadProgressChangedEventHandler downloadHandler,
                                             AsyncCompletedEventHandler downloadCompletedHandler, string programid = null)
        {
            try
            {
                using (ByteGuardWebClient byteguardWebClient = new ByteGuardWebClient())
                {
                    byteguardWebClient.CookieJar = CookieContainer;

                    byteguardWebClient.DownloadProgressChanged += downloadHandler;
                    //byteguardWebClient.DownloadDataCompleted += downloadCompletedHandler;
                    byteguardWebClient.DownloadFileCompleted += downloadCompletedHandler;

                    Uri postUri =
                        new Uri(
                            String.Format("{0}process.php?act=dlprogram&pid={1}",
                                          Variables.ByteGuardHost, programid));

                    lock (LockObject)
                    {
                        byteguardWebClient.DownloadFileAsync(postUri, fileLocation);
                    }
                }
            }
            catch
            {
                Variables.Containers.Main.SetStatus("Failed to download program, please try again shortly.", 1);
            }
        }
Exemple #2
0
        public static void DownloadFileAsync(string fileLocation,
                                             DownloadProgressChangedEventHandler downloadHandler,
                                             AsyncCompletedEventHandler downloadCompletedHandler, string fileName)
        {
            General.IsUpdating = true;

            try
            {
                using (ByteGuardWebClient byteguardWebClient = new ByteGuardWebClient())
                {
                    byteguardWebClient.CookieJar = CookieContainer;

                    byteguardWebClient.DownloadProgressChanged += downloadHandler;
                    byteguardWebClient.DownloadFileCompleted   += downloadCompletedHandler;

                    Uri postUri =
                        new Uri(
                            String.Format("{0}process.php?act=downloadupdate&filename={1}", General.ByteGuardHost, fileName));

                    lock (LockObject)
                    {
                        byteguardWebClient.DownloadFileAsync(postUri, fileLocation);
                    }
                }
            }
            catch
            {
                MessageBox.Show("Failed to download update, please try again shortly.", "Update Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }