I have been working on a WebGL project using Unity 2017. We use ICSharpCode.SharpZipLib.Zip
to generate zip-files and upload them to our server. This worked well using the following code:
public string ZipFiles(List<string> files)
{
// create new zip file
string zipPath = Application.persistentDataPath + "/upload.zip";
try
{
// prepare
FileStream fsOut = File.Create(zipPath);
ZipFile zip = ZipFile.Create(fsOut);
// fill
zip.BeginUpdate();
foreach (string file in files)
{
zip.Add(file, Path.GetFileName(file));
}
Debug.Log("Zip before commit");
zip.CommitUpdate();
Debug.Log("Zip after commit");
zip.Close();
Debug.Log("Zip after close");
fsOut.Close();
Debug.Log("Zip filestream closed");
}
catch (Exception ex)
{
Debug.Log("Exception Zip: " + ex);
}
// finish
return zipPath;
}
Now with the update to Unity 2018.1 we also updated to .Net 4.6 - everything is working fine in Editor.
Using the WebGL build the application fails on zip.CommitUpdate();
Error Log only displays:
NotSupportedException: Encoding 437 data could not be found. Make sure you have correct international codeset assembly installed and enabled.
at System.Text.Encoding.GetEncoding (System.Int32 codepage) [0x00000] in <00000000000000000000000000000000>:0
(Filename: currently not available on il2cpp Line: -1)
I think this a very useless error log...
The zip-file in the file-system gets uploaded, but is empty. Files are available: one xml and two json files. (Already made a check with File.exists
earlier...)
Can anyone help? Thanks!
Finally figured it out!
I cloned the github project SharpZipLib and created the DLL with .Net Standard 2.0 as ClassLibrary. I replaced my existing DLL with the self created DLL.
Then I made little changes to the code: before we were using a FileStream to generate the zip-file. Now we use the ZipFile.Create(string path)
variant.
Also we use a DiskArchiveStorage
refering to the zip-file. ("on disk")
public string ZipFiles(List<string> files)
{
// create new zip file
string zipPath = Application.persistentDataPath + "/upload.zip";
try
{
// prepare
ZipFile zip = ZipFile.Create(zipPath);
// fill
DiskArchiveStorage myDisk = new DiskArchiveStorage(zip);
zip.BeginUpdate(myDisk);
foreach (string file in files)
{
Debug.Log("ZIP: add " + file);
if (!File.Exists(file))
{
Debug.Log("File not found!");
}
zip.Add(file, Path.GetFileName(file));
}
zip.CommitUpdate();
zip.Close();
}
catch (Exception ex)
{
Debug.Log("Exception Zip: " + ex);
}
// finish
return zipPath;
}
Now it is working like before!