Exemplo n.º 1
0
    public static DownloadTaskErrorCode FetchByUrl(string url, string destFile, int timeout, out string errMsg)
    {
        if (!FileOperate.MakeDir(destFile))
        {
            Common.HobaDebuger.LogWarning(HobaText.Format("[FetchByUrl] MakeDir {0} Failed!", destFile));
        }

        if (FileOperate.IsFileExist(destFile))
        {
            FileOperate.DeleteFile(destFile);
        }

        string hostName = UpdateUtility.GetHostName(url);

        var code = UpdateUtility.GetByUrl(
            url,
            hostName,
            destFile,
            timeout,          //10s
            null,
            null,
            out errMsg);

        return(code);
    }
Exemplo n.º 2
0
    //从服务器下载 version.txt 到 strGameNewVerFile
    public DownloadTaskErrorCode FetchServerVersionFile(string url, string hostName, string savedFile, int timeout, out string errMsg)
    {
        if (!FileOperate.MakeDir(savedFile))
        {
            LogString(HobaText.Format("[FetchServerVersionFile] MakeDir {0} Failed!", savedFile));
        }

        if (FileOperate.IsFileExist(savedFile))
        {
            FileOperate.DeleteFile(savedFile);
        }

        //测试
        //         int filesize2 = (int)SeasideResearch.LibCurlNet.External.CURL_GetUrlFileSize(url, timeout);
        //         LogString(HobaString.Format("c++ url FileSize: {0}, fileSize: {1}", url, filesize2));
        //
        //         int filesize = (int)UpdateUtility.GetUrlFileSizeEx(url, hostName, timeout);
        //         LogString(HobaString.Format("url FileSize: {0}, fileSize: {1}", url, filesize));

        var code = UpdateUtility.GetByUrl(
            url,
            hostName,
            savedFile,
            timeout,          //10s
            null,
            null,
            out errMsg);

        return(code);
    }
Exemplo n.º 3
0
    //如果本地文件不存在,设置为初始版本, 如果当前版本 < 初始版本,则写新版本, ret是否新写入baseVersion
    public bool SetFirstVersion(ELEMENT_VER ver, bool bForceWrite)
    {
        m_baseVer = ver;

        if (bForceWrite || !FileOperate.IsFileExist(strGameOldVerFile))
        {
            if (!FileOperate.MakeDir(strGameOldVerFile))
            {
                LogString(HobaText.Format("[SetFirstVersion] MakeDir {0} Failed!", strGameOldVerFile));
            }
            UpdateRetCode ret = SetLocalVersion(ver);
            if (ret != UpdateRetCode.success)
            {
                LogString(HobaText.Format("[SetFirstVersion] SetLocalVersion {0} Failed!", strGameOldVerFile));
            }
            else
            {
                return(true);
            }
        }
        else
        {
            ELEMENT_VER localVersion;
            if (GetLocalVersion(out localVersion) && localVersion < m_baseVer)
            {
                LogString(HobaText.Format("[SetFirstVersion] Local Version File Exist {0}! Write New Version From: {1} To {2}", strGameOldVerFile, localVersion.ToString(), ver.ToString()));

                if (!FileOperate.MakeDir(strGameOldVerFile))
                {
                    LogString(HobaText.Format("[SetFirstVersion] MakeDir {0} Failed2!", strGameOldVerFile));
                }
                UpdateRetCode ret = SetLocalVersion(ver);
                if (ret != UpdateRetCode.success)
                {
                    LogString(HobaText.Format("[SetFirstVersion] SetLocalVersion {0} Failed2!", strGameOldVerFile));
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                LogString(HobaText.Format("[SetFirstVersion] Local Version File Exist {0}!", strGameOldVerFile));
            }
        }

        return(false);
    }
Exemplo n.º 4
0
    public static DownloadTaskErrorCode FetchAccountRoleListFile(string url, string hostName, string savedFile, int timeout, out string errMsg)
    {
        if (!FileOperate.MakeDir(savedFile))
        {
            Common.HobaDebuger.LogErrorFormat("[FetchAccountRoleListFile] MakeDir {0} Failed!", savedFile);
        }

        var code = UpdateUtility.GetByUrl(
            url,
            hostName,
            savedFile,
            timeout,          //10s
            null,
            null,
            out errMsg);

        return(code);
    }
Exemplo n.º 5
0
    private bool CreateFile(string filename)
    {
        string strLogPath = filename;

        if (FileOperate.IsFileExist(strLogPath))
        {
            FileOperate.DeleteFile(strLogPath);
        }
        try
        {
            FileOperate.MakeDir(strLogPath);

            logWriter = File.CreateText(strLogPath);
            LogWriteLine("StatisticsInfo Created!");
        }
        catch (Exception)
        {
            logWriter = null;
        }
        return(logWriter != null);
    }
Exemplo n.º 6
0
    public bool CreateLog(string filename)
    {
        string strLogPath = filename;

        if (FileOperate.IsFileExist(strLogPath))
        {
            FileOperate.DeleteFile(strLogPath);
        }
        try
        {
            FileOperate.MakeDir(strLogPath);

            logWriter = File.CreateText(strLogPath);
            LogWriteLine(string.Format("UpdateLog Created! {0:G}", System.DateTime.Now));
        }
        catch (Exception)
        {
            logWriter = null;
        }
        return(logWriter != null);
    }
Exemplo n.º 7
0
    public IEnumerable Init(string baseDir,
                            string docDir,
                            string libDir,
                            string tmpDir,
                            string updateServerDir1,
                            string updateServerDir2,
                            string updateServerDir3,
                            string clientServerDir,
                            string dynamicServerDir,
                            string dynamicAccountRoleDir)
    {
        strBaseDir = baseDir.NormalizeDir();
        strDocDir  = docDir.NormalizeDir();
        strLibDir  = libDir.NormalizeDir();
        strTmpDir  = tmpDir.NormalizeDir();

        //
        strUpdateServerDir1      = updateServerDir1.NormalizeDir();
        strUpdateServerDir2      = updateServerDir2.NormalizeDir();
        strUpdateServerDir3      = updateServerDir3.NormalizeDir();
        strClientServerDir       = clientServerDir.NormalizeDir();
        strDynamicServerDir      = dynamicServerDir.NormalizeDir();
        strDynamicAccountRoleDir = dynamicAccountRoleDir;

        strUpdateServerHostName1 = UpdateUtility.GetHostName(strUpdateServerDir1);
        strUpdateServerHostName2 = UpdateUtility.GetHostName(strUpdateServerDir2);
        strUpdateServerHostName3 = UpdateUtility.GetHostName(strUpdateServerDir3);
        strClientServerHostName  = UpdateUtility.GetHostName(strClientServerDir);
        strDynamicServerHostName = UpdateUtility.GetHostName(strDynamicServerDir);

        //
        strGameOldVerFile        = strLibDir + strGameOldVerFile;
        strGameNewVerFile        = strLibDir + strGameNewVerFile;
        strUpdateIncFile         = strLibDir + strUpdateIncFile;
        strDownloadPath          = strLibDir + strDownloadPath;
        strServerListXML         = strLibDir + strServerListXML;
        strServerListJSON        = strLibDir + strServerListJSON;
        strAccountRoleListJSON   = strLibDir + strAccountRoleListJSON;
        strErrorLog              = strDocDir + strErrorLog;
        strTempWritePackFileName = strLibDir + strTempWritePackFileName;
        //strAnnoucementFile = strLibDir + strAnnoucementFile;
        //strLibPatcherDir = strLibDir + strLibPatcherDir;
        //strLibPackageDir = strLibDir + strLibPackageDir;
        //strLibPatcherConfigDir = strLibDir + strLibPatcherConfigDir;
        strLibPatcherTmpDir = strLibDir + strLibPatcherTmpDir;
        //strLibAssetBundleDir = strLibDir + strLibAssetBundleDir;

        //create log
        FileOperate.MakeDir(strErrorLog);
        yield return(null);

        _UpdateLog.CreateLog(strErrorLog);
        yield return(null);

        LogString(HobaText.Format("skipUpdate: {0}", EntryPoint.Instance.SkipUpdate));

        LogString(HobaText.Format("baseDir: {0}", strBaseDir));
        LogString(HobaText.Format("docDir: {0}", strDocDir));
        LogString(HobaText.Format("libDir: {0}", strLibDir));
        LogString(HobaText.Format("TmpDir: {0}", strTmpDir));

        LogString(HobaText.Format("updateServerDir1: {0}, updateServerDir2: {1}, updateServerDir3: {2}",
                                  strUpdateServerDir1, strUpdateServerDir2, strUpdateServerDir3));
        LogString(HobaText.Format("clientServerDir: {0}", strClientServerDir));
        LogString(HobaText.Format("dynamicServerDir: {0}", strDynamicServerDir));
        LogString(HobaText.Format("dynamicAccountRoleDir: {0}", strDynamicAccountRoleDir));
        LogString(HobaText.Format("strUpdateServerHostName1: {0}, strUpdateServerHostName2: {1}, strUpdateServerHostName3: {2}",
                                  strUpdateServerHostName1, strUpdateServerHostName2, strUpdateServerHostName3));
        LogString(HobaText.Format("strClientServerHostName: {0}", strClientServerHostName));
        LogString(HobaText.Format("strDynamicServerHostName: {0}", strDynamicServerHostName));
        yield return(null);

        LogString(HobaText.Format("strGameOldVerFile: {0}", strGameOldVerFile));
        LogString(HobaText.Format("strGameNewVerFile: {0}", strGameNewVerFile));
        LogString(HobaText.Format("strUpdateIncFile: {0}", strUpdateIncFile));
        LogString(HobaText.Format("strDownloadPath: {0}", strDownloadPath));
        LogString(HobaText.Format("strServerListXML: {0}", strServerListXML));
        LogString(HobaText.Format("strServerListJSON: {0}", strServerListJSON));
        LogString(HobaText.Format("strAccountRoleListJSON: {0}", strAccountRoleListJSON));
    }
Exemplo n.º 8
0
    private IEnumerator DownloadPictureFromUrl(string strFileName, string url, int timeout, DownloadPictureCallback callback)
    {
        yield return(new WaitForEndOfFrame());

        string strFile     = Path.Combine(EntryPoint.Instance.CustomPicDir, strFileName);
        string contentType = Patcher.GetUrlContentType(url, timeout);
        int    retCode     = 0;

        if (contentType.StartsWith("text/"))
        {
            string tmpPath = Path.Combine(EntryPoint.Instance.TmpPath, "tmp.txt");
            string errMsg;
            var    code = Patcher.FetchByUrl(url, tmpPath, timeout, out errMsg);
            if (code == Downloader.DownloadTaskErrorCode.Success)
            {
                try
                {
                    var    bytes = File.ReadAllBytes(tmpPath);
                    var    chars = System.Text.Encoding.UTF8.GetChars(bytes);
                    string str   = new string(chars, 0, chars.Length);
                    retCode = int.Parse(str);
                }
                catch (Exception)
                {
                    retCode = -1;
                }
            }
            else
            {
                retCode = -1;
            }

            callback(strFileName, retCode, null);
        }
        else //下载图片
        {
            UnityWebRequest request            = UnityWebRequest.Get(url);
            string          authorizationValue = GameCustomConfigParams.Authorization;
            request.SetRequestHeader("Authorization", authorizationValue);
            yield return(request.Send());

            int resCode = -1;
            if (request.responseCode == 200)
            {
                var dic = JsonUtility.FromJson <URLResult>(request.downloadHandler.text);
                url = dic.url;

                request = UnityWebRequest.Get(url);
                yield return(request.Send());

                if (request.responseCode == 200)
                {
                    if (!FileOperate.MakeDir(strFile))
                    {
                        Common.HobaDebuger.LogWarning(HobaText.Format("[FetchByUrl] MakeDir {0} Failed!", strFileName));
                    }

                    if (FileOperate.IsFileExist(strFile))
                    {
                        FileOperate.DeleteFile(strFile);
                    }

                    var streamFile = new FileStream(strFile, FileMode.OpenOrCreate);
                    streamFile.Write(request.downloadHandler.data, 0, (int)request.downloadedBytes);
                    streamFile.Close();

                    //string errMsg;
                    //var code = Patcher.FetchByUrl(url, strFile, timeout, out errMsg);
                    if (dic.resCode == (int)Downloader.DownloadTaskErrorCode.Success)
                    {
                        callback(strFileName, retCode, null);
                    }
                    else
                    {
                        callback(strFileName, retCode, HobaText.Format("{0}, {1}", (int)dic.resCode, url));
                    }
                }
                else
                {
                    callback(strFileName, retCode, HobaText.Format("{0}, {1}", (int)resCode, url));
                }
            }
            else
            {
                callback(strFileName, retCode, HobaText.Format("{0}, {1}", (int)resCode, url));
            }
        }
    }
Exemplo n.º 9
0
    public IEnumerable UpdateAutoCoroutine(ELEMENT_VER verBegin, ELEMENT_VER verLatest)
    {
        long packSizeOverAll = m_VersionMan.CalcSize(verBegin, verLatest);

        if (packSizeOverAll <= 0)
        {
            packSizeOverAll = 1;
        }
        long packFinishedSize = m_VersionMan.CalcSize(verBegin, m_PackFileVer.VerFrom);

        int nTotalPack   = m_VersionMan.CalcPackCount(verBegin, verLatest);
        int nCurrentPack = m_VersionMan.CalcPackCount(verBegin, m_PackFileVer.VerTo);

        GameUpdateMan.Instance.HotUpdateViewer.SetPackageNum(nCurrentPack, nTotalPack);

        UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.Total, (float)((double)packFinishedSize / (double)packSizeOverAll));
        UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.File, 0.0f);
        UpdateInfoUtil.SetStateString(UPDATE_STATE.UpdateStatus_BeginUpdate);

        yield return(null);

        UpdateRetCode ret    = UpdateRetCode.success;
        string        strMd5 = this.m_PackFileVer.md5;

        //要下载的路径
        this.strDownloadUPackName = HobaText.Format(
            "{0}-{1}.jup",
            this.m_PackFileVer.VerFrom.ToString(),
            this.m_PackFileVer.VerTo.ToString());
        string strDownloadUPack = this.strDownloadPath + this.strDownloadUPackName;

        //计时
        float nStartTime = Time.time;
        float nLasTime   = nStartTime;
        float nNowTime   = nStartTime;

        //准备下载
        using (DownloadMan downloadMan = new DownloadMan(this.strDownloadPath))              //DownloadMan
        {
            downloadMan.TaskEndEvent += delegate { this.IsDownloadDone = true; };

            int nTryTimes = 0;

            bool bFileEqual = false;
            while (!bFileEqual)
            {
                if (ret == UpdateRetCode.net_err || ret == UpdateRetCode.io_err || ret == UpdateRetCode.urlarg_error)
                {
                    ++nTryTimes;

                    //重连次数超过
                    if (nTryTimes > UpdateConfig.TotalReconnectTime)
                    {
                        ret = UpdateRetCode.connect_fail;
                        break;          //这次更新错误,等待选择重试
                    }

                    //重连,间隔一定时间
                    do
                    {
                        yield return(new WaitForSeconds(1.0f));

                        nNowTime = Time.time;
                    }while (nNowTime - nLasTime <= UpdateConfig.ReconnectTime);
                    nLasTime = nNowTime;

                    this.LogString(HobaText.Format("DownloadMan net_err begin retry {0} ... file: {1}", nTryTimes, this.strDownloadUPackName));
                }
                else
                {
                    nTryTimes = 0;
                }

                if (ret == UpdateRetCode.md5_not_match || ret == UpdateRetCode.download_fail)
                {
                    break;
                }

                //如果文件已存在,判断md5
                if (FileOperate.IsFileExist(strDownloadUPack))
                {
                    yield return(new WaitForSeconds(0.01f));

                    UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.File, 100.0f);
                    UpdateInfoUtil.SetStateString(UPDATE_STATE.UpdateStatus_CheckingExistPack);
                    yield return(null);

                    //string md5_exist = FileOperate.CalcFileMd5(strDownloadUPack);
                    CalcMd5ThreadInfo calcMd5Info = CalcFileMd5(strDownloadUPack);
                    while (calcMd5Info.IsRunning)
                    {
                        yield return(_ShortWait);
                    }
                    OnCalcMd5Complete();
                    string md5_exist = calcMd5Info.Md5;

                    if (md5_exist == strMd5)
                    {
                        bFileEqual = true;
                        break;
                    }
                    FileOperate.DeleteFile(strDownloadUPack);       //删除旧文件
                }

                //重新开始下载
                this.IsDownloadDone = false;
                if (!FileOperate.MakeDir(strDownloadUPack))
                {
                    LogString(HobaText.Format("[UpdateAutoCoroutine] MakeDir {0} Failed!", strDownloadUPack));
                }

                //
                UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.File, 0.0f);
                UpdateInfoUtil.SetDownStatusString(0.0f);
                GameUpdateMan.Instance.HotUpdateViewer.SetDownloadInfo_TextUpate(UpdateInfoUtil.GetStateString(UPDATE_STATE.UpdateString_TextUpdate));

                yield return(null);

//              foreach (var item in FetchPackByUrlCoroutine(downloadMan,
//                     this.strUpdateServerDir1, this.strUpdateServerHostName1, this.strDownloadUPackName, strMd5))
                foreach (var item in FetchPackCoroutine(downloadMan,
                                                        this.strUpdateServerDir1, this.strUpdateServerHostName1,
                                                        this.strUpdateServerDir2, this.strUpdateServerHostName2,
                                                        this.strUpdateServerDir3, this.strUpdateServerHostName3,
                                                        this.strDownloadUPackName, strMd5))
                {
                    if (item is UpdateRetCode)
                    {
                        ret = (UpdateRetCode)item;
                        break;
                    }
                    else
                    {
                        yield return(item);
                    }
                }

                if (ret != UpdateRetCode.success)
                {
                    bFileEqual = false;
                }
            }

            if (bFileEqual)
            {
                ret = UpdateRetCode.success;
            }
        }

        if (ret == UpdateRetCode.success)        //下载成功
        {
            UpdateInfoUtil.bShowWritingPack = true;

            //设置本地包路径
            strLocalPackFileName = strDownloadPath + strDownloadUPackName;
            UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.File, 0.0f);

            yield return(null);

            //打开本地包,更新...
            //提示正在写包
            GameUpdateMan.Instance.HotUpdateViewer.SetInstallInfo(UpdateInfoUtil.GetStateString(UPDATE_STATE.UpdateStatus_WritingPack));
            GameUpdateMan.Instance.HotUpdateViewer.SetInstallPercent(-1.0f);

            foreach (var item in UpdateFileFromPackCoroutine(strLocalPackFileName, verBegin, verLatest))
            {
                if (item is UpdateRetCode)
                {
                    ret = (UpdateRetCode)item;
                    break;
                }

                yield return(item);
            }

            //关闭临时包
            FileOperate.DeleteFile(this.strLocalPackFileName);
            this.strLocalPackFileName = "";

            UpdateInfoUtil.bShowWritingPack = false;
        }

        if (ret == UpdateRetCode.invalid_param)
        {
            ret = UpdateRetCode.cancel;
            yield return(ret);
        }
        else if (ret == UpdateRetCode.pack_file_broken ||
                 ret == UpdateRetCode.net_err ||
                 ret == UpdateRetCode.connect_fail ||
                 ret == UpdateRetCode.md5_not_match ||
                 ret == UpdateRetCode.io_err ||
                 ret == UpdateRetCode.urlarg_error ||
                 ret == UpdateRetCode.download_fail)
        {
            yield return(ret);
        }
        else if (ret != UpdateRetCode.success)
        {
            ret = UpdateRetCode.fail;
            yield return(ret);
        }

        //写入本地版本
        UpdateInfoUtil.SetVersion(UPDATE_VERSION.Local, this.m_CurrentVersion);

        yield return(UpdateRetCode.success);
    }
Exemplo n.º 10
0
    public IEnumerable DoUpdateFrom7zCoroutine(string strPack, ELEMENT_VER verBegin, ELEMENT_VER verLatest)
    {
        //this.LogString(HobaText.Format("DoUpdateFrom7zCoroutine: {0}, {1}, {2}", strPack, verBegin.ToString(), verLatest.ToString()));

        UpdateRetCode code = UpdateRetCode.success;

        SevenZReader reader = new SevenZReader();

        if (!reader.Init(strPack))
        {
            code = UpdateRetCode.pack_file_broken;
            reader.Release();
            yield return(code);            //
        }

        int fileCount = reader.GetFileCount();

        if (fileCount > 0)
        {
            GameUpdateMan.Instance.HotUpdateViewer.SetInstallProgress(1, fileCount);
            yield return(null);
        }

        FileIncList fileIncList = new FileIncList();
        //找到7z包中的版本文件, inc, 得到版本
        bool bIncValid = false;

        for (int iFile = 0; iFile < fileCount; ++iFile)
        {
            string name = reader.GetFileName(iFile);

            //            LogString(HobaString.Format("7z pack file: {0}: {1}", iFile, name));
            if (name == "")
            {
                this.LogString(HobaText.Format("Fail to get file name: {0}", iFile));
                code = UpdateRetCode.pack_file_broken;
                reader.Release();
                yield return(code);        //
            }

            if (!bIncValid && name == "inc")
            {
                bIncValid = true;

                //读取
                ExtractPackThreadInfo threadInfo = ExtractFileFrom7zReader(reader, iFile);
                while (threadInfo.IsRunning)
                {
                    yield return(_ShortWait);
                }
                OnExtractFileComplete();

                int    dataSize = threadInfo.DataSize;
                IntPtr pData    = threadInfo.Pointer;
                if (pData == IntPtr.Zero)
                {
                    this.LogString(HobaText.Format("Fail to extract file name: {0}", iFile));
                    code = UpdateRetCode.pack_file_broken;
                    reader.Release();
                    yield return(code);    //
                }

                //写入
                if (!FileOperate.MakeDir(this.strUpdateIncFile))
                {
                    LogString(HobaText.Format("[UpdateAutoCoroutine] MakeDir {0} Failed!", this.strUpdateIncFile));
                }

                byte[] pText = new byte[dataSize];
                Marshal.Copy(pData, pText, 0, dataSize);
                char[] text = Encoding.UTF8.GetChars(pText);
                bool   ret  = FileOperate.WriteToTextFile(this.strUpdateIncFile, text, text.Length);

                if (!ret)
                {
                    this.LogString(HobaText.Format("Fail to write inc file name: %d", iFile));
                    code = UpdateRetCode.file_write_err;
                    reader.Release();
                    yield return(code);    //
                }

                //读取inc内容
                code = ReadIncFileList(this.strUpdateIncFile, out fileIncList, out m_currentNewVer);
                //删除本地inc文件
                FileOperate.DeleteFile(this.strUpdateIncFile);
            }

            if (bIncValid)
            {
                break;
            }
        }

        if (!bIncValid || code != UpdateRetCode.success)          //找不到inc文件
        {
            this.LogString("Pack has no list file: " + strPack);
            code = UpdateRetCode.pack_file_broken;
            reader.Release();
            yield return(code);    //
        }

        //计算进度
        long packSizeOverAll = m_VersionMan.CalcSize(verBegin, verLatest);

        if (packSizeOverAll <= 0)
        {
            packSizeOverAll = 1;
        }
        long packFinishedSize   = m_VersionMan.CalcSize(verBegin, m_CurrentVersion);
        long packNextFinishSize = m_VersionMan.CalcSize(verBegin, m_currentNewVer);

        float fFileProgress  = 0.0f;
        float fTotalProgress = (float)((packFinishedSize + (packNextFinishSize - packFinishedSize) * (double)fFileProgress) / (double)packSizeOverAll);

        UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.File, fFileProgress);
        UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.Total, fTotalProgress);
        //UpdateInfoUtil.SetWritingPackStatusString(fFileProgress);

        //新UI
        fileCount = reader.GetFileCount();
        if (fileCount > 0)
        {
            GameUpdateMan.Instance.HotUpdateViewer.SetInstallProgress(1, fileCount);
        }
        else
        {
            GameUpdateMan.Instance.HotUpdateViewer.SetInstallPercent(-1.0f);
        }

        yield return(null);

        //读取patch文件列表
        for (int iFile = 0; iFile < fileCount; ++iFile)
        {
            //新UI
            GameUpdateMan.Instance.HotUpdateViewer.SetInstallProgress(iFile + 1, fileCount);
            yield return(null);

            if (reader.IsDir(iFile))
            {
                continue;
            }

            string name = reader.GetFileName(iFile);

            //            LogString(HobaString.Format("7z pack file: {0}: {1}", iFile, name));
            if (string.IsNullOrEmpty(name))
            {
                this.LogString(HobaText.Format("Fail to get file name: {0}", iFile));
                code = UpdateRetCode.pack_file_broken;
                reader.Release();
                yield return(code);    //
            }

            if (name == "inc")      //skip inc
            {
                continue;
            }

            string strMd5;
            if (!fileIncList.GetFileMd5(name, out strMd5))
            {
                this.LogString(HobaText.Format("Fail to get file md5: {0} {1}", iFile, name));
                code = UpdateRetCode.pack_file_broken;
                reader.Release();
                yield return(code);        //
            }

            bool bInPack        = PackFunc.IsFileInPack(name); //是否属于指定的包
            bool bSameFileExist = false;

            if (bInPack)         //在包里的文件是否和更新文件md5一致,如果是则跳过更新
            {
                if (PackFunc.CalcPackFileMd5(name) == strMd5)
                {
                    bSameFileExist = true;
                }
            }
            if (bSameFileExist)
            {
                //if (iFile % (10 * 3) == 0)
                {
                    fFileProgress  = (float)(iFile + 1) / fileCount;
                    fTotalProgress = (float)(packFinishedSize + (packNextFinishSize - packFinishedSize) * fFileProgress) / packSizeOverAll;

                    UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.File, fFileProgress);
                    UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.Total, fTotalProgress);
                    //UpdateInfoUtil.SetWritingPackStatusString(fFileProgress);
                    GameUpdateMan.Instance.HotUpdateViewer.SetInstallProgress(fileCount, fileCount);

                    yield return(null);
                }
                continue;
            }

            //读取patch文件
            ExtractPackThreadInfo threadInfo = ExtractFileFrom7zReader(reader, iFile);
            while (threadInfo.IsRunning)
            {
                yield return(_ShortWait);
            }
            OnExtractFileComplete();

            int    dataSize = threadInfo.DataSize;
            IntPtr pData    = threadInfo.Pointer;

            if (pData == IntPtr.Zero)
            {
                this.LogString(HobaText.Format("Fail to extract file name: {0}", iFile));
                code = UpdateRetCode.pack_file_broken;
                reader.Release();
                yield return(code);        //
            }

            //检查md5
            //string memMd5 = FileOperate.CalcMemMd5(pData, dataSize);
            CalcMd5ThreadInfo calcMd5Info = CalcMemMd5(pData, dataSize);
            while (calcMd5Info.IsRunning)
            {
                yield return(_ShortWait);
            }
            OnCalcMd5Complete();
            string memMd5 = calcMd5Info.Md5;

            if (memMd5 != strMd5)
            {
                this.LogString(HobaText.Format("File md5 mismatch: {0} {1}", iFile, name));
                code = UpdateRetCode.pack_file_broken;
                reader.Release();
                yield return(code);        //
            }

            if (dataSize < 4)        //不是压缩文件
            {
                this.LogString(HobaText.Format("Compressed file has no header {0} {1}", iFile, name));
                code = UpdateRetCode.pack_file_broken;
                reader.Release();
                yield return(code);        //
            }

            if (bInPack) //add to package
            {
                this.WritePacking(true);
                bool retFlag = PackFunc.AddCompressedDataToPack(name, pData, dataSize);

                if (!retFlag)
                {
                    this.LogString(HobaText.Format("Update fail to add file: {0} {1}", iFile, name));
                    code = UpdateRetCode.pack_file_broken;
                    reader.Release();
                    yield return(code);        //
                }
                else
                {
                    //                  this.LogString(HobaString.Format("Success to add pack file: {0} {1}", iFile, name));
                    code = UpdateRetCode.success;
                }
            }
            else                   //解压,写文件
            {
                //使用更新目录, 将 AssetBundle/<Plaform> 和 AssetBundle/<Plaform>/Update 整合成AssetBundle
                string actualName;
                if (PackFunc.IsFileInAssetBundles(name))
                {
                    actualName = PackFunc.MakeShortAssetBundlesFileName(name);
                    //                    this.LogString(HobaString.Format("MakeShortAssetBundlesFileName: {0} {1} TO {2}", iFile, name, actualName));
                }
                else
                {
                    actualName = name;
                }

                UncompressToSepFileThreadInfo uncompressInfo = UncompressToSepFile(actualName, pData, dataSize);
                while (uncompressInfo.IsRunning)
                {
                    yield return(_ShortWait);
                }
                OnUncompressToSepFileComplete();

                bool retFlag = uncompressInfo.RetFlag;
                if (!retFlag)
                {
                    this.LogString(HobaText.Format("Update fail to uncompress file: {0} {1}", iFile, actualName));
                    code = UpdateRetCode.pack_file_broken;
                    reader.Release();
                    yield return(code);        //
                }
                else
                {
                    //                  this.LogString(HobaString.Format("Success to add sep file: {0} {1}", iFile, name));
                    code = UpdateRetCode.success;
                }
            }
        }

        reader.Release();

        PackFunc.FlushWritePack();
        if (!PackFunc.SaveAndOpenUpdatePack())
        {
            this.LogString(HobaText.Format("PackFunc.SaveAndOpenUpdatePack() Failed!!! {0}", strPack));
        }
        else
        {
            this.WritePacking(false);       //清除写包标志
        }

        yield return(code);        //
    }