public static AssetFileList DiffAssetFileList(AssetFileList current, AssetFileList update)
        {
            AssetFileList diffs = new AssetFileList();

            AssetFile gameConstItem = null;

            int count = update.list.Count;

            for (int i = 0; i < count; i++)
            {
                AssetFile item = update.list[i];

                if (item.path == AssetManagerSetting.GameConstName)
                {
                    gameConstItem = item;
                    continue;
                }

                if (!current.Has(item.path))
                {
                    diffs.Add(item);
                }
                else if (item.md5 != current.Get(item.path).md5)
                {
                    diffs.Add(item);
                }
            }

            if (gameConstItem != null)
            {
                diffs.Add(gameConstItem);
            }
            else
            {
                diffs.Add(new AssetFile(AssetManagerSetting.GameConstName, "md5"));
            }

            return(diffs);
        }
예제 #2
0
        IEnumerator UpdateResource(string rootUrl)
        {
            // rootUrl = "http://www.ihaiu.com/StreamingAssets/"
            OnUpdateEnter();

            //获取服务器端的file.csv

            OnState("获取服务器端的file.csv");
            string updateAssetListUrl = AssetManagerSetting.GetServerFilesCsvURL(rootUrl);

            Debug.Log("UpdateAssetList URL: " + updateAssetListUrl);
            WWW www = new WWW(updateAssetListUrl);

            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                OnError("更新资源读取资源列表失败");
                Debug.LogErrorFormat("更新资源读取资源列表失败 updateAssetListUrl={0}, www.error={1}", updateAssetListUrl, www.error);
                www.Dispose();
                www = null;
                yield break;
            }

            AssetFileList updateAssetList = AssetFileList.Deserialize(www.text);

            www.Dispose();
            www = null;
            //Debug.Log("count: " + files.Length + " text: " + filesText);


            OnState("读取" + AssetManagerSetting.AssetFileListPath);
            if (assetList == null)
            {
                assetList = AssetFileList.Read(AssetManagerSetting.AssetFileListPath);
            }

            List <AssetFile> diffs = AssetFileList.Diff(assetList, updateAssetList);

            AssetManagerSetting.persistentAssetFileList = AssetFileList.Read(AssetManagerSetting.PersistentAssetFileListPath);

            string path;
            //更新
            int count = diffs.Count;

            for (int i = 0; i < count; i++)
            {
                AssetFile item = diffs[i];
                path = AssetManagerSetting.GetPlatformPath(item.path);

                OnState("更新" + path);
                OnUpdateProgress((float)(i + 1) / (float)count);

                string url = rootUrl + path;
                www = new WWW(url);

                yield return(www);

                if (!string.IsNullOrEmpty(www.error))
                {
                    OnUpdateFailed(url);

                    www.Dispose();
                    www = null;
                    continue;
                }

                string localPath = AssetManagerSetting.RootPathPersistent + path;
                PathUtil.CheckPath(localPath, true);
                File.WriteAllBytes(localPath, www.bytes);

                www.Dispose();
                www = null;

                assetList.Add(item);

                AssetManagerSetting.persistentAssetFileList.Add(path, item.md5);
            }
            yield return(new WaitForEndOfFrame());


            assetList.Save(AssetManagerSetting.AssetFileListPath);
            AssetManagerSetting.persistentAssetFileList.Save(AssetManagerSetting.PersistentAssetFileListPath);


            // 更新完成
            OnUpdateEnd();
        }