1

My program has an Update button that downloads the latest version zip from GitHub.

It worked for many months but now the progress bar no longer updates and it doesn't download a file from the GitHub Release URL.

However, I tested it with a Google Drive URL and it works, but URL naming convention won't be compatible with this project.

Is there a way to get around it with the code, or is does this have something to do with GitHub server rules?

Update Window


Download Handlers

// Progress Changed
//
public void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
    // Progress Bar
    this.Dispatcher.BeginInvoke((Action)(() =>
    {
        double bytesIn = double.Parse(e.BytesReceived.ToString());
        double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
        double percentage = bytesIn / totalBytes * 100;
        this.progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());
    }));
}


// Download Complete
//
public void wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
    // Set the waiter Release
    // Must be here
    this.Dispatcher.BeginInvoke((Action)(() =>
    {
        waiter.Set();
    }));
}

Download Method

In the actual code, the version number is a string that dynamically changes in the URL.

Doesn't Work:
https://github.com/MattMcManis/Glow/releases/download/v0.0.5.4-alpha/Glow.zip

Works:
https://drive.google.com/uc?authuser=0&id=1_7hzLR4FFZXK6qr2sP0uOleeB2GgtghE&export=download

public void StartDownload()
{
    // Start New Thread
    Thread worker = new Thread(() =>
    {
        waiter = new ManualResetEvent(false);

        Uri downloadUrl = new Uri("https://github.com/MattMcManis/Glow/releases/download/v0.0.5.4-alpha/Glow.zip);

        //Async
        wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
        wc.DownloadFileCompleted += new AsyncCompletedEventHandler(wc_DownloadFileCompleted);
        wc.DownloadFileAsync(downloadUrl, tempDir + "Glow.zip");

        // Wait for Download to finish
        waiter.WaitOne();
    });

    // Start Download Thread
    worker.Start();
}
jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
Matt McManis
  • 4,475
  • 5
  • 38
  • 93
  • Where is `wc` defined/initialized? – Ron Beyer Mar 02 '18 at 03:32
  • @RonBeyer in the UpdateWindow Class. At the top, when the Window first opens. `public static WebClient wc = new WebClient();`. After `InitializeComponent()` it runs `StartDownload();`. It all used to work fine until just recently. – Matt McManis Mar 02 '18 at 03:37
  • 1
    It is also possible you are getting an exception during the download causing your thread to terminate. Have you looked at the thread view to see if the thread is still running? – Ron Beyer Mar 02 '18 at 03:37
  • @RonBeyer Exception thrown: "A call to SSPI failed, see inner exception." and "The request was aborted: Could not create SSL/TLS secure channel." – Matt McManis Mar 02 '18 at 03:44
  • @RonBeyer And "Safe handle has been closed." – Matt McManis Mar 02 '18 at 03:45
  • 2
    Try setting the [`ServicePointManager.SecurityProtocol`](https://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.securityprotocol(v=vs.110).aspx), see [this question](https://stackoverflow.com/questions/30491716/how-to-specify-ssl-protocol-to-use-for-webclient-class) – Ron Beyer Mar 02 '18 at 03:54
  • @RonBeyer It works and downloads now, thanks. – Matt McManis Mar 02 '18 at 03:58
  • @RonBeyer I put `ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;` right before Async. – Matt McManis Mar 02 '18 at 04:00

2 Answers2

2

On February 22, 2018 GitHub disabled certain depreciated algorithms. This causes the TLS error that you are encountering.

The fix (as outlined in the comments) is to only allow WebClient to connect using TLS1.2 or higher. To do that, set the ServicePointManager.SecurityProtocol to SecurityProtocolType.Tls12 or higher.

I'm not sure why your progress bar would be showing "half" downloaded before it stopped, this error should pop up immediately when starting to download.

Ron Beyer
  • 11,003
  • 1
  • 19
  • 37
0

you just need to make your URL from github to raw file. Something like this:

https://raw.githubusercontent.com/MattMcManis/Glow/releases/download/v0.0.5.4-alpha/Glow.zip