コード例 #1
0
    /// <summary>
    /// 以md5标识命名资源包
    /// </summary>
    static void NameMD5Files()
    {
        var strArr = mIManifest.GetAllAssetBundles();

        //添加依赖表的加密路径,妈蛋不要了,自己做依赖!
        //arr.Add(GetPlatformFloder());
        //arr.Add(GetPlatformFloder() + ".manifest");
        mStringBuilder.Remove(0, mStringBuilder.Length);

        StringBuilder("<root version='", mVersion, "'>");
        for (int i = 0; i < strArr.Length; i++)
        {
            string name = strArr[i];
            if (name == "a811bde74b26b53498b4f6d872b09b6d")
            {
                Debug.LogError(" 找到a811bde74b26b53498b4f6d872b09b6d !!");
            }

            string oriPath = m_RootDirectory + "/" + strArr[i];

            //如果文件不存在
            if (!File.Exists(oriPath))
            {
                var lowName = name.ToLower();
                if (mCacheAssetBund.ContainsKey(lowName))
                {
                    var cache = mCacheAssetBund[lowName];
                    StringBuilder("<asset name='", lowName, "' md5='", cache.md5, "' size='", cache.size, "' path='", cache.path, "'/>");
                }
                else
                {
                    Debug.LogError("错误!!预重命名路径文件不存在=> " + oriPath);
                    continue;
                }
            }
            else
            {
                byte[] bytes = File.ReadAllBytes(oriPath);
                var    hash  = GetMd5(bytes);
                int    size  = bytes.Length / 1024;
                var    index = name.LastIndexOf("/");
                //获取Asset下路径
                string path    = (index == -1) ? "" : name.Substring(0, index);
                string newPath = (path == "") ? m_RootDirectory + "/" + hash : m_RootDirectory + "/" + path + "/" + hash;
                //        Debug.LogError("重命名 odl Name " + name + " new Path " + newPath);
                StringBuilder("<asset name='", name.ToLower(), "' md5='", hash, "' size='", size, "' path='", path, "'/>");

                File.Move(oriPath, newPath);
            }
        }
        string mf_path    = m_RootDirectory + "/Manifest.xml";
        var    mf_bytes   = File.ReadAllBytes(mf_path);
        var    mf_hash    = GetMd5(mf_bytes);
        var    mf_size    = mf_bytes.Length / 1024;
        var    mf_newpath = m_RootDirectory + "/" + mf_hash;

        StringBuilder("<asset name='", "Manifest", "' md5='", mf_hash, "' size='", mf_size, "' path='", "", "'/>");
        File.Move(mf_path, mf_newpath);
        StringBuilder("</root>");

        XmlDocument xml = new XmlDocument();

        xml.LoadXml(mStringBuilder.ToString());
        xml.Save(m_RootDirectory + "/ResVersion.xml");
        xml.Save(Application.persistentDataPath + "/ResVersion.xml");
    }