Ejemplo n.º 1
0
        /// <summary>
        /// 对比可读写文件夹下资源版本和包内资源版本
        /// 加载asb可以从streaming路径加载,不需要将资源拷贝到可读写文件夹
        /// 当包体资源有更新时,删除老的已下载资源包
        /// </summary>
        private void _checkLocalRes()
        {
            if (GameConfig.UseAsb)
            {
                string sUrl = _confUrlStream();
                string wUrl = _confUrlWrite();

                WWWTO streamWWW = WWWTO.ReadFileStr(sUrl, (rst, msg) =>
                {
                    if (rst)
                    {
                        mStreamConf = new ResConf(msg);
                        EventManager.NotifyMain(STR_EVENT_PKG_VERSION, mStreamConf.version);
                    }
                    else
                    {
                        // 该包没有在游戏包体内
                        mStreamConf = new ResConf("");
                    }
                    WWWTO writableWWW = WWWTO.ReadFileStr(wUrl, _onWriteableConf, null);
                    writableWWW.Start();
                }, null);
                streamWWW.Start();
            }
            else
            {
                _callbackLocal(true, "");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 当从本地读取到服务器地址配置表
        /// </summary>
        /// <param name="text">Text.</param>
        void _onServListLoaded(string text)
        {
            //TODO:后期服务器配置表等数据需要加密
            if (!string.IsNullOrEmpty(text))
            {
                ResConf   servers = new ResConf(text);
                ResInfo[] arr     = new ResInfo[servers.files.Values.Count];
                servers.files.Values.CopyTo(arr, 0);
                if (null == mResServList)
                {
                    mResServList = new List <ResInfo>(arr);
                }
                else
                {
                    mResServList.Clear();
                    mResServList.AddRange(arr);
                }
                mResServList.Sort((ResInfo a, ResInfo b) =>
                {
                    return(a.size < b.size ? -1 : 1);
                });

                _callbackServList();
            }
        }
Ejemplo n.º 3
0
 public void Update(ResConf newConf)
 {
     version = newConf.version;
     foreach (var item in newConf.files)
     {
         files[item.Key] = item.Value;
     }
 }
Ejemplo n.º 4
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不用拷贝/下载资源");
                }
            }
        }
Ejemplo n.º 5
0
        public List <ResInfo> GetUpdateFiles(ResConf newConf = null)
        {
            //version = newConf.version;
            List <ResInfo> newFiles = new List <ResInfo>();
            Dictionary <string, ResInfo> of;
            Dictionary <string, ResInfo> nf;

            //如果跟空的比较就把自己记录的所有文件更新
            if (null == newConf)
            {
                of = new Dictionary <string, ResInfo>();
                nf = files;
            }
            else
            {
                int rst = CompareVer(newConf);
                if (-1 == rst)
                {
                    LogFile.Log("当newConf的版本号比较大");
                    //当newConf的版本号比较大
                    of = files;
                    nf = newConf.files;
                }
                else if (1 == rst)
                {
                    LogFile.Log("当自己的的版本号比较大");
                    //当自己的的版本号比较大
                    of = newConf.files;
                    nf = files;
                }
                else
                {
                    LogFile.Log("版本号相同");
                    //==0 版本号相同
                    return(newFiles);
                }
            }
            foreach (var item in nf)
            {
                ResInfo or;
                if (of.TryGetValue(item.Key, out or))
                {
                    if (or.crc == item.Value.crc)
                    {
                        continue;
                    }
                }
                newFiles.Add(item.Value);
                LogFile.Log("检测到 {0} 需要拷贝", item.Value.path);
            }

            return(newFiles);
        }
Ejemplo n.º 6
0
        protected override void _disposMananged()
        {
            mCurConf       = null;
            mServConf      = null;
            mStreamConf    = null;
            mWriteableConf = null;

            if (null != mNewFiles)
            {
                mNewFiles.Clear();
            }
            mNewFiles = null;
            mServList = null;
            mServList = null;
        }
Ejemplo n.º 7
0
 public int CompareVer(ResConf other)
 {
     LogFile.Log("版本对比:[{0}] : [{1}]", version, other.version);
     if (null == other || string.IsNullOrEmpty(other.version))
     {
         LogFile.Log("跟空版本号对比,默认本版本号大");
         return(1);
     }
     if (Equals(version, other.version))
     {
         return(0);
     }
     return(VersionCode > other.VersionCode ? 1 : -1);
     //string[] selfVn = getVersionNums(version);
     //string[] otherVn = getVersionNums(other.version);
     //int sc = selfVn.Length;
     //int oc = otherVn.Length;
     ////以两个版本号短的部分来比较(多的部分是包体资源的版本号有.base后缀)
     //int rst = 0;
     //for (int i = 0; i < (sc < oc ? sc : oc); ++i)
     //{
     //    if (int.Parse(selfVn[i]) != int.Parse(otherVn[i]))
     //    {
     //        rst = int.Parse(selfVn[i]) > int.Parse(otherVn[i]) ? 1 : -1;
     //        break;
     //    }
     //}
     ////这种情况只出现在本地刚解压好包体内的资源,这个时候资源配置版本会多一个.base后缀
     ////如果前面的版本号相同则默认服务器的版本号大
     //if (0 == rst && 1 == Math.Abs(sc - oc))
     //{
     //    if (sc > oc && Equals(selfVn[sc - 1], STR_BASE))
     //    {
     //        rst = -1;
     //    }
     //    else if (sc < oc && Equals(otherVn[oc - 1], STR_BASE))
     //    {
     //        rst = 1;
     //    }
     //}
     //return rst;
 }
Ejemplo n.º 8
0
        public void LoadResServList(Action <List <ResInfo> > action, bool forceLoad = false)
        {
            if (null == mResServList || mResServList.Count == 0 || forceLoad)
            {
                GameResManager.Instance.GetStrAsync("UpdateServer", ".bytes", (text) =>
                {
                    // TextAsset text = obj as TextAsset;
                    if (!string.IsNullOrEmpty(text))
                    {
                        ResConf servers = new ResConf(text);
                        ResInfo[] arr   = new ResInfo[servers.files.Values.Count];
                        servers.files.Values.CopyTo(arr, 0);
                        if (null == mResServList)
                        {
                            mResServList = new List <ResInfo>(arr);
                        }
                        else
                        {
                            mResServList.Clear();
                            mResServList.AddRange(arr);
                        }
                        mResServList.Sort((ResInfo a, ResInfo b) =>
                        {
                            return(a.size < b.size ? -1 : 1);
                        });

                        if (null != action)
                        {
                            action(mResServList);
                        }
                    }
                });
            }
            else
            {
                if (null != action)
                {
                    action(mResServList);
                }
            }
        }
Ejemplo n.º 9
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, "");
        }
Ejemplo n.º 10
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不用拷贝/下载资源");
                }
            }
        }
Ejemplo n.º 11
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, "");
            }
        }