コード例 #1
0
    public void Init()
    {
        //读取自带的版本号
        LoadInnerVersion();

        //读取SD卡的版本
        byte[] data = RuntimeInfo.GetLocalFile(RuntimeInfo.GetVersionFileName());
        if (data == null || data.Length != ResManager.RES_NUM * 4 + 4)
        {
            return;
        }
        uint crc = Crc.Crc32(data, 4, data.Length - 4);

        if (crc != System.BitConverter.ToUInt32(data, 0))
        {
            return;
        }

        for (int i = 0, idx = 4; i < ResManager.RES_NUM; ++i, idx += 4)
        {
            uint     resCrc = System.BitConverter.ToUInt32(data, idx);
            string   path   = RuntimeInfo.GetResPersistentPath((ResType)i);
            FileInfo fi     = new FileInfo(path);
            if (!fi.Exists)
            {
                continue;
            }
            m_ResVer[i].ResSize = (uint)fi.Length;
            m_ResVer[i].ResCrc  = resCrc;
        }
        m_bHasVerFile = true;
    }
コード例 #2
0
    public bool BeginLoadRes(ResType dir, bool bManager)
    {
//#if UNITY_EDITOR
        if (ENABLE_RESOURCES)
        {
            return(true);
        }
//#endif
        m_bLoadedRes = true;
        int idx = (int)dir;

        if (m_AssetList[idx] != null)
        {
            return(true);
        }

        m_AssetManager[idx] = bManager;

        string path;

        path = RuntimeInfo.GetResPersistentPath(dir);
#if UNITY_EDITOR
        if (!File.Exists(path))
        {
            return(true);
        }
#endif
        //从资源包里加载文件  @magiii
        m_AssetList[idx] = AssetBundle.LoadFromFile(path);
        if (m_AssetList[idx] == null)
        {
            LogMgr.Log("Asset not found:" + path + "exists:" + File.Exists(path));
#if UNITY_EDITOR
            return(true);
#endif
        }
        if (m_AssetList[idx] != null)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
コード例 #3
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;
    }
コード例 #4
0
    bool SaveRes(MultiFileOK dd)
    {
        //验证crc
        DownResData drd = dd.Drd;

        if (drd.ResSize != dd.Data.Length)
        {
            LogMgr.Log("Res:" + drd.ResType + " 大小不匹配,localSize:" + dd.Data.Length + ", serverSize:" + drd.ResSize);
            return(false);
        }
        uint crc = Crc.Crc32(dd.Data, 0, dd.Data.Length);

        if (crc != drd.ResCrc)
        {
            LogMgr.Log("Res:" + drd.ResType + "资源检验失败, size:" + dd.Data.Length + ", localCrc:" + crc + ", serverCrc:" + drd.ResCrc);
            return(false);
        }

        System.Random rr       = new System.Random();
        int           name     = rr.Next(100, 10000);
        string        tempFile = RuntimeInfo.GetLocalPath(drd.ResType + name.ToString() + "_temp.dat");
        string        path     = RuntimeInfo.GetResPersistentPath(drd.ResType);

        try
        {
            File.Delete(tempFile);
        }
        catch
        {
        }
        try
        {
            File.Delete(path);
        }
        catch
        {
        }
        try
        {
            FileStream fsTemp = File.Create(tempFile);
            if (fsTemp == null)
            {
                LogMgr.Log("RES文件创建失败:" + drd.ResType);
                return(false);
            }
            //解压
            fsTemp.Write(dd.Data, 0, dd.Data.Length);
            fsTemp.Flush();
            fsTemp.Close();
            fsTemp = null;
            LZMA.DecompressFile(tempFile, path);
        }
        catch (System.Exception e)
        {
            ReportException.Instance.AddException("文件解压失败:" + e.ToString());
        }
        try
        {
            File.Delete(tempFile);
        }
        catch
        {
        }
        if (File.Exists(path) == false)
        {
            LogMgr.Log("RES文件解压失败:" + drd.ResType);
            return(false);
        }
        ResManager.Instance.VersionMgr.SetResVersion(drd.ResType, drd.ResCrc, drd.ResUnzipSize);
        return(ResManager.Instance.VersionMgr.SaveVersion());
    }
コード例 #5
0
 string GetClientPath()
 {
     return(RuntimeInfo.GetResPersistentPath(ResType.MAX));
 }