Esempio n. 1
0
    //关闭pck环境
    public UpdateRetCode ReleasePackages()
    {
        UpdateRetCode code = UpdateRetCode.success;

        PackFunc.PackFinalize(true);
        return(code);
    }
Esempio n. 2
0
    //初始化pck环境
    public UpdateRetCode InitPackages()
    {
        UpdateRetCode code = UpdateRetCode.success;

        bool ret = PackFunc.PackInitialize(false);

        if (!ret)
        {
            code = UpdateRetCode.pack_err;
        }

        return(code);
    }
Esempio n. 3
0
    private UncompressToSepFileThreadInfo UncompressToSepFile(string filename, IntPtr pData, int dataSize)
    {
        if (_UncompressToSepFileResult.IsRunning)
        {
            return(_UncompressToSepFileResult);
        }

        if (_UncompressToSepFileThread == null)
        {
            _UncompressToSepFileThread = new AssetUtility.SingleThreadWorker();
        }

        _UncompressToSepFileResult.IsRunning = true;
        _UncompressToSepFileThread.StartTask(() =>
        {
            _UncompressToSepFileResult.RetFlag   = PackFunc.UncompressToSepFile(filename, pData, dataSize);
            _UncompressToSepFileResult.IsRunning = false;
        });

        return(_UncompressToSepFileResult);
    }
Esempio n. 4
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);        //
    }
 public PackPair(PackFunc pack, UnpackFunc unpack)
 {
     Pack   = pack;
     Unpack = unpack;
 }