Exemplo n.º 1
0
    public System.Collections.IEnumerator UnzipProcess(object obj)
    {
        float step = 0.5f / ResManager.RES_NUM;

        for (int i = 0; i < ResManager.RES_NUM; ++i)
        {
            ResType rt           = (ResType)i;
            string  path         = RuntimeInfo.GetResStreamingPath(rt);
            string  destPath     = RuntimeInfo.GetResPersistentPath(rt);
            string  destPathTemp = destPath + ".temp";
            WWW     www          = new WWW(path);
            while (www.isDone == false)
            {
                yield return(new WaitForEndOfFrame());
            }
            if (www.bytes == null || www.bytes.Length == 0)
            {
                m_Error = "资源解压失败:" + path;
                LogMgr.Log("解压失败,未找到文件:" + www.error + ", Path:" + path);
                yield break;
            }
            try
            {
                FileInfo fi = new FileInfo(destPathTemp);
                if (fi.Exists)
                {
                    fi.Delete();
                }
                FileStream fss = fi.Create();
                fss.Write(www.bytes, 0, www.bytes.Length);
                fss.Flush();
                fss.Close();
                LZMA.DecompressFile(destPathTemp, destPath);
                if (fi.Exists)
                {
                    fi.Delete();
                }
                m_Progress += step;
            }
            catch (System.Exception e)
            {
                m_Error = "资源解压失败:" + path;
                ReportException.Instance.AddException("Exception:解压文件失败: " + e.ToString());
                yield break;
            }
            yield return(new WaitForEndOfFrame());

            try
            {
                m_ResVer[i].ResCrc = Crc.Crc32FromFile(destPathTemp);
                FileInfo ff = new FileInfo(destPath);
                m_ResVer[i].ResSize = (uint)ff.Length;
                m_Progress         += step;
            }
            catch (System.Exception e)
            {
                m_Error = "计算CRC失败:" + path;
                ReportException.Instance.AddException("Exception:计算文件CRC失败: " + e.ToString());
                yield break;
            }
            File.Delete(destPathTemp);
            yield return(new WaitForEndOfFrame());
        }
        m_bHasVerFile = true;
        m_Progress    = 1.0f;
        if (!SaveVersion())
        {
            ReportException.Instance.AddException("Exception:保存版本文件失败:");
        }
        yield break;
    }