private void WriteVersionFile()
        {
            string persistentFileListRelativePath = FileSystemUtils.GetFileRelativePath(FileDownloadData.FileListFileName, string.Empty);

            byte[] fileBytes = GameMain.Instance.FileOperateMgr.ReadAsBinary(persistentFileListRelativePath);
            mSynchronizeData.localVersionInfo.persistentMd5 = Utils.MD5(fileBytes);

            mSynchronizeData.localVersionInfo.serverMd5 = mSynchronizeData.serverVersionInfo.md5;
            string relativePath = FileSystemUtils.GetFileRelativePath(FileDownloadData.VersionFileName, string.Empty);
            string fileContent  = Newtonsoft.Json.JsonConvert.SerializeObject(mSynchronizeData.localVersionInfo);

            string        fileOpeError = string.Empty;
            FileErrorCode result       = FileOperateUtils.TryFileWrite(delegate() {
                GameMain.Instance.FileOperateMgr.WriteTextFile(relativePath, fileContent, false);
            }, out fileOpeError);

            if (FileErrorCode.Null == result)
            {
                mFinishHandler.Invoke();
            }
            else
            {
                mErrorHandler.Invoke(result, relativePath);
            }
        }
Ejemplo n.º 2
0
 private void EnterNextState()
 {
     if (mLocalFileListHasChange)
     {
         string        fileOpeError = string.Empty;
         FileErrorCode result       = FileOperateUtils.TryFileWrite(delegate() {
             string fileContent  = FileListUtils.FileListToString(mSynchronizeData.persistentFileListDic);
             string relativePath = FileSystemUtils.GetFileRelativePath(FileDownloadData.FileListFileName, string.Empty);
             GameMain.Instance.FileOperateMgr.WriteTextFile(relativePath, fileContent, false);
         }, out fileOpeError);
         if (FileErrorCode.Null != result)
         {
             mErrorHandler.Invoke(result, "Write filelist");
             return;
         }
     }
     if (mSynchronizeData.needDownloadSet.Count > 0)
     {
         mNextHandler.Invoke(FileDownloadStateId.DownLoadFile);
     }
     else
     {
         mNextHandler.Invoke(FileDownloadStateId.WritePersistentVersionFile);
     }
 }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        private void AbortFileTransfer(FileErrorCode errorCode)
        {
            ASDU deactivateFile = NewAsdu(new FileCallOrSelect(ioa, nof, 0, SelectAndCallQualifier.DEACTIVATE_FILE));

            master.SendASDU(deactivateFile);

            if (fileReceiver != null)
            {
                fileReceiver.Finished(errorCode);
            }

            ResetStateToIdle();
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
        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");
            }));
        }
Ejemplo n.º 7
0
        public static FileErrorCode TryFileWrite(Action proc, out string errorInfo)
        {
            int           ERROR_HANDLE_DISK_FULL = 0x27;
            int           ERROR_DISK_FULL        = 0x70;
            FileErrorCode ret = FileErrorCode.Null;

            errorInfo = string.Empty;
            try {
                proc.Invoke();
            }
            catch (System.Security.SecurityException e) {
                ret       = FileErrorCode.WriteFileNoPermission;
                errorInfo = e.ToString();
            }
            catch (System.UnauthorizedAccessException e) {
                ret       = FileErrorCode.WriteFileNoPermission;
                errorInfo = e.ToString();
            }
            catch (System.IO.IOException e) {
                var hResult = System.Runtime.InteropServices.Marshal.GetHRForException(e) & 0xFFFF;
                if (hResult == ERROR_DISK_FULL || hResult == ERROR_HANDLE_DISK_FULL)
                {
                    ret = FileErrorCode.NoSpace;
                }
                else
                {
                    ret = FileErrorCode.Unknown;
                }
                errorInfo = e.ToString();
            }
            catch (Exception e) {
                ret       = FileErrorCode.Unknown;
                errorInfo = e.ToString();
            }
            return(ret);
        }
Ejemplo n.º 8
0
        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;
            }
        }
        /// <summary>
        /// 把文件列表和Version信息同步到硬盘
        /// </summary>
        private void SyncInfoToHardDisk()
        {
            string fileOpeError = string.Empty;
            string fileListMd5  = string.Empty;
            //同步Version信息
            FileErrorCode result = FileOperateUtils.TryFileWrite(delegate() {
                string fileContent  = FileListUtils.FileListToString(mSynchronizeData.persistentFileListDic);
                fileListMd5         = Utils.MD5(fileContent);
                string relativePath = FileSystemUtils.GetFileRelativePath(FileDownloadData.FileListFileName, string.Empty);
                GameMain.Instance.FileOperateMgr.WriteTextFile(relativePath, fileContent, false);
            }, out fileOpeError);

            //同步文件列表信息
            if (FileErrorCode.Null == result)
            {
                mSynchronizeData.localVersionInfo.persistentMd5 = fileListMd5;
                result = FileOperateUtils.TryFileWrite(delegate() {
                    string fileContent  = Newtonsoft.Json.JsonConvert.SerializeObject(mSynchronizeData.localVersionInfo);
                    string relativePath = FileSystemUtils.GetFileRelativePath(FileDownloadData.VersionFileName, string.Empty);
                    GameMain.Instance.FileOperateMgr.WriteTextFile(relativePath, fileContent, false);
                }, out fileOpeError);

                if (FileErrorCode.Null == result)
                {
                    mHdlNextState.Invoke(FileDownloadStateId.LoadStreamingFileList);
                }
                else
                {
                    mHdlError.Invoke(result, "Version info");
                }
            }
            else
            {
                mHdlError.Invoke(result, "FileList info");
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="code">Error code</param>
 public FileError(FileErrorCode code) { }
Ejemplo n.º 11
0
 public void Finished(FileErrorCode result)
 {
     Console.WriteLine("File download finished - code: " + result.ToString());
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="code">Error code</param>
 /// <param name="message"></param>
 public FileException(FileErrorCode code, JsString message)
 {
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="code">Error code</param>
 public FileException(FileErrorCode code)
 {
 }
Ejemplo n.º 14
0
        private void DownLoadFile()
        {
            if (mSynchronizeData.needDownloadSet.Count == 0)
            {
                mNextHandler.Invoke(FileDownloadStateId.WritePersistentVersionFile);
                return;
            }
            ShowTipInfo();
            FileDetailInfo downloadFileInfo = mSynchronizeData.needDownloadSet [mSynchronizeData.needDownloadSet.Count - 1];

            mSynchronizeData.needDownloadSet.RemoveAt(mSynchronizeData.needDownloadSet.Count - 1);

            string fileRelativePath = null;

            if (string.IsNullOrEmpty(downloadFileInfo.filePath))
            {
                //服务器中是以MD5命名的。
                fileRelativePath = downloadFileInfo.fileMd5;
            }
            else
            {
                fileRelativePath = Path.Combine(downloadFileInfo.filePath, downloadFileInfo.fileMd5);
            }
            string fileUrl = Path.Combine(mSynchronizeData.ServerDataPath, fileRelativePath);

            mDownloadId = GameMain.Instance.HttpMgr.DownLoad(fileUrl, delegate(byte[] fileBytes) {
                Logger.LogInfo("NewDownload download file success,name:" + downloadFileInfo.fileName + " url:" + fileUrl);
                if (downloadFileInfo.fileLength != fileBytes.Length)
                {
                    mErrorHandler.Invoke(FileErrorCode.FileLengthError, fileUrl + " serverL:" + downloadFileInfo.fileLength + "  realL:" + fileBytes.Length);
                }
                else
                {
                    string md5 = Utils.MD5(fileBytes);
                    if (md5 != downloadFileInfo.fileMd5)
                    {
                        mErrorHandler.Invoke(FileErrorCode.FileMd5Error, fileUrl + " serverMd5:" + downloadFileInfo.fileMd5 + "  realMd5:" + md5);
                    }
                    else
                    {
                        string errorInfo;
                        FileErrorCode errorCode = FileOperateUtils.TryFileWrite(delegate(){
                            string relativePath = FileSystemUtils.GetFileRelativePath(downloadFileInfo.fileName, downloadFileInfo.filePath, true);
                            GameMain.Instance.FileOperateMgr.CreateDirIfNotExist(Path.GetDirectoryName(relativePath));
                            GameMain.Instance.FileOperateMgr.WriteBinaryFile(relativePath, fileBytes);
                        }, out errorInfo);
                        if (FileErrorCode.Null != errorCode)
                        {
                            mErrorHandler.Invoke(errorCode, errorInfo);
                        }
                        else
                        {
                            mSynchronizeData.persistentFileListDic.Add(downloadFileInfo.fileName, downloadFileInfo);
                            errorCode = FileOperateUtils.TryFileWrite(delegate(){
                                string detailStr    = FileListUtils.DetailInfoToString(downloadFileInfo);
                                string relativePath = FileSystemUtils.GetFileRelativePath(FileDownloadData.FileListFileName, string.Empty);
                                GameMain.Instance.FileOperateMgr.WriteTextFile(relativePath, detailStr, true);
                            }, out errorInfo);
                            if (FileErrorCode.Null != errorCode)
                            {
                                mErrorHandler.Invoke(errorCode, errorInfo);
                            }
                            else
                            {
                                mFinishFilesSize += (ulong)downloadFileInfo.fileLength;
                                mCurFileSize      = 0;
                                DownLoadFile();
                            }
                        }
                    }
                }
            }, delegate(string errorCode) {
                Logger.LogError("NewDownload download file failed,name:" + downloadFileInfo.fileName + " url:" + fileUrl);
                mErrorHandler.Invoke(FileErrorCode.DownloadFileError, fileUrl);
            }, delegate(ulong curDownloadedBytes) {
                mCurFileSize = curDownloadedBytes;
                ShowTipInfo();
            });
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="code">Error code</param>
 public FileException(FileErrorCode code) { }
Ejemplo n.º 16
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="code">Error code</param>
 /// <param name="message"></param>
 public FileException(FileErrorCode code, JsString message) { }
Ejemplo n.º 17
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="code">Error code</param>
 public FileError(FileErrorCode code) { }