-1

I have a problem with the ".zip" file download. I want to make a game launcher and I need to add the game download and install feature. When I download the packed game with ZipFile.DownloadFile from the server it gets corrupted.

This is the code:

using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;

// Installation folder will be set in the folder browse dialog
string installationFolder;

// I don't want to show the download url but its in Mediafire 
// and I tried to download it from Google Drive
string remoteUri = "the .zip file url";
string fileName = "gamename.zip", myStringWebResource = null;

// Create a new WebClient instance.
WebClient myWebClient = new WebClient();

// Concatenate the domain with the Web resource filename.
myStringWebResource = remoteUri + fileName;

// Download the Web resource and save it into the current filesystem folder.
myWebClient.DownloadFile(remoteUri, Application.StartupPath + "/gamesdownload/" + fileName);

ZipFile.ExtractToDirectory(Application.StartupPath + "/gamesdownload/gamename.zip", installationFolder);

What is wrong with the code?

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
Marakusa
  • 54
  • 6
  • 1
    Removed Visual Studio 2017 tag – ProgrammingLlama Mar 31 '18 at 05:24
  • 2
    "but its in Mediafire" - what happens if you take the link to the zip file and open it in an incognito/private browsing session? I suspect you're actually downloading a redirect page intended for humans. If this isn't the case, then you should use a tool like `VBinDiff` to compare the expected zip file to the downloaded zip file. – ProgrammingLlama Mar 31 '18 at 05:25
  • 2
    can u share the link so that we can see if it works ? – Software Dev Mar 31 '18 at 05:28
  • It works fine if I download it myself, but if I download it with `ZipFile.DownloadFile` code it corrupts the file. – Marakusa Mar 31 '18 at 05:35
  • 1
    OK, can we get an [mcve] – ProgrammingLlama Mar 31 '18 at 05:37
  • Can I have a code that downloads a zip file without corrupting it? – Marakusa Mar 31 '18 at 05:45
  • Or what is the problem? – Marakusa Mar 31 '18 at 05:46
  • 1
    @Marakusa can't you try to download another zip, that perhaps is less sensitive to you and you may be willing to share with us? – Francesco B. Mar 31 '18 at 05:47
  • Ok there you go. Working zip: https://drive.google.com/open?id=1AwH0yI56OU_sarWsy5RPlaGTUkwYqTMm And corrupted: https://drive.google.com/open?id=1uykT10coYRWSqhym1SZaLEHViYlbmad3 – Marakusa Mar 31 '18 at 05:52
  • The "corrupted" zip file is actually an HTML file. – ProgrammingLlama Mar 31 '18 at 05:55
  • I renamed it from .zip to .html and opened it: https://i.imgur.com/72dWrEx.png – ProgrammingLlama Mar 31 '18 at 05:57
  • Umm... ok, so the problem is in the code? – Marakusa Mar 31 '18 at 05:57
  • The problem is either that `remoteUri` doesn't contain the full zipfile URL, or more likely, mediafire redirects the browser to a page before allowing you to download the file. As I originally commented. – ProgrammingLlama Mar 31 '18 at 05:58
  • So what should I use? – Marakusa Mar 31 '18 at 06:00
  • 1
    I suggest you get the file manually (using for example Chrome) and look at the network traffic (use the F12 dev tools). You need to find that one URL that gets you the file. Then do the same thing with your program; you can inspect the traffic with [Fiddler](https://www.telerik.com/fiddler). Compare the two requests and account for any differences between them. My guess is that the request for the ZIP file requires you send along some cookies or other data or else you get the HTML file instead. – John Wu Mar 31 '18 at 06:01

1 Answers1

0

Found the answer! I changed from Mediafire to GitHub! And this is the solution for the error that comes: The request was aborted: Could not create SSL/TLS secure channel

Marakusa
  • 54
  • 6