예제 #1
0
        /// <summary>
        /// 读取AB包MD5文件,找出改变的ab包
        /// </summary>
        /// <param name="abmd5Path">ab包md5文件路径</param>
        /// <param name="hotCount">热更次数</param>
        static void ReadMd5Com(string abmd5Path, string hotCount)
        {
            m_PackedMD5.Clear();
            using (FileStream fs = new FileStream(abmd5Path, FileMode.Open, FileAccess.Read))
            {
                BinaryFormatter bf    = new BinaryFormatter();
                ABMD5           abmd5 = bf.Deserialize(fs) as ABMD5;
                foreach (ABMD5Base abmd5Base in abmd5.ABMD5List)
                {
                    m_PackedMD5.Add(abmd5Base.Name, abmd5Base);
                }
            }
            //搜集变化的AB包的list
            List <string> changeList = new List <string>();
            //获取当前AB包目录下的所有的AB包文件
            DirectoryInfo directory = new DirectoryInfo(m_BundleTargetPath);

            FileInfo[] files = directory.GetFiles("*", SearchOption.AllDirectories);

            for (int i = 0; i < files.Length; ++i)
            {
                //过滤meta文件和mainfest文件
                if (!files[i].Name.EndsWith(".meta") && !files[i].Name.EndsWith(".manifest"))
                {
                    string    name      = files[i].Name;
                    string    md5       = MD5Manager.Instance.BuildFileMd5(files[i].FullName);
                    ABMD5Base abmd5Base = null;
                    //新打的ab包
                    if (!m_PackedMD5.ContainsKey(name))
                    {
                        changeList.Add(name);
                    }
                    else
                    {
                        if (m_PackedMD5.TryGetValue(name, out abmd5Base))
                        {
                            //变化了的AB包
                            if (md5 != abmd5Base.Md5)
                            {
                                changeList.Add(name);
                            }
                        }
                    }
                }
            }

            CopyABAndGeneratXml(changeList, hotCount);
        }
예제 #2
0
        /// <summary>
        /// 读取本地资源MD5码
        /// </summary>
        void ReadMD5()
        {
            m_PackedMd5.Clear();
            TextAsset md5 = Resources.Load <TextAsset>("ABMD5");

            if (md5 == null)
            {
                Debug.LogError("未读取到本地MD5");
                return;
            }

            using (MemoryStream stream = new MemoryStream(md5.bytes))
            {
                BinaryFormatter bf    = new BinaryFormatter();
                ABMD5           abmd5 = bf.Deserialize(stream) as ABMD5;
                foreach (ABMD5Base abmd5Base in abmd5.ABMD5List)
                {
                    m_PackedMd5.Add(abmd5Base.Name, abmd5Base);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// 写入AB包的MD5信息
        /// </summary>
        static void WriteABMD5()
        {
            //获取AssetBundle文件夹下的所有信息
            DirectoryInfo directoryInfo = new DirectoryInfo(m_BundleTargetPath);

            FileInfo[] files = directoryInfo.GetFiles("*", SearchOption.AllDirectories);
            ABMD5      abmd5 = new ABMD5();

            abmd5.ABMD5List = new List <ABMD5Base>();
            for (int i = 0; i < files.Length; ++i)
            {
                //过滤meta文件和mainfest文件
                if (!files[i].Name.EndsWith(".meta") && !files[i].Name.EndsWith(".manifest"))
                {
                    ABMD5Base abmd5Base = new ABMD5Base();
                    abmd5Base.Name = files[i].Name;
                    abmd5Base.Md5  = MD5Manager.Instance.BuildFileMd5(files[i].FullName);
                    abmd5Base.Size = files[i].Length / 1024.0f;
                    abmd5.ABMD5List.Add(abmd5Base);
                }
            }

            string ABMD5Path = Application.dataPath + "/Resources/ABMD5.bytes";

            BinarySerializeOpt.BinarySerilize(ABMD5Path, abmd5);
            //将打包的版本拷贝到外部进行储存
            if (!Directory.Exists(m_VersionsMd5Path))
            {
                Directory.CreateDirectory(m_VersionsMd5Path);
            }
            string targetPath = m_VersionsMd5Path + "/ABMD5_" + PlayerSettings.bundleVersion + ".bytes";

            if (File.Exists(targetPath))
            {
                File.Delete(targetPath);
            }
            File.Copy(ABMD5Path, targetPath);
        }