public void UnInit()
 {
     StopAllCoroutines();
     //
     _curSession    = null;
     _localFileList = null;
     _netFileList   = null;
     _diffFileList  = null;
     //移动解压终止
     if (_cachedDownloader != null)
     {
         _cachedDownloader.Dispose();
         _cachedDownloader = null;
     }
     //终止文件列表下载
     if (_diffDownloadInfo != null)
     {
         foreach (KeyValuePair <uint, string> kvp in _diffDownloadInfo)
         {
             HttpService.GetInstance().UnRegisteFileHttpDownload(kvp.Key);
         }
         _diffDownloadInfo.Clear();
         _diffDownloadInfo = null;
     }
     _errorCnt = 0;
     IsDone    = false;
 }
 private void UnInit()
 {
     StopAllCoroutines();
     _handler       = null;
     _localFileList = null;
     IsDone         = false;
 }
        public void StopSession()
        {
            StopCoroutine("StartSession");
            //回收
            if (_netFileList != null)
            {
                _netFileList = null;
            }
            if (_localFileList != null)
            {
                _localFileList = null;
            }
            if (_diffFileList != null)
            {
                _diffFileList = null;
            }

            //移动解压终止
            if (_cachedDownloader != null)
            {
                _cachedDownloader.Dispose();
                _cachedDownloader = null;
            }
            //终止文件列表下载
            if (_diffDownloadInfo != null)
            {
                foreach (KeyValuePair <uint, string> kvp in _diffDownloadInfo)
                {
                    HttpService.GetInstance().UnRegisteFileHttpDownload(kvp.Key);
                }
                _diffDownloadInfo.Clear();
                _diffDownloadInfo = null;
            }

            if (_curSession == null)
            {
                JW.Common.Log.LogE("IFS Service Stop No Run");
                return;
            }
            else
            {
                _curSession.SessionHandler = null;
                //删除标记文件
                string ifsDir    = JW.Res.FileUtil.GetIFSExtractPath();
                string localPath = JW.Res.FileUtil.CombinePath(ifsDir, _curSession.FileListFileName);
                JW.Res.FileUtil.DeleteFile(localPath);
                _curSession = null;
            }
            //
            IsDone = true;
        }
Exemple #4
0
 //差异生成
 IEnumerator DoDiffNetFileList()
 {
     if (_netFileList != null)
     {
         if (_localFileList != null)
         {
             _diffFileList = _localFileList.DiffWithOther(ref _netFileList);
         }
         else
         {
             _diffFileList = _netFileList;
         }
         JW.Common.Log.LogD("<color=yellow>IFSUpdateChecker 需要更新文件列表</color>:" + UnityEngine.JsonUtility.ToJson(_diffFileList));
     }
     yield return(null);
 }
Exemple #5
0
        //本地文件列表检查
        IEnumerator DoLocalFileListCheck()
        {
            string ifsDir = JW.Res.FileUtil.GetIFSExtractPath();
            //ToDO 二进制读取列表方式
            string flpath = JW.Res.FileUtil.CombinePath(ifsDir, this._fileListFileName);

            if (JW.Res.FileUtil.IsFileExist(flpath))
            {
                string localFlStr = System.Text.UTF8Encoding.UTF8.GetString(JW.Res.FileUtil.ReadFile(flpath));
                _localFileList = UnityEngine.JsonUtility.FromJson <UFileInfoList>(localFlStr);
                localFlStr     = null;
                if (_localFileList == null)
                {
                    JW.Common.Log.LogE("IFSUpdateChecker Local File List File Error");
                    _isLocalOk = false;
                }
            }
            else
            {
                _localFileList = null;
                _isLocalOk     = false;
            }
            yield return(null);

            if (_localFileList != null)
            {
                int   totalCnt  = _localFileList.FileList.Count;
                float totalCnt2 = (float)totalCnt;
                for (int i = 0; i < totalCnt; i++)
                {
                    UFileInfo uf       = _localFileList.FileList[i];
                    string    filePath = JW.Res.FileUtil.CombinePath(ifsDir, uf.FileName);
                    string    fileMd5  = JW.Res.FileUtil.GetFileMd5ByFileStream(filePath);
                    if (!fileMd5.Equals(uf.MD5Num, System.StringComparison.CurrentCultureIgnoreCase))
                    {
                        JW.Common.Log.LogE("IFSUpdateChecker Local Res File Hacked:" + uf.FileName);
                        //设置00000 重新下载
                        uf.MD5Num = "000000";
                    }
                    if (i % 2 == 0)
                    {
                        yield return(null);
                    }
                }
            }
            yield return(null);
        }
Exemple #6
0
        //下载网络文件列表
        IEnumerator DoDownloadNetFileList()
        {
            string netUrl = this._netFileListFileUrl;

            JW.Common.Log.LogD("IFSUpdateChecker DoDownloadNetFileList:" + netUrl);
            WWW www = new WWW(netUrl);

            while (www.isDone == false)
            {
                yield return(null);
            }
            if (string.IsNullOrEmpty(www.error))
            {
                string netss = www.text;
                if (!string.IsNullOrEmpty(netss))
                {
                    JW.Common.Log.LogD("IFSUpdateChecker DoDownloadNetFileList Done:" + netss);
                    _netFileList = JsonUtility.FromJson <UFileInfoList>(netss);
                    if (_netFileList == null)
                    {
                        JW.Common.Log.LogE("IFSUpdateChecker Net File List File Error");
                        _isNetOk = false;
                    }
                    www.Dispose();
                    www = null;
                }
                else
                {
                    JW.Common.Log.LogE("IFSUpdateChecker DoDownloadNetFileList Error:" + www.error);
                    www.Dispose();
                    www          = null;
                    _netFileList = null;
                    _isNetOk     = false;
                }
            }
            else
            {
                JW.Common.Log.LogE("IFSUpdateChecker DoDownloadNetFileList Error:" + netUrl + ":" + www.error);
                www.Dispose();
                www          = null;
                _netFileList = null;
                _isNetOk     = false;
            }
            yield return(null);
        }
        //本地文件列表检查
        IEnumerator DoLocalFileListCheck()
        {
            string ifsDir = JW.Res.FileUtil.GetIFSExtractPath();
            //ToDO 二进制读取列表方式
            string flpath = JW.Res.FileUtil.CombinePath(ifsDir, _curSession.FileListFileName);

            if (JW.Res.FileUtil.IsFileExist(flpath))
            {
                string localFlStr = System.Text.UTF8Encoding.UTF8.GetString(JW.Res.FileUtil.ReadFile(flpath));
                _localFileList = UnityEngine.JsonUtility.FromJson <UFileInfoList>(localFlStr);
                localFlStr     = null;
            }
            else
            {
                _errorCnt++;
                _localFileList = null;
            }
            yield return(null);

            if (_localFileList != null)
            {
                int   totalCnt  = _localFileList.FileList.Count;
                float totalCnt2 = (float)totalCnt;
                for (int i = 0; i < totalCnt; i++)
                {
                    UFileInfo uf       = _localFileList.FileList[i];
                    string    filePath = JW.Res.FileUtil.CombinePath(ifsDir, uf.FileName);
                    string    fileMd5  = JW.Res.FileUtil.GetFileMd5ByFileStream(filePath);
                    if (!fileMd5.Equals(uf.MD5Num))
                    {
                        JW.Common.Log.LogE("Local Res File Hacked:" + uf.FileName);
                        //设置00000 重新下载
                        uf.MD5Num = "000000";
                    }

                    if (i % 2 == 0)
                    {
                        CallSessionHandler(IFSState.LocalFileListInit, i / totalCnt2);
                        yield return(null);
                    }
                }
            }
            CallSessionHandler(IFSState.LocalFileListInit, 1.0f);
            yield return(null);
        }
        //下载网络文件列表
        IEnumerator DoDownloadNetFileList()
        {
            string netUrl = _curSession.FileListFileUrl;

            JW.Common.Log.LogD("DoDownloadNetFileList:" + netUrl);
            WWW www = new WWW(netUrl);

            while (www.isDone == false)
            {
                CallSessionHandler(IFSState.NetFileListDownload, www.progress);
                yield return(null);
            }
            if (string.IsNullOrEmpty(www.error))
            {
                string netss = www.text;
                if (!string.IsNullOrEmpty(netss))
                {
                    JW.Common.Log.LogD("DoDownloadNetFileList Done:" + netss);
                    _netFileList = JsonUtility.FromJson <UFileInfoList>(netss);
                    www.Dispose();
                    www = null;
                }
                else
                {
                    _errorCnt++;
                    JW.Common.Log.LogE("DoDownloadNetFileList Error:" + www.error);
                    www.Dispose();
                    www          = null;
                    _netFileList = null;
                }
            }
            else
            {
                _errorCnt++;
                JW.Common.Log.LogE("DoDownloadNetFileList Error:" + netUrl + ":" + www.error);
                www.Dispose();
                www          = null;
                _netFileList = null;
            }
            CallSessionHandler(IFSState.NetFileListDownload, 1.0f);
            yield return(null);
        }
        /// <summary>
        /// 生成当前目录的文件列表 json
        /// </summary>
        /// <param name="workDir">工作目录</param>
        public static void GenerateFileList(string ifsBuildDir, string outName, string buildSvnResNum = "0")
        {
            //
            if (!JW.Res.FileUtil.IsDirectoryExist(ifsBuildDir))
            {
                JW.Common.Log.LogE("UpdateBuilder-->Not Exist WorkDir:" + ifsBuildDir);
            }
            UFileInfoList fileList = new UFileInfoList();

            fileList.ResVersion = buildSvnResNum;
            fileList.ListType   = UFileInfoListType.MainGame;
            //
            string[] files = Directory.GetFiles(ifsBuildDir, "*", SearchOption.AllDirectories);

            for (int i = 0; i < files.Length; i++)
            {
                string path = files[i];
                string ext  = JW.Res.FileUtil.GetExtension(path);
                if (ext.StartsWith(".svn") || ext.StartsWith(".manifest"))
                {
                    continue;
                }
                string    relativePath = JW.Res.FileUtil.GetRelativePath(path, ifsBuildDir);
                UFileInfo uf           = new UFileInfo();
                uf.FileName  = relativePath;
                uf.MD5Num    = JW.Res.FileUtil.GetFileMd5(path.Replace('\\', '/'));
                uf.SvnVerNum = buildSvnResNum;
                uf.FileSize  = JW.Res.FileUtil.GetFileLength(path.Replace('\\', '/'));
                //
                fileList.AddUFile(ref uf);
            }
            //生成json
            string       jss = UnityEngine.JsonUtility.ToJson(fileList);
            UTF8Encoding en  = new UTF8Encoding();

            JW.Res.FileUtil.WriteFile(JW.Res.FileUtil.CombinePath(ifsBuildDir, outName), en.GetBytes(jss));
            JW.Common.Log.LogD("------>GenerateFileList Done<-----");
        }