Example #1
0
        void IFsmNode.OnEnter()
        {
            PatchEventDispatcher.SendPatchStatesChangeMsg(EPatchStates.CheckSandboxDirty);

            string appVersion = PatchManager.Instance.GetAPPVersion();
            string filePath   = PatchHelper.GetSandboxStaticFilePath();

            // 记录APP版本信息到静态文件
            if (PatchHelper.CheckSandboxStaticFileExist() == false)
            {
                PatchHelper.Log(ELogLevel.Log, $"Create sandbox static file : {filePath}");
                FileUtility.CreateFile(filePath, appVersion);
                _patcher.SwitchNext();
                return;
            }

            // 每次启动时比对APP版本号是否一致
            string recordVersion = FileUtility.ReadFile(filePath);

            // 如果记录的版本号不一致
            if (recordVersion != appVersion)
            {
                PatchHelper.Log(ELogLevel.Warning, $"Sandbox is dirty, Record version is {recordVersion}, APP version is {appVersion}");
                PatchHelper.Log(ELogLevel.Warning, "Clear all sandbox files.");
                PatchHelper.ClearSandbox();
                _patcher.SwitchLast();
            }
            else
            {
                _patcher.SwitchNext();
            }
        }
        public IEnumerator Download()
        {
            // 请求游戏版本
            string webURL      = _patcher.GetWebServerURL();
            string postContent = _patcher.GetWebPostContent();

            MotionLog.Log($"Beginning to request from web : {webURL}");
            MotionLog.Log($"Web post content : {postContent}");
            WebPostRequest download = new WebPostRequest(webURL);

            download.SendRequest(postContent);
            yield return(download);

            // Check fatal
            if (download.HasError())
            {
                download.ReportError();
                download.Dispose();
                PatchEventDispatcher.SendGameVersionRequestFailedMsg();
                yield break;
            }

            string responseContent = download.GetResponse();

            MotionLog.Log($"Succeed get response from web : {responseContent}");
            download.Dispose();
            _patcher.ParseResponseContent(responseContent);
            _patcher.SwitchNext();
        }
        public IEnumerator Download()
        {
            // 获取最新的游戏版本号
            {
                string url  = _patcher.GetWebServerIP();
                string post = _patcher.GetWebPostData();
                MotionLog.Log($"Beginning to request from web : {url} {post}");
                WebPostRequest download = new WebPostRequest(url, post);
                download.DownLoad();
                yield return(download);

                //Check fatal
                if (download.HasError())
                {
                    download.ReportError();
                    download.Dispose();
                    PatchEventDispatcher.SendGameVersionRequestFailedMsg();
                    yield break;
                }

                string response = download.GetResponse();
                MotionLog.Log($"Succeed get response from web : {url} {response}");
                _patcher.ParseWebResponseData(response);
                download.Dispose();
            }

            // 检测强更安装包
            if (_patcher.ForceInstall)
            {
                string requestedGameVersion = _patcher.RequestedGameVersion.ToString();
                MotionLog.Log($"Found new APP can be install : {requestedGameVersion}");
                PatchEventDispatcher.SendFoundForceInstallAPPMsg(requestedGameVersion, _patcher.AppURL);
                yield break;
            }

            // 检测资源版本是否变化
            int newResourceVersion = _patcher.RequestedResourceVersion;
            int oldResourceVersion = _patcher.LocalResourceVersion;

            if (newResourceVersion == oldResourceVersion)
            {
                MotionLog.Log($"Resource version is not change.");
                _patcher.Switch(EPatchStates.DownloadOver.ToString());
            }
            else
            {
                MotionLog.Log($"Resource version is change : {oldResourceVersion} -> {newResourceVersion}");
                _patcher.SwitchNext();
            }
        }
        public IEnumerator Download()
        {
            // 获取最新的游戏版本号
            {
                string url  = _patcher.GetWebServerIP();
                string post = _patcher.GetWebPostData();
                PatchHelper.Log(ELogLevel.Log, $"Request game version : {url} : {post}");
                WebPostRequest download = new WebPostRequest(url, post);
                yield return(download.DownLoad());

                //Check fatal
                if (download.States != EWebRequestStates.Success)
                {
                    download.Dispose();
                    PatchEventDispatcher.SendGameVersionRequestFailedMsg();
                    yield break;
                }

                string responseData = download.GetResponse();
                _patcher.ParseResponseData(responseData);
                download.Dispose();
            }

            int newResourceVersion = _patcher.RequestedResourceVersion;
            int oldResourceVersion = _patcher.SandboxPatchManifest.Version;

            // 检测强更安装包
            string appInstallURL = _patcher.GetForceInstallAppURL();

            if (string.IsNullOrEmpty(appInstallURL) == false)
            {
                PatchHelper.Log(ELogLevel.Log, $"Found new APP can be install : {_patcher.GameVersion.ToString()}");
                PatchEventDispatcher.SendFoundForceInstallAPPMsg(_patcher.GameVersion.ToString(), appInstallURL);
                yield break;
            }

            // 检测资源版本是否变化
            if (newResourceVersion == oldResourceVersion)
            {
                PatchHelper.Log(ELogLevel.Log, $"Resource version is not change.");
                _patcher.Switch(EPatchStates.DownloadOver.ToString());
            }
            else
            {
                PatchHelper.Log(ELogLevel.Log, $"Resource version is change : {oldResourceVersion} -> {newResourceVersion}");
                _patcher.SwitchNext();
            }
        }
Example #5
0
        private IEnumerator Download()
        {
            var downloader = _patcher.InternalDownloader;

            // 注册下载回调
            downloader.OnPatchFileCheckFailedCallback     = PatchEventDispatcher.SendWebFileCheckFailedMsg;
            downloader.OnPatchFileDownloadFailedCallback  = PatchEventDispatcher.SendWebFileDownloadFailedMsg;
            downloader.OnPatchFileDownloadSucceedCallback = PatchEventDispatcher.SendDownloadFilesProgressMsg;
            downloader.Download();
            yield return(downloader);

            // 检测下载结果
            if (downloader.DownloadStates != EDownloaderStates.Succeed)
            {
                yield break;
            }

            _patcher.SwitchNext();
        }
        void IFsmNode.OnEnter()
        {
            PatchEventDispatcher.SendPatchStatesChangeMsg(EPatchStates.ParseSandboxPatchManifest);

            // 读取并解析沙盒内的补丁清单
            if (PatchHelper.CheckSandboxPatchManifestFileExist())
            {
                string filePath    = AssetPathHelper.MakePersistentLoadPath(PatchDefine.PatchManifestFileName);
                string fileContent = PatchHelper.ReadFile(filePath);

                PatchHelper.Log(ELogLevel.Log, $"Parse sandbox patch file.");
                _patcher.ParseSandboxPatchManifest(fileContent);
            }
            else
            {
                _patcher.ParseSandboxPatchManifest(_patcher.AppPatchManifest);
            }

            _patcher.SwitchNext();
        }
        private IEnumerator DownLoad()
        {
            // 解析APP里的补丁清单
            string         filePath   = AssetPathHelper.MakeStreamingLoadPath(PatchDefine.PatchManifestFileName);
            string         url        = AssetPathHelper.ConvertToWWWPath(filePath);
            WebDataRequest downloader = new WebDataRequest(url);

            yield return(downloader.DownLoad());

            if (downloader.States == EWebRequestStates.Success)
            {
                PatchHelper.Log(ELogLevel.Log, "Parse app patch manifest.");
                _patcher.ParseAppPatchManifest(downloader.GetText());
                downloader.Dispose();
                _patcher.SwitchNext();
            }
            else
            {
                throw new System.Exception($"Fatal error : Failed download file : {url}");
            }
        }
        private IEnumerator Download()
        {
            // 从网络上解析最新的补丁清单
            int            newResourceVersion = _patcher.RequestedResourceVersion;
            string         url      = _patcher.GetWebDownloadURL(newResourceVersion.ToString(), PatchDefine.PatchManifestBytesFileName);
            WebDataRequest download = new WebDataRequest(url);

            yield return(download.DownLoad());

            // Check fatal
            if (download.States != EWebRequestStates.Success)
            {
                download.Dispose();
                PatchEventDispatcher.SendWebPatchManifestDownloadFailedMsg();
                yield break;
            }

            MotionLog.Log($"Parse web patch manifest.");
            _patcher.ParseWebPatchManifest(download.GetData());
            download.Dispose();
            _patcher.SwitchNext();
        }
        private IEnumerator Download()
        {
            // 注意:等所有文件下载完毕后,下载并替换补丁清单
            int            newResourceVersion = _patcher.RequestedResourceVersion;
            string         url      = _patcher.GetWebDownloadURL(newResourceVersion.ToString(), PatchDefine.PatchManifestFileName);
            string         savePath = AssetPathHelper.MakePersistentLoadPath(PatchDefine.PatchManifestFileName);
            WebFileRequest download = new WebFileRequest(url, savePath);

            yield return(download.DownLoad());

            if (download.States != EWebRequestStates.Success)
            {
                download.Dispose();
                PatchEventDispatcher.SendWebPatchManifestDownloadFailedMsg();
                yield break;
            }
            else
            {
                PatchHelper.Log(ELogLevel.Log, "Web patch manifest is download.");
                download.Dispose();
                _patcher.SwitchNext();
            }
        }
Example #10
0
        private IEnumerator Download()
        {
            // 从远端下载最新的补丁清单
            int           newResourceVersion = _patcher.RequestedResourceVersion;
            string        url      = _patcher.GetWebDownloadURL(newResourceVersion.ToString(), PatchDefine.PatchManifestFileName);
            WebGetRequest download = new WebGetRequest(url);

            download.DownLoad();
            yield return(download);

            // Check fatal
            if (download.HasError())
            {
                download.ReportError();
                download.Dispose();
                PatchEventDispatcher.SendWebPatchManifestDownloadFailedMsg();
                yield break;
            }

            // 解析远端下载的补丁清单
            _patcher.ParseRemotePatchManifest(download.GetText());
            download.Dispose();
            _patcher.SwitchNext();
        }
        private IEnumerator Download()
        {
            // 注意:开发者需要在下载前检测磁盘空间不足

            // 计算下载文件的总大小
            int  totalDownloadCount     = _patcher.DownloadList.Count;
            long totalDownloadSizeBytes = 0;

            foreach (var element in _patcher.DownloadList)
            {
                totalDownloadSizeBytes += element.SizeBytes;
            }

            // 开始下载列表里的所有资源
            PatchHelper.Log(ELogLevel.Log, $"Begine download web files : {_patcher.DownloadList.Count}");
            long currentDownloadSizeBytes = 0;
            int  currentDownloadCount     = 0;

            foreach (var element in _patcher.DownloadList)
            {
                // 注意:资源版本号只用于确定下载路径
                string url      = _patcher.GetWebDownloadURL(element.Version.ToString(), element.Name);
                string savePath = AssetPathHelper.MakePersistentLoadPath(element.Name);
                element.SavePath = savePath;
                FileUtility.CreateFileDirectory(savePath);

                // 创建下载器
                WebFileRequest download = new WebFileRequest(url, savePath);
                yield return(download.DownLoad());                //文件依次加载(在一个文件加载完毕后加载下一个)

                PatchHelper.Log(ELogLevel.Log, $"Web file is download : {savePath}");

                // 检测是否下载失败
                if (download.States != EWebRequestStates.Success)
                {
                    PatchEventDispatcher.SendWebFileDownloadFailedMsg(url, element.Name);
                    yield break;
                }

                // 立即释放加载器
                download.Dispose();
                currentDownloadCount++;
                currentDownloadSizeBytes += element.SizeBytes;
                PatchEventDispatcher.SendDownloadFilesProgressMsg(totalDownloadCount, currentDownloadCount, totalDownloadSizeBytes, currentDownloadSizeBytes);
            }

            // 验证下载文件的大小
            if (_patcher.CheckLevel == ECheckLevel.CheckSize)
            {
                foreach (var element in _patcher.DownloadList)
                {
                    long fileSize = FileUtility.GetFileSize(element.SavePath);
                    if (fileSize != element.SizeBytes)
                    {
                        PatchHelper.Log(ELogLevel.Error, $"Web file size check failed : {element.Name}");
                        PatchEventDispatcher.SendWebFileCheckFailedMsg(element.Name);
                        yield break;
                    }
                }
            }

            // 验证下载文件的MD5
            if (_patcher.CheckLevel == ECheckLevel.CheckMD5)
            {
                foreach (var element in _patcher.DownloadList)
                {
                    string md5 = HashUtility.FileMD5(element.SavePath);
                    if (md5 != element.MD5)
                    {
                        PatchHelper.Log(ELogLevel.Error, $"Web file md5 check failed : {element.Name}");
                        PatchEventDispatcher.SendWebFileCheckFailedMsg(element.Name);
                        yield break;
                    }
                }
            }

            // 最后清空下载列表
            _patcher.DownloadList.Clear();
            _patcher.SwitchNext();
        }
 void IFsmNode.OnUpdate()
 {
     _patcher.SwitchNext();
 }
        private IEnumerator Download()
        {
            // 如果忽略资源版本,那么每次启动都会下载补丁清单
            bool ignoreResourceVersion = _patcher.IgnoreResourceVersion;

            // 新安装的用户首次启动游戏(包括覆盖安装的用户)
            // 注意:请求的补丁清单会在下载流程结束的时候,自动保存在沙盒里。
            bool firstStartGame = PatchHelper.CheckSandboxPatchManifestFileExist() == false;

            // 检测资源版本是否变化
            int newResourceVersion = _patcher.RequestedResourceVersion;
            int oldResourceVersion = _patcher.LocalResourceVersion;

            if (ignoreResourceVersion == false && firstStartGame == false && newResourceVersion == oldResourceVersion)
            {
                MotionLog.Log($"Resource version is not change.");
                _patcher.Switch(EPatchStates.PatchDone);
            }
            else
            {
                // 从远端请求补丁清单
                _requestCount++;
                string        url      = GetRequestURL(ignoreResourceVersion, newResourceVersion, PatchDefine.PatchManifestFileName);
                WebGetRequest download = new WebGetRequest(url);
                download.SendRequest();
                yield return(download);

                // Check fatal
                if (download.HasError())
                {
                    download.ReportError();
                    download.Dispose();
                    PatchEventDispatcher.SendPatchManifestRequestFailedMsg();
                    yield break;
                }

                // 解析补丁清单
                _patcher.ParseRemotePatchManifest(download.GetText());
                download.Dispose();

                // 如果发现了新的安装包
                if (_patcher.FoundNewApp)
                {
                    string requestedGameVersion = _patcher.RequestedGameVersion.ToString();
                    MotionLog.Log($"Found new APP can be install : {requestedGameVersion}");
                    PatchEventDispatcher.SendFoundNewAppMsg(_patcher.ForceInstall, _patcher.AppURL, requestedGameVersion);
                }
                else
                {
                    if (firstStartGame)
                    {
                        MotionLog.Log("First start game.");
                    }
                    if (newResourceVersion != oldResourceVersion)
                    {
                        MotionLog.Log($"Resource version is change : {oldResourceVersion} -> {newResourceVersion}");
                    }
                    _patcher.SwitchNext();
                }
            }
        }
Example #14
0
 void IFsmNode.OnEnter()
 {
     PatchEventDispatcher.SendPatchStepsChangeMsg(EPatchStates.DownloadOver);
     _patcher.SaveRemotePatchManifest();
     _patcher.SwitchNext();
 }
        private void GetDownloadList()
        {
            _patcher.DownloadList.Clear();

            // 临时下载列表
            List <PatchElement> downloadList = new List <PatchElement>(1000);

            // 准备下载列表
            foreach (var pair in _patcher.WebPatchManifest.Elements)
            {
                PatchElement element = pair.Value;

                // 先检测APP里的清单
                PatchElement appElement;
                if (_patcher.AppPatchManifest.Elements.TryGetValue(element.Name, out appElement))
                {
                    if (appElement.MD5 == element.MD5)
                    {
                        continue;
                    }
                }

                // 再检测沙盒里的清单
                PatchElement sandboxElement;
                if (_patcher.SandboxPatchManifest.Elements.TryGetValue(element.Name, out sandboxElement))
                {
                    if (sandboxElement.MD5 != element.MD5)
                    {
                        downloadList.Add(element);
                    }
                }
                else
                {
                    downloadList.Add(element);
                }
            }

            // 检测已经存在的文件
            // 注意:如果玩家在加载过程中强制退出,下次再进入的时候跳过已经加载的文件
            List <string> removeList = new List <string>();

            foreach (var element in downloadList)
            {
                string filePath = AssetPathHelper.MakePersistentLoadPath(element.Name);
                if (System.IO.File.Exists(filePath))
                {
                    string md5 = HashUtility.FileMD5(filePath);
                    if (md5 == element.MD5)
                    {
                        removeList.Add(element.Name);
                    }
                }
            }
            foreach (var name in removeList)
            {
                for (int i = 0; i < downloadList.Count; i++)
                {
                    if (downloadList[i].Name == name)
                    {
                        downloadList.RemoveAt(i);
                        break;
                    }
                }
            }

            // 如果下载列表为空
            if (downloadList.Count == 0)
            {
                _patcher.SwitchNext();
            }
            else
            {
                // 最后添加到正式下载列表里
                _patcher.DownloadList.AddRange(downloadList);
                downloadList.Clear();

                // 发现新更新文件后,挂起流程系统
                int  totalDownloadCount  = _patcher.DownloadList.Count;
                long totalDownloadSizeKB = 0;
                foreach (var element in _patcher.DownloadList)
                {
                    totalDownloadSizeKB += element.SizeKB;
                }
                PatchEventDispatcher.SendFoundUpdateFilesMsg(totalDownloadCount, totalDownloadSizeKB);
            }
        }