BF2Statistics.ProgramUpdater.DownloadUpdateAsync C# (CSharp) Method

DownloadUpdateAsync() public static method

Downloads the new update from Github Async.
public static DownloadUpdateAsync ( ) : bool
return bool
        public static bool DownloadUpdateAsync()
        {
            // Returns if there is no update
            if (!UpdateAvailable)
                return false;

            // Simulate some headers, Github throws a fit otherwise
            Web = new WebClient();
            Web.Headers["User-Agent"] = "BF2Statistics Control Center v" + Program.Version;
            Web.Headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
            Web.Headers["Accept-Language"] = "en-US,en;q=0.8";
            Web.Proxy = null; // Disable proxy because this can cause slowdown on some machines

            // Github file location
            string Download = "https://github.com/BF2Statistics/ControlCenter/releases/download/{0}/BF2Statistics_ControlCenter_{0}.zip";
            Uri FileLocation = new Uri(String.Format(Download, NewVersion));

            // Path to the Downloaded file
            UpdateFileLocation = Path.Combine(Paths.DocumentsFolder, String.Format("BF2Statistics_ControlCenter_{0}.zip", NewVersion));

            // Show Task Form
            IsDownloading = true;
            TaskForm.Cancelled += TaskForm_Cancelled;
            TaskForm.Show(MainForm.Instance, "Downloading Update", "Downloading Update... Please Standby", true);
            TaskForm.Progress.Report(new TaskProgressUpdate("Preparing the download..."));

            try
            {
                // Download the new version Zip file
                Web.DownloadProgressChanged += Wc_DownloadProgressChanged;
                Web.DownloadFileCompleted += Wc_DownloadFileCompleted;
                Web.DownloadFileAsync(FileLocation, UpdateFileLocation);
            }
            catch (Exception ex)
            {
                // Close that task form if its open!
                if (TaskForm.IsOpen)
                    TaskForm.CloseForm();

                // Create Exception Log
                Program.ErrorLog.Write("WARNING: Unable to Download new update archive :: Generating Exception Log");
                ExceptionHandler.GenerateExceptionLog(ex);

                // Alert User
                MessageBox.Show(
                    "Failed to download update archive! Reason: " + ex.Message
                    + Environment.NewLine.Repeat(1)
                    + "An exception log has been generated and created inside the My Documents/BF2Statistics folder.",
                    "Download Failed",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                );

                return false;
            }

            // Tell the mainform that we have this handled
            return true;
        }