Beispiel #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, "");
            }
        }
Beispiel #2
0
        public static WWWTO UploadFiles(List <WWWInfo> infos, WWWRstDel del, LuaFunction lua)
        {
            WWWTO www = new WWWTO();

            www.mType = WWWType.upload;

            www.mRstDel = del;
            www._setLuaCallback(lua);

            if (null == infos || infos.Count == 0)
            {
                www._callback(-1, "download files info list is null or empty!");
                www.Dispose();
                return(null);
            }
            for (int i = 0; i < infos.Count; i++)
            {
                www.mTotalSize += infos[i].Size;
            }

            www.mList.Clear();
            www.mList.AddRange(infos);
            www.mFialedList.Clear();

            return(www);
        }
        public static void RequestUrl(string url, LuaFunction call, float timeoutSec = 3f, int retry = 3)
        {
            var www = WWWTO.RequestUrl(url, null, call);

            www.TimeoutSec = timeoutSec;
            www.Retry      = retry;
            www.Start();
        }
        public static void UploadFiles(LuaTable info, LuaFunction call, float timeoutSec = 3f, int retry = 3)
        {
            var www = WWWTO.UploadFiles(WWWInfo.GetListByLua(info), null, call);

            www.TimeoutSec = timeoutSec;
            www.Retry      = retry;
            www.Start();
        }
        public static void DownloadFile(LuaTable info, LuaFunction call, float timeoutSec, int retry = 3)
        {
            var www = WWWTO.DownloadFile(new WWWInfo(info), null, call);

            www.TimeoutSec = timeoutSec;
            www.Retry      = retry;
            www.Start();
        }
Beispiel #6
0
        public void ReadCotainPkgs(Action <bool> callback)
        {
            mCotainCall = callback;
            string url = Tools.GetFileUrl(GameConfig.STR_ASB_MANIFIST + "/version/" + ConfFile);
            WWWTO  www = WWWTO.ReadFileStr(url, _onReadConf, null);

            www.Start();
        }
Beispiel #7
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不用拷贝/下载资源");
                }
            }
        }
Beispiel #8
0
        public static WWWTO ReadFileBytes(string fileUrl, WWWUrlRstBytesDel del, LuaFunction lua)
        {
            WWWTO www = new WWWTO();

            www.mType           = WWWType.readBytes;
            www.mUrlRstBytesDel = del;
            www._setLuaCallback(lua);

            www.mList.Clear();
            www.mList.Add(new WWWInfo(fileUrl, ""));

            return(www);
        }
Beispiel #9
0
        public void ReqAllPkgs(Action <bool> callback)
        {
            mReqAllCall = callback;
            List <string> urls = new List <string>();

            foreach (var item in UpdateMgr.Instance.ResServList)
            {
                urls.Add(Tools.PathCombine(item.path, GameConfig.STR_ASB_MANIFIST + "/version/" + ConfFile));
            }
            WWWTO www = WWWTO.ReadFirstExistsStr(urls, _onAllPkgResp, null);

            www.Start();
        }
Beispiel #10
0
        /// <summary>
        /// 请求某个链接,并获取其返回值或错误信息
        /// </summary>
        /// <param name="url">请求地址</param>
        /// <param name="del">请求回调:
        /// (bool rst, string msg)
        /// rst 表示请求是否成功,msg信息(成返回结果,失败返回错误信息)
        /// </param>
        /// <param name="lua">lua回调,参数跟del相同</param>
        public static WWWTO RequestUrl(string url, WWWUrlRstDel del, LuaFunction lua)
        {
            WWWTO www = new WWWTO();

            www.mType      = WWWType.request;
            www.mUrlRstDel = del;
            www._setLuaCallback(lua);

            www.mList.Add(new WWWInfo()
            {
                Url = url,
            });
            return(www);
        }
Beispiel #11
0
        public static WWWTO UploadFile(WWWInfo info, WWWRstDel del, LuaFunction lua)
        {
            WWWTO www = new WWWTO();

            www.mType   = WWWType.upload;
            www.mRstDel = del;
            www._setLuaCallback(lua);
            www.mTotalSize = info.Size;

            www.mList.Clear();
            www.mList.Add(info);

            return(www);
        }
Beispiel #12
0
        public static WWWTO ReadFirstExistsBytes(List <string> files, WWWUrlRstBytesDel del, LuaFunction lua)
        {
            WWWTO www = new WWWTO();

            www.mType           = WWWType.readBytes;
            www.mUrlRstBytesDel = del;
            www._setLuaCallback(lua);

            www.mList.Clear();
            for (int i = 0; i < files.Count; i++)
            {
                string fileUrl = files[i];
                www.mList.Add(new WWWInfo(fileUrl, ""));
            }

            return(www);
        }
Beispiel #13
0
        protected override void _disposUnmananged()
        {
            if (null != mLocalLua)
            {
                mLocalLua.Dispose();
                mLocalLua = null;
            }

            if (null != mServLua)
            {
                mServLua.Dispose();
                mServLua = null;
            }

            if (null != mDownloader)
            {
                mDownloader.Dispose();
                mDownloader = null;
            }
        }
Beispiel #14
0
 /// <summary>
 /// 获取服务器上相应平台的配置信息
 /// </summary>
 /// <param name="callback">回调.</param>
 /// <param name="forceLoad">如果设置为 <c>true</c> 强制从服务器获取</param>
 public void LoadServConf(Action <Dictionary <string, string> > callback, bool forceLoad = false)
 {
     mServConfCall = callback;
     if (null == mServConf || mServConf.Count == 0 || forceLoad)
     {
         LoadResServList((ResInfo[] list) =>
         {
             List <string> files = new List <string>();
             for (int i = 0; i < list.Length; i++)
             {
                 files.Add(Tools.PathCombine(list[i].path, GameConfig.STR_ASB_MANIFIST + "/servConf.bytes"));
             }
             WWWTO www      = WWWTO.ReadFirstExistsStr(files, _onServConfResp, null);
             www.TimeoutSec = 1.5f;
             www.Start();
         });
     }
     else
     {
         _callbackServConf();
     }
 }
Beispiel #15
0
        void _download()
        {
            if (mTotalSize == 0 || mIsDownloading)
            {
                LogFile.Log(mPkgName + " 正在下载,不用重复下载。");
                return;
            }
            string srcUrl   = _getServUrl();
            float  last     = Time.time;
            long   lastSize = 0L;

            if (null != mNewFiles && mNewFiles.Count > 0)
            {
                List <WWWInfo> infos = new List <WWWInfo>();
                for (int i = 0; i < mNewFiles.Count; ++i)
                {
                    ResInfo ri       = mNewFiles[i];
                    string  url      = Tools.PathCombine(srcUrl, ri.path);
                    string  savePath = Tools.GetWriteableDataPath(GameConfig.STR_ASB_MANIFIST + "/" + ri.path);
                    infos.Add(new WWWInfo(url, savePath, ri.size));
                }

                //需要拷贝资源到可读写文件夹
                mDownloader = WWWTO.DownloadFiles(
                    infos,
                    (double progress, int index, string msg) =>
                {
                    if (Tools.Equals(progress, 1d))
                    {
                        if (msg.Equals(WWWTO.STR_SUCCEEDED))
                        {
                            mCurConf.version = mServConf.version;
                            //保存新的资源版本号
                            saveVersionCode();
                            _callbackDownload(1d, 0, msg);
                        }
                        else
                        {
                            _callbackDownload(1d, -1, msg);
                        }

                        mCurConf.SaveToFile(_confPathWrite());
                        mIsDownloading = false;
                    }
                    else
                    {
                        string filePath = mNewFiles[index - 1].path;
                        if (Tools.Equals(progress, -1d))
                        {
                            //有文件下载失败
                            LogFile.Warn("[" + filePath + "]下载失败,url:" + infos[index - 1].Url);
                        }
                        else
                        {
                            if (msg.Equals(WWWTO.STR_DONE))
                            {
                                //有文件下载成功
                                mCurConf.files[filePath] = mServConf.files[filePath];
                            }
                            float now       = Time.time;
                            float dt        = now - last;
                            long doneSize   = (long)(mTotalSize * progress);
                            long sizePerSec = (long)((doneSize - lastSize) / dt);
                            if (sizePerSec >= 0)
                            {
                                _callbackDownload(progress, sizePerSec, filePath);
                            }
                            last     = now;
                            lastSize = doneSize;
                        }
                    }
                },
                    null
                    );
                mDownloader.Start();
                mIsDownloading = true;
            }
        }