Example #1
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();
        }
    }