示例#1
0
 public UnzipBaseResData(ResourceFileData fileData, long pos, long sourceSize)
 {
     FileData = fileData;
     StartPos = pos;
     //             SourcePath = path;
     SourceSize = sourceSize;
 }
示例#2
0
        /// <summary>
        /// 释放资源
        /// 文件结构 4x32 文件头 |32位记录路径长度|32位记录文件名|32位记录md5长度|32位记录文件大小|
        /// 然后根据这4个结构获取具体的路径、文件名、md5值、文件内容
        /// </summary>
        /// <returns></returns>
        public int UnzipRes()
        {
            UpdateLog.INFO_LOG(_TAG + "unzipRes()");

            int        ret           = CodeDefine.RET_SUCCESS;
            FileStream resFileStream = null;
            long       filePostion   = 0;
            long       fileSize      = 0;

            try
            {
                resFileStream = new FileStream(_resPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                fileSize      = resFileStream.Length;

                List <ResourceFileData> fileDataList = new List <ResourceFileData>();

                //启动线程池
                // var threadPool = new HttpThreadPool<UnzipData>(4, ThreadFunc);
                while (fileSize > 0 && filePostion < fileSize)
                {
                    ResourceFileData fileData = new ResourceFileData();

                    //4x32长度的头
                    fileData.DirLen   = int.Parse(read(resFileStream, 32, filePostion, out filePostion));
                    fileData.NameLen  = int.Parse(read(resFileStream, 32, filePostion, out filePostion));
                    fileData.Md5Len   = int.Parse(read(resFileStream, 32, filePostion, out filePostion));
                    fileData.FileSize = long.Parse(read(resFileStream, 32, filePostion, out filePostion));

                    //读取内容
                    fileData.Dir  = read(resFileStream, fileData.DirLen, filePostion, out filePostion);
                    fileData.Name = read(resFileStream, fileData.NameLen, filePostion, out filePostion);
                    fileData.Md5  = read(resFileStream, fileData.Md5Len, filePostion, out filePostion);

                    //跳过localversion的释放
                    if (fileData.Name.ToLower().Equals("localversion.xml"))
                    {
                        resFileStream.Seek(fileData.FileSize, SeekOrigin.Current);
                    }
                    else
                    {
                        writeFile(resFileStream, fileData.FileSize, fileData.Dir, fileData.Name);

                        //resFileStream.Seek(fileData.FileSize, SeekOrigin.Current);
                        //UnzipData ud = new UnzipData(fileData, filePostion, fileSize);
                        //threadPool.addTask(ud);
                    }
                    filePostion += fileData.FileSize;
                }

                //等待所有文件下载完
                //threadPool.waitWhileWorking();
            }
            catch (System.Exception ex)
            {
                ret = CodeDefine.RET_FAIL_UNZIP_RES_FILE;
                UpdateLog.ERROR_LOG(_TAG + ex.Message + "\n" + ex.StackTrace);
                UpdateLog.EXCEPTION_LOG(ex);
            }
            finally
            {
                if (resFileStream != null)
                {
                    resFileStream.Close();
                }
            }
            return(ret);
        }