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();
        }
Esempio n. 2
0
    public IEnumerator Download()
    {
        // 请求游戏版本
        string webURL      = GameLauncher.GetWebServerURL();
        string postContent = GetWebPostContent();

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

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

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

        string responseContent = download.GetResponse();

        download.Dispose();

        // 解析游戏版本信息
        try
        {
            GameLog.Log($"Response content : {responseContent}");
            WebResponse response        = JsonUtility.FromJson <WebResponse>(responseContent);
            Version     gameVersion     = new Version(response.GameVersion);
            int         resourceVersion = response.ResourceVersion;
            bool        foundNewApp     = response.FoundNewApp;
            bool        forceInstall    = response.ForceInstall;
            string      appURL          = response.AppURL;

            PatchUpdater.Instance.GameVersion     = gameVersion;
            PatchUpdater.Instance.ResourceVersion = resourceVersion;

            if (foundNewApp)
            {
                PatchEventDispatcher.SendFoundNewAppMsg(forceInstall, appURL, gameVersion.ToString());
            }
            else
            {
                PatchUpdater.Instance.SwitchNext();
            }
        }
        catch (Exception)
        {
            Debug.LogError($"Parse web response failed : {responseContent}");
            PatchEventDispatcher.SendGameVersionParseFailedMsg();
        }
    }
        public IEnumerator Download(ProcedureSystem system)
        {
            // 如果跳过CDN服务器
            if (PatchManager.Instance.SkipCDN)
            {
                PatchManager.Log(ELogType.Warning, $"Skip CDN server !");
                system.Switch((int)EPatchStates.PatchOver);
                yield break;
            }

            // 获取最新的游戏版本号
            {
                string url = $"{PatchManager.Instance.StrWebServerIP}/GameVersion.php";
                PatchManager.Log(ELogType.Log, $"Request game version : {url}");
                WebPostRequest download = new WebPostRequest(url);
                download.PostContent = PatchManager.Instance.AppVersion.ToString();
                yield return(download.DownLoad());

                //Check fatal
                if (download.States != EWebRequestStates.Succeed)
                {
                    download.Dispose();
                    system.Switch((int)EPatchStates.PatchError);
                    yield break;
                }

                string version = download.GetResponse();
                PatchManager.Instance.InitGameVesion(version);
                download.Dispose();
            }

            int newResourceVersion = PatchManager.Instance.GameVersion.Revision;
            int oldResourceVersion = PatchManager.Instance.SandboxPatchFile.Version;

            // 检测是否需要重新下载安装包
            if (PatchManager.Instance.GameVersion.Major != PatchManager.Instance.AppVersion.Major || PatchManager.Instance.GameVersion.Minor != PatchManager.Instance.AppVersion.Minor)
            {
                PatchManager.Log(ELogType.Log, $"Found new APP can be install : {PatchManager.Instance.GameVersion.ToString()}");
                PatchManager.SendFoundNewAPPMsg(PatchManager.Instance.GameVersion.ToString());
                yield break;
            }

            // 检测是否需要下载热更文件
            if (newResourceVersion == oldResourceVersion)
            {
                PatchManager.Log(ELogType.Log, $"Not found file to download.");
                system.Switch((int)EPatchStates.PatchOver);
            }
            else
            {
                PatchManager.Log(ELogType.Log, $"Found new file to download : {newResourceVersion.ToString()}");
                system.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();
            }
        }