Search Unity

Use a zipped xml file

Discussion in 'Scripting' started by MatOfLink, Aug 19, 2009.

  1. MatOfLink

    MatOfLink

    Joined:
    Jun 22, 2009
    Posts:
    31
    Hi everyone,

    I have a config file in xml which is zipped.
    And I would like to unzip it and use its content in javascript at runtime.

    Could anyone show me the way to do that ?

    Thanks
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    unless you implement one or find assemblies / a programmer that does, there isn't one.
     
  3. MatOfLink

    MatOfLink

    Joined:
    Jun 22, 2009
    Posts:
    31
    Ok thank you, and what about in C# ?
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That doesn't make any difference.

    --Eric
     
  5. twintower31

    twintower31

    Joined:
    Oct 31, 2007
    Posts:
    89
    Hello, Bonjour !

    I implemented such a solution.
    I used the library provided in Unity called ICSharpCode.SharpZipLib.dll.
    You can find lot of samples on the net, it's not a Unity library.
    Copy the dll into your assets directory and the clause using ICSharpCode.SharpZipLib.Zip;



    Code (csharp):
    1.  
    2.     void unzip()
    3.     {
    4.         try
    5.         {
    6.        
    7.         string strRealzip = "myzip.zip";
    8.  
    9.         ICSharpCode.SharpZipLib.Zip.ZipInputStream s = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(strRealzip));
    10.          
    11.         ZipEntry theEntry;
    12.  
    13.             //loop on all the files in the zip file
    14.             while ((theEntry = s.GetNextEntry()) != null)
    15.             {
    16.                
    17.                 string strFileName = Path.GetFileName(theEntry.Name);
    18.            
    19.                 if (strFileName != string.Empty)
    20.                 {
    21.                     using (FileStream streamWriter = File.Create(strFileName))
    22.                     {
    23.                         int size = 2048;
    24.                         byte[] data = new byte[2048];
    25.                         while (true)
    26.                         {
    27.                             size = s.Read(data, 0, data.Length);
    28.                             if (size > 0)
    29.                             {
    30.                                 streamWriter.Write(data, 0, size);
    31.                             }
    32.                             else
    33.                             {
    34.                                 break;
    35.                             }
    36.                         }
    37.                     }
    38.                 }
    39.             }//while
    40.  
    41.        
    42.         }
    43.         catch(System.Exception ex)
    44.         {
    45.           Debug.Log("Excep - " + ex.Message);  
    46.         }
    47.     }
    48.  
    49.  
     
  6. MatOfLink

    MatOfLink

    Joined:
    Jun 22, 2009
    Posts:
    31
    I'll try that , thank you.
     
  7. twintower31

    twintower31

    Joined:
    Oct 31, 2007
    Posts:
    89
    Under Windows (it works well under MacOs)
    You can have problem with a codePage exception.
    Add the dlls I18N et I18N.West to your assets.

    Hope it can help