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);
        }
        private string CaculateAssetBundleNameWithOutEncrypt(string directory, AssetImporter importer, string bundleName, string suffix)
        {
            //为了防止重名,如果不是需要直接加载的资源,计算路径的crc32 加入到bundlename里边
            if (string.IsNullOrEmpty(directory) || IsDirectoryInDataOrPackOrUgui(directory))
            {
                directory = string.Empty;
            }
            else
            {
                directory = GetCRC32(directory) + "_";
            }

            if (string.IsNullOrEmpty(bundleName))
            {
                Debug.LogError("error bundle name ,name is null or empty " + bundleName);
            }

            // fix bundle name
            var lastName = bundleName;
            var isChange = FixName(ref bundleName);

            if (isChange)
            {
                Debug.LogFormat("auto fix bundle name {0} to {1} ", lastName, bundleName);
            }
            CheckAutoFixedNameIsLegal(lastName, bundleName);
            //把路径的crc32编入到bundlename,如果是需要直接加载的资源,比如data 和 pack下的资源,不处理
            bundleName = directory + bundleName;

            for (int i = 0; i < m_AlwaysNullBundleNameSuffixList.Length; ++i)
            {
                if (importer.assetPath.EndsWith(m_AlwaysNullBundleNameSuffixList[i]))
                {
                    bundleName = null;
                    return(null);
                }
            }
            if (null != bundleName)
            {
                if (bundleName.Length > 100)
                {
                    Debug.LogWarning("bundle name too long " + bundleName);
                    bundleName = CRC32.GetCRC32Str(bundleName).ToString();
                    Debug.LogWarning("auto fix long bundle name to " + bundleName);
                }
                bundleName += suffix;
                bundleName  = bundleName.ToLower();
            }
            return(bundleName);
        }
        private string CaculateAssetBundleNameWithEncrypt(string directory, AssetImporter importer, string bundleName, string suffix)
        {
            bool needGenReport = false;

            if (string.IsNullOrEmpty(directory) || IsDirectoryInDataOrPackOrUgui(directory))
            {
                directory     = string.Empty;
                needGenReport = true;
            }

            if (string.IsNullOrEmpty(bundleName))
            {
                Debug.LogError("error bundle name ,name is null or empty " + bundleName);
                return(null);
            }

            bundleName = directory + bundleName;
            var lastName = bundleName;

            // caculate bundle name with crc32
            bundleName = CRC32.GetCRC32Str(bundleName).ToString();

            CheckAutoFixedNameIsLegal(lastName, bundleName);
            for (int i = 0; i < m_AlwaysNullBundleNameSuffixList.Length; ++i)
            {
                if (importer.assetPath.EndsWith(m_AlwaysNullBundleNameSuffixList[i]))
                {
                    bundleName = null;
                    return(null);
                }
            }
            if (null != bundleName)
            {
                if (bundleName.Length > 100)
                {
                    Debug.LogWarning("bundle name too long " + bundleName);
                    bundleName = CRC32.GetCRC32Str(bundleName).ToString();
                    Debug.LogWarning("auto fix long bundle name to " + bundleName);
                }
                bundleName += suffix;
                bundleName  = bundleName.ToLower();
                if (needGenReport)
                {
                    GenReport(lastName, bundleName);
                }
            }
            return(bundleName);
        }
 private string GetCRC32(string directory)
 {
     return(CRC32.GetCRC32Str(directory).ToString());
     // return directory.Replace('/', '_');
 }