Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unity3d Unity 2018.1 WebGL在提交日期使用icsharpcode.sharpziplib失败_Unity3d_C# 4.0_Zip_Unity Webgl_Icsharpcode - Fatal编程技术网

Unity3d Unity 2018.1 WebGL在提交日期使用icsharpcode.sharpziplib失败

Unity3d Unity 2018.1 WebGL在提交日期使用icsharpcode.sharpziplib失败,unity3d,c#-4.0,zip,unity-webgl,icsharpcode,Unity3d,C# 4.0,Zip,Unity Webgl,Icsharpcode,我一直在使用Unity 2017进行WebGL项目。我们使用ICSharpCode.SharpZipLib.Zip生成Zip文件并将其上传到服务器。这在使用以下代码时运行良好: public string ZipFiles(List<string> files) { // create new zip file string zipPath = Application.persistentDataPath + "/upload.zip"; try {

我一直在使用Unity 2017进行WebGL项目。我们使用
ICSharpCode.SharpZipLib.Zip
生成Zip文件并将其上传到服务器。这在使用以下代码时运行良好:

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;
}
我认为这是一个非常无用的错误日志

文件系统中的zip文件已上载,但为空。文件可用:一个xml文件和两个json文件。(已对
文件进行了检查。是否存在
早期版本…)


有人能帮忙吗?谢谢

在.NET 4.6类库中,编码437可能位于嵌入式资源中。默认情况下,WebGL构建不包括用于保存大小的嵌入式资源。您可以如下方式为WebGL启用嵌入式资源:


我不确定这是否是问题所在,但可能值得一试。如果这不起作用,这是一个我们应该从统一方面调查的错误。请提交一份错误报告。

终于解决了

我克隆了并创建了以.Net标准2.0作为类库的DLL。 我用自己创建的DLL替换了现有的DLL

然后我对代码做了一些修改:在我们使用FileStream生成zip文件之前。现在我们使用
ZipFile.Create(字符串路径)
变量。 我们还使用
DiskArchiveStorage
引用zip文件。(“磁盘上”)

公共字符串ZipFiles(列表文件)
{
//创建新的zip文件
字符串zipPath=Application.persistentDataPath+“/upload.zip”;
尝试
{
//预备
ZipFile zip=ZipFile.Create(zipPath);
//填满
DiskArchiveStorage myDisk=新的DiskArchiveStorage(zip);
zip.BeginUpdate(myDisk);
foreach(文件中的字符串文件)
{
Log(“ZIP:add”+文件);
如果(!File.Exists(File))
{
Log(“找不到文件!”);
}
Add(文件,Path.GetFileName(文件));
}
zip.CommitUpdate();
zip.Close();
}
捕获(例外情况除外)
{
Log(“异常Zip:+ex”);
}
//完成
返回zipPath;
}

现在它像以前一样工作

谢谢你的回答!不幸的是,这并没有奏效。。。仍然收到相同的错误,应用程序在
CommitUpdate()
上失败-我尝试在一个干净的项目中使用
ICSharpCode.SharpZipLib.Zip
。它在这里工作。所以我认为这不是一个统一的错误。啊!忘记在播放器设置中设置.Net 4.x。选择.NET4.x后,WebGL也无法使用干净的项目!
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)
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;
}