Beispiel #1
0
    public static void GetDiff(ref List <BundleInfo> downLoadList, ref List <BundleInfo> removeList, FileList localListInfo, FileList serverListInfo)
    {
        if (downLoadList == null || removeList == null || localListInfo == null || serverListInfo == null)
        {
            return;
        }

        downLoadList.Clear();
        removeList.Clear();

        List <BundleInfo> localList  = localListInfo.m_FileList;
        List <BundleInfo> serverList = serverListInfo.m_FileList;

        if (serverList == null)
        {
            return;
        }
        // 查找需要下载的资源;
        for (int index = 0; index < serverList.Count; index++)
        {
            BundleInfo serverDataInfo = serverList[index];
            if (serverDataInfo == null)
            {
                continue;
            }

            BundleInfo localDataInfo = GetBundleInfo(serverDataInfo.bundleName, localList);

            // 如果本地FileList没有记录这个文件;
            if (localDataInfo == null)
            {
                downLoadList.Add(serverDataInfo);
                continue;
            }

            // 如果服务器上的比本地的要新,则需要重新下载;
            if (!BundleInfo.Equals(FileListUtils.s_updateMode, serverDataInfo, localDataInfo))
            {
                downLoadList.Add(serverDataInfo);
                continue;
            }

            //Debug.LogFormat("{5} s_updateMode = {0}, serverDataInfo = {1} - {2}, localDataInfo = {3} - {4}", s_updateMode, serverDataInfo.crc, serverDataInfo.md5, localDataInfo.crc, localDataInfo.md5, serverDataInfo.bundleName);

            //if (serverDataInfo.crc != localDataInfo.crc)
            //{
            //    downLoadList.Add(serverDataInfo);
            //    continue;
            //}

#if !UNITY_EDITOR
            bool find = false;
            if (localDataInfo.stream)
            {
                find = FindStreamFile(serverDataInfo.bundleName);
            }
            else
            {
                find = FindLocalFile(serverDataInfo.bundleName);
            }

            // 如果列表记录了,但是本地又没有,只能再次下载;
            if (!find)
            {
                downLoadList.Add(serverDataInfo);
                continue;
            }
#else
            bool find = FindLocalFile(serverDataInfo.bundleName);
            if (!find)
            {
                downLoadList.Add(serverDataInfo);
                continue;
            }
#endif
        }

        if (localList == null)
        {
            return;
        }
        // 查找需要删除的资源;
        for (int index = 0; index < localList.Count; index++)
        {
            BundleInfo localDataInfo  = localList[index];
            BundleInfo serverDataInfo = GetBundleInfo(localDataInfo.bundleName, serverList);

            // 如果本地没有这个文件;
            if (serverDataInfo == null)
            {
                removeList.Add(localDataInfo);
                continue;
            }
        }
    }
Beispiel #2
0
    public static FileListCompareData Compare(FileList newFileList, FileList oldFileList, bool remove_old = true, BundleUpdateMode mode = BundleUpdateMode.Update_CRC)
    {
        FileListCompareData comData = new FileListCompareData();

        if (newFileList == null)
        {
            return(comData);
        }

        if (oldFileList == null)
        {
            comData.addList.CopyFrom(newFileList.m_FileList);
            return(comData);
        }

        for (int i = 0; i < newFileList.m_FileList.Count; i++)
        {
            BundleInfo bundleInfo = newFileList.m_FileList[i];
            if (bundleInfo == null || string.IsNullOrEmpty(bundleInfo.bundleName))
            {
                continue;
            }

            BundleInfo oldBundleInfo = oldFileList.GetBundleInfo(bundleInfo.bundleName);
            if (oldBundleInfo == null)
            {
                comData.addList.Add(bundleInfo);
                continue;
            }

            if (BundleInfo.Equals(mode, oldBundleInfo, bundleInfo))
            {
                continue;
            }

            //if (oldBundleInfo.crc == bundleInfo.crc)
            //{
            //    continue;
            //}

            comData.modifiyList.Add(bundleInfo);
        }

        if (remove_old)
        {
            return(comData);
        }

        for (int i = 0; i < oldFileList.m_FileList.Count; i++)
        {
            BundleInfo oldBundleInfo = oldFileList.m_FileList[i];
            if (oldBundleInfo == null || string.IsNullOrEmpty(oldBundleInfo.bundleName))
            {
                continue;
            }

            BundleInfo bundleInfo = newFileList.GetBundleInfo(oldBundleInfo.bundleName);
            if (bundleInfo != null)
            {
                continue;
            }
            comData.deleteList.Add(bundleInfo);
        }

        return(comData);
    }