예제 #1
0
 public void CheckVersion(DelegateCheckResVersion checkVersionDelFun, bool updateGate = false)
 {
     ResourceManager.Instance.StartCoroutine(CheckResourceVersion(checkVersionDelFun, updateGate));
 }
예제 #2
0
    // 检查版本号,不参与资源更新,不使用成员变量
    public static IEnumerator CheckResVersion(DelegateCheckResVersion delFun, MonoBehaviour parent)
    {
        int    localVersion         = -1;
        int    appVersion           = -1;
        int    remoteVersion        = -1;
        string localVersionFilePath = LocalVersionPath + "/" + VersionFileName;
        string AppVersionFilePath   = GetAppDataUrl(AppVersionFolder, VersionFileName);

        // 读取本地版本号文件
        if (File.Exists(localVersionFilePath))
        {
            LogModule.DebugLog("read local version:" + localVersionFilePath.ToString());
            if (!Utils.GetFileInt(localVersionFilePath, out localVersion))
            {
                LogModule.ErrorLog("parse version error");
            }
        }

        // 读取包体
        WWW wwwAppVersionFile = new WWW(AppVersionFilePath);

        yield return(wwwAppVersionFile);

        if (!string.IsNullOrEmpty(wwwAppVersionFile.error))
        {
            LogModule.DebugLog("read app version:" + AppVersionFilePath.ToString() + " error:" + wwwAppVersionFile.error);
        }
        else
        {
            if (!int.TryParse(wwwAppVersionFile.text, out appVersion))
            {
                LogModule.ErrorLog("parse app path version error");
            }
        }

        if (appVersion > localVersion)
        {
            localVersion = appVersion;
        }

        // 读取远程版本号文件
        LogModule.DebugLog("ger version form " + m_resServerUrl + "/" + VersionFileName);

        // 获取远程版本号,重试3次
        int retryTime      = 3;
        WWW wwwVersionFile = null;

        while (retryTime > 0)
        {
            wwwVersionFile = null;
            yield return(parent.StartCoroutine(DownloadHelper.GetCDNWWW(m_resServerUrl + "/" + VersionFileName, value => wwwVersionFile = value)));

            if (!string.IsNullOrEmpty(wwwVersionFile.error))
            {
                LogModule.ErrorLog(wwwVersionFile.error);
            }
            else
            {
                break;
            }
            retryTime--;
        }

        if (retryTime > 0 && null != wwwVersionFile)
        {
            // 获取成功
            if (!int.TryParse(wwwVersionFile.text, out remoteVersion))
            {
                // 解析失败
                delFun(CheckVersionResult.ERROR);
            }
            else
            {
                if (remoteVersion > localVersion)
                {
                    delFun(CheckVersionResult.NEEDUPDATE);
                }
                else
                {
                    delFun(CheckVersionResult.NONEEDUPDATE);
                }
            }
        }
    }
예제 #3
0
    //检查游戏和资源版本号
    private IEnumerator CheckResourceVersion(DelegateCheckResVersion checkVersionDelFun, bool updateGate)
    {
        UpdateStatus = GetDictionaryText(3300000);
        string versionConfig;
        var    gameVersionPath = Path.Combine(Application.streamingAssetsPath, "Game.ver");

        if (!GameUtils.GetStringFromPackage(gameVersionPath, out versionConfig))
        {
            Logger.Error("cant find Game.ver at{0}", gameVersionPath);
            if (null != checkVersionDelFun)
            {
                checkVersionDelFun(CheckVersionResult.ERROR, GetDictionaryText(3300008));
            }
            yield break;
        }

        var config          = versionConfig.Split(',');
        var langue          = config[0];
        var platform        = config[1];
        var channel         = config[2];
        var bigVersion      = config[3];
        var resourceVersion = config[4];

        if (string.IsNullOrEmpty(langue) || string.IsNullOrEmpty(platform) || string.IsNullOrEmpty(channel) ||
            string.IsNullOrEmpty(bigVersion) || string.IsNullOrEmpty(bigVersion))
        {
            Logger.Error("Game.ver error {0}", versionConfig);
        }

        Channel = channel;

        LocalGameVersion = bigVersion;

        Platform = platform;

        if (!Int32.TryParse(resourceVersion, out LocalVersion))
        {
            Logger.Error("Game.ver error {0}", LocalVersion);
            if (null != checkVersionDelFun)
            {
                checkVersionDelFun(CheckVersionResult.ERROR, GetDictionaryText(3300009));
            }
            yield break;
        }

        UpdateStatus = GetDictionaryText(3300001);
        //获取远端游戏版本信息
        var UpdateHelper = new GameObject("UpdateHelper");
        var network      = UpdateHelper.AddComponent <DirectoryNetwork>();
        CheckVersion3OutMessage msg;

        var index = 0;

        while (true)
        {
            if (index == GameSetting.Instance.DirectoryAddress.Count)
            {
                network.Stop();
                Object.Destroy(UpdateHelper);
                if (null != checkVersionDelFun)
                {
                    checkVersionDelFun(CheckVersionResult.ERROR, GetDictionaryText(3300010));
                }
                yield break;
            }

            network.ServerAddress = GameSetting.Instance.DirectoryAddress[index];
            yield return(network.StartAndWaitConnect(TimeSpan.FromSeconds(3)));

            if (network.Connected)
            {
                Logger.Debug("Connect to Directory [" + network.ServerAddress + "] succeed!");

                msg = network.CheckVersion3(langue, platform, channel, bigVersion);
                yield return(msg.SendAndWaitUntilDone());

                if (msg.State == MessageState.Reply)
                {
                    break;
                }
            }
            network.Stop();
            index++;
        }

        UpdateStatus = GetDictionaryText(3300002);

        if (msg.ErrorCode == (int)ErrorCodes.OK)
        {
            if (msg.Response.HasNewVersion == 1)
            {
                var url = CheckUrl(msg.Response.NewVersionURL);
                if (null != checkVersionDelFun)
                {
                    checkVersionDelFun(CheckVersionResult.GAMENEEDUPDATE, url);
                }
                network.Stop();
                Object.DestroyImmediate(UpdateHelper);
                yield break;
            }
            LocalGameVersion = bigVersion;
            RemoteVersion    = msg.Response.SmallVersion;
            RemoteUrlRoot    = msg.Response.ResourceURL;
            AnnoucementURL   = CheckUrl(msg.Response.AnnoucementURL);
            if (updateGate && GateAddress != msg.Response.GateAddress)
            {
                yield return(NetManager.Instance.ChooseGateAddr(msg.Response.GateAddress, TimeSpan.FromSeconds(3)));

                GateAddress = NetManager.Instance.ChooseGateAddress;
            }
            GameSetting.Instance.ReviewState  = msg.Response.ReviewState;
            GameSetting.Instance.ForceShowAnn = msg.Response.ForceShowAnn;
            var isbns = Regex.Split(msg.Response.Isbn, "@_@");
            GameSetting.Instance.Isbn1 = isbns[0];
            GameSetting.Instance.Isbn2 = isbns.Length > 1 ? isbns[1] : string.Empty;

            //如果需要预先显示公告,先预加载网页
            if (GameSetting.Instance.ForceShowAnn == 1)
            {
                PlatformHelper.UpdateUrl(AnnoucementURL);
            }

            //数据收集,设备id,只发送一次
            const string key  = "deviceid";
            var          udid = PlayerPrefs.GetString(key);
            if (string.IsNullOrEmpty(udid))
            {
                udid = Guid.NewGuid().ToString();
                NetManager.Instance.ServerAddress = GateAddress;
                yield return(NetManager.Instance.StartAndWaitConnect(TimeSpan.FromSeconds(3)));

                if (NetManager.Instance.Connected)
                {
                    var msgUdid = NetManager.Instance.SendDeviceUdid(udid);
                    yield return(msgUdid.SendAndWaitUntilDone());

                    PlayerPrefs.SetString(key, udid);
                    PlayerPrefs.Save();
                    NetManager.Instance.Stop();
                }
            }

            //获取到公告url之后第一时间后台加载
            //不能预加载了,因为只有登录过后才能获取37的pid才能正确显示公告地址
            //  PlatformHelper.UpdateUrl(AnnoucementURL);
        }
        else
        {
            network.Stop();
            Object.Destroy(UpdateHelper);
            if (null != checkVersionDelFun)
            {
                checkVersionDelFun(CheckVersionResult.ERROR, GetDictionaryText(3300011) + msg.ErrorCode);
            }
            yield break;
        }


        network.Stop();
        Object.DestroyImmediate(UpdateHelper);

        ClearLastGameVersionResource();

        //读取之前更新过的版本号
        if (File.Exists(DownLoadVersionPath))
        {
            if (!GameUtils.GetIntFromFile(DownLoadVersionPath, out LocalVersion))
            {
                Logger.Error("parse version error");
                if (null != checkVersionDelFun)
                {
                    checkVersionDelFun(CheckVersionResult.ERROR, GetDictionaryText(3300013));
                }
            }
            Logger.Debug("Last Update ResourceVersion from local =" + LocalVersion);
        }

        if (RemoteVersion > LocalVersion)
        {
            UpdateStatus = GetDictionaryText(3300003);
            checkVersionDelFun(CheckVersionResult.NEEDUPDATE);
            Logger.Debug("-----CheckUpDate needupdate = true--");
        }
        else
        {
            UpdateStatus = "";
            checkVersionDelFun(CheckVersionResult.NONEEDUPDATE);
            Logger.Debug("-----CheckUpdate needupdate = false---");
        }
    }