Beispiel #1
0
        public void Begin(Action updateHandle, Action <byte[]> finishHandle, Action failHandle, Action <byte[]> skipHandle)
        {
            m_updateHandle = updateHandle;
            m_finishHandle = finishHandle;
            m_skipHandle   = skipHandle;
            m_failHandle   = failHandle;

            //加载包内VersionData
            TextAsset apkTextAsset = Resources.Load <TextAsset>(FileHelper.CodeVersionFileCrc.ToString());

            if (apkTextAsset != null)
            {
                mApkVersionData = VersionData.LoadVersionData(apkTextAsset.bytes);
            }

            //加载本地VersionData
            string localVersionPath = FileHelper.PersistentPath + FileHelper.CodeVersionFileCrc;

            if (File.Exists(localVersionPath))
            {
                byte[] localData = FileHelper.ReadFile(localVersionPath);
                mLocalVersionData = VersionData.LoadVersionData(localData);
            }

            //下载服务端CodeVersion.bytes
            Httper.instance.Apply(m_path + FileHelper.CodeVersionFileCrc + "?time=" + DateTime.Now.Ticks, OnLoadVersion);
        }
Beispiel #2
0
        public static VersionData LoadVersionData(byte[] data)
        {
            VersionData returnData = new VersionData();

            if (data == null)
            {
                return(returnData);
            }

            MemoryStream ms = new MemoryStream(data);
            BinaryReader br = new BinaryReader(ms);

            returnData.major       = br.ReadByte();
            returnData.minor       = br.ReadByte();
            returnData.revision    = br.ReadInt32();
            returnData.fileListRCR = br.ReadUInt32();
            returnData.initalize   = true;

            br.Close();
            ms.Close();

            return(returnData);
        }
Beispiel #3
0
        //下载服务端Version文件回调
        void OnLoadVersion(byte[] data, object param, bool error)
        {
            //下载Version出错
            if (error)
            {
                Debug.LogError("下载cdn的代码Version:" + FileHelper.CodeVersionFileCrc + "文件出错");
                if (m_failHandle != null)
                {
                    m_failHandle();
                }
            }
            else
            {
                mServerVersionBytes = data;
                mServerVersionData  = VersionData.LoadVersionData(data);
                if (!mServerVersionData.initalize)
                {
                    Debug.LogError("加载cdn的Version:" + FileHelper.CodeVersionFileCrc + "失败");
                    if (m_failHandle != null)
                    {
                        m_failHandle();
                    }
                    return;
                }

                //需要强更客户端
                if (mApkVersionData.initalize && mApkVersionData.major != mServerVersionData.major)
                {
                    ForceUpdateClient();
                    return;
                }

                bool needUpdate = false;

                if (!mApkVersionData.initalize)
                {
                    Debug.LogError("包内VersionData资源不应该为空");
                    return;
                }

                //如果包外资源为空,只检测包内的VersionData
                if (!mLocalVersionData.initalize)
                {
                    if (mApkVersionData.fileListRCR != mServerVersionData.fileListRCR)
                    {
                        needUpdate = true;
                    }
                }
                else
                {
                    if (mLocalVersionData.fileListRCR != mServerVersionData.fileListRCR)
                    {
                        needUpdate = true;
                    }
                }

                //检测包外FileList的缺失
                if (mLocalVersionData.initalize && mLocalVersionData.fileListRCR == mServerVersionData.fileListRCR)
                {
                    string fileListPath = FileHelper.PersistentPath + mServerVersionData.fileListRCR;
                    if (!File.Exists(fileListPath))
                    {
                        needUpdate = true;
                    }
                }

                //需要更新
                if (needUpdate)
                {
                    if (null != m_updateHandle)
                    {
                        m_updateHandle();
                    }

                    Httper.instance.Apply(m_path + mServerVersionData.fileListRCR, OnLoadDescribe, null);
                }
                //不需要更新
                else
                {
                    string fileListPath = FileHelper.PersistentPath + mServerVersionData.fileListRCR;
                    byte[] dllData      = null;
                    //用包外dll文件
                    if (mLocalVersionData.fileListRCR == mServerVersionData.fileListRCR)
                    {
                        dllData = FileHelper.ReadFile(fileListPath);
                        if (m_skipHandle != null)
                        {
                            m_skipHandle(dllData);
                        }
                    }
                    //用包内dll文件
                    else if (mApkVersionData.fileListRCR == mServerVersionData.fileListRCR)
                    {
                        TextAsset textAsset = Resources.Load(mServerVersionData.fileListRCR.ToString()) as TextAsset;
                        if (textAsset != null)
                        {
                            dllData = textAsset.bytes;
                            if (m_skipHandle != null)
                            {
                                m_skipHandle(dllData);
                            }
                        }
                    }
                    else
                    {
                        if (m_failHandle != null)
                        {
                            m_failHandle();
                        }
                        Debug.LogError("更新流程出错,请检测代码");
                        return;
                    }
                }
            }
        }