예제 #1
0
        //IFS工具处理 处理
        public void DoResIFSPackage(BuildTarget target, IFSCompressType ct = IFSCompressType.None, bool firstInclude = false, bool mergeLua = false, string luaZipName = "")
        {
            //SVN 版本号
            string svnVersion = EditorSvnHelper.DoSvnInfoRivision(JW.Res.FileUtil.CombinePaths(Application.dataPath, "Resources"));

            //合并Lua脚本
            if (mergeLua && (!string.IsNullOrEmpty(luaZipName)))
            {
                IFSArchiver.ArchiveDir(JW.Res.FileUtil.CombinePaths(_ifsBuildPath, GetPlatformStr(target), "LuaScripts"),
                                       JW.Res.FileUtil.CombinePaths(_ifsBuildPath, GetPlatformStr(target), luaZipName), IFSCompressType.None);
                //删除散lua 脚本
                JW.Res.FileUtil.DeleteDirectory(JW.Res.FileUtil.CombinePaths(_ifsBuildPath, GetPlatformStr(target), "LuaScripts"));
            }
            //生成文件列表
            IFSTool.GenerateFileList(JW.Res.FileUtil.CombinePath(_ifsBuildPath, GetPlatformStr(target)), _ifsFileListName, svnVersion);
            string dd      = JW.Res.FileUtil.CombinePath(_ifsBuildPath, GetPlatformStr(target));
            string zipPath = JW.Res.FileUtil.CombinePath(_ifsBuildPath, _ifsZipFileName);

            IFSTool.GenerateFirstIFSFile(zipPath, dd, ct);
            if (firstInclude)
            {
                //copy
                IFSTool.MoveFirstIFSFileToStreamingAssets(zipPath);
            }
            //移动Zip到原本目录
            if (JW.Res.FileUtil.IsFileExist(zipPath))
            {
                string fileName = JW.Res.FileUtil.GetFullName(zipPath);
                string dir      = JW.Res.FileUtil.CombinePath(_ifsBuildPath, GetPlatformStr(target));
                string dstPath  = JW.Res.FileUtil.CombinePath(dir, _ifsZipFileName);
                JW.Res.FileUtil.MoveFile(zipPath, dstPath);
            }
        }
 //条目名称长度
 private bool DealEntryNameLength()
 {
     if (_waitToDealBytes.Count > 4)
     {
         byte[] dd = _waitToDealBytes.GetRange(0, 4).ToArray();
         _dealOffset      = 0;
         _entryNameLength = IFSArchiver.ConvertBytesToInt(dd, ref _dealOffset);
         _waitToDealBytes.RemoveRange(0, 4);
         JW.Common.Log.LogD("Get EntryName Length:{0}", _entryNameLength);
         dd = null;
         if (_entryNameLength <= 0)
         {
             JW.Common.Log.LogE("Get Error EntryName Length");
             _isError = true;
             return(false);
         }
         else
         {
             //条目名称段
             _ifsFile.Entrys = new IFSEntry[_ifsFile.EntryCount];
             for (int i = 0; i < _ifsFile.EntryCount; i++)
             {
                 _ifsFile.Entrys[i] = new IFSEntry();
             }
             return(true);
         }
     }
     return(false);
 }
 //处理签名获取数据
 private bool DealSignatureData()
 {
     if (_waitToDealBytes.Count > 4)
     {
         byte[] dd = _waitToDealBytes.GetRange(0, 4).ToArray();
         _dealOffset = 0;
         uint sig = (uint)IFSArchiver.ConvertBytesToInt(dd, ref _dealOffset);
         //
         _waitToDealBytes.RemoveRange(0, 4);
         //
         if (sig != IFSFile.IFSSignature)
         {
             JW.Common.Log.LogE("IFSDownloader DealSignatureData Error Signature ");
             //
             _isError = true;
             return(false);
         }
         else
         {
             JW.Common.Log.LogD("Get Signature:{0:X}", sig);
             return(true);
         }
     }
     return(false);
 }
예제 #4
0
 /// <summary>
 /// 生成IFS 的首次Zip包
 /// </summary>
 /// <param name="ifsBuildDir"></param>
 /// <param name="firstName"></param>
 public static void GenerateFirstIFSFile(string firstNamePath, string ifsBuildDir, IFSCompressType tt = IFSCompressType.None)
 {
     if (!JW.Res.FileUtil.IsDirectoryExist(ifsBuildDir))
     {
         JW.Common.Log.LogE("Dir Not Exist:" + ifsBuildDir);
     }
     IFSArchiver.ArchiveDir(ifsBuildDir, firstNamePath, tt);
 }
        //处理条目文件数据
        private bool DealEntryDatas()
        {
            if (_waitToDealBytes.Count > 4 && (_dealEntryDataIndex < _ifsFile.EntryCount))
            {
                //数据长度
                _dealOffset = 0;
                IFSEntry entry = _ifsFile.Entrys[_dealEntryDataIndex];
                byte[]   ll    = _waitToDealBytes.GetRange(0, 4).ToArray();;
                int      vv    = IFSArchiver.ConvertBytesToInt(ll, ref _dealOffset);
                entry.DataSize = vv;
                if (_waitToDealBytes.Count >= (4 + vv))
                {
                    string outPath   = JW.Res.FileUtil.CombinePaths(_unarchiveDir, entry.Name);
                    string directory = Path.GetDirectoryName(outPath);
                    if (!Directory.Exists(directory))
                    {
                        Directory.CreateDirectory(directory);
                    }
                    //数据
                    byte[] fileDd = _waitToDealBytes.GetRange(4, vv).ToArray();

                    if (_ifsFile.CompressType == IFSCompressType.None)
                    {
                        //
                        JW.Res.FileUtil.DeleteFile(outPath);
                        //
                        FileStream output = new FileStream(outPath, FileMode.Create);
                        try
                        {
                            output.Write(fileDd, 0, vv);
                            output.Flush();
                        }
                        finally
                        {
                            output.Close();
                            output.Dispose();
                            output = null;
                        }
                    }
                    else if (_ifsFile.CompressType == IFSCompressType.LZMA)
                    {
                        //LZMA 数据
                        UnLzmaDataToFile(outPath, fileDd, vv);
                    }
                    //
                    _dealEntryDataIndex++;
                    //移除
                    _waitToDealBytes.RemoveRange(0, vv + 4);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }
 //获取压缩方式
 private bool DealCompressType( )
 {
     if (_waitToDealBytes.Count > (4))
     {
         byte[] dd = _waitToDealBytes.GetRange(0, 4).ToArray();
         _dealOffset           = 0;
         _ifsFile.CompressType = (IFSCompressType)IFSArchiver.ConvertBytesToInt(dd, ref _dealOffset);
         _waitToDealBytes.RemoveRange(0, 4);
         JW.Common.Log.LogD("Get CompressType:{0}", _ifsFile.CompressType.ToString());
         return(true);
     }
     return(false);
 }
 //条目数据位置信息
 private bool DealEntryDataPos()
 {
     if (_waitToDealBytes.Count > (_ifsFile.EntryCount * 4))
     {
         byte[] poss = _waitToDealBytes.GetRange(0, _ifsFile.EntryCount * 4).ToArray();
         _dealOffset = 0;
         for (int i = 0; i < _ifsFile.EntryCount; i++)
         {
             IFSEntry entry = _ifsFile.Entrys[i];
             int      vv    = IFSArchiver.ConvertBytesToInt(poss, ref _dealOffset);
             entry.DataPos = vv;
         }
         _waitToDealBytes.RemoveRange(0, _ifsFile.EntryCount * 4);
         poss = null;
         return(true);
     }
     return(false);
 }
 //处理条目名称
 private bool DealEntryNames()
 {
     if (_waitToDealBytes.Count > _entryNameLength)
     {
         byte[] names = _waitToDealBytes.GetRange(0, _entryNameLength).ToArray();
         _dealOffset = 0;
         //读取条目名称
         for (int i = 0; i < _ifsFile.EntryCount; i++)
         {
             IFSEntry entry = _ifsFile.Entrys[i];
             entry.Name = IFSArchiver.ConvertBytesToString(names, ref _dealOffset);
             JW.Common.Log.LogD("Get Entry Name:" + entry.Name);
         }
         //
         _waitToDealBytes.RemoveRange(0, _entryNameLength);
         //
         names = null;
         return(true);
     }
     return(false);
 }
        //条目个数
        private bool DealEntryCnt()
        {
            if (_waitToDealBytes.Count > 4)
            {
                byte[] dd = _waitToDealBytes.GetRange(0, 4).ToArray();
                _dealOffset         = 0;
                _ifsFile.EntryCount = IFSArchiver.ConvertBytesToInt(dd, ref _dealOffset);
                _waitToDealBytes.RemoveRange(0, 4);
                JW.Common.Log.LogD("Get EntryCount:{0}", _ifsFile.EntryCount);

                if (_ifsFile.EntryCount <= 0)
                {
                    JW.Common.Log.LogE("Get Error EntryCount");
                    _isError = true;
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            return(false);
        }
        //首次移动或者下载
        IEnumerator DoFirstMoveOrDownload()
        {
            bool isNeedMove = false;

            if (!JW.Res.FileUtil.IsExistInIFSExtraFolder(_curSession.FileListFileName))
            {
                isNeedMove = true;
            }
            //--------------------移动或者下载--------
            if (isNeedMove)
            {
                string filePath   = "";
                bool   isDownload = false;
                //存在
                if (JW.Res.FileUtil.IsFileExistInStreamingAssets(_curSession.FirstZipName))
                {
                    CallSessionHandler(IFSState.FirstMoveInit, 0);
                    filePath = JW.Res.FileUtil.GetStreamingAssetsPathWithHeader(_curSession.FirstZipName);
                }
                else
                {
                    isDownload = true;
                    filePath   = _curSession.FirstZipURL;
                    CallSessionHandler(IFSState.FirstDownloadInit, 0);
                }
                JW.Common.Log.LogD("DoFirstMoveOrDownload:" + filePath);
                yield return(null);

                if (!string.IsNullOrEmpty(filePath))
                {
                    string ifsDirPath = JW.Res.FileUtil.GetIFSExtractPath();
                    if (!JW.Res.FileUtil.IsDirectoryExist(ifsDirPath))
                    {
                        JW.Common.Log.LogD("Create IFS Dir " + ifsDirPath);
                        JW.Res.FileUtil.CreateDirectory(ifsDirPath);
                    }
                    //非android 直接解压
                    if (false)//isDownload==false && (Application.platform== RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.WindowsPlayer|| Application.platform == RuntimePlatform.WindowsEditor))
                    {
                        CallSessionHandler(IFSState.FirstUnZip, 0f);
                        string pp = JW.Res.FileUtil.GetStreamingAssetsPath(_curSession.FirstZipName);
                        IFSArchiver.SyncUnarchiveIFSFile(pp, ifsDirPath, false);
                        CallSessionHandler(IFSState.FirstUnZip, 1f);
                    }
                    else
                    {
                        //边下载边解档
                        IFSFileDownloader www = new IFSFileDownloader(filePath, ifsDirPath);
                        _cachedDownloader = www;
                        //
                        CallSessionHandler(isDownload ? IFSState.FirstDownloading : IFSState.FirstMoving, 0);
                        //
                        www.Begin();
                        while (www.IsDone == false)
                        {
                            www.Update();
                            CallSessionHandler(isDownload ? IFSState.FirstDownloading : IFSState.FirstMoving, www.Progress);
                            yield return(null);
                        }
                        if (www.IsError == false)
                        {
                            CallSessionHandler(isDownload ? IFSState.FirstDownloading : IFSState.FirstMoving, 1.0f);
                            yield return(null);

                            CallSessionHandler(IFSState.FirstUnZip, 0f);
                            yield return(null);

                            CallSessionHandler(IFSState.FirstUnZip, 1.0f);
                        }
                        else
                        {
                            JW.Common.Log.LogE("IFSService DoFirstMoveOrDownload Error");
                            _errorCnt++;
                            CallSessionHandler(isDownload ? IFSState.FirstDownloadFailed : IFSState.FirstMoveFailed, 1.0f);
                        }
                        www.Dispose();
                        www = null;
                        _cachedDownloader = null;
                    }
                }
                else
                {
                    JW.Common.Log.LogE("IFSService DoFirstMoveOrDownload Error FilePATH");
                    CallSessionHandler(isDownload ? IFSState.FirstDownloadFailed : IFSState.FirstMoveFailed, 1.0f);
                }
            }
            else
            {
                JW.Common.Log.LogD("No Need Move!");
            }
            yield return(null);
        }