| | |
| | |
|
| | | public string androidRoot { get { return StringUtility.Contact(SDKUtility.Instance.DeviceRootPath, "/", VersionConfig.Get().bundleIdentifier); } }
|
| | |
|
| | | public float progress
|
| | | {
|
| | | public float progress {
|
| | | get { return RemoteFile.TotalDownloadedSize / ((float)versionInfo.GetLatestVersion().file_size * 1024); }
|
| | | }
|
| | |
|
| | | public string apkLocalURL = string.Empty;
|
| | | public VersionInfo versionInfo { get; private set; }
|
| | | public MaoErVersion maoerVersion;
|
| | | public bool completed { get { return step == Step.Completed; } }
|
| | |
|
| | | Step m_Step = Step.None;
|
| | | public Step step
|
| | | {
|
| | | public Step step {
|
| | | get { return m_Step; }
|
| | | private set
|
| | | {
|
| | | private set {
|
| | | if (m_Step != value)
|
| | | {
|
| | | m_Step = value;
|
| | |
| | | if (_ok)
|
| | | {
|
| | | versionInfo = JsonMapper.ToObject<VersionInfo>(_result);
|
| | | if (versionInfo.VersionCount > 0)
|
| | | if (NeedUpdate())
|
| | | {
|
| | | var version = versionInfo.GetLatestVersion();
|
| | | var remoteURL = version.download_url;
|
| | |
|
| | | switch (Application.platform)
|
| | | {
|
| | | case RuntimePlatform.Android:
|
| | | var fileName = Path.GetFileName(remoteURL);
|
| | | apkLocalURL = StringUtility.Contact(androidRoot, "/", fileName);
|
| | | if (File.Exists(apkLocalURL))
|
| | | if (File.Exists(GetApkLocalUrl()))
|
| | | {
|
| | | step = Step.ApkExist;
|
| | | WindowCenter.Instance.OpenFromLocal<VersionUpdateWin>();
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | public bool NeedUpdate()
|
| | | {
|
| | | if (IsMaoErGame())
|
| | | {
|
| | | return versionInfo.downAsset == 0 && versionInfo.VersionCount > 0;
|
| | | }
|
| | | else
|
| | | {
|
| | | return versionInfo.downAsset == 1 && versionInfo.VersionCount > 0;
|
| | | }
|
| | | }
|
| | |
|
| | | public string GetApkLocalUrl()
|
| | | {
|
| | | if (IsMaoErGame())
|
| | | {
|
| | | return StringUtility.Contact(androidRoot, "/", "maoErGame.apk");
|
| | | }
|
| | | else
|
| | | {
|
| | | var remoteURL = GetApkRemoteUrl();
|
| | | var fileName = Path.GetFileName(remoteURL);
|
| | | return StringUtility.Contact(androidRoot, "/", fileName);
|
| | | }
|
| | | }
|
| | |
|
| | | public string GetApkRemoteUrl()
|
| | | {
|
| | | if (IsMaoErGame())
|
| | | {
|
| | | return maoerVersion.url;
|
| | | }
|
| | | else
|
| | | {
|
| | | var version = versionInfo.GetLatestVersion();
|
| | | return version.download_url;
|
| | | }
|
| | | }
|
| | |
|
| | | public string GetUpdateContent()
|
| | | {
|
| | | if (IsMaoErGame())
|
| | | {
|
| | | if (string.IsNullOrEmpty(maoerVersion.content))
|
| | | {
|
| | | return string.Empty;
|
| | | }
|
| | | else
|
| | | {
|
| | | return StringUtility.Contact(Language.GetFromLocal(30), "\r\n", maoerVersion.content);
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | return string.Empty;
|
| | | }
|
| | | }
|
| | |
|
| | | public void StartDownLoad()
|
| | | {
|
| | | step = Step.DownLoad;
|
| | | var version = versionInfo.GetLatestVersion();
|
| | | var remoteURL = version.download_url;
|
| | | var fileName = Path.GetFileName(remoteURL);
|
| | | apkLocalURL = StringUtility.Contact(androidRoot, "/", fileName);
|
| | | var remoteURL = GetApkRemoteUrl();
|
| | | var apkLocalUrl = GetApkLocalUrl();
|
| | |
|
| | | RemoteFile.Prepare();
|
| | |
|
| | | var remoteFile = new RemoteFile();
|
| | | remoteFile.Init(remoteURL, apkLocalURL, null);
|
| | | remoteFile.Init(remoteURL, apkLocalUrl, null);
|
| | | remoteFile.Begin(OnDownLoadApkCompleted);
|
| | | }
|
| | |
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | SDKUtility.Instance.InstallAPK(apkLocalURL);
|
| | | SDKUtility.Instance.InstallAPK(GetApkLocalUrl());
|
| | | }
|
| | | else
|
| | | {
|
| | |
| | | step = Step.Completed;
|
| | | }
|
| | |
|
| | | const string maoerGameAppId = "mrgame";
|
| | | static List<string> maoerGameAppId = new List<string> { "mrgame", "mrgameios" };
|
| | | public bool IsMaoErGame()
|
| | | {
|
| | | return VersionConfig.Get().appId == maoerGameAppId;
|
| | | return maoerGameAppId.Contains(VersionConfig.Get().appId);
|
| | | }
|
| | |
|
| | | public void RequestMaoErVersionCheck()
|
| | | {
|
| | | if (IsMaoErGame() && versionInfo.VersionCount > 0)
|
| | | {
|
| | | step = Step.None;
|
| | | var tables = new Dictionary<string, string>();
|
| | | tables["uid"] = ModelCenter.Instance.GetModel<LoginModel>().sdkLoginResult.account;
|
| | | var url = StringUtility.Contact("https://api.maoergame.com/update/download/url?", HttpRequest.HashtablaToString(tables));
|
| | | Debug.Log("猫耳强更url:" + url);
|
| | | HttpRequest.Instance.RequestHttpPost(url, string.Empty, HttpRequest.defaultHttpContentType, 1, OnMaoErVersionCheckResult);
|
| | | }
|
| | | }
|
| | |
|
| | | private void OnMaoErVersionCheckResult(bool ok, string result)
|
| | | {
|
| | | Debug.Log("猫耳强更 result:" + result);
|
| | | if (ok)
|
| | | {
|
| | | try
|
| | | {
|
| | | maoerVersion = JsonMapper.ToObject<MaoErVersion>(result);
|
| | | if (maoerVersion.code == 0)
|
| | | {
|
| | | step = Step.DownLoadPrepared;
|
| | | WindowCenter.Instance.OpenFromLocal<VersionUpdateWin>();
|
| | | }
|
| | | else
|
| | | {
|
| | | step = Step.None;
|
| | | Clock.Create(DateTime.Now + new TimeSpan(TimeSpan.TicksPerSecond), RequestMaoErVersionCheck);
|
| | | }
|
| | | }
|
| | | catch (System.Exception ex)
|
| | | {
|
| | | step = Step.None;
|
| | | Clock.Create(DateTime.Now + new TimeSpan(TimeSpan.TicksPerSecond), RequestMaoErVersionCheck);
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | step = Step.None;
|
| | | Clock.Create(DateTime.Now + new TimeSpan(TimeSpan.TicksPerSecond), RequestMaoErVersionCheck);
|
| | | }
|
| | | }
|
| | |
|
| | | public class VersionInfo
|
| | |
| | | public JsonData resource_url;
|
| | | public JsonData notice_flag;
|
| | | public Version[] versions;
|
| | | public int downAsset =1;
|
| | | public int downAsset = 1;
|
| | |
|
| | | public Version GetLatestVersion()
|
| | | {
|
| | |
| | | public string version_name;
|
| | | }
|
| | |
|
| | | public struct MaoErVersion
|
| | | {
|
| | | public string msg;
|
| | | public int code;
|
| | | public string content;
|
| | | public string url;
|
| | | }
|
| | |
|
| | | public enum Step
|
| | | {
|
| | | None,
|