简体   繁体   English

使用DotNetZip 1.9无法将其读取为zip文件

[英]Cannot read that as a zip file using DotNetZip 1.9

I am working on an application that will download a .zip file from my server and extract it when the download is complete using DotNetZip 1.9 我正在使用一个应用程序,它将从服务器上下载.zip文件并在使用DotNetZip 1.9下载完成后将其解压缩。

The application is downloading the zip file properly, but when it gets to the section to read the .zip file it throws the exception "Cannot read that as a zip file" (full exception at http://pastebin.com/NTrtMgR9 ). 该应用程序正在正确下载zip文件,但是当它进入读取.zip文件的部分时,将引发异常“无法将其作为zip文件读取”(位于http://pastebin.com/NTrtMgR9的完整异常)。

What throws me off, is even tho it is throwing an exception, the file is still unzipped properly... 是什么让我失望,甚至引发异常,文件仍正确解压缩...

Here is my source: 这是我的资料来源:

private void btnDownload_Click(object sender, EventArgs e)
{
    if (!Directory.Exists(HardCorpsPath))
    {
        //MessageBox.Show("Downloading HardCorps Mod Pack (Full)", "Downloading", MessageBoxButtons.OK, MessageBoxIcon.Information);
        zipFileName = "HardCorps";

        HCDownloadURL = String.Format("http://www.survivaloperations.net/client/hardcorps/{0}.zip", zipFileName);
        HCZipPath = Path.Combine(Arma2OAPath, @"HardCorps.zip");

        WebClient Download_Client = new WebClient();//Declaring the webclient as Download_Client
        Download_Client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);//the event handler
        Download_Client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);// " "
        Download_Client.DownloadFileAsync(new Uri(HCDownloadURL.Trim().ToString()), HCZipPath);// " "

        //extract 
        using (var zipFile = ZipFile.Read(HCZipPath))
        {
            zipFile.ExtractAll(Arma2OAPath, ExtractExistingFileAction.OverwriteSilently);
        }
    }
    else
    {
        MessageBox.Show("Directory Validated!");
        //Read users HardCorpsPath\version.txt and compare to server version.txt
        //if server version > user version, download patch.zip where "patch" == the number version of the server's version.txt (ex: 1001.zip)
        //On download complete, extract to HardCorpsPath and overwrite silently
    }
}//close Download Button

and my ProgressChanged/Completed methods: 和我的ProgressChanged / Completed方法:

private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
    pbDownloader.Value = e.ProgressPercentage;//setting the progressbar value as downloadprogress
}

private void Completed(object sender, AsyncCompletedEventArgs e)
{
    using (var zipFile = ZipFile.Read(String.Format(HCZipPath)))
    {
        zipFile.ExtractAll(Arma2OAPath, ExtractExistingFileAction.OverwriteSilently);
    }

    MessageBox.Show("Downloading Successful ", "Download_Completed", MessageBoxButtons.OK, MessageBoxIcon.Information);//just a messagebox          
    pbDownloader.Value = (0);//resetting the progressbar  
}

HCZipPath is a string variable (if that makes any difference) HCZipPath是一个字符串变量(如果有任何区别)

In your btnDownload_Click method, you are trying to extract the file before it has been downloaded. btnDownload_Click方法中,您尝试在下载文件之前提取文件。 You call Download_Client.DownloadFileAsync which starts the download, and you've correctly set up the handler for the DownloadFileCompleted event where you try to do the extraction (again). 您调用Download_Client.DownloadFileAsync开始下载,并且您已经正确设置了DownloadFileCompleted事件的处理程序(尝试再次进行提取)。 Take out the code below the DownloadFileAsync method call (to prevent the exception). 取出DownloadFileAsync方法调用下面的代码(以防止发生异常)。 You file is being extracted because you extract it in the Completed method (which is the correct way to do it). 正在提取文件,因为您是使用Completed方法(这是正确的方法)提取文件的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM