using System; using System.Collections.Generic; using System.IO; using System.Text; using UnityEngine; using XUpdater; namespace XUtliPoolLib { public class XFileLog : MonoBehaviour { private static Queue CustomLogQueue = new Queue(); private const int QUEUE_SIZE = 20; public static string RoleName = ""; public static uint RoleLevel = 0u; public static int RoleProf = 0; public static string ServerID = ""; public static string OpenID = ""; public static uint SceneID = 0u; private static Application.LogCallback callBack = null; private string _outpath; public bool _logOpen = true; private bool _firstWrite = true; private string _guiLog = ""; private bool _showGuiLog = false; private GUIStyle fontStyle = null; public static string debugStr = "0"; public static bool _OpenCustomBtn = false; public static bool _debugTrigger = true; private Vector2 scrollPosition; private bool _showCustomInfo = false; public static bool _logBundleOpen = false; public static string _customInfo = ""; public static int _customInfoHeight = 0; private void Start() { this._outpath = Application.persistentDataPath + string.Format("/{0}{1}{2}_{3}{4}{5}.log", 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') }); string path = ((int)Application.platform == 8) ? ("/private" + Application.persistentDataPath) : Application.persistentDataPath; bool flag = Directory.Exists(path); if (flag) { DirectoryInfo directoryInfo = new DirectoryInfo(path); 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 != "log"; if (!flag3) { bool flag4 = DateTime.Now.Subtract(files[i].CreationTime).TotalDays > 1.0; if (flag4) { try { files[i].Delete(); } catch { XSingleton.singleton.AddErrorLog("Del Log File Error!!!", null, null, null, null, null); } } } } } } XFileLog.callBack = new Application.LogCallback(this.HandleLog); Application.logMessageReceived += XFileLog.callBack; XSingleton.singleton.AddLog(this._outpath, null, null, null, null, null, XDebugColor.XDebug_None); } public void HandleLog(string logString, string stackTrace, LogType type) { bool flag = !this._firstWrite; if (!flag) { bool logOpen = this._logOpen; if (logOpen) { this.WriterLog(logString); } bool flag2 = type == null || (int)type == 4; if (flag2) { this._firstWrite = false; this.Log(new object[] { logString }); this.Log(new object[] { stackTrace }); string text = string.Format("{0}\n{1}\n", logString, stackTrace); while (XFileLog.CustomLogQueue.Count > 0) { text = string.Format("{0}\n{1}", text, XFileLog.CustomLogQueue.Dequeue()); } this.SendBuglyReport(text); this._guiLog = text; this._showGuiLog = true; } } } private void OnGUI() { bool logBundleOpen = XFileLog._logBundleOpen; if (logBundleOpen) { bool flag = XSingleton.singleton.ABManager != null; if (flag) { GUI.TextArea(new Rect(0f, 30f, 100f, 30f), XSingleton.singleton.ABManager.BundleCount.ToString()); } } bool flag2 = this.fontStyle == null; if (flag2) { this.fontStyle = new GUIStyle(); } bool showGuiLog = this._showGuiLog; if (showGuiLog) { bool flag3 = GUI.Button(new Rect(0f, 0f, 100f, 30f), "CrashLog"); if (flag3) { this._showGuiLog = !this._showGuiLog; } bool showGuiLog2 = this._showGuiLog; if (showGuiLog2) { this.fontStyle.normal.textColor = new Color(1f, 0f, 0f); this.fontStyle.fontSize = 14; this.fontStyle.normal.background = Texture2D.whiteTexture; GUI.TextArea(new Rect(0f, 40f, 1136f, 3200f), this._guiLog, this.fontStyle); } } bool key = Input.GetKey((KeyCode)286); if (key) { XFileLog._OpenCustomBtn = !XFileLog._OpenCustomBtn; } bool openCustomBtn = XFileLog._OpenCustomBtn; if (openCustomBtn) { bool flag4 = GUI.Button(new Rect(250f, 0f, 150f, 50f), "Info"); if (flag4) { this._showCustomInfo = !this._showCustomInfo; } } bool showCustomInfo = this._showCustomInfo; if (showCustomInfo) { this.fontStyle.normal.textColor = new Color(0f, 0f, 0f); this.fontStyle.fontSize = 16; this.fontStyle.normal.background = Texture2D.whiteTexture; this.scrollPosition = GUI.BeginScrollView(new Rect(0f, 30f, 1136f, 640f), this.scrollPosition, new Rect(0f, 30f, 1136f, (float)(XFileLog._customInfoHeight * (this.fontStyle.fontSize + 2) + 100))); GUI.Label(new Rect(0f, 30f, 1136f, (float)(XFileLog._customInfoHeight * (this.fontStyle.fontSize + 2) + 30)), XFileLog._customInfo, this.fontStyle); GUI.EndScrollView(); } } public void WriterLog(string logString) { using (StreamWriter streamWriter = new StreamWriter(this._outpath, true, Encoding.UTF8)) { streamWriter.WriteLine(string.Format("[{0}]{1}", string.Format("{0}/{1}/{2} {3}:{4}:{5}.{6}", new object[] { DateTime.Now.Year, 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'), DateTime.Now.Millisecond.ToString().PadLeft(3, '0') }), logString)); XSingleton.singleton.XPlatform.SetNoBackupFlag(this._outpath); } } private void Update() { } public void Log(params object[] objs) { string text = ""; for (int i = 0; i < objs.Length; i++) { bool flag = i == 0; if (flag) { text += objs[i].ToString(); } else { text = text + ", " + objs[i].ToString(); } } this.WriterLog(text); } public void SendBuglyReport(string logstring) { bool flag = (int) Application.platform != 7 && Application.platform > 0; if (flag) { IXBuglyMgr ixbuglyMgr = XUpdater.XUpdater.XGameRoot.GetComponent("XBuglyMgr") as IXBuglyMgr; ixbuglyMgr.ReportCrashToBugly(XFileLog.ServerID, XFileLog.RoleName, XFileLog.RoleLevel, XFileLog.RoleProf, XFileLog.OpenID, XSingleton.singleton.Version, Time.realtimeSinceStartup.ToString(), "loaded", XFileLog.SceneID.ToString(), logstring); } } public static void AddCustomLog(string customLog) { XFileLog.CustomLogQueue.Enqueue(customLog); while (XFileLog.CustomLogQueue.Count > 20) { XFileLog.CustomLogQueue.Dequeue(); } } } }