Example #1
0
 public void CheckMD5Call(OneABClassInfo newClassInfo, ABState aBState, List <string> NeedDownList)
 {
     this.newClassInfo = newClassInfo;
     this.aBState      = aBState;
     this.NeedDownList = NeedDownList;
     CalculateSize();
 }
 public void LoadDataSet()
 {
     Debug.Log("OneABClassInfo路径:" + ABHotUpdate.Instance.GetSavePathByClass(Key, false));
     oneABClassInfo = FileHelper.ReadJsonTxtToObject <OneABClassInfo>(ABHotUpdate.Instance.GetSavePathByClass(Key, false));
     isDataSetReady = true;
     Debug.Log(oneABClassInfo.dataSetInfos);
 }
Example #3
0
        /// <summary>
        /// 下载云端MD5文件与本地MD5对比
        /// </summary>
        /// <param name="ResClass"></param>
        /// <param name="processEvent">如果不是AR的AB,那么久需要直接下载,这里是AB包下载进度回调</param>
        /// <param name="aBMD5CallBack">MD5下载完成后的回调,会将结果传回去</param>
        /// <param name="isHasRecog"></param>
        public void ABMD5Request(string ResClass, ABProcessEvent processEvent, ABMD5CallBack aBMD5CallBack = null, bool isHasRecog = false)
        {
            OneABClassInfo oldClassInfo = SerializeHelper.FromJson <OneABClassInfo>(FileHelper.ReadTxtToStr(GetSavePathByClass(ResClass, false)));

            AddDownload(ResClass, true, ABDataHolder.Instance.GetMD5DownURL() + ResClass + "Info.txt");
            DownManager.Instance.StartDownABMD5(ABClassDownInfo.Allocate(ResClass,
                                                                         ABDataHolder.Instance.GetMD5DownURL() + ResClass + "Info.txt",
                                                                         GetSavePathByClass(ResClass, true), true, aBMD5CallBack, ABMD5ResultCallback, processEvent, oldClassInfo, isHasRecog));
        }
Example #4
0
 public void OnRecycled()
 {
     IsRecycled     = true;
     ResClass       = "";
     ABMD5Callback  = null;
     ABprocessevent = null;
     oldClassInfo   = null;
     newClassInfo   = null;
     NeedDownList   = null;
     IsDownFinish   = false;
     CurSize        = 0;
     totalSize      = 0;
     allprocess     = 0;
 }
Example #5
0
        public static ABClassDownInfo Allocate(string ResClass, string m_srcUrl, string m_savePath, bool isMD5File,
                                               ABMD5CallBack aBMD5CallBack, ABMD5CallBack aBMD5CallBackLocal, ABProcessEvent ABprocessevent,
                                               OneABClassInfo OldABClassinfo = null, bool isHasRecog = false)
        {
            ABClassDownInfo aBDownInfo = SafeObjectPool <ABClassDownInfo> .Instance.Allocate();

            aBDownInfo.ResClass           = ResClass;
            aBDownInfo.oldClassInfo       = OldABClassinfo;
            aBDownInfo.isHasRecog         = isHasRecog;
            aBDownInfo.m_srcUrl           = m_srcUrl;
            aBDownInfo.m_savePath         = m_savePath;
            aBDownInfo.isMD5File          = isMD5File;
            aBDownInfo.ABMD5Callback      = aBMD5CallBack;
            aBDownInfo.ABMD5CallbackLocal = aBMD5CallBackLocal;
            aBDownInfo.ABprocessevent     = ABprocessevent;
            return(aBDownInfo);
        }
Example #6
0
        public override void DownloadFinish()
        {
            base.DownloadFinish();
            ABClassDownInfo aBDownInfo        = (ABClassDownInfo)httpInfo;
            OneABClassInfo  NewABInfo         = SerializeHelper.FromJson <OneABClassInfo>(FileHelper.ReadTxtToStr(m_saveFilePath));
            List <string>   downStr           = new List <string>();
            bool            isLocalABComplete = true;
            bool            isNeedHot         = false;

            if (aBDownInfo.oldClassInfo != null)
            {
                List <string> keys = new List <string>(NewABInfo.FileMD5.Keys);
                for (int i = 0; i < keys.Count; i++)
                {
                    if (aBDownInfo.oldClassInfo.FileMD5.ContainsKey(keys[i]))
                    {
                        if (NewABInfo.FileMD5[keys[i]].Equals(aBDownInfo.oldClassInfo.FileMD5[keys[i]])) //  MD5相等
                        {
                            if (!FileHelper.JudgeFilePathExit(PathTool.PersistentDataPath + keys[i]))    //本地没有AB存在
                            {
                                AFLogger.d("检测MD5:本地没有AB存在111");
                                isLocalABComplete = false; //本地AB包不完整
                                isNeedHot         = true;
                                downStr.Add(keys[i]);
                            }
                        }
                        else
                        {
                            isNeedHot = true;
                            downStr.Add(keys[i]);
                            if (!FileHelper.JudgeFilePathExit(PathTool.PersistentDataPath + "/" + keys[i])) //本地没有AB存在
                            {
                                AFLogger.d("检测MD5:本地没有AB存在222");
                                isLocalABComplete = false; //本地AB包不完整
                            }
                        }
                    }
                    else
                    {
                        isLocalABComplete = false; //本地AB包不完整
                        isNeedHot         = true;
                        downStr.Add(keys[i]);
                    }
                }
            }
            else
            {
                isLocalABComplete = false;
                isNeedHot         = true;
                List <string> keys = new List <string>(NewABInfo.FileMD5.Keys);
                for (int i = 0; i < keys.Count; i++)
                {
                    FileHelper.DeleteFile(PathTool.PersistentDataPath + "/" + keys[i]);
                    downStr.Add(keys[i]);
                }
            }
            if (aBDownInfo.ABMD5Callback != null)
            {
                ABState aBState = ABState.Newest;
                if (isNeedHot)
                {
                    if (isLocalABComplete)
                    {
                        aBState = ABState.UpdateAndLocalComplete;
                    }
                    else
                    {
                        aBState = ABState.UpdateAndLocalNotComplete;
                    }
                }
                aBDownInfo.CheckMD5Call(NewABInfo, aBState, downStr);
                aBDownInfo.ABMD5CallbackLocal(aBDownInfo, downResult, downError);
            }
        }
        /// <summary>
        /// AB包打包完成后执行的函数,这里是将AB包移到指定的路径并生成对应的info文件
        /// </summary>
        /// <param name="mTargetPath">AB包目标路径,可以在ABCommonPath脚本中设置</param>
        /// <param name="m_BunleTargetPath">AB包初步路径</param>
        /// <param name="abConfig"></param>
        /// <param name="mInfoPath">info信息文件路径</param>
        /// <param name="AppInfoConfig"></param>
        public static void BundleFinish(string mTargetPath, string m_BunleTargetPath, AF_ABConfig abConfig, string mInfoPath, AppInfoConfig AppInfoConfig)
        {
            //一个类别对应的info
            Dictionary <string, OneABClassInfo> ClassToInfo    = new Dictionary <string, OneABClassInfo>();
            Dictionary <string, bool>           ClassToAppType = new Dictionary <string, bool>();
            Dictionary <string, string>         ABNameToPath   = new Dictionary <string, string>();

            for (int i = 0; i < abConfig.m_AllClass.Count; i++)
            {
                string classStr = abConfig.m_AllClass[i].ABClassType;
                ClassToAppType.Add(classStr, abConfig.m_AllClass[i].isSameAppType(abConfig.CurrentAppType));
                OneABClassInfo oneClassInfo = new OneABClassInfo();
                oneClassInfo.RecogType = abConfig.m_AllClass[i].ARrecogType;
                switch (oneClassInfo.RecogType)
                {
                case ARRecogType.DataSet:
                    List <OneDataSetInfo> dataSetInfos = new List <OneDataSetInfo>();
                    foreach (OneDataSet oneDataSet in abConfig.m_AllClass[i].dataSetList)
                    {
                        OneDataSetInfo oneDataSetInfo = new OneDataSetInfo();
                        oneDataSetInfo.TargetDataSet = oneDataSet.TargetDataSetName;
                        //记录识别图资料
                        oneDataSetInfo.TargetInfo = new Dictionary <string, OneTargetInfo>();
                        char[] t           = abConfig.defaultDataSetPath.ToCharArray();
                        string dataSetPath = abConfig.defaultDataSetPath;
                        if (t[t.Length - 1] != '/')
                        {
                            dataSetPath += "/";
                        }
                        string targetDataSetName = oneDataSet.TargetDataSetName;
                        string xmlMD5            = "";
                        string datMD5            = "";
                        if (abConfig.packageABType == PackageABType.StreamingAssetAB)
                        {
                            string vuforiaPath = Application.streamingAssetsPath + "/Vuforia/";
                            Directory.CreateDirectory(vuforiaPath);
                            //拷贝识别资源
                            if (!FileHelper.CopyFile(dataSetPath +
                                                     targetDataSetName
                                                     + ".xml", vuforiaPath + targetDataSetName + ".xml"))
                            {
                                break;
                            }
                            xmlMD5 = FileHelper.getFileHash(vuforiaPath + targetDataSetName + ".dat");
                            if (!FileHelper.CopyFile(dataSetPath +
                                                     targetDataSetName
                                                     + ".dat", vuforiaPath + targetDataSetName + ".dat"))
                            {
                                break;
                            }
                            datMD5 = FileHelper.getFileHash(vuforiaPath + targetDataSetName + ".xml");

                            if (!oneClassInfo.ABName.ContainsKey(targetDataSetName + ".xml") &&
                                !oneClassInfo.ABName.ContainsKey(targetDataSetName + ".dat"))
                            {
                                //将识别资源添加到ABName中,因为也是要下载的,同时记录其大小
                                oneClassInfo.ABName.Add(targetDataSetName + ".xml",
                                                        FileHelper.GetFileSize(vuforiaPath + targetDataSetName + ".xml"));
                                oneClassInfo.ABName.Add(targetDataSetName + ".dat",
                                                        FileHelper.GetFileSize(vuforiaPath + targetDataSetName + ".dat"));
                            }
                        }
                        else
                        {
                            //拷贝识别资源
                            if (!FileHelper.CopyFile(dataSetPath +
                                                     targetDataSetName
                                                     + ".xml", mTargetPath + targetDataSetName + ".xml"))
                            {
                                break;
                            }
                            xmlMD5 = FileHelper.getFileHash(dataSetPath +
                                                            targetDataSetName
                                                            + ".xml");

                            if (!FileHelper.CopyFile(dataSetPath
                                                     + targetDataSetName + ".dat",
                                                     mTargetPath + targetDataSetName + ".dat"))
                            {
                                break;
                            }
                            datMD5 = FileHelper.getFileHash(dataSetPath +
                                                            targetDataSetName + ".dat");

                            if (!oneClassInfo.ABName.ContainsKey(targetDataSetName + ".xml") &&
                                !oneClassInfo.ABName.ContainsKey(targetDataSetName + ".dat"))
                            {
                                //将识别资源添加到ABName中,因为也是要下载的,同时记录其大小
                                oneClassInfo.ABName.Add(targetDataSetName + ".xml",
                                                        FileHelper.GetFileSize(mTargetPath + targetDataSetName + ".xml"));
                                oneClassInfo.ABName.Add(targetDataSetName + ".dat",
                                                        FileHelper.GetFileSize(mTargetPath + targetDataSetName + ".dat"));
                            }
                        }

                        //添加识别资源的MD5码,
                        if (!oneClassInfo.FileMD5.ContainsKey(targetDataSetName + ".xml") &&
                            !oneClassInfo.FileMD5.ContainsKey(targetDataSetName + ".dat"))
                        {
                            // Debug.Log("第一次添加xml MD5:" + CategoryOfOwnershipS + " " + targetDataSetName);
                            oneClassInfo.FileMD5.Add(targetDataSetName + ".xml", xmlMD5);
                            oneClassInfo.FileMD5.Add(targetDataSetName + ".dat", datMD5);
                        }
                        else
                        {
                            //是已经打包过的类别
                            // Debug.Log("重复添加xml MD5:" + CategoryOfOwnershipS + " " + targetDataSetName);
                        }
                        if (!ABNameToPath.ContainsKey(targetDataSetName + ".xml") &&
                            !ABNameToPath.ContainsKey(targetDataSetName + ".dat"))
                        {
                            ABNameToPath.Add(targetDataSetName + ".xml", classStr + "/" + targetDataSetName + ".xml");
                            ABNameToPath.Add(targetDataSetName + ".dat", classStr + "/" + targetDataSetName + ".dat");
                        }


                        for (int j = 0; j < oneDataSet.mImagetTargetInfo.Count; j++)
                        {
                            oneDataSetInfo.TargetInfo.Add(oneDataSet.mImagetTargetInfo[j].ImageTargetName, oneDataSet.mImagetTargetInfo[j]);
                        }
                        dataSetInfos.Add(oneDataSetInfo);
                    }
                    oneClassInfo.dataSetInfos = dataSetInfos;
                    break;

                case ARRecogType.Plane:
                    oneClassInfo.ResInfoForPlane = abConfig.m_AllClass[i].ResInfoForPlane;
                    break;
                }
                oneClassInfo.isNeedPackageAB = abConfig.m_AllClass[i].isNeedPackageAB;
                ClassToInfo.Add(classStr, oneClassInfo);
            }
            List <AF_OneAB> allAB = new List <AF_OneAB>();

            foreach (AF_OneAB oneAB in abConfig.m_AllFileAB)
            {
                allAB.Add(oneAB);
            }
            foreach (AF_OneAB oneAB in abConfig.m_AllPrefabAB)
            {
                allAB.Add(oneAB);
            }
            //遍历
            for (int i = 0; i < allAB.Count; i++)
            {
                EditorUtility.DisplayProgressBar("整理AB包资源", "名字TargetDataSet:" + allAB[i].mABIdentifier, i * 1.0f / (allAB.Count + abConfig.m_AllPrefabAB.Count));
                //分别拷贝到对应的类别中
                for (int k = 0; k < allAB[i].CategoryOfOwnership.Count; k++)
                {
                    string CategoryOfOwnershipS = allAB[i].CategoryOfOwnership[k];
                    if (!ClassToInfo.ContainsKey(CategoryOfOwnershipS))
                    {
                        AFLogger.EditorErrorLog(allAB[i].mABIdentifier + "所属类型错误,不在m_AllClass内,请检查");
                        EditorUtility.ClearProgressBar();
                        return;
                    }
                    //不是当前APP Type的类型,跳过
                    if (!ClassToAppType[CategoryOfOwnershipS])
                    {
                        continue;
                    }
                    if (!ClassToInfo[CategoryOfOwnershipS].isNeedPackageAB)
                    {
                        continue;
                    }
                    string ABIdentifier = allAB[i].mABIdentifier.ToLower();

                    //拷贝AB包
                    if (!FileHelper.CopyFile(m_BunleTargetPath + "/" + ABIdentifier,
                                             mTargetPath + ABIdentifier))
                    {
                        break;
                    }
                    //添加AB包的MD5码
                    string ABMD5 = FileHelper.getFileHash(m_BunleTargetPath + "/" + ABIdentifier);
                    if (!ClassToInfo[CategoryOfOwnershipS].FileMD5.ContainsKey(ABIdentifier))
                    {
                        ClassToInfo[CategoryOfOwnershipS].FileMD5.Add(ABIdentifier, ABMD5);
                    }
                    //是已经打包过的类别
                    if (ABNameToPath.ContainsKey(ABIdentifier))
                    {
                        ABNameToPath.Add(ABIdentifier, CategoryOfOwnershipS + "/" + ABIdentifier);
                    }
                    //保存文件的大小
                    ClassToInfo[CategoryOfOwnershipS].ABName.Add(ABIdentifier,
                                                                 FileHelper.GetFileSize(mTargetPath + ABIdentifier));
                }
            }
            //保存info文件
            for (int i = 0; i < abConfig.m_AllClass.Count; i++)
            {
                if (abConfig.m_AllClass[i].isNeedPackageAB)
                {
                    SerializeHelper.SaveJson <OneABClassInfo>(ClassToInfo[abConfig.m_AllClass[i].ABClassType.ToString()],
                                                              mInfoPath + abConfig.m_AllClass[i].ABClassType + "Info.txt");
                }
            }
            if (abConfig.configWritingMode == ConfigWritingMode.Binary)
            {
                FileHelper.DeleteFile(PathTool.ProjectPath + "Assets/AssetbundleConfig.bytes");
                FileHelper.CopyFile(m_BunleTargetPath + "assetbundleconfig", mTargetPath + "AssetbundleConfig");
            }
            AssetDatabase.Refresh();
            Debug.Log("资源拷贝完毕,保存路径为 : " + mTargetPath);
            EditorUtility.RevealInFinder(mTargetPath);
        }