Exemplo n.º 1
0
 // Token: 0x060001E5 RID: 485 RVA: 0x0000A3B8 File Offset: 0x000085B8
 public static List <AudioManager4CRI.FileInfo> LoadFileInfos(string filepath)
 {
     return(AudioManager4CRI.ParseFileInfosText(AudioManager4CRI.LoadTextFile(filepath)));
 }
Exemplo n.º 2
0
        // Token: 0x060001D2 RID: 466 RVA: 0x00009AC0 File Offset: 0x00007CC0
        public static IEnumerator DownloadAudioFiles(Action <bool> onEnd, Action <long, long> onUpdate = null, Action <long> onEndAfterGotDownloadLength = null, MonoBehaviour coroutineOwner = null)
        {
            if (GameManager.Instance == null || GameManager.Instance.GameClientSetting == null)
            {
                yield break;
            }
            if (!GameManager.Instance.GameClientSetting.AudioSetting.EnableDownload)
            {
                yield break;
            }
            if (!AudioManager4CRI.LoadAllFilesPaths())
            {
                global::Debug.LogError("AudioManager4CRI.DownloadAudioFiles Failed to LoadAllFilesPaths().");
                yield break;
            }
            bool   isSuccess         = false;
            string serverFileListMd5 = string.Empty;

            yield return(Util.DownloadHttpFile(string.Format("{0}/{1}", AudioManager4CRI.DownloadUrlRoot, "AllFilesPath.txt.md5"), delegate(bool ret, WWW www)
            {
                isSuccess = ret;
                if (ret)
                {
                    serverFileListMd5 = www.text;
                }
            }, null));

            if (!isSuccess)
            {
                global::Debug.LogError("AudioManager4CRI.DownloadAudioFiles download filelist's md5 Failed .");
                if (onEnd != null)
                {
                    onEnd(false);
                }
                yield break;
            }
            string localFileListMd5 = AudioManager4CRI.LoadTextFile(string.Format("{0}/{1}", AudioManager4CRI.CacheFolderPath, "ServerAllFilesPath.txt.md5"));

            if (string.IsNullOrEmpty(localFileListMd5) || localFileListMd5 != serverFileListMd5)
            {
                yield return(Util.DownloadHttpFile(string.Format("{0}/{1}", AudioManager4CRI.DownloadUrlRoot, "AllFilesPath.txt"), delegate(bool ret, WWW www)
                {
                    isSuccess = ret;
                    if (ret)
                    {
                        try
                        {
                            if (!Directory.Exists(AudioManager4CRI.CacheFolderPath))
                            {
                                Directory.CreateDirectory(AudioManager4CRI.CacheFolderPath);
                            }
                            File.WriteAllText(string.Format("{0}/{1}", AudioManager4CRI.CacheFolderPath, "ServerAllFilesPath.txt"), www.text);
                            File.WriteAllText(string.Format("{0}/{1}", AudioManager4CRI.CacheFolderPath, "ServerAllFilesPath.txt.md5"), serverFileListMd5);
                        }
                        catch (Exception ex)
                        {
                            global::Debug.LogError(string.Format("AudioManager4CRI.DownloadAudioFiles exception: {0}", ex.Message));
                            isSuccess = false;
                        }
                    }
                }, null));

                if (!isSuccess)
                {
                    global::Debug.LogError("AudioManager4CRI.DownloadAudioFiles download filelist Failed .");
                    if (onEnd != null)
                    {
                        onEnd(false);
                    }
                    yield break;
                }
            }
            AudioManager4CRI.m_serverCriAssetFileInfos = AudioManager4CRI.LoadFileInfos(string.Format("{0}/{1}", AudioManager4CRI.CacheFolderPath, "ServerAllFilesPath.txt"));
            AudioManager4CRI.m_cacheCriAssetFileInfos  = AudioManager4CRI.LoadFileInfos(string.Format("{0}/{1}", AudioManager4CRI.CacheFolderPath, "AllFilesPath.txt"));
            List <AudioManager4CRI.FileInfo> differentFileInfos = AudioManager4CRI.DifferentiateFileInfos(AudioManager4CRI.m_serverCriAssetFileInfos, AudioManager4CRI.m_clientCriAssetFileInfos, AudioManager4CRI.m_cacheCriAssetFileInfos);
            long totalDownloadLength = AudioManager4CRI.GetTotalFileLengh(differentFileInfos);

            if (onEndAfterGotDownloadLength != null)
            {
                onEndAfterGotDownloadLength(totalDownloadLength);
                yield break;
            }
            long downloadedLength = 0L;

            if (coroutineOwner == null || coroutineOwner.gameObject == null || !coroutineOwner.gameObject.activeInHierarchy)
            {
                using (List <AudioManager4CRI.FileInfo> .Enumerator enumerator = differentFileInfos.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        AudioManager4CRI.FileInfo i = enumerator.Current;
                        yield return(AudioManager4CRI.DownloadAudioFileToCache(i, delegate(bool ret)
                        {
                            if (!ret)
                            {
                                global::Debug.LogError(string.Format("AudioManager4CRI.DownloadAudioFiles download audio file {0} Failed .", i.m_path));
                                isSuccess = false;
                            }
                            else
                            {
                                downloadedLength += i.m_length;
                            }
                            if (!AudioManager4CRI.SaveFileInfos(Path.Combine(AudioManager4CRI.CacheFolderPath, "AllFilesPath.txt"), AudioManager4CRI.m_cacheCriAssetFileInfos))
                            {
                                global::Debug.LogError("AudioManager4CRI.DownloadAudioFiles save cache filelist Failed .");
                                isSuccess = false;
                            }
                        }, delegate(WWW www)
                        {
                            if (onUpdate != null)
                            {
                                onUpdate(downloadedLength + (long)www.bytesDownloaded, totalDownloadLength);
                            }
                        }));
                    }
                }
            }
            else
            {
                int           downloadCoroutinCount = 0;
                HashSet <WWW> runningWWW            = new HashSet <WWW>();
                using (List <AudioManager4CRI.FileInfo> .Enumerator enumerator2 = differentFileInfos.GetEnumerator())
                {
                    while (enumerator2.MoveNext())
                    {
                        AudioManager4CRI.FileInfo i = enumerator2.Current;
                        yield return(new WaitUntil(() => downloadCoroutinCount < 4));

                        downloadCoroutinCount++;
                        coroutineOwner.StartCoroutine(AudioManager4CRI.DownloadAudioFileToCache(i, delegate(bool ret)
                        {
                            if (!ret)
                            {
                                global::Debug.LogError(string.Format("AudioManager4CRI.DownloadAudioFiles download audio file {0} Failed .", i.m_path));
                                isSuccess = false;
                            }
                            else
                            {
                                downloadedLength += i.m_length;
                            }
                            if (!AudioManager4CRI.SaveFileInfos(Path.Combine(AudioManager4CRI.CacheFolderPath, "AllFilesPath.txt"), AudioManager4CRI.m_cacheCriAssetFileInfos))
                            {
                                global::Debug.LogError("AudioManager4CRI.DownloadAudioFiles save cache filelist Failed .");
                                isSuccess = false;
                            }
                            downloadCoroutinCount--;
                        }, delegate(WWW www)
                        {
                            if (!runningWWW.Contains(www) && !www.isDone)
                            {
                                runningWWW.Add(www);
                            }
                            long num = 0L;
                            foreach (WWW www2 in runningWWW)
                            {
                                num += (long)www2.bytesDownloaded;
                            }
                            if (onUpdate != null)
                            {
                                onUpdate(downloadedLength + num, totalDownloadLength);
                            }
                            if (runningWWW.Contains(www) && www.isDone)
                            {
                                runningWWW.Remove(www);
                            }
                        }));
                    }
                }
                yield return(new WaitUntil(() => downloadCoroutinCount == 0));
            }
            if (!isSuccess)
            {
                if (onEnd != null)
                {
                    onEnd(false);
                }
                yield break;
            }
            if (onEnd != null)
            {
                onEnd(true);
            }
            yield break;
        }