示例#1
0
        /// <summary>
        /// get Md5 or normal filename
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static string GetRightFileName(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(string.Empty);
            }

#if !HUGULA_COMMON_ASSETBUNDLE
            int lastFileIndex, lastDotIndex, fileLen, suffixLen;
            AnalysePathName(fileName, out lastFileIndex, out fileLen, out lastDotIndex, out suffixLen);

            string fname = fileName.Substring(lastFileIndex + 1, fileLen);
            string md5   = string.Empty;
            md5            = CryptographHelper.Md5String(fname);
            _textSB.Length = 0;
            _textSB.Append(fileName);
            if (fileLen > 0)
            {
                _textSB.Replace(fname, md5, lastFileIndex + 1, fileLen);
            }
            fname = _textSB.ToString();
            return(fname);
#else
            return(fileName);
#endif
        }
示例#2
0
文件: CUtils.cs 项目: yinlei/hugula
        /// <summary>
        /// get Md5 or normal filename
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static string GetRightFileName(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(string.Empty);
            }
            string fname = string.Empty;

            int lastFileIndex, lastDotIndex, fileLen, suffixLen;

            AnalysePathName(fileName, out lastFileIndex, out fileLen, out lastDotIndex, out suffixLen);
            if (lastFileIndex > 0)
            {
                fname = fileName.Substring(0, lastFileIndex + 1);
            }

#if BUILD_COMMON_ASSETBUNDLE
            fname += fileName.Substring(lastFileIndex + 1, fileLen);
#else
            fname += CryptographHelper.Md5String(fileName.Substring(lastFileIndex + 1, fileLen));
#endif
            if (suffixLen > 0)
            {
                fname += fileName.Substring(lastDotIndex, suffixLen);
            }
            return(fname);
        }
示例#3
0
        public static void GenerateAssetBundlesMd5Mapping(string[] allAssets)
        {
            string info = "Generate AssetBundles Md5Mapping ";

            EditorUtility.DisplayProgressBar("GenerateAssetBundlesMd5Mapping", info, 0);
            string        speciallyPath = "Assets/Config/Lan/";
            string        luaPath       = "Assets/Lua/";
            AssetImporter import        = null;
            float         i             = 0;
            float         allLen        = allAssets.Length;
            string        name          = "";
            string        nameMd5       = "";

            //name mapping
            StringBuilder nameSb = new StringBuilder();

            //asset map
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("return {");

            foreach (string path in allAssets)
            {
                import = AssetImporter.GetAtPath(path);
                string line = string.Empty;

                if (import != null && string.IsNullOrEmpty(import.assetBundleName) == false)
                {
                    // Object s = AssetDatabase.LoadAssetAtPath(path, typeof(Object));
                    name = CUtils.GetAssetName(path).ToLower();

                    if (string.IsNullOrEmpty(import.assetBundleVariant))
                    {
                        line = "[\"" + import.assetBundleName + "\"] = { name = \"" + name + "\", path = \"" + path + "\"},";
                    }
                    else
                    {
                        line = "[\"" + import.assetBundleName + "." + import.assetBundleVariant + "\"] = { name = \"" + name + "\", path = \"" + path + "\"},";
                    }

                    sb.AppendLine(line);
                    nameSb.AppendFormat("{0}={1}\r\n", CryptographHelper.Md5String(name), name);
                    if (name.Contains(" "))
                    {
                        Debug.LogWarning(name + " contains space");
                    }
                }
                else if (import != null && path.Contains(speciallyPath))
                {
                    name = CUtils.GetAssetName(path).ToLower();
                    string md5name = CryptographHelper.Md5String(name) + Common.CHECK_ASSETBUNDLE_SUFFIX;
                    line = "[\"" + md5name + "\"] = { name = \"" + name + "\", path = \"" + path + "\"},";
                    sb.AppendLine(line);
                    nameSb.AppendFormat("{0}={1}\r\n", md5name, name);
                }
                else if (import != null && path.Contains(luaPath))
                {
                    string luaname    = path.Replace(luaPath, "").Replace("\\", ".").Replace("/", ".");
                    string luacname   = luaname.Replace(".lua", "").Replace(".", "+");
                    string luaMd5Name = CryptographHelper.Md5String(luacname);
                    line = "[\"" + luaMd5Name + "\"] = { name = \"" + luaname + "\", path = \"" + path + "\"},";
                    sb.AppendLine(line);
                    nameSb.AppendFormat("{0}={1}\r\n", luaMd5Name, luaname);
                }
                EditorUtility.DisplayProgressBar("Generate AssetBundles Md5Mapping", info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen);

                i++;
            }

            string[] special = new string[] { CUtils.platform, Common.CONFIG_CSV_NAME, Common.CRC32_FILELIST_NAME, Common.CRC32_VER_FILENAME };
            foreach (string p in special)
            {
                name    = EditorUtils.GetAssetBundleName(p);
                nameMd5 = CUtils.GetRightFileName(name);
                string line = "[\"" + nameMd5 + "\"] ={ name = \"" + name + "\", path = \"" + p + "\" },";
                sb.AppendLine(line);
                nameSb.AppendFormat("{0}={1}\r\n", CryptographHelper.Md5String(name), name);
            }

            sb.AppendLine("}");
            string tmpPath = Path.Combine(Application.dataPath, EditorUtils.TmpPath);

            EditorUtils.CheckDirectory(tmpPath);
            EditorUtility.DisplayProgressBar("Generate AssetBundles Md5Mapping", "write file to Assets/" + EditorUtils.TmpPath + "Md5Mapping.txt", 0.99f);

            string outPath = Path.Combine(tmpPath, "md5_asset_mapping.txt");

            Debug.Log("write to path=" + outPath);
            using (StreamWriter sr = new StreamWriter(outPath, false)) {
                sr.Write(sb.ToString());
            }

            outPath = Path.Combine(tmpPath, "md5_name_mapping.txt");
            Debug.Log("write to path=" + outPath);
            using (StreamWriter sr = new StreamWriter(outPath, false)) {
                sr.Write(nameSb.ToString());
            }
            EditorUtility.ClearProgressBar();
            Debug.Log(info + " Complete! Assets/" + EditorUtils.TmpPath + "md5_asset_mapping.txt");
        }