summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XUtliPoolLib/XFileLog.cs
blob: 616db28ea8a3837ce6954f13a1be1f0ac3068797 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
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<string> CustomLogQueue = new Queue<string>();

		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<XDebug>.singleton.AddErrorLog("Del Log File Error!!!", null, null, null, null, null);
								}
							}
						}
					}
				}
			}
			XFileLog.callBack = new Application.LogCallback(this.HandleLog);
			Application.logMessageReceived += XFileLog.callBack;
			XSingleton<XDebug>.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<XUpdater.XUpdater>.singleton.ABManager != null;
				if (flag)
				{
					GUI.TextArea(new Rect(0f, 30f, 100f, 30f), XSingleton<XUpdater.XUpdater>.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<XUpdater.XUpdater>.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<XUpdater.XUpdater>.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();
			}
		}
	}
}