public void Finished(FileErrorCode result) { Console.WriteLine("File download finished - code: " + result.ToString()); // now the valid file data it in the buffer. User can now handle the file data (e.g. store data in local file system) if (result == FileErrorCode.SUCCESS) { File.WriteAllBytes("file_30001.dat", recvBuffer); } }
private void CopyFiles() { Lancher.Instance.SetTips("请稍等,正在解压资源......(" + (mCopyFileMaxCount - mCopyList.Count).ToString() + "/" + mCopyFileMaxCount + ")"); if (mCopyList.Count == 0) { mHdlOnFinish.Invoke(); return; } string fileName = mCopyList[mCopyList.Count - 1]; mCopyList.RemoveAt(mCopyList.Count - 1); FileDetailInfo fileInfo = mStreamingFileListDic [fileName]; string relativePath = FileSystemUtils.GetFileRelativePath(fileName, fileInfo.filePath, true); this.StartCoroutine(LoadFile(relativePath, delegate(byte[] fileBytes) { GameMain.Instance.FileOperateMgr.CreateDirIfNotExist(Path.GetDirectoryName(relativePath)); string fileOpeErrorStr; FileErrorCode errorCode = FileOperateUtils.TryFileWrite(delegate(){ Logger.LogInfo("AndroidStreamingCopy copy file " + relativePath); GameMain.Instance.FileOperateMgr.WriteBinaryFile(relativePath, fileBytes); }, out fileOpeErrorStr); if (FileErrorCode.Null != errorCode) { OnError("AndroidStreamingCopy Write " + relativePath + " " + errorCode.ToString() + " " + fileOpeErrorStr); return; } errorCode = FileOperateUtils.TryFileWrite(delegate(){ string detailStr = FileListUtils.DetailInfoToString(fileInfo); GameMain.Instance.FileOperateMgr.WriteTextFile(mPersistentFileListRelativePath, detailStr, true); }, out fileOpeErrorStr); if (FileErrorCode.Null != errorCode) { OnError("AndroidStreamingCopy write fileList " + errorCode.ToString() + " " + fileOpeErrorStr); return; } CopyFiles(); }, delegate() { OnError("Load streaming FileList"); })); }
private void OnError(FileErrorCode error, string param) { Logger.LogError("Download onError " + error.ToString() + " " + param); switch (error) { case FileErrorCode.DownLoadFileListError: case FileErrorCode.ParseFileListError: case FileErrorCode.DownloadFileError: case FileErrorCode.FileMd5Error: case FileErrorCode.FileLengthError: case FileErrorCode.Unknown: Lancher.Instance.ShowDialog("下载失败,错误码:" + error.ToString(), delegate() { EnterState(FileDownloadStateId.GetServerFileList); }); break; case FileErrorCode.NoSpace: case FileErrorCode.WriteFileNoPermission: break; default: break; } }
private void GenerateCopyList() { bool hasPersistentListChanged = false; Dictionary <string, FileDetailInfo> .Enumerator enumerateo = mStreamingFileListDic.GetEnumerator(); while (enumerateo.MoveNext()) { string fileName = enumerateo.Current.Key; FileDetailInfo streamDetailInfo = enumerateo.Current.Value; FileDetailInfo persistentDetailInfo = null; if (null == mPersistentFileListDic || !mPersistentFileListDic.TryGetValue(fileName, out persistentDetailInfo)) { mCopyList.Add(fileName); } else { if (persistentDetailInfo.fileMd5 != streamDetailInfo.fileMd5 || persistentDetailInfo.filePath != streamDetailInfo.filePath) { string relativePath = FileSystemUtils.GetFileRelativePath(fileName, persistentDetailInfo.filePath, true); GameMain.Instance.FileOperateMgr.DeleteIfExist(relativePath); mCopyList.Add(fileName); hasPersistentListChanged = true; mPersistentFileListDic.Remove(fileName); } } } if (hasPersistentListChanged) { //使Persistent目录下的文件列表和实际文件一致,避免下一阶段拷贝中断造成文件列表和实际文件不一致 string errorStr; FileErrorCode errorCode = FileListUtils.WriteFileList(mPersistentFileListDic, out errorStr); if (FileErrorCode.Null != errorCode) { OnError("GenerateCopyList write persistent fileList " + errorCode.ToString() + " " + errorStr); return; } } mCopyFileMaxCount = mCopyList.Count; CopyFiles(); }
public void Finished(FileErrorCode result) { Console.WriteLine("File download finished - code: " + result.ToString()); }