Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Using Zip Compression with the Unity 3D web player (Windows)

Discussion in 'Editor & General Support' started by dylan.ryan, Dec 6, 2012.

  1. dylan.ryan

    dylan.ryan

    Joined:
    Oct 15, 2012
    Posts:
    29
    Hello,
    I have currently tried two compression libraries for unzipping files(DotNetZip and SharpZipLib), but neither of them seem to work on the webplayer when running in windows. I am unzipping the files to memory, but both zip libraries give me a text encoding/decoding error. I have researched the problem on the web, and the various answers for copying dlls around are not working in the webplayer. All of the other platforms I have tested work just fine(OSX Standalone, Iphone, Android).

    Does anyone have any experience working with a zip library in the webplayer?

    Thank you,
    Dylan
     
  2. dylan.ryan

    dylan.ryan

    Joined:
    Oct 15, 2012
    Posts:
    29
    After trying a bunch of suggestions I found on the web, I finally decided to edit the SharpZipLib library myself, and was able to fix the problem. I am posting the steps below:

    Steps to fix unzipping errors on the web player(related to text decoding):

    • Download the SharpZipLib source from: http://www.icsharpcode.net/opensource/sharpziplib/
    • Open the main project (ICSharpCode.SharpZLib.csproj) under the /src directory in monodevelop
    • Navigate to the file ZipConstants.cs (Under the zip folder)
    • Replace the functions that use System.Text.Encoding.GetEncoding() with Encoding.UTF8.

    Example:
    replace
    Encoding.GetEncoding(defaultCodePage).GetString(da ta, 0, count);
    with:
    Encoding.UTF8.GetString(data, 0, count);

    Compile your new library(it should compile with no errors)
    and then drop it in your unity Plugins folder.

    So far I have tested this on OSX, Webplayer(windows and OSx), Android and IOS. For this to work correctly you will need to make absolute sure that the zips you are unzipping are encoded in utf8(which i believe is the default).


    Hopefully this helps someone out.

    -Dylan
     
  3. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    983
    Yep this works very well.
     
  4. solmyr-fr

    solmyr-fr

    Joined:
    Jun 18, 2009
    Posts:
    24
    Yes Dylan, it was very helpful ! Thanks a lot :D ! (and I confirm that zip compression with SharpZipLib work in the editor but not in the webplayer with unity 4 unless you do as Dylan instructed).
    Now I can zip several screenshots of my unity application and upload them in a single zip file on a webserver :) !