Ejemplo n.º 1
0
    protected void LoadLuaScriptBundle()
    {
        ResLoader         resLoader   = GameManager.GetResLoader();
        List <BundleInfo> bundleInfos = resLoader.bundleLoader.bundleInfos;

        for (int i = 0; i < bundleInfos.Count; i++)
        {
            if (bundleInfos[i].buildType == BuildType.Lua)
            {
                string      bundleName = bundleInfos[i].bundleName;
                string      luaRootDir = BMUtility.Name2Path(bundleName);
                AssetBundle luaBundle  = resLoader.GetBundleByBundleName(bundleName);
                if (luaBundle)
                {
                    LuaFileUtils.Instance.AddSearchBundle(bundleName, luaBundle);
                    string[] allNames = luaBundle.GetAllAssetNames();
                    for (int j = 0; j < allNames.Length; j++)
                    {
                        string name = allNames[j];
                        name = name.Substring(0, name.Length - tailLength); //去掉md5后缀,转化为正确的Lua文件名
                        name = name.Replace(luaRootDir.ToLower() + "/", "");
                        name = "lua_" + BMUtility.Path2Name(name);
                        //Debug.LogFormat("{0} - {1}", name, allNames[j]);
                        LuaFileUtils.Instance.AddLuaNameMap(name, allNames[j]);
                    }
                }
                else
                {
                    Logger.Error("There is not lua bundle:{0}", bundleName);
                }
            }
        }
    }
Ejemplo n.º 2
0
 public static void CleanCache()
 {
     Caching.CleanCache();
     BMUtility.DeletePersistentData(DOWNLOAD_INFO_CACHE_NAME);
     BMUtility.DeletePersistentData(CONFIGER_CACHE_NAME);
     PlayerPrefs.DeleteKey(BMDATA_VERSION_PREFSKEY);
 }
Ejemplo n.º 3
0
 public static void MarkChangeDate(string path)
 {
     int[] date = BMUtility.long2doubleInt(File.GetLastWriteTime(path).ToBinary());
     PlayerPrefs.SetInt("BMChangeDate0", date[0]);
     PlayerPrefs.SetInt("BMChangeDate1", date[1]);
     //AssetDatabase.ImportAsset(path);
 }
Ejemplo n.º 4
0
    public string GetInterpretedDownloadUrl(BuildPlatform platform, bool bUseBackup = false)
    {
        if (bUseBackup)
        {
            return(BMUtility.InterpretPath(backupDownloadUrls[platform.ToString()], platform));
        }

        return(BMUtility.InterpretPath(downloadUrls[platform.ToString()], platform));
    }
Ejemplo n.º 5
0
    private void CopyToDownloadPath()
    {
        var srcPath  = BuildConfiger.InterpretedOutputPath;
        var destPath = BMUtility.InterpretPath(BuildConfiger.CopyFolderStr, BuildConfiger.AutoBundleBuildtarget);

        if (Directory.Exists(destPath))
        {
            Directory.Delete(destPath, true);
        }
        BuildHelper.CopyFiles(srcPath, destPath);
    }
Ejemplo n.º 6
0
    void initRootUrl()
    {
        TextAsset downloadUrlText = (TextAsset)Resources.Load("Urls");

        bmUrl = JsonMapper.ToObject <BMUrls>(downloadUrlText.text);

        if (Application.platform == RuntimePlatform.WindowsEditor ||
            Application.platform == RuntimePlatform.OSXEditor)
        {
#if UNITY_EDITOR
            switch (UnityEditor.EditorUserBuildSettings.activeBuildTarget)
            {
            case UnityEditor.BuildTarget.Android:
                curPlatform = BuildPlatform.Android;
                break;

            case UnityEditor.BuildTarget.iPhone:
                curPlatform = BuildPlatform.IOS;
                break;

            default:
                curPlatform = BuildPlatform.Standalones;
                break;
            }
#else
            curPlatform = bmUrl.bundleTarget;
#endif
        }
        else
        {
            curPlatform = getRuntimePlatform();
        }
        string downloadPathStr = string.Empty;
        if (manualUrl == "")
        {
            if (bmUrl.downloadFromOutput)
            {
                downloadPathStr = bmUrl.GetInterpretedOutputPath(curPlatform);
            }
            else
            {
                downloadPathStr = bmUrl.GetInterpretedDownloadUrl(curPlatform);
            }
        }
        else
        {
            downloadPathStr = BMUtility.InterpretPath(manualUrl, curPlatform);
        }
        if (!string.IsNullOrEmpty(downloadPathStr))
        {
            localRootUrl = new Uri(downloadPathStr).AbsoluteUri;
        }
    }
Ejemplo n.º 7
0
    static bool isDateChangedManually(string asset)
    {
        if (!PlayerPrefs.HasKey("BMChangeDate0") || !PlayerPrefs.HasKey("BMChangeDate1"))
        {
            return(false);
        }

        long assetChangeTime  = File.GetLastWriteTime(asset).ToBinary();
        long markedChangeTime = BMUtility.doubleInt2long(PlayerPrefs.GetInt("BMChangeDate0"), PlayerPrefs.GetInt("BMChangeDate1"));

        return(assetChangeTime != markedChangeTime);
    }
Ejemplo n.º 8
0
    public IEnumerator UpdateBundles()
    {
        if (!initializationFinished)
        {
            yield break;
        }
        initializationFinished = false;
        StopAll();

        foreach (var req in succeedRequest.Values)
        {
            var ab = req.assetBundle;
            if (ab)
            {
                ab.Unload(false);
            }
        }

        string[] disposeRequestArray = new string[succeedRequest.Count + failedRequest.Count];
        succeedRequest.Keys.CopyTo(disposeRequestArray, 0);
        failedRequest.Keys.CopyTo(disposeRequestArray, succeedRequest.Count);
        foreach (var req in disposeRequestArray)
        {
            DisposeBundle(req);
        }

        long downloadFileSize = 0;

        for (int i = 0; i < updateList.Count; ++i)
        {
            var info = updateList[i];
            UpdateFinishFielCount = i + 1;
            var www = WWW.LoadFromCacheOrDownload(info.url, info.version);
            do
            {
                yield return(null);

                UpdateFinishSize = downloadFileSize + (long)(www.progress * info.versionInfo.size);
            } while (!www.isDone);
            www.Dispose();
            downloadFileSize += info.versionInfo.size;
            UpdateFinishSize  = downloadFileSize;
            info.needDownload = false;
            BMUtility.SaveToPersistentData(bundles, DOWNLOAD_INFO_CACHE_NAME);
        }
        CurrentVesion = UpdateVersion;
        PlayerPrefs.SetInt(BMDATA_VERSION_PREFSKEY, CurrentVesion);
        initializationFinished = true;
    }
Ejemplo n.º 9
0
    private void mergeVersion(VersionInfo versionInfo)
    {
        if (!versionInfo.isValue)
        {
            return;
        }

        var newList = new List <BundleDownloadInfo>();

        foreach (var bundleVersionInfo in versionInfo.bundles)
        {
            var bundleName = bundleVersionInfo.name;
            BundleDownloadInfo downloadInfo = null;
            if (bundleDict.ContainsKey(bundleName))
            {
                downloadInfo = bundleDict[bundleName];
            }
            else
            {
                downloadInfo         = new BundleDownloadInfo();
                downloadInfo.name    = bundleName;
                downloadInfo.version = 0;
            }

            if (downloadInfo.versionInfo == null || downloadInfo.versionInfo.crc != bundleVersionInfo.crc ||
                (!downloadInfo.localBundle && !Caching.IsVersionCached(downloadInfo.url, downloadInfo.version)))
            {
                downloadInfo.versionInfo = bundleVersionInfo;
                downloadInfo.version++;
                downloadInfo.localBundle  = versionInfo.rootUrl == localRootUrl;
                downloadInfo.url          = formatUrl(versionInfo.rootUrl, bundleVersionInfo.requestString);
                downloadInfo.needDownload = !downloadInfo.localBundle;
            }

            newList.Add(downloadInfo);
        }

        bundles    = newList;
        bmConfiger = versionInfo.bmConfiger ?? bmConfiger;

        BMUtility.SaveToPersistentData(bundles, DOWNLOAD_INFO_CACHE_NAME);
        BMUtility.SaveToPersistentData(bmConfiger, CONFIGER_CACHE_NAME);
    }
Ejemplo n.º 10
0
    void initRootUrl()
    {
        TextAsset downloadUrlText = (TextAsset)Resources.Load("Urls");

        bmUrl = JsonMapper.ToObject <BMUrls>(downloadUrlText.text);

        if (Application.platform == RuntimePlatform.WindowsEditor ||
            Application.platform == RuntimePlatform.OSXEditor)
        {
            curPlatform = bmUrl.bundleTarget;
        }
        else
        {
            curPlatform = getRuntimePlatform();
        }

        if (manualUrl == "")
        {
            string downloadPathStr;
            if (bmUrl.downloadFromOutput)
            {
                downloadPathStr = bmUrl.GetInterpretedOutputPath(curPlatform);
            }
            else
            {
                downloadPathStr = bmUrl.GetInterpretedDownloadUrl(curPlatform);
            }

            Uri downloadUri = new Uri(downloadPathStr);
            downloadRootUrl = downloadUri.AbsoluteUri;
        }
        else
        {
            string downloadPathStr = BMUtility.InterpretPath(manualUrl, curPlatform);
            Uri    downloadUri     = new Uri(downloadPathStr);
            downloadRootUrl = downloadUri.AbsoluteUri;
        }

        downloadLoadRootUrl = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf("/")) + "/" + "assetBundle";
    }
Ejemplo n.º 11
0
 public string GetInterpretedOutputPath(BuildPlatform platform)
 {
     return(BMUtility.InterpretPath(outputs[platform.ToString()], platform));
 }
Ejemplo n.º 12
0
 public string GetInterpretedDownloadUrl(BuildPlatform platform)
 {
     return(BMUtility.InterpretPath(downloadUrls[platform.ToString()], platform));
 }
Ejemplo n.º 13
0
        private static void AndroidPackageProcess(string path)
        {
            #region 打开apk,装入bundles
            FileInfo bundle = new FileInfo(path);
            if (bundle.Length < MaxBundleSize || MaxBundleSize == 0)
            {
                using (var zipFile = new ZipFile(path))
                {
                    string basePath   = BMUtility.InterpretPath("$(Personal)/LTSites/", BuildPlatform.Android);
                    string outputPath = BuildConfiger.InterpretedOutputPath;
                    string shortPath  = "assets/AssetBundles/" + outputPath.Substring(basePath.Length);
                    if (zipFile.ContainsEntry(shortPath + "/" + "BundleShipInfo.json"))                     //已装过bundles
                    {
                        UnityEngine.Debug.LogWarning("AssetBundles already exists");
                    }
                    else
                    {
                        //获取要装入的bundles
                        // UnityEngine.Debug.LogError($"AndroidPackageProcess=====>max: {MaxBundleSize}==bundleLenght: {bundle.Length}");
                        var assets = MaxBundleSize > 0 ? BuildHelper.GetBundlesByPriority(MaxBundleSize - bundle.Length) : BMDataAccessor.BundleShipInfos;
                        zipFile.AddDirectoryByName(shortPath);
                        //装入准备好的bundles
                        foreach (var file in assets)
                        {
                            if (!GM.RemoteBundleManager.IsBuildBundle(file.BundleName))
                            {
                                continue;
                            }
                            var fullpath  = Path.Combine(outputPath, file.BundleName.ToLower() + ".cz");
                            var shortname = shortPath + "/" + file.BundleName.ToLower() + ".cz";
                            if (zipFile.ContainsEntry(shortname))
                            {
                                UnityEngine.Debug.LogWarningFormat("{0} already exists", shortname);
                            }
                            else
                            {
                                zipFile.AddFile(fullpath, shortPath);
                            }
                        }

                        //装入json等文件
                        if (MaxBundleSize == 0)
                        {
                            foreach (string s in Directory.GetFiles(outputPath, "*.json"))
                            {
                                string fileName  = System.IO.Path.GetFileName(s);
                                var    shortname = shortPath + "/" + fileName;
                                if (zipFile.ContainsEntry(shortname))
                                {
                                    UnityEngine.Debug.LogWarningFormat("{0} already exists", shortname);
                                }
                                else
                                {
                                    zipFile.AddFile(s, shortPath);
                                }
                            }

                            string sourcePath      = Path.GetDirectoryName(outputPath);
                            string destinationPath = Path.GetDirectoryName(shortPath);
                            foreach (string s in Directory.GetFiles(sourcePath))
                            {
                                string fileName  = System.IO.Path.GetFileName(s);
                                var    shortname = destinationPath + "/" + fileName;
                                if (zipFile.ContainsEntry(shortname))
                                {
                                    UnityEngine.Debug.LogWarningFormat("{0} already exists", shortname);
                                }
                                else
                                {
                                    zipFile.AddFile(s, destinationPath);
                                }
                            }
                        }
                        else
                        {
                            string shipInfoFile = shortPath + "/" + "BundleShipInfo.json";
                            if (zipFile.ContainsEntry(shipInfoFile))
                            {
                                zipFile.UpdateEntry(shipInfoFile, EB.Encoding.GetBytes(GM.JSON.ToJson(assets)));
                            }
                            else
                            {
                                zipFile.AddEntry(shipInfoFile, EB.Encoding.GetBytes(GM.JSON.ToJson(assets)));
                            }
                        }

                        //由于包体过大,压缩前需要设置这个
                        zipFile.UseZip64WhenSaving = Zip64Option.AsNecessary;
                        zipFile.Save();
                    }
                }
            }
            #endregion

            //重新签名
            ResignAPK(path);
        }
Ejemplo n.º 14
0
    // Privats
    IEnumerator Start()
    {
        // Initial download urls
        initRootUrl();

        // Try to get Url redirect file
        WWW redirectWWW = new WWW(formatUrl("BMRedirect.txt"));

        yield return(redirectWWW);

        if (redirectWWW.error == null)
        {
            // Redirect download
            string downloadPathStr = BMUtility.InterpretPath(redirectWWW.text, curPlatform);
            Uri    downloadUri     = new Uri(downloadPathStr);
            downloadRootUrl = downloadUri.AbsoluteUri;
        }

        redirectWWW.Dispose();


        // Download the initial data bundle
        const string verNumKey         = "BMDataVersion";
        string       bmDataUrl         = formatUrl("BM.data");
        int          lastBMDataVersion = 0;

        if (PlayerPrefs.HasKey(verNumKey))
        {
            lastBMDataVersion = PlayerPrefs.GetInt(verNumKey);
        }

        // Download and cache new data version
        WWW initDataWWW;

        if (bmUrl.offlineCache)
        {
            initDataWWW = WWW.LoadFromCacheOrDownload(bmDataUrl, lastBMDataVersion + 1);

            yield return(initDataWWW);

            if (initDataWWW.error != null)
            {
                initDataWWW.Dispose();
                Debug.Log("Cannot load BMData from target url. Try load it from cache.");

                initDataWWW = WWW.LoadFromCacheOrDownload(bmDataUrl, lastBMDataVersion);
                yield return(initDataWWW);

                if (initDataWWW.error != null)
                {
                    Debug.LogError("Download BMData failed.\nError: " + initDataWWW.error);
                    yield break;
                }
            }
            else
            {
                // Update cache version number
                PlayerPrefs.SetInt(verNumKey, lastBMDataVersion + 1);
            }
        }
        else
        {
            initDataWWW = new WWW(bmDataUrl);

            yield return(initDataWWW);

            if (initDataWWW.error != null)
            {
                Debug.LogError("Download BMData failed.\nError: " + initDataWWW.error);
                yield break;
            }
        }

        // Init datas
        //
        // Bundle Data
#if UNITY_5
        TextAsset ta = initDataWWW.assetBundle.LoadAsset <TextAsset>("BundleData");
#else
        TextAsset ta = initDataWWW.assetBundle.Load("BundleData") as TextAsset;
#endif
        bundles = JsonMapper.ToObject <List <BundleData> >(ta.text);
        foreach (var bundle in bundles)
        {
            bundleDict.Add(bundle.name, bundle);
        }

        // Build States
#if UNITY_5
        ta = initDataWWW.assetBundle.LoadAsset <TextAsset>("BuildStates");
#else
        ta = initDataWWW.assetBundle.Load("BuildStates") as TextAsset;
#endif
        buildStates = JsonMapper.ToObject <List <BundleBuildState> >(ta.text);
        foreach (var buildState in buildStates)
        {
            buildStatesDict.Add(buildState.bundleName, buildState);
        }

        // BMConfiger
#if UNITY_5
        ta = initDataWWW.assetBundle.LoadAsset <TextAsset>("BMConfiger");
#else
        ta = initDataWWW.assetBundle.Load("BMConfiger") as TextAsset;
#endif
        bmConfiger = JsonMapper.ToObject <BMConfiger>(ta.text);

        initDataWWW.assetBundle.Unload(true);
        initDataWWW.Dispose();


        // Start download for requests before init
        foreach (WWWRequest request in requestedBeforeInit)
        {
            download(request);
        }
    }
Ejemplo n.º 15
0
    // Privats
    IEnumerator Start()
    {
        if (instance != this)
        {
            Destroy(gameObject);
            yield break;
        }
#if UNITY_EDITOR
        //HACK:Ϊ���ñ༭������������������
        //����������޷����ظ��°������Ҫ��������汾���֣�ǿ�ƿͻ������Cache���ذ�
        if (!PlayerPrefs.HasKey(FORCE_DOWNLOAD_PREFSKEY) ||
            PlayerPrefs.GetInt(FORCE_DOWNLOAD_PREFSKEY) < FORCE_DOWNLOAD_VERSION)
        {
            CleanCache();
            PlayerPrefs.SetInt(FORCE_DOWNLOAD_PREFSKEY, FORCE_DOWNLOAD_VERSION);
        }
#endif
        // Initial download urls
        initRootUrl();

        //�ӱ�������������ж�ȡ����
        int lastBMDataVersion = 0;
        if (PlayerPrefs.HasKey(BMDATA_VERSION_PREFSKEY))
        {
            lastBMDataVersion = PlayerPrefs.GetInt(BMDATA_VERSION_PREFSKEY);
#if UNITY_EDITOR && ALWAYS_UPDATE_LOCAL
            //�ڱ༭��ģʽ�¿��ܿ�������Ҳ�����������ᵼ�¿��������б�������İ��汾���ֺ����ɵİ汾���ֲ�����ͻ
            //���Ա༭��ģʽ�����Ӱ汾���ֻ���
            lastBMDataVersion = 0;
#endif
        }
        CurrentVesion = lastBMDataVersion;

        if (BMUtility.IsPersistentDataExists(DOWNLOAD_INFO_CACHE_NAME) &&
            BMUtility.IsPersistentDataExists(CONFIGER_CACHE_NAME))
        {
            bundles    = BMUtility.LoadFromPersistentData <List <BundleDownloadInfo> >(DOWNLOAD_INFO_CACHE_NAME);
            bmConfiger = BMUtility.LoadFromPersistentData <BMConfiger>(CONFIGER_CACHE_NAME);
        }



        //�����ȡ�����г������⣬��������л��棬֮����Դ�LoadRootUrl������������
        if (bundles == null || bmConfiger == null)
        {
            DownloadManager.CleanCache();
            CurrentVesion = 0;
            bundles       = new List <BundleDownloadInfo>();
            bmConfiger    = new BMConfiger();
        }
        refreshBundleDict();

        //���Դ�LoadDownloadUrl���ذ汾��Ϣ
        //��Ҹ��¿ͻ��˺����LoadDownLoadUrl�а汾���Ϊ���°汾���������ͬ����ҪmergeVersion�ʹӱ��ظ�������
        if (string.IsNullOrEmpty(localRootUrl))
        {
        }
        else
        {
            var localVersionInfo = new VersionInfo(localRootUrl);
            yield return(StartCoroutine(downloadVersionInfoCo(localVersionInfo)));

            if (localVersionInfo.isValue)
            {
                CleanCache();
                bundles = new List <BundleDownloadInfo>();
                mergeVersion(localVersionInfo);
                refreshBundleDict();
                CurrentVesion = localVersionInfo.listVersion;
                PlayerPrefs.SetInt(BMDATA_VERSION_PREFSKEY, CurrentVesion);
            }
        }

        //Validation
        if (bundles == null)
        {
            Debug.LogError("{BM} Cannot get bundle list.");
            yield break;
        }
        if (bmConfiger == null)
        {
            Debug.LogError("{BM} Fail to load BMConfiger.");
        }

        initializationFinished = true;

        //Start download for requests before init
        foreach (var request in requestedBeforeInit)
        {
            download(request);
        }
    }
Ejemplo n.º 16
0
    void Update()
    {
        if (!ConfigLoaded)
        {
            return;
        }

        // Check if any WWW is finished or errored
        List <string> newFinisheds = new List <string>();
        List <string> newFaileds   = new List <string>();

        foreach (WWWRequest request in processingRequest.Values)
        {
            if (request.error != null)
            {
                if (request.triedTimes - 1 < bmConfiger.downloadRetryTime)
                {
                    // Retry download
                    request.CreatWWW();
                }
                else
                {
                    request.DisposeWWW();
                    newFaileds.Add(request.bundleName);
                    Debug.LogError("{BM}Download Bundle " + request.bundleName + "URL:" + request.info.url + "failed for " + request.triedTimes + " times.\nError: " + request.error);
                }
            }
            else if (request.isDone)
            {
                request.DisposeWWW();
                newFinisheds.Add(request.bundleName);
            }
        }

        // Move complete bundles out of downloading list
        foreach (string finishedUrl in newFinisheds)
        {
            var req = processingRequest[finishedUrl];
            if (req.info.needDownload)
            {
                req.info.needDownload = false;
            }
            req.assetBundle.name = req.bundleName;
            dbgDownloadBundles.Add(req.assetBundle);
            succeedRequest.Add(finishedUrl, req);
            processingRequest.Remove(finishedUrl);
        }

        // Move failed bundles out of downloading list
        foreach (string finishedUrl in newFaileds)
        {
            if (!failedRequest.ContainsKey(finishedUrl))
            {
                failedRequest.Add(finishedUrl, processingRequest[finishedUrl]);
            }
            processingRequest.Remove(finishedUrl);
        }

        // Start download new bundles
        int waitingIndex = 0;

        while (processingRequest.Count < bmConfiger.downloadThreadsCount &&
               waitingIndex < waitingRequests.Count)
        {
            WWWRequest curRequest = waitingRequests[waitingIndex++];

            bool canStartDownload = curRequest.info == null || isBundleDependenciesReady(curRequest.info.name);
            if (canStartDownload)
            {
                waitingRequests.Remove(curRequest);
                curRequest.CreatWWW();
                processingRequest.Add(curRequest.bundleName, curRequest);
            }
        }

        if (needSaveDownloadInfoCache && processingRequest.Count == 0 && waitingRequests.Count == 0)
        {
            needSaveDownloadInfoCache = false;
            BMUtility.SaveToPersistentData(bundles, DOWNLOAD_INFO_CACHE_NAME);
        }
    }    //update end
Ejemplo n.º 17
0
    // Privats
    IEnumerator Start()
    {
        if (instance != this)
        {
            Destroy(gameObject);
            yield break;
        }
#if UNITY_EDITOR
        //HACK:为了让编辑器工作可以正常运作
        //如果出现了无法下载更新包的情况要递增这个版本数字,强制客户端清空Cache下载包
        if (!PlayerPrefs.HasKey(FORCE_DOWNLOAD_PREFSKEY) ||
            PlayerPrefs.GetInt(FORCE_DOWNLOAD_PREFSKEY) < FORCE_DOWNLOAD_VERSION)
        {
            CleanCache();
            PlayerPrefs.SetInt(FORCE_DOWNLOAD_PREFSKEY, FORCE_DOWNLOAD_VERSION);
        }
#endif
        // Initial download urls
        initRootUrl();

        //从本机缓存的数据中读取数据
        int lastBMDataVersion = 0;
        if (PlayerPrefs.HasKey(BMDATA_VERSION_PREFSKEY))
        {
            lastBMDataVersion = PlayerPrefs.GetInt(BMDATA_VERSION_PREFSKEY);
#if UNITY_EDITOR && ALWAYS_UPDATE_LOCAL
            //在编辑器模式下可能开发者中也会打包,这样会导致开发过程中本机缓存的包版本数字和主干的版本数字产生冲突
            //所以编辑器模式下无视版本数字缓存
            lastBMDataVersion = 0;
#endif
        }
        CurrentVesion = lastBMDataVersion;

        if (BMUtility.IsPersistentDataExists(DOWNLOAD_INFO_CACHE_NAME) &&
            BMUtility.IsPersistentDataExists(CONFIGER_CACHE_NAME))
        {
            bundles    = BMUtility.LoadFromPersistentData <List <BundleDownloadInfo> >(DOWNLOAD_INFO_CACHE_NAME);
            bmConfiger = BMUtility.LoadFromPersistentData <BMConfiger>(CONFIGER_CACHE_NAME);
        }



        //如果读取数据中出现问题,则清空所有缓存,之后可以从LoadRootUrl重新生成数据
        if (bundles == null || bmConfiger == null)
        {
            DownloadManager.CleanCache();
            CurrentVesion = 0;
            bundles       = new List <BundleDownloadInfo>();
            bmConfiger    = new BMConfiger();
        }
        refreshBundleDict();

        //尝试从LoadDownloadUrl下载版本信息
        //玩家更新客户端后可能LoadDownLoadUrl中版本会成为最新版本,这种情况同样需要mergeVersion和从本地更新下载
        if (string.IsNullOrEmpty(localRootUrl))
        {
        }
        else
        {
            var localVersionInfo = new VersionInfo(localRootUrl);
            yield return(StartCoroutine(downloadVersionInfoCo(localVersionInfo)));

            if (localVersionInfo.isValue)
            {
                CleanCache();
                bundles = new List <BundleDownloadInfo>();
                mergeVersion(localVersionInfo);
                refreshBundleDict();
                CurrentVesion = localVersionInfo.listVersion;
                PlayerPrefs.SetInt(BMDATA_VERSION_PREFSKEY, CurrentVesion);
            }
        }

        //Validation
        if (bundles == null)
        {
            Debug.LogError("{BM} Cannot get bundle list.");
            yield break;
        }
        if (bmConfiger == null)
        {
            Debug.LogError("{BM} Fail to load BMConfiger.");
        }

        initializationFinished = true;

        //Start download for requests before init
        foreach (var request in requestedBeforeInit)
        {
            download(request);
        }
    }
Ejemplo n.º 18
0
    public IEnumerator CheckUpdate(string downloadPath)
    {
        while (!ConfigLoaded)
        {
            yield return(null);
        }

        var downloadPathStr = BMUtility.InterpretPath(downloadPath, curPlatform);

        if (string.IsNullOrEmpty(downloadPathStr))
        {
            CheckUpdateError = "{BM} Invalid update download path" + downloadPathStr;
            yield break;
        }

        remoteRootUrl = new Uri(downloadPathStr).AbsoluteUri;

        //Try to get Url redirect file
        var redirectUrl = formatUrl(remoteRootUrl, "BMRedirect.txt");

        if (!string.IsNullOrEmpty(redirectUrl))
        {
            WWW redirectWWW = new WWW(redirectUrl);
            yield return(redirectWWW);

            if (redirectWWW.error == null)
            {
                //Redirect download
                var redirectedDownloadPath = redirectWWW.text;
                downloadPathStr = BMUtility.InterpretPath(redirectedDownloadPath, curPlatform);
                if (string.IsNullOrEmpty(downloadPathStr))
                {
                    Debug.LogError("{BM} Invalid redirected download Path :" + downloadPathStr + "(Retrived from url:" + redirectUrl + ")." +
                                   "Using the original download path" + remoteRootUrl);
                }
                else
                {
                    remoteRootUrl = new Uri(downloadPathStr).AbsoluteUri;
                }
            }
            redirectWWW.Dispose();
        }

        var versionInfo = new VersionInfo(remoteRootUrl);

        yield return(StartCoroutine(downloadVersionInfoCo(versionInfo)));

        CheckUpdateError = versionInfo.error;

        if (versionInfo.isValue)
        {
            UpdateTotalSize = 0;
            UpdateVersion   = versionInfo.listVersion;

            mergeVersion(versionInfo);
            refreshBundleDict();
        }

        updateList = new List <BundleDownloadInfo>();
        foreach (var bundleDownloadInfo in bundles)
        {
            if (bundleDownloadInfo.needDownload)
            {
                if (!updateList.Contains(bundleDownloadInfo))
                {
                    updateList.Add(bundleDownloadInfo);
                    UpdateTotalSize += bundleDownloadInfo.versionInfo.size;
                }
            }
        }
    }