/// <summary> /// 更新资源信息文件 /// </summary> /// <param name="fileName">File name.</param> private void UpdateResoureceInfoData(string fileName) { ResourcesInfoData localResourceInfoData = new ResourcesInfoData(); if (File.Exists(AssetBundleFilePath.ServerExtensionDataPath + "ResourceInfoData.csv")) { localResourceInfoData.InitFromPath(AssetBundleFilePath.ServerExtensionDataPath + "ResourceInfoData.csv"); } else { localResourceInfoData.InitFromResource(); } int localId = localResourceInfoData.GetIDByBundleName(fileName); int serverId = serverResourceInfoData.GetIDByBundleName(fileName); int verCode = serverResourceInfoData.GetVersionCode(serverId); string crc = serverResourceInfoData.GetCRC(serverId); string hash = serverResourceInfoData.GetHashCode(serverId); if (localId < 0) { localResourceInfoData.AddRowWithoutId(fileName, verCode.ToString(), crc, hash); } else { localResourceInfoData.SetVersionCode(localId, verCode); localResourceInfoData.SetCRC(localId, crc); localResourceInfoData.SetHashCode(localId, hash); } StringBuilder strBuilder = localResourceInfoData.GetTotalString(); FileStream assetFile = File.Open(AssetBundleFilePath.ServerExtensionDataPath + "ResourceInfoData.csv", FileMode.Create); StreamWriter sw = new StreamWriter(assetFile, Encoding.UTF8); sw.Write(strBuilder); sw.Close(); assetFile.Close(); }
/// <summary> /// 对比本地和服务器上的ResourceInfoData /// 确定要下载的文件 /// </summary> /// <returns>The compare info file.</returns> IEnumerator IECompareInfoFile() { WWW getAssetInfoW = new WWW(serverAddr + "ResourceInfoData.csv"); yield return(getAssetInfoW); if (getAssetInfoW.error != null) { Debug.LogError("can not connect to server"); yield break; } string infoText = getAssetInfoW.text; serverResourceInfoData = new ResourcesInfoData(); serverResourceInfoData.InitFromString(infoText); ResourcesInfoData localResourceInfoData = new ResourcesInfoData(); if (File.Exists(AssetBundleFilePath.ServerExtensionDataPath + "ResourceInfoData.csv")) { localResourceInfoData.InitFromPath(AssetBundleFilePath.ServerExtensionDataPath + "ResourceInfoData.csv"); } else { localResourceInfoData.InitFromResource(); } downLoadFileList.Clear(); downingFileCount = 0; for (int i = 1; i <= serverResourceInfoData.GetDataRow(); ++i) { string bundleName = serverResourceInfoData.GetBundleName(i); int serverVersionCode = serverResourceInfoData.GetVersionCode(i); int localVerCode = localResourceInfoData.GetVersionCodeByBundleName(bundleName); if (localVerCode < 0) { downLoadFileList.Add(bundleName); } else if (localVerCode < serverVersionCode) { downLoadFileList.Add(bundleName); } Debug.Log(bundleName + " " + serverVersionCode + " " + localVerCode); } if (downLoadFileList.Count > 0) { isDownloadingFile = true; downloadFileIndex = 1; totalFileCount = downLoadFileList.Count; downloadRetryCount = 0; DownLoadNextFile(); } else { Debug.Log("ALL file had updated"); EndHotFixUpdate(); } }