ResVersionFile _GetRemoteVersionFile() { ResVersionFile versionFile; var txt = this.DownloadTxt(ResConfig.VERSION_FILE); if (string.IsNullOrEmpty(txt) == false) { versionFile = ResVersionFile.UnSerialize(txt); } else { versionFile = new ResVersionFile(0); } return(versionFile); }
ResVersionFile _GetLocalVersionFile() { ResVersionFile versionFile; byte[] bytes = null; var txt = this.LoadTxtAtPath(ResConfig.VERSION_FILE, ref bytes); if (string.IsNullOrEmpty(txt) == false) { versionFile = ResVersionFile.UnSerialize(txt); } else { versionFile = new ResVersionFile(0); } return(versionFile); }
ResVersionFile GetLocalVersionFile() { ResVersionFile versionFile; var txtAsset = this.Load <TextAsset>(ResConfig.VERSION_FILE); var txt = txtAsset.text; if (string.IsNullOrEmpty(txt) == false) { versionFile = ResVersionFile.UnSerialize(txt); } else { versionFile = new ResVersionFile(0); } // Unload this.UnloadAsset(ResConfig.VERSION_FILE); return(versionFile); }
IEnumerator HotUpdating() { // Get local version file at first var localVersionFile = GetLocalVersionFile(); // Get remote version file and compare // Download remote version file and save to temporary directory var file = ResConfig.ConvertToBundleName(ResConfig.VERSION_FILE) + ResConfig.BUNDLE_EXTENSION; var assets = new List <string>(); assets.Add(file); var fileFolder = "resversionfile_tempfolder"; var fileDirectory = ResConfig.MOBILE_HOTUPDATE_PATH + "/" + fileFolder; var failure = false; byte[] downloadBytes = null; yield return(this.StartCoroutine(this.DownloadAssetsAsyncAndSave( ResConfig.SERVER_URL + "/", assets, (processInfo, www) => { if (string.IsNullOrEmpty(processInfo.Error) == false) { failure = true; processInfo.Index = -1; processInfo.Count = 0; this.NotifyHotUpdate(processInfo); } else { var length = www.bytesDownloaded; // var length = www.bytes.Length; downloadBytes = new byte[length]; Array.Copy(www.bytes, 0, downloadBytes, 0, length); } }, fileDirectory ))); if (failure) { yield break; } var txtAsset = this.Load <TextAsset>(fileFolder + "/" + ResConfig.VERSION_FILE); if (txtAsset == null) { var processInfo = new ProcessInfo(); processInfo.File = ResConfig.VERSION_FILE; processInfo.Index = -1; processInfo.Count = 0; processInfo.Error = "Download version file error"; this.NotifyHotUpdate(processInfo); yield break; } var txt = txtAsset.text; var remoteVersionFile = ResVersionFile.UnSerialize(txt); // Unload asset bundle this.UnloadAsset(fileFolder + "/" + ResConfig.VERSION_FILE); // Hotupdating(download and save) var diffInfos = ResVersionFile.GetDiffInfos(localVersionFile, remoteVersionFile); if (diffInfos.Count <= 0) { this.NotifyNoHotUpdate(); yield break; } assets.Clear(); for (int i = 0; i < diffInfos.Count; ++i) { var asset = diffInfos[i].File; assets.Add(asset); } var count = assets.Count; var downloadedCount = 0; yield return(this.StartCoroutine(this.DownloadAssetsAsyncAndSave( ResConfig.SERVER_URL + "/", assets, (processInfo, www) => { downloadedCount++; processInfo.Index = downloadedCount - 1; processInfo.Count = assets.Count; this.NotifyHotUpdate(processInfo); } ))); // Finally replace local version file FileUtility.WriteFile(ResConfig.MOBILE_HOTUPDATE_PATH + "/" + file, downloadBytes, downloadBytes.Length, false); }