Пример #1
0
	public static IEnumerable ChooseWhetherUpdate(String title, String content, ReturnTuple<Boolean> result)
	{
		String prefabName = "ui/prefab/panel_updatechoose";
		GameObject dialog = ECUpdateUIManagerInstance.Value.CreateDialog(prefabName);
		UpdateMsgBoxSleepControl.AddSleepControl(dialog.gameObject, 30, (Int32)SleepTimeoutManager.Priority.MessageBox);

		var Group_UpdateTypeChoose = dialog.FindChild("Widget", "Group_UpdateTypeChoose");
		Group_UpdateTypeChoose.SetActive(false);

		var Group_UpdateChoose = dialog.FindChild("Widget", "Group_UpdateChoose");
		Group_UpdateChoose.SetActive(true);
		Group_UpdateChoose.FindChild("Scroll View", "Txt_UpdateMessageTitle").GetComponent<UILabel>().text = title;
		Group_UpdateChoose.FindChild("Scroll View", "Txt_UpdateMessage").GetComponent<UILabel>().text = content;

		Boolean hasChoose = false;
		result.value_0 = false;

		EventDelegate.Add(Group_UpdateChoose.FindChild("Btn_Yes").GetComponent<UIButton>().onClick, ()=>
		{
			hasChoose = true;
			result.value_0 = true;
		});
		EventDelegate.Add(Group_UpdateChoose.FindChild("Btn_No").GetComponent<UIButton>().onClick, ()=>
		{
			hasChoose = true;
			result.value_0 = false;
		});

		while (!hasChoose)
			yield return null;

		ECUpdateUIManagerInstance.Value.DestroyDialog(dialog);
		yield break;
	}
Пример #2
0
	public static IEnumerable ChooseYYBUpdateStyle(ReturnTuple<YYBUpdateStyle> result)
	{
		String prefabName = "ui/prefab/panel_updatechoose";
		GameObject dialog = ECUpdateUIManagerInstance.Value.CreateDialog(prefabName);
		UpdateMsgBoxSleepControl.AddSleepControl(dialog.gameObject, 30, (Int32)SleepTimeoutManager.Priority.MessageBox);

		var Group_UpdateChoose = dialog.FindChild("Widget", "Group_UpdateChoose");
		Group_UpdateChoose.SetActive(false);

		var Group_UpdateTypeChoose = dialog.FindChild("Widget", "Group_UpdateTypeChoose");
		Group_UpdateTypeChoose.SetActive(true);

		Boolean hasChoose = false;
		result.value_0 = YYBUpdateStyle.None;

		EventDelegate.Add(Group_UpdateTypeChoose.FindChild("Btn_Type01").GetComponent<UIButton>().onClick, ()=>
		{
			hasChoose = true;
			result.value_0 = YYBUpdateStyle.InGame;
		});
		EventDelegate.Add(Group_UpdateTypeChoose.FindChild("Btn_Type02").GetComponent<UIButton>().onClick, ()=>
		{
			hasChoose = true;
			result.value_0 = YYBUpdateStyle.PopYYB;
		});

		while (!hasChoose)
			yield return null;

		ECUpdateUIManagerInstance.Value.DestroyDialog(dialog);
		yield break;
	}
Пример #3
0
	public static IEnumerable Pop(String message, MessageBoxType type, ReturnTuple<MessageBoxResult> result)
	{
		if (result != null)
			result.value_0 = MessageBoxResult.None;
		UIPanelUpdateMessageBox dialog = Show(message, type, (ret)=>{ if (result != null) result.value_0=ret; });
		GameObject gameObject = dialog.gameObject;
		while (gameObject && gameObject.activeSelf)
		{
			yield return null;
		}
	}
Пример #4
0
	private IEnumerable PopYYBCoroutineInner(ProgramUpdate.VersionParam versionParam, UIPanelUpdate updatePanel, ReturnTuple<ProgramUpdate.ProgramsUpdateRetcode> result)
	{
		result.value_0 = ProgramUpdate.ProgramsUpdateRetcode.NotSuccess;

		StartSaveUpdate();

		foreach (var item in ShowProgressCoroutine(versionParam, updatePanel, result))
			yield return item;
	}
Пример #5
0
	public static IEnumerable PopYYBCoroutine(ProgramUpdate.VersionParam versionParam, UIPanelUpdate updatePanel, ReturnTuple<ProgramUpdate.ProgramsUpdateRetcode> result)
	{
		Debug.Log("PopYYBCoroutine");

		var self = Instance;
		foreach (var item in self.PopYYBCoroutineInner(versionParam, updatePanel, result))
			yield return item;
		self.CleanupCallbacks();

	}
Пример #6
0
	private IEnumerable ShowProgressCoroutine(ProgramUpdate.VersionParam versionParam, UIPanelUpdate updatePanel, ReturnTuple<ProgramUpdate.ProgramsUpdateRetcode> result)
	{
		updatePanel.sub_statusText.text = GameUpdateManager.Instance.GetString("preparing to update");

		//显示下载进度
		Boolean bFailed = false;
		String failMsg = "";

		m_OnDownloadAppStateChangedEvent = (state, errorCode, errorMsg) =>
		{
			if (state == (Int32)TMAssistantDownloadSDKTaskState.DownloadSDKTaskState_FAILED)
			{
				Debug.LogWarning(String.Format("DownloadApp failed, state={0}, errorCode={1}, errorMsg={2}", state, errorCode, errorMsg));
				CleanupCallbacks();

				failMsg = String.Format(GameUpdateManager.Instance.GetString("download error: {0}"), errorMsg);
				bFailed = true;
			}
			else if (state == (Int32)TMAssistantDownloadSDKTaskState.DownloadSDKTaskState_SUCCEED)
			{
				updatePanel.sub_statusText.text = GameUpdateManager.Instance.GetString("waiting for finish install");
				updatePanel.sub_progress.value = 1.0f;
				updatePanel.sub_progressText.text = "";
			}
		};

		m_OnDownloadAppProgressChangedEvent = (receiveDataLen, totalDataLen) =>
		{
			updatePanel.sub_statusText.text = GameUpdateManager.Instance.GetString("downloading installer");
			updatePanel.sub_progress.value = (float)receiveDataLen / Math.Max((float)totalDataLen, 1.0f);
			updatePanel.sub_progressText.text = FormatProgressSize(receiveDataLen, totalDataLen);
		};

		m_OnDownloadYYBStateChangedEvent = (url, state, errorCode, errorMsg) =>
		{
			if (state == (Int32)TMAssistantDownloadSDKTaskState.DownloadSDKTaskState_FAILED)
			{
				Debug.LogWarning(String.Format("DownloadYYB failed, state={0}, errorCode={1}, errorMsg={2}", state, errorCode, errorMsg));
				CleanupCallbacks();

				failMsg = String.Format(GameUpdateManager.Instance.GetString("download error: {0}"), errorMsg);
				bFailed = true;
			}
			else if (state == (Int32)TMAssistantDownloadSDKTaskState.DownloadSDKTaskState_SUCCEED)
			{
				updatePanel.sub_statusText.text = GameUpdateManager.Instance.GetString("waiting for finish install");
				updatePanel.sub_progress.value = 1.0f;
				updatePanel.sub_progressText.text = "";
			}
		};

		m_OnDownloadYYBProgressChangedEvent = (url, receiveDataLen, totalDataLen) =>
		{
			updatePanel.sub_statusText.text = GameUpdateManager.Instance.GetString("downloading yyb");
			updatePanel.sub_progress.value = (float)receiveDataLen / Math.Max((float)totalDataLen, 1.0f);
			updatePanel.sub_progressText.text = FormatProgressSize(receiveDataLen, totalDataLen);
		};

		while (!bFailed)
			yield return null;

		foreach (var item in UpdateMessageBox.Pop(String.IsNullOrEmpty(failMsg) ? GameUpdateManager.Instance.GetString("update failed") : failMsg, UpdateMessageBox.MessageBoxType.None))
			yield return item;

		yield return new WaitForSeconds(Single.MaxValue);
	}
Пример #7
0
	private IEnumerable UpdateCoroutineInner(ProgramUpdate.VersionParam versionParam, UIPanelUpdate updatePanel, ReturnTuple<ProgramUpdate.ProgramsUpdateRetcode> result)
	{
		result.value_0 = ProgramUpdate.ProgramsUpdateRetcode.NotSuccess;

		//load string table
		var stringTable = GameUpdateManager.Instance.StringTable;

		//check runtime platform ? Not quite needed

		var checkNeedUpdateResult = new ReturnTuple<Boolean, Int64, String, Int64, Int32, String, Int32>();
		foreach (var item in CheckNeedUpdateCoroutine(10.0f, checkNeedUpdateResult))
			yield return item;

		if (!checkNeedUpdateResult.value_0)
		{
			Debug.LogWarning("CheckNeedUpdate timeout");
			foreach (var item in UpdateMessageBox.Pop(GameUpdateManager.Instance.GetString("update failed"), UpdateMessageBox.MessageBoxType.None))
				yield return item;
			yield return new WaitForSeconds(Single.MaxValue);
		}

		Debug.Log("CheckNeedUpdate success");


		//Boolean hasPatch = false;

		var updateMethod = checkNeedUpdateResult.value_6;
		if (updateMethod == (Int32)TMSelfUpdateSDKUpdateInfo.UpdateMethod_NoUpdate)
		{
			//判断有更新,但应用宝无更新可下载
			Debug.LogWarning("No Update Available");
			foreach (var item in UpdateMessageBox.Pop(GameUpdateManager.Instance.GetString("no update available"), UpdateMessageBox.MessageBoxType.None))
				yield return item;
			yield return new WaitForSeconds(Single.MaxValue);
		}
		//else if (updateMethod == (Int32)TMSelfUpdateSDKUpdateInfo.UpdateMethod_Normal)
		//{
		//    hasPatch = false;
		//}
		//else if (updateMethod == (Int32)TMSelfUpdateSDKUpdateInfo.UpdateMethod_ByPatch)
		//{
		//    hasPatch = true;
		//}
		//else
		//{
		//    Debug.LogWarning("Invalid update method");
		//    foreach (var item in UpdateMessageBox.Pop(GameUpdateManager.Instance.GetString("update failed"), UpdateMessageBox.MessageBoxType.None))
		//        yield return item;

		//    yield return new WaitForSeconds(Single.MaxValue);
		//}

		var chooseYYBUpdateStyleResult = new ReturnTuple<UpdateChooseBox.YYBUpdateStyle>();
		foreach (var item in UpdateChooseBox.ChooseYYBUpdateStyle(chooseYYBUpdateStyleResult))
			yield return item;

		if (chooseYYBUpdateStyleResult.value_0 == UpdateChooseBox.YYBUpdateStyle.InGame)
		{
			//游戏内更新且没用wifi需要提示
			ReturnTuple<Boolean> confirmWirelessDownloadingResult = new ReturnTuple<Boolean>();
			foreach (var item in GameUpdateManager.Instance.ConfirmWirelessDownloading(confirmWirelessDownloadingResult))
				yield return item;

			if (!confirmWirelessDownloadingResult.value_0)
			{
				result.value_0 = ProgramUpdate.ProgramsUpdateRetcode.Fail;	//用户取消
				yield break;
			}
		}

		if (chooseYYBUpdateStyleResult.value_0 == UpdateChooseBox.YYBUpdateStyle.PopYYB)
		{
			StartSaveUpdate();
		}
		else if (chooseYYBUpdateStyleResult.value_0 == UpdateChooseBox.YYBUpdateStyle.InGame)
		{
			StartCommonUpdate();
		}
		else
		{
			result.value_0 = ProgramUpdate.ProgramsUpdateRetcode.Fail;	//用户取消
			yield break;
		}

		foreach (var item in ShowProgressCoroutine(versionParam, updatePanel, result))
			yield return item;
	}
Пример #8
0
	/// <summary>
	/// 
	/// </summary>
	/// <param name="timeout">超时时长</param>
	/// <param name="result">value_0: 有结果(即未超时), value_1~n: 各个结果</param>
	/// <returns></returns>
	private IEnumerable CheckNeedUpdateCoroutine(Single timeout, ReturnTuple<Boolean, Int64, String, Int64, Int32, String, Int32> result)
	{
		result.value_0 = false;

		CheckNeedUpdate();
		Boolean bHasResult = false;
		m_OnCheckNeedUpdateInfoEvent = (newApkSize, newFeature, patchSize, status, updateDownloadUrl, updateMethod) =>
		{
			result.value_1 = newApkSize;
			result.value_2 = newFeature;
			result.value_3 = patchSize;
			result.value_4 = status;
			result.value_5 = updateDownloadUrl;
			result.value_6 = updateMethod;

			bHasResult = true;
		};

		Single startTime = Time.realtimeSinceStartup;
		while (!bHasResult)		//等结果
		{
			if (Time.realtimeSinceStartup - startTime > timeout)		//超时了
			{
				m_OnCheckNeedUpdateInfoEvent = null;
				yield break;
			}

			yield return null;
		}

		result.value_0 = true;
	}
Пример #9
0
	public static IEnumerable GetDirInfoCoroutine(UIPanelUpdate updatePanel, ReturnTuple<ProgramsUpdateRetcode> result)
	{
		result.value_0 = ProgramsUpdateRetcode.NotSuccess;

		//load string table
		var stringTable = GameUpdateManager.Instance.StringTable;

		{	//init update ui
			updatePanel.sub_programTextGroup.SetActive(false);
			updatePanel.sub_resourceTextGroup.SetActive(false);

			updatePanel.sub_progress.value = 0;
			updatePanel.sub_progressText.text = "";
			updatePanel.sub_programLocalVersion.text = "";
			updatePanel.sub_programNewestVersion.text = "";
			updatePanel.sub_statusText.text = "";
		}

		SecurityElement dir_server = PlatformConfig.GetConfig("dir_server");
		String dir_server_address = dir_server.Attributes["address"].ToString();
		Int32 dir_server_port = Convert.ToInt32(dir_server.Attributes["port"].ToString());
		Boolean hasBackupAddress = true;
		//此时还未取得远程版本信息,所以 resource_update 从本地取,而不调用 GetResourceUpdateConfig
		var importantlist_address = PlatformConfig.GetConfig("resource_update").Attributes["importantlist"];
		if (importantlist_address == null || importantlist_address.ToString() == "")
			hasBackupAddress = false;

		if (String.IsNullOrEmpty(dir_server_address) || dir_server_port == 0)	//no dir server
		{
			result.value_0 = ProgramsUpdateRetcode.Success;
			yield break;
		}

		updatePanel.sub_statusText.text = stringTable["checking for update"];
		do
		{
			var dirSession = GNET.DirClient.RequestInfo(dir_server_address, dir_server_port);

			Single startWaitTime = Time.realtimeSinceStartup;
			Single timeOut = 10f;
			while (!GNET.DirClient.GetInstance().HasGotInfo())
			{
				if (Time.realtimeSinceStartup - startWaitTime > timeOut)
				{
					if (!hasBackupAddress)	//失败时无备选则提示重试
					{
						var msgBoxRet = new ReturnTuple<UpdateMessageBox.MessageBoxResult>();
						foreach (var item in UpdateMessageBox.Pop(stringTable["failed to check for update. click confirm to retry"], UpdateMessageBox.MessageBoxType.OK, msgBoxRet))
							yield return item;
					}

					GNET.DirClient.AbortRequest(dirSession);
					Debug.LogWarning("get dir info time out");

					break;
				}
				yield return null;
			}

			if (GNET.DirClient.GetInstance().HasGotInfo())
				break;
		}
		while (!hasBackupAddress);	//失败时无备选则重试

		EntryPoint.Instance.StartCoroutine(GetDirInfoLoopCoroutine(dir_server_address, dir_server_port));

		result.value_0 = ProgramsUpdateRetcode.Success;
	}
Пример #10
0
	public static IEnumerable UpdateCoroutine(UIPanelUpdate updatePanel, Boolean bSkipResourceUpdate, ReturnTuple<Boolean> result)
	{
		PatcherSpace.Patcher.PatcherConfig config;
		config.minimumVersion = GameUpdateManager.Instance.MinimumResourceVersion;
		config.resourcePath = EntryPointParam.AssetsPath;
		TextAsset stringtableAsset = Resources.Load("patcher/stringtable", typeof(TextAsset)) as TextAsset;
		String stringTableContent = stringtableAsset ? stringtableAsset.text : "";
		if (stringTableContent.Length == 0 || stringTableContent[0] != 0xfeff)	//add bom
			stringTableContent = '\xfeff' + stringTableContent;

		SecurityElement configXml = PlatformConfig.GetResourceUpdateConfig();

		config.resBaseVersion = LoadResBaseVersion();
		config.resBasePath = EntryPoint.Instance.BackupAssetsPath;
		config.cachePath = EntryPointParam.AssetsPath + "/cache";
		config.stringTableContent = stringTableContent;
		config.packext = configXml.Attributes["packext"].ToString();
		config.project = configXml.Attributes["project"].ToString();
		config.address = configXml.Attributes["address"].ToString();
		config.importantlist = configXml.Attributes["importantlist"].ToString();
		var packdownloadurlNode = configXml.Attributes["packdownloadurl"];
		config.packdownloadurl = packdownloadurlNode != null ? packdownloadurlNode.ToString() : "";
        config.newVersionFromDirInfo = GNET.DirClient.GetInstance().GetVersionList() ?? "";

		PatcherSpace.Patcher patcher = PatcherSpace.Patcher.instance();
		patcher.setup(config, EntryPoint.GetResBaseRelativePath());

		////D test message box (and wait for debugger)
		//var msgBoxRet = new ReturnTuple<UpdateMessageBox.MessageBoxResult>();
		//foreach (var item in UpdateMessageBox.Pop("Are you sure to update resource ?", UpdateMessageBox.MessageBoxType.YES_NO, msgBoxRet))
		//    yield return item;

		//if (msgBoxRet.value_0 == UpdateMessageBox.MessageBoxResult.NO)
		//{
		//    result.value_0 = false;
		//    yield break;
		//}

		//init ui
		{
			updatePanel.sub_programTextGroup.SetActive(false);
			updatePanel.sub_resourceTextGroup.SetActive(true);

			updatePanel.sub_resourceLocalVersion.text = "";
			updatePanel.sub_resourceNewestVersion.text = "";
			updatePanel.sub_progress.value = 0;
			updatePanel.sub_statusText.text = "";
			updatePanel.sub_progressText.text = "";
		}
		updatePanel.gameObject.SetActive(true);

		do
		{
			Debug.Log("Start update stages");

			ExpansionPackManager.Instance.Touch();	//保证在主线程中初始化

			foreach (var item in RunPatcherStage(updatePanel, () => patcher.startInitResource((e) => { Debug.LogException(e); }), result))
				yield return item;

			if (patcher.getErrorCode() != PatcherSpace.Patcher.ErrorCode.OK)
				continue;

			if (!bSkipResourceUpdate)
			{
				Debug.Log("expansion dir: " + ExpansionPackManager.Instance.GetDownloadedDir());
				foreach (var item in RunPatcherStage(updatePanel, () => patcher.startExpansionPackUpdate((e) => { Debug.LogException(e); }), result))
					yield return item;

				if (patcher.getErrorCode() != PatcherSpace.Patcher.ErrorCode.OK)
					continue;

				foreach (var item in RunPatcherStage(updatePanel, () => patcher.startAutoUpdate((e) => { Debug.LogException(e); }), result))
					yield return item;

				if (patcher.getErrorCode() != PatcherSpace.Patcher.ErrorCode.OK)
					continue;
			}
		}
		while (patcher.getErrorCode() == PatcherSpace.Patcher.ErrorCode.Restart);

		{
			//updatePanel.sub_groupAll.SetActive(false);
			//yield return null;
			ECUpdateUIManagerInstance.Value.DestroyDialog(updatePanel);
		}
	}
Пример #11
0
	/// <param name="targetVersion">应设为 GetProgramNewestVersion 所得结果</param>
	/// <param name="result">第一个元素表示是否成功</param>
	private static IEnumerable UpdateProgram(VersionParam versionParam, UIPanelUpdate updatePanel, ReturnTuple<ProgramsUpdateRetcode> result)
	{
		//init
		result.value_0 = ProgramsUpdateRetcode.NotSuccess;

		String method = versionParam.updateMethod;
		if (method == "install")
		{
			foreach (var item in InstallCoroutine(versionParam, updatePanel, result))
				yield return item;
		}
		else if (method == "open_url")
		{
			OpenUrl(versionParam.updateUrl);
			var stringTable = GameUpdateManager.Instance.StringTable;
			foreach (var item in UpdateMessageBox.Pop(stringTable["waiting for finish update"], UpdateMessageBox.MessageBoxType.None))
				yield return item;
			yield return new WaitForSeconds(Single.MaxValue);
		}
		else if (method == "yyb")
		{
			foreach (var item in ProgramUpdateYYB.UpdateCoroutine(versionParam, updatePanel, result))
				yield return item;
		}
		else if (method == "pop_yyb")
		{
			foreach (var item in ProgramUpdateYYB.PopYYBCoroutine(versionParam, updatePanel, result))
				yield return item;
		}
		else if (method == "msg")	//实在没辙了可以显示一条消息
		{
			foreach (var item in UpdateMessageBox.Pop(versionParam.updateUrl, UpdateMessageBox.MessageBoxType.None))
				yield return item;

			yield return new WaitForSeconds(Single.MaxValue);
		}
		else
		{
			throw new Exception("unsupported program_update method: " + method);
		}
	}
Пример #12
0
	/// <param name="result">第一个元素表示是否成功;第二个元素为结果</param>
	private static IEnumerable GetProgramVersionByUrl(String url, ReturnTuple<Boolean, String> result)
	{
		WebClientWithTimeout webClient = new WebClientWithTimeout();
		webClient.Timeout = 30 * 1000;
		DownloadState downloadState = new DownloadState();

		webClient.DownloadDataCompleted += (object sender, DownloadDataCompletedEventArgs arg) =>
		{
			if (arg.Cancelled)
			{
				downloadState.cancel = true;
			}
			else if (arg.Error != null)	//error occurs
			{
				downloadState.exception = arg.Error;
			}
			else
			{
				downloadState.result = arg.Result;
			}

			downloadState.done = true;
		};

		webClient.DownloadDataAsync(new Uri(PatcherSpace.Utility.AddRandomParamToUrl(url)));
		while (!downloadState.done)
		{
			yield return null;
		}

		if (!downloadState.cancel && downloadState.exception == null)	//success
		{
			result.value_0 = true;
			result.value_1 = Encoding.UTF8.GetString(downloadState.result);
		}
		else
		{
			UnityEngine.Debug.LogWarning("Failed to download version file: " + url);
			if (downloadState.exception != null)
			{
				UnityEngine.Debug.LogWarning(downloadState.exception.ToString());
			}
		}
	}
Пример #13
0
	/// <param name="result">第一个元素表示是否成功;第二个元素为结果</param>
	private static IEnumerable GetProgramNewestVersionInfo(ReturnTuple<Boolean, String> result)
	{
		//init
		result.value_0 = false;

		SecurityElement config = PlatformConfig.GetConfig("program_get_version");
		String method = config.Attributes["method"].ToString();
		if (method == "get_by_url")
		{
			foreach (var item in GetProgramVersionByUrl(config.Attributes["url"].ToString(), result))
				yield return item;
		}
		else
		{
			throw new Exception("unsupported program_get_version method: " + method);
		}
	}
Пример #14
0
	public static IEnumerable UpdateCoroutine(UIPanelUpdate updatePanel, ReturnTuple<ProgramsUpdateRetcode> result, ReturnTuple<MaintenanceInfo> maintenanceInfo)
	{
		result.value_0 = ProgramsUpdateRetcode.NotSuccess;
		maintenanceInfo.value_0.status = false;
		maintenanceInfo.value_0.reason = "";

		//load string table
		var stringTable = GameUpdateManager.Instance.StringTable;

		{	//init update ui
			updatePanel.sub_programTextGroup.SetActive(true);
			updatePanel.sub_resourceTextGroup.SetActive(false);

			updatePanel.sub_progress.value = 0;
			updatePanel.sub_progressText.text = "";
			updatePanel.sub_programLocalVersion.text = "";
			updatePanel.sub_programNewestVersion.text = "";
			updatePanel.sub_statusText.text = "";
		}

		//local version
		ProgramVersionInfo localVersionInfo = GetProgramCurrentVersionInfo();
		
		updatePanel.sub_programLocalVersion.text = localVersionInfo.descriptionName;
		Debug.Log(String.Format("local version: {0}", localVersionInfo.version));

		////Test message box
		//{
		//    var msgBoxRet = new ReturnTuple<UpdateMessageBox.MessageBoxResult>();
		//    foreach (var item in UpdateMessageBox.Pop("Are you sure to update program ?", UpdateMessageBox.MessageBoxType.YES_NO, msgBoxRet))
		//        yield return item;

		//    if (msgBoxRet.value_0 == UpdateMessageBox.MessageBoxResult.NO)
		//    {
		//        result.value_0 = false;
		//        yield break;
		//    }
		//}

		updatePanel.sub_statusText.text = stringTable["checking for update"];
		var getVersionResult = new ReturnTuple<Boolean, String>();		//bSucc, content

		String newestVersionInfo = null;
		if (GNET.DirClient.GetInstance().HasGotInfo())
		{
			newestVersionInfo = GNET.DirClient.GetInstance().GetVersion();
		}
		else
		{
			while (true)
			{
				foreach (var item in GetProgramNewestVersionInfo(getVersionResult))
					yield return item;

				if (getVersionResult.value_0)
				{
					break;
				}
				else	//未取得版本号
				{
					var msgBoxRet = new ReturnTuple<UpdateMessageBox.MessageBoxResult>();
					foreach (var item in UpdateMessageBox.Pop(stringTable["failed to check for update. click confirm to retry"], UpdateMessageBox.MessageBoxType.OK, msgBoxRet))
						yield return item;
				}
			}
			newestVersionInfo = getVersionResult.value_1;
		}

		//分析取得的版本信息
		Exception error = null;
		VersionParam versionParam = new VersionParam();
		try
		{
			SecurityElement versionDoc = SecurityElement.FromString(newestVersionInfo);
			SecurityElement verNode = versionDoc;

			//如果有 specialRegion,按 specialRegion 再找一级
			String specialRegion = PlatformConfig.GetSpecialRegion();
			if (specialRegion != "")
				verNode = verNode.SearchForChildByTag(specialRegion);

			versionParam.newestVersion = Convert.ToInt32(verNode.Attributes["value"].ToString());
			Int32.TryParse(verNode.Attributes["compatible_version"].ToString(), out versionParam.compatibleVersion);

			if (verNode.Attributes["evaluation"] != null && verNode.Attributes["evaluation"].ToString() == "true")
				m_isEvaluation = true;
				
			if (verNode.Attributes["evaluation_version"] != null)
			{
				String evaluation_version_str = verNode.Attributes["evaluation_version"].ToString();
				if (evaluation_version_str.Length > 0)
				{
					Int32 evaluation_version = Convert.ToInt32(verNode.Attributes["evaluation_version"].ToString());
					if (localVersionInfo.version >= evaluation_version)
						m_isEvaluation = true;
				}
			}

			if (verNode.Attributes["evaluation_update"] != null && verNode.Attributes["evaluation_update"].ToString() == "true")
				m_isEvaluationUpdate = true;


			versionParam.minimumResourceVersion = verNode.Attributes["minimum_resource_version"].ToString();
			versionParam.updateMethod = verNode.SearchForChildByTag("update").Attributes["method"].ToString();
			String url = "";
			if (verNode.SearchForChildByTag("update").Attributes.Contains("url"))
				url = verNode.SearchForChildByTag("update").Attributes["url"].ToString();
			versionParam.updateUrl = url;

			if (verNode.SearchForChildByTag("update").Attributes.Contains("md5"))
				versionParam.updateMd5 = verNode.SearchForChildByTag("update").Attributes["md5"].ToString();

			versionParam.newestVersionShowName = verNode.SearchForChildByTag("description").Attributes["name"].ToString();
			versionParam.newestVersionContent = verNode.SearchForChildByTag("description").Attributes["content"].ToString();

			maintenanceInfo.value_0.status = verNode.SearchForChildByTag("maintenance").Attributes["status"].ToString() == "true";
			maintenanceInfo.value_0.reason = verNode.SearchForChildByTag("maintenance").Attributes["reason"].ToString();
			
			PlatformConfig.SetResourceUpdateConfig(verNode.SearchForChildByTag("resource_update"));
		}
		catch (XmlSyntaxException e)
		{	error = e;	}
		catch (NullReferenceException e)
		{	error = e;	}
		catch (FormatException e)
		{	error = e;	}
		catch (OverflowException e)
		{	error = e;	}

		if (error != null)
		{
			Debug.LogWarning("version.xml has format error");
			Debug.LogException(error);
			foreach (var item in UpdateMessageBox.Pop(stringTable["update server has error"], UpdateMessageBox.MessageBoxType.None))
			    yield return item;

			yield return new WaitForSeconds(Single.MaxValue);
		}

		if (IsEvaluation() && !IsEvaluationUpdate())
		{
			result.value_0 = ProgramsUpdateRetcode.Skip;
			yield break;
		}

		//已取得最低资源版本,记下来
		GameUpdateManager.Instance.MinimumResourceVersion = PatcherSpace.Patcher.VersionInfo.FromString(versionParam.minimumResourceVersion);

		updatePanel.sub_programNewestVersion.text = versionParam.newestVersionShowName;

		if (versionParam.newestVersion > localVersionInfo.version)
		{
			PatcherSpace.Launcher.instance().ClearTempDir(versionParam.newestVersion, makeLauncherTempDir());

			Debug.Log(String.Format("has new version: {0}", versionParam.newestVersion));

			while (true)
			{
				ReturnTuple<Boolean> chooseWhetherUpdateResult = new ReturnTuple<Boolean>();
				String title = String.Format(stringTable["newest version is {0}"], versionParam.newestVersionShowName);
				foreach (var item in UpdateChooseBox.ChooseWhetherUpdate(title, versionParam.newestVersionContent, chooseWhetherUpdateResult))
					yield return item;

				if (chooseWhetherUpdateResult.value_0)	//选了“是”
				{
					break;
				}
				else
				{
					//选了“否”
					if (versionParam.compatibleVersion > localVersionInfo.version)	//必须更新
					{
						var msgBoxRet = new ReturnTuple<UpdateMessageBox.MessageBoxResult>();
						foreach (var item in UpdateMessageBox.Pop(stringTable["must update"], UpdateMessageBox.MessageBoxType.OK, msgBoxRet))
							yield return item;
					}
					else	//跳过更新
					{
						result.value_0 = ProgramsUpdateRetcode.Success;
						yield break;
					}
				}
			}

			foreach (var item in UpdateProgram(versionParam, updatePanel, result))
				yield return item;

			if (result.value_0 == ProgramsUpdateRetcode.Fail)
			{
				Debug.Log("UpdateCoroutine failed");
				foreach (var item in UpdateMessageBox.Pop(stringTable["update failed"], UpdateMessageBox.MessageBoxType.None))
					yield return item;
				yield return new WaitForSeconds(Single.MaxValue);
			}
		}
		else
		{
			PatcherSpace.Launcher.instance().ClearTempDir(makeLauncherTempDir());
		}
	}
Пример #15
0
	public IEnumerable UpdateRoutine()
	{
		exp_af_SetCopyBackupFilePackage(EntryPoint.Instance.CopyBackupPackage);

        //String[] commandLineArgs = Environment.GetCommandLineArgs();
		do
		{
			bool bSkipProgramUpdate = EntryPoint.Instance.NoProgramUpdate;

			bool bCancelUpdate = false;

			//ECUpdateUIManagerInstance.Value.CreateDialog("ui/prefab/panel_updatebackground");
			//add update ui
			UIPanelUpdate updatePanel = ECUpdateUIManagerInstance.Value.CreateDialog("ui/prefab/panel_update").AddComponent<UIPanelUpdate>();

			//
			//get dir info
			//
			var getDirInfoResult = new ReturnTuple<ProgramUpdate.ProgramsUpdateRetcode>();
			foreach (var item in ProgramUpdate.GetDirInfoCoroutine(updatePanel, getDirInfoResult))
				yield return item;
			//if (getDirInfoResult. ...			//失败后有备选

			//
			//programs update
			//
			var maintenanceInfo = new ReturnTuple<ProgramUpdate.MaintenanceInfo>();
			if (!bSkipProgramUpdate)
			{
				var updateResult = new ReturnTuple<ProgramUpdate.ProgramsUpdateRetcode>();
				foreach (var item in ProgramUpdate.UpdateCoroutine(updatePanel, updateResult, maintenanceInfo))
					yield return item;

				if (updateResult.value_0 == ProgramUpdate.ProgramsUpdateRetcode.Skip)
					bCancelUpdate = true;
			}

			//
			//maintenance status
			//
			{
				foreach (var item in ResourceUpdate.ShowMaintenanceInfo(updatePanel, maintenanceInfo.value_0))
					yield return item;
			}

			//
			//resource update
			//
			//if (!EntryPoint.Instance.NoResourceUpdate && (commandLineArgs == null || Array.IndexOf(commandLineArgs, "-noresourceupdate") < 0))
			{
				bool bSkipResourceUpdate = EntryPoint.Instance.IsNoResourceUpdate();

				var updateResult = new ReturnTuple<Boolean>();
				foreach (var item in ResourceUpdate.UpdateCoroutine(updatePanel, bCancelUpdate || bSkipResourceUpdate, updateResult))
					yield return item;
			}
		}
		while (false);

		ECUpdateUIManagerInstance.Value.Destroy();
		Resources.UnloadUnusedAssets();
	}
Пример #16
0
	/// <summary>
	/// 确认是否用无线网络下载(可能产生流量费用)
	/// </summary>
	/// <param name="result"></param>
	/// <returns></returns>
	public IEnumerable ConfirmWirelessDownloading(ReturnTuple<Boolean> result)
	{
		//是否需要确认
		{
			Boolean bCanDownload;
			if (!NeedConfirmWirelessDownloading(out bCanDownload))
			{
				result.value_0 = bCanDownload;
				yield break;
			}
		}

		var msgBoxRet = new ReturnTuple<UpdateMessageBox.MessageBoxResult>();
		foreach (var item in UpdateMessageBox.Pop(StringTable["confirm download via wireless network"], UpdateMessageBox.MessageBoxType.YES_NO, msgBoxRet))
			yield return item;

		result.value_0 = (msgBoxRet.value_0 == UpdateMessageBox.MessageBoxResult.YES);
	}
Пример #17
0
	private static IEnumerable InstallCoroutine(VersionParam versionParam, UIPanelUpdate updatePanel, ReturnTuple<ProgramsUpdateRetcode> result)
	{
		result.value_0 = ProgramsUpdateRetcode.NotSuccess;

		//load string table
		var stringTable = GameUpdateManager.Instance.StringTable;

		//check runtime platform
		if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.Android)		//supported
		{
		}
		else if (Application.platform == RuntimePlatform.WindowsEditor)		//方便测试用
		{}
		else
		{
			updatePanel.sub_statusText.text = stringTable["auto update not supported"];
			foreach (var item in UpdateMessageBox.Pop(stringTable["auto update not supported, please update manually"], UpdateMessageBox.MessageBoxType.OK))
			    yield return item;

		    result.value_0 = ProgramsUpdateRetcode.Fail;
		    yield break;
		}

		yield return null;

		PatcherSpace.LauncherConfig launcherConfig;
		launcherConfig.resourcePath = EntryPointParam.AssetsPath;
		launcherConfig.stringTable = stringTable;
		launcherConfig.targetVersion = versionParam.newestVersion;
		launcherConfig.packAddress = versionParam.updateUrl;
		launcherConfig.packMd5 = versionParam.updateMd5;
		launcherConfig.tempDir = makeLauncherTempDir();

		PatcherSpace.Launcher launcher = PatcherSpace.Launcher.instance();
		launcher.init(launcherConfig);
		launcher.startInstall((e) => { Debug.LogException(e); });

		Int32 toFinish = 2;
		while (toFinish > 0)
		{
			if (!launcher.isBusy())	//这样能在结束后更新状态
				--toFinish;

			updatePanel.sub_progress.value = (float)launcher.getTotalProgress();
			updatePanel.sub_statusText.text = launcher.getStatusText();

			Int64 totalUpdateSize = launcher.getUpdateTotalSize();
			if (totalUpdateSize > 0)
			{
				updatePanel.sub_progressText.text = FormatFileSize((Int64)(totalUpdateSize * launcher.getTotalProgress())) + "/" + FormatFileSize(totalUpdateSize);
			}
			else
			{
				updatePanel.sub_progressText.text = "";
			}

			yield return null;
		}

		PatcherSpace.Launcher.ErrorCode errorCode = launcher.getErrorCode();
		Boolean bSuccess = (errorCode == PatcherSpace.Launcher.ErrorCode.OK);
		result.value_0 = ProgramsUpdateRetcode.Success;

		if (errorCode == PatcherSpace.Launcher.ErrorCode.OK)
		{
			if (Application.platform == RuntimePlatform.WindowsPlayer)
			{
				EntryPoint.ExitGame();
			}
			else if (Application.platform == RuntimePlatform.WindowsEditor)		//方便测试用
			{
				foreach (var item in UpdateMessageBox.Pop(GameUpdateManager.Instance.GetString("waiting for finish install"), UpdateMessageBox.MessageBoxType.None))
					yield return item;
				yield return new WaitForSeconds(Single.MaxValue);
			}
			else if (Application.platform == RuntimePlatform.Android)
			{
				foreach (var item in UpdateMessageBox.Pop(GameUpdateManager.Instance.GetString("waiting for finish install"), UpdateMessageBox.MessageBoxType.None))
					yield return item;
				yield return new WaitForSeconds(Single.MaxValue);
			}
		}
		else if (errorCode == PatcherSpace.Launcher.ErrorCode.Fail)
		{
			foreach (var item in UpdateMessageBox.Pop(GameUpdateManager.Instance.GetString("update failed"), UpdateMessageBox.MessageBoxType.None))
				yield return item;
			yield return new WaitForSeconds(Single.MaxValue);
		}
		else if (errorCode == PatcherSpace.Launcher.ErrorCode.NoSpace)
		{
			foreach (var item in UpdateMessageBox.Pop(GameUpdateManager.Instance.GetString("no disk space"), UpdateMessageBox.MessageBoxType.None))
				yield return item;
			yield return new WaitForSeconds(Single.MaxValue);
		}
	}
Пример #18
0
	private static IEnumerable RunPatcherStage(UIPanelUpdate updatePanel, Action stageAction, ReturnTuple<Boolean> result)
	{
		result.value_0 = false;

		PatcherSpace.Patcher patcher = PatcherSpace.Patcher.instance();

		stageAction();

		yield return null;

		Int32 toFinish = 2;
		while (toFinish > 0)
		{
			if (!patcher.isBusy())	//这样能在结束后更新状态
				--toFinish;

			updatePanel.sub_resourceLocalVersion.text = patcher.getLocalVersion().ToString();
			updatePanel.sub_resourceNewestVersion.text = patcher.getServerVersion().ToString();

			Double progress = patcher.getTotalProgress();
			updatePanel.sub_progress.value = (float)patcher.getTotalProgress();

			updatePanel.sub_statusText.text = patcher.getStatusText();

			Int64 totalUpdateSize = patcher.getUpdateTotalSize();
			if (totalUpdateSize > 0 && patcher.getUpdateStage() == PatcherSpace.Patcher.UpdateStage.Update)
			{
			    updatePanel.sub_progressText.text = FormatFileSize((Int64)(totalUpdateSize * progress)) + "/" + FormatFileSize(totalUpdateSize);
			}
			else
			{
			    updatePanel.sub_progressText.text = "";
			}

			yield return null;
		}
		
		PatcherSpace.Patcher.ErrorCode errorCode = patcher.getErrorCode();
		if (errorCode == PatcherSpace.Patcher.ErrorCode.OK
			|| errorCode == PatcherSpace.Patcher.ErrorCode.Cancel
			|| errorCode == PatcherSpace.Patcher.ErrorCode.Restart)
		{
			//updatePanel.sub_progress.sliderValue = 1;
			Debug.Log("Status: " + patcher.getStatusText());

			result.value_0 = true;
		}
		else
		{
			result.value_0 = false;

			Debug.Log(patcher.getErrorCode());
			Debug.Log("Status: " + patcher.getStatusText());
			Debug.Log("Error message: " + patcher.getErrorText());
			foreach (var item in UpdateMessageBox.Pop(GameUpdateManager.Instance.GetString("update failed"), UpdateMessageBox.MessageBoxType.None))
				yield return item;
			yield return new WaitForSeconds(Single.MaxValue);
		}

	}