Example #1
0
        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);
        }
Example #2
0
 static public string GetCRC32byteFormate(byte[] data)
 {
     return(string.Format("{0:X}", CRC32.GetCRC32byte(data)).ToUpper());
 }