using System; using System.Collections; using System.IO; using UnityEngine; using XMainClient.UI; using XMainClient.UI.UICommon; using XUpdater; using XUtliPoolLib; namespace XMainClient { internal class XScreenShotMgr : XSingleton { public string FilePath { get { return this._file_path; } } public string FileName { get { return this._file_name; } } private string _file_name; private string _file_path; private string _share_type; private int _check_count = 0; private int _max_check_count = 50; private bool _is_sharing = false; private IXIFlyMgr _ifly_mgr = null; private uint _check_token = 0u; private uint _share_token = 0u; private int _share_count = 0; private bool _share_doing = false; private string _logo_local_path; private int _share_index = 1; private WWW _downloader = null; private bool _share_session = false; private ShareTagType _tag = ShareTagType.Invite_Tag; private string _url = null; private object[] _params; private ScreenShotCallback _share_callback = null; public override bool Init() { bool flag = this._ifly_mgr == null; if (flag) { this._ifly_mgr = (XUpdater.XUpdater.XGameRoot.GetComponent("XIFlyMgr") as IXIFlyMgr); } this._logo_local_path = Application.persistentDataPath + "/sharelogo"; this.ClearOldPic(); return true; } public override void Uninit() { base.Uninit(); } private void CheckScreenShotPic(object obj) { bool flag = this._ifly_mgr == null; if (!flag) { bool flag2 = File.Exists(this._file_path); if (flag2) { this._is_sharing = false; bool flag3 = XSingleton.singleton.Channel == XAuthorizationChannel.XAuthorization_QQ; if (flag3) { this._ifly_mgr.ScreenShotQQShare(this._file_path, this._share_type); } else { this._ifly_mgr.ScreenShotWeChatShare(this._file_path, this._share_type); } DlgBase.singleton.SetVisible(false, true); } else { bool flag4 = this._check_count >= this._max_check_count; if (flag4) { XSingleton.singleton.AddErrorLog("Share failed", null, null, null, null, null); } else { this._check_token = XSingleton.singleton.SetTimer(0.1f, new XTimerMgr.ElapsedEventHandler(this.CheckScreenShotPic), null); this._check_count++; } } } } public void CaptureScreenshot(object obj) { XSingleton.singleton.SendStatisticToServer(ShareOpType.Photo, DragonShareType.None); this._file_name = string.Format("{0}{1}{2}_{3}{4}{5}.png", new object[] { DateTime.Now.Year.ToString().PadLeft(2, '0'), DateTime.Now.Month.ToString().PadLeft(2, '0'), DateTime.Now.Day.ToString().PadLeft(2, '0'), DateTime.Now.Hour.ToString().PadLeft(2, '0'), DateTime.Now.Minute.ToString().PadLeft(2, '0'), DateTime.Now.Second.ToString().PadLeft(2, '0') }); this._file_path = Application.persistentDataPath + "/" + this._file_name; XSingleton.singleton.AddLog("Take a screen shot: ", this._file_path, null, null, null, null, XDebugColor.XDebug_None); RuntimePlatform platform = Application.platform; if ((int)platform != 8 && (int)platform != 11) { Application.CaptureScreenshot(this._file_path, 0); } else { Application.CaptureScreenshot(this._file_name, 0); } } public void ShareScreen(bool issession) { if (issession) { this._share_type = "Session"; } else { bool flag = XSingleton.singleton.Channel == XAuthorizationChannel.XAuthorization_QQ; if (flag) { this._share_type = "QZone"; } else { this._share_type = "Timeline"; } } bool is_sharing = this._is_sharing; if (!is_sharing) { this._check_count = 0; this.CheckScreenShotPic(null); } } public string PartCaptureScreen(Rect rect, string accountType, string scene) { this._share_type = scene; XSingleton.singleton.SendStatisticToServer(ShareOpType.Share, DragonShareType.Pandora); XSingleton.singleton.IFLYMGR.GetMonoBehavior().StartCoroutine(this.CaptureByCamera(rect, accountType)); return this._file_path; } private IEnumerator CaptureByCamera(Rect rect, string accountType) { yield return new WaitForEndOfFrame(); Texture2D texture = new Texture2D((int)rect.width, (int)rect.height); texture.ReadPixels(rect, 0, 0); texture.Apply(); try { byte[] bytes = texture.EncodeToPNG(); this._file_name = string.Format("{0}{1}{2}_{3}{4}{5}.png", new object[] { DateTime.Now.Year.ToString().PadLeft(2, '0'), DateTime.Now.Month.ToString().PadLeft(2, '0'), DateTime.Now.Day.ToString().PadLeft(2, '0'), DateTime.Now.Hour.ToString().PadLeft(2, '0'), DateTime.Now.Minute.ToString().PadLeft(2, '0'), DateTime.Now.Second.ToString().PadLeft(2, '0') }); this._file_path = Application.persistentDataPath + "/" + this._file_name; File.WriteAllBytes(this._file_path, bytes); bytes = null; } catch (Exception ex) { Exception e = ex; XSingleton.singleton.AddErrorLog("part capture failed " + e.Message, null, null, null, null, null); } bool flag = File.Exists(this._file_path); if (flag) { bool flag2 = accountType == "qq"; if (flag2) { this._ifly_mgr.ScreenShotQQShare(this._file_path, this._share_type); } else { this._ifly_mgr.ScreenShotWeChatShare(this._file_path, this._share_type); } } yield break; } private void ClearOldPic() { string persistentDataPath = Application.persistentDataPath; bool flag = Directory.Exists(persistentDataPath); if (flag) { DirectoryInfo directoryInfo = new DirectoryInfo(persistentDataPath); FileInfo[] files = directoryInfo.GetFiles(); bool flag2 = files != null; if (flag2) { for (int i = 0; i < files.Length; i++) { string a = files[i].Name.Substring(files[i].Name.LastIndexOf(".") + 1); bool flag3 = a != "png"; if (!flag3) { files[i].Delete(); } } } } } public void SaveScreenshotPic(string filepath) { this._ifly_mgr.ScreenShotSave(filepath); } public void RefreshPhotoView(string fullpath) { this._ifly_mgr.RefreshAndroidPhotoView(fullpath); } public void StartExternalScreenShotView(ScreenShotCallback callback) { bool share_doing = this._share_doing; if (!share_doing) { this._share_callback = callback; this.CaptureScreenshot(null); this._share_token = XSingleton.singleton.SetTimer(0.2f, new XTimerMgr.ElapsedEventHandler(this.ExternalReadyShare), null); } } private void ExternalReadyShare(object obj) { bool flag = !File.Exists(XSingleton.singleton.FilePath); if (flag) { this._share_count++; bool flag2 = this._share_count > 30; if (flag2) { XSingleton.singleton.ShowSystemTip("Failed", "fece00"); this._share_doing = false; } else { this._share_token = XSingleton.singleton.SetTimer(0.1f, new XTimerMgr.ElapsedEventHandler(this.ExternalReadyShare), null); } } else { XSingleton.singleton.AddLog("The screen file path: ", XSingleton.singleton.FilePath, null, null, null, null, XDebugColor.XDebug_None); XSingleton.singleton.AddLog("File exist: ", File.Exists(XSingleton.singleton.FilePath).ToString(), null, null, null, null, XDebugColor.XDebug_None); RuntimePlatform platform = Application.platform; if ((int)platform == 8 || (int)platform == 11) { byte[] array = File.ReadAllBytes(XSingleton.singleton.FilePath); Texture2D texture2D = new Texture2D(2, 2); bool flag3 = texture2D.LoadImage(array); XSingleton.singleton.AddLog("Use file load", null, null, null, null, null, XDebugColor.XDebug_None); bool flag4 = flag3; if (flag4) { int width = texture2D.width; int height = texture2D.height; XSingleton.singleton.AddLog("The width: ", width.ToString(), ", height: ", height.ToString(), null, null, XDebugColor.XDebug_None); bool flag5 = width <= 600 && this._share_callback != null; if (flag5) { this._share_callback(false); } else { this.DoShareAction(); } UnityEngine.Object.DestroyImmediate(texture2D, true); } else { bool flag6 = !flag3 && this._share_callback != null; if (flag6) { this._share_callback(false); } } this._share_doing = false; } } } private void DoShareAction() { this.ShareScreen(false); } private IEnumerator StartDownloadLogo(string path) { XSingleton.singleton.AddLog("StartDownloadLogo", null, null, null, null, null, XDebugColor.XDebug_None); this._downloader = new WWW(path); yield return this._downloader; while (!this._downloader.isDone) { yield return this._downloader; } XSingleton.singleton.AddLog("Will do share, local icon: ", this._logo_local_path, null, null, null, null, XDebugColor.XDebug_None); XSingleton.singleton.AddLog("IsDone: ", this._downloader.isDone.ToString(), ", error: ", this._downloader.error, null, null, XDebugColor.XDebug_None); bool flag = this._downloader.isDone && string.IsNullOrEmpty(this._downloader.error); if (flag) { byte[] bs = this._downloader.bytes; bool flag2 = bs != null; if (flag2) { try { File.WriteAllBytes(this._logo_local_path, bs); } catch (Exception ex) { Exception e = ex; XSingleton.singleton.AddErrorLog("write file local failed!", e.Message, null, null, null, null); } XSingleton.singleton.AddLog("Is icon exsit: ", File.Exists(this._logo_local_path).ToString(), null, null, null, null, XDebugColor.XDebug_None); bool flag3 = File.Exists(this._logo_local_path); if (flag3) { this.DownLoadCallback(); } } bs = null; } this._downloader.Dispose(); this._downloader = null; yield break; } private void DownLoadCallback() { bool flag = this._ifly_mgr == null; if (!flag) { ShareTable.RowData shareInfoById = XScreenShotShareDocument.GetShareInfoById(this._share_index); string[] array = shareInfoById.Link.Split(new char[] { '|' }); XSingleton.singleton.AddLog("Links: ", shareInfoById.Link, null, null, null, null, XDebugColor.XDebug_None); bool flag2 = XSingleton.singleton.Channel == XAuthorizationChannel.XAuthorization_QQ; if (flag2) { string text = this._url; bool flag3 = string.IsNullOrEmpty(text); if (flag3) { text = array[0]; text = string.Format(text, this._params); } this._ifly_mgr.ShareQZoneLink(shareInfoById.Title, shareInfoById.Desc, text, this._logo_local_path, this._share_session); } else { bool flag4 = XSingleton.singleton.Channel == XAuthorizationChannel.XAuthorization_WeChat; if (flag4) { string text2 = this._url; bool flag5 = string.IsNullOrEmpty(text2); if (flag5) { text2 = ((array.Length > 1) ? array[1] : array[0]); text2 = string.Format(text2, this._params); } bool flag6 = this._tag == ShareTagType.Invite_Tag; if (flag6) { this._ifly_mgr.ShareWechatLink(shareInfoById.Title, this._logo_local_path, text2, this._share_session); } else { bool flag7 = this._tag == ShareTagType.GiftBag_Tag; if (flag7) { this._ifly_mgr.ShareWechatLinkWithMediaTag(shareInfoById.Title, this._logo_local_path, text2, this._share_session, "MSG_GIFT_PACKS_FD"); } } } } } } public void DoShareWithLink(int shareindex, bool issession = false, ShareTagType tag = ShareTagType.Invite_Tag, string url = null, params object[] args) { this.SendStatisticToServer(ShareOpType.Share, DragonShareType.ActivityShare); ShareTable.RowData shareInfoById = XScreenShotShareDocument.GetShareInfoById(shareindex); XSingleton.singleton.AddLog("Will doshare with link", null, null, null, null, null, XDebugColor.XDebug_None); bool flag = shareInfoById != null; if (flag) { this._share_index = shareindex; this._share_session = issession; this._tag = tag; this._params = args; this._url = url; bool flag2 = File.Exists(this._logo_local_path); if (flag2) { File.Delete(this._logo_local_path); } XSingleton.singleton.AddLog("Icon: ", shareInfoById.Icon, null, null, null, null, XDebugColor.XDebug_None); XSingleton.singleton.IFLYMGR.GetMonoBehavior().StartCoroutine(this.StartDownloadLogo(shareInfoById.Icon)); } } public void SendStatisticToServer(ShareOpType op, DragonShareType type) { PtcC2G_ShareReport ptcC2G_ShareReport = new PtcC2G_ShareReport(); ptcC2G_ShareReport.Data.type = (int)type; ptcC2G_ShareReport.Data.op = (int)type; XSingleton.singleton.Send(ptcC2G_ShareReport); } } }