void _StartDownloadMasterFile() { _currentProgress = 0.0f; _downloadMaterfileByteArray = null; string masterFileUrl = EAAssetBundleInfoMgr.GetMasterFileRemoteURL(DOWNLOADING_BUNDLE_VERSION, string.Empty); Debug.Log("MasterFileUrl: " + masterFileUrl); UnityWebRequest http = CreateHttp(new Uri(masterFileUrl), (UnityWebRequest webReq) => { if (!string.IsNullOrEmpty(webReq.error)) { _OnNetworkError(@"StatusCode:" + webReq.error); return(false); } if (webReq.downloadHandler.isDone == false || webReq.downloadProgress < 1.0f) { return(false); } Debug.Log("Finished!"); _currentProgress = 1; _continuousNetworkErrorCnt = 0; _currentFile = string.Empty; try { using (MemoryStream deserialize = new MemoryStream(webReq.downloadHandler.data)) { EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo = new AssetBundleMasterFileInfo(); StreamReader reader = new StreamReader(deserialize); List <string> lines = new List <string>(); string line; while ((line = reader.ReadLine()) != null) { lines.Add(line); } EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo.bundleVersion = lines[0]; EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo.assetBundleMasterFileDic = AssetBundleMasterFileInfo.LoadAssetBundleMasterFileDic(lines); _downloadMaterfileByteArray = webReq.downloadHandler.data; } } catch (Exception e) { // master 파일데이터 깨짐? _OnNetworkError(e.Message); return(false); } webReq.Dispose(); _ChangeState(State.CalcDownloadList); Debug.Log("m_AssetBundleMgr count:" + EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo.assetBundleMasterFileDic.Count); return(true); }); http.SendWebRequest(); }
public static AssetBundleMasterFileInfo GetMasterFileInfo() { if (_masterFileInfo == null || _masterFileInfo.assetBundleMasterFileDic.Count == 0) { //마스터 파일에 관한 정보가 없으면 로컬에 있는 마스터 파일을 불러온다. List <string> stringLineArray = FileManager.LoadTextLineList(AssetBundleConfig.m_LocalPath + @"BundleMasterFileInfo.bundlelist"); _masterFileInfo = new AssetBundleMasterFileInfo(); if (stringLineArray == null || stringLineArray.Count <= 0) { //마스터파일 오류시에 삭제 if (File.Exists(AssetBundleConfig.m_LocalPath + @"BundleMasterFileInfo.bundlelist")) { File.Delete(AssetBundleConfig.m_LocalPath + @"BundleMasterFileInfo.bundlelist"); } } else { //정상적으로 마스터 파일을 불러왔을경우 //첫줄 번들버전정보 _masterFileInfo.bundleVersion = stringLineArray[0]; //마스터 파일 정보 로드 _masterFileInfo.assetBundleMasterFileDic = AssetBundleMasterFileInfo.LoadAssetBundleMasterFileDic(stringLineArray); } if (CoreApplication.IsMobileIPhone) { // IOS 경우에는 StreamAssets에 있는 마스터 파일 로드 stringLineArray = FileManager.LoadTextLineList(AssetBundleConfig.m_streamingAssetsPath + @"BundleMasterFileInfo.bundlelist"); if (_masterFileInfo.assetBundleMasterFileDic.Count > 0) { //다운 받았던 번들정보가 있으므로 다운받은 마스터 버전 을 사용 } else { //다운받은 번들정가 없으므로 로컬에 있는 번들버전을 사용 _masterFileInfo.bundleVersion = stringLineArray[0]; } Char[] delimiters = { '\t', '\t', '\t', '\t', '\t' }; string key = string.Empty; for (int index = 1; index < stringLineArray.Count; index++) { //순서 : 파일경로, 파일이름, CRC, 파일용량 string[] items = stringLineArray[index].Split(delimiters); //키값을 생성한다 (소문자 경로) key = string.Format(@"{0}/{1}", items[0], items[2]).ToLower(); if (_masterFileInfo.assetBundleMasterFileDic.ContainsKey(key)) { if (items.Length == 5) { //이미 키가 있을 경우 비교를 한후 CRC가 다르면 m_streamingAssets = false 같으면 m_streamingAssets = true if (_masterFileInfo.assetBundleMasterFileDic[key].m_crc == Int32.Parse(items[3])) { _masterFileInfo.assetBundleMasterFileDic[key].m_streamingAssets = true; //IOS 경우 어떤 걸 사용하지 여부 판단 if (EAAssetBundleLoadModule.m_streamAseetBundle.ContainsKey(_masterFileInfo.assetBundleMasterFileDic[key].m_fileName)) { EAAssetBundleLoadModule.m_streamAseetBundle[_masterFileInfo.assetBundleMasterFileDic[key].m_fileName] = true; } else { EAAssetBundleLoadModule.m_streamAseetBundle.Add(_masterFileInfo.assetBundleMasterFileDic[key].m_fileName, true); } } else { _masterFileInfo.assetBundleMasterFileDic[key].m_streamingAssets = false; //IOS 경우 어떤 걸 사용하지 여부 판단 if (EAAssetBundleLoadModule.m_streamAseetBundle.ContainsKey(_masterFileInfo.assetBundleMasterFileDic[key].m_fileName)) { EAAssetBundleLoadModule.m_streamAseetBundle[_masterFileInfo.assetBundleMasterFileDic[key].m_fileName] = false; } else { EAAssetBundleLoadModule.m_streamAseetBundle.Add(_masterFileInfo.assetBundleMasterFileDic[key].m_fileName, false); } } } else if (items.Length == 6) { //내부 번들이 해쉬값을 가지고 있음으로 해쉬 비교를 해준다. if (!string.IsNullOrEmpty(items[5]) && !string.IsNullOrEmpty(_masterFileInfo.assetBundleMasterFileDic[key].m_hash)) { //둘다 해쉬값이 있으므로 해쉬비교 //이미 키가 있을 경우 비교를 한후 해쉬값이 다르면 m_streamingAssets = false 같으면 m_streamingAssets = true if (_masterFileInfo.assetBundleMasterFileDic[key].m_hash.Equals(items[5])) { _masterFileInfo.assetBundleMasterFileDic[key].m_streamingAssets = true; //IOS 경우 어떤 걸 사용하지 여부 판단 if (EAAssetBundleLoadModule.m_streamAseetBundle.ContainsKey(_masterFileInfo.assetBundleMasterFileDic[key].m_fileName)) { EAAssetBundleLoadModule.m_streamAseetBundle[_masterFileInfo.assetBundleMasterFileDic[key].m_fileName] = true; } else { EAAssetBundleLoadModule.m_streamAseetBundle.Add(_masterFileInfo.assetBundleMasterFileDic[key].m_fileName, true); } } else { _masterFileInfo.assetBundleMasterFileDic[key].m_streamingAssets = false; //IOS 경우 어떤 걸 사용하지 여부 판단 if (EAAssetBundleLoadModule.m_streamAseetBundle.ContainsKey(_masterFileInfo.assetBundleMasterFileDic[key].m_fileName)) { EAAssetBundleLoadModule.m_streamAseetBundle[_masterFileInfo.assetBundleMasterFileDic[key].m_fileName] = false; } else { EAAssetBundleLoadModule.m_streamAseetBundle.Add(_masterFileInfo.assetBundleMasterFileDic[key].m_fileName, false); } } } else { //이미 키가 있을 경우 비교를 한후 CRC가 다르면 m_streamingAssets = false 같으면 m_streamingAssets = true if (_masterFileInfo.assetBundleMasterFileDic[key].m_crc == Int32.Parse(items[3])) { _masterFileInfo.assetBundleMasterFileDic[key].m_streamingAssets = true; //IOS 경우 어떤 걸 사용하지 여부 판단 if (EAAssetBundleLoadModule.m_streamAseetBundle.ContainsKey(_masterFileInfo.assetBundleMasterFileDic[key].m_fileName)) { EAAssetBundleLoadModule.m_streamAseetBundle[_masterFileInfo.assetBundleMasterFileDic[key].m_fileName] = true; } else { EAAssetBundleLoadModule.m_streamAseetBundle.Add(_masterFileInfo.assetBundleMasterFileDic[key].m_fileName, true); } } else { _masterFileInfo.assetBundleMasterFileDic[key].m_streamingAssets = false; //IOS 경우 어떤 걸 사용하지 여부 판단 if (EAAssetBundleLoadModule.m_streamAseetBundle.ContainsKey(_masterFileInfo.assetBundleMasterFileDic[key].m_fileName)) { EAAssetBundleLoadModule.m_streamAseetBundle[_masterFileInfo.assetBundleMasterFileDic[key].m_fileName] = false; } else { EAAssetBundleLoadModule.m_streamAseetBundle.Add(_masterFileInfo.assetBundleMasterFileDic[key].m_fileName, false); } } } } } else { //키값이 없을 경우 그냥 추가 //내부의 것이니 m_streamingAssets 을 true로 한다. if (items.Length == 5) { _masterFileInfo.assetBundleMasterFileDic.Add(key, new AssetBundleMasterFile(items[0], items[1], items[2], Int32.Parse(items[3]), Int32.Parse(items[4]), string.Empty, true)); } else if (items.Length == 6) { _masterFileInfo.assetBundleMasterFileDic.Add(key, new AssetBundleMasterFile(items[0], items[1], items[2], Int32.Parse(items[3]), Int32.Parse(items[4]), items[5], true)); } //IOS 경우 어떤 걸 사용하지 여부 판단 if (EAAssetBundleLoadModule.m_streamAseetBundle.ContainsKey(_masterFileInfo.assetBundleMasterFileDic[key].m_fileName)) { EAAssetBundleLoadModule.m_streamAseetBundle[_masterFileInfo.assetBundleMasterFileDic[key].m_fileName] = true; } else { EAAssetBundleLoadModule.m_streamAseetBundle.Add(_masterFileInfo.assetBundleMasterFileDic[key].m_fileName, true); } } } } } return(_masterFileInfo); }
/// <summary> /// Check the list of bundles recorded on the master to find out which files need patches. /// </summary> IEnumerator _BuildDownloadList() { _downloadList.Clear(); int counter = 0; float prevTime = Time.realtimeSinceStartup; _downloadSize = 0; string retError; AssetBundleMasterFileInfo compareMaterFileInfo = AssetBundleConfig.GetMasterFileInfo(); // Android is used as is if (CoreApplication.IsMobileIPhone) { //IOS uses internal master files. List <string> stringLineArray = FileManager.LoadTextLineList(AssetBundleConfig.m_streamingAssetsPath + @"BundleMasterFileInfo.bundlelist"); compareMaterFileInfo.assetBundleMasterFileDic = AssetBundleMasterFileInfo.LoadAssetBundleMasterFileDic(stringLineArray); } foreach (string key in EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo.assetBundleMasterFileDic.Keys) { Debug.Log("Downloader._BuildDownloadList() check.. " + counter); counter++; if (compareMaterFileInfo.assetBundleMasterFileDic.Count <= 0) { // Check everything because there is no master file if (!_CheckBundleFileConsistency(EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo.assetBundleMasterFileDic[key], true, out retError)) { Debug.Log("Downloader._BuildDownloadList() - AddFile: " + EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo.assetBundleMasterFileDic[key].GetBundleLocalSaveFilePath()); _downloadList.Add(EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo.assetBundleMasterFileDic[key]); _downloadSize += EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo.assetBundleMasterFileDic[key].m_size; } } else { //Since there is a master file, the standard file is checked. if (compareMaterFileInfo.assetBundleMasterFileDic.ContainsKey(key)) { //Judge whether there is hash information in the saved and received master file if (!string.IsNullOrEmpty(compareMaterFileInfo.assetBundleMasterFileDic[key].m_hash) && !string.IsNullOrEmpty(EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo.assetBundleMasterFileDic[key].m_hash)) { //Both compare to the hash if there is one. if (compareMaterFileInfo.assetBundleMasterFileDic[key].m_hash.Equals(EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo.assetBundleMasterFileDic[key].m_hash)) { //Pass if the hashes are equal if (CoreApplication.IsMobileIPhone) { string path = string.Format("{0}{1}", AssetBundleConfig.m_LocalPath, compareMaterFileInfo.assetBundleMasterFileDic[key].m_fileName); // If you have an iPhone, check the file and remove it if it exists if (File.Exists(path)) { File.Delete(path); } } } else { //If the hash is different, the file is compared to the hash value and added to the download list if (!_CheckBundleFileConsistency(EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo.assetBundleMasterFileDic[key], true, out retError)) { Debug.Log("Downloader._BuildDownloadList() - AddFile: " + EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo.assetBundleMasterFileDic[key].GetBundleLocalSaveFilePath()); _downloadList.Add(EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo.assetBundleMasterFileDic[key]); _downloadSize += EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo.assetBundleMasterFileDic[key].m_size; } } } else { //If a file has no hash information, it is compared with crc. if (compareMaterFileInfo.assetBundleMasterFileDic[key].m_crc == EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo.assetBundleMasterFileDic[key].m_crc) { //Pass if CRC values are equal if (CoreApplication.IsMobileIPhone) { string path = string.Format("{0}{1}", AssetBundleConfig.m_LocalPath, compareMaterFileInfo.assetBundleMasterFileDic[key].m_fileName); //If you have an iPhone, check the file and remove it if it exists. if (File.Exists(path)) { File.Delete(path); } } } else { //If the CRC values are different, add the download list after comparing the file with the CRC. if (!_CheckBundleFileConsistency(EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo.assetBundleMasterFileDic[key], true, out retError)) { Debug.Log("Downloader._BuildDownloadList() - AddFile: " + EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo.assetBundleMasterFileDic[key].GetBundleLocalSaveFilePath()); _downloadList.Add(EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo.assetBundleMasterFileDic[key]); _downloadSize += EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo.assetBundleMasterFileDic[key].m_size; } } } } else { //If the master file is not in the list, add it unconditionally. _downloadList.Add(EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo.assetBundleMasterFileDic[key]); _downloadSize += EAAssetBundleLoadModule.m_AssetBundleMasterFileInfo.assetBundleMasterFileDic[key].m_size; } } if (Time.realtimeSinceStartup - prevTime > 0.05f) { prevTime = Time.realtimeSinceStartup; yield return(null); } } if (_downloadList.Count == 0) { _ChangeState(State.End); } else { _ChangeState(State.ShowConfirmMsg); } }
public AssetBundleMasterFileInfo(AssetBundleMasterFileInfo info) { bundleVersion = info.bundleVersion; assetBundleMasterFileDic = info.assetBundleMasterFileDic; }