Exemplo n.º 1
0
        /// <summary>
        /// 对比服务器配置文件,记录新的文件
        /// </summary>
        /// <param name="url">服务器地址 URL.</param>
        /// <param name="callback">Callback.</param>
        private void _compareNewFiles(string url, Action <long, string> callback)
        {
            if (null != callback)
            {
                if (GameConfig.UseAsb)
                {
                    string sUrl = _confUrl(url);
                    string pUrl = _confUrlWrite();

                    WWWTO streamWWW = WWWTO.ReadFileStr(sUrl, (rst, msg) =>
                    {
                        if (rst)
                        {
                            mServConf = new ResConf(msg);

                            WWWTO writableWWW = WWWTO.ReadFileStr(pUrl, (_rst, _msg) =>
                            {
                                if (_rst)
                                {
                                    //之前已经拷贝过资源
                                    mCurConf = new ResConf(_msg);
                                }
                                else
                                {
                                    mCurConf = new ResConf("");
                                }
                                mTotalSize = 0;
                                if (mServConf.CompareVer(mCurConf) > 0)
                                {
                                    mNewFiles = mServConf.GetUpdateFiles(mCurConf);
                                    foreach (var f in mNewFiles)
                                    {
                                        mTotalSize += f.size;
                                    }
                                    callback(mTotalSize, mServConf.version);
                                }
                                else
                                {
                                    LogFile.Log("没有检测到新版本资源,跳过更新步骤");
                                    callback(mTotalSize, "没有检测到新版本资源,跳过更新步骤");
                                }
                            }, null);
                            writableWWW.Start();
                        }
                        else
                        {
                            LogFile.Warn("资源配置文件" + sUrl + "丢失");
                            callback(-1, STR_CONFIG_MISSING);
                        }
                    }, null);
                    streamWWW.Start();
                }
                else
                {
                    callback(0, "不使用Assetbundle不用拷贝/下载资源");
                }
            }
        }
Exemplo n.º 2
0
        void _onWriteableConf(bool rst, string msg)
        {
            if (rst)
            {
                //之前已经拷贝过资源
                mWriteableConf = new ResConf(msg);
            }
            else
            {
                mWriteableConf = new ResConf("");
            }

            mCurConf = mWriteableConf;

            if (mStreamConf.CompareVer(mWriteableConf) > 0)
            {
                List <ResInfo> list = mStreamConf.GetUpdateFiles(mWriteableConf);
                if (list.Count > 0)
                {
                    //将可读写文件夹下的老版本资源删除
                    for (int i = 0; i < list.Count; i++)
                    {
                        ResInfo ri       = list[i];
                        string  savePath = Tools.GetWriteableDataPath(GameConfig.STR_ASB_MANIFIST + "/" + ri.path);
                        if (File.Exists(savePath))
                        {
                            File.Delete(savePath);
                            LogFile.Log("删除已下载的老资源:" + savePath);
                        }
                        mCurConf.files[ri.path] = mStreamConf.files[ri.path];
                    }
                }
                mCurConf.version = mStreamConf.version;
                //保存新的资源版本号
                saveVersionCode();
                mCurConf.SaveToFile(_confPathWrite());
            }
            _callbackLocal(true, "");
        }
Exemplo n.º 3
0
        /// <summary>
        /// 对比resConf.bytes文件,根据需要进行拷贝或下载
        /// </summary>
        /// <param name="srcUrl">Source URL.</param>
        /// <param name="tarUrl">Tar URL.</param>
        /// <param name="callback">Callback.</param>
        private void checkResConf(string srcUrl, string tarUrl, Action <bool, string> callback)
        {
            string confPath = STR_RES_CONF;

            if (null != callback)
            {
                ResConf srcConf = null;
                ResConf tarConf = null;

                if (GameConfig.useAsb)
                {
                    string sUrl = Tools.PathCombine(srcUrl, confPath);
                    string pUrl = Tools.PathCombine(tarUrl, confPath);

                    TimeOutWWW streamWWW = getTimeOutWWW();
                    streamWWW.ReadFileStr("localResCOnf", sUrl, 1f, (rst, msg) =>
                    {
                        if (rst)
                        {
                            srcConf = new ResConf(msg);

                            TimeOutWWW writableWWW = getTimeOutWWW();
                            writableWWW.ReadFileStr("externalResConf", pUrl, 1f, (_rst, _msg) =>
                            {
                                if (_rst)
                                {
                                    //之前已经拷贝过资源
                                    tarConf = new ResConf(_msg);
                                }
                                else
                                {
                                    tarConf = new ResConf("");
                                }

                                curConf       = tarConf;
                                float last    = Time.time;
                                long lastSize = 0;

                                if (srcConf.CompareVer(tarConf) > 0)
                                {
                                    List <ResInfo> list = srcConf.GetUpdateFiles(tarConf);
                                    if (list.Count > 0)
                                    {
                                        string format = Lm.GetStr("正在下载资源,已完成[ {0} / {1} ],下载速度:{2} ...");
                                        mInfoStr      = string.Format(format, 0, list.Count, "0Byte/s");
                                        //需要拷贝资源到可读写文件夹
                                        TimeOutWWW copyLocal = getTimeOutWWW();
                                        List <WWWInfo> infos = new List <WWWInfo>();
                                        long totalSize       = 0;
                                        for (int i = 0; i < list.Count; ++i)
                                        {
                                            ResInfo ri      = list[i];
                                            string url      = Tools.PathCombine(srcUrl, ri.path);
                                            string savePath = Tools.GetWriteableDataPath(GameConfig.STR_ASB_MANIFIST + "/" + ri.path);
                                            totalSize      += ri.size;
                                            infos.Add(new WWWInfo(url, savePath, ri.size));
                                        }
                                        string totalSizeStr = Tools.FormatMeroySize(totalSize);
                                        copyLocal.DownloadFiles("copyLocal", infos, 2f, (string noticeKey, double progress, int index, string __msg) =>
                                        {
                                            //LogFile.Log("progress:{0}; index:{1}; msg:{2};", progress, index, __msg);

                                            if (progress.Equals(1d))
                                            {
                                                if (__msg.Equals(TimeOutWWW.STR_SUCCEEDED))
                                                {
                                                    curConf.version = srcConf.version;
                                                    //保存新的资源版本号
                                                    GameConfig.SetInt(GameDefine.STR_CONF_KEY_RES_VER_I, curConf.VersionCode);
                                                    mVersionStr = "app:v" + Application.version + " res" + curConf.version;
                                                    refreshUI(100);
                                                    //拷贝完成
                                                    callback(true, "资源更新完成");
                                                }
                                                else
                                                {
                                                    callback(false, "部分资源更新失败");
                                                }
                                                curConf.SaveToFile(Tools.GetWriteableDataPath(GameConfig.STR_ASB_MANIFIST + "/" + STR_RES_CONF));

                                                return;
                                            }
                                            if (progress.Equals(-1d))
                                            {
                                                //有文件下载或者拷贝失败
                                                LogFile.Warn("[" + infos[index].Url + "]拷贝或下载失败");
                                            }
                                            else
                                            {
                                                if (__msg.Equals(TimeOutWWW.STR_DONE))
                                                {
                                                    //有文件下载成功
                                                    curConf.files[list[index - 1].path] = srcConf.files[list[index - 1].path];

                                                    //mInfoStr = string.Format(format, index, list.Count);
                                                }
                                                float now       = Time.time;
                                                float dt        = now - last;
                                                long doneSize   = (long)(totalSize * progress);
                                                long siezPerSec = (long)((doneSize - lastSize) / dt);
                                                if (siezPerSec > 0)
                                                {
                                                    mInfoStr = string.Format(format, Tools.FormatMeroySize(doneSize), totalSizeStr, Tools.FormatMeroySize(siezPerSec) + "/s");
                                                    //LogFile.Log(mInfoStr);
                                                    refreshUI((float)progress);
                                                }
                                                last     = now;
                                                lastSize = doneSize;
                                            }
                                        }, null);
                                    }
                                }
                                else
                                {
                                    LogFile.Log("没有检测到新版本资源,跳过更新步骤");
                                    callback(true, "没有检测到新版本资源,跳过更新步骤");
                                }
                            }, null);
                        }
                        else
                        {
                            LogFile.Warn("资源配置文件" + sUrl + "丢失");
                            callback(false, STR_CONFIG_MISSING);
                        }
                    }, null);
                }
                else
                {
                    callback(true, "不使用Assetbundle不用拷贝/下载资源");
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 加载asb可以从streaming路径加载,不需要将资源拷贝到可读写文件夹
        /// 当包体资源有更新时,删除老的资源包
        /// </summary>
        /// <param name="srcUrl">Source URL.</param>
        /// <param name="tarUrl">Tar URL.</param>
        /// <param name="callback">Callback.</param>
        private void delOldWriteableRes(string srcUrl, string tarUrl, Action <bool, string> callback)
        {
            string confPath = STR_RES_CONF;

            if (null != callback)
            {
                ResConf srcConf = null;
                ResConf tarConf = null;

                if (GameConfig.useAsb)
                {
                    string sUrl = Tools.PathCombine(srcUrl, confPath);
                    string pUrl = Tools.PathCombine(tarUrl, confPath);

                    TimeOutWWW streamWWW = getTimeOutWWW();
                    streamWWW.ReadFileStr("localResConf", sUrl, 1f, (rst, msg) =>
                    {
                        if (rst)
                        {
                            srcConf = new ResConf(msg);

                            TimeOutWWW writableWWW = getTimeOutWWW();
                            writableWWW.ReadFileStr("externalResConf", pUrl, 1f, (_rst, _msg) =>
                            {
                                if (_rst)
                                {
                                    //之前已经拷贝过资源
                                    tarConf = new ResConf(_msg);
                                }
                                else
                                {
                                    tarConf = new ResConf("");
                                }

                                curConf = tarConf;

                                if (srcConf.CompareVer(tarConf) > 0)
                                {
                                    List <ResInfo> list = srcConf.GetUpdateFiles(tarConf);
                                    if (list.Count > 0)
                                    {
                                        //将可读写文件夹下的老版本资源删除
                                        for (int i = 0; i < list.Count; i++)
                                        {
                                            ResInfo ri      = list[i];
                                            string savePath = Tools.GetWriteableDataPath(GameConfig.STR_ASB_MANIFIST + "/" + ri.path);
                                            if (File.Exists(savePath))
                                            {
                                                File.Delete(savePath);
                                                LogFile.Log("删除已下载的老资源:" + savePath);
                                            }
                                            curConf.files[ri.path] = srcConf.files[ri.path];
                                        }
                                    }
                                    curConf.version = srcConf.version;
                                    //保存新的资源版本号
                                    GameConfig.SetInt(GameDefine.STR_CONF_KEY_RES_VER_I, curConf.VersionCode);
                                    curConf.SaveToFile(Tools.GetWriteableDataPath(GameConfig.STR_ASB_MANIFIST + "/" + STR_RES_CONF));
                                    mVersionStr = "app:v" + Application.version + " res" + curConf.version;
                                    refreshUI(100);
                                }
                            }, null);
                        }
                    }, null);
                }
                callback(true, "");
            }
        }