private void BeginPackPackageResource(PackageResourceCompressType compressType, string sourceDirectory, string targetDirectory) { m_ReportConfig = new PackageResourceConfig(); m_ReportConfig.compressType = (int)compressType; m_ReportConfig.fileList = new List <string>(); // get compressor var compressor = PackageResourceCompressHelper.GetCompress(compressType); if (null == compressor) { Debug.LogError("Unsupport compress type " + compressType); return; } // sign list StringBuilder allFileCRC32Code = new StringBuilder(); // create file list var fileList = GetFileList(sourceDirectory, targetDirectory); for (int i = 0; i < fileList.Count; ++i) { var elem = fileList[i]; // load file to memory byte[] content = File.ReadAllBytes(elem.GetSourcePath()); // compess file with compress type content = CompressFile(content, compressor); // get crc32 allFileCRC32Code.Append(CRC32.GetCRC32byte(content)); // get output path string outputPath = elem.GetOutputPath(); // ensure folder PackageResourceTool.EnsureFolder(outputPath); // write file to target directory File.WriteAllBytes(outputPath, content); // update report m_ReportConfig.fileList.Add(elem.GetSubpath()); } // update report version m_ReportConfig.version = CRC32.GetCRC32Str(allFileCRC32Code.ToString()).ToString(); // save report file var reportFile = XmlConfigBase.Serialize(m_ReportConfig); File.WriteAllText(targetDirectory + m_strPackageResourceConfigName, reportFile); }
private void OnOneTaskDone(PackageResourceLoaderElement taskElem, PackageResourceWWWElement request) { do { if (request.GetError() != null) { taskElem.SetErrorInfo(request.GetError()); // release www request.GetRequest().Dispose(); // add to error list m_TaskErrorQueue.Enqueue(taskElem); break; } // check www content if (null == request.GetRequest().bytes) { taskElem.SetErrorInfo("load error"); // release www request.GetRequest().Dispose(); // add to error list m_TaskErrorQueue.Enqueue(taskElem); break; } try { byte[] content = request.GetRequest().bytes; if (null != m_Decompressor) { // decompress content = m_Decompressor.Decompress(content); } // ensure folder PackageResourceTool.EnsureFolder(taskElem.GetOutputPath()); // try write byte files System.IO.File.WriteAllBytes(taskElem.GetOutputPath(), content); // add to succeed list m_TaskSucceedQueue.Enqueue(taskElem); } catch (Exception e) { // mark error msg taskElem.SetErrorInfo(e.Message); // release www request.GetRequest().Dispose(); // add to error list m_TaskErrorQueue.Enqueue(taskElem); // check is need crash m_bIsCrash = true; CallbackWithError(); return; } }while (false); // check next CheckNext(taskElem); }