Depois de minha pergunta de Criar arquivos Zip e descompactar usando .NET 3.5 eu estou com um problema. É que antes eu conseguia fazer o download de meu arquivo numa release do GitHub, só que depois não funcionava mais.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Net;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using System.IO.Compression;
using System.Reflection;
namespace IEIPInstaller
{
public partial class Main : Form
{
private string temp = Path.Combine(Path.GetTempPath(), "IEIPInst");
private string localProg = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
public Main()
{
if (Directory.Exists(temp))
{
if(File.Exists(temp + "\\IEIPv0.2-alpha-Windows.zip"))
{
File.Delete(temp + "\\IEIPv0.2-alpha-Windows.zip");
}
Directory.Delete(temp);
}
if(File.Exists(localProg + "\\IEIPv0.2-alpha-Windows.zip"))
{
MessageBox.Show("Installer cannot be initialized because you have IEIP with this program.", "IEIPInst", MessageBoxButtons.OK, MessageBoxIcon.Error);
Environment.Exit(0);
}
else
{
InitializeComponent();
Directory.CreateDirectory(temp);
}
}
private void btnNo_Click(object sender, EventArgs e)
{
Directory.Delete(temp, true);
Application.Exit();
}
private void btnYes_Click(object sender, EventArgs e)
{
btnYes.Enabled = false;
btnNo.Enabled = false;
lblWant.Text = "";
Complete.Text = "Status: Connecting...";
startDownload();
}
private void startDownload()
{
WebClient client = new WebClient();
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
client.DownloadFileAsync(new Uri("https://github.com/JPPlaysGamer/IndustriesExes.Inc/releases/download/ieip-pre2/IEIPv0.2-alpha-Windows.zip"), temp + "\\IEIPv0.2-alpha-Windows.zip");
}
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
this.BeginInvoke((MethodInvoker)delegate {
double bytesIn = double.Parse(e.BytesReceived.ToString());
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = bytesIn / totalBytes * 100;
Mbs.Text = (bytesIn / 1024 / 1024).ToString("F2") + " / " + (totalBytes / 1024/ 1024).ToString("F2") + " Mb";
Complete.Text = "Status: Downloading...";
IEIPProgress.Value = int.Parse(Math.Truncate(percentage).ToString());
this.Text = "IEIP Installer - " + IEIPProgress.Value + "%";
});
}
void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
this.BeginInvoke((MethodInvoker)delegate {
if(File.Exists(temp + "\\IEIPv0.2-alpha-Windows.zip"))
{
File.Move(temp + "\\IEIPv0.2-alpha-Windows.zip", localProg + "\\IEIPv0.2-alpha-Windows.zip");
}
Complete.Text = "Status: Completed";
btnNo.Text = "Exit";
btnNo.Enabled = true;
});
}
}
}
Esse é o código de antes e esse é a URL do arquivo:
WebClient client = new WebClient();
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
client.DownloadFileAsync(new Uri("https://github.com/JPPlaysGamer/IndustriesExes.Inc/releases/download/ieip-pre2/IEIPv0.2-alpha-Windows.zip"), temp + "\\IEIPv0.2-alpha-Windows.zip");
Eu troquei DownloadFileAsync para DownloadFile como a função Async tem thread separada da main e recebo esta exceção: System.Net.WebException: A conexão subjacente estava fechada: Erro inesperado em um envio. ---> System.IO.IOException: EOF inesperado ou 0 bytes recebidos do fluxo de transporte.
Eu fiz tudo certo mas agora não funciona mais. Alguém poderia me explicar sobre isso?