Esempio n. 1
0
        private void LoadPersistentDataFileList()
        {
            mPersistentFileListRelativePath = FileSystemUtils.GetFileRelativePath(FileDownloadData.FileListFileName, string.Empty);
            if (!GameMain.Instance.FileOperateMgr.IsFileExist(mPersistentFileListRelativePath))
            {
                GenerateCopyList();
                return;
            }
            string fileContent = GameMain.Instance.FileOperateMgr.ReadAsText(mPersistentFileListRelativePath);

            FileListUtils.FileListParseError error;
            mPersistentFileListDic = FileListUtils.StringToFileList(fileContent, out error);
            if (FileListUtils.FileListParseError.Null == error)
            {
                GenerateCopyList();
            }
            else
            {
                OnError("Parse persistent fileList " + error.ToString());
            }
        }
Esempio n. 2
0
        private void LoadStreamingFileList()
        {
            string relativePath = FileSystemUtils.GetFileRelativePath(FileDownloadData.FileListFileName, string.Empty);

            this.StartCoroutine(LoadFile(relativePath, delegate(byte[] fileBytes) {
                //保存的文件是无BOM形式的,所以直接用Encoding.UTF8.GetString不会有问题
                string fileContent = Encoding.UTF8.GetString(fileBytes);
                FileListUtils.FileListParseError error;
                mStreamingFileListDic = FileListUtils.StringToFileList(fileContent, out error);
                if (FileListUtils.FileListParseError.Null == error)
                {
                    LoadPersistentDataFileList();
                }
                else
                {
                    OnError("Parse streaming fileList " + error.ToString());
                }
            }, delegate() {
                OnError("Load streaming fileList");
            }));
        }
Esempio n. 3
0
 void RequestServerFileList()
 {
     mDownloadId = GameMain.Instance.HttpMgr.DownLoad(mSynchronizeData.ServerFileListPath, delegate(byte[] data) {
         string fileContent = Encoding.UTF8.GetString(data);
         FileListUtils.FileListParseError errorCode;
         mSynchronizeData.serverFileListDic = FileListUtils.StringToFileList(fileContent, out errorCode);
         if (FileListUtils.FileListParseError.Null != errorCode)
         {
             mErrorHandler.Invoke(FileErrorCode.ParseFileListError, "Parse server fileList " + errorCode.ToString());
             return;
         }
         if (mSynchronizeData.serverFileListDic.Count == 0)
         {
             mErrorHandler.Invoke(FileErrorCode.ParseFileListError, "Server fileList parse error, file length:" + fileContent.Length);
             return;
         }
         mNextStateHandler.Invoke(FileDownloadStateId.CompareFileList);
     }, delegate(string error) {
         mErrorHandler.Invoke(FileErrorCode.DownLoadFileListError, " Request server file list error: " + error);
     });
 }
        private void LoadFileList()
        {
            string fileListRelativePath = FileSystemUtils.GetFileRelativePath(FileDownloadData.FileListFileName, string.Empty);
            string filelistPath         = Path.Combine(Application.streamingAssetsPath, fileListRelativePath);

            if (!File.Exists(filelistPath))
            {
                Finish();
                return;
            }
            string fileContent = GameMain.Instance.FileOperateMgr.ReadAsText(filelistPath);

            FileListUtils.FileListParseError error;
            mSynchronizeData.streamingFileListDic = FileListUtils.StringToFileList(fileContent, out error);
            if (error != FileListUtils.FileListParseError.Null)
            {
                mErrorHandler.Invoke(FileErrorCode.ParseFileListError, "Load streaming file list " + error.ToString());
            }
            else
            {
                Finish();
            }
        }
        /// <summary>
        /// 加载文件列表和Version信息,并做内容合法检查
        /// </summary>
        private void LoadInfo()
        {
            string localVersionFilePath = FileSystemUtils.GetFileRelativePath(FileDownloadData.VersionFileName, string.Empty);

            if (GameMain.Instance.FileOperateMgr.IsFileExist(localVersionFilePath))
            {
                string localVersionContent = GameMain.Instance.FileOperateMgr.ReadAsText(localVersionFilePath);
                mSynchronizeData.localVersionInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <LocalVersionInfo> (localVersionContent);
            }
            if (null == mSynchronizeData.localVersionInfo)
            {
                mSynchronizeData.localVersionInfo = new LocalVersionInfo();
                mSynchronizeData.localVersionInfo.Clear();
            }

            string localFileListFilePath = FileSystemUtils.GetFileRelativePath(FileDownloadData.FileListFileName, string.Empty);
            Dictionary <string, FileDetailInfo> fileListDic = null;

            if (GameMain.Instance.FileOperateMgr.IsFileExist(localFileListFilePath))
            {
                string fileListContent = GameMain.Instance.FileOperateMgr.ReadAsText(localFileListFilePath);
                FileListUtils.FileListParseError error = FileListUtils.FileListParseError.Null;
                fileListDic = FileListUtils.StringToFileList(fileListContent, out error);
                if (FileListUtils.FileListParseError.Null != error)
                {
                    //文件列表已经被破坏,所以直接删除文件
                    GameMain.Instance.FileOperateMgr.DeleteIfExist(localVersionFilePath);
                    GameMain.Instance.FileOperateMgr.DeleteIfExist(localFileListFilePath);
                }
                else
                {
                    string localFileListMd5 = Utils.MD5(fileListContent);
                    if (localFileListMd5 != mSynchronizeData.localVersionInfo.persistentMd5)
                    {
                        //文件列表被修改
                        mSynchronizeData.localVersionInfo.Clear();
                    }
                }
            }
            if (null == fileListDic)
            {
                //如果文件列表不存在,那么有可能是被其他系统删除,也有可能是文件解析失败,所以清空localVersionInfo,保证一定能够进入CompareFileListState状态
                mSynchronizeData.localVersionInfo.Clear();
                mSynchronizeData.persistentFileListDic = new Dictionary <string, FileDetailInfo> ();
            }
            else
            {
                List <string> removeList = new List <string> ();
                Dictionary <string, FileDetailInfo> .Enumerator enumerator = fileListDic.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    FileDetailInfo detailInfo = enumerator.Current.Value;
                    if (detailInfo.IsInvalid())
                    {
                        removeList.Add(enumerator.Current.Key);
                    }
                }
                if (removeList.Count > 0)
                {
                    //有部分信息是不合法的,那么一定需要进入CompareFileListState状态
                    mSynchronizeData.localVersionInfo.Clear();
                    for (int i = 0; i < removeList.Count; ++i)
                    {
                        fileListDic.Remove(removeList [i]);
                    }
                }
                mSynchronizeData.persistentFileListDic = fileListDic;
            }
        }